mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 07:16:49 +00:00
Makes passed in options accessible inside serializers
In some cases, we want to pass arguments from the controller and we want to serializer a resource according to that. This allows serializers to use the `options` method to retrieve whatever was passed in via arguments.
This commit is contained in:
21
test/serializers/options_test.rb
Normal file
21
test/serializers/options_test.rb
Normal file
@@ -0,0 +1,21 @@
|
||||
require 'test_helper'
|
||||
|
||||
module ActiveModel
|
||||
class Serializer
|
||||
class OptionsTest < Minitest::Test
|
||||
def setup
|
||||
@profile = Profile.new(name: 'Name 1', description: 'Description 1')
|
||||
end
|
||||
|
||||
def test_options_are_accessible
|
||||
@profile_serializer = ProfileSerializer.new(@profile, my_options: :accessible)
|
||||
assert @profile_serializer.arguments_passed_in?
|
||||
end
|
||||
|
||||
def test_no_option_is_passed_in
|
||||
@profile_serializer = ProfileSerializer.new(@profile)
|
||||
refute @profile_serializer.arguments_passed_in?
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user