json_api_toolbox 1.5.1 → 2.0.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
  SHA256:
3
- metadata.gz: 2bd96792ca86fca2089b5b5f5e837b0d5555e9d8ad549d17f4d2697034288c8c
4
- data.tar.gz: be654d88ed537bae350035da7ef869a50dbde04271e491b693815398e3fdfb3a
3
+ metadata.gz: fc9706da38e740273930904f1f8c2921fa7172ac47f73a1f4130683c5774c624
4
+ data.tar.gz: dd5b01dfad5c434d8b569769ad6149da78e317aaa8bb3f58102e1eb53b8f4630
5
5
  SHA512:
6
- metadata.gz: 2a6b0f774066482fe66821665f9a39cdb55e7f345b765fe1ad7c131994595a2c98fdc8853b0b3314f0e317a450babb944cc1052c92caaaa6405e8710eb86c86e
7
- data.tar.gz: 4ab8137ebee0a96c5ee2680b1725a206632d31b69281e0d86be0f4fea7596331a60ef3ea243d7e536781ed1088bb5c489735deef75871c67846f02c87cf88d7b
6
+ metadata.gz: 91111bdba8cbe7562eb92f1b73172fbefbf062c501e298546ff6a795573e585ee3e53dfcafeee86a78631735f8b5f8935d5f9f11e499f3a7f8e64de60425b399
7
+ data.tar.gz: 11a64750e2c53a541e9df20bce0032d122352bfacbf976500ebb22c1c8a2f949a9f93ee50570bb7dcf99dc905382b348c5e6089f9d5e3ac13fdb26c141499873
data/.gitignore CHANGED
@@ -1,6 +1,5 @@
1
1
  /.bundle/
2
2
  /.yardoc
3
- /Gemfile.lock
4
3
  /_yardoc/
5
4
  /coverage/
6
5
  /doc/
@@ -10,3 +9,5 @@
10
9
 
11
10
  # rspec failure tracking
12
11
  .rspec_status
12
+
13
+ .rubocop.base.yml
data/.rubocop.yml ADDED
@@ -0,0 +1,6 @@
1
+ inherit_from:
2
+ - '.rubocop.base.yml'
3
+
4
+ AllCops:
5
+ TargetRubyVersion: 2.6
6
+ SuggestExtensions: false
data/CHANGELOG.md CHANGED
@@ -5,7 +5,24 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
5
5
  and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
6
6
 
7
7
  ## [Unreleased]
8
+
9
+ ## [2.0.0] - 2021-06-23
8
10
  ### Added
11
+ - New README file describing the gem and it's uses
12
+ - Added support for default rubocop config
13
+ - New setup script
14
+ - Added docker to run rubocop and rspec
15
+
16
+ ### Changed
17
+ - New 2.0 branch! With better support for semver and ruby updates
18
+ - Moved the rspec examples file for easier manual import
19
+ - Updated all dependencies
20
+ - Moved some dependencies into development dependencies
21
+
22
+ ### Removed
23
+ - Removed support for ruby 2.5 series
24
+ - Removed unneeded files (old CI files, ruby version lock, etc…)
25
+ - Removed auto import for rspec examples. It now need to be added manually on `rails_helper.rb`
9
26
 
10
27
  ## [Released]
11
28
 
data/Dockerfile ADDED
@@ -0,0 +1,18 @@
1
+ FROM ruby:2.6-alpine
2
+
3
+ RUN apk update \
4
+ && apk upgrade \
5
+ && apk add --update \
6
+ git \
7
+ openssh \
8
+ build-base \
9
+ && rm -rf /var/cache/apk/*
10
+
11
+ RUN gem update --system
12
+
13
+ WORKDIR /gem
14
+ COPY . .
15
+
16
+ ENTRYPOINT ["sh", "docker-entrypoint.sh"]
17
+
18
+ CMD ["rake", "lint-and-test"]
data/Gemfile.lock ADDED
@@ -0,0 +1,237 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ json_api_toolbox (2.0.0)
5
+ activerecord (>= 5.1.0)
6
+ activesupport (>= 5.1.0)
7
+ json-api-vanilla
8
+ jsonapi-serializable
9
+ log_toolbox
10
+ request_store
11
+ rest-client
12
+ will_paginate
13
+
14
+ GEM
15
+ remote: https://rubygems.org/
16
+ specs:
17
+ actioncable (6.1.4)
18
+ actionpack (= 6.1.4)
19
+ activesupport (= 6.1.4)
20
+ nio4r (~> 2.0)
21
+ websocket-driver (>= 0.6.1)
22
+ actionmailbox (6.1.4)
23
+ actionpack (= 6.1.4)
24
+ activejob (= 6.1.4)
25
+ activerecord (= 6.1.4)
26
+ activestorage (= 6.1.4)
27
+ activesupport (= 6.1.4)
28
+ mail (>= 2.7.1)
29
+ actionmailer (6.1.4)
30
+ actionpack (= 6.1.4)
31
+ actionview (= 6.1.4)
32
+ activejob (= 6.1.4)
33
+ activesupport (= 6.1.4)
34
+ mail (~> 2.5, >= 2.5.4)
35
+ rails-dom-testing (~> 2.0)
36
+ actionpack (6.1.4)
37
+ actionview (= 6.1.4)
38
+ activesupport (= 6.1.4)
39
+ rack (~> 2.0, >= 2.0.9)
40
+ rack-test (>= 0.6.3)
41
+ rails-dom-testing (~> 2.0)
42
+ rails-html-sanitizer (~> 1.0, >= 1.2.0)
43
+ actiontext (6.1.4)
44
+ actionpack (= 6.1.4)
45
+ activerecord (= 6.1.4)
46
+ activestorage (= 6.1.4)
47
+ activesupport (= 6.1.4)
48
+ nokogiri (>= 1.8.5)
49
+ actionview (6.1.4)
50
+ activesupport (= 6.1.4)
51
+ builder (~> 3.1)
52
+ erubi (~> 1.4)
53
+ rails-dom-testing (~> 2.0)
54
+ rails-html-sanitizer (~> 1.1, >= 1.2.0)
55
+ activejob (6.1.4)
56
+ activesupport (= 6.1.4)
57
+ globalid (>= 0.3.6)
58
+ activemodel (6.1.4)
59
+ activesupport (= 6.1.4)
60
+ activerecord (6.1.4)
61
+ activemodel (= 6.1.4)
62
+ activesupport (= 6.1.4)
63
+ activestorage (6.1.4)
64
+ actionpack (= 6.1.4)
65
+ activejob (= 6.1.4)
66
+ activerecord (= 6.1.4)
67
+ activesupport (= 6.1.4)
68
+ marcel (~> 1.0.0)
69
+ mini_mime (>= 1.1.0)
70
+ activesupport (6.1.4)
71
+ concurrent-ruby (~> 1.0, >= 1.0.2)
72
+ i18n (>= 1.6, < 2)
73
+ minitest (>= 5.1)
74
+ tzinfo (~> 2.0)
75
+ zeitwerk (~> 2.3)
76
+ ast (2.4.2)
77
+ builder (3.2.4)
78
+ byebug (11.1.3)
79
+ coderay (1.1.3)
80
+ concurrent-ruby (1.1.9)
81
+ crass (1.0.6)
82
+ diff-lcs (1.4.4)
83
+ domain_name (0.5.20190701)
84
+ unf (>= 0.0.5, < 1.0.0)
85
+ erubi (1.10.0)
86
+ globalid (0.4.2)
87
+ activesupport (>= 4.2.0)
88
+ http-accept (1.7.0)
89
+ http-cookie (1.0.4)
90
+ domain_name (~> 0.5)
91
+ i18n (1.8.10)
92
+ concurrent-ruby (~> 1.0)
93
+ json-api-vanilla (1.0.2)
94
+ jsonapi-renderer (0.2.2)
95
+ jsonapi-serializable (0.3.1)
96
+ jsonapi-renderer (~> 0.2.0)
97
+ log_toolbox (1.3.11)
98
+ lograge (>= 0.11.1)
99
+ logstash-event (>= 1.2.02)
100
+ logstash-logger (>= 0.26.1)
101
+ rails (>= 5.0)
102
+ lograge (0.11.2)
103
+ actionpack (>= 4)
104
+ activesupport (>= 4)
105
+ railties (>= 4)
106
+ request_store (~> 1.0)
107
+ logstash-event (1.2.02)
108
+ logstash-logger (0.26.1)
109
+ logstash-event (~> 1.2)
110
+ loofah (2.10.0)
111
+ crass (~> 1.0.2)
112
+ nokogiri (>= 1.5.9)
113
+ mail (2.7.1)
114
+ mini_mime (>= 0.1.1)
115
+ marcel (1.0.1)
116
+ method_source (1.0.0)
117
+ mime-types (3.3.1)
118
+ mime-types-data (~> 3.2015)
119
+ mime-types-data (3.2021.0704)
120
+ mini_mime (1.1.0)
121
+ minitest (5.14.4)
122
+ netrc (0.11.0)
123
+ nio4r (2.5.7)
124
+ nokogiri (1.11.7-x86_64-linux)
125
+ racc (~> 1.4)
126
+ parallel (1.20.1)
127
+ parser (3.0.1.1)
128
+ ast (~> 2.4.1)
129
+ pry (0.13.1)
130
+ coderay (~> 1.1)
131
+ method_source (~> 1.0)
132
+ pry-byebug (3.9.0)
133
+ byebug (~> 11.0)
134
+ pry (~> 0.13.0)
135
+ racc (1.5.2)
136
+ rack (2.2.3)
137
+ rack-test (1.1.0)
138
+ rack (>= 1.0, < 3)
139
+ rails (6.1.4)
140
+ actioncable (= 6.1.4)
141
+ actionmailbox (= 6.1.4)
142
+ actionmailer (= 6.1.4)
143
+ actionpack (= 6.1.4)
144
+ actiontext (= 6.1.4)
145
+ actionview (= 6.1.4)
146
+ activejob (= 6.1.4)
147
+ activemodel (= 6.1.4)
148
+ activerecord (= 6.1.4)
149
+ activestorage (= 6.1.4)
150
+ activesupport (= 6.1.4)
151
+ bundler (>= 1.15.0)
152
+ railties (= 6.1.4)
153
+ sprockets-rails (>= 2.0.0)
154
+ rails-dom-testing (2.0.3)
155
+ activesupport (>= 4.2.0)
156
+ nokogiri (>= 1.6)
157
+ rails-html-sanitizer (1.3.0)
158
+ loofah (~> 2.3)
159
+ railties (6.1.4)
160
+ actionpack (= 6.1.4)
161
+ activesupport (= 6.1.4)
162
+ method_source
163
+ rake (>= 0.13)
164
+ thor (~> 1.0)
165
+ rainbow (3.0.0)
166
+ rake (13.0.4)
167
+ regexp_parser (2.1.1)
168
+ request_store (1.5.0)
169
+ rack (>= 1.4)
170
+ rest-client (2.1.0)
171
+ http-accept (>= 1.7.0, < 2.0)
172
+ http-cookie (>= 1.0.2, < 2.0)
173
+ mime-types (>= 1.16, < 4.0)
174
+ netrc (~> 0.8)
175
+ rexml (3.2.5)
176
+ rspec (3.10.0)
177
+ rspec-core (~> 3.10.0)
178
+ rspec-expectations (~> 3.10.0)
179
+ rspec-mocks (~> 3.10.0)
180
+ rspec-core (3.10.1)
181
+ rspec-support (~> 3.10.0)
182
+ rspec-expectations (3.10.1)
183
+ diff-lcs (>= 1.2.0, < 2.0)
184
+ rspec-support (~> 3.10.0)
185
+ rspec-mocks (3.10.2)
186
+ diff-lcs (>= 1.2.0, < 2.0)
187
+ rspec-support (~> 3.10.0)
188
+ rspec-support (3.10.2)
189
+ rubocop (1.18.3)
190
+ parallel (~> 1.10)
191
+ parser (>= 3.0.0.0)
192
+ rainbow (>= 2.2.2, < 4.0)
193
+ regexp_parser (>= 1.8, < 3.0)
194
+ rexml
195
+ rubocop-ast (>= 1.7.0, < 2.0)
196
+ ruby-progressbar (~> 1.7)
197
+ unicode-display_width (>= 1.4.0, < 3.0)
198
+ rubocop-ast (1.7.0)
199
+ parser (>= 3.0.1.1)
200
+ ruby-progressbar (1.11.0)
201
+ shoulda-matchers (4.5.1)
202
+ activesupport (>= 4.2.0)
203
+ sprockets (4.0.2)
204
+ concurrent-ruby (~> 1.0)
205
+ rack (> 1, < 3)
206
+ sprockets-rails (3.2.2)
207
+ actionpack (>= 4.0)
208
+ activesupport (>= 4.0)
209
+ sprockets (>= 3.0.0)
210
+ thor (1.1.0)
211
+ tzinfo (2.0.4)
212
+ concurrent-ruby (~> 1.0)
213
+ unf (0.1.4)
214
+ unf_ext
215
+ unf_ext (0.0.7.7)
216
+ unicode-display_width (2.0.0)
217
+ websocket-driver (0.7.5)
218
+ websocket-extensions (>= 0.1.0)
219
+ websocket-extensions (0.1.5)
220
+ will_paginate (3.3.0)
221
+ zeitwerk (2.4.2)
222
+
223
+ PLATFORMS
224
+ x86_64-darwin-20
225
+ x86_64-linux
226
+
227
+ DEPENDENCIES
228
+ bundler
229
+ json_api_toolbox!
230
+ pry-byebug
231
+ rake
232
+ rspec
233
+ rubocop
234
+ shoulda-matchers
235
+
236
+ BUNDLED WITH
237
+ 2.2.22
data/README.md CHANGED
@@ -1,42 +1,32 @@
1
1
  # JsonApiToolbox
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_toolbox`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ This toolbox serve as a JSON API helper within Guide TI specs
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
5
+ The current features are:
6
+ - Integrates the gems `jsonapi-serializable`, `json-api-vanilla` and `log_toolbox`
7
+ - Rspec support through a series of shares examples
8
+ - Suport for JSON API services
6
9
 
7
10
  ## Installation
8
11
 
9
- Add this line to your application's Gemfile:
12
+ Add this line in your `Gemfile`:
10
13
 
11
- ```ruby
12
- gem 'json_api_toolbox'
13
- ```
14
-
15
- And then execute:
16
-
17
- $ bundle
18
-
19
- Or install it yourself as:
20
-
21
- $ gem install json_api_toolbox
14
+ gem 'json_api_toolbox'
22
15
 
23
- ## Usage
16
+ then execute:
24
17
 
25
- TODO: Write usage instructions here
18
+ $ bundle install
26
19
 
27
- ## Development
28
-
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
20
+ For rspec support, add this line on your `rails_helper.rb`:
30
21
 
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
22
+ require 'json_api_toolbox/rspec'
32
23
 
33
- ## Contributing
24
+ ## Usage Examples
34
25
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/abacha/json_api_toolbox.
26
+ You can check some gem uses within the examples below:
36
27
 
37
- ## Examples
28
+ ### Service
38
29
 
39
- #Service
40
30
  ```ruby
41
31
  class MyService < JsonApiToolbox::Service
42
32
  BASE_URL = 'http://localhost:3000/my_model'
@@ -61,9 +51,10 @@ class MyService < JsonApiToolbox::Service
61
51
  end
62
52
  ```
63
53
 
64
- #Renderizable
54
+ ### Renderizable
55
+
56
+ A simple render:
65
57
 
66
- Render common
67
58
  ```ruby
68
59
  render_object(Quota.all)
69
60
  ```
@@ -76,7 +67,7 @@ new Hash, the key must be 'Hash' and the value must be your Serializable.
76
67
  render_object(QuotaGap.all, class: { Hash: SerializableQuotaGap })
77
68
  ```
78
69
 
79
- #Paginable
70
+ ### Paginable
80
71
 
81
72
  To render a collection with a json api pagination, you will need to send a Hash
82
73
  that contains two keys called 'links' and 'meta', and its values must be Hashs.
@@ -96,35 +87,33 @@ class MyController
96
87
  end
97
88
  ```
98
89
 
99
- ##ShareExamplesForControllers
90
+ ### Rspec Shared Examples
100
91
 
101
- it_behaves_like 'a http method'
102
- validate if your response have http status 200
92
+ `it_behaves_like 'a http method'`
93
+ - validate if your response have http status 200
103
94
 
104
- it_behaves_like 'a get method'
105
- validate if your response have http status 200
106
- validate if your response responde to body method
95
+ `it_behaves_like 'a get method'`
96
+ - validate if your response have http status 200
97
+ - validate if your response responde to body method
107
98
 
108
- it_behaves_like 'a json api response with included node'
109
- validate if yor response.body has included node
99
+ `it_behaves_like 'a json api response with included node'`
100
+ - validate if yor response.body has included node
110
101
 
111
- it_behaves_like 'a get with jsonapi with default value of', SomeModel
112
- validate if all attributes are present on your data
113
- obs:
114
- 1 - for enums who have '_cd' in the end of attribute name, '_cd' is removed.
115
- ex: enum_cd => enum
116
- 2 - id attributes are removed from validation
117
- 3 - for attributes who have _id in the end of attribute name, they are
118
- removed from validation
102
+ `it_behaves_like 'a get with jsonapi with default value of', SomeModel`
103
+ - validate if all attributes are present on your data based on the current criteria:
104
+ 1. for enums who have `_cd` in the end of attribute name, `_cd` is removed.
119
105
 
120
- it_behaves_like 'a json api response with all relations of', SomeModel
121
- validate if all relations are included on your data
106
+ ex: `enum_cd` => `enum`
107
+ 1. id attributes are removed from validation
108
+ 1. for attributes who have `_id` in the end of attribute name, they are removed from validation
122
109
 
123
- it_behaves_like 'a failed attempt to retrieve a resource'
124
- check if the api response will include an error when `find` raise a exception retrieving a resource.
110
+ `it_behaves_like 'a json api response with all relations of', SomeModel`
111
+ - validate if all relations are included on your data
125
112
 
126
- ## Example Tests
113
+ `it_behaves_like 'a failed attempt to retrieve a resource'`
114
+ - checks if the api response will include an error when `find` raise a exception retrieving a resource.
127
115
 
116
+ ## Test example
128
117
 
129
118
  ```ruby
130
119
  # frozen_string_literal: true
@@ -221,3 +210,26 @@ RSpec.describe ManagersController, type: :controller do
221
210
  end
222
211
  end
223
212
  ```
213
+
214
+ ## Development
215
+
216
+ To change the gem is simple, just clone this repository and run the `bin/setup` script
217
+
218
+ Then you can make your changes and check them with `rspec` or `rubocop .`.
219
+
220
+
221
+ ### On docker
222
+
223
+ #### Building
224
+ ```bash
225
+ docker build . -t json-api-toolbox-dev
226
+ ```
227
+
228
+ #### Running tests
229
+ ```bash
230
+ docker run --rm -it -v "$(echo $HOME)/.ssh:/root/.ssh" -v "$(pwd):/gem" json-api-toolbox-dev
231
+ ```
232
+
233
+ ## Contributing
234
+
235
+ > To be written
data/Rakefile CHANGED
@@ -1,6 +1,11 @@
1
1
  require "bundler/gem_tasks"
2
2
  require "rspec/core/rake_task"
3
+ require "rubocop/rake_task"
3
4
 
4
5
  RSpec::Core::RakeTask.new(:spec)
6
+ RuboCop::RakeTask.new(:lint)
5
7
 
6
- task :default => :spec
8
+ task default: :spec
9
+
10
+ desc 'Execute both RuboCop and RSpec'
11
+ task "lint-and-test" => [:lint, :spec]
data/bin/setup.sh ADDED
@@ -0,0 +1,54 @@
1
+ #! /bin/sh
2
+
3
+ DEFAULT_REPO=git@bitbucket.org:guideinvestimentos/rails_defaults.git
4
+ STRICT=${1:-no}
5
+ ONE_WEEK_AGO=$(( $(date +%s) - 604800 ))
6
+ FILE_TIME=$(date +%s -r .rubocop.base.yml 2> /dev/null)
7
+
8
+ info(){
9
+ echo -e "\\e[34;1m$1\\e[0m"
10
+ }
11
+
12
+ step(){
13
+ printf "- $1: \\e7\n"
14
+ }
15
+
16
+ success(){
17
+ printf "\\e8\\e[32;1mOK!\\e[0m\n\\e[2K"
18
+ }
19
+
20
+ skipped(){
21
+ printf "\\e8\\e[33;1mSKIPPED ($1)\\e[0m\n\\e[2K"
22
+ }
23
+
24
+ error() {
25
+ printf "\\e8\\e[31;1mERRO!\\e[0m\n\\e[2K"
26
+ printf "\\e[31m $1\\e[0m\n"
27
+ [ $STRICT == "--strict" ] && exit $2
28
+ }
29
+
30
+ info "Configurando o projeto\n"
31
+
32
+ step "Atualizando configuração base do Rubocop"
33
+
34
+ if [ ${FILE_TIME:-0} -lt $ONE_WEEK_AGO ]; then
35
+ RUBOCOP_FILE=$(git archive --remote=$DEFAULT_REPO HEAD .rubocop.yml 2> /dev/null | tar xO 2> /dev/null)
36
+
37
+ if [ -z "$RUBOCOP_FILE" ]; then
38
+ error "Não foi possível baixar o arquivo de configuração" 1
39
+ else
40
+ echo "$RUBOCOP_FILE" > .rubocop.base.yml
41
+ success
42
+ fi
43
+ else
44
+ skipped "Arquivo recente"
45
+ fi
46
+
47
+ step "Instalando dependências"
48
+
49
+ bundle check 2>&1 > /dev/null && skipped "up-to date" || {
50
+ RESULT=$(bundle install 2>&1 > /dev/null)
51
+ [ $? == 0 ] && success || error "$RESULT" 2
52
+ }
53
+
54
+ info "\nConfiguração executada com sucesso"
@@ -1,21 +1,58 @@
1
- image: ruby:2.5.8
1
+ image: ruby:2.6
2
2
 
3
- pipelines:
4
- default:
5
- - step:
3
+ definitions:
4
+ caches:
5
+ bundler-26: vendor/bundle
6
+ bundler-27: vendor/bundle
7
+ bundler-30: vendor/bundle
8
+
9
+ steps:
10
+ - step: &test
11
+ name: Testing
12
+ script:
13
+ - apt-get install git
14
+ - gem update --system
15
+ - bundle config set --local path "vendor/bundle"
16
+ - bin/setup.sh --strict
17
+ - bundle exec rake lint-and-test
18
+ - step: &release
19
+ name: Release gem
6
20
  script:
7
- - git archive --remote=git@bitbucket.org:guideinvestimentos/rails_defaults.git HEAD .rubocop.yml | tar -x
21
+ - apt-get install git
22
+ - gem update --system
23
+ - bundle config set --local path "vendor/bundle"
8
24
  - bundle install
9
- - gem install rubocop
10
- - rspec -fdoc
11
- - rubocop .
25
+ - "[ -d ~/.gem/ ] || mkdir -p ~/.gem/"
26
+ - curl -u $RUBYGEMS_USERNAME:$RUBYGEMS_PASSWORD https://rubygems.org/api/v1/api_key.yaml -o ~/.gem/credentials
27
+ - chmod 0600 ~/.gem/credentials
28
+ - bundle exec rake release
29
+ caches:
30
+ - bundler-26
12
31
 
32
+ pipelines:
33
+ pull-requests:
34
+ '**':
35
+ - parallel:
36
+ - step:
37
+ <<: *test
38
+ name: Ruby 2.6
39
+ image: ruby:2.6
40
+ caches:
41
+ - bundler-26
42
+ - step:
43
+ <<: *test
44
+ name: Ruby 2.7
45
+ image: ruby:2.7
46
+ caches:
47
+ - bundler-27
48
+ - step:
49
+ <<: *test
50
+ name: Ruby 3.0
51
+ image: ruby:3.0
52
+ caches:
53
+ - bundler-30
13
54
  branches:
14
55
  master:
15
- - step:
16
- script:
17
- - gem build json_api_toolbox.gemspec
18
- - mkdir /root/.gem
19
- - curl -u $RUBYGEMS_USERNAME:$RUBYGEMS_PASSWORD https://rubygems.org/api/v1/api_key.yaml > ~/.gem/credentials
20
- - chmod 0600 ~/.gem/credentials
21
- - gem push $(ls *.gem)
56
+ - step: *release
57
+ 'branch-1.x':
58
+ - step: *release
@@ -0,0 +1,3 @@
1
+ #! /bin/sh
2
+
3
+ . bin/setup.sh && bundle exec "$@"
@@ -1,14 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # rubocop:disable Metrics/BlockLength
4
3
  lib = File.expand_path('lib', __dir__)
5
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
6
5
  require 'json_api_toolbox/version'
7
6
 
8
7
  Gem::Specification.new do |spec|
9
- spec.required_ruby_version = '~> 2.5.0'
8
+ spec.required_ruby_version = '>= 2.6.0'
10
9
  spec.name = 'json_api_toolbox'
11
10
  spec.version = JsonApiToolbox::VERSION
11
+
12
12
  spec.authors = ['Adriano Bacha']
13
13
  spec.email = ['abacha@gmail.com']
14
14
 
@@ -20,23 +20,19 @@ Gem::Specification.new do |spec|
20
20
  end
21
21
  spec.require_paths = ['lib']
22
22
 
23
- spec.add_dependency 'actionpack', '>= 4.0.0'
24
- spec.add_dependency 'activerecord', '>= 4.0.0'
25
- spec.add_dependency 'activesupport', '>= 4.0.0'
26
- spec.add_dependency 'jsonapi-serializable', '>= 0.3.0'
27
- spec.add_dependency 'json-api-vanilla', '~> 1.0.1'
23
+ spec.add_dependency 'activerecord', '>= 5.1.0'
24
+ spec.add_dependency 'activesupport', '>= 5.1.0'
25
+ spec.add_dependency 'jsonapi-serializable'
26
+ spec.add_dependency 'json-api-vanilla'
28
27
  spec.add_dependency 'log_toolbox'
29
- spec.add_dependency 'request_store', '~> 1.3.2'
30
- spec.add_dependency 'rest-client', '>= 2.0.1'
31
- spec.add_dependency 'rspec', '>= 3.0.0'
32
- spec.add_dependency 'will_paginate', '>= 3.1.0'
28
+ spec.add_dependency 'request_store'
29
+ spec.add_dependency 'rest-client'
30
+ spec.add_dependency 'will_paginate'
33
31
 
34
32
  spec.add_development_dependency 'bundler'
35
- spec.add_development_dependency 'json'
36
- spec.add_development_dependency 'pry'
37
33
  spec.add_development_dependency 'pry-byebug'
38
34
  spec.add_development_dependency 'rake'
35
+ spec.add_development_dependency 'rspec'
39
36
  spec.add_development_dependency 'rubocop'
40
- spec.add_development_dependency 'shoulda-matchers', '~> 3.1'
37
+ spec.add_development_dependency 'shoulda-matchers'
41
38
  end
42
- # rubocop:enable Metrics/BlockLength
@@ -11,7 +11,6 @@ require 'json_api_toolbox/paginable'
11
11
  require 'will_paginate'
12
12
  require 'will_paginate/active_record'
13
13
 
14
- require_relative 'json_api_toolbox/spec_support/shared_examples_for_controllers'
15
14
  require_relative 'json_api_toolbox/serializables/serializable_enum_option'
16
15
  require_relative 'json_api_toolbox/serializables/serializable_job'
17
16
  require_relative 'json_api_toolbox/serializables/serializable_version'
@@ -0,0 +1,82 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rspec'
4
+
5
+ module JsonApiToolbox
6
+ module Rspec
7
+ RSpec.shared_examples 'a http method' do
8
+ it 'returns http success' do
9
+ expect(response).to have_http_status(:success)
10
+ end
11
+ end
12
+
13
+ RSpec.shared_examples 'a post with status 422 Unprocessable Entity' do
14
+ it 'returns http code 422 Unprocessable Entity' do
15
+ expect(response).to have_http_status(422)
16
+ end
17
+ end
18
+
19
+ RSpec.shared_examples 'a get method' do
20
+ it_behaves_like 'a http method'
21
+
22
+ it 'response with JSON body' do
23
+ expect { response.body }.not_to raise_exception
24
+ end
25
+ end
26
+
27
+ RSpec.shared_examples 'a json api response with included node' do
28
+ it 'returns with included node' do
29
+ expect(JSON.parse(response.body)['included'].count).not_to eql(0)
30
+ end
31
+ end
32
+
33
+ RSpec.shared_examples 'a get with jsonapi with default value of' do |model|
34
+ let(:attributes) { data['attributes'].keys }
35
+ let(:model_keys) do
36
+ enums = []
37
+ model.new.attributes.keys.map do |attr|
38
+ case attr
39
+ when /_cd$/
40
+ enums << attr
41
+ attr.gsub(/_cd/, '')
42
+ when /_id$|^id$/
43
+ nil
44
+ else
45
+ attr
46
+ end
47
+ end.compact + enums
48
+ end
49
+
50
+ it 'returns response with default values' do
51
+ expect((model_keys & attributes).size).to eq(model_keys.size)
52
+ end
53
+ end
54
+
55
+ RSpec.shared_examples 'a json api response with all relations of' do |model|
56
+ let(:attributes) { data['relationships'].keys }
57
+ let(:relation_keys) { model.reflections.keys }
58
+
59
+ it 'returns response with default relationships' do
60
+ expect(attributes).to match_array(relation_keys)
61
+ end
62
+ end
63
+
64
+ RSpec.shared_examples 'a json api response' do
65
+ let(:body) { JSON.parse(response.body) }
66
+ let(:data) { body['data'].first }
67
+
68
+ it { expect(body).to have_key('data') }
69
+ it { expect(data).to have_key('type') }
70
+ it { expect(data).to have_key('id') }
71
+ it { expect(data).to have_key('attributes') }
72
+ end
73
+
74
+ RSpec.shared_examples 'a failed attempt to retrieve a resource' do
75
+ let(:errors) { JSON.parse(response.body)['errors'] }
76
+
77
+ it 'returns response with error\'s title including RecordNotFound' do
78
+ expect(errors.first['title']).to eq('ActiveRecord::RecordNotFound')
79
+ end
80
+ end
81
+ end
82
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JsonApiToolbox
4
- VERSION = '1.5.1'
4
+ VERSION = '2.0.0'
5
5
  end
metadata CHANGED
@@ -1,85 +1,71 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json_api_toolbox
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.1
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adriano Bacha
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-06-08 00:00:00.000000000 Z
11
+ date: 2021-08-10 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: actionpack
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: 4.0.0
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: 4.0.0
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: activerecord
29
15
  requirement: !ruby/object:Gem::Requirement
30
16
  requirements:
31
17
  - - ">="
32
18
  - !ruby/object:Gem::Version
33
- version: 4.0.0
19
+ version: 5.1.0
34
20
  type: :runtime
35
21
  prerelease: false
36
22
  version_requirements: !ruby/object:Gem::Requirement
37
23
  requirements:
38
24
  - - ">="
39
25
  - !ruby/object:Gem::Version
40
- version: 4.0.0
26
+ version: 5.1.0
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: activesupport
43
29
  requirement: !ruby/object:Gem::Requirement
44
30
  requirements:
45
31
  - - ">="
46
32
  - !ruby/object:Gem::Version
47
- version: 4.0.0
33
+ version: 5.1.0
48
34
  type: :runtime
49
35
  prerelease: false
50
36
  version_requirements: !ruby/object:Gem::Requirement
51
37
  requirements:
52
38
  - - ">="
53
39
  - !ruby/object:Gem::Version
54
- version: 4.0.0
40
+ version: 5.1.0
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: jsonapi-serializable
57
43
  requirement: !ruby/object:Gem::Requirement
58
44
  requirements:
59
45
  - - ">="
60
46
  - !ruby/object:Gem::Version
61
- version: 0.3.0
47
+ version: '0'
62
48
  type: :runtime
63
49
  prerelease: false
64
50
  version_requirements: !ruby/object:Gem::Requirement
65
51
  requirements:
66
52
  - - ">="
67
53
  - !ruby/object:Gem::Version
68
- version: 0.3.0
54
+ version: '0'
69
55
  - !ruby/object:Gem::Dependency
70
56
  name: json-api-vanilla
71
57
  requirement: !ruby/object:Gem::Requirement
72
58
  requirements:
73
- - - "~>"
59
+ - - ">="
74
60
  - !ruby/object:Gem::Version
75
- version: 1.0.1
61
+ version: '0'
76
62
  type: :runtime
77
63
  prerelease: false
78
64
  version_requirements: !ruby/object:Gem::Requirement
79
65
  requirements:
80
- - - "~>"
66
+ - - ">="
81
67
  - !ruby/object:Gem::Version
82
- version: 1.0.1
68
+ version: '0'
83
69
  - !ruby/object:Gem::Dependency
84
70
  name: log_toolbox
85
71
  requirement: !ruby/object:Gem::Requirement
@@ -96,60 +82,46 @@ dependencies:
96
82
  version: '0'
97
83
  - !ruby/object:Gem::Dependency
98
84
  name: request_store
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - "~>"
102
- - !ruby/object:Gem::Version
103
- version: 1.3.2
104
- type: :runtime
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - "~>"
109
- - !ruby/object:Gem::Version
110
- version: 1.3.2
111
- - !ruby/object:Gem::Dependency
112
- name: rest-client
113
85
  requirement: !ruby/object:Gem::Requirement
114
86
  requirements:
115
87
  - - ">="
116
88
  - !ruby/object:Gem::Version
117
- version: 2.0.1
89
+ version: '0'
118
90
  type: :runtime
119
91
  prerelease: false
120
92
  version_requirements: !ruby/object:Gem::Requirement
121
93
  requirements:
122
94
  - - ">="
123
95
  - !ruby/object:Gem::Version
124
- version: 2.0.1
96
+ version: '0'
125
97
  - !ruby/object:Gem::Dependency
126
- name: rspec
98
+ name: rest-client
127
99
  requirement: !ruby/object:Gem::Requirement
128
100
  requirements:
129
101
  - - ">="
130
102
  - !ruby/object:Gem::Version
131
- version: 3.0.0
103
+ version: '0'
132
104
  type: :runtime
133
105
  prerelease: false
134
106
  version_requirements: !ruby/object:Gem::Requirement
135
107
  requirements:
136
108
  - - ">="
137
109
  - !ruby/object:Gem::Version
138
- version: 3.0.0
110
+ version: '0'
139
111
  - !ruby/object:Gem::Dependency
140
112
  name: will_paginate
141
113
  requirement: !ruby/object:Gem::Requirement
142
114
  requirements:
143
115
  - - ">="
144
116
  - !ruby/object:Gem::Version
145
- version: 3.1.0
117
+ version: '0'
146
118
  type: :runtime
147
119
  prerelease: false
148
120
  version_requirements: !ruby/object:Gem::Requirement
149
121
  requirements:
150
122
  - - ">="
151
123
  - !ruby/object:Gem::Version
152
- version: 3.1.0
124
+ version: '0'
153
125
  - !ruby/object:Gem::Dependency
154
126
  name: bundler
155
127
  requirement: !ruby/object:Gem::Requirement
@@ -165,7 +137,7 @@ dependencies:
165
137
  - !ruby/object:Gem::Version
166
138
  version: '0'
167
139
  - !ruby/object:Gem::Dependency
168
- name: json
140
+ name: pry-byebug
169
141
  requirement: !ruby/object:Gem::Requirement
170
142
  requirements:
171
143
  - - ">="
@@ -179,7 +151,7 @@ dependencies:
179
151
  - !ruby/object:Gem::Version
180
152
  version: '0'
181
153
  - !ruby/object:Gem::Dependency
182
- name: pry
154
+ name: rake
183
155
  requirement: !ruby/object:Gem::Requirement
184
156
  requirements:
185
157
  - - ">="
@@ -193,7 +165,7 @@ dependencies:
193
165
  - !ruby/object:Gem::Version
194
166
  version: '0'
195
167
  - !ruby/object:Gem::Dependency
196
- name: pry-byebug
168
+ name: rspec
197
169
  requirement: !ruby/object:Gem::Requirement
198
170
  requirements:
199
171
  - - ">="
@@ -207,7 +179,7 @@ dependencies:
207
179
  - !ruby/object:Gem::Version
208
180
  version: '0'
209
181
  - !ruby/object:Gem::Dependency
210
- name: rake
182
+ name: rubocop
211
183
  requirement: !ruby/object:Gem::Requirement
212
184
  requirements:
213
185
  - - ">="
@@ -221,7 +193,7 @@ dependencies:
221
193
  - !ruby/object:Gem::Version
222
194
  version: '0'
223
195
  - !ruby/object:Gem::Dependency
224
- name: rubocop
196
+ name: shoulda-matchers
225
197
  requirement: !ruby/object:Gem::Requirement
226
198
  requirements:
227
199
  - - ">="
@@ -234,20 +206,6 @@ dependencies:
234
206
  - - ">="
235
207
  - !ruby/object:Gem::Version
236
208
  version: '0'
237
- - !ruby/object:Gem::Dependency
238
- name: shoulda-matchers
239
- requirement: !ruby/object:Gem::Requirement
240
- requirements:
241
- - - "~>"
242
- - !ruby/object:Gem::Version
243
- version: '3.1'
244
- type: :development
245
- prerelease: false
246
- version_requirements: !ruby/object:Gem::Requirement
247
- requirements:
248
- - - "~>"
249
- - !ruby/object:Gem::Version
250
- version: '3.1'
251
209
  description:
252
210
  email:
253
211
  - abacha@gmail.com
@@ -257,22 +215,25 @@ extra_rdoc_files: []
257
215
  files:
258
216
  - ".gitignore"
259
217
  - ".rspec"
260
- - ".ruby-version"
261
- - ".travis.yml"
218
+ - ".rubocop.yml"
262
219
  - CHANGELOG.md
220
+ - Dockerfile
263
221
  - Gemfile
222
+ - Gemfile.lock
264
223
  - README.md
265
224
  - Rakefile
225
+ - bin/setup.sh
266
226
  - bitbucket-pipelines.yml
227
+ - docker-entrypoint.sh
267
228
  - json_api_toolbox.gemspec
268
229
  - lib/enums.rb
269
230
  - lib/json_api_toolbox.rb
270
231
  - lib/json_api_toolbox/paginable.rb
232
+ - lib/json_api_toolbox/rspec.rb
271
233
  - lib/json_api_toolbox/serializables/serializable_enum_option.rb
272
234
  - lib/json_api_toolbox/serializables/serializable_exception.rb
273
235
  - lib/json_api_toolbox/serializables/serializable_job.rb
274
236
  - lib/json_api_toolbox/serializables/serializable_version.rb
275
- - lib/json_api_toolbox/spec_support/shared_examples_for_controllers.rb
276
237
  - lib/json_api_toolbox/version.rb
277
238
  - lib/postable.rb
278
239
  - lib/renderizable.rb
@@ -287,16 +248,16 @@ require_paths:
287
248
  - lib
288
249
  required_ruby_version: !ruby/object:Gem::Requirement
289
250
  requirements:
290
- - - "~>"
251
+ - - ">="
291
252
  - !ruby/object:Gem::Version
292
- version: 2.5.0
253
+ version: 2.6.0
293
254
  required_rubygems_version: !ruby/object:Gem::Requirement
294
255
  requirements:
295
256
  - - ">="
296
257
  - !ruby/object:Gem::Version
297
258
  version: '0'
298
259
  requirements: []
299
- rubygems_version: 3.0.3
260
+ rubygems_version: 3.2.25
300
261
  signing_key:
301
262
  specification_version: 4
302
263
  summary: Json API usefull tools
data/.ruby-version DELETED
@@ -1 +0,0 @@
1
- ruby-2.5.0
data/.travis.yml DELETED
@@ -1,5 +0,0 @@
1
- sudo: false
2
- language: ruby
3
- rvm:
4
- - 2.2.5
5
- before_install: gem install bundler -v 1.15.1
@@ -1,86 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'rspec'
4
-
5
- module JsonApiToolbox
6
- module SpecSupport
7
- module SharedExamplesForControllers
8
- RSpec.shared_examples 'a http method' do
9
- it 'returns http success' do
10
- expect(response).to have_http_status(:success)
11
- end
12
- end
13
-
14
- RSpec.shared_examples 'a post with status 422 Unprocessable Entity' do
15
- it 'returns http code 422 Unprocessable Entity' do
16
- expect(response).to have_http_status(422)
17
- end
18
- end
19
-
20
- RSpec.shared_examples 'a get method' do
21
- it_behaves_like 'a http method'
22
-
23
- it 'response with JSON body' do
24
- expect { response.body }.not_to raise_exception
25
- end
26
- end
27
-
28
- RSpec.shared_examples 'a json api response with included node' do
29
- it 'returns with included node' do
30
- expect(JSON.parse(response.body)['included'].count).not_to eql(0)
31
- end
32
- end
33
-
34
- RSpec.
35
- shared_examples 'a get with jsonapi with default value of' do |model|
36
- let(:attributes) { data['attributes'].keys }
37
- let(:model_keys) do
38
- enums = []
39
- model.new.attributes.keys.map do |attr|
40
- case attr
41
- when /_cd$/
42
- enums << attr
43
- attr.gsub(/_cd/, '')
44
- when /_id$|^id$/
45
- nil
46
- else
47
- attr
48
- end
49
- end.compact + enums
50
- end
51
-
52
- it 'returns response with default values' do
53
- expect((model_keys & attributes).size).to eq(model_keys.size)
54
- end
55
- end
56
-
57
- RSpec.
58
- shared_examples 'a json api response with all relations of' do |model|
59
- let(:attributes) { data['relationships'].keys }
60
- let(:relation_keys) { model.reflections.keys }
61
-
62
- it 'returns response with default relationships' do
63
- expect(attributes).to match_array(relation_keys)
64
- end
65
- end
66
-
67
- RSpec.shared_examples 'a json api response' do
68
- let(:body) { JSON.parse(response.body) }
69
- let(:data) { body['data'].first }
70
-
71
- it { expect(body).to have_key('data') }
72
- it { expect(data).to have_key('type') }
73
- it { expect(data).to have_key('id') }
74
- it { expect(data).to have_key('attributes') }
75
- end
76
-
77
- RSpec.shared_examples 'a failed attempt to retrieve a resource' do
78
- let(:errors) { JSON.parse(response.body)['errors'] }
79
-
80
- it 'returns response with error\'s title including RecordNotFound' do
81
- expect(errors.first['title']).to eq('ActiveRecord::RecordNotFound')
82
- end
83
- end
84
- end
85
- end
86
- end