introspective_grape 0.6.1 → 0.7.0

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.
Files changed (70) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +85 -84
  3. data/.ruby-version +1 -1
  4. data/CHANGELOG.md +10 -0
  5. data/Gemfile +38 -22
  6. data/README.md +13 -20
  7. data/introspective_grape.gemspec +41 -64
  8. data/lib/introspective_grape/api.rb +469 -461
  9. data/lib/introspective_grape/camel_snake.rb +3 -3
  10. data/lib/introspective_grape/create_helpers.rb +25 -25
  11. data/lib/introspective_grape/filters.rb +5 -3
  12. data/lib/introspective_grape/route.rb +11 -0
  13. data/lib/introspective_grape/traversal.rb +56 -56
  14. data/lib/introspective_grape/validators.rb +37 -36
  15. data/lib/introspective_grape/version.rb +5 -5
  16. data/lib/introspective_grape.rb +1 -0
  17. data/spec/dummy/Gemfile +24 -23
  18. data/spec/dummy/app/api/{api_helpers.rb → authentication_helper.rb} +38 -38
  19. data/spec/dummy/app/api/dummy/chat_api.rb +1 -1
  20. data/spec/dummy/app/api/dummy/company_api.rb +1 -1
  21. data/spec/dummy/app/api/dummy/location_api.rb +1 -1
  22. data/spec/dummy/app/api/dummy/project_api.rb +2 -2
  23. data/spec/dummy/app/api/dummy/role_api.rb +1 -1
  24. data/spec/dummy/app/api/dummy/sessions.rb +2 -2
  25. data/spec/dummy/app/api/dummy/user_api.rb +1 -1
  26. data/spec/dummy/app/api/dummy_api.rb +60 -61
  27. data/spec/dummy/app/api/error_handlers.rb +6 -6
  28. data/spec/dummy/app/api/permissions_helper.rb +7 -7
  29. data/spec/dummy/app/helpers/current.rb +3 -3
  30. data/spec/dummy/app/models/abstract_adapter.rb +11 -8
  31. data/spec/dummy/app/models/chat_message.rb +34 -34
  32. data/spec/dummy/app/models/chat_user.rb +16 -16
  33. data/spec/dummy/app/models/company.rb +3 -2
  34. data/spec/dummy/app/models/location.rb +26 -26
  35. data/spec/dummy/app/models/role.rb +30 -30
  36. data/spec/dummy/app/models/team.rb +14 -14
  37. data/spec/dummy/app/models/user/chatter.rb +79 -79
  38. data/spec/dummy/app/models/user.rb +2 -0
  39. data/spec/dummy/bin/bundle +3 -3
  40. data/spec/dummy/bin/rails +4 -4
  41. data/spec/dummy/bin/setup +36 -36
  42. data/spec/dummy/bin/update +31 -31
  43. data/spec/dummy/bin/yarn +11 -11
  44. data/spec/dummy/config/application.rb +30 -30
  45. data/spec/dummy/config/boot.rb +3 -3
  46. data/spec/dummy/config/environment.rb +5 -5
  47. data/spec/dummy/config/environments/development.rb +54 -54
  48. data/spec/dummy/config/environments/production.rb +81 -81
  49. data/spec/dummy/config/environments/test.rb +47 -47
  50. data/spec/dummy/config/initializers/application_controller_renderer.rb +8 -8
  51. data/spec/dummy/config/initializers/assets.rb +14 -14
  52. data/spec/dummy/config/initializers/content_security_policy.rb +25 -25
  53. data/spec/dummy/config/initializers/cookies_serializer.rb +5 -5
  54. data/spec/dummy/config/initializers/new_framework_defaults_5_2.rb +38 -38
  55. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -14
  56. data/spec/dummy/config/locales/en.yml +33 -33
  57. data/spec/dummy/config/routes.rb +1 -1
  58. data/spec/dummy/config/storage.yml +34 -34
  59. data/spec/models/image_spec.rb +10 -10
  60. data/spec/rails_helper.rb +1 -2
  61. data/spec/requests/chat_api_spec.rb +1 -1
  62. data/spec/requests/company_api_spec.rb +1 -1
  63. data/spec/requests/location_api_spec.rb +1 -1
  64. data/spec/requests/project_api_spec.rb +185 -185
  65. data/spec/requests/role_api_spec.rb +1 -1
  66. data/spec/requests/user_api_spec.rb +221 -221
  67. data/spec/support/request_helpers.rb +22 -22
  68. metadata +9 -192
  69. data/spec/dummy/.ruby-version +0 -1
  70. data/spec/dummy/config/initializers/inflections.rb +0 -16
@@ -1,185 +1,185 @@
1
- require 'rails_helper'
2
-
3
- describe Dummy::ProjectAPI, type: :request do
4
- before :all do
5
- [User,Project,Company,Location].map(&:destroy_all)
6
- cm = User.make!(email:'company.admin@springshot.com')
7
- pm = User.make!(email:'project.admin@springshot.com')
8
-
9
- 2.times { Project.make! }
10
-
11
- c = Company.make!(name:"Sprockets")
12
- p = Project.make!(name:"Manufacture Sprockets", owner: c)
13
- Project.make!(name:"Disassemble Sprockets", owner: c)
14
-
15
- cm.admin_companies.push c
16
- pm.admin_projects.push p
17
-
18
- cm.save!
19
- pm.save!
20
- end
21
-
22
- let(:company) { Company.find_by_name("Sprockets") }
23
- let(:project) { Project.find_by_name("Manufacture Sprockets") }
24
-
25
- context "As a super admin" do
26
- it "should return a list of all projects" do
27
- get '/api/v1/projects', params: { per_page: 10, offset: 0 }
28
- response.should be_successful
29
- json.length.should == Project.count
30
- json.map{|c| c['id'].to_i}.include?(project.id).should == true
31
- end
32
-
33
- it "should return the specified project" do
34
- get "/api/v1/projects/#{project.id}"
35
- response.should be_successful
36
- json['name'].should == project.name
37
- end
38
-
39
- it "should return an error if the project doesn't exist" do
40
- get "/api/v1/projects/#{Project.last.id+1}"
41
- response.code.should == "404"
42
- end
43
-
44
- context "edit a project team" do
45
-
46
- before(:each) do
47
- @team = Team.make!(project: project)
48
- @u1 = User.make!
49
- @u2 = User.make!
50
- UserProjectJob.make!(project: project, job: project.jobs.first, user: @u1)
51
- UserProjectJob.make!(project: project, job: project.jobs.first, user: @u2)
52
- end
53
-
54
- context "via nested attributes" do
55
- it "should create a team with users" do
56
- count = Team.count
57
- p = {
58
- name: 'New Team', creator_id: @u1.id, team_users_attributes: [{ user_id: @u1.id }, { user_id: @u2.id }]
59
- }
60
- post "/api/v1/projects/#{project.id}/teams", params: p
61
- response.should be_successful
62
-
63
- Team.count.should eq count+1
64
- Team.last.name.should == 'New Team'
65
- Team.last.users.to_a.should == [@u1,@u2]
66
- end
67
-
68
- it "should add a team member" do
69
- p = { team_users_attributes: [
70
- { user_id: @u1.id }, { user_id: @u2.id }
71
- ] }
72
- put "/api/v1/projects/#{project.id}/teams/#{@team.id}", params: p
73
- response.should be_successful
74
-
75
- Team.last.users.to_a.should == [@u1,@u2]
76
- end
77
-
78
- it "should delete a team member" do
79
- @team.users << [@u1,@u2]
80
- @team.save!
81
- p = { team_users_attributes: [
82
- { id: @team.team_users.where(user_id:@u1.id).first.id, _destroy: 1 }
83
- ] }
84
- put "/api/v1/projects/#{project.id}/teams/#{@team.id}", params: p
85
- response.should be_successful
86
- Team.last.users.to_a.should == [@u2]
87
- end
88
- end
89
-
90
- context "edit a project team via nested routes" do
91
- it "should add a team member" do
92
- p = { user_id: @u1.id }
93
- post "/api/v1/projects/#{project.id}/teams/#{@team.id}/team_users", params: p
94
- response.should be_successful
95
- Team.last.users.to_a.should == [@u1]
96
- end
97
-
98
- it "should delete a team member" do
99
- @team.users << [@u1,@u2]
100
- @team.save!
101
- id = @team.team_users.where(user_id:@u1.id).first.id
102
- delete "/api/v1/projects/#{project.id}/teams/#{@team.id}/team_users/#{id}"
103
- response.should be_successful
104
- Team.last.users.to_a.should == [@u2]
105
- end
106
- end
107
- end
108
- end
109
-
110
- context "As a company admin" do
111
- before :all do
112
- @without_authentication = true
113
- end
114
-
115
- before :each do
116
- Grape::Endpoint.before_each do |endpoint|
117
- allow(endpoint).to receive(:current_user) do
118
- User.find_by_email("company.admin@springshot.com")
119
- end
120
- end
121
- end
122
-
123
- it "should return a list of all the company's projects" do
124
- get '/api/v1/projects', params: { offset: 0 }
125
- response.should be_successful
126
- json.length.should == 2
127
- json.map{|c| c['name']}.include?("Manufacture Sprockets").should == true
128
- json.map{|c| c['name']}.include?("Disassemble Sprockets").should == true
129
- end
130
-
131
- end
132
-
133
- context "As a project admin" do
134
- before :all do
135
- @without_authentication = true
136
- end
137
- before :each do
138
- Grape::Endpoint.before_each do |endpoint|
139
- allow(endpoint).to receive(:current_user) do
140
- User.find_by_email("project.admin@springshot.com")
141
- end
142
- end
143
- end
144
-
145
- it "should return a list of all the project admin's projects" do
146
- get '/api/v1/projects', params: { offset: 0 }
147
- response.should be_successful
148
- json.length.should == 1
149
- json.map{|c| c['name']}.include?("Manufacture Sprockets").should == true
150
- json.map{|c| c['name']}.include?("Disassemble Sprockets").should == false
151
- end
152
- end
153
-
154
- context :pagination do
155
- before(:all) do
156
- Project.destroy_all
157
- 20.times { Project.make! }
158
- end
159
-
160
- it "should return the project API's declared default paginated results" do
161
- get '/api/v1/projects'
162
- response.should be_successful
163
- json.length.should == 2
164
- json.first['id'].should eq Project.all[2].id
165
- json.second['id'].should eq Project.all[3].id
166
- response.headers.slice("X-Total", "X-Total-Pages", "X-Per-Page", "X-Page", "X-Next-Page", "X-Prev-Page", "X-Offset").values.should eq ["20", "9", "2", "1", "2", "", "2"]
167
- end
168
-
169
- it "should return the request number of results" do
170
- get '/api/v1/projects', params: { per_page: 9, offset: 9 }
171
- response.should be_successful
172
- json.size.should == 9
173
- json.map {|j| j['id']}.should eq Project.all[9..17].map(&:id)
174
- response.headers.slice("X-Total", "X-Total-Pages", "X-Per-Page", "X-Page", "X-Next-Page", "X-Prev-Page", "X-Offset").values.should eq ["20", "2", "9", "1", "2", "", "9"]
175
- end
176
-
177
- it "should respect the maximum number of results" do
178
- get '/api/v1/projects', params: { per_page: 20, offset: 0 }
179
- response.code.should eq "400"
180
- json['error'].should eq "per_page must be less than or equal 10"
181
- end
182
- end
183
-
184
-
185
- end
1
+ require 'rails_helper'
2
+
3
+ describe Dummy::ProjectApi, type: :request do
4
+ before :all do
5
+ [User,Project,Company,Location].map(&:destroy_all)
6
+ cm = User.make!(email:'company.admin@springshot.com')
7
+ pm = User.make!(email:'project.admin@springshot.com')
8
+
9
+ 2.times { Project.make! }
10
+
11
+ c = Company.make!(name:"Sprockets")
12
+ p = Project.make!(name:"Manufacture Sprockets", owner: c)
13
+ Project.make!(name:"Disassemble Sprockets", owner: c)
14
+
15
+ cm.admin_companies.push c
16
+ pm.admin_projects.push p
17
+
18
+ cm.save!
19
+ pm.save!
20
+ end
21
+
22
+ let(:company) { Company.find_by_name("Sprockets") }
23
+ let(:project) { Project.find_by_name("Manufacture Sprockets") }
24
+
25
+ context "As a super admin" do
26
+ it "should return a list of all projects" do
27
+ get '/api/v1/projects', params: { per_page: 10, offset: 0 }
28
+ response.should be_successful
29
+ json.length.should == Project.count
30
+ json.map{|c| c['id'].to_i}.include?(project.id).should == true
31
+ end
32
+
33
+ it "should return the specified project" do
34
+ get "/api/v1/projects/#{project.id}"
35
+ response.should be_successful
36
+ json['name'].should == project.name
37
+ end
38
+
39
+ it "should return an error if the project doesn't exist" do
40
+ get "/api/v1/projects/#{Project.last.id+1}"
41
+ response.code.should == "404"
42
+ end
43
+
44
+ context "edit a project team" do
45
+
46
+ before(:each) do
47
+ @team = Team.make!(project: project)
48
+ @u1 = User.make!
49
+ @u2 = User.make!
50
+ UserProjectJob.make!(project: project, job: project.jobs.first, user: @u1)
51
+ UserProjectJob.make!(project: project, job: project.jobs.first, user: @u2)
52
+ end
53
+
54
+ context "via nested attributes" do
55
+ it "should create a team with users" do
56
+ count = Team.count
57
+ p = {
58
+ name: 'New Team', creator_id: @u1.id, team_users_attributes: [{ user_id: @u1.id }, { user_id: @u2.id }]
59
+ }
60
+ post "/api/v1/projects/#{project.id}/teams", params: p
61
+ response.should be_successful
62
+
63
+ Team.count.should eq count+1
64
+ Team.last.name.should == 'New Team'
65
+ Team.last.users.to_a.should == [@u1,@u2]
66
+ end
67
+
68
+ it "should add a team member" do
69
+ p = { team_users_attributes: [
70
+ { user_id: @u1.id }, { user_id: @u2.id }
71
+ ] }
72
+ put "/api/v1/projects/#{project.id}/teams/#{@team.id}", params: p
73
+ response.should be_successful
74
+
75
+ Team.last.users.to_a.should == [@u1,@u2]
76
+ end
77
+
78
+ it "should delete a team member" do
79
+ @team.users << [@u1,@u2]
80
+ @team.save!
81
+ p = { team_users_attributes: [
82
+ { id: @team.team_users.where(user_id:@u1.id).first.id, _destroy: 1 }
83
+ ] }
84
+ put "/api/v1/projects/#{project.id}/teams/#{@team.id}", params: p
85
+ response.should be_successful
86
+ Team.last.users.to_a.should == [@u2]
87
+ end
88
+ end
89
+
90
+ context "edit a project team via nested routes" do
91
+ it "should add a team member" do
92
+ p = { user_id: @u1.id }
93
+ post "/api/v1/projects/#{project.id}/teams/#{@team.id}/team_users", params: p
94
+ response.should be_successful
95
+ Team.last.users.to_a.should == [@u1]
96
+ end
97
+
98
+ it "should delete a team member" do
99
+ @team.users << [@u1,@u2]
100
+ @team.save!
101
+ id = @team.team_users.where(user_id:@u1.id).first.id
102
+ delete "/api/v1/projects/#{project.id}/teams/#{@team.id}/team_users/#{id}"
103
+ response.should be_successful
104
+ Team.last.users.to_a.should == [@u2]
105
+ end
106
+ end
107
+ end
108
+ end
109
+
110
+ context "As a company admin" do
111
+ before :all do
112
+ @without_authentication = true
113
+ end
114
+
115
+ before :each do
116
+ Grape::Endpoint.before_each do |endpoint|
117
+ allow(endpoint).to receive(:current_user) do
118
+ User.find_by_email("company.admin@springshot.com")
119
+ end
120
+ end
121
+ end
122
+
123
+ it "should return a list of all the company's projects" do
124
+ get '/api/v1/projects', params: { offset: 0 }
125
+ response.should be_successful
126
+ json.length.should == 2
127
+ json.map{|c| c['name']}.include?("Manufacture Sprockets").should == true
128
+ json.map{|c| c['name']}.include?("Disassemble Sprockets").should == true
129
+ end
130
+
131
+ end
132
+
133
+ context "As a project admin" do
134
+ before :all do
135
+ @without_authentication = true
136
+ end
137
+ before :each do
138
+ Grape::Endpoint.before_each do |endpoint|
139
+ allow(endpoint).to receive(:current_user) do
140
+ User.find_by_email("project.admin@springshot.com")
141
+ end
142
+ end
143
+ end
144
+
145
+ it "should return a list of all the project admin's projects" do
146
+ get '/api/v1/projects', params: { offset: 0 }
147
+ response.should be_successful
148
+ json.length.should == 1
149
+ json.map{|c| c['name']}.include?("Manufacture Sprockets").should == true
150
+ json.map{|c| c['name']}.include?("Disassemble Sprockets").should == false
151
+ end
152
+ end
153
+
154
+ context :pagination do
155
+ before(:all) do
156
+ Project.destroy_all
157
+ 20.times { Project.make! }
158
+ end
159
+
160
+ it "should return the project API's declared default paginated results" do
161
+ get '/api/v1/projects'
162
+ response.should be_successful
163
+ json.length.should == 2
164
+ json.first['id'].should eq Project.all[2].id
165
+ json.second['id'].should eq Project.all[3].id
166
+ response.headers.slice("X-Total", "X-Total-Pages", "X-Per-Page", "X-Page", "X-Next-Page", "X-Prev-Page", "X-Offset").values.should eq ["20", "9", "2", "1", "2", "", "2"]
167
+ end
168
+
169
+ it "should return the request number of results" do
170
+ get '/api/v1/projects', params: { per_page: 9, offset: 9 }
171
+ response.should be_successful
172
+ json.size.should == 9
173
+ json.map {|j| j['id']}.should eq Project.all[9..17].map(&:id)
174
+ response.headers.slice("X-Total", "X-Total-Pages", "X-Per-Page", "X-Page", "X-Next-Page", "X-Prev-Page", "X-Offset").values.should eq ["20", "2", "9", "1", "2", "", "9"]
175
+ end
176
+
177
+ it "should respect the maximum number of results" do
178
+ get '/api/v1/projects', params: { per_page: 20, offset: 0 }
179
+ response.code.should eq "400"
180
+ json['error'].should eq "per_page must be less than or equal 10"
181
+ end
182
+ end
183
+
184
+
185
+ end
@@ -1,5 +1,5 @@
1
1
  require 'rails_helper'
2
- describe Dummy::RoleAPI, type: :request do
2
+ describe Dummy::RoleApi, type: :request do
3
3
  let(:role) { Role.last }
4
4
  let(:user) { User.last }
5
5
  let(:company) { Company.last }