unsakini 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +28 -0
- data/Rakefile +34 -0
- data/angular/README.md +31 -0
- data/angular/angular-cli.json +59 -0
- data/angular/karma.conf.js +45 -0
- data/angular/package.json +49 -0
- data/angular/protractor.conf.js +32 -0
- data/angular/src/app/app.component.css +0 -0
- data/angular/src/app/app.component.html +4 -0
- data/angular/src/app/app.component.spec.ts +47 -0
- data/angular/src/app/app.component.ts +10 -0
- data/angular/src/app/app.module.ts +29 -0
- data/angular/src/app/app.routes.module.ts +29 -0
- data/angular/src/app/index.ts +2 -0
- data/angular/src/app/registration/registration.component.css +0 -0
- data/angular/src/app/registration/registration.component.html +14 -0
- data/angular/src/app/registration/registration.component.spec.ts +157 -0
- data/angular/src/app/registration/registration.component.ts +42 -0
- data/angular/src/environments/environment.prod.ts +3 -0
- data/angular/src/environments/environment.ts +8 -0
- data/angular/src/favicon.ico +0 -0
- data/angular/src/index.html +14 -0
- data/angular/src/main.ts +12 -0
- data/angular/src/polyfills.ts +19 -0
- data/angular/src/styles.css +1 -0
- data/angular/src/test.ts +31 -0
- data/angular/src/tsconfig.json +18 -0
- data/angular/src/typings.d.ts +2 -0
- data/angular/tslint.json +114 -0
- data/angular/typings.json +4 -0
- data/app/controllers/api/boards_controller.rb +67 -0
- data/app/controllers/api/comments_controller.rb +51 -0
- data/app/controllers/api/posts_controller.rb +58 -0
- data/app/controllers/api/share_board_controller.rb +118 -0
- data/app/controllers/api/users_controller.rb +27 -0
- data/app/controllers/application_controller.rb +5 -0
- data/app/controllers/concerns/board_owner_controller_concern.rb +38 -0
- data/app/controllers/concerns/comment_owner_controller_concern.rb +33 -0
- data/app/controllers/concerns/logged_in_controller_concern.rb +21 -0
- data/app/controllers/concerns/post_owner_controller_concern.rb +36 -0
- data/app/controllers/concerns/serializer_controller_concern.rb +11 -0
- data/app/controllers/user_token_controller.rb +2 -0
- data/app/controllers/web_base_controller.rb +11 -0
- data/app/models/application_record.rb +5 -0
- data/app/models/board.rb +14 -0
- data/app/models/comment.rb +9 -0
- data/app/models/concerns/encryptable_model_concern.rb +96 -0
- data/app/models/post.rb +12 -0
- data/app/models/user.rb +6 -0
- data/app/models/user_board.rb +71 -0
- data/app/serializers/board_serializer.rb +5 -0
- data/app/serializers/comment_serializer.rb +10 -0
- data/app/serializers/post_serializer.rb +23 -0
- data/app/serializers/user_board_serializer.rb +10 -0
- data/app/serializers/user_serializer.rb +6 -0
- data/config/initializers/unsakini.rb +4 -0
- data/config/routes.rb +22 -0
- data/db/migrate/20161116114222_create_boards.rb +9 -0
- data/db/migrate/20161116200034_create_user_boards.rb +11 -0
- data/db/migrate/20161118031023_create_posts.rb +12 -0
- data/db/migrate/20161118100454_create_comments.rb +11 -0
- data/db/migrate/20161118221508_add_encrypted_password_to_user_board.rb +5 -0
- data/db/migrate/20161122211105_create_users.rb +12 -0
- data/lib/generators/unsakini/angular/USAGE +8 -0
- data/lib/generators/unsakini/angular/angular_generator.rb +7 -0
- data/lib/generators/unsakini/config/USAGE +8 -0
- data/lib/generators/unsakini/config/config_generator.rb +7 -0
- data/lib/generators/unsakini/config/templates/unsakini.rb +4 -0
- data/lib/tasks/unsakini_tasks.rake +33 -0
- data/lib/unsakini/engine.rb +30 -0
- data/lib/unsakini/version.rb +3 -0
- data/lib/unsakini.rb +5 -0
- data/spec/concerns/models/encryptable_concern.rb +40 -0
- data/spec/dummy/Rakefile +6 -0
- data/spec/dummy/angular/README.md +31 -0
- data/spec/dummy/angular/angular-cli.json +59 -0
- data/spec/dummy/angular/e2e/app.e2e-spec.ts +14 -0
- data/spec/dummy/angular/e2e/app.po.ts +11 -0
- data/spec/dummy/angular/e2e/signup.e2e-spec.ts +28 -0
- data/spec/dummy/angular/e2e/signup.po.ts +31 -0
- data/spec/dummy/angular/e2e/tsconfig.json +16 -0
- data/spec/dummy/angular/karma.conf.js +45 -0
- data/spec/dummy/angular/package.json +50 -0
- data/spec/dummy/angular/protractor.conf.js +32 -0
- data/spec/dummy/angular/src/app/app.component.css +0 -0
- data/spec/dummy/angular/src/app/app.component.html +4 -0
- data/spec/dummy/angular/src/app/app.component.spec.ts +47 -0
- data/spec/dummy/angular/src/app/app.component.ts +10 -0
- data/spec/dummy/angular/src/app/app.module.ts +29 -0
- data/spec/dummy/angular/src/app/app.routes.module.ts +29 -0
- data/spec/dummy/angular/src/app/index.ts +2 -0
- data/spec/dummy/angular/src/app/registration/registration.component.css +0 -0
- data/spec/dummy/angular/src/app/registration/registration.component.html +14 -0
- data/spec/dummy/angular/src/app/registration/registration.component.spec.ts +157 -0
- data/spec/dummy/angular/src/app/registration/registration.component.ts +42 -0
- data/spec/dummy/angular/src/environments/environment.prod.ts +3 -0
- data/spec/dummy/angular/src/environments/environment.ts +8 -0
- data/spec/dummy/angular/src/favicon.ico +0 -0
- data/spec/dummy/angular/src/index.html +14 -0
- data/spec/dummy/angular/src/main.ts +12 -0
- data/spec/dummy/angular/src/polyfills.ts +19 -0
- data/spec/dummy/angular/src/styles.css +1 -0
- data/spec/dummy/angular/src/test.ts +31 -0
- data/spec/dummy/angular/src/tsconfig.json +18 -0
- data/spec/dummy/angular/src/typings.d.ts +2 -0
- data/spec/dummy/angular/tslint.json +114 -0
- data/spec/dummy/angular/typings.json +4 -0
- data/spec/dummy/app/assets/config/manifest.js +3 -0
- data/spec/dummy/app/assets/javascripts/application.js +13 -0
- data/spec/dummy/app/assets/stylesheets/application.css +15 -0
- data/spec/dummy/app/channels/application_cable/channel.rb +4 -0
- data/spec/dummy/app/channels/application_cable/connection.rb +4 -0
- data/spec/dummy/app/controllers/application_controller.rb +2 -0
- data/spec/dummy/app/jobs/application_job.rb +2 -0
- data/spec/dummy/app/mailers/application_mailer.rb +4 -0
- data/spec/dummy/app/models/application_record.rb +3 -0
- data/spec/dummy/app/views/layouts/mailer.html.erb +13 -0
- data/spec/dummy/app/views/layouts/mailer.text.erb +1 -0
- data/spec/dummy/bin/bundle +3 -0
- data/spec/dummy/bin/rails +4 -0
- data/spec/dummy/bin/rake +4 -0
- data/spec/dummy/bin/setup +34 -0
- data/spec/dummy/bin/update +29 -0
- data/spec/dummy/config/application.rb +22 -0
- data/spec/dummy/config/boot.rb +5 -0
- data/spec/dummy/config/cable.yml +9 -0
- data/spec/dummy/config/crypto.yml +7 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +47 -0
- data/spec/dummy/config/environments/production.rb +78 -0
- data/spec/dummy/config/environments/test.rb +42 -0
- data/spec/dummy/config/initializers/application_controller_renderer.rb +6 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/cors.rb +16 -0
- data/spec/dummy/config/initializers/inflections.rb +16 -0
- data/spec/dummy/config/initializers/mime_types.rb +4 -0
- data/spec/dummy/config/initializers/new_framework_defaults.rb +18 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +23 -0
- data/spec/dummy/config/puma.rb +47 -0
- data/spec/dummy/config/routes.rb +3 -0
- data/spec/dummy/config/secrets.yml +22 -0
- data/spec/dummy/config/spring.rb +6 -0
- data/spec/dummy/config.ru +5 -0
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/schema.rb +56 -0
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/public/app/favicon.ico +0 -0
- data/spec/dummy/public/app/index.html +14 -0
- data/spec/dummy/public/app/inline.bundle.js +139 -0
- data/spec/dummy/public/app/inline.map +1 -0
- data/spec/dummy/public/app/main.bundle.js +64689 -0
- data/spec/dummy/public/app/main.map +1 -0
- data/spec/dummy/public/app/styles.bundle.js +364 -0
- data/spec/dummy/public/app/styles.map +1 -0
- data/spec/factories/boards.rb +5 -0
- data/spec/factories/comments.rb +7 -0
- data/spec/factories/posts.rb +8 -0
- data/spec/factories/user_boards.rb +9 -0
- data/spec/factories/users.rb +10 -0
- data/spec/models/board_spec.rb +19 -0
- data/spec/models/comment_spec.rb +26 -0
- data/spec/models/post_spec.rb +19 -0
- data/spec/models/user_board_spec.rb +193 -0
- data/spec/models/user_spec.rb +5 -0
- data/spec/rails_helper.rb +58 -0
- data/spec/requests/api/api_boards_spec.rb +238 -0
- data/spec/requests/api/api_share_board_spec.rb +167 -0
- data/spec/requests/api/api_users_spec.rb +52 -0
- data/spec/requests/api/board/api_board_posts_spec.rb +299 -0
- data/spec/requests/api/board/post/api_board_post_comments_spec.rb +370 -0
- data/spec/requests/render_app_index_spec.rb +19 -0
- data/spec/schema/board.json +39 -0
- data/spec/schema/comment.json +51 -0
- data/spec/schema/post.json +87 -0
- data/spec/schema/user.json +27 -0
- data/spec/spec_helper.rb +67 -0
- data/spec/support/auth_helper.rb +17 -0
- data/spec/support/scenario_helper.rb +134 -0
- data/spec/support/serialize_helper.rb +37 -0
- metadata +540 -0
@@ -0,0 +1,370 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
RSpec.describe "Api::Board::Post::Comments", type: :request do
|
4
|
+
|
5
|
+
before(:all) do
|
6
|
+
user_has_shared_board_with_posts_scenario
|
7
|
+
end
|
8
|
+
|
9
|
+
let(:valid_attributes) {
|
10
|
+
{content: Faker::Hacker.say_something_smart}
|
11
|
+
}
|
12
|
+
|
13
|
+
let(:invalid_attributes) {
|
14
|
+
{content: nil}
|
15
|
+
}
|
16
|
+
|
17
|
+
context "Private board" do
|
18
|
+
|
19
|
+
context "Comments on my post" do
|
20
|
+
|
21
|
+
it "returns http unauthorized" do
|
22
|
+
get api_board_post_comments_path(@board, @post)
|
23
|
+
expect(response).to have_http_status(:unauthorized)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "returns http unauthorized" do
|
27
|
+
put api_board_post_comment_path(@board, @post, @comment), params: valid_attributes, as: :json
|
28
|
+
expect(response).to have_http_status(:unauthorized)
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
describe "Get all comments on my post" do
|
33
|
+
describe "As a post owner" do
|
34
|
+
it "returns all comments" do
|
35
|
+
get api_board_post_comments_path(@board, @post), headers: auth_headers(@user)
|
36
|
+
expect(response).to have_http_status(:ok)
|
37
|
+
expect(body_to_json('0')).to match_json_schema(:comment)
|
38
|
+
expect(body_to_json.count).to eq @post.comments.count
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "As another user" do
|
43
|
+
it "returns http forbidden" do
|
44
|
+
get api_board_post_comments_path(@board, @post), headers: auth_headers(@user_2)
|
45
|
+
expect(response).to have_http_status(:forbidden)
|
46
|
+
end
|
47
|
+
|
48
|
+
it "returns http forbidden" do
|
49
|
+
get api_board_post_comments_path(@shared_board, @post), headers: auth_headers(@user_2)
|
50
|
+
expect(response).to have_http_status(:forbidden)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
describe "Creating comment to my post" do
|
57
|
+
|
58
|
+
describe "As post owner" do
|
59
|
+
|
60
|
+
it "returns http unauthorized" do
|
61
|
+
post api_board_post_comments_path(@board, @post), as: :json, params: valid_attributes
|
62
|
+
expect(response).to have_http_status(:unauthorized)
|
63
|
+
end
|
64
|
+
|
65
|
+
it "returns http unprocessable_entity" do
|
66
|
+
post(
|
67
|
+
api_board_post_comments_path(@board, @post),
|
68
|
+
headers: auth_headers(@user),
|
69
|
+
params: invalid_attributes,
|
70
|
+
as: :json
|
71
|
+
)
|
72
|
+
expect(response).to have_http_status(:unprocessable_entity)
|
73
|
+
#todo: assert errors
|
74
|
+
end
|
75
|
+
|
76
|
+
it "creates a new comment" do
|
77
|
+
comment_count = @post.comments.count
|
78
|
+
post(
|
79
|
+
api_board_post_comments_path(@board, @post),
|
80
|
+
headers: auth_headers(@user),
|
81
|
+
params: valid_attributes,
|
82
|
+
as: :json
|
83
|
+
)
|
84
|
+
expect(response).to have_http_status(:ok)
|
85
|
+
expect(response.body).to match_json_schema(:comment)
|
86
|
+
expect(body_to_json('id')).to eq @post.comments.last.id
|
87
|
+
expect(body_to_json('user/id')).to eq @user.id
|
88
|
+
expect(Comment.find_by_id(body_to_json('id'))).to eq @post.comments.last
|
89
|
+
expect(@post.comments.count).to eq(comment_count+1)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
describe "As another user" do
|
94
|
+
|
95
|
+
it "returns http unauthorized" do
|
96
|
+
post api_board_post_comments_path(@board, @post), as: :json, params: valid_attributes
|
97
|
+
expect(response).to have_http_status(:unauthorized)
|
98
|
+
end
|
99
|
+
|
100
|
+
it "returns http forbidden" do
|
101
|
+
post(
|
102
|
+
api_board_post_comments_path(@board, @post),
|
103
|
+
headers: auth_headers(@user_2),
|
104
|
+
params: valid_attributes,
|
105
|
+
as: :json
|
106
|
+
)
|
107
|
+
expect(response).to have_http_status(:forbidden)
|
108
|
+
end
|
109
|
+
|
110
|
+
end
|
111
|
+
|
112
|
+
end
|
113
|
+
|
114
|
+
describe "Updating my comment on my post" do
|
115
|
+
|
116
|
+
describe "As comment owner" do
|
117
|
+
|
118
|
+
it "updates my comment if user is me" do
|
119
|
+
put(
|
120
|
+
api_board_post_comment_path(@board, @post, @comment),
|
121
|
+
params: valid_attributes,
|
122
|
+
headers: auth_headers(@user),
|
123
|
+
as: :json
|
124
|
+
)
|
125
|
+
expect(response).to have_http_status(:ok)
|
126
|
+
expect(response.body).to match_json_schema(:comment)
|
127
|
+
expect(body_to_json('content')).to eq @comment.reload.content
|
128
|
+
expect(@comment.content).to eq(valid_attributes[:content])
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
describe "As another user" do
|
133
|
+
|
134
|
+
it "returns http forbidden if not comment owner" do
|
135
|
+
put(
|
136
|
+
api_board_post_comment_path(@board, @post, @comment),
|
137
|
+
params: valid_attributes,
|
138
|
+
headers: auth_headers(@user_2),
|
139
|
+
as: :json
|
140
|
+
)
|
141
|
+
expect(response).to have_http_status(:forbidden)
|
142
|
+
end
|
143
|
+
|
144
|
+
end
|
145
|
+
|
146
|
+
end
|
147
|
+
|
148
|
+
describe "Deleting my comment on my post" do
|
149
|
+
|
150
|
+
describe "As comment owner" do
|
151
|
+
|
152
|
+
it "Deletes my comment if user is me" do
|
153
|
+
prev_comment_count = @post.comments.count
|
154
|
+
delete(
|
155
|
+
api_board_post_comment_path(@board, @post, @comment),
|
156
|
+
headers: auth_headers(@user),
|
157
|
+
)
|
158
|
+
expect(response).to have_http_status(:ok)
|
159
|
+
expect(@post.comments.count).to eq(prev_comment_count-1)
|
160
|
+
expect(Comment.find_by_id(@comment.id)).to be_nil
|
161
|
+
end
|
162
|
+
|
163
|
+
end
|
164
|
+
|
165
|
+
describe "As another user" do
|
166
|
+
|
167
|
+
it "returns http forbidden if not comment owner" do
|
168
|
+
prev_comment_count = @post.comments.count
|
169
|
+
delete(
|
170
|
+
api_board_post_comment_path(@board, @post, @comment),
|
171
|
+
headers: auth_headers(@user_2),
|
172
|
+
)
|
173
|
+
expect(response).to have_http_status(:forbidden)
|
174
|
+
expect(@post.comments.count).to eq(prev_comment_count)
|
175
|
+
expect(Comment.find_by_id(@comment.id)).not_to be_nil
|
176
|
+
end
|
177
|
+
|
178
|
+
it "Deletes my comment if user is me" do
|
179
|
+
prev_comment_count = @post.comments.count
|
180
|
+
delete(
|
181
|
+
api_board_post_comment_path(@board, @post, @comment),
|
182
|
+
headers: auth_headers(@user),
|
183
|
+
)
|
184
|
+
expect(response).to have_http_status(:ok)
|
185
|
+
expect(@post.comments.count).to eq(prev_comment_count-1)
|
186
|
+
expect(Comment.find_by_id(@comment.id)).to be_nil
|
187
|
+
end
|
188
|
+
|
189
|
+
end
|
190
|
+
|
191
|
+
end
|
192
|
+
|
193
|
+
end
|
194
|
+
|
195
|
+
end
|
196
|
+
|
197
|
+
context "Shared Board" do
|
198
|
+
|
199
|
+
context "Comments on My Post" do
|
200
|
+
|
201
|
+
describe "Get all comments on my post" do
|
202
|
+
|
203
|
+
describe "As a post owner" do
|
204
|
+
|
205
|
+
it "returns all comments" do
|
206
|
+
get api_board_post_comments_path(@shared_board, @shared_post), headers: auth_headers(@user)
|
207
|
+
expect(response).to have_http_status(:ok)
|
208
|
+
expect(body_to_json('0')).to match_json_schema(:comment)
|
209
|
+
expect(body_to_json.count).to eq @shared_post.comments.count
|
210
|
+
end
|
211
|
+
|
212
|
+
end
|
213
|
+
|
214
|
+
describe "As another user" do
|
215
|
+
it "returns all comments" do
|
216
|
+
get api_board_post_comments_path(@shared_board, @shared_post), headers: auth_headers(@user_2)
|
217
|
+
expect(response).to have_http_status(:ok)
|
218
|
+
expect(body_to_json('0')).to match_json_schema(:comment)
|
219
|
+
expect(body_to_json.count).to eq @shared_post.comments.count
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
223
|
+
end
|
224
|
+
|
225
|
+
describe "Creating comment to my post" do
|
226
|
+
|
227
|
+
context "As post owner" do
|
228
|
+
|
229
|
+
it "returns http unprocessable_entity" do
|
230
|
+
post(
|
231
|
+
api_board_post_comments_path(@shared_board, @shared_post),
|
232
|
+
headers: auth_headers(@user),
|
233
|
+
params: invalid_attributes,
|
234
|
+
as: :json
|
235
|
+
)
|
236
|
+
expect(response).to have_http_status(:unprocessable_entity)
|
237
|
+
#todo: assert errors
|
238
|
+
end
|
239
|
+
|
240
|
+
it "creates a new comment" do
|
241
|
+
comment_count = @shared_post.comments.count
|
242
|
+
post(
|
243
|
+
api_board_post_comments_path(@shared_board, @shared_post),
|
244
|
+
headers: auth_headers(@user),
|
245
|
+
params: valid_attributes,
|
246
|
+
as: :json
|
247
|
+
)
|
248
|
+
expect(response).to have_http_status(:ok)
|
249
|
+
expect(response.body).to match_json_schema(:comment)
|
250
|
+
expect(body_to_json('content')).to eq valid_attributes[:content]
|
251
|
+
expect(body_to_json('user/id')).to eq @user.id
|
252
|
+
expect(Comment.find_by_id(body_to_json('id'))).to eq @shared_post.comments.last
|
253
|
+
expect(@shared_post.comments.count).to eq(comment_count+1)
|
254
|
+
end
|
255
|
+
|
256
|
+
end
|
257
|
+
|
258
|
+
context "As another user" do
|
259
|
+
|
260
|
+
it "returns http unprocessable_entity" do
|
261
|
+
post(
|
262
|
+
api_board_post_comments_path(@shared_board, @shared_post),
|
263
|
+
headers: auth_headers(@user_2),
|
264
|
+
params: invalid_attributes,
|
265
|
+
as: :json
|
266
|
+
)
|
267
|
+
expect(response).to have_http_status(:unprocessable_entity)
|
268
|
+
# todo: assert errors
|
269
|
+
end
|
270
|
+
|
271
|
+
it "creates a new comment" do
|
272
|
+
comment_count = @shared_post.comments.count
|
273
|
+
post(
|
274
|
+
api_board_post_comments_path(@shared_board, @shared_post),
|
275
|
+
headers: auth_headers(@user_2),
|
276
|
+
params: valid_attributes,
|
277
|
+
as: :json
|
278
|
+
)
|
279
|
+
expect(response).to have_http_status(:ok)
|
280
|
+
expect(response.body).to match_json_schema(:comment)
|
281
|
+
expect(body_to_json('content')).to eq valid_attributes[:content]
|
282
|
+
expect(body_to_json('user/id')).to eq @user_2.id
|
283
|
+
expect(Comment.find_by_id(body_to_json('id'))).to eq @shared_post.comments.last
|
284
|
+
expect(@shared_post.comments.count).to eq(comment_count+1)
|
285
|
+
end
|
286
|
+
|
287
|
+
end
|
288
|
+
|
289
|
+
end
|
290
|
+
|
291
|
+
describe "Updating my comment" do
|
292
|
+
|
293
|
+
context "As comment owner" do
|
294
|
+
it "updates my comment if user is me" do
|
295
|
+
put(
|
296
|
+
api_board_post_comment_path(@shared_board, @shared_post, @shared_comment),
|
297
|
+
params: valid_attributes,
|
298
|
+
headers: auth_headers(@user),
|
299
|
+
as: :json
|
300
|
+
)
|
301
|
+
expect(response).to have_http_status(:ok)
|
302
|
+
expect(body_to_json('content')).to eq(valid_attributes[:content])
|
303
|
+
expect(@shared_comment.reload.content).to eq valid_attributes[:content]
|
304
|
+
end
|
305
|
+
end
|
306
|
+
|
307
|
+
context "As another user" do
|
308
|
+
|
309
|
+
it "returns http forbidden if not comment owner" do
|
310
|
+
put(
|
311
|
+
api_board_post_comment_path(@shared_board, @shared_post, @shared_comment),
|
312
|
+
params: valid_attributes,
|
313
|
+
headers: auth_headers(@user_2),
|
314
|
+
as: :json
|
315
|
+
)
|
316
|
+
expect(response).to have_http_status(:forbidden)
|
317
|
+
end
|
318
|
+
end
|
319
|
+
end
|
320
|
+
|
321
|
+
describe "Deleting my comment on my post" do
|
322
|
+
|
323
|
+
context "As comment owner" do
|
324
|
+
|
325
|
+
it "Deletes my comment if user is me" do
|
326
|
+
prev_comment_count = @shared_post.comments.count
|
327
|
+
delete(
|
328
|
+
api_board_post_comment_path(@shared_board, @shared_post, @shared_comment),
|
329
|
+
headers: auth_headers(@user),
|
330
|
+
)
|
331
|
+
expect(response).to have_http_status(:ok)
|
332
|
+
expect(@shared_post.comments.count).to eq(prev_comment_count-1)
|
333
|
+
expect(Comment.find_by_id(@shared_comment.id)).to be_nil
|
334
|
+
end
|
335
|
+
|
336
|
+
end
|
337
|
+
|
338
|
+
context "As another user" do
|
339
|
+
|
340
|
+
it "returns http forbidden if not comment owner" do
|
341
|
+
prev_comment_count = @shared_post.comments.count
|
342
|
+
delete(
|
343
|
+
api_board_post_comment_path(@shared_board, @shared_post, @shared_comment),
|
344
|
+
headers: auth_headers(@user_2),
|
345
|
+
)
|
346
|
+
expect(response).to have_http_status(:forbidden)
|
347
|
+
expect(@shared_post.comments.count).to eq(prev_comment_count)
|
348
|
+
expect(Comment.find_by_id(@shared_comment.id)).not_to be_nil
|
349
|
+
end
|
350
|
+
|
351
|
+
it "Deletes my comment if user is me" do
|
352
|
+
prev_comment_count = @shared_post.comments.count
|
353
|
+
delete(
|
354
|
+
api_board_post_comment_path(@shared_board, @shared_post, @shared_comment),
|
355
|
+
headers: auth_headers(@user),
|
356
|
+
)
|
357
|
+
expect(response).to have_http_status(:ok)
|
358
|
+
expect(@shared_post.comments.count).to eq(prev_comment_count-1)
|
359
|
+
expect(Comment.find_by_id(@shared_comment.id)).to be_nil
|
360
|
+
end
|
361
|
+
|
362
|
+
end
|
363
|
+
|
364
|
+
end
|
365
|
+
|
366
|
+
end
|
367
|
+
|
368
|
+
end
|
369
|
+
|
370
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
RSpec.describe "WebBaseController", type: :request do
|
4
|
+
|
5
|
+
describe 'catch html5 pushState routes' do
|
6
|
+
|
7
|
+
def self.visit_app_urls(urls)
|
8
|
+
urls.each do |url|
|
9
|
+
it "renders app/index.html when visiting #{url}" do
|
10
|
+
get "/#{url}"
|
11
|
+
expect(response.body).to match File.read(Rails.public_path.join("app","index.html"))
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
visit_app_urls(['/app', 'app/', 'app/*anything'])
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
{
|
2
|
+
"type": "object",
|
3
|
+
"required": [
|
4
|
+
"board",
|
5
|
+
"id",
|
6
|
+
"is_admin",
|
7
|
+
"encrypted_password",
|
8
|
+
"created_at",
|
9
|
+
"updated_at"
|
10
|
+
],
|
11
|
+
"properties": {
|
12
|
+
"board": {
|
13
|
+
"type": "object",
|
14
|
+
"required": [
|
15
|
+
"name"
|
16
|
+
],
|
17
|
+
"properties": {
|
18
|
+
"name": {
|
19
|
+
"type": "string"
|
20
|
+
}
|
21
|
+
}
|
22
|
+
},
|
23
|
+
"id": {
|
24
|
+
"type": "integer"
|
25
|
+
},
|
26
|
+
"is_admin": {
|
27
|
+
"type": "boolean"
|
28
|
+
},
|
29
|
+
"encrypted_password": {
|
30
|
+
"type": "string|nil"
|
31
|
+
},
|
32
|
+
"created_at": {
|
33
|
+
"type": "string"
|
34
|
+
},
|
35
|
+
"updated_at": {
|
36
|
+
"type": "string"
|
37
|
+
}
|
38
|
+
}
|
39
|
+
}
|
@@ -0,0 +1,51 @@
|
|
1
|
+
{
|
2
|
+
"type": "object",
|
3
|
+
"required": [
|
4
|
+
"id",
|
5
|
+
"content",
|
6
|
+
"user",
|
7
|
+
"created_at",
|
8
|
+
"updated_at"
|
9
|
+
],
|
10
|
+
"properties": {
|
11
|
+
"id": {
|
12
|
+
"type": "integer"
|
13
|
+
},
|
14
|
+
"content": {
|
15
|
+
"type": "string"
|
16
|
+
},
|
17
|
+
"created_at": {
|
18
|
+
"type": "string"
|
19
|
+
},
|
20
|
+
"updated_at": {
|
21
|
+
"type": "string"
|
22
|
+
},
|
23
|
+
"user": {
|
24
|
+
"type": "object",
|
25
|
+
"requires": [
|
26
|
+
"id",
|
27
|
+
"name",
|
28
|
+
"email",
|
29
|
+
"created_at",
|
30
|
+
"updated_at"
|
31
|
+
],
|
32
|
+
"properties": {
|
33
|
+
"id": {
|
34
|
+
"type": "integer"
|
35
|
+
},
|
36
|
+
"name": {
|
37
|
+
"type": "string"
|
38
|
+
},
|
39
|
+
"email": {
|
40
|
+
"type": "string"
|
41
|
+
},
|
42
|
+
"created_at": {
|
43
|
+
"type": "string"
|
44
|
+
},
|
45
|
+
"updated_at": {
|
46
|
+
"type": "string"
|
47
|
+
}
|
48
|
+
}
|
49
|
+
}
|
50
|
+
}
|
51
|
+
}
|
@@ -0,0 +1,87 @@
|
|
1
|
+
{
|
2
|
+
"type": "object",
|
3
|
+
"required": [
|
4
|
+
"id",
|
5
|
+
"title",
|
6
|
+
"content",
|
7
|
+
"user",
|
8
|
+
"board",
|
9
|
+
"created_at",
|
10
|
+
"updated_at"
|
11
|
+
],
|
12
|
+
"properties": {
|
13
|
+
"id": {
|
14
|
+
"type": "integer"
|
15
|
+
},
|
16
|
+
"title": {
|
17
|
+
"type": "string"
|
18
|
+
},
|
19
|
+
"content": {
|
20
|
+
"type": "string"
|
21
|
+
},
|
22
|
+
"created_at": {
|
23
|
+
"type": "string"
|
24
|
+
},
|
25
|
+
"updated_at": {
|
26
|
+
"type": "string"
|
27
|
+
},
|
28
|
+
"user": {
|
29
|
+
"type": "object",
|
30
|
+
"requires": [
|
31
|
+
"id",
|
32
|
+
"name",
|
33
|
+
"email",
|
34
|
+
"created_at",
|
35
|
+
"updated_at"
|
36
|
+
],
|
37
|
+
"properties": {
|
38
|
+
"id": {
|
39
|
+
"type": "integer"
|
40
|
+
},
|
41
|
+
"name": {
|
42
|
+
"type": "string"
|
43
|
+
},
|
44
|
+
"email": {
|
45
|
+
"type": "string"
|
46
|
+
},
|
47
|
+
"created_at": {
|
48
|
+
"type": "string"
|
49
|
+
},
|
50
|
+
"updated_at": {
|
51
|
+
"type": "string"
|
52
|
+
}
|
53
|
+
}
|
54
|
+
},
|
55
|
+
"board": {
|
56
|
+
"type": "object",
|
57
|
+
"required": [
|
58
|
+
"id",
|
59
|
+
"is_admin",
|
60
|
+
"name",
|
61
|
+
"encrypted_password",
|
62
|
+
"created_at",
|
63
|
+
"updated_at"
|
64
|
+
],
|
65
|
+
"properties": {
|
66
|
+
"id": {
|
67
|
+
"type": "integer"
|
68
|
+
},
|
69
|
+
"is_admin": {
|
70
|
+
"type": "boolean"
|
71
|
+
},
|
72
|
+
"name": {
|
73
|
+
"type": "string"
|
74
|
+
},
|
75
|
+
"encrypted_password": {
|
76
|
+
"type": "string|nil"
|
77
|
+
},
|
78
|
+
"created_at": {
|
79
|
+
"type": "string"
|
80
|
+
},
|
81
|
+
"updated_at": {
|
82
|
+
"type": "string"
|
83
|
+
}
|
84
|
+
}
|
85
|
+
}
|
86
|
+
}
|
87
|
+
}
|
@@ -0,0 +1,27 @@
|
|
1
|
+
{
|
2
|
+
"type": "object",
|
3
|
+
"requires": [
|
4
|
+
"id",
|
5
|
+
"name",
|
6
|
+
"email",
|
7
|
+
"created_at",
|
8
|
+
"updated_at"
|
9
|
+
],
|
10
|
+
"properties": {
|
11
|
+
"id": {
|
12
|
+
"type": "integer"
|
13
|
+
},
|
14
|
+
"name": {
|
15
|
+
"type": "string"
|
16
|
+
},
|
17
|
+
"email": {
|
18
|
+
"type": "string"
|
19
|
+
},
|
20
|
+
"created_at": {
|
21
|
+
"type": "string"
|
22
|
+
},
|
23
|
+
"updated_at": {
|
24
|
+
"type": "string"
|
25
|
+
}
|
26
|
+
}
|
27
|
+
}
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
ENV['RAILS_ENV'] ||= 'test'
|
2
|
+
|
3
|
+
require File.expand_path("../dummy/config/environment.rb", __FILE__)
|
4
|
+
require 'rspec/rails'
|
5
|
+
# require 'rspec/autorun'
|
6
|
+
require 'byebug'
|
7
|
+
require 'rb-readline'
|
8
|
+
require 'factory_girl_rails'
|
9
|
+
require 'json_spec'
|
10
|
+
require 'json-schema-rspec'
|
11
|
+
require 'faker'
|
12
|
+
require 'database_cleaner'
|
13
|
+
|
14
|
+
Rails.backtrace_cleaner.remove_silencers!
|
15
|
+
|
16
|
+
# Load support files
|
17
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
18
|
+
Dir["#{File.dirname(__FILE__)}/concerns/**/*.rb"].each { |f| require f }
|
19
|
+
|
20
|
+
RSpec.configure do |config|
|
21
|
+
|
22
|
+
config.mock_with :rspec
|
23
|
+
config.use_transactional_fixtures = true
|
24
|
+
config.infer_base_class_for_anonymous_controllers = false
|
25
|
+
# config.order = "random"
|
26
|
+
|
27
|
+
config.include JsonSpec::Helpers
|
28
|
+
config.include FactoryGirl::Syntax::Methods
|
29
|
+
|
30
|
+
|
31
|
+
RSpec.configure do |config|
|
32
|
+
config.include JSON::SchemaMatchers
|
33
|
+
config.json_schemas[:user] = "spec/schema/user.json"
|
34
|
+
config.json_schemas[:board] = "spec/schema/board.json"
|
35
|
+
config.json_schemas[:post] = "spec/schema/post.json"
|
36
|
+
config.json_schemas[:comment] = "spec/schema/comment.json"
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
# http://stackoverflow.com/questions/5608203/rspec-integration-test-not-cleaning-the-database
|
41
|
+
# http://stackoverflow.com/questions/29466868/rspec-how-to-clean-the-database-after-each-test
|
42
|
+
|
43
|
+
RSpec.configure do |config|
|
44
|
+
config.before(:suite) do
|
45
|
+
DatabaseCleaner.clean_with(:truncation)
|
46
|
+
end
|
47
|
+
|
48
|
+
config.before(:each) do
|
49
|
+
DatabaseCleaner.strategy = :transaction
|
50
|
+
end
|
51
|
+
|
52
|
+
# config.before(:each, :js => true) do
|
53
|
+
# DatabaseCleaner.strategy = :truncation
|
54
|
+
# end
|
55
|
+
|
56
|
+
config.before(:each) do
|
57
|
+
DatabaseCleaner.start
|
58
|
+
end
|
59
|
+
|
60
|
+
config.after(:each) do
|
61
|
+
DatabaseCleaner.clean
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
|
66
|
+
|
67
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
|
2
|
+
module AuthHelper
|
3
|
+
|
4
|
+
def auth_headers(user)
|
5
|
+
# debugger
|
6
|
+
token = Knock::AuthToken.new(payload: { sub: user.id }).token
|
7
|
+
|
8
|
+
{
|
9
|
+
'Authorization': "Bearer #{token}"
|
10
|
+
}
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
RSpec.configure do |config|
|
16
|
+
config.include AuthHelper
|
17
|
+
end
|