diff options
author | Eileen M. Uchitelle <eileencodes@gmail.com> | 2016-09-12 08:21:14 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-09-12 08:21:14 -0400 |
commit | 3dbb371445fa5d9e7477159e0d3079213633d5f9 (patch) | |
tree | 22c3f017b3386c85587d2410db547617225d1838 /activerecord/test/cases/enum_test.rb | |
parent | c48016c514f8991cb4f70eed673672a1440e271f (diff) | |
parent | 6009107caf9b0b570519b17aa0745fdb5a8c3b1f (diff) | |
download | rails-3dbb371445fa5d9e7477159e0d3079213633d5f9.tar.gz rails-3dbb371445fa5d9e7477159e0d3079213633d5f9.tar.bz2 rails-3dbb371445fa5d9e7477159e0d3079213633d5f9.zip |
Merge pull request #26459 from ysksn/add_test_for_activerecord_enum
Add tests for ActiveRecord::Enum#enum when suffix specified
Diffstat (limited to 'activerecord/test/cases/enum_test.rb')
-rw-r--r-- | activerecord/test/cases/enum_test.rb | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/activerecord/test/cases/enum_test.rb b/activerecord/test/cases/enum_test.rb index c2009843f0..b7641fcf32 100644 --- a/activerecord/test/cases/enum_test.rb +++ b/activerecord/test/cases/enum_test.rb @@ -18,6 +18,7 @@ class EnumTest < ActiveRecord::TestCase assert @book.author_visibility_visible? assert @book.illustrator_visibility_visible? assert @book.with_medium_font_size? + assert @book.medium_to_read? end test "query state with strings" do @@ -26,6 +27,7 @@ class EnumTest < ActiveRecord::TestCase assert_equal "english", @book.language assert_equal "visible", @book.author_visibility assert_equal "visible", @book.illustrator_visibility + assert_equal "medium", @book.difficulty end test "find via scope" do @@ -34,6 +36,7 @@ class EnumTest < ActiveRecord::TestCase assert_equal @book, Book.in_english.first assert_equal @book, Book.author_visibility_visible.first assert_equal @book, Book.illustrator_visibility_visible.first + assert_equal @book, Book.medium_to_read.first end test "find via where with values" do @@ -422,6 +425,43 @@ class EnumTest < ActiveRecord::TestCase assert_not @book.in_french? end + test "query state by predicate with custom suffix" do + assert @book.medium_to_read? + assert_not @book.easy_to_read? + assert_not @book.hard_to_read? + end + + test "enum methods with custom suffix defined" do + assert @book.class.respond_to?(:easy_to_read) + assert @book.class.respond_to?(:medium_to_read) + assert @book.class.respond_to?(:hard_to_read) + + assert @book.respond_to?(:easy_to_read?) + assert @book.respond_to?(:medium_to_read?) + assert @book.respond_to?(:hard_to_read?) + + assert @book.respond_to?(:easy_to_read!) + assert @book.respond_to?(:medium_to_read!) + assert @book.respond_to?(:hard_to_read!) + end + + test "update enum attributes with custom suffix" do + @book.medium_to_read! + assert_not @book.easy_to_read? + assert @book.medium_to_read? + assert_not @book.hard_to_read? + + @book.easy_to_read! + assert @book.easy_to_read? + assert_not @book.medium_to_read? + assert_not @book.hard_to_read? + + @book.hard_to_read! + assert_not @book.easy_to_read? + assert_not @book.medium_to_read? + assert @book.hard_to_read? + end + test "uses default status when no status is provided in fixtures" do book = books(:tlg) assert book.proposed?, "expected fixture to default to proposed status" |