File tree Expand file tree Collapse file tree
spec/rspec/json_api/matchers Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11PATH
22 remote: .
33 specs:
4- rspec-json_api (1.2.1 )
4+ rspec-json_api (1.2.2 )
55 activesupport (>= 6.1.4.1 )
66 rails (>= 6.1.4.1 )
77 rspec-rails (>= 5.0.2 )
Original file line number Diff line number Diff line change 1+ # frozen_string_literal: true
2+
3+ class Array
4+ def deep_sort
5+ map { |element | element . is_a? ( Array ) ? element . deep_sort : element }
6+ . sort_by { |el | el . is_a? ( Array ) ? el . first . to_s : el . to_s }
7+ end
8+ end
Original file line number Diff line number Diff line change 1111
1212# Load extentions
1313require "extentions/hash"
14+ require "extentions/array"
1415
1516# Load matchers
1617require "rspec/json_api/matchers"
Original file line number Diff line number Diff line change @@ -21,7 +21,7 @@ def matches?(actual)
2121 RSpec ::JsonApi ::CompareArray . compare ( actual , expected )
2222 else
2323 # Compare actual and expected schema
24- return false unless actual . deep_keys == expected . deep_keys
24+ return false unless actual . deep_keys . deep_sort == expected . deep_keys . deep_sort
2525
2626 RSpec ::JsonApi ::CompareHash . compare ( actual , expected )
2727 end
Original file line number Diff line number Diff line change 22
33module RSpec
44 module JsonApi
5- VERSION = "1.2.1 "
5+ VERSION = "1.2.2 "
66 end
77end
Original file line number Diff line number Diff line change 217217 end
218218 end
219219
220+ context 'when keys are in arbitrary order' do
221+ let ( :expected ) do
222+ {
223+ id : "8eccff73-f134-42f2-aed4-751d1f4ebd4f" ,
224+ name : "Caroline Mayer" ,
225+ age : 25 ,
226+ children : [
227+ {
228+ id : "8eccff73-f134-42f2-aed4-751d1f4ebd4a" ,
229+ name : "Webster Medina" ,
230+ age : 2
231+ } ,
232+ {
233+ id : "8eccff73-f134-42f2-aed4-751d1f4ebd4b" ,
234+ name : "Roy Mcdaniel" ,
235+ age : 3
236+ }
237+ ]
238+ }
239+ end
240+
241+ context "when correct match" do
242+ let ( :actual ) do
243+ {
244+ name : "Caroline Mayer" ,
245+ age : 25 ,
246+ id : "8eccff73-f134-42f2-aed4-751d1f4ebd4f" ,
247+ children : [
248+ {
249+ name : "Webster Medina" ,
250+ age : 2 ,
251+ id : "8eccff73-f134-42f2-aed4-751d1f4ebd4a" ,
252+ } ,
253+ {
254+ id : "8eccff73-f134-42f2-aed4-751d1f4ebd4b" ,
255+ name : "Roy Mcdaniel" ,
256+ age : 3
257+ }
258+ ]
259+ } . to_json
260+ end
261+
262+ include_examples "correct-match"
263+ end
264+ end
265+
220266 context "when data typed given" do
221267 let ( :expected ) do
222268 {
You can’t perform that action at this time.
0 commit comments