api_me 0.9.3 → 0.9.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/{LICENCE → LICENSE} +1 -1
- data/lib/api_me.rb +28 -13
- data/lib/api_me/version.rb +1 -1
- data/lib/generators/api_me/controller/controller_generator.rb +1 -1
- data/spec/acceptance/api/v1/users_spec.rb +12 -6
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aed5d142524f6fbf74249ad247e7570f6043bf46fab0d142025333464c95b615
|
4
|
+
data.tar.gz: 5533d6ed2788081506b6ab79f448ae58e91bc4cdada605e9e086d2875ffe3ed6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 18c8ffeed181d5346baddf0e705e4a5507222fc65248f90d12ff845bde6d3b223a54ec740c99a29e53f151d29c0a26acbacb498f0fafd896b718b6185a35633b
|
7
|
+
data.tar.gz: 2041df09681bb28d2c87b31993ad6917a5c6c778657fa28330ea629e1f3ef4ea9b87886212e0a049267127cde0b1aec4efb5a9dd3e5dfc7ba0e86a1e511ea655
|
data/Gemfile.lock
CHANGED
data/{LICENCE → LICENSE}
RENAMED
data/lib/api_me.rb
CHANGED
@@ -76,14 +76,21 @@ module ApiMe
|
|
76
76
|
|
77
77
|
def show
|
78
78
|
@object = find_resource
|
79
|
-
|
79
|
+
authorize_resource @object
|
80
80
|
|
81
81
|
render json: @object, root: singular_root_key, serializer: serializer_klass
|
82
82
|
end
|
83
83
|
|
84
|
+
def new
|
85
|
+
@object = model_klass.new
|
86
|
+
authorize_resource @object
|
87
|
+
|
88
|
+
render_errors(['new endpoint not supported'], 404)
|
89
|
+
end
|
90
|
+
|
84
91
|
def create
|
85
|
-
@object =
|
86
|
-
|
92
|
+
@object = build_resource
|
93
|
+
authorize_resource @object
|
87
94
|
@object.save!(object_params)
|
88
95
|
|
89
96
|
render status: 201, json: @object, root: singular_root_key, serializer: serializer_klass
|
@@ -91,9 +98,16 @@ module ApiMe
|
|
91
98
|
handle_errors(e)
|
92
99
|
end
|
93
100
|
|
101
|
+
def edit
|
102
|
+
@object = find_resource
|
103
|
+
authorize_resource @object
|
104
|
+
|
105
|
+
render_errors(['edit endpoint not supported'], 404)
|
106
|
+
end
|
107
|
+
|
94
108
|
def update
|
95
109
|
@object = find_resource
|
96
|
-
|
110
|
+
authorize_resource @object
|
97
111
|
@object.update!(object_params)
|
98
112
|
|
99
113
|
head 204
|
@@ -103,8 +117,9 @@ module ApiMe
|
|
103
117
|
|
104
118
|
def destroy
|
105
119
|
@object = find_resource
|
106
|
-
|
120
|
+
authorize_resource @object
|
107
121
|
@object.destroy
|
122
|
+
|
108
123
|
head 204
|
109
124
|
rescue ActiveRecord::RecordInvalid => e
|
110
125
|
handle_errors(e)
|
@@ -177,10 +192,10 @@ module ApiMe
|
|
177
192
|
).results
|
178
193
|
end
|
179
194
|
|
180
|
-
def sort_scope(scope)
|
195
|
+
def sort_scope(scope, sortable_params=sort_params)
|
181
196
|
sort_klass.new(
|
182
197
|
scope: scope,
|
183
|
-
sort_params:
|
198
|
+
sort_params: sortable_params
|
184
199
|
).results
|
185
200
|
end
|
186
201
|
|
@@ -201,15 +216,15 @@ module ApiMe
|
|
201
216
|
params[:filters]
|
202
217
|
end
|
203
218
|
|
204
|
-
def
|
205
|
-
|
219
|
+
def find_resource
|
220
|
+
@find_resource ||= model_klass.find_by_id!(params[:id])
|
206
221
|
end
|
207
222
|
|
208
|
-
def
|
209
|
-
|
223
|
+
def build_resource
|
224
|
+
@build_resource ||= model_klass.new(object_params)
|
210
225
|
end
|
211
226
|
|
212
|
-
def
|
213
|
-
|
227
|
+
def authorize_resource(resource)
|
228
|
+
authorize resource
|
214
229
|
end
|
215
230
|
end
|
data/lib/api_me/version.rb
CHANGED
@@ -76,7 +76,7 @@ module ApiMe
|
|
76
76
|
in_root do
|
77
77
|
insert_into_file(
|
78
78
|
'config/routes.rb',
|
79
|
-
" resources :#{resource_name}\n",
|
79
|
+
" resources :#{resource_name}, only: [:show, :index, :create, :update, :destroy]\n",
|
80
80
|
after: "namespace :#{controllers_api_version} do\n"
|
81
81
|
)
|
82
82
|
end
|
@@ -23,15 +23,21 @@ describe 'Users API' do
|
|
23
23
|
expect(last_response.status).to eq(404)
|
24
24
|
end
|
25
25
|
|
26
|
-
it '
|
27
|
-
user = User.create(username: 'Test')
|
26
|
+
it 'returns a 404 for new' do
|
28
27
|
|
29
|
-
get '/api/v1/users/'
|
28
|
+
get '/api/v1/users/new'
|
30
29
|
|
31
|
-
expect(last_response.status).to eq(
|
32
|
-
|
30
|
+
expect(last_response.status).to eq(404)
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'returns a 404 for edit' do
|
34
|
+
user = User.create(username: 'Foo')
|
35
|
+
|
36
|
+
expect(user.username).to eq('Foo')
|
33
37
|
|
34
|
-
|
38
|
+
get '/api/v1/users/' + user.id.to_s + '/edit'
|
39
|
+
|
40
|
+
expect(last_response.status).to eq(404)
|
35
41
|
end
|
36
42
|
|
37
43
|
it 'creates a new user' do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: api_me
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sam Clopton
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2018-
|
12
|
+
date: 2018-09-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|
@@ -180,7 +180,7 @@ files:
|
|
180
180
|
- ".travis.yml"
|
181
181
|
- Gemfile
|
182
182
|
- Gemfile.lock
|
183
|
-
-
|
183
|
+
- LICENSE
|
184
184
|
- README.md
|
185
185
|
- Rakefile
|
186
186
|
- api_me.gemspec
|