introspective_grape 0.5.7 → 0.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +22 -18
- data/README.md +2 -0
- data/introspective_grape.gemspec +5 -4
- data/lib/introspective_grape/api.rb +461 -459
- data/lib/introspective_grape/create_helpers.rb +25 -25
- data/lib/introspective_grape/traversal.rb +1 -1
- data/lib/introspective_grape/validators.rb +36 -36
- data/lib/introspective_grape/version.rb +5 -5
- data/spec/dummy/Gemfile +23 -22
- data/spec/dummy/app/api/api_helpers.rb +38 -37
- data/spec/dummy/app/api/dummy_api.rb +61 -61
- data/spec/dummy/app/api/permissions_helper.rb +7 -7
- data/spec/dummy/app/helpers/current.rb +3 -0
- data/spec/dummy/app/models/chat_message.rb +34 -34
- data/spec/dummy/app/models/chat_user.rb +16 -16
- data/spec/dummy/app/models/location.rb +26 -26
- data/spec/dummy/app/models/role.rb +30 -30
- data/spec/dummy/app/models/team.rb +14 -9
- data/spec/dummy/app/models/user/chatter.rb +79 -79
- data/spec/dummy/bin/bundle +3 -3
- data/spec/dummy/bin/rails +4 -4
- data/spec/dummy/bin/setup +36 -29
- data/spec/dummy/bin/update +31 -0
- data/spec/dummy/bin/yarn +11 -0
- data/spec/dummy/config/application.rb +30 -37
- data/spec/dummy/config/boot.rb +3 -6
- data/spec/dummy/config/environment.rb +5 -11
- data/spec/dummy/config/environments/development.rb +54 -42
- data/spec/dummy/config/environments/production.rb +81 -79
- data/spec/dummy/config/environments/test.rb +47 -44
- data/spec/dummy/config/initializers/application_controller_renderer.rb +8 -0
- data/spec/dummy/config/initializers/assets.rb +14 -11
- data/spec/dummy/config/initializers/content_security_policy.rb +25 -0
- data/spec/dummy/config/initializers/cookies_serializer.rb +5 -3
- data/spec/dummy/config/initializers/inflections.rb +16 -16
- data/spec/dummy/config/initializers/new_framework_defaults_5_2.rb +38 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -14
- data/spec/dummy/config/locales/en.yml +33 -23
- data/spec/dummy/config/storage.yml +34 -0
- data/spec/models/image_spec.rb +10 -14
- data/spec/requests/project_api_spec.rb +185 -182
- data/spec/requests/user_api_spec.rb +221 -221
- data/spec/support/request_helpers.rb +22 -21
- metadata +20 -157
@@ -1,182 +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
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
before :
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
response.
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
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
|