introspective_grape 0.3.3 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +5 -5
  2. data/.travis.yml +5 -52
  3. data/CHANGELOG.md +46 -0
  4. data/Gemfile +2 -0
  5. data/README.md +15 -0
  6. data/gemfiles/{Gemfile.rails.4.2.7.1 → Gemfile.rails.5.0.0} +5 -4
  7. data/gemfiles/Gemfile.rails.5.0.1 +1 -0
  8. data/gemfiles/{Gemfile.rails.4.2.7.1.new.swagger → Gemfile.rails.5.1.0} +5 -3
  9. data/gemfiles/{Gemfile.rails.3.2.22 → Gemfile.rails.5.2.0} +5 -4
  10. data/gemfiles/Gemfile.rails.master +1 -0
  11. data/introspective_grape.gemspec +15 -13
  12. data/lib/introspective_grape.rb +1 -1
  13. data/lib/introspective_grape/api.rb +38 -31
  14. data/lib/introspective_grape/camel_snake.rb +30 -31
  15. data/lib/introspective_grape/create_helpers.rb +8 -3
  16. data/lib/introspective_grape/version.rb +1 -1
  17. data/spec/dummy/Gemfile +6 -3
  18. data/spec/dummy/app/api/api_helpers.rb +2 -0
  19. data/spec/dummy/app/api/dummy/company_api.rb +1 -1
  20. data/spec/dummy/app/models/image.rb +1 -1
  21. data/spec/dummy/app/models/role.rb +1 -1
  22. data/spec/dummy/app/models/user.rb +2 -2
  23. data/spec/dummy/config.ru +12 -0
  24. data/spec/dummy/config/application.rb +1 -1
  25. data/spec/dummy/config/environments/development.rb +3 -3
  26. data/spec/dummy/config/initializers/paperclip_adapter.rb +1 -1
  27. data/spec/dummy/db/migrate/20190325231304_add_test_data.rb +5 -0
  28. data/spec/dummy/db/schema.rb +154 -173
  29. data/spec/requests/chat_api_spec.rb +26 -26
  30. data/spec/requests/company_api_spec.rb +15 -15
  31. data/spec/requests/location_api_spec.rb +18 -18
  32. data/spec/requests/project_api_spec.rb +21 -21
  33. data/spec/requests/role_api_spec.rb +4 -4
  34. data/spec/requests/sessions_api_spec.rb +10 -10
  35. data/spec/requests/swagger_spec.rb +1 -1
  36. data/spec/requests/user_api_spec.rb +34 -34
  37. metadata +33 -44
  38. data/gemfiles/2.0.0-Gemfile +0 -22
  39. data/gemfiles/2.2.0-Gemfile +0 -21
  40. data/gemfiles/Gemfile.rails.4.1.13 +0 -13
  41. data/gemfiles/Gemfile.rails.4.2.8 +0 -12
@@ -13,14 +13,14 @@ describe Dummy::RoleAPI, type: :request do
13
13
 
14
14
  it 'should return a list of user roles' do
15
15
  get '/api/v1/roles'
16
- response.should be_success
16
+ response.should be_successful
17
17
  json.length.should == 1
18
18
  json.first['id'].to_i.should == role.id
19
19
  end
20
20
 
21
21
  it 'should return the specified user role' do
22
22
  get "/api/v1/roles/#{role.id}"
23
- response.should be_success
23
+ response.should be_successful
24
24
  json['email'].should == role.email
25
25
  end
26
26
 
@@ -30,13 +30,13 @@ describe Dummy::RoleAPI, type: :request do
30
30
  end
31
31
 
32
32
  it 'should not duplicate user roles' do
33
- post '/api/v1/roles', { user_id: user.id, ownable_type: 'Company', ownable_id: company.id }
33
+ post '/api/v1/roles', params: { user_id: user.id, ownable_type: 'Company', ownable_id: company.id }
34
34
  response.code.should == '400'
35
35
  json['error'].should =~ /user has already been assigned that role/
36
36
  end
37
37
 
38
38
  it 'validates ownable type value specified in grape_validations' do
39
- post '/api/v1/roles', { user_id: user.id, ownable_type: 'NotCompany' }
39
+ post '/api/v1/roles', params: { user_id: user.id, ownable_type: 'NotCompany' }
40
40
  response.code.should == '400'
41
41
  json['error'].should eq "ownable_type does not have a valid value"
42
42
  end
@@ -12,16 +12,16 @@ describe Dummy::Sessions, type: :request do
12
12
  context :sign_in do
13
13
 
14
14
  it "should set a user token on login" do
15
- post '/api/v1/sessions', { login: user.email, password: 'abc12345', token: true }
16
- response.should be_success
15
+ post '/api/v1/sessions', params: { login: user.email, password: 'abc12345', token: true }
16
+ response.should be_successful
17
17
  json['id'].to_i.should == user.id
18
18
  json['email'].should == user.email
19
19
  json['authentication_token'].should be_truthy
20
20
  end
21
21
 
22
22
  it "should not set a token if the login fails" do
23
- post '/api/v1/sessions', { login: user.email, password: 'bad password', token: true }
24
- response.should_not be_success
23
+ post '/api/v1/sessions', params: { login: user.email, password: 'bad password', token: true }
24
+ response.should_not be_successful
25
25
  json['error'].should be_truthy
26
26
  json['error']['type'].should == 'unauthenticated'
27
27
  user.authentication_token.should be_nil
@@ -32,8 +32,8 @@ describe Dummy::Sessions, type: :request do
32
32
  it "should reset a user's auth token" do
33
33
  user.authentication_token = "1234567890"
34
34
  user.save!
35
- delete "/api/v1/sessions", { api_key: "1234567890" }
36
- response.should be_success
35
+ delete "/api/v1/sessions", params: { api_key: "1234567890" }
36
+ response.should be_successful
37
37
  user.reload
38
38
  user.authentication_token.should be_nil
39
39
  end
@@ -41,12 +41,12 @@ describe Dummy::Sessions, type: :request do
41
41
  it "signing out an already signed-out user should look fine, right?" do
42
42
  user.authentication_token = "1234567890"
43
43
  user.save!
44
- delete "/api/v1/sessions", { api_key: "1234567890" }
45
- response.should be_success
44
+ delete "/api/v1/sessions", params: { api_key: "1234567890" }
45
+ response.should be_successful
46
46
  user.reload
47
47
  user.authentication_token.should be_nil
48
- delete "/api/v1/sessions", { api_key: "1234567890" }
49
- response.should be_success
48
+ delete "/api/v1/sessions", params: { api_key: "1234567890" }
49
+ response.should be_successful
50
50
  user.reload
51
51
  user.authentication_token.should be_nil
52
52
  end
@@ -5,7 +5,7 @@ describe GrapeSwagger, type: :request do
5
5
 
6
6
  it "should render swagger docs for the api" do
7
7
  get '/api/v1/swagger_doc'
8
- response.should be_success
8
+ response.should be_successful
9
9
  json = JSON.parse( response.body )
10
10
  if Gem::Version.new( GrapeSwagger::VERSION ) <= Gem::Version.new('0.11.0')
11
11
  json['apiVersion'].should == '0.1'
@@ -16,7 +16,7 @@ describe Dummy::UserAPI, type: :request do
16
16
 
17
17
  it "should return a list of users" do
18
18
  get '/api/v1/users'
19
- response.should be_success
19
+ response.should be_successful
20
20
  json.length.should == 1
21
21
  json.first['id'].to_i.should == user.id
22
22
  json.first['first_name'].should == user.first_name
@@ -30,8 +30,8 @@ describe Dummy::UserAPI, type: :request do
30
30
  6.times { User.make! }
31
31
  u = User.last
32
32
  u.update_column(:created_at, 1.day.ago)
33
- get '/api/v1/users', { created_at_start: 2.day.ago, created_at_end: 8.hours.ago }
34
- response.should be_success
33
+ get '/api/v1/users', params: { created_at_start: 2.day.ago, created_at_end: 8.hours.ago }
34
+ response.should be_successful
35
35
  json.length.should eq 1
36
36
  json.first['id'].to_i.should eq u.id
37
37
  json.first['first_name'].should eq u.first_name
@@ -40,15 +40,15 @@ describe Dummy::UserAPI, type: :request do
40
40
  it "should accept a comma separated list of ids" do
41
41
  4.times { User.make! }
42
42
  user_ids = [User.first,User.second,User.third].map(&:id)
43
- get '/api/v1/users', { id: user_ids.join(',') }
44
- response.should be_success
43
+ get '/api/v1/users', params: { id: user_ids.join(',') }
44
+ response.should be_successful
45
45
  json.length.should eq 3
46
46
  json.map {|j| j['id'] }.should eq user_ids
47
47
  end
48
48
 
49
49
  it "should not expose users' encrypted_passwords" do
50
50
  get "/api/v1/users"
51
- response.should be_success
51
+ response.should be_successful
52
52
  json.first['encrypted_password'].should be_nil
53
53
  end
54
54
  end
@@ -57,13 +57,13 @@ describe Dummy::UserAPI, type: :request do
57
57
  context :show do
58
58
  it "should return the specified user" do
59
59
  get "/api/v1/users/#{user.id}"
60
- response.should be_success
60
+ response.should be_successful
61
61
  json['email'].should == user.email
62
62
  end
63
63
 
64
64
  it "should not expose a user's encrypted_password" do
65
65
  get "/api/v1/users/#{user.id}"
66
- response.should be_success
66
+ response.should be_successful
67
67
  json['encrypted_password'].should be_nil
68
68
  end
69
69
 
@@ -77,31 +77,31 @@ describe Dummy::UserAPI, type: :request do
77
77
  context :create do
78
78
 
79
79
  it "should create a user and send the confirmation email" do
80
- post "/api/v1/users", { email: 'email@test.com', password: 'abc12345' }
81
- response.should be_success
80
+ post "/api/v1/users", params: { email: 'email@test.com', password: 'abc12345' }
81
+ response.should be_successful
82
82
  json['email'].should == user.email
83
83
  User.last.confirmed_at.should == nil
84
84
  User.last.confirmation_sent_at.should_not == nil
85
85
  end
86
86
 
87
87
  it "should create a user and skip the confirmation email" do
88
- post "/api/v1/users", { email: 'email@test.com', password: 'abc12345', skip_confirmation_email: true }
89
- response.should be_success
88
+ post "/api/v1/users", params: { email: 'email@test.com', password: 'abc12345', skip_confirmation_email: true }
89
+ response.should be_successful
90
90
  json['email'].should == user.email
91
91
  User.last.confirmed_at.should_not == nil
92
92
  User.last.confirmation_sent_at.should == nil
93
93
  end
94
94
 
95
95
  it "should validate a new user" do
96
- post "/api/v1/users", { email: 'a'*257, password: '' }
96
+ post "/api/v1/users", params: { email: 'a'*257, password: '' }
97
97
  response.code.should == "400"
98
98
  json['error'].should == "Email: is invalid, Password: can't be blank"
99
99
  end
100
100
 
101
101
  it "should return only the records that were created at a nested endpoint" do
102
102
  new_company = Company.make!
103
- post "/api/v1/users/#{user.id}/roles", {ownable_type: 'Company', ownable_id: new_company.id}
104
- response.should be_success
103
+ post "/api/v1/users/#{user.id}/roles", params: {ownable_type: 'Company', ownable_id: new_company.id}
104
+ response.should be_successful
105
105
  json.size.should eq 1
106
106
  json.first['ownable_id'].should eq new_company.id
107
107
  end
@@ -117,8 +117,8 @@ describe Dummy::UserAPI, type: :request do
117
117
 
118
118
  it "should create a company admin" do
119
119
  params[:roles_attributes].push(role)
120
- post "/api/v1/users", params
121
- response.should be_success
120
+ post "/api/v1/users", params: params
121
+ response.should be_successful
122
122
  User.last.admin?(company).should be_truthy
123
123
  end
124
124
 
@@ -134,15 +134,15 @@ describe Dummy::UserAPI, type: :request do
134
134
  end
135
135
 
136
136
  it "should set an empty password to an assigned project's default password" do
137
- post "/api/v1/users", params
138
- response.should be_success
137
+ post "/api/v1/users", params: params
138
+ response.should be_successful
139
139
  json['user_project_jobs_attributes'][0]['name'].should == project.name
140
140
  json['user_project_jobs_attributes'][0]['title'].should == job.title
141
141
  end
142
142
 
143
143
  it "should return a validation error if the user's assigned project has no default password" do
144
144
  project.update_attributes(default_password: nil)
145
- post "/api/v1/users", params
145
+ post "/api/v1/users", params: params
146
146
  response.status.should == 400
147
147
  json['error'].should == "Password: can't be blank"
148
148
  end
@@ -154,9 +154,9 @@ describe Dummy::UserAPI, type: :request do
154
154
  it "should upload a user avatar via the root route" do
155
155
  params = { avatar_attributes: { file: Rack::Test::UploadedFile.new(Rails.root+'../fixtures/images/avatar.jpeg', 'image/jpeg', true) } }
156
156
 
157
- put "/api/v1/users/#{user.id}", params
157
+ put "/api/v1/users/#{user.id}", params: params
158
158
 
159
- response.should be_success
159
+ response.should be_successful
160
160
  json['avatar_url'].should eq Image.last.file.url(:medium)
161
161
  user.avatar.should eq Image.last
162
162
  user.avatar_url.should eq Image.last.file.url(:medium)
@@ -165,9 +165,9 @@ describe Dummy::UserAPI, type: :request do
165
165
  it "should upload a user avatar via the nested route, to test the restful api's handling of has_one associations" do
166
166
  params = { file: Rack::Test::UploadedFile.new(Rails.root+'../fixtures/images/avatar.jpeg', 'image/jpeg', true) }
167
167
 
168
- post "/api/v1/users/#{user.id}/avatars", params
168
+ post "/api/v1/users/#{user.id}/avatars", params: params
169
169
 
170
- response.should be_success
170
+ response.should be_successful
171
171
  user.avatar.should == Image.last
172
172
  user.avatar_url.should == Image.last.file.url(:medium)
173
173
  user.avatar_url
@@ -176,8 +176,8 @@ describe Dummy::UserAPI, type: :request do
176
176
  it "should require a devise re-confirmation email to update a user's email address" do
177
177
  new_email = 'new.email@test.com'
178
178
  old_email = user.email
179
- put "/api/v1/users/#{user.id}", { email: new_email }
180
- response.should be_success
179
+ put "/api/v1/users/#{user.id}", params: { email: new_email }
180
+ response.should be_successful
181
181
  user.reload
182
182
  user.email.should == old_email
183
183
  user.unconfirmed_email.should == new_email
@@ -186,16 +186,16 @@ describe Dummy::UserAPI, type: :request do
186
186
 
187
187
  it "should skip the confirmation and update a user's email address" do
188
188
  new_email = 'new.email@test.com'
189
- put "/api/v1/users/#{user.id}", { email: new_email, skip_confirmation_email: true }
190
- response.should be_success
189
+ put "/api/v1/users/#{user.id}", params: { email: new_email, skip_confirmation_email: true }
190
+ response.should be_successful
191
191
  json['email'].should == new_email
192
192
  user.reload
193
193
  user.email.should == new_email
194
194
  end
195
195
 
196
196
  it "should validate the uniqueness of a user role" do
197
- put "/api/v1/users/#{user.id}", { roles_attributes: [{ownable_type: 'Company', ownable_id: company.id}] }
198
- response.should_not be_success
197
+ put "/api/v1/users/#{user.id}", params: { roles_attributes: [{ownable_type: 'Company', ownable_id: company.id}] }
198
+ response.should_not be_successful
199
199
  json['error'].should =~ /user has already been assigned that role/
200
200
  user.admin?(company).should be_truthy
201
201
  end
@@ -203,16 +203,16 @@ describe Dummy::UserAPI, type: :request do
203
203
  it "should update a user to be company admin" do
204
204
  c = Company.make
205
205
  c.save!
206
- put "/api/v1/users/#{user.id}", { roles_attributes: [{ownable_type: 'Company', ownable_id: c.id}] }
207
- response.should be_success
206
+ put "/api/v1/users/#{user.id}", params: { roles_attributes: [{ownable_type: 'Company', ownable_id: c.id}] }
207
+ response.should be_successful
208
208
  user.reload
209
209
  user.admin?(c).should be_truthy
210
210
  end
211
211
 
212
212
  it "should destroy a user's company admin role" do
213
213
  user.admin?(company).should be_truthy
214
- put "/api/v1/users/#{user.id}", { roles_attributes: [{id: user.roles.last.id, _destroy: '1'}] }
215
- response.should be_success
214
+ put "/api/v1/users/#{user.id}", params: { roles_attributes: [{id: user.roles.last.id, _destroy: '1'}] }
215
+ response.should be_successful
216
216
  user.reload
217
217
  user.admin?(company).should be_falsey
218
218
  end
metadata CHANGED
@@ -1,43 +1,49 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: introspective_grape
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josh Buermann
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-07 00:00:00.000000000 Z
11
+ date: 2020-10-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - ">"
18
18
  - !ruby/object:Gem::Version
19
- version: 3.0.0
19
+ version: 5.0.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - ">"
25
25
  - !ruby/object:Gem::Version
26
- version: 3.0.0
26
+ version: 5.0.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: grape
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: 1.2.0
34
+ - - "<"
35
+ - !ruby/object:Gem::Version
36
+ version: 1.2.5
34
37
  type: :runtime
35
38
  prerelease: false
36
39
  version_requirements: !ruby/object:Gem::Requirement
37
40
  requirements:
38
- - - ">="
41
+ - - "~>"
39
42
  - !ruby/object:Gem::Version
40
- version: '0'
43
+ version: 1.2.0
44
+ - - "<"
45
+ - !ruby/object:Gem::Version
46
+ version: 1.2.5
41
47
  - !ruby/object:Gem::Dependency
42
48
  name: grape-entity
43
49
  requirement: !ruby/object:Gem::Requirement
@@ -68,20 +74,6 @@ dependencies:
68
74
  version: '0'
69
75
  - !ruby/object:Gem::Dependency
70
76
  name: kaminari
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - "<"
74
- - !ruby/object:Gem::Version
75
- version: '1.0'
76
- type: :runtime
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - "<"
81
- - !ruby/object:Gem::Version
82
- version: '1.0'
83
- - !ruby/object:Gem::Dependency
84
- name: grape-kaminari
85
77
  requirement: !ruby/object:Gem::Requirement
86
78
  requirements:
87
79
  - - ">="
@@ -126,16 +118,16 @@ dependencies:
126
118
  name: sqlite3
127
119
  requirement: !ruby/object:Gem::Requirement
128
120
  requirements:
129
- - - ">="
121
+ - - "<"
130
122
  - !ruby/object:Gem::Version
131
- version: '0'
123
+ version: 1.4.0
132
124
  type: :development
133
125
  prerelease: false
134
126
  version_requirements: !ruby/object:Gem::Requirement
135
127
  requirements:
136
- - - ">="
128
+ - - "<"
137
129
  - !ruby/object:Gem::Version
138
- version: '0'
130
+ version: 1.4.0
139
131
  - !ruby/object:Gem::Dependency
140
132
  name: rspec-rails
141
133
  requirement: !ruby/object:Gem::Requirement
@@ -168,18 +160,18 @@ dependencies:
168
160
  name: paperclip
169
161
  requirement: !ruby/object:Gem::Requirement
170
162
  requirements:
171
- - - "<"
163
+ - - ">="
172
164
  - !ruby/object:Gem::Version
173
- version: '5.0'
165
+ version: 5.2.0
174
166
  type: :development
175
167
  prerelease: false
176
168
  version_requirements: !ruby/object:Gem::Requirement
177
169
  requirements:
178
- - - "<"
170
+ - - ">="
179
171
  - !ruby/object:Gem::Version
180
- version: '5.0'
172
+ version: 5.2.0
181
173
  - !ruby/object:Gem::Dependency
182
- name: machinist
174
+ name: machinist_redux
183
175
  requirement: !ruby/object:Gem::Requirement
184
176
  requirements:
185
177
  - - ">="
@@ -246,14 +238,10 @@ files:
246
238
  - app/models/.keep
247
239
  - app/views/.keep
248
240
  - bin/rails
249
- - gemfiles/2.0.0-Gemfile
250
- - gemfiles/2.2.0-Gemfile
251
- - gemfiles/Gemfile.rails.3.2.22
252
- - gemfiles/Gemfile.rails.4.1.13
253
- - gemfiles/Gemfile.rails.4.2.7.1
254
- - gemfiles/Gemfile.rails.4.2.7.1.new.swagger
255
- - gemfiles/Gemfile.rails.4.2.8
241
+ - gemfiles/Gemfile.rails.5.0.0
256
242
  - gemfiles/Gemfile.rails.5.0.1
243
+ - gemfiles/Gemfile.rails.5.1.0
244
+ - gemfiles/Gemfile.rails.5.2.0
257
245
  - gemfiles/Gemfile.rails.master
258
246
  - introspective_grape.gemspec
259
247
  - lib/introspective_grape.rb
@@ -379,6 +367,7 @@ files:
379
367
  - spec/dummy/db/migrate/20150820190524_add_user_names.rb
380
368
  - spec/dummy/db/migrate/20150824215701_create_images.rb
381
369
  - spec/dummy/db/migrate/20150909225019_add_password_to_project.rb
370
+ - spec/dummy/db/migrate/20190325231304_add_test_data.rb
382
371
  - spec/dummy/db/schema.rb
383
372
  - spec/dummy/lib/assets/.keep
384
373
  - spec/dummy/log/.keep
@@ -421,17 +410,16 @@ require_paths:
421
410
  - lib
422
411
  required_ruby_version: !ruby/object:Gem::Requirement
423
412
  requirements:
424
- - - "~>"
413
+ - - ">="
425
414
  - !ruby/object:Gem::Version
426
- version: '2.0'
415
+ version: '2.3'
427
416
  required_rubygems_version: !ruby/object:Gem::Requirement
428
417
  requirements:
429
418
  - - ">="
430
419
  - !ruby/object:Gem::Version
431
420
  version: '0'
432
421
  requirements: []
433
- rubyforge_project:
434
- rubygems_version: 2.6.8
422
+ rubygems_version: 3.1.2
435
423
  signing_key:
436
424
  specification_version: 4
437
425
  summary: Introspectively configure deeply nested RESTful Grape APIs for ActiveRecord
@@ -547,6 +535,7 @@ test_files:
547
535
  - spec/dummy/db/migrate/20150820190524_add_user_names.rb
548
536
  - spec/dummy/db/migrate/20150824215701_create_images.rb
549
537
  - spec/dummy/db/migrate/20150909225019_add_password_to_project.rb
538
+ - spec/dummy/db/migrate/20190325231304_add_test_data.rb
550
539
  - spec/dummy/db/schema.rb
551
540
  - spec/dummy/lib/assets/.keep
552
541
  - spec/dummy/log/.keep