Make test attributes explicit

- Organize test poros with associations and by serializer
- Freeze derived attributes/associations against mutation
- Cleanup PORO fixtures
This commit is contained in:
Benjamin Fleischer
2016-11-21 09:31:11 -06:00
parent 095ad9c82c
commit 80af763d2e
20 changed files with 380 additions and 278 deletions

View File

@@ -8,7 +8,7 @@ module ActiveModel
@author.roles = []
@blog = Blog.new(name: 'AMS Blog')
@post = Post.new(title: 'New Post', body: 'Body')
@tag = Tag.new(name: '#hashtagged')
@tag = Tag.new(id: 'tagid', name: '#hashtagged')
@comment = Comment.new(id: 1, body: 'ZOMG A COMMENT')
@post.comments = [@comment]
@post.tags = [@tag]
@@ -53,7 +53,7 @@ module ActiveModel
assert_equal :tags, key
assert_nil serializer
assert_equal [{ name: '#hashtagged' }].to_json, options[:virtual_value].to_json
assert_equal [{ id: 'tagid', name: '#hashtagged' }].to_json, options[:virtual_value].to_json
end
end
@@ -62,7 +62,13 @@ module ActiveModel
.associations
.detect { |assoc| assoc.key == :comments }
assert association.serializer.first.custom_options[:custom_options]
comment_serializer = association.serializer.first
class << comment_serializer
def custom_options
instance_options
end
end
assert comment_serializer.custom_options.fetch(:custom_options)
end
def test_belongs_to
@@ -159,7 +165,9 @@ module ActiveModel
class NamespacedResourcesTest < ActiveSupport::TestCase
class ResourceNamespace
class Post < ::Model; end
class Post < ::Model
associations :comments, :author, :description
end
class Comment < ::Model; end
class Author < ::Model; end
class Description < ::Model; end
@@ -200,7 +208,9 @@ module ActiveModel
end
class NestedSerializersTest < ActiveSupport::TestCase
class Post < ::Model; end
class Post < ::Model
associations :comments, :author, :description
end
class Comment < ::Model; end
class Author < ::Model; end
class Description < ::Model; end
@@ -240,7 +250,10 @@ module ActiveModel
# rubocop:disable Metrics/AbcSize
def test_conditional_associations
model = ::Model.new(true: true, false: false)
model = Class.new(::Model) do
attributes :true, :false
associations :association
end.new(true: true, false: false)
scenarios = [
{ options: { if: :true }, included: true },