File tree Expand file tree Collapse file tree 1 file changed +29
-3
lines changed Expand file tree Collapse file tree 1 file changed +29
-3
lines changed Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ module DSL
5
5
module ParametersSpec
6
6
class Dummy
7
7
include Grape ::DSL ::Parameters
8
- attr_accessor :api
8
+ attr_accessor :api , :element , :parent
9
9
10
10
def validate_attributes ( *args )
11
11
@validate_attributes = *args
@@ -127,8 +127,34 @@ def validates_reader
127
127
end
128
128
end
129
129
130
- xdescribe '#params' do
131
- it 'does some thing'
130
+ describe '#params' do
131
+ it 'inherits params from parent' do
132
+ parent_params = { foo : 'bar' }
133
+ subject . parent = Object . new
134
+ allow ( subject . parent ) . to receive ( :params ) . and_return ( parent_params )
135
+ expect ( subject . params ( { } ) ) . to eq parent_params
136
+ end
137
+
138
+ describe 'when params argument is an array of hashes' do
139
+ it 'returns values of each hash for @element key' do
140
+ subject . element = :foo
141
+ expect ( subject . params ( [ { foo : 'bar' } , { foo : 'baz' } ] ) ) . to eq ( %w( bar baz ) )
142
+ end
143
+ end
144
+
145
+ describe 'when params argument is a hash' do
146
+ it 'returns value for @element key' do
147
+ subject . element = :foo
148
+ expect ( subject . params ( foo : 'bar' ) ) . to eq ( 'bar' )
149
+ end
150
+ end
151
+
152
+ describe 'when params argument is not a array or a hash' do
153
+ it 'returns empty hash' do
154
+ subject . element = Object . new
155
+ expect ( subject . params ( Object . new ) ) . to eq ( { } )
156
+ end
157
+ end
132
158
end
133
159
end
134
160
end
You can’t perform that action at this time.
0 commit comments