diff options
author | Godfrey Chan <godfreykfc@gmail.com> | 2015-02-13 16:46:52 -0800 |
---|---|---|
committer | Godfrey Chan <godfreykfc@gmail.com> | 2015-02-13 16:46:52 -0800 |
commit | 58adda34778ef2c874ee86e491d05042b99e6a18 (patch) | |
tree | e2a3fa0d53fa41fb89765d514df4743174c0e45a /activerecord/test/cases | |
parent | 3dfd1bab6a523061e41fb89be51f149968eea510 (diff) | |
download | rails-58adda34778ef2c874ee86e491d05042b99e6a18.tar.gz rails-58adda34778ef2c874ee86e491d05042b99e6a18.tar.bz2 rails-58adda34778ef2c874ee86e491d05042b99e6a18.zip |
Break up these tests
Make sure we have coverage for both the find/build cases
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r-- | activerecord/test/cases/enum_test.rb | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/activerecord/test/cases/enum_test.rb b/activerecord/test/cases/enum_test.rb index 43fca42478..0cb34b5960 100644 --- a/activerecord/test/cases/enum_test.rb +++ b/activerecord/test/cases/enum_test.rb @@ -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? |