active_record_api-rest 0.0.2 → 0.0.3
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
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 93727d4d0d64a6537cd42c8d97ef4ef8cfdcfa1b3738f62b0e87339d1f88736b
|
4
|
+
data.tar.gz: 32626d83c89f7f6167f5b6c84920c726d4f08a2fe5be339239f91a47c3c0f467
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 68e76ec59baf9cdb836aaabedda3a3945a87ca3b01851cdc4c3ab669e5c4c067afade6a886e78e2a04ff8291e49cb1bb1ba69b9e165cf4e4a34fc738cb656fb0
|
7
|
+
data.tar.gz: b2143dcebb3d5156980570cdf6d34505ecf309a8dbb71e45b50066dfac09c3c923b56e3977c777d7d5a27c083217046a4031b6bd597f3cab2878e272f4bf4545
|
data/Gemfile.lock
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
active_record_api-rest (0.0.
|
4
|
+
active_record_api-rest (0.0.2)
|
5
5
|
active_attr
|
6
6
|
active_model_serializers
|
7
7
|
cancancan
|
8
|
-
rails (>= 5.
|
8
|
+
rails (>= 5.1)
|
9
9
|
|
10
10
|
GEM
|
11
11
|
remote: https://rubygems.org/
|
@@ -211,4 +211,4 @@ DEPENDENCIES
|
|
211
211
|
webmock
|
212
212
|
|
213
213
|
BUNDLED WITH
|
214
|
-
1.16.
|
214
|
+
1.16.2
|
@@ -47,12 +47,12 @@ module ActiveRecordApi
|
|
47
47
|
|
48
48
|
def resource_params
|
49
49
|
@resource_params ||= filtered_params.reject do |column_name|
|
50
|
-
column_name ==
|
50
|
+
column_name.to_s == 'id'
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
54
|
def not_allowed_params
|
55
|
-
@not_allowed_params ||= ((params.keys.map(&:to_sym) - [:controller, :action, model_klass.name.underscore.to_sym]) - resource_params.keys.map(&:to_sym))
|
55
|
+
@not_allowed_params ||= ((params.keys.map(&:to_sym) - [:controller, :action, model_klass.name.underscore.to_sym, :id]) - resource_params.keys.map(&:to_sym))
|
56
56
|
end
|
57
57
|
|
58
58
|
def initialize_model
|
@@ -10,10 +10,18 @@ shared_examples 'all::rest::actions' do
|
|
10
10
|
let(:factory_symbol) { model_klass.to_s.underscore.to_sym }
|
11
11
|
let(:index_non_accessible_data) { create factory_symbol, organization_id: (model.organization_id + 1) }
|
12
12
|
let(:model_array) { [model] + create_list(factory_symbol, 4, organization_id: model.organization_id) }
|
13
|
+
let(:base_model_klass) do
|
14
|
+
if model_klass.superclass == ApplicationRecord
|
15
|
+
model_klass
|
16
|
+
else
|
17
|
+
model_klass.superclass
|
18
|
+
end
|
19
|
+
end
|
20
|
+
let(:host) { ActiveRecordApi::Rest::RequestUrlGenerator.new(request: request).micro_service_url }
|
13
21
|
describe 'All rest actions' do
|
14
22
|
let(:serializer) { ActiveModelSerializers::SerializableResource }
|
15
23
|
let(:model_klass) { described_class.controller_name.classify.constantize }
|
16
|
-
let(:model) { create
|
24
|
+
let(:model) { create factory_symbol }
|
17
25
|
include_examples 'get::show'
|
18
26
|
include_examples 'get::index'
|
19
27
|
include_examples 'put::update'
|
@@ -40,7 +48,7 @@ shared_examples 'get::show' do
|
|
40
48
|
get :show, params: { id: -1 }
|
41
49
|
end
|
42
50
|
it { expect(response.status).to eq 404 }
|
43
|
-
it { expect(JSON.parse(response.body)['base']).to
|
51
|
+
it { expect(JSON.parse(response.body)['base']).to eq "Couldn't find #{base_model_klass} with 'id'=-1" }
|
44
52
|
end
|
45
53
|
end
|
46
54
|
context 'when not authorized' do
|
@@ -79,7 +87,7 @@ shared_examples 'get::index' do
|
|
79
87
|
end
|
80
88
|
it { expect(response.status).to eq 200 }
|
81
89
|
it { expect(response.headers['x-total']).to eq model_array.length }
|
82
|
-
it { expect(response.headers['x-link-next']).to eq "
|
90
|
+
it { expect(response.headers['x-link-next']).to eq "#{host}#{request.path}?limit=1&previous_id=#{next_previous_id}" }
|
83
91
|
it { expect(response.body).to be_json_eql model_klass.where('id > ?', previous_id).limit(1).map { |o| serializer.new(o) }.to_json }
|
84
92
|
end
|
85
93
|
|
@@ -107,9 +115,8 @@ shared_examples 'get::index' do
|
|
107
115
|
end
|
108
116
|
|
109
117
|
shared_examples 'put::update' do
|
110
|
-
let(:payload) { model.
|
111
|
-
let(:
|
112
|
-
let(:relative_url) { Rails.application.routes.url_helpers.url_for(controller: model_klass.to_s.underscore.pluralize, action: 'show', id: model.id, only_path: true) }
|
118
|
+
let(:payload) { serializer.new(model).as_json }
|
119
|
+
let(:relative_url) { Rails.application.routes.url_helpers.url_for(controller: base_model_klass.to_s.underscore.pluralize, action: 'show', id: model.id, only_path: true) }
|
113
120
|
describe 'PUT update' do
|
114
121
|
context 'when authorized' do
|
115
122
|
before(:each) do
|
@@ -124,7 +131,7 @@ shared_examples 'put::update' do
|
|
124
131
|
end
|
125
132
|
context 'when invalid param values provided' do
|
126
133
|
before(:each) do
|
127
|
-
put :update, params: update_invalid_model.
|
134
|
+
put :update, params: serializer.new(update_invalid_model).as_json.merge(id: model.id)
|
128
135
|
expect(update_invalid_model.valid?).to be false
|
129
136
|
end
|
130
137
|
it { expect(response.status).to eq(422) }
|
@@ -132,7 +139,7 @@ shared_examples 'put::update' do
|
|
132
139
|
end
|
133
140
|
context 'when invalid param keys provided' do
|
134
141
|
before(:each) do
|
135
|
-
put :update, params:
|
142
|
+
put :update, params: payload.merge('foobars' => 'stuff')
|
136
143
|
end
|
137
144
|
it { expect(response.status).to eq(422) }
|
138
145
|
it { expect(response.body).to be_json_eql({ base: 'Extra parameters are not allow: foobars' }.to_json) }
|
@@ -150,10 +157,9 @@ shared_examples 'put::update' do
|
|
150
157
|
end
|
151
158
|
|
152
159
|
shared_examples 'post::create' do
|
153
|
-
let(:new_attributes) { model.
|
160
|
+
let(:new_attributes) { serializer.new(model).as_json.except(:id) }
|
154
161
|
let(:model_id) { model.id }
|
155
|
-
let(:
|
156
|
-
let(:relative_url) { Rails.application.routes.url_helpers.url_for(controller: model_klass.to_s.underscore.pluralize, action: 'show', id: model_klass.last.id, only_path: true) }
|
162
|
+
let(:relative_url) { Rails.application.routes.url_helpers.url_for(controller: base_model_klass.to_s.underscore.pluralize, action: 'show', id: model_klass.last.id, only_path: true) }
|
157
163
|
describe 'POST create' do
|
158
164
|
context 'when authorized' do
|
159
165
|
before(:each) do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_record_api-rest
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Full Measure Education
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-07-
|
11
|
+
date: 2018-07-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|