Break up these tests

Make sure we have coverage for both the find/build cases
This commit is contained in:
Godfrey Chan 2015-02-13 16:46:52 -08:00
parent 3dfd1bab6a
commit 58adda3477

@ -26,10 +26,15 @@ class EnumTest < ActiveRecord::TestCase
assert_equal @book, Book.unread.first
end
test "build from scope" do
assert Book.proposed.build.proposed?
refute Book.proposed.build.written?
assert Book.where(status: Book.statuses[:proposed]).build.proposed?
test "find via where with values" do
proposed, written = Book.statuses[:proposed], Book.statuses[:written]
assert_equal @book, Book.where(status: proposed).first
refute_equal @book, Book.where(status: written).first
assert_equal @book, Book.where(status: [proposed]).first
refute_equal @book, Book.where(status: [written]).first
refute_equal @book, Book.where("status <> ?", proposed).first
assert_equal @book, Book.where("status <> ?", written).first
end
test "find via where with symbols" do
@ -50,6 +55,20 @@ class EnumTest < ActiveRecord::TestCase
assert_equal @book, Book.where("status <> ?", "written").first
end
test "build from scope" do
assert Book.written.build.written?
refute Book.written.build.proposed?
end
test "build from where" do
assert Book.where(status: Book.statuses[:written]).build.written?
refute Book.where(status: Book.statuses[:written]).build.proposed?
assert Book.where(status: :written).build.written?
refute Book.where(status: :written).build.proposed?
assert Book.where(status: "written").build.written?
refute Book.where(status: "written").build.proposed?
end
test "update by declaration" do
@book.written!
assert @book.written?