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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 13972ff9aba7a136befeba0bbc99baff56bd5b48882de8fb62c439a3eeafde7b
4
- data.tar.gz: 4742b40b1123e162ff279abbeea1410f99550bc8d0468f5136c882b4a7ac2af7
3
+ metadata.gz: aed5d142524f6fbf74249ad247e7570f6043bf46fab0d142025333464c95b615
4
+ data.tar.gz: 5533d6ed2788081506b6ab79f448ae58e91bc4cdada605e9e086d2875ffe3ed6
5
5
  SHA512:
6
- metadata.gz: b4214d4d9a69499ec77ffe564e328d68b99ec3dfba66e61916ce22c94108591999c5ece0b61aa6e1d27134cefd5b9bb35d380dacf600342942b5cf8367102014
7
- data.tar.gz: 989b0117ab862e775848bf30010c800bec998c3e0c3497abfefc5e70eda83e19358f5dbfdeb1bccc252779c21a2f5143d0733ac086e2627b6a0e13b8a6313d45
6
+ metadata.gz: 18c8ffeed181d5346baddf0e705e4a5507222fc65248f90d12ff845bde6d3b223a54ec740c99a29e53f151d29c0a26acbacb498f0fafd896b718b6185a35633b
7
+ data.tar.gz: 2041df09681bb28d2c87b31993ad6917a5c6c778657fa28330ea629e1f3ef4ea9b87886212e0a049267127cde0b1aec4efb5a9dd3e5dfc7ba0e86a1e511ea655
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- api_me (0.9.3)
4
+ api_me (0.9.4)
5
5
  active_model_serializers (~> 0.10.0)
6
6
  activerecord (>= 4.1.16)
7
7
  activesupport (>= 4.1.16)
@@ -1,4 +1,4 @@
1
- Copyright (c) 2014 Sam Clopton
1
+ Copyright (c) 2018 Wildland Labs Inc.
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/lib/api_me.rb CHANGED
@@ -76,14 +76,21 @@ module ApiMe
76
76
 
77
77
  def show
78
78
  @object = find_resource
79
- authorize @object
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 = model_klass.new(object_params)
86
- authorize @object
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
- authorize @object
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
- authorize @object
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: sort_hash
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 sort_hash
205
- sort_params
219
+ def find_resource
220
+ @find_resource ||= model_klass.find_by_id!(params[:id])
206
221
  end
207
222
 
208
- def sort_params
209
- params[:sort]
223
+ def build_resource
224
+ @build_resource ||= model_klass.new(object_params)
210
225
  end
211
226
 
212
- def find_resource
213
- model_klass.find_by_id!(params[:id])
227
+ def authorize_resource(resource)
228
+ authorize resource
214
229
  end
215
230
  end
@@ -1,3 +1,3 @@
1
1
  module ApiMe
2
- VERSION = '0.9.3'.freeze
2
+ VERSION = '0.9.4'.freeze
3
3
  end
@@ -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 'sends an individual user' do
27
- user = User.create(username: 'Test')
26
+ it 'returns a 404 for new' do
28
27
 
29
- get '/api/v1/users/' + user.id.to_s + '/'
28
+ get '/api/v1/users/new'
30
29
 
31
- expect(last_response.status).to eq(200)
32
- json = JSON.parse(last_response.body)
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
- expect(json['user']['id']).to eq(user.id)
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.3
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-08-16 00:00:00.000000000 Z
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
- - LICENCE
183
+ - LICENSE
184
184
  - README.md
185
185
  - Rakefile
186
186
  - api_me.gemspec