Permalink
Browse files

Merge pull request #26459 from ysksn/add_test_for_activerecord_enum

Add tests for ActiveRecord::Enum#enum when suffix specified
  • Loading branch information...
eileencodes committed Sep 12, 2016
2 parents c48016c + 6009107 commit 3dbb371445fa5d9e7477159e0d3079213633d5f9
@@ -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 @@ def self.name; "Book"; end
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"
@@ -9,6 +9,7 @@ awdr:
author_visibility: :visible
illustrator_visibility: :visible
font_size: :medium
difficulty: :medium
rfr:
author_id: 1
@@ -14,6 +14,7 @@ class Book < ActiveRecord::Base
enum author_visibility: [:visible, :invisible], _prefix: true
enum illustrator_visibility: [:visible, :invisible], _prefix: true
enum font_size: [:small, :medium, :large], _prefix: :with, _suffix: true
enum difficulty: [:easy, :medium, :hard], _suffix: :to_read
enum cover: { hard: "hard", soft: "soft" }
def published!
@@ -98,6 +98,7 @@
t.column :author_visibility, :integer, default: 0
t.column :illustrator_visibility, :integer, default: 0
t.column :font_size, :integer, default: 0
t.column :difficulty, :integer, default: 0
t.column :cover, :string, default: "hard"
end

0 comments on commit 3dbb371

Please sign in to comment.