api_me 0.4.0 → 0.4.1

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
  SHA1:
3
- metadata.gz: 0658898c8db26ece5dcf4eba4465c41a4c944007
4
- data.tar.gz: 1ac19dc633b67d85039621edee0c9afc06e0f76c
3
+ metadata.gz: d6be2bfc501d6e34780bb7d71cc7f9504110bbe5
4
+ data.tar.gz: 0cdf554cf51fc1c08cc960b9aa03d9869a631ecc
5
5
  SHA512:
6
- metadata.gz: 9011c9ca170a159c3802421d85662be738038e32337655ef74a412ddacd48dc12727cff413db45217c8fbb4294493e34ba2728b3d2148a3bfb572fb3f6a66195
7
- data.tar.gz: 5bf8be52281acd86adc7a8316893e2a55b543ca6b22d46bc6e79be11ad8a1d5854142a668515963fa93ef037a3074342f65f91ee5aa75f6553b24977d0011453
6
+ metadata.gz: af00b5703f9677aa28ae0e7ae5422440931e246d90ef0f3b2ea0166d4e85b53e2c259e22568e77fa5c65bac992b2d118bb0742a616dd916f30ab08bb8c9ce5d2
7
+ data.tar.gz: d46be75bc55cf3ab8fa89f8c33af26c9a139098b680153a62b750a05f15130fe61802cde9955ca8731f0a046d77b548050090ecd5c58936deea169ae0cc432b0
data/README.md CHANGED
@@ -108,5 +108,8 @@ end
108
108
  - [ ] Add the ability to specify the api controller path (I.E. app/controllers/api/v2)
109
109
  - [ ] Add the ability to inject the resource route into the routes file in the resource generators
110
110
 
111
+ ## Code Of Conduct
112
+ Wildland Open Source [Code Of Conduct](https://github.com/wildland/code-of-conduct)
113
+
111
114
  ## License
112
115
  Copyright (c) 2014, Api Me is developed and maintained by Sam Clopton, and is released under the open MIT Licence.
data/api_me.gemspec CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |s|
9
9
  s.version = ApiMe::VERSION
10
10
  s.authors = ['Sam Clopton', 'Joe Weakley']
11
11
  s.email = ['samsinite@gmail.com']
12
- s.homepage = 'https://github.com/inigo/api_me'
12
+ s.homepage = 'https://github.com/wildland/api_me'
13
13
  s.summary = 'Api Me'
14
14
  s.description = "This friendly library gives you helpers and generators to assist building RESTful API's in your Rails app."
15
15
  s.license = 'MIT'
data/lib/api_me.rb CHANGED
@@ -11,6 +11,7 @@ module ApiMe
11
11
 
12
12
  included do
13
13
  rescue_from Pundit::NotAuthorizedError, with: :user_not_authorized
14
+ rescue_from ActiveRecord::RecordNotFound, with: :resource_not_found
14
15
  end
15
16
 
16
17
  module ClassMethods
@@ -73,7 +74,7 @@ module ApiMe
73
74
  end
74
75
 
75
76
  def show
76
- @object = model_klass.find(params[:id])
77
+ @object = find_resource
77
78
  authorize @object
78
79
 
79
80
  render json: @object, serializer: serializer_klass
@@ -90,7 +91,7 @@ module ApiMe
90
91
  end
91
92
 
92
93
  def update
93
- @object = model_klass.find(params[:id])
94
+ @object = find_resource
94
95
  authorize @object
95
96
  @object.update!(object_params)
96
97
 
@@ -100,14 +101,14 @@ module ApiMe
100
101
  end
101
102
 
102
103
  def destroy
103
- @object = model_klass.find(params[:id])
104
+ @object = find_resource
104
105
  authorize @object
105
106
  @object.destroy
106
107
 
107
108
  render status: 204, nothing: true
108
109
  end
109
110
 
110
- private
111
+ protected
111
112
 
112
113
  def object_params
113
114
  params.require(params_klass_symbol).permit(*policy(@object || model_klass).permitted_attributes)
@@ -127,6 +128,10 @@ module ApiMe
127
128
  render json: payload, status: 403
128
129
  end
129
130
 
131
+ def resource_not_found
132
+ render status: 404, nothing: true
133
+ end
134
+
130
135
  def model_klass
131
136
  self.class.model_klass
132
137
  end
@@ -150,4 +155,8 @@ module ApiMe
150
155
  def filter_params
151
156
  params[:filters]
152
157
  end
158
+
159
+ def find_resource
160
+ model_klass.find_by_id!(params[:id])
161
+ end
153
162
  end
@@ -1,3 +1,3 @@
1
1
  module ApiMe
2
- VERSION = '0.4.0'
2
+ VERSION = '0.4.1'
3
3
  end
@@ -15,6 +15,14 @@ describe 'Users API' do
15
15
  expect(json['users'].length).to eq(users.count)
16
16
  end
17
17
 
18
+ it 'returns a 404 for a user that does not exist' do
19
+ invalid_user_id = User.maximum(:id).to_i + 1
20
+
21
+ get '/api/v1/users/' + invalid_user_id.to_s + '/'
22
+
23
+ expect(last_response.status).to eq(404)
24
+ end
25
+
18
26
  it 'sends an individual user' do
19
27
  user = User.create(username: 'Test')
20
28
 
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.4.0
4
+ version: 0.4.1
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: 2015-04-21 00:00:00.000000000 Z
12
+ date: 2015-07-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
@@ -210,7 +210,7 @@ files:
210
210
  - spec/internal/log/.gitignore
211
211
  - spec/internal/public/favicon.ico
212
212
  - spec/spec_helper.rb
213
- homepage: https://github.com/inigo/api_me
213
+ homepage: https://github.com/wildland/api_me
214
214
  licenses:
215
215
  - MIT
216
216
  metadata: {}
@@ -231,7 +231,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
231
231
  version: '0'
232
232
  requirements: []
233
233
  rubyforge_project:
234
- rubygems_version: 2.4.6
234
+ rubygems_version: 2.2.2
235
235
  signing_key:
236
236
  specification_version: 4
237
237
  summary: Api Me