mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-22 13:56:53 +00:00
Update reflection tests
This commit is contained in:
parent
5e01a93fc0
commit
876190440f
@ -25,6 +25,10 @@ module ActiveModel
|
||||
@instance_options = {}
|
||||
end
|
||||
|
||||
def evaluate_association_value(association)
|
||||
association.lazy_association.eval_reflection_block
|
||||
end
|
||||
|
||||
# TODO: Remaining tests
|
||||
# test_reflection_value_block_with_scope
|
||||
# test_reflection_value_uses_serializer_instance_method
|
||||
@ -175,10 +179,12 @@ module ActiveModel
|
||||
|
||||
# Build Association
|
||||
association = reflection.build_association(serializer_instance, @instance_options)
|
||||
|
||||
# Assert association links empty when not yet evaluated
|
||||
assert_equal @empty_links, reflection.options.fetch(:links)
|
||||
assert_equal @empty_links, association.links
|
||||
association.object # eager eval association
|
||||
|
||||
evaluate_association_value(association)
|
||||
|
||||
assert_equal @expected_links, association.links
|
||||
assert_equal @expected_links, reflection.options.fetch(:links)
|
||||
@ -200,12 +206,16 @@ module ActiveModel
|
||||
|
||||
# Build Association
|
||||
association = reflection.build_association(serializer_instance, @instance_options)
|
||||
|
||||
# Assert association links empty when not yet evaluated
|
||||
assert_equal @empty_links, association.links
|
||||
association.object # eager eval association
|
||||
|
||||
evaluate_association_value(association)
|
||||
|
||||
# Assert before instance_eval link
|
||||
link = association.links.fetch(:self)
|
||||
assert_respond_to link, :call
|
||||
assert_respond_to reflection.options.fetch(:links).fetch(:self), :call
|
||||
|
||||
# Assert after instance_eval link
|
||||
assert_equal @expected_links.fetch(:self), reflection.instance_eval(&link)
|
||||
@ -226,7 +236,9 @@ module ActiveModel
|
||||
|
||||
# Build Association
|
||||
association = reflection.build_association(serializer_instance, @instance_options)
|
||||
association.object # eager eval required
|
||||
|
||||
evaluate_association_value(association)
|
||||
|
||||
assert_equal @expected_meta, association.meta
|
||||
assert_equal @expected_meta, reflection.options.fetch(:meta)
|
||||
end
|
||||
@ -248,7 +260,9 @@ module ActiveModel
|
||||
# Build Association
|
||||
association = reflection.build_association(serializer_instance, @instance_options)
|
||||
# Assert before instance_eval meta
|
||||
association.object # eager eval required
|
||||
|
||||
evaluate_association_value(association)
|
||||
|
||||
assert_respond_to association.meta, :call
|
||||
assert_respond_to reflection.options.fetch(:meta), :call
|
||||
|
||||
@ -281,7 +295,8 @@ module ActiveModel
|
||||
assert_nil association.meta
|
||||
assert_nil reflection.options.fetch(:meta)
|
||||
|
||||
association.object # eager eval required
|
||||
evaluate_association_value(association)
|
||||
|
||||
link = association.links.fetch(:self)
|
||||
assert_respond_to link, :call
|
||||
assert_respond_to reflection.options.fetch(:links).fetch(:self), :call
|
||||
@ -290,8 +305,7 @@ module ActiveModel
|
||||
# Assert after instance_eval link
|
||||
assert_equal 'no_uri_validation', reflection.instance_eval(&link)
|
||||
assert_equal @expected_meta, reflection.options.fetch(:meta)
|
||||
return # oh no, need to figure this out
|
||||
assert_nil association.meta # rubocop:disable Lint/UnreachableCode
|
||||
assert_equal @expected_meta, association.meta
|
||||
end
|
||||
# rubocop:enable Metrics/AbcSize
|
||||
|
||||
@ -319,7 +333,9 @@ module ActiveModel
|
||||
assert_nil reflection.options.fetch(:meta)
|
||||
|
||||
# Assert before instance_eval link
|
||||
association.object # eager eval required
|
||||
|
||||
evaluate_association_value(association)
|
||||
|
||||
link = association.links.fetch(:self)
|
||||
assert_nil reflection.options.fetch(:meta)
|
||||
assert_respond_to link, :call
|
||||
@ -330,12 +346,11 @@ module ActiveModel
|
||||
assert_respond_to association.links.fetch(:self), :call
|
||||
# Assert before instance_eval link meta
|
||||
assert_respond_to reflection.options.fetch(:meta), :call
|
||||
return # oh no, need to figure this out
|
||||
assert_nil association.meta # rubocop:disable Lint/UnreachableCode
|
||||
assert_respond_to association.meta, :call
|
||||
|
||||
# Assert after instance_eval link meta
|
||||
assert_equal @expected_meta, reflection.instance_eval(&reflection.options.fetch(:meta))
|
||||
assert_nil association.meta
|
||||
assert_respond_to association.meta, :call
|
||||
end
|
||||
# rubocop:enable Metrics/AbcSize
|
||||
|
||||
@ -356,7 +371,9 @@ module ActiveModel
|
||||
# Build Association
|
||||
association = reflection.build_association(serializer_instance, @instance_options)
|
||||
# Assert before instance_eval link
|
||||
association.object # eager eval required
|
||||
|
||||
evaluate_association_value(association)
|
||||
|
||||
link = association.links.fetch(:self)
|
||||
assert_respond_to link, :call
|
||||
|
||||
@ -380,7 +397,9 @@ module ActiveModel
|
||||
reflection = serializer_class._reflections.fetch(:blog)
|
||||
assert_nil reflection.options.fetch(:meta)
|
||||
association = reflection.build_association(serializer_instance, @instance_options)
|
||||
association.object # eager eval required
|
||||
|
||||
evaluate_association_value(association)
|
||||
|
||||
assert_equal model1_meta, association.meta
|
||||
assert_equal model1_meta, reflection.options.fetch(:meta)
|
||||
|
||||
@ -396,7 +415,9 @@ module ActiveModel
|
||||
assert_equal model1_meta, reflection.options.fetch(:meta)
|
||||
|
||||
association = reflection.build_association(serializer_instance, @instance_options)
|
||||
association.object # eager eval required
|
||||
|
||||
evaluate_association_value(association)
|
||||
|
||||
assert_equal model2_meta, association.meta
|
||||
assert_equal model2_meta, reflection.options.fetch(:meta)
|
||||
end
|
||||
|
||||
Loading…
Reference in New Issue
Block a user