Add tests for conditional attributes/associations.

This commit is contained in:
Lucas Hosseini
2016-01-12 13:42:44 +01:00
parent 7fbf7e536d
commit 7af198653d
2 changed files with 47 additions and 1 deletions

View File

@@ -238,6 +238,29 @@ module ActiveModel
end
end
end
def test_conditional_associations
serializer = Class.new(ActiveModel::Serializer) do
belongs_to :if_assoc_included, if: :true
belongs_to :if_assoc_excluded, if: :false
belongs_to :unless_assoc_included, unless: :false
belongs_to :unless_assoc_excluded, unless: :true
def true
true
end
def false
false
end
end
model = ::Model.new
hash = serializable(model, serializer: serializer).serializable_hash
expected = { if_assoc_included: nil, unless_assoc_included: nil }
assert_equal(expected, hash)
end
end
end
end