enju_question 0.0.3
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.
- data/MIT-LICENSE +20 -0
- data/README.rdoc +3 -0
- data/Rakefile +36 -0
- data/app/controllers/answers_controller.rb +140 -0
- data/app/controllers/questions_controller.rb +171 -0
- data/app/models/answer.rb +59 -0
- data/app/models/answer_has_item.rb +20 -0
- data/app/models/question.rb +87 -0
- data/app/models/question_sweeper.rb +17 -0
- data/app/views/answers/_form.html.erb +33 -0
- data/app/views/answers/edit.html.erb +13 -0
- data/app/views/answers/index.atom.builder +16 -0
- data/app/views/answers/index.html.erb +44 -0
- data/app/views/answers/index.rss.builder +31 -0
- data/app/views/answers/new.html.erb +14 -0
- data/app/views/answers/new.mobile.erb +35 -0
- data/app/views/answers/show.html.erb +54 -0
- data/app/views/questions/_crd.html.erb +24 -0
- data/app/views/questions/_index.html.erb +22 -0
- data/app/views/questions/_index_user.html.erb +18 -0
- data/app/views/questions/_list.html.erb +69 -0
- data/app/views/questions/_solved_facet.html.erb +21 -0
- data/app/views/questions/edit.html.erb +44 -0
- data/app/views/questions/index.atom.builder +16 -0
- data/app/views/questions/index.html.erb +5 -0
- data/app/views/questions/index.js.erb +2 -0
- data/app/views/questions/index.mobile.erb +21 -0
- data/app/views/questions/index.rss.builder +41 -0
- data/app/views/questions/index_crd.xml.builder +36 -0
- data/app/views/questions/new.html.erb +35 -0
- data/app/views/questions/show.html.erb +62 -0
- data/app/views/questions/show.mobile.erb +46 -0
- data/app/views/questions/show_crd.xml.builder +34 -0
- data/config/routes.rb +10 -0
- data/db/migrate/098_create_questions.rb +21 -0
- data/db/migrate/099_create_answers.rb +21 -0
- data/db/migrate/20100217054028_create_answer_has_items.rb +17 -0
- data/lib/enju_question/engine.rb +4 -0
- data/lib/enju_question/version.rb +3 -0
- data/lib/enju_question.rb +4 -0
- data/lib/tasks/enju_question_tasks.rake +4 -0
- data/spec/cassette_library/enju_ndl/crd.yml +440 -0
- data/spec/controllers/answers_controller_spec.rb +486 -0
- data/spec/controllers/questions_controller_spec.rb +559 -0
- data/spec/dummy/Rakefile +7 -0
- data/spec/dummy/app/assets/javascripts/application.js +9 -0
- data/spec/dummy/app/assets/stylesheets/application.css +7 -0
- data/spec/dummy/app/controllers/application_controller.rb +106 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/models/ability.rb +42 -0
- data/spec/dummy/app/models/item.rb +5 -0
- data/spec/dummy/app/models/role.rb +8 -0
- data/spec/dummy/app/models/user.rb +29 -0
- data/spec/dummy/app/models/user_group.rb +2 -0
- data/spec/dummy/app/models/user_has_role.rb +4 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/app/views/page/403.html.erb +9 -0
- data/spec/dummy/app/views/page/403.mobile.erb +5 -0
- data/spec/dummy/app/views/page/403.xml.erb +4 -0
- data/spec/dummy/app/views/page/404.html.erb +9 -0
- data/spec/dummy/app/views/page/404.mobile.erb +5 -0
- data/spec/dummy/app/views/page/404.xml.erb +4 -0
- data/spec/dummy/config/application.rb +46 -0
- data/spec/dummy/config/boot.rb +10 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +30 -0
- data/spec/dummy/config/environments/production.rb +60 -0
- data/spec/dummy/config/environments/test.rb +39 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/devise.rb +209 -0
- data/spec/dummy/config/initializers/inflections.rb +10 -0
- data/spec/dummy/config/initializers/mime_types.rb +6 -0
- data/spec/dummy/config/initializers/secret_token.rb +7 -0
- data/spec/dummy/config/initializers/session_store.rb +8 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +5 -0
- data/spec/dummy/config/routes.rb +60 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/migrate/006_create_items.rb +36 -0
- data/spec/dummy/db/migrate/20100525171356_acts_as_taggable_on_migration.rb +30 -0
- data/spec/dummy/db/migrate/20111201121636_create_languages.rb +16 -0
- data/spec/dummy/db/migrate/20111201121844_create_roles.rb +12 -0
- data/spec/dummy/db/migrate/20111201155456_create_users.rb +13 -0
- data/spec/dummy/db/migrate/20111201155513_add_devise_to_users.rb +31 -0
- data/spec/dummy/db/migrate/20111201163342_create_user_groups.rb +12 -0
- data/spec/dummy/db/migrate/20111201163718_create_user_has_roles.rb +10 -0
- data/spec/dummy/db/schema.rb +168 -0
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/lib/expire_editable_fragment.rb +62 -0
- data/spec/dummy/log/development.log +2 -0
- data/spec/dummy/log/sunspot-solr-test.log +222 -0
- data/spec/dummy/log/test.log +77918 -0
- data/spec/dummy/public/404.html +26 -0
- data/spec/dummy/public/422.html +26 -0
- data/spec/dummy/public/500.html +26 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/script/rails +6 -0
- data/spec/dummy/solr/conf/admin-extra.html +31 -0
- data/spec/dummy/solr/conf/elevate.xml +36 -0
- data/spec/dummy/solr/conf/mapping-ISOLatin1Accent.txt +246 -0
- data/spec/dummy/solr/conf/protwords.txt +21 -0
- data/spec/dummy/solr/conf/schema.xml +238 -0
- data/spec/dummy/solr/conf/scripts.conf +24 -0
- data/spec/dummy/solr/conf/solrconfig.xml +934 -0
- data/spec/dummy/solr/conf/spellings.txt +2 -0
- data/spec/dummy/solr/conf/stopwords.txt +58 -0
- data/spec/dummy/solr/conf/synonyms.txt +31 -0
- data/spec/dummy/solr/data/test/index/segments.gen +0 -0
- data/spec/dummy/solr/data/test/index/segments_1 +0 -0
- data/spec/dummy/solr/data/test/spellchecker/segments.gen +0 -0
- data/spec/dummy/solr/data/test/spellchecker/segments_1 +0 -0
- data/spec/factories/answer.rb +7 -0
- data/spec/factories/question.rb +6 -0
- data/spec/factories/user.rb +34 -0
- data/spec/fixtures/answer_has_items.yml +26 -0
- data/spec/fixtures/answers.yml +61 -0
- data/spec/fixtures/questions.yml +61 -0
- data/spec/fixtures/roles.yml +21 -0
- data/spec/fixtures/user_groups.yml +25 -0
- data/spec/fixtures/user_has_roles.yml +41 -0
- data/spec/fixtures/users.yml +69 -0
- data/spec/models/answer_has_item_spec.rb +20 -0
- data/spec/models/answer_spec.rb +25 -0
- data/spec/spec_helper.rb +48 -0
- data/spec/support/controller_macros.rb +48 -0
- data/spec/support/devise.rb +4 -0
- data/spec/support/vcr.rb +6 -0
- metadata +306 -0
|
@@ -0,0 +1,559 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe QuestionsController do
|
|
4
|
+
fixtures :all
|
|
5
|
+
|
|
6
|
+
describe "GET index", :solr => true do
|
|
7
|
+
describe "When logged in as Administrator" do
|
|
8
|
+
login_fixture_admin
|
|
9
|
+
|
|
10
|
+
it "assigns all questions as @questions" do
|
|
11
|
+
get :index
|
|
12
|
+
assigns(:questions).should_not be_nil
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
describe "When logged in as Librarian" do
|
|
17
|
+
login_fixture_librarian
|
|
18
|
+
|
|
19
|
+
it "assigns all questions as @questions" do
|
|
20
|
+
get :index
|
|
21
|
+
assigns(:questions).should_not be_nil
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
it "assigns all questions as @questionsin rss format" do
|
|
25
|
+
get :index, :format => 'rss'
|
|
26
|
+
assigns(:questions).should_not be_nil
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
describe "When logged in as User" do
|
|
31
|
+
login_fixture_user
|
|
32
|
+
|
|
33
|
+
it "assigns all questions as @questions" do
|
|
34
|
+
get :index
|
|
35
|
+
assigns(:questions).should_not be_nil
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
it "should get my index feed" do
|
|
39
|
+
get :index, :format => 'rss'
|
|
40
|
+
response.should be_success
|
|
41
|
+
assigns(:questions).should eq Question.public_questions.order(:updated_at).page(1)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
it "should redirect_to my index feed if user_id is specified" do
|
|
45
|
+
get :index, :user_id => users(:user1).username, :format => 'rss'
|
|
46
|
+
response.should be_success
|
|
47
|
+
assigns(:questions).should eq users(:user1).questions
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
it "should get other user's index" do
|
|
51
|
+
get :index, :user_id => users(:user2).username
|
|
52
|
+
response.should be_success
|
|
53
|
+
assigns(:questions).should_not be_empty
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
it "should get other user's index feed" do
|
|
57
|
+
get :index, :user_id => users(:user2).username, :format => 'rss'
|
|
58
|
+
response.should be_success
|
|
59
|
+
assigns(:questions).should_not be_empty
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
describe "When not logged in" do
|
|
64
|
+
use_vcr_cassette "enju_ndl/crd", :record => :new_episodes
|
|
65
|
+
|
|
66
|
+
it "assigns all questions as @questions" do
|
|
67
|
+
get :index
|
|
68
|
+
assigns(:questions).should_not be_nil
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
it "should get index with query" do
|
|
72
|
+
get :index, :query => 'Yahoo'
|
|
73
|
+
response.should be_success
|
|
74
|
+
assigns(:questions).should_not be_nil
|
|
75
|
+
assigns(:crd_results).should_not be_nil
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
it "should render crd_xml template" do
|
|
79
|
+
get :index, :query => 'Yahoo', :mode => 'crd', :format => :xml
|
|
80
|
+
response.should be_success
|
|
81
|
+
response.should render_template("questions/index_crd")
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
describe "GET show" do
|
|
87
|
+
before(:each) do
|
|
88
|
+
@question = FactoryGirl.create(:question)
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
describe "When logged in as Administrator" do
|
|
92
|
+
login_fixture_admin
|
|
93
|
+
|
|
94
|
+
it "assigns the requested question as @question" do
|
|
95
|
+
get :show, :id => @question.id
|
|
96
|
+
assigns(:question).should eq(@question)
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
describe "When logged in as Librarian" do
|
|
101
|
+
login_fixture_librarian
|
|
102
|
+
|
|
103
|
+
it "assigns the requested question as @question" do
|
|
104
|
+
get :show, :id => @question.id
|
|
105
|
+
assigns(:question).should eq(@question)
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
describe "When logged in as User" do
|
|
110
|
+
login_fixture_user
|
|
111
|
+
|
|
112
|
+
it "assigns the requested question as @question" do
|
|
113
|
+
get :show, :id => @question.id
|
|
114
|
+
assigns(:question).should eq(@question)
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
it "should show other user's question" do
|
|
118
|
+
get :show, :id => 5
|
|
119
|
+
response.should be_success
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
it "should not show missing question" do
|
|
123
|
+
get :show, :id => 'missing'
|
|
124
|
+
response.should be_missing
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
it "should show my question" do
|
|
128
|
+
get :show, :id => 3
|
|
129
|
+
assigns(:question).should eq Question.find(3)
|
|
130
|
+
response.should be_success
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
it "should show other user's shared question" do
|
|
134
|
+
get :show, :id => 5
|
|
135
|
+
assigns(:question).should eq Question.find(5)
|
|
136
|
+
response.should be_success
|
|
137
|
+
end
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
describe "When not logged in" do
|
|
141
|
+
it "assigns the requested question as @question" do
|
|
142
|
+
get :show, :id => @question.id
|
|
143
|
+
assigns(:question).should eq(@question)
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
it "should show crd xml" do
|
|
147
|
+
get :show, :id => @question.id, :mode => 'crd', :format => :xml
|
|
148
|
+
response.should be_success
|
|
149
|
+
response.should render_template("questions/show_crd")
|
|
150
|
+
end
|
|
151
|
+
end
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
describe "GET new" do
|
|
155
|
+
describe "When logged in as Administrator" do
|
|
156
|
+
login_fixture_admin
|
|
157
|
+
|
|
158
|
+
it "assigns the requested question as @question" do
|
|
159
|
+
get :new
|
|
160
|
+
assigns(:question).should_not be_valid
|
|
161
|
+
end
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
describe "When logged in as Librarian" do
|
|
165
|
+
login_fixture_librarian
|
|
166
|
+
|
|
167
|
+
it "assigns the requested question as @question" do
|
|
168
|
+
get :new
|
|
169
|
+
assigns(:question).should_not be_valid
|
|
170
|
+
end
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
describe "When logged in as User" do
|
|
174
|
+
login_fixture_user
|
|
175
|
+
|
|
176
|
+
it "should assign the requested question as @question" do
|
|
177
|
+
get :new
|
|
178
|
+
assigns(:question).should_not be_valid
|
|
179
|
+
end
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
describe "When not logged in" do
|
|
183
|
+
it "should not assign the requested question as @question" do
|
|
184
|
+
get :new
|
|
185
|
+
assigns(:question).should_not be_valid
|
|
186
|
+
response.should redirect_to(new_user_session_url)
|
|
187
|
+
end
|
|
188
|
+
end
|
|
189
|
+
end
|
|
190
|
+
|
|
191
|
+
describe "GET edit" do
|
|
192
|
+
before(:each) do
|
|
193
|
+
@question = FactoryGirl.create(:question)
|
|
194
|
+
end
|
|
195
|
+
|
|
196
|
+
describe "When logged in as Administrator" do
|
|
197
|
+
login_fixture_admin
|
|
198
|
+
|
|
199
|
+
it "assigns the requested question as @question" do
|
|
200
|
+
get :edit, :id => @question.id
|
|
201
|
+
assigns(:question).should eq(@question)
|
|
202
|
+
end
|
|
203
|
+
end
|
|
204
|
+
|
|
205
|
+
describe "When logged in as Librarian" do
|
|
206
|
+
login_fixture_librarian
|
|
207
|
+
|
|
208
|
+
it "assigns the requested question as @question" do
|
|
209
|
+
get :edit, :id => @question.id
|
|
210
|
+
assigns(:question).should eq(@question)
|
|
211
|
+
end
|
|
212
|
+
end
|
|
213
|
+
|
|
214
|
+
describe "When logged in as User" do
|
|
215
|
+
login_fixture_user
|
|
216
|
+
|
|
217
|
+
it "assigns the requested question as @question" do
|
|
218
|
+
get :edit, :id => @question.id
|
|
219
|
+
response.should be_forbidden
|
|
220
|
+
end
|
|
221
|
+
|
|
222
|
+
it "should not edit other user's question" do
|
|
223
|
+
get :edit, :id => 5
|
|
224
|
+
response.should be_forbidden
|
|
225
|
+
end
|
|
226
|
+
|
|
227
|
+
it "should not edit missing question" do
|
|
228
|
+
get :edit, :id => 'missing'
|
|
229
|
+
response.should be_missing
|
|
230
|
+
end
|
|
231
|
+
|
|
232
|
+
it "should edit my question" do
|
|
233
|
+
get :edit, :id => 3
|
|
234
|
+
response.should be_success
|
|
235
|
+
end
|
|
236
|
+
end
|
|
237
|
+
|
|
238
|
+
describe "When not logged in" do
|
|
239
|
+
it "should not assign the requested question as @question" do
|
|
240
|
+
get :edit, :id => @question.id
|
|
241
|
+
response.should redirect_to(new_user_session_url)
|
|
242
|
+
end
|
|
243
|
+
end
|
|
244
|
+
end
|
|
245
|
+
|
|
246
|
+
describe "POST create" do
|
|
247
|
+
before(:each) do
|
|
248
|
+
@attrs = FactoryGirl.attributes_for(:question)
|
|
249
|
+
@invalid_attrs = {:body => ''}
|
|
250
|
+
end
|
|
251
|
+
|
|
252
|
+
describe "When logged in as Administrator" do
|
|
253
|
+
login_fixture_admin
|
|
254
|
+
|
|
255
|
+
describe "with valid params" do
|
|
256
|
+
it "assigns a newly created question as @question" do
|
|
257
|
+
post :create, :question => @attrs
|
|
258
|
+
assigns(:question).should be_valid
|
|
259
|
+
end
|
|
260
|
+
|
|
261
|
+
it "redirects to the created question" do
|
|
262
|
+
post :create, :question => @attrs
|
|
263
|
+
response.should redirect_to(question_url(assigns(:question)))
|
|
264
|
+
end
|
|
265
|
+
end
|
|
266
|
+
|
|
267
|
+
describe "with invalid params" do
|
|
268
|
+
it "assigns a newly created but unsaved question as @question" do
|
|
269
|
+
post :create, :question => @invalid_attrs
|
|
270
|
+
assigns(:question).should_not be_valid
|
|
271
|
+
end
|
|
272
|
+
|
|
273
|
+
it "re-renders the 'new' template" do
|
|
274
|
+
post :create, :question => @invalid_attrs
|
|
275
|
+
response.should render_template("new")
|
|
276
|
+
end
|
|
277
|
+
end
|
|
278
|
+
end
|
|
279
|
+
|
|
280
|
+
describe "When logged in as Librarian" do
|
|
281
|
+
login_fixture_librarian
|
|
282
|
+
|
|
283
|
+
describe "with valid params" do
|
|
284
|
+
it "assigns a newly created question as @question" do
|
|
285
|
+
post :create, :question => @attrs
|
|
286
|
+
assigns(:question).should be_valid
|
|
287
|
+
end
|
|
288
|
+
|
|
289
|
+
it "redirects to the created question" do
|
|
290
|
+
post :create, :question => @attrs
|
|
291
|
+
response.should redirect_to(question_url(assigns(:question)))
|
|
292
|
+
end
|
|
293
|
+
end
|
|
294
|
+
|
|
295
|
+
describe "with invalid params" do
|
|
296
|
+
it "assigns a newly created but unsaved question as @question" do
|
|
297
|
+
post :create, :question => @invalid_attrs
|
|
298
|
+
assigns(:question).should_not be_valid
|
|
299
|
+
end
|
|
300
|
+
|
|
301
|
+
it "re-renders the 'new' template" do
|
|
302
|
+
post :create, :question => @invalid_attrs
|
|
303
|
+
response.should render_template("new")
|
|
304
|
+
end
|
|
305
|
+
end
|
|
306
|
+
end
|
|
307
|
+
|
|
308
|
+
describe "When logged in as User" do
|
|
309
|
+
login_fixture_user
|
|
310
|
+
|
|
311
|
+
describe "with valid params" do
|
|
312
|
+
it "assigns a newly created question as @question" do
|
|
313
|
+
post :create, :question => @attrs
|
|
314
|
+
assigns(:question).should be_valid
|
|
315
|
+
end
|
|
316
|
+
|
|
317
|
+
it "redirects to the created question" do
|
|
318
|
+
post :create, :question => @attrs
|
|
319
|
+
response.should redirect_to(question_url(assigns(:question)))
|
|
320
|
+
end
|
|
321
|
+
end
|
|
322
|
+
|
|
323
|
+
describe "with invalid params" do
|
|
324
|
+
it "assigns a newly created but unsaved question as @question" do
|
|
325
|
+
post :create, :question => @invalid_attrs
|
|
326
|
+
assigns(:question).should_not be_valid
|
|
327
|
+
end
|
|
328
|
+
|
|
329
|
+
it "re-renders the 'new' template" do
|
|
330
|
+
post :create, :question => @invalid_attrs
|
|
331
|
+
response.should render_template("new")
|
|
332
|
+
end
|
|
333
|
+
end
|
|
334
|
+
end
|
|
335
|
+
|
|
336
|
+
describe "When not logged in" do
|
|
337
|
+
describe "with valid params" do
|
|
338
|
+
it "assigns a newly created question as @question" do
|
|
339
|
+
post :create, :question => @attrs
|
|
340
|
+
assigns(:question).should be_valid
|
|
341
|
+
end
|
|
342
|
+
|
|
343
|
+
it "should be forbidden" do
|
|
344
|
+
post :create, :question => @attrs
|
|
345
|
+
response.should redirect_to(new_user_session_url)
|
|
346
|
+
end
|
|
347
|
+
end
|
|
348
|
+
|
|
349
|
+
describe "with invalid params" do
|
|
350
|
+
it "assigns a newly created but unsaved question as @question" do
|
|
351
|
+
post :create, :question => @invalid_attrs
|
|
352
|
+
assigns(:question).should_not be_valid
|
|
353
|
+
end
|
|
354
|
+
|
|
355
|
+
it "should be forbidden" do
|
|
356
|
+
post :create, :question => @invalid_attrs
|
|
357
|
+
response.should redirect_to(new_user_session_url)
|
|
358
|
+
end
|
|
359
|
+
end
|
|
360
|
+
end
|
|
361
|
+
end
|
|
362
|
+
|
|
363
|
+
describe "PUT update" do
|
|
364
|
+
before(:each) do
|
|
365
|
+
@question = FactoryGirl.create(:question)
|
|
366
|
+
@attrs = FactoryGirl.attributes_for(:question)
|
|
367
|
+
@invalid_attrs = {:body => ''}
|
|
368
|
+
end
|
|
369
|
+
|
|
370
|
+
describe "When logged in as Administrator" do
|
|
371
|
+
login_fixture_admin
|
|
372
|
+
|
|
373
|
+
describe "with valid params" do
|
|
374
|
+
it "updates the requested question" do
|
|
375
|
+
put :update, :id => @question.id, :question => @attrs
|
|
376
|
+
end
|
|
377
|
+
|
|
378
|
+
it "assigns the requested question as @question" do
|
|
379
|
+
put :update, :id => @question.id, :question => @attrs
|
|
380
|
+
assigns(:question).should eq(@question)
|
|
381
|
+
end
|
|
382
|
+
end
|
|
383
|
+
|
|
384
|
+
describe "with invalid params" do
|
|
385
|
+
it "assigns the requested question as @question" do
|
|
386
|
+
put :update, :id => @question.id, :question => @invalid_attrs
|
|
387
|
+
end
|
|
388
|
+
|
|
389
|
+
it "re-renders the 'edit' template" do
|
|
390
|
+
put :update, :id => @question.id, :question => @invalid_attrs
|
|
391
|
+
response.should render_template("edit")
|
|
392
|
+
end
|
|
393
|
+
end
|
|
394
|
+
|
|
395
|
+
it "should not update my question without body" do
|
|
396
|
+
put :update, :id => 3, :question => {:body => ""}
|
|
397
|
+
assigns(:question).should_not be_valid
|
|
398
|
+
response.should be_success
|
|
399
|
+
end
|
|
400
|
+
|
|
401
|
+
it "should not update missing question" do
|
|
402
|
+
put :update, :id => 'missing', :question => { }
|
|
403
|
+
response.should be_missing
|
|
404
|
+
end
|
|
405
|
+
end
|
|
406
|
+
|
|
407
|
+
describe "When logged in as Librarian" do
|
|
408
|
+
login_fixture_librarian
|
|
409
|
+
|
|
410
|
+
describe "with valid params" do
|
|
411
|
+
it "updates the requested question" do
|
|
412
|
+
put :update, :id => @question.id, :question => @attrs
|
|
413
|
+
end
|
|
414
|
+
|
|
415
|
+
it "assigns the requested question as @question" do
|
|
416
|
+
put :update, :id => @question.id, :question => @attrs
|
|
417
|
+
assigns(:question).should eq(@question)
|
|
418
|
+
response.should redirect_to(@question)
|
|
419
|
+
end
|
|
420
|
+
end
|
|
421
|
+
|
|
422
|
+
describe "with invalid params" do
|
|
423
|
+
it "assigns the question as @question" do
|
|
424
|
+
put :update, :id => @question.id, :question => @invalid_attrs
|
|
425
|
+
assigns(:question).should_not be_valid
|
|
426
|
+
end
|
|
427
|
+
|
|
428
|
+
it "re-renders the 'edit' template" do
|
|
429
|
+
put :update, :id => @question.id, :question => @invalid_attrs
|
|
430
|
+
response.should render_template("edit")
|
|
431
|
+
end
|
|
432
|
+
end
|
|
433
|
+
end
|
|
434
|
+
|
|
435
|
+
describe "When logged in as User" do
|
|
436
|
+
login_fixture_user
|
|
437
|
+
|
|
438
|
+
describe "with valid params" do
|
|
439
|
+
it "updates the requested question" do
|
|
440
|
+
put :update, :id => @question.id, :question => @attrs
|
|
441
|
+
end
|
|
442
|
+
|
|
443
|
+
it "should be forbidden" do
|
|
444
|
+
put :update, :id => @question.id, :question => @attrs
|
|
445
|
+
assigns(:question).should eq(@question)
|
|
446
|
+
response.should be_forbidden
|
|
447
|
+
end
|
|
448
|
+
end
|
|
449
|
+
|
|
450
|
+
describe "with invalid params" do
|
|
451
|
+
it "assigns the question as @question" do
|
|
452
|
+
put :update, :id => @question.id, :question => @invalid_attrs
|
|
453
|
+
end
|
|
454
|
+
|
|
455
|
+
it "should be forbidden" do
|
|
456
|
+
put :update, :id => @question.id, :question => @invalid_attrs
|
|
457
|
+
response.should be_forbidden
|
|
458
|
+
end
|
|
459
|
+
end
|
|
460
|
+
|
|
461
|
+
it "should update my question" do
|
|
462
|
+
put :update, :id => 3, :question => { }
|
|
463
|
+
assigns(:question).should eq Question.find(3)
|
|
464
|
+
response.should redirect_to(assigns(:question))
|
|
465
|
+
end
|
|
466
|
+
end
|
|
467
|
+
|
|
468
|
+
describe "When not logged in" do
|
|
469
|
+
describe "with valid params" do
|
|
470
|
+
it "updates the requested question" do
|
|
471
|
+
put :update, :id => @question.id, :question => @attrs
|
|
472
|
+
end
|
|
473
|
+
|
|
474
|
+
it "should be forbidden" do
|
|
475
|
+
put :update, :id => @question.id, :question => @attrs
|
|
476
|
+
response.should redirect_to(new_user_session_url)
|
|
477
|
+
end
|
|
478
|
+
end
|
|
479
|
+
|
|
480
|
+
describe "with invalid params" do
|
|
481
|
+
it "assigns the requested question as @question" do
|
|
482
|
+
put :update, :id => @question.id, :question => @invalid_attrs
|
|
483
|
+
response.should redirect_to(new_user_session_url)
|
|
484
|
+
end
|
|
485
|
+
end
|
|
486
|
+
end
|
|
487
|
+
end
|
|
488
|
+
|
|
489
|
+
describe "DELETE destroy" do
|
|
490
|
+
before(:each) do
|
|
491
|
+
@question = FactoryGirl.create(:question)
|
|
492
|
+
end
|
|
493
|
+
|
|
494
|
+
describe "When logged in as Administrator" do
|
|
495
|
+
login_fixture_admin
|
|
496
|
+
|
|
497
|
+
it "destroys the requested question" do
|
|
498
|
+
delete :destroy, :id => @question.id
|
|
499
|
+
end
|
|
500
|
+
|
|
501
|
+
it "redirects to the questions list" do
|
|
502
|
+
delete :destroy, :id => @question.id
|
|
503
|
+
response.should redirect_to(user_questions_url(assigns(:question).user))
|
|
504
|
+
end
|
|
505
|
+
|
|
506
|
+
it "should not destroy missing question" do
|
|
507
|
+
delete :destroy, :id => 'missing'
|
|
508
|
+
response.should be_missing
|
|
509
|
+
end
|
|
510
|
+
end
|
|
511
|
+
|
|
512
|
+
describe "When logged in as Librarian" do
|
|
513
|
+
login_fixture_librarian
|
|
514
|
+
|
|
515
|
+
it "destroys the requested question" do
|
|
516
|
+
delete :destroy, :id => @question.id
|
|
517
|
+
end
|
|
518
|
+
|
|
519
|
+
it "redirects to the questions list" do
|
|
520
|
+
delete :destroy, :id => @question.id
|
|
521
|
+
response.should redirect_to(user_questions_url(assigns(:question).user))
|
|
522
|
+
end
|
|
523
|
+
end
|
|
524
|
+
|
|
525
|
+
describe "When logged in as User" do
|
|
526
|
+
login_fixture_user
|
|
527
|
+
|
|
528
|
+
it "destroys the requested question" do
|
|
529
|
+
delete :destroy, :id => @question.id
|
|
530
|
+
end
|
|
531
|
+
|
|
532
|
+
it "should be forbidden" do
|
|
533
|
+
delete :destroy, :id => @question.id
|
|
534
|
+
response.should be_forbidden
|
|
535
|
+
end
|
|
536
|
+
|
|
537
|
+
it "should destroy my question" do
|
|
538
|
+
delete :destroy, :id => 3
|
|
539
|
+
response.should redirect_to user_questions_url(assigns(:question).user)
|
|
540
|
+
end
|
|
541
|
+
|
|
542
|
+
it "should not destroy other question" do
|
|
543
|
+
delete :destroy, :id => 5
|
|
544
|
+
response.should be_forbidden
|
|
545
|
+
end
|
|
546
|
+
end
|
|
547
|
+
|
|
548
|
+
describe "When not logged in" do
|
|
549
|
+
it "destroys the requested question" do
|
|
550
|
+
delete :destroy, :id => @question.id
|
|
551
|
+
end
|
|
552
|
+
|
|
553
|
+
it "should be forbidden" do
|
|
554
|
+
delete :destroy, :id => @question.id
|
|
555
|
+
response.should redirect_to(new_user_session_url)
|
|
556
|
+
end
|
|
557
|
+
end
|
|
558
|
+
end
|
|
559
|
+
end
|
data/spec/dummy/Rakefile
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
#!/usr/bin/env rake
|
|
2
|
+
# Add your own tasks in files placed in lib/tasks ending in .rake,
|
|
3
|
+
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
|
|
4
|
+
|
|
5
|
+
require File.expand_path('../config/application', __FILE__)
|
|
6
|
+
|
|
7
|
+
Dummy::Application.load_tasks
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// This is a manifest file that'll be compiled into including all the files listed below.
|
|
2
|
+
// Add new JavaScript/Coffee code in separate files in this directory and they'll automatically
|
|
3
|
+
// be included in the compiled file accessible from http://example.com/assets/application.js
|
|
4
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
|
5
|
+
// the compiled file.
|
|
6
|
+
//
|
|
7
|
+
//= require jquery
|
|
8
|
+
//= require jquery_ujs
|
|
9
|
+
//= require_tree .
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* This is a manifest file that'll automatically include all the stylesheets available in this directory
|
|
3
|
+
* and any sub-directories. You're free to add application-wide styles to this file and they'll appear at
|
|
4
|
+
* the top of the compiled file, but it's generally better to create a new file per style scope.
|
|
5
|
+
*= require_self
|
|
6
|
+
*= require_tree .
|
|
7
|
+
*/
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
class ApplicationController < ActionController::Base
|
|
2
|
+
protect_from_forgery
|
|
3
|
+
|
|
4
|
+
rescue_from CanCan::AccessDenied, :with => :render_403
|
|
5
|
+
rescue_from ActiveRecord::RecordNotFound, :with => :render_404
|
|
6
|
+
|
|
7
|
+
before_filter :set_locale
|
|
8
|
+
|
|
9
|
+
private
|
|
10
|
+
def render_403
|
|
11
|
+
return if performed?
|
|
12
|
+
if user_signed_in?
|
|
13
|
+
respond_to do |format|
|
|
14
|
+
format.html {render :template => 'page/403', :status => 403}
|
|
15
|
+
format.mobile {render :template => 'page/403', :status => 403}
|
|
16
|
+
format.xml {render :template => 'page/403', :status => 403}
|
|
17
|
+
format.json
|
|
18
|
+
end
|
|
19
|
+
else
|
|
20
|
+
respond_to do |format|
|
|
21
|
+
format.html {redirect_to new_user_session_url}
|
|
22
|
+
format.mobile {redirect_to new_user_session_url}
|
|
23
|
+
format.xml {render :template => 'page/403', :status => 403}
|
|
24
|
+
format.json
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def render_404
|
|
30
|
+
return if performed?
|
|
31
|
+
respond_to do |format|
|
|
32
|
+
format.html {render :template => 'page/404', :status => 404}
|
|
33
|
+
format.mobile {render :template => 'page/404', :status => 404}
|
|
34
|
+
format.xml {render :template => 'page/404', :status => 404}
|
|
35
|
+
format.json
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def set_locale
|
|
40
|
+
if params[:locale]
|
|
41
|
+
unless I18n.available_locales.include?(params[:locale].to_s.intern)
|
|
42
|
+
raise InvalidLocaleError
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
if user_signed_in?
|
|
46
|
+
locale = params[:locale] || session[:locale] || current_user.locale.try(:to_sym)
|
|
47
|
+
else
|
|
48
|
+
locale = params[:locale] || session[:locale]
|
|
49
|
+
end
|
|
50
|
+
if locale
|
|
51
|
+
I18n.locale = @locale = session[:locale] = locale.to_sym
|
|
52
|
+
else
|
|
53
|
+
I18n.locale = @locale = session[:locale] = I18n.default_locale
|
|
54
|
+
end
|
|
55
|
+
rescue InvalidLocaleError
|
|
56
|
+
@locale = I18n.default_locale
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def not_found
|
|
60
|
+
raise ActiveRecord::RecordNotFound
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def access_denied
|
|
64
|
+
raise CanCan::AccessDenied
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def get_user_if_nil
|
|
68
|
+
@user = User.where(:username => params[:user_id]).first if params[:user_id]
|
|
69
|
+
#authorize! :show, @user if @user
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def get_question
|
|
73
|
+
@question = Question.find(params[:question_id]) if params[:question_id]
|
|
74
|
+
authorize! :show, @question if @question
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def convert_charset
|
|
78
|
+
case params[:format]
|
|
79
|
+
when 'csv'
|
|
80
|
+
return unless configatron.csv_charset_conversion
|
|
81
|
+
# TODO: 他の言語
|
|
82
|
+
if @locale.to_sym == :ja
|
|
83
|
+
headers["Content-Type"] = "text/csv; charset=Shift_JIS"
|
|
84
|
+
response.body = NKF::nkf('-Ws', response.body)
|
|
85
|
+
end
|
|
86
|
+
when 'xml'
|
|
87
|
+
if @locale.to_sym == :ja
|
|
88
|
+
headers["Content-Type"] = "application/xml; charset=Shift_JIS"
|
|
89
|
+
response.body = NKF::nkf('-Ws', response.body)
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def store_location
|
|
95
|
+
if request.get? and request.format.try(:html?) and !request.xhr?
|
|
96
|
+
session[:user_return_to] = request.fullpath
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
def solr_commit
|
|
101
|
+
Sunspot.commit
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
class InvalidLocaleError < StandardError
|
|
106
|
+
end
|