jsonapi-resources-matchers 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 93bdae4ac60db2a61069a9fa95f46cdc5f74ae3a
4
- data.tar.gz: b562aaabdb09a5b417e8d71d4637545035322075
3
+ metadata.gz: ffdc3c34e07d0eba98540f569af585f9a65ae833
4
+ data.tar.gz: 76b8c6029107278b4f739182c42ac19c5c9426ef
5
5
  SHA512:
6
- metadata.gz: b7dc61e1d5ce3904fe96e66ce3ee6fc2b9d27f6874e9ee1ba2e30490417ec0b36db1fbc672bc6b7025af45fc41cef7648a848f4c070eb4ee9f4df306940ee08e
7
- data.tar.gz: 57af4617abbe0a7d979136295ce6a1de03e5cc67f249ce2abee32378b9b5156ae5bce36e521113b5dd5296ae2a4a2d39c5b1285574aa83d794aaa8849a16feee
6
+ metadata.gz: 060978fd5389c6cf06d79085df92ed2e4a731d8407b2e12b9cf0bb41b726701240f3bed4ff1064f08ad6c92bc07023eb5fc08e5a336b192f852f790d70d938f3
7
+ data.tar.gz: 4eb50049fd4a9e07d2d5fe75493e410208e0c5e40f2b96e764ef41cff058350947f586ac5592b0abb3eb8cfd34ee727457bec4b92d633bc620e13ccfd78b6591
data/CHANGELOG.md CHANGED
@@ -2,6 +2,10 @@
2
2
  All notable changes to this project will be documented in this file.
3
3
  This project adheres to [Semantic Versioning](http://semver.org/).
4
4
 
5
+ ## [0.5.0] - 2016-11-24
6
+ ### Added
7
+ - support for `have_creatable_field` and `have_updatable_field`
8
+
5
9
  ## [0.4.0]
6
10
  ### Changed
7
11
  - Update jsonapi-resources dependency to `>= 0.6.0`
data/README.md CHANGED
@@ -9,7 +9,7 @@ Currently, only RSpec matchers exist.
9
9
  Add this line to your application's Gemfile (in a `test` group):
10
10
 
11
11
  ```ruby
12
- gem 'jsonapi-resources-matchers'
12
+ gem 'jsonapi-resources-matchers', require: false
13
13
  ```
14
14
 
15
15
  And then execute:
@@ -20,6 +20,12 @@ Or install it yourself as:
20
20
 
21
21
  $ gem install jsonapi-resources-matchers
22
22
 
23
+ Require the gem in your `spec/spec_helper`:
24
+
25
+ ```ruby
26
+ require 'jsonapi-resources-matchers'
27
+ ```
28
+
23
29
  ## Usage
24
30
 
25
31
  Anything with a `type` of `resource` will have the matchers automatically included.
@@ -1,5 +1,7 @@
1
1
  require "jsonapi/resources/matchers/version"
2
2
  require "jsonapi/resources/matchers/have_attribute"
3
+ require "jsonapi/resources/matchers/have_creatable_field"
4
+ require "jsonapi/resources/matchers/have_updatable_field"
3
5
  require "jsonapi/resources/matchers/filter"
4
6
  require "jsonapi/resources/matchers/relationship"
5
7
  require "jsonapi/resources/matchers/have_model_name"
@@ -9,6 +11,14 @@ module JSONAPI
9
11
  module Resources
10
12
  module Matchers
11
13
 
14
+ def have_creatable_field(name)
15
+ HaveCreatableField.new(name)
16
+ end
17
+
18
+ def have_updatable_field(name)
19
+ HaveUpdatableField.new(name)
20
+ end
21
+
12
22
  def have_attribute(name)
13
23
  HaveAttribute.new(name)
14
24
  end
@@ -0,0 +1,34 @@
1
+ module JSONAPI
2
+ module Resources
3
+ module Matchers
4
+ class HaveCreatableField
5
+
6
+ attr_accessor :name, :resource
7
+
8
+ def initialize(name)
9
+ self.name = name
10
+ end
11
+
12
+ def matches?(resource)
13
+ self.resource = resource
14
+ resource.class.creatable_fields(resource.context).include?(name)
15
+ end
16
+
17
+ def failure_message
18
+ resource_name = resource.class.name.demodulize
19
+ %Q(expected #{resource_name} to have creatable field `#{name}`)
20
+ end
21
+
22
+ def failure_message_when_negated
23
+ resource_name = resource.class.name.demodulize
24
+ %Q(expected #{resource_name} not to have creatable field `#{name}`)
25
+ end
26
+
27
+ def description
28
+ "have creatable field `#{name}`"
29
+ end
30
+
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,34 @@
1
+ module JSONAPI
2
+ module Resources
3
+ module Matchers
4
+ class HaveUpdatableField
5
+
6
+ attr_accessor :name, :resource
7
+
8
+ def initialize(name)
9
+ self.name = name
10
+ end
11
+
12
+ def matches?(resource)
13
+ self.resource = resource
14
+ resource.class.updatable_fields(resource.context).include?(name)
15
+ end
16
+
17
+ def failure_message
18
+ resource_name = resource.class.name.demodulize
19
+ %Q(expected #{resource_name} to have updatable field `#{name}`)
20
+ end
21
+
22
+ def failure_message_when_negated
23
+ resource_name = resource.class.name.demodulize
24
+ %Q(expected #{resource_name} not to have updatable field `#{name}`)
25
+ end
26
+
27
+ def description
28
+ "have updatable field `#{name}`"
29
+ end
30
+
31
+ end
32
+ end
33
+ end
34
+ end
@@ -1,7 +1,7 @@
1
1
  module JSONAPI
2
2
  module Resources
3
3
  module Matchers
4
- VERSION = "0.4.0"
4
+ VERSION = "0.5.0"
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jsonapi-resources-matchers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - G5
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2016-10-13 00:00:00.000000000 Z
12
+ date: 2016-11-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: jsonapi-resources
@@ -105,8 +105,10 @@ files:
105
105
  - lib/jsonapi/resources/matchers.rb
106
106
  - lib/jsonapi/resources/matchers/filter.rb
107
107
  - lib/jsonapi/resources/matchers/have_attribute.rb
108
+ - lib/jsonapi/resources/matchers/have_creatable_field.rb
108
109
  - lib/jsonapi/resources/matchers/have_model_name.rb
109
110
  - lib/jsonapi/resources/matchers/have_primary_key.rb
111
+ - lib/jsonapi/resources/matchers/have_updatable_field.rb
110
112
  - lib/jsonapi/resources/matchers/integrations/rspec.rb
111
113
  - lib/jsonapi/resources/matchers/relationship.rb
112
114
  - lib/jsonapi/resources/matchers/version.rb
@@ -136,4 +138,3 @@ signing_key:
136
138
  specification_version: 4
137
139
  summary: Spec matchers for jsonapi-resources
138
140
  test_files: []
139
- has_rdoc: