Module: SmartRspec::Support::Controller::Response
- Included in:
- Matchers::JsonApiMatchers
- Defined in:
- lib/smart_rspec/support/controller/response.rb
Instance Method Summary collapse
- #check_keys_in(member, keys) ⇒ Object
- #collection ⇒ Object
- #error ⇒ Object
- #included_data ⇒ Object
- #json(response) ⇒ Object
- #meta_record_count ⇒ Object
- #relationship_data ⇒ Object
Instance Method Details
#check_keys_in(member, keys) ⇒ Object
39 40 41 42 43 |
# File 'lib/smart_rspec/support/controller/response.rb', line 39 def check_keys_in(member, keys) collection.all? do |record| record[member].keys.sort == keys.sort end end |
#collection ⇒ Object
16 17 18 |
# File 'lib/smart_rspec/support/controller/response.rb', line 16 def collection @collection ||= [@json['data']].flatten end |
#error ⇒ Object
12 13 14 |
# File 'lib/smart_rspec/support/controller/response.rb', line 12 def error @error ||= @json['errors'].first end |
#included_data ⇒ Object
32 33 34 35 36 37 |
# File 'lib/smart_rspec/support/controller/response.rb', line 32 def included_data return [] if @json['included'].nil? @included_data ||= @json['included'].flat_map do |record| record.slice('type', 'id') end end |
#json(response) ⇒ Object
7 8 9 10 |
# File 'lib/smart_rspec/support/controller/response.rb', line 7 def json(response) @json ||= JSON.parse(response.body) self end |
#meta_record_count ⇒ Object
20 21 22 |
# File 'lib/smart_rspec/support/controller/response.rb', line 20 def @json['meta']['record_count'] end |
#relationship_data ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/smart_rspec/support/controller/response.rb', line 24 def relationship_data @relationship_data ||= collection.flat_map do |record| record['relationships'].flat_map do |_, relation| [relation['data']].flatten.map { |data| data.slice('type', 'id') } end.compact end end |