enju_question 0.1.0.pre13 → 0.1.0.pre14
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 +4 -4
- data/README.rdoc +8 -1
- data/app/controllers/answers_controller.rb +15 -2
- data/app/controllers/questions_controller.rb +7 -2
- data/app/models/answer.rb +0 -1
- data/app/models/answer_has_item.rb +0 -1
- data/app/models/question.rb +0 -1
- data/lib/enju_question/engine.rb +0 -1
- data/lib/enju_question/version.rb +1 -1
- data/spec/controllers/answers_controller_spec.rb +61 -61
- data/spec/controllers/questions_controller_spec.rb +70 -70
- 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 +29 -0
- data/spec/fixtures/users.yml +1 -1
- data/spec/spec_helper.rb +2 -0
- metadata +44 -82
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/script/rails +0 -6
- data/spec/dummy/solr/conf/admin-extra.html +0 -31
- data/spec/dummy/solr/conf/elevate.xml +0 -36
- data/spec/dummy/solr/conf/mapping-ISOLatin1Accent.txt +0 -246
- data/spec/dummy/solr/conf/protwords.txt +0 -21
- data/spec/dummy/solr/conf/schema.xml +0 -255
- data/spec/dummy/solr/conf/scripts.conf +0 -24
- data/spec/dummy/solr/conf/solrconfig.xml +0 -667
- data/spec/dummy/solr/conf/spellings.txt +0 -2
- data/spec/dummy/solr/conf/stopwords.txt +0 -58
- data/spec/dummy/solr/conf/synonyms.txt +0 -31
- data/spec/dummy/solr/default/data/index/segments.gen +0 -0
- data/spec/dummy/solr/default/data/index/segments_1km +0 -0
- data/spec/dummy/solr/default/data/tlog/tlog.0000000000000002027 +0 -0
- data/spec/dummy/solr/default/data/tlog/tlog.0000000000000002028 +0 -0
- data/spec/dummy/solr/default/data/tlog/tlog.0000000000000002029 +0 -0
- data/spec/dummy/solr/default/data/tlog/tlog.0000000000000002030 +0 -0
- data/spec/dummy/solr/default/data/tlog/tlog.0000000000000002031 +0 -0
- data/spec/dummy/solr/default/data/tlog/tlog.0000000000000002032 +0 -0
- data/spec/dummy/solr/default/data/tlog/tlog.0000000000000002033 +0 -0
- data/spec/dummy/solr/default/data/tlog/tlog.0000000000000002034 +0 -0
- data/spec/dummy/solr/default/data/tlog/tlog.0000000000000002035 +0 -0
- data/spec/dummy/solr/default/data/tlog/tlog.0000000000000002036 +0 -0
- data/spec/dummy/solr/development/data/index/segments.gen +0 -0
- data/spec/dummy/solr/development/data/index/segments_1 +0 -0
- data/spec/dummy/solr/solr.xml +0 -8
- data/spec/dummy/solr/test/data/index/segments.gen +0 -0
- data/spec/dummy/solr/test/data/index/segments_1 +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 101535f4eb4968f929c27c8a7069d5c02f29a0eb
|
4
|
+
data.tar.gz: 6125d6da856d612f25fec130cb5a26df86da7239
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f5cf4a94f2bd3c0d91913d093c936a9625309a42a1ad33f8b3bdc3a7908c969c73462c490b1ee3592210d24d40869d8a3a3b5642afa1b3f8d3baa0950dad806b
|
7
|
+
data.tar.gz: f323e652656e605b677d4f7b0716f61a14f4db15401ae36453f1acba56a571b8f751f8f724793d810f5a6c3a87595934681ab5318049fcfce2e1a425257703b0
|
data/README.rdoc
CHANGED
@@ -1,3 +1,10 @@
|
|
1
1
|
= EnjuQuestion
|
2
|
+
{<img src="https://secure.travis-ci.org/next-l/enju_question.png?branch=1.1" alt="Build Status" />}[http://travis-ci.org/next-l/enju_question]
|
3
|
+
{<img src="https://coveralls.io/repos/next-l/enju_question/badge.png?branch=1.1" alt="Coverage Status" />}[https://coveralls.io/r/next-l/enju_question?branch=1.1]
|
4
|
+
{<img src="https://hakiri.io/github/next-l/enju_question/1.1.svg" alt="security" />}[https://hakiri.io/github/next-l/enju_question/1.1]
|
2
5
|
|
3
|
-
This project rocks and uses MIT-LICENSE.
|
6
|
+
This project rocks and uses MIT-LICENSE.
|
7
|
+
|
8
|
+
== 製作者・貢献者 (Authors and contributors)
|
9
|
+
* {TANABE, Kosuke}[https://github.com/nabeta] ({@nabeta}[https://twitter.com/nabeta])
|
10
|
+
* {Project Next-L}[http://www.next-l.jp] ({@ProjectNextL}[https://twitter.com/ProjectNextL])
|
@@ -91,7 +91,7 @@ class AnswersController < ApplicationController
|
|
91
91
|
# POST /answers
|
92
92
|
# POST /answers.json
|
93
93
|
def create
|
94
|
-
@answer = Answer.new(
|
94
|
+
@answer = Answer.new(answer_params)
|
95
95
|
@answer.user = current_user
|
96
96
|
unless @answer.question
|
97
97
|
redirect_to questions_url
|
@@ -116,7 +116,7 @@ class AnswersController < ApplicationController
|
|
116
116
|
# PUT /answers/1.json
|
117
117
|
def update
|
118
118
|
respond_to do |format|
|
119
|
-
if @answer.update_attributes(
|
119
|
+
if @answer.update_attributes(answer_update_params)
|
120
120
|
flash[:notice] = t('controller.successfully_updated', model: t('activerecord.models.answer'))
|
121
121
|
format.html { redirect_to @answer }
|
122
122
|
format.json { head :no_content }
|
@@ -137,4 +137,17 @@ class AnswersController < ApplicationController
|
|
137
137
|
format.json { head :no_content }
|
138
138
|
end
|
139
139
|
end
|
140
|
+
|
141
|
+
private
|
142
|
+
def answer_params
|
143
|
+
params.require(:answer).permit(
|
144
|
+
:question_id, :body, :item_identifier_list, :url_list
|
145
|
+
)
|
146
|
+
end
|
147
|
+
|
148
|
+
def answer_update_params
|
149
|
+
params.require(:answer).permit(
|
150
|
+
:body, :item_identifier_list, :url_list
|
151
|
+
)
|
152
|
+
end
|
140
153
|
end
|
@@ -129,7 +129,7 @@ class QuestionsController < ApplicationController
|
|
129
129
|
# POST /questions
|
130
130
|
# POST /questions.json
|
131
131
|
def create
|
132
|
-
@question = Question.new(
|
132
|
+
@question = Question.new(question_params)
|
133
133
|
@question.user = current_user
|
134
134
|
|
135
135
|
respond_to do |format|
|
@@ -148,7 +148,7 @@ class QuestionsController < ApplicationController
|
|
148
148
|
# PUT /questions/1.json
|
149
149
|
def update
|
150
150
|
respond_to do |format|
|
151
|
-
if @question.update_attributes(
|
151
|
+
if @question.update_attributes(question_params)
|
152
152
|
flash[:notice] = t('controller.successfully_updated', model: t('activerecord.models.question'))
|
153
153
|
format.html { redirect_to @question }
|
154
154
|
format.json { head :no_content }
|
@@ -169,4 +169,9 @@ class QuestionsController < ApplicationController
|
|
169
169
|
format.json { head :no_content }
|
170
170
|
end
|
171
171
|
end
|
172
|
+
|
173
|
+
private
|
174
|
+
def question_params
|
175
|
+
params.require(:question).permit(:body, :shared, :solved, :note)
|
176
|
+
end
|
172
177
|
end
|
data/app/models/answer.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
class Answer < ActiveRecord::Base
|
3
|
-
attr_accessible :question_id, :body, :item_identifier_list, :url_list
|
4
3
|
default_scope { order('answers.id ASC') }
|
5
4
|
#scope :public_answers, where(:shared => true)
|
6
5
|
#scope :private_answers, where(:shared => false)
|
data/app/models/question.rb
CHANGED
data/lib/enju_question/engine.rb
CHANGED
@@ -37,24 +37,24 @@ describe AnswersController do
|
|
37
37
|
end
|
38
38
|
|
39
39
|
it "should get to my index if user_id is specified" do
|
40
|
-
get :index, :
|
40
|
+
get :index, user_id: users(:user1).username
|
41
41
|
response.should be_success
|
42
42
|
assigns(:answers).should eq users(:user1).answers.order('answers.id DESC').page(1)
|
43
43
|
end
|
44
44
|
|
45
45
|
it "should not get other user's index without user_id" do
|
46
|
-
get :index, :
|
46
|
+
get :index, user_id: users(:user2).username
|
47
47
|
response.should be_forbidden
|
48
48
|
end
|
49
49
|
|
50
50
|
it "should get my index feed" do
|
51
|
-
get :index, :
|
51
|
+
get :index, user_id: users(:user1).username, format: 'rss'
|
52
52
|
response.should be_success
|
53
53
|
assigns(:answers).should_not be_empty
|
54
54
|
end
|
55
55
|
|
56
56
|
it "should not get other user's index if question is not shared" do
|
57
|
-
get :index, :
|
57
|
+
get :index, user_id: users(:librarian1).username, question_id: 2
|
58
58
|
response.should be_forbidden
|
59
59
|
end
|
60
60
|
end
|
@@ -67,24 +67,24 @@ describe AnswersController do
|
|
67
67
|
end
|
68
68
|
|
69
69
|
it "should not get index with other user's question_id" do
|
70
|
-
get :index, :
|
70
|
+
get :index, question_id: 1
|
71
71
|
assigns(:answers).should eq assigns(:question).answers.order('answers.id DESC').page(1)
|
72
72
|
response.should be_success
|
73
73
|
end
|
74
74
|
|
75
75
|
it "should get other user's index if question is shared" do
|
76
|
-
get :index, :
|
76
|
+
get :index, question_id: 5
|
77
77
|
response.should be_success
|
78
78
|
assigns(:answers).should eq assigns(:question).answers.order('answers.id DESC').page(1)
|
79
79
|
end
|
80
80
|
|
81
81
|
it "should not get other user's index feed if question is not shared" do
|
82
|
-
get :index, :
|
82
|
+
get :index, question_id: 2, format: 'rss'
|
83
83
|
response.should be_client_error
|
84
84
|
end
|
85
85
|
|
86
86
|
it "should get other user's index feed if question is shared" do
|
87
|
-
get :index, :
|
87
|
+
get :index, question_id: 5, format: 'rss'
|
88
88
|
response.should be_success
|
89
89
|
assigns(:answers).should eq assigns(:question).answers.order('answers.id DESC').page(1)
|
90
90
|
end
|
@@ -97,7 +97,7 @@ describe AnswersController do
|
|
97
97
|
|
98
98
|
it "assigns the requested answer as @answer" do
|
99
99
|
answer = FactoryGirl.create(:answer)
|
100
|
-
get :show, :
|
100
|
+
get :show, id: answer.id
|
101
101
|
assigns(:answer).should eq(answer)
|
102
102
|
end
|
103
103
|
end
|
@@ -107,7 +107,7 @@ describe AnswersController do
|
|
107
107
|
|
108
108
|
it "assigns the requested answer as @answer" do
|
109
109
|
answer = FactoryGirl.create(:answer)
|
110
|
-
get :show, :
|
110
|
+
get :show, id: answer.id
|
111
111
|
assigns(:answer).should eq(answer)
|
112
112
|
end
|
113
113
|
end
|
@@ -117,47 +117,47 @@ describe AnswersController do
|
|
117
117
|
|
118
118
|
it "assigns the requested answer as @answer" do
|
119
119
|
answer = FactoryGirl.create(:answer)
|
120
|
-
get :show, :
|
120
|
+
get :show, id: answer.id
|
121
121
|
assigns(:answer).should eq(answer)
|
122
122
|
end
|
123
123
|
|
124
124
|
it "should show answer without user_id" do
|
125
|
-
get :show, :
|
125
|
+
get :show, id: 1, question_id: 1
|
126
126
|
assigns(:answer).should eq(answers(:answer_00001))
|
127
127
|
assert_response :success
|
128
128
|
end
|
129
129
|
|
130
130
|
it "should show public answer without question_id" do
|
131
|
-
get :show, :
|
131
|
+
get :show, id: 3, user_id: users(:user1).username
|
132
132
|
assigns(:answer).should eq(Answer.find(3))
|
133
133
|
assert_response :success
|
134
134
|
end
|
135
135
|
|
136
136
|
it "should show my answer" do
|
137
|
-
get :show, :
|
137
|
+
get :show, id: 3, user_id: users(:user1).username
|
138
138
|
assigns(:answer).should eq(Answer.find(3))
|
139
139
|
assert_response :success
|
140
140
|
end
|
141
141
|
|
142
142
|
it "should not show private answer" do
|
143
|
-
get :show, :
|
143
|
+
get :show, id: 4, user_id: users(:user1).username
|
144
144
|
response.should be_forbidden
|
145
145
|
end
|
146
146
|
|
147
147
|
it "should not show missing answer" do
|
148
148
|
lambda{
|
149
|
-
get :show, :
|
149
|
+
get :show, id: 'missing', user_id: users(:user1).username, question_id: 1
|
150
150
|
}.should raise_error(ActiveRecord::RecordNotFound)
|
151
151
|
#response.should be_missing
|
152
152
|
end
|
153
153
|
|
154
154
|
it "should not show answer with other user's user_id" do
|
155
|
-
get :show, :
|
155
|
+
get :show, id: 5, user_id: users(:user2).username, question_id: 2
|
156
156
|
response.should be_forbidden
|
157
157
|
end
|
158
158
|
|
159
159
|
it "should not show answer without other user's user_id" do
|
160
|
-
get :show, :
|
160
|
+
get :show, id: 5, question_id: 2
|
161
161
|
response.should be_forbidden
|
162
162
|
end
|
163
163
|
end
|
@@ -165,18 +165,18 @@ describe AnswersController do
|
|
165
165
|
describe "When not logged in" do
|
166
166
|
it "assigns the requested answer as @answer" do
|
167
167
|
answer = FactoryGirl.create(:answer)
|
168
|
-
get :show, :
|
168
|
+
get :show, id: answer.id
|
169
169
|
assigns(:answer).should eq(answer)
|
170
170
|
end
|
171
171
|
|
172
172
|
it "should show public_answer" do
|
173
|
-
get :show, :
|
173
|
+
get :show, id: 1, question_id: 1
|
174
174
|
assigns(:answer).should eq(Answer.find(1))
|
175
175
|
response.should be_success
|
176
176
|
end
|
177
177
|
|
178
178
|
it "should not show private answer" do
|
179
|
-
get :show, :
|
179
|
+
get :show, id: 4, question_id: 1
|
180
180
|
assigns(:answer).should eq(Answer.find(4))
|
181
181
|
response.should redirect_to new_user_session_url
|
182
182
|
end
|
@@ -211,7 +211,7 @@ describe AnswersController do
|
|
211
211
|
end
|
212
212
|
|
213
213
|
it "should get new template with question_id" do
|
214
|
-
get :new, :
|
214
|
+
get :new, question_id: 1
|
215
215
|
assigns(:answer).should_not be_valid
|
216
216
|
response.should be_success
|
217
217
|
end
|
@@ -232,7 +232,7 @@ describe AnswersController do
|
|
232
232
|
|
233
233
|
it "assigns the requested answer as @answer" do
|
234
234
|
answer = FactoryGirl.create(:answer)
|
235
|
-
get :edit, :
|
235
|
+
get :edit, id: answer.id
|
236
236
|
assigns(:answer).should eq(answer)
|
237
237
|
end
|
238
238
|
end
|
@@ -242,7 +242,7 @@ describe AnswersController do
|
|
242
242
|
|
243
243
|
it "assigns the requested answer as @answer" do
|
244
244
|
answer = FactoryGirl.create(:answer)
|
245
|
-
get :edit, :
|
245
|
+
get :edit, id: answer.id
|
246
246
|
assigns(:answer).should eq(answer)
|
247
247
|
end
|
248
248
|
end
|
@@ -252,39 +252,39 @@ describe AnswersController do
|
|
252
252
|
|
253
253
|
it "assigns the requested answer as @answer" do
|
254
254
|
answer = FactoryGirl.create(:answer)
|
255
|
-
get :edit, :
|
255
|
+
get :edit, id: answer.id
|
256
256
|
response.should be_forbidden
|
257
257
|
end
|
258
258
|
|
259
259
|
it "should edit my answer without user_id" do
|
260
|
-
get :edit, :
|
260
|
+
get :edit, id: 3, question_id: 1
|
261
261
|
response.should be_success
|
262
262
|
end
|
263
263
|
|
264
264
|
it "should not edit other answer without user_id" do
|
265
|
-
get :edit, :
|
265
|
+
get :edit, id: 4, question_id: 1
|
266
266
|
response.should be_forbidden
|
267
267
|
end
|
268
268
|
|
269
269
|
it "should edit answer without question_id" do
|
270
|
-
get :edit, :
|
270
|
+
get :edit, id: 3 , user_id: users(:user1).username
|
271
271
|
response.should be_success
|
272
272
|
end
|
273
273
|
|
274
274
|
it "should not edit missing answer" do
|
275
275
|
lambda{
|
276
|
-
get :edit, :
|
276
|
+
get :edit, id: 100, user_id: users(:user1).username, question_id: 1
|
277
277
|
}.should raise_error(ActiveRecord::RecordNotFound)
|
278
278
|
#response.should be_missing
|
279
279
|
end
|
280
280
|
|
281
281
|
it "should edit my answer" do
|
282
|
-
get :edit, :
|
282
|
+
get :edit, id: 3, user_id: users(:user1).username, question_id: 1
|
283
283
|
response.should be_success
|
284
284
|
end
|
285
285
|
|
286
286
|
it "should not edit other user's answer" do
|
287
|
-
get :edit, :
|
287
|
+
get :edit, id: 5, user_id: users(:user2).username, question_id: 2
|
288
288
|
response.should be_forbidden
|
289
289
|
end
|
290
290
|
end
|
@@ -292,7 +292,7 @@ describe AnswersController do
|
|
292
292
|
describe "When not logged in" do
|
293
293
|
it "should not assign the requested answer as @answer" do
|
294
294
|
answer = FactoryGirl.create(:answer)
|
295
|
-
get :edit, :
|
295
|
+
get :edit, id: answer.id
|
296
296
|
response.should redirect_to(new_user_session_url)
|
297
297
|
end
|
298
298
|
end
|
@@ -301,25 +301,25 @@ describe AnswersController do
|
|
301
301
|
describe "POST create" do
|
302
302
|
before(:each) do
|
303
303
|
@attrs = FactoryGirl.attributes_for(:answer)
|
304
|
-
@invalid_attrs = {:
|
304
|
+
@invalid_attrs = {body: ''}
|
305
305
|
end
|
306
306
|
|
307
307
|
describe "When logged in as User" do
|
308
308
|
login_fixture_user
|
309
309
|
|
310
310
|
it "should create answer without user_id" do
|
311
|
-
post :create, :
|
311
|
+
post :create, answer: {question_id: 1, body: 'hoge'}
|
312
312
|
response.should redirect_to answer_url(assigns(:answer))
|
313
313
|
end
|
314
314
|
|
315
315
|
it "should not create answer without question_id" do
|
316
|
-
post :create, :
|
316
|
+
post :create, answer: {body: 'hoge'}
|
317
317
|
assigns(:answer).should_not be_valid
|
318
318
|
response.should redirect_to questions_url
|
319
319
|
end
|
320
320
|
|
321
321
|
it "should create answer with question_id" do
|
322
|
-
post :create, :
|
322
|
+
post :create, answer: {question_id: 1, body: 'hoge'}
|
323
323
|
assigns(:answer).should be_valid
|
324
324
|
response.should redirect_to answer_url(assigns(:answer))
|
325
325
|
end
|
@@ -328,24 +328,24 @@ describe AnswersController do
|
|
328
328
|
describe "When not logged in" do
|
329
329
|
describe "with valid params" do
|
330
330
|
it "assigns a newly created answer as @answer" do
|
331
|
-
post :create, :
|
331
|
+
post :create, answer: @attrs
|
332
332
|
assigns(:answer).should_not be_valid
|
333
333
|
end
|
334
334
|
|
335
335
|
it "redirects to the created answer" do
|
336
|
-
post :create, :
|
336
|
+
post :create, answer: @attrs
|
337
337
|
response.should redirect_to new_user_session_url
|
338
338
|
end
|
339
339
|
end
|
340
340
|
|
341
341
|
describe "with invalid params" do
|
342
342
|
it "assigns a newly created but unsaved answer as @answer" do
|
343
|
-
post :create, :
|
343
|
+
post :create, answer: @invalid_attrs
|
344
344
|
assigns(:answer).should_not be_valid
|
345
345
|
end
|
346
346
|
|
347
347
|
it "re-renders the 'new' template" do
|
348
|
-
post :create, :
|
348
|
+
post :create, answer: @invalid_attrs
|
349
349
|
response.should redirect_to new_user_session_url
|
350
350
|
end
|
351
351
|
end
|
@@ -355,8 +355,8 @@ describe AnswersController do
|
|
355
355
|
describe "PUT update" do
|
356
356
|
before(:each) do
|
357
357
|
@answer = answers(:answer_00001)
|
358
|
-
@attrs = {:
|
359
|
-
@invalid_attrs = {:
|
358
|
+
@attrs = {body: 'test'}
|
359
|
+
@invalid_attrs = {body: ''}
|
360
360
|
end
|
361
361
|
|
362
362
|
describe "When logged in as Administrator" do
|
@@ -364,18 +364,18 @@ describe AnswersController do
|
|
364
364
|
|
365
365
|
describe "with valid params" do
|
366
366
|
it "updates the requested answer" do
|
367
|
-
put :update, :
|
367
|
+
put :update, id: answers(:answer_00003).id, answer: @attrs
|
368
368
|
end
|
369
369
|
|
370
370
|
it "assigns the requested answer as @answer" do
|
371
|
-
put :update, :
|
371
|
+
put :update, id: answers(:answer_00003).id, answer: @attrs
|
372
372
|
assigns(:answer).should eq(Answer.find(3))
|
373
373
|
end
|
374
374
|
end
|
375
375
|
|
376
376
|
describe "with invalid params" do
|
377
377
|
it "assigns the requested answer as @answer" do
|
378
|
-
put :update, :
|
378
|
+
put :update, id: answers(:answer_00003).id, answer: @invalid_attrs
|
379
379
|
response.should render_template("edit")
|
380
380
|
end
|
381
381
|
end
|
@@ -386,24 +386,24 @@ describe AnswersController do
|
|
386
386
|
|
387
387
|
describe "with valid params" do
|
388
388
|
it "updates the requested answer" do
|
389
|
-
put :update, :
|
389
|
+
put :update, id: answers(:answer_00003).id, answer: @attrs
|
390
390
|
end
|
391
391
|
|
392
392
|
it "assigns the requested answer as @answer" do
|
393
|
-
put :update, :
|
393
|
+
put :update, id: answers(:answer_00003).id, answer: @attrs
|
394
394
|
assigns(:answer).should eq(Answer.find(3))
|
395
395
|
end
|
396
396
|
end
|
397
397
|
|
398
398
|
describe "with invalid params" do
|
399
399
|
it "assigns the requested answer as @answer" do
|
400
|
-
put :update, :
|
400
|
+
put :update, id: answers(:answer_00003).id, answer: @invalid_attrs
|
401
401
|
response.should render_template("edit")
|
402
402
|
end
|
403
403
|
end
|
404
404
|
|
405
405
|
it "should update other user's answer" do
|
406
|
-
put :update, :
|
406
|
+
put :update, id: 3, answer: {body: 'test'}, user_id: users(:user1).username
|
407
407
|
response.should redirect_to answer_url(assigns(:answer))
|
408
408
|
end
|
409
409
|
end
|
@@ -413,41 +413,41 @@ describe AnswersController do
|
|
413
413
|
|
414
414
|
describe "with valid params" do
|
415
415
|
it "updates the requested answer" do
|
416
|
-
put :update, :
|
416
|
+
put :update, id: answers(:answer_00003).id, answer: @attrs
|
417
417
|
end
|
418
418
|
|
419
419
|
it "assigns the requested answer as @answer" do
|
420
|
-
put :update, :
|
420
|
+
put :update, id: answers(:answer_00003).id, answer: @attrs
|
421
421
|
assigns(:answer).should eq(Answer.find(3))
|
422
422
|
end
|
423
423
|
end
|
424
424
|
|
425
425
|
describe "with invalid params" do
|
426
426
|
it "assigns the requested answer as @answer" do
|
427
|
-
put :update, :
|
427
|
+
put :update, id: answers(:answer_00003).id, answer: @invalid_attrs
|
428
428
|
response.should render_template("edit")
|
429
429
|
end
|
430
430
|
end
|
431
431
|
|
432
432
|
it "should update my answer" do
|
433
|
-
put :update, :
|
433
|
+
put :update, id: answers(:answer_00003), answer: {body: 'test'}, user_id: users(:user1).username
|
434
434
|
response.should redirect_to answer_url(assigns(:answer))
|
435
435
|
end
|
436
436
|
|
437
437
|
it "should not update missing answer" do
|
438
438
|
lambda{
|
439
|
-
put :update, :
|
439
|
+
put :update, id: 'missing', answer: {body: 'test'}, user_id: users(:user1).username
|
440
440
|
}.should raise_error(ActiveRecord::RecordNotFound)
|
441
441
|
#response.should be_missing
|
442
442
|
end
|
443
443
|
|
444
444
|
it "should not update other user's answer" do
|
445
|
-
put :update, :
|
445
|
+
put :update, id: 5, answer: {body: 'test'}, user_id: users(:user2).username
|
446
446
|
response.should be_forbidden
|
447
447
|
end
|
448
448
|
|
449
449
|
it "should update my answer with question_id" do
|
450
|
-
put :update, :
|
450
|
+
put :update, id: 3, answer: {body: 'test'}, user_id: users(:user1).username, question_id: 1
|
451
451
|
response.should redirect_to answer_url(assigns(:answer))
|
452
452
|
end
|
453
453
|
end
|
@@ -455,11 +455,11 @@ describe AnswersController do
|
|
455
455
|
describe "When not logged in" do
|
456
456
|
describe "with valid params" do
|
457
457
|
it "updates the requested answer" do
|
458
|
-
put :update, :
|
458
|
+
put :update, id: @answer.id, answer: @attrs
|
459
459
|
end
|
460
460
|
|
461
461
|
it "assigns the requested answer as @answer" do
|
462
|
-
put :update, :
|
462
|
+
put :update, id: @answer.id, answer: @attrs
|
463
463
|
assigns(:answer).should eq(@answer)
|
464
464
|
response.should redirect_to new_user_session_url
|
465
465
|
end
|
@@ -472,19 +472,19 @@ describe AnswersController do
|
|
472
472
|
login_fixture_user
|
473
473
|
|
474
474
|
it "should destroy my answer" do
|
475
|
-
delete :destroy, :
|
475
|
+
delete :destroy, id: 3
|
476
476
|
response.should redirect_to question_answers_url(assigns(:answer).question)
|
477
477
|
end
|
478
478
|
|
479
479
|
it "should not destroy other user's answer" do
|
480
|
-
delete :destroy, :
|
480
|
+
delete :destroy, id: 5
|
481
481
|
response.should be_forbidden
|
482
482
|
end
|
483
483
|
end
|
484
484
|
|
485
485
|
describe "When not logged in" do
|
486
486
|
it "should be forbidden" do
|
487
|
-
delete :destroy, :
|
487
|
+
delete :destroy, id: 1
|
488
488
|
response.should redirect_to new_user_session_url
|
489
489
|
end
|
490
490
|
end
|