File tree Expand file tree Collapse file tree 3 files changed +28
-0
lines changed Expand file tree Collapse file tree 3 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -140,6 +140,7 @@ def self.root_name
140
140
141
141
def initialize ( object , options = { } )
142
142
@object = object
143
+ @options = options
143
144
@root = options [ :root ] || ( self . class . _root ? self . class . root_name : false )
144
145
@meta = options [ :meta ]
145
146
@meta_key = options [ :meta_key ]
@@ -201,6 +202,8 @@ def serializer_from_options(options)
201
202
202
203
private
203
204
205
+ attr_reader :options
206
+
204
207
def self . get_serializer_for ( klass )
205
208
serializer_class_name = "#{ klass . name } Serializer"
206
209
serializer_class = serializer_class_name . safe_constantize
Original file line number Diff line number Diff line change @@ -45,6 +45,10 @@ class ProfileSerializer < ActiveModel::Serializer
45
45
attributes :name , :description
46
46
47
47
urls :posts , :comments
48
+
49
+ def arguments_passed_in?
50
+ options [ :my_options ] == :accessible
51
+ end
48
52
end
49
53
50
54
class ProfilePreviewSerializer < ActiveModel ::Serializer
Original file line number Diff line number Diff line change
1
+ require 'test_helper'
2
+
3
+ module ActiveModel
4
+ class Serializer
5
+ class OptionsTest < Minitest ::Test
6
+ def setup
7
+ @profile = Profile . new ( name : 'Name 1' , description : 'Description 1' )
8
+ end
9
+
10
+ def test_options_are_accessible
11
+ @profile_serializer = ProfileSerializer . new ( @profile , my_options : :accessible )
12
+ assert @profile_serializer . arguments_passed_in?
13
+ end
14
+
15
+ def test_no_option_is_passed_in
16
+ @profile_serializer = ProfileSerializer . new ( @profile )
17
+ refute @profile_serializer . arguments_passed_in?
18
+ end
19
+ end
20
+ end
21
+ end
You can’t perform that action at this time.
0 commit comments