hoodoo 2.5.0 → 2.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/hoodoo/services/middleware/exception_reporting/base_reporter.rb +7 -1
- data/lib/hoodoo/services/services/request.rb +55 -18
- data/lib/hoodoo/version.rb +2 -2
- data/spec/services/middleware/exception_reporting/base_reporter_spec.rb +5 -5
- data/spec/services/services/request_spec.rb +294 -110
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bcd6275929dde876479da0087f2eef17e4d9fd3c8606182daeff2fd4c02c35c9
|
4
|
+
data.tar.gz: 3763e2d462802bbdae8240864e7bf73b83eb5458675da127af70edba8013dc1b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6492416bb7afa5d8e7d9a23169293f055c73a6b9e8c63362f65b08ce7f49bd219874be90480ea7156c02373725e8088b19f9dfdda3a9ba2329b3037b7bc8b958
|
7
|
+
data.tar.gz: a8142c1c0973b77b1101af5f757b088b81a11bac48cce8597691288dcc288c8a786efd1ea6dd16820c44b9c222fb8df351cb739e6a2a6ea3e248f09b3943bacb
|
@@ -162,7 +162,13 @@ module Hoodoo; module Services
|
|
162
162
|
:embeds => context.request.embeds,
|
163
163
|
:references => context.request.references,
|
164
164
|
:headers => context.request.headers,
|
165
|
-
:list =>
|
165
|
+
:list => {
|
166
|
+
:offset => context.request.list.offset,
|
167
|
+
:limit => context.request.list.limit,
|
168
|
+
:sort_data => context.request.list.sort_data,
|
169
|
+
:search_data => context.request.list.search_data,
|
170
|
+
:filter_data => context.request.list.filter_data
|
171
|
+
}
|
166
172
|
}
|
167
173
|
}
|
168
174
|
|
@@ -64,31 +64,44 @@ module Hoodoo; module Services
|
|
64
64
|
self.filter_data = {}
|
65
65
|
end
|
66
66
|
|
67
|
-
# Represent the list data as a Hash, for uses such as persistence
|
68
|
-
#
|
69
|
-
#
|
70
|
-
#
|
67
|
+
# Represent the list data as a Hash, for uses such as persistence or
|
68
|
+
# loading into another session instance. The returned Hash is a full
|
69
|
+
# deep copy of any internal data; changing it will not alter the
|
70
|
+
# ListParameters object state.
|
71
71
|
#
|
72
|
-
# Top-level keys in the Hash are Strings corresponding to
|
73
|
-
#
|
72
|
+
# Top-level keys in the Hash are Strings corresponding to fields
|
73
|
+
# supported by the query Hash in Hoodoo::Client::Endpoint#list,
|
74
|
+
# intentionally compatible so that pass-through / proxy scenarios from
|
75
|
+
# resource implementation to another resource are assisted:
|
74
76
|
#
|
75
77
|
# * +"offset"+
|
76
78
|
# * +"limit"+
|
77
|
-
# * +"
|
78
|
-
# * +"
|
79
|
-
# * +"
|
79
|
+
# * +"sort"+ (keys from the Hash under attribute #sort_data)
|
80
|
+
# * +"direction"+ (values from the Hash under #sort_data)
|
81
|
+
# * +"search"+ (deep-duplcated value of attribute #search_data)
|
82
|
+
# * +"filter"+ (deep-duplcated value of attribute #filter_data)
|
80
83
|
#
|
81
|
-
# Sort, search and filter data, if not empty, also have
|
84
|
+
# Sort, direction, search and filter data, if not empty, also have
|
85
|
+
# String keys / values. A single sort-direction key-value pair will be
|
86
|
+
# flattened to a simple value, while multiple sort-direction pairs are
|
87
|
+
# given as Arrays.
|
82
88
|
#
|
83
89
|
# See also #from_h!.
|
84
90
|
#
|
85
91
|
def to_h
|
92
|
+
sorts = self.sort_data.keys.map( & :to_s )
|
93
|
+
directions = self.sort_data.values.map( & :to_s )
|
94
|
+
|
95
|
+
sorts = sorts.first if sorts.count == 1
|
96
|
+
directions = directions.first if directions.count == 1
|
97
|
+
|
86
98
|
{
|
87
|
-
'offset'
|
88
|
-
'limit'
|
89
|
-
'
|
90
|
-
'
|
91
|
-
'
|
99
|
+
'offset' => self.offset,
|
100
|
+
'limit' => self.limit,
|
101
|
+
'sort' => sorts,
|
102
|
+
'direction' => directions,
|
103
|
+
'search' => Hoodoo::Utilities.deep_dup( self.search_data ),
|
104
|
+
'filter' => Hoodoo::Utilities.deep_dup( self.filter_data )
|
92
105
|
}
|
93
106
|
end
|
94
107
|
|
@@ -99,9 +112,33 @@ module Hoodoo; module Services
|
|
99
112
|
def from_h!( hash )
|
100
113
|
self.offset = hash[ 'offset' ] if hash.has_key?( 'offset' )
|
101
114
|
self.limit = hash[ 'limit' ] if hash.has_key?( 'limit' )
|
102
|
-
self.
|
103
|
-
self.
|
104
|
-
|
115
|
+
self.search_data = Hoodoo::Utilities.deep_dup( hash[ 'search' ] ) if hash[ 'search' ].is_a?( Hash )
|
116
|
+
self.filter_data = Hoodoo::Utilities.deep_dup( hash[ 'filter' ] ) if hash[ 'filter' ].is_a?( Hash )
|
117
|
+
|
118
|
+
sorts = hash[ 'sort' ]
|
119
|
+
directions = hash[ 'direction' ]
|
120
|
+
|
121
|
+
# Ensure the values are Arrays not just simple e.g. Strings,
|
122
|
+
# so that we can zip them up into a Hash for the 'sort_data'
|
123
|
+
# attribute value. Merge the result onto the existing values.
|
124
|
+
#
|
125
|
+
sorts = [ sorts ] unless sorts.is_a?( Array )
|
126
|
+
directions = [ directions ] unless directions.is_a?( Array )
|
127
|
+
|
128
|
+
sorts.compact!
|
129
|
+
directions.compact!
|
130
|
+
|
131
|
+
sorts.concat( self.sort_data.keys[ sorts.count .. -1 ] || [] )
|
132
|
+
directions.concat( self.sort_data.values[ directions.count .. -1 ] || [] )
|
133
|
+
|
134
|
+
# The middleware enforces a URI query string match of the
|
135
|
+
# count of sort and direction specifiers, so we do the same.
|
136
|
+
#
|
137
|
+
if sorts.length != directions.length
|
138
|
+
raise 'Hoodoo::Services::Request::ListParameters#from_h!: Sort and direction array lengths must match'
|
139
|
+
end
|
140
|
+
|
141
|
+
self.sort_data = Hash[ sorts.zip( directions ) ]
|
105
142
|
end
|
106
143
|
end
|
107
144
|
|
data/lib/hoodoo/version.rb
CHANGED
@@ -12,11 +12,11 @@ module Hoodoo
|
|
12
12
|
# The Hoodoo gem version. If this changes, be sure to re-run
|
13
13
|
# <tt>bundle install</tt> or <tt>bundle update</tt>.
|
14
14
|
#
|
15
|
-
VERSION = '2.5.
|
15
|
+
VERSION = '2.5.1'
|
16
16
|
|
17
17
|
# The Hoodoo gem date. If this changes, be sure to re-run
|
18
18
|
# <tt>bundle install</tt> or <tt>bundle update</tt>.
|
19
19
|
#
|
20
|
-
DATE = '2018-05-
|
20
|
+
DATE = '2018-05-18'
|
21
21
|
|
22
22
|
end
|
@@ -88,11 +88,11 @@ describe Hoodoo::Services::Middleware::ExceptionReporting::BaseReporter do
|
|
88
88
|
:references => [ 'r1', 'r2' ],
|
89
89
|
:headers => { 'HTTP_X_EXAMPLE' => '42' },
|
90
90
|
:list => {
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
91
|
+
:offset => 0,
|
92
|
+
:limit => 50,
|
93
|
+
:sort_data => { 'created_at' => 'desc' },
|
94
|
+
:search_data => { 'example' => '42' },
|
95
|
+
:filter_data => { 'unexample' => '24' }
|
96
96
|
}
|
97
97
|
},
|
98
98
|
:session => Hoodoo::Services::Middleware.test_session().to_h()
|
@@ -65,6 +65,71 @@ describe Hoodoo::Services::Request do
|
|
65
65
|
end
|
66
66
|
end
|
67
67
|
|
68
|
+
# ==========================================================================
|
69
|
+
|
70
|
+
# Used for #list sub-tests around "#from_h!", where we want to ensure that
|
71
|
+
# a Hash containing less-than-all possible keys results in updates to just
|
72
|
+
# the relevant attributes of the target object.
|
73
|
+
#
|
74
|
+
# Provide a Hash of *attribute* key-value pairs for new values to assign,
|
75
|
+
# except for the special cases of Arrays in 'sort' and 'direction', which
|
76
|
+
# are mapped to the 'sort_data' Hash.
|
77
|
+
#
|
78
|
+
# Iterates over all the possible keys above and builds a Hash that contains
|
79
|
+
# just one at a time. Makes a new Request, sets the list options from the
|
80
|
+
# one-at-a-time Hash and verifies that only the one parameter changed.
|
81
|
+
#
|
82
|
+
# A little fiddly due to the name mappings "search"/"search_data" or
|
83
|
+
# "filter"/"filter_data" and the unpacking of "sort_data" into independently
|
84
|
+
# alterable "sort" and "direction" lists. Tests sort/direction flattening of
|
85
|
+
# single element arrays into simple types in passing.
|
86
|
+
#
|
87
|
+
def test_replacements( replacements )
|
88
|
+
replacements.each do | replacement_key, replacement_value |
|
89
|
+
request = Hoodoo::Services::Request.new
|
90
|
+
clean = {
|
91
|
+
'offset' => request.list.offset,
|
92
|
+
'limit' => request.list.limit,
|
93
|
+
'sort_data' => request.list.sort_data,
|
94
|
+
'search_data' => request.list.search_data,
|
95
|
+
'filter_data' => request.list.filter_data
|
96
|
+
}
|
97
|
+
|
98
|
+
from_h_key = case replacement_key
|
99
|
+
when 'search_data'
|
100
|
+
'search'
|
101
|
+
when 'filter_data'
|
102
|
+
'filter'
|
103
|
+
else
|
104
|
+
replacement_key
|
105
|
+
end
|
106
|
+
|
107
|
+
hash = { from_h_key => replacement_value }
|
108
|
+
request.list.from_h!( hash )
|
109
|
+
|
110
|
+
clean.each do | clean_key, clean_value |
|
111
|
+
expected_value = replacement_value # Makes code below easier to read
|
112
|
+
|
113
|
+
if clean_key == 'sort_data' && replacement_key == 'sort'
|
114
|
+
# In passing, test 1-element-array flattening...
|
115
|
+
expected_value = expected_value.first if expected_value.is_a?( Array ) && expected_value.count == 1
|
116
|
+
expect( request.list.send( clean_key ) ).to eql( { expected_value => clean_value.values.first } )
|
117
|
+
|
118
|
+
elsif clean_key == 'sort_data' && replacement_key == 'direction'
|
119
|
+
expected_value = expected_value.first if expected_value.is_a?( Array ) && expected_value.count == 1
|
120
|
+
expect( request.list.send( clean_key ) ).to eql( { clean_value.keys.first => expected_value } )
|
121
|
+
|
122
|
+
elsif clean_key == replacement_key
|
123
|
+
expect( request.list.send( clean_key ) ).to eql( expected_value )
|
124
|
+
|
125
|
+
else
|
126
|
+
expect( request.list.send( clean_key ) ).to eql( clean_value )
|
127
|
+
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
68
133
|
context '#list' do
|
69
134
|
it 'has correct default values' do
|
70
135
|
expect( @r.list.offset ).to eq( 0 )
|
@@ -74,149 +139,268 @@ describe Hoodoo::Services::Request do
|
|
74
139
|
expect( @r.list.filter_data ).to eq( {} )
|
75
140
|
end
|
76
141
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
'filter_data' => @filter
|
91
|
-
}
|
92
|
-
end
|
142
|
+
it 'supports deprecated accessors' do
|
143
|
+
lo = 10
|
144
|
+
ll = 20
|
145
|
+
ke = 'foo'
|
146
|
+
di = 'asc'
|
147
|
+
sd = { :foo => :bar }
|
148
|
+
fd = { :baz => :foo }
|
149
|
+
|
150
|
+
@r.list_offset = lo
|
151
|
+
@r.list_limit = ll
|
152
|
+
@r.list_sort_data = { ke => di }
|
153
|
+
@r.list_search_data = sd
|
154
|
+
@r.list_filter_data = fd
|
93
155
|
|
94
|
-
|
156
|
+
expect( @r.list_offset ).to eq( lo )
|
157
|
+
expect( @r.list_limit ).to eq( ll )
|
158
|
+
expect( @r.list_sort_data ).to eq( { ke => di } )
|
159
|
+
expect( @r.list_search_data ).to eq( sd )
|
160
|
+
expect( @r.list_filter_data ).to eq( fd )
|
161
|
+
end
|
162
|
+
|
163
|
+
# ========================================================================
|
164
|
+
|
165
|
+
context 'with a single sort key and direction' do
|
166
|
+
context 'and via' do
|
95
167
|
before :each do
|
96
|
-
@
|
97
|
-
@
|
98
|
-
@
|
99
|
-
@
|
100
|
-
@
|
168
|
+
@offset = 1000
|
169
|
+
@limit = 500
|
170
|
+
@sort = { 'new_sort' => 'asc' }
|
171
|
+
@search = { 'foo' => 'bar', 'bar' => { 'baz' => 3 } }
|
172
|
+
@filter = { 'bar' => 'foo', 'baz' => { 'bar' => 2 } }
|
173
|
+
|
174
|
+
@replacement_hash = {
|
175
|
+
'offset' => @offset,
|
176
|
+
'limit' => @limit,
|
177
|
+
'sort' => @sort.keys.first,
|
178
|
+
'direction' => @sort.values.first,
|
179
|
+
'search' => @search,
|
180
|
+
'filter' => @filter
|
181
|
+
}
|
101
182
|
end
|
102
183
|
|
103
|
-
|
104
|
-
|
105
|
-
|
184
|
+
context '#to_h' do
|
185
|
+
before :each do
|
186
|
+
@r.list.offset = @offset
|
187
|
+
@r.list.limit = @limit
|
188
|
+
@r.list.sort_data = @sort
|
189
|
+
@r.list.search_data = @search
|
190
|
+
@r.list.filter_data = @filter
|
191
|
+
end
|
106
192
|
|
107
|
-
|
108
|
-
|
193
|
+
it 'returns the expected Hash' do
|
194
|
+
expect( @r.list.to_h ).to eq( @replacement_hash )
|
195
|
+
end
|
109
196
|
|
110
|
-
|
111
|
-
|
112
|
-
expect( @sort[ @sort.keys.first ] ).to eql( old_sort_value )
|
197
|
+
it 'deep-duplicates the parameters' do
|
198
|
+
result = @r.list.to_h()
|
113
199
|
|
114
|
-
|
115
|
-
|
116
|
-
|
200
|
+
old_search_value = @search.values.first
|
201
|
+
result[ 'search' ][ @search.keys.first ] = 'changed'
|
202
|
+
expect( @search.values.first ).to eql( old_search_value )
|
117
203
|
|
118
|
-
|
119
|
-
|
120
|
-
|
204
|
+
old_filter_value = @filter.values.first
|
205
|
+
result[ 'filter' ][ @filter.keys.first ] = 'changed'
|
206
|
+
expect( @filter.values.first ).to eql( old_filter_value )
|
207
|
+
end
|
121
208
|
end
|
122
|
-
end
|
123
209
|
|
124
|
-
|
125
|
-
|
126
|
-
|
210
|
+
context '#from_h!' do
|
211
|
+
it 'overwrites all parameters' do
|
212
|
+
request = Hoodoo::Services::Request.new
|
213
|
+
|
214
|
+
expect( request.list.offset ).to eq( 0 )
|
215
|
+
expect( request.list.limit ).to eq( 50 )
|
216
|
+
expect( request.list.sort_data ).to eq( { 'created_at' => 'desc' } )
|
217
|
+
expect( request.list.search_data ).to eq( {} )
|
218
|
+
expect( request.list.filter_data ).to eq( {} )
|
127
219
|
|
128
|
-
|
129
|
-
expect( request.list.limit ).to eq( 50 )
|
130
|
-
expect( request.list.sort_data ).to eq( { 'created_at' => 'desc' } )
|
131
|
-
expect( request.list.search_data ).to eq( {} )
|
132
|
-
expect( request.list.filter_data ).to eq( {} )
|
220
|
+
request.list.from_h!( @replacement_hash )
|
133
221
|
|
134
|
-
|
222
|
+
expect( request.list.offset ).to eq( @offset )
|
223
|
+
expect( request.list.limit ).to eq( @limit )
|
224
|
+
expect( request.list.sort_data ).to eq( @sort )
|
225
|
+
expect( request.list.search_data ).to eq( @search )
|
226
|
+
expect( request.list.filter_data ).to eq( @filter )
|
227
|
+
end
|
135
228
|
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
229
|
+
it 'overwrites only provided parameters' do
|
230
|
+
test_replacements( {
|
231
|
+
'offset' => @offset,
|
232
|
+
'limit' => @limit,
|
233
|
+
'sort' => @sort.keys.first,
|
234
|
+
'direction' => @sort.values.first,
|
235
|
+
'search_data' => @search,
|
236
|
+
'filter_data' => @filter
|
237
|
+
} )
|
238
|
+
end
|
141
239
|
end
|
142
240
|
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
241
|
+
context '#to_h and #from_h! together' do
|
242
|
+
before :each do
|
243
|
+
@r.list.offset = @offset
|
244
|
+
@r.list.limit = @limit
|
245
|
+
@r.list.sort_data = @sort
|
246
|
+
@r.list.search_data = @search
|
247
|
+
@r.list.filter_data = @filter
|
248
|
+
end
|
151
249
|
|
152
|
-
|
153
|
-
|
154
|
-
# options from the one-at-a-time Hash and verify that only that
|
155
|
-
# one parameter changed.
|
250
|
+
it 'translates from one list to another' do
|
251
|
+
hash = @r.list.to_h
|
156
252
|
|
157
|
-
replacements.each do | replacement_key, replacement_value |
|
158
253
|
request = Hoodoo::Services::Request.new
|
159
|
-
clean = {
|
160
|
-
'offset' => request.list.offset,
|
161
|
-
'limit' => request.list.limit,
|
162
|
-
'sort_data' => request.list.sort_data,
|
163
|
-
'search_data' => request.list.search_data,
|
164
|
-
'filter_data' => request.list.filter_data
|
165
|
-
}
|
166
|
-
|
167
|
-
hash = { replacement_key => replacement_value }
|
168
254
|
request.list.from_h!( hash )
|
169
255
|
|
170
|
-
|
171
|
-
if clean_key == replacement_key
|
172
|
-
expect( request.list.send( clean_key ) ).to eql( replacement_value )
|
173
|
-
else
|
174
|
-
expect( request.list.send( clean_key ) ).to eql( clean_value )
|
175
|
-
end
|
176
|
-
end
|
256
|
+
expect( request.list.to_h ).to eql( @replacement_hash )
|
177
257
|
end
|
178
258
|
end
|
179
259
|
end
|
260
|
+
end
|
180
261
|
|
181
|
-
|
262
|
+
# ========================================================================
|
263
|
+
|
264
|
+
context 'with multiple sort keys and directions' do
|
265
|
+
context 'and via' do
|
182
266
|
before :each do
|
183
|
-
@
|
184
|
-
@
|
185
|
-
@
|
186
|
-
@
|
187
|
-
@
|
267
|
+
@offset = 1000
|
268
|
+
@limit = 500
|
269
|
+
@sort = { 'new_sort' => 'asc', 'another_new_sort' => 'asc' }
|
270
|
+
@search = { 'foo' => 'bar', 'bar' => { 'baz' => 3 } }
|
271
|
+
@filter = { 'bar' => 'foo', 'baz' => { 'bar' => 2 } }
|
272
|
+
|
273
|
+
@replacement_hash = {
|
274
|
+
'offset' => @offset,
|
275
|
+
'limit' => @limit,
|
276
|
+
'sort' => @sort.keys,
|
277
|
+
'direction' => @sort.values,
|
278
|
+
'search' => @search,
|
279
|
+
'filter' => @filter
|
280
|
+
}
|
188
281
|
end
|
189
282
|
|
190
|
-
|
191
|
-
|
283
|
+
context '#to_h' do
|
284
|
+
before :each do
|
285
|
+
@r.list.offset = @offset
|
286
|
+
@r.list.limit = @limit
|
287
|
+
@r.list.sort_data = @sort
|
288
|
+
@r.list.search_data = @search
|
289
|
+
@r.list.filter_data = @filter
|
290
|
+
end
|
192
291
|
|
193
|
-
|
194
|
-
|
292
|
+
it 'returns the expected Hash' do
|
293
|
+
expect( @r.list.to_h ).to eq( @replacement_hash )
|
294
|
+
end
|
195
295
|
|
196
|
-
|
296
|
+
it 'deep-duplicates the parameters' do
|
297
|
+
result = @r.list.to_h()
|
298
|
+
|
299
|
+
old_sort_key = @sort.keys.first
|
300
|
+
result[ 'sort' ][ 0 ] = 'changed'
|
301
|
+
expect( @sort.keys.first ).to eql( old_sort_key )
|
302
|
+
|
303
|
+
old_sort_value = @sort.values.first
|
304
|
+
result[ 'direction' ][ 0 ] = 'changed'
|
305
|
+
expect( @sort.values.first ).to eql( old_sort_value )
|
306
|
+
end
|
307
|
+
end
|
308
|
+
|
309
|
+
context '#from_h!' do
|
310
|
+
it 'overwrites all parameters' do
|
311
|
+
request = Hoodoo::Services::Request.new
|
312
|
+
|
313
|
+
expect( request.list.offset ).to eq( 0 )
|
314
|
+
expect( request.list.limit ).to eq( 50 )
|
315
|
+
expect( request.list.sort_data ).to eq( { 'created_at' => 'desc' } )
|
316
|
+
expect( request.list.search_data ).to eq( {} )
|
317
|
+
expect( request.list.filter_data ).to eq( {} )
|
318
|
+
|
319
|
+
request.list.from_h!( @replacement_hash )
|
320
|
+
|
321
|
+
expect( request.list.offset ).to eq( @offset )
|
322
|
+
expect( request.list.limit ).to eq( @limit )
|
323
|
+
expect( request.list.sort_data ).to eq( @sort )
|
324
|
+
expect( request.list.search_data ).to eq( @search )
|
325
|
+
expect( request.list.filter_data ).to eq( @filter )
|
326
|
+
end
|
327
|
+
|
328
|
+
context 'overwrites only provided parameters' do
|
329
|
+
it 'with single element sort/direction arrays' do
|
330
|
+
test_replacements( {
|
331
|
+
'offset' => @offset,
|
332
|
+
'limit' => @limit,
|
333
|
+
'sort' => [ @sort.keys.first ],
|
334
|
+
'direction' => [ @sort.values.first ],
|
335
|
+
'search_data' => @search,
|
336
|
+
'filter_data' => @filter
|
337
|
+
} )
|
338
|
+
end
|
339
|
+
|
340
|
+
# The default Request object has only one 'sort_data' key-value
|
341
|
+
# pair, so if we tried to replace "one half" of that with more
|
342
|
+
# elements, we should get an exception about mismatched lengths.
|
343
|
+
#
|
344
|
+
context 'with multi-element sort/direction arrays' do
|
345
|
+
it 'and raises an exception if changing sort only' do
|
346
|
+
expect {
|
347
|
+
request = Hoodoo::Services::Request.new
|
348
|
+
request.list.from_h!( { 'sort' => @sort.keys } )
|
349
|
+
}.to raise_error( RuntimeError, 'Hoodoo::Services::Request::ListParameters#from_h!: Sort and direction array lengths must match' )
|
350
|
+
end
|
351
|
+
|
352
|
+
it 'and raises an exception if changing direction only' do
|
353
|
+
expect {
|
354
|
+
request = Hoodoo::Services::Request.new
|
355
|
+
request.list.from_h!( { 'direction' => @sort.keys } )
|
356
|
+
}.to raise_error( RuntimeError, 'Hoodoo::Services::Request::ListParameters#from_h!: Sort and direction array lengths must match' )
|
357
|
+
end
|
358
|
+
|
359
|
+
it 'and works if changing sort and direction' do
|
360
|
+
request = Hoodoo::Services::Request.new
|
361
|
+
request.list.from_h!( { 'sort' => @sort.keys, 'direction' => @sort.values } )
|
362
|
+
expect( request.list.sort_data ).to eql( @sort )
|
363
|
+
end
|
364
|
+
end
|
365
|
+
end
|
197
366
|
end
|
198
367
|
end
|
199
368
|
end
|
200
369
|
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
370
|
+
# ========================================================================
|
371
|
+
|
372
|
+
context '#from_h!' do
|
373
|
+
context 'edge case' do
|
374
|
+
context 'of mismatched sort and direction arrays' do
|
375
|
+
it 'raises an exception' do
|
376
|
+
expect {
|
377
|
+
request = Hoodoo::Services::Request.new
|
378
|
+
request.list.from_h!( { 'sort' => [ '1', '2' ], 'direction' => [ '1', '2', '3' ] } )
|
379
|
+
}.to raise_error( RuntimeError, 'Hoodoo::Services::Request::ListParameters#from_h!: Sort and direction array lengths must match' )
|
380
|
+
|
381
|
+
expect {
|
382
|
+
request = Hoodoo::Services::Request.new
|
383
|
+
request.list.from_h!( { 'sort' => [ '1', '2', '3' ], 'direction' => [ '1', '2' ] } )
|
384
|
+
}.to raise_error( RuntimeError, 'Hoodoo::Services::Request::ListParameters#from_h!: Sort and direction array lengths must match' )
|
385
|
+
end
|
386
|
+
end
|
208
387
|
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
388
|
+
context 'of nil sort keys and directions' do
|
389
|
+
it 'works if the arrays still match' do
|
390
|
+
request = Hoodoo::Services::Request.new
|
391
|
+
request.list.from_h!( { 'sort' => [ '1', nil, '2' ], 'direction' => [ '1', '2', nil ] } )
|
392
|
+
expect( request.list.sort_data ).to eql( { '1' => '1', '2' => '2' } )
|
393
|
+
end
|
214
394
|
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
395
|
+
it 'raises an exception if the arrays then mismatch' do
|
396
|
+
expect {
|
397
|
+
request = Hoodoo::Services::Request.new
|
398
|
+
request.list.from_h!( { 'sort' => [ '1', '2', '3' ], 'direction' => [ '1', '2', nil ] } )
|
399
|
+
}.to raise_error( RuntimeError, 'Hoodoo::Services::Request::ListParameters#from_h!: Sort and direction array lengths must match' )
|
400
|
+
end
|
401
|
+
end
|
402
|
+
end
|
220
403
|
end
|
221
|
-
|
222
|
-
end
|
404
|
+
|
405
|
+
end # "context '#list' do"
|
406
|
+
end # "describe Hoodoo::Services::Request do"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hoodoo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.5.
|
4
|
+
version: 2.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Loyalty New Zealand
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-05-
|
11
|
+
date: 2018-05-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dalli
|