jsonapi_rspec 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8409f6d1d66e1c807057ae55f76b8fcbd2d22383
4
- data.tar.gz: 94cf34c0cb18fdbd4b8c7ec1a3d90beb751da926
3
+ metadata.gz: 51b4c3c8b180371728a5009b411cda7f77e2abe6
4
+ data.tar.gz: 258bf4d2d722df6b7c821d4d9aafd0d60f7261f2
5
5
  SHA512:
6
- metadata.gz: 717a0dea8650593f11055f37b483bb53f4d57c516024cddce6ff344517d145b9aa78437479db856d46772a55c3cb6b30c5b88eba7b7dee6c43b0fbad485959a9
7
- data.tar.gz: fef72061c50a0bb8f9f622e871015627f625125265621e14bb037d41070774c41ab49050e57ab06c85b4f8afb0ff1fc2596dc37d6838d0979a88b2f9bc5b94fb
6
+ metadata.gz: 9ad0236147e56ee872977834fc829c04bbe5e20442d06c1da8abb2164e1a2a0a9467f4d425bd7cfd3827949156d247cdd334eafef56389c7bede2543a88c9cc2
7
+ data.tar.gz: 0db6c4e02dc98702339c10cf7a28f6b247057c63332922d15b553770f98034527903cf08434ae3650c2d660646073dedba3894d21cd5a394af12588ca2742805
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- jsonapi_rspec (0.1.0)
4
+ jsonapi_rspec (0.2.0)
5
5
  activesupport (>= 4.2.8)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -1,12 +1,13 @@
1
1
  # JsonapiRspec
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/jsonapi_rspec.svg)](https://badge.fury.io/rb/jsonapi_rspec)
3
4
  [![Build Status](https://travis-ci.org/midwire/jsonapi_rspec.svg?branch=master)](https://travis-ci.org/midwire/jsonapi_rspec)
4
5
 
5
6
  Match json:api formatted Rack::Response (or Rails controller response) to an instantiated object or ActiveRecord/ActiveModel object.
6
7
 
7
- This project started because I wanted to be able to easily compare a json:api response to a model in my Rails API controllers, across several projects. Finding myself copying the code between projects, I decided to stick it all in a gem.
8
+ This project started because I wanted to be able to easily compare a json:api response to a model in my Rails API controllers, across several projects. Finding myself copying the code between projects, I decided to put it all in a gem.
8
9
 
9
- As such, it may not strictly suit your needs, but if you let me know I'll do my best to accommodate.
10
+ As such, it may not strictly suit your needs, but if you let me know I'll do my best to accommodate, and [pull requests](https://github.com/midwire/jsonapi_rspec/pulls) are always welcome.
10
11
 
11
12
  ## Installation
12
13
 
@@ -33,7 +34,7 @@ expect(response).to be_jsonapi_response_for(my_model)
33
34
  ```
34
35
 
35
36
  It currently tests for required json:api sections and matching attributes for the passed model instance.
36
- ```json
37
+ ```
37
38
  {
38
39
  "jsonapi": "version 1.1", // does not check
39
40
  "data":{ // checks if exists and is a hash
@@ -75,19 +76,19 @@ It currently tests for required json:api sections and matching attributes for th
75
76
 
76
77
  ### Possible Failure Messages
77
78
 
78
- * 'Response is an error'
79
- * "Unexpected key in response: '#{key}'"
80
- * 'Expected response to match an object instance but it is an empty string'
81
- * "The 'data' section is missing or invalid"
79
+ * "Attribute: :#{attr_name} with a value of '#{json_val}'(#{json_val.class.name}) does not match object: '#{obj_val}'(#{obj_val.class.name})
80
+ * "Expected '#{value}' to match object id: '#{object_id}'"
82
81
  * "Expected data:type '#{data_type}' to match: '#{object_type}'"
82
+ * "Fix 'match_attribute?' method to handle: '#{obj_val_class_name}'" - [please file an issue](https://github.com/midwire/jsonapi_rspec/issues/new) if you get this one.
83
+ * "The 'data' section is missing or invalid"
83
84
  * "The 'meta' section is missing or invalid"
84
- * "The 'meta:version' is missing"
85
85
  * "The 'meta:copyright' is missing or invalid - regex: '/^Copyright.+\\d{4}/'"
86
- * "Fix 'match_attribute?' method to handle: '#{obj_val_class_name}'" - please file an issue if you get this one.
87
- * "Attribute: :#{attr_name} with a value of '#{json_val}'(#{json_val.class.name}) does not match object: '#{obj_val}'(#{obj_val.class.name})
88
- * "Expected '#{value}' to match object id: '#{object_id}'"
86
+ * "The 'meta:version' is missing"
87
+ * "Unexpected key in response: '#{key}'"
88
+ * 'Expected response to match an object instance but it is an empty string'
89
+ * 'Response is an error'
89
90
 
90
- See the specs for details.
91
+ [See the specs](https://github.com/midwire/jsonapi_rspec/blob/develop/spec/lib/jsonapi_rspec/be_json_api_response_for_spec.rb) for more details.
91
92
 
92
93
  ### Configuration
93
94
 
@@ -14,8 +14,9 @@ require 'active_support/all'
14
14
  # @author Chris Blackburn <87a1779b@opayq.com>
15
15
  #
16
16
  class BeJsonApiResponseFor
17
- def initialize(object_instance)
17
+ def initialize(object_instance, plural_form = nil)
18
18
  @object_instance = object_instance
19
+ @plural_form = plural_form
19
20
  end
20
21
 
21
22
  def matches?(response)
@@ -91,7 +92,8 @@ class BeJsonApiResponseFor
91
92
  end
92
93
 
93
94
  def valid_type?(data_type)
94
- object_type = @object_instance.class.name.underscore.dasherize.pluralize
95
+ object_type = @plural_form ||
96
+ @object_instance.class.name.pluralize.underscore.dasherize
95
97
  unless data_type == object_type
96
98
  return set_failure_message("Expected data:type '#{data_type}' to match: '#{object_type}'")
97
99
  end
@@ -173,9 +175,9 @@ end
173
175
  # Usage:
174
176
  # expect(response).to be_jsonapi_response_for(object_instance)
175
177
  #
176
- RSpec::Matchers.define :be_jsonapi_response_for do |object|
178
+ RSpec::Matchers.define :be_jsonapi_response_for do |object, plural_form|
177
179
  match do |actual_response|
178
- @instance = BeJsonApiResponseFor.new(object)
180
+ @instance = BeJsonApiResponseFor.new(object, plural_form)
179
181
 
180
182
  def failure_message
181
183
  @instance.failure_message
@@ -1,3 +1,3 @@
1
1
  module JsonapiRspec
2
- VERSION = '0.1.0'.freeze
2
+ VERSION = '0.2.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jsonapi_rspec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Blackburn
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-10-17 00:00:00.000000000 Z
11
+ date: 2017-10-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler