Skip to content

Instantly share code, notes, and snippets.

@kjlape
Created December 14, 2021 03:39
Show Gist options
  • Save kjlape/231edf7dcb0638291e190218282b31d4 to your computer and use it in GitHub Desktop.
Save kjlape/231edf7dcb0638291e190218282b31d4 to your computer and use it in GitHub Desktop.
class WishlistFlowsTest < ActionDispatch::IntegrationTest
setup do
@builder = Builder.new
end
test "can make a wish" do
wisher = @builder.users(name: "George Wishington").create!
sign_in_as(wisher)
assert_changes "Wish.count" do
post wishes_path, {title: "My two front teeth"}
end
assert_redirected_to wishes_path
follow_redirect!
assert_select "wishlist-notice", "Success"
end
test "wishes do come true" do
gifter = @builder.users(name: "Santa Clause").create!
wish = @builder.wishes(name: "My two front teeth").create!
sign_in_as(gifter)
get wisher_wishes_path(wish.wisher)
assert_status :ok
assert_select "wishlist-wish", "My two front teeth"
patch wisher_wish_path(wish), {status: :purchased}
assert_redirected_to wisher_wishes_path(wish.wisher)
follow_redirect!
assert_select "wishlist-notice", "Success"
end
class Builder
def wishes(wisher: users.new, title: "A Generic Wish")
Wish.create_with(
wisher: wisher,
title: title
)
end
def users(name:, email: emailify(name))
User.create_with(
email: email,
name: name
)
end
def categories(name: "Christmas")
Category.create_with(name: name)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment