mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 07:16:49 +00:00
Merge pull request #836 from rails-api/stores-passed-in-options
Makes passed in options accessible inside serializers
This commit is contained in:
4
test/fixtures/poro.rb
vendored
4
test/fixtures/poro.rb
vendored
@@ -45,6 +45,10 @@ class ProfileSerializer < ActiveModel::Serializer
|
||||
attributes :name, :description
|
||||
|
||||
urls :posts, :comments
|
||||
|
||||
def arguments_passed_in?
|
||||
options[:my_options] == :accessible
|
||||
end
|
||||
end
|
||||
|
||||
class ProfilePreviewSerializer < ActiveModel::Serializer
|
||||
|
||||
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