diff options
author | Sean Griffin <sean@seantheprogrammer.com> | 2015-06-12 07:02:24 -0600 |
---|---|---|
committer | Sean Griffin <sean@seantheprogrammer.com> | 2015-06-12 07:02:24 -0600 |
commit | 0158f9261f0f3d7be5bb5974ceef96bcf862766a (patch) | |
tree | ff49f157cec90482f8593eee71d29394cfb2704f /activerecord/test/cases | |
parent | 40ffcd88a6a3129d8b9eb9f4dc077d8fd00aeb54 (diff) | |
parent | 09bef7684a5ddd0e37d8bed38858a9fa866e1df2 (diff) | |
download | rails-0158f9261f0f3d7be5bb5974ceef96bcf862766a.tar.gz rails-0158f9261f0f3d7be5bb5974ceef96bcf862766a.tar.bz2 rails-0158f9261f0f3d7be5bb5974ceef96bcf862766a.zip |
Merge pull request #19813 from igas/enum-prefix
Add prefix option to enum definition
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r-- | activerecord/test/cases/enum_test.rb | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/activerecord/test/cases/enum_test.rb b/activerecord/test/cases/enum_test.rb index 3641826daa..769b171717 100644 --- a/activerecord/test/cases/enum_test.rb +++ b/activerecord/test/cases/enum_test.rb @@ -14,16 +14,26 @@ class EnumTest < ActiveRecord::TestCase assert_not @book.proposed? assert @book.read? + assert @book.in_english? + assert @book.author_visibility_visible? + assert @book.illustrator_visibility_visible? + assert @book.with_medium_font_size? end test "query state with strings" do assert_equal "published", @book.status assert_equal "read", @book.read_status + assert_equal "english", @book.language + assert_equal "visible", @book.author_visibility + assert_equal "visible", @book.illustrator_visibility end test "find via scope" do assert_equal @book, Book.published.first assert_equal @book, Book.read.first + assert_equal @book, Book.in_english.first + assert_equal @book, Book.author_visibility_visible.first + assert_equal @book, Book.illustrator_visibility_visible.first end test "find via where with values" do @@ -72,6 +82,10 @@ class EnumTest < ActiveRecord::TestCase test "update by declaration" do @book.written! assert @book.written? + @book.in_english! + assert @book.in_english? + @book.author_visibility_visible! + assert @book.author_visibility_visible? end test "update by setter" do @@ -96,42 +110,61 @@ class EnumTest < ActiveRecord::TestCase test "enum changed attributes" do old_status = @book.status + old_language = @book.language @book.status = :proposed + @book.language = :spanish assert_equal old_status, @book.changed_attributes[:status] + assert_equal old_language, @book.changed_attributes[:language] end test "enum changes" do old_status = @book.status + old_language = @book.language @book.status = :proposed + @book.language = :spanish assert_equal [old_status, 'proposed'], @book.changes[:status] + assert_equal [old_language, 'spanish'], @book.changes[:language] end test "enum attribute was" do old_status = @book.status + old_language = @book.language @book.status = :published + @book.language = :spanish assert_equal old_status, @book.attribute_was(:status) + assert_equal old_language, @book.attribute_was(:language) end test "enum attribute changed" do @book.status = :proposed + @book.language = :french assert @book.attribute_changed?(:status) + assert @book.attribute_changed?(:language) end test "enum attribute changed to" do @book.status = :proposed + @book.language = :french assert @book.attribute_changed?(:status, to: 'proposed') + assert @book.attribute_changed?(:language, to: 'french') end test "enum attribute changed from" do old_status = @book.status + old_language = @book.language @book.status = :proposed + @book.language = :french assert @book.attribute_changed?(:status, from: old_status) + assert @book.attribute_changed?(:language, from: old_language) end test "enum attribute changed from old status to new status" do old_status = @book.status + old_language = @book.language @book.status = :proposed + @book.language = :french assert @book.attribute_changed?(:status, from: old_status, to: 'proposed') + assert @book.attribute_changed?(:language, from: old_language, to: 'french') end test "enum didn't change" do @@ -201,11 +234,15 @@ class EnumTest < ActiveRecord::TestCase test "building new objects with enum scopes" do assert Book.written.build.written? assert Book.read.build.read? + assert Book.in_spanish.build.in_spanish? + assert Book.illustrator_visibility_invisible.build.illustrator_visibility_invisible? end test "creating new objects with enum scopes" do assert Book.written.create.written? assert Book.read.create.read? + assert Book.in_spanish.create.in_spanish? + assert Book.illustrator_visibility_invisible.create.illustrator_visibility_invisible? end test "_before_type_cast returns the enum label (required for form fields)" do @@ -355,4 +392,17 @@ class EnumTest < ActiveRecord::TestCase book2 = klass.single.create! assert book2.single? end + + test "query state by predicate with prefix" do + assert @book.author_visibility_visible? + assert_not @book.author_visibility_invisible? + assert @book.illustrator_visibility_visible? + assert_not @book.illustrator_visibility_invisible? + end + + test "query state by predicate with custom prefix" do + assert @book.in_english? + assert_not @book.in_spanish? + assert_not @book.in_french? + end end |