json_api_test_helpers 1.0 → 1.0.1

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
  SHA256:
3
- metadata.gz: ade3817a7474126aa64befde944275678fa8c6f3fc55112f53fbfb170759fa17
4
- data.tar.gz: c3cc5078d775403db8d0a19497d4718020f06b293fcec16978c6312fb9c5a0e7
3
+ metadata.gz: c70ab02800ebe7be08cef8201ac03e03bd8422abf8ce965d016afd084621ec5f
4
+ data.tar.gz: 836fd219786c8b7fe4c5b778c7f582e3e641b61730cb467b23bcd8d516ca3921
5
5
  SHA512:
6
- metadata.gz: 7d637f5b56d3066650ad3a8453673508d870cd1d9c564b2635dd05ece65cef86606cdf049858dc7e7c4e84695ef3e647f54cfafdfb73e913c4f58e0c7012e077
7
- data.tar.gz: 8f9d572686ac8cde3d8bbfebf4ce8d79c579439ab16b3409344f2270afbf3a62054229f112205c16d9aef03b04e2485333adb0e8e19728b8a76bd36723002f81
6
+ metadata.gz: c2c5577d47c9db9e0058ad95a385891f3603253b4331bbf15cdd253d365b5537bf9b66480279255395185d43c7ce13f7534c3fc432f4d7ad8d5cebbca8fa9951
7
+ data.tar.gz: 9367aa3f8a13efdb25ad91038fc116899a2c6a3c793dc2ec5bcc12d004cb16aa37da4c76af39871ab8db399c60ad0402ce3aca4ee8374252a011a2d118d0f82a
data/.gitignore CHANGED
@@ -1,11 +1,8 @@
1
- /.bundle/
2
- /.yardoc
3
- /_yardoc/
4
- /coverage/
5
- /doc/
6
- /pkg/
7
- /spec/reports/
8
- /tmp/
9
-
10
- # rspec failure tracking
11
- .rspec_status
1
+ .bundle/
2
+ log/*.log
3
+ pkg/
4
+ /**/spec/dummy/log/*.log
5
+ /**/spec/dummy/tmp/
6
+ /**/spec/dummy/test/
7
+ *.gem
8
+ /**/Gemfile.lock
data/README.md CHANGED
@@ -1,8 +1,6 @@
1
1
  # JsonApiTestHelpers
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/json_api_test_helpers`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
3
+ Collection of helper methods to easy testing of JSON API https://jsonapi.org/ responses
6
4
 
7
5
  ## Installation
8
6
 
@@ -22,7 +20,26 @@ Or install it yourself as:
22
20
 
23
21
  ## Usage
24
22
 
25
- TODO: Write usage instructions here
23
+ Methods:
24
+
25
+ | Methods | Params | Description |
26
+ |---------------|---------|-------------------------------------------------------------------------|
27
+ | json_response | | Returns parsed `response.body` as Hash with indifferent access or Array |
28
+ | json_api_record | `record`, `attributes`, `relationships: nil`, `additional: nil`| Returns Hash in JSON API format with serialized object |
29
+ | json_api_collection | `collection`, `attributes = nil`, `relationships: nil` | Returns Hash in JSON API format with serialized array |
30
+ | fix_value_for_json | `value` | Fix values which are usually used in Rails apps. `DateTime`, `ActiveSupport::TimeWithZone` to `iso8601`; `CarrierWave::Uploader::Serialization` to `serializable_hash`; everything else to Hash with replaced underscores `_` to minus `-` in attribute names |
31
+ | fix_comparing_types | `value` | Fix type value to easy compare. `DateTime`, `ActiveSupport::TimeWithZone` to `datetime` with UTC; `ActiveRecord::Point` to string `"#{value.x}, #{value.y}"`. |
32
+ | attributes_for_nested | `attributes`, `**associations` | Merge `attributes` with associations with JSON API format |
33
+
34
+ ## Examples
35
+
36
+ ```ruby
37
+ expect(json_response).to include_json(json_api_record(User.first))
38
+
39
+ expect(json_response).to include_json(json_api_collection(User.all))
40
+
41
+ expect(json_response).to include_json(json_api
42
+ ```
26
43
 
27
44
  ## Development
28
45
 
@@ -2,8 +2,12 @@ require 'json_api_test_helpers/version'
2
2
 
3
3
  module JsonApiTestHelpers
4
4
  def json_response
5
- parsed_json = JSON.parse response.body
6
- parsed_json.with_indifferent_access unless parsed_json.is_a? Array
5
+ if response.body.present?
6
+ parsed_json = JSON.parse response.body
7
+ parsed_json.with_indifferent_access unless parsed_json.is_a? Array
8
+ else
9
+ raise 'Response body is empty'
10
+ end
7
11
  end
8
12
 
9
13
  def json_api_record(record, attributes, relationships: nil, additional: nil)
@@ -1,3 +1,3 @@
1
1
  module JsonApiTestHelpers
2
- VERSION = '1.0'
2
+ VERSION = '1.0.1'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json_api_test_helpers
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.0'
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pavel Kalashnikov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-05-17 00:00:00.000000000 Z
11
+ date: 2019-05-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler