enju_barcode 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +20 -0
- data/README.rdoc +3 -0
- data/Rakefile +45 -0
- data/app/assets/javascripts/barcodes.js +2 -0
- data/app/assets/stylesheets/barcodes.css +4 -0
- data/app/assets/stylesheets/scaffold.css +56 -0
- data/app/controllers/barcodes_controller.rb +89 -0
- data/app/helpers/barcodes_helper.rb +2 -0
- data/app/models/barcode.rb +24 -0
- data/app/views/barcodes/_form.html.erb +14 -0
- data/app/views/barcodes/barcode.html.erb +32 -0
- data/app/views/barcodes/edit.html.erb +13 -0
- data/app/views/barcodes/index.html.erb +32 -0
- data/app/views/barcodes/new.html.erb +12 -0
- data/app/views/barcodes/show.html.erb +27 -0
- data/app/views/barcodes/show.png.erb +1 -0
- data/config/locales/translation_en.yml +9 -0
- data/config/locales/translation_ja.yml +9 -0
- data/config/routes.rb +3 -0
- data/db/migrate/20081108112016_create_barcodes.rb +14 -0
- data/lib/enju_barcode.rb +4 -0
- data/lib/enju_barcode/engine.rb +8 -0
- data/lib/enju_barcode/version.rb +3 -0
- data/lib/tasks/enju_barcode_tasks.rake +4 -0
- data/spec/controllers/barcodes_controller_spec.rb +479 -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 +62 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/models/ability.rb +18 -0
- data/spec/dummy/app/models/role.rb +5 -0
- data/spec/dummy/app/models/user.rb +28 -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.xml.erb +4 -0
- data/spec/dummy/app/views/page/404.html.erb +9 -0
- data/spec/dummy/app/views/page/404.xml.erb +4 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +45 -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/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/20111201163718_create_user_has_roles.rb +10 -0
- data/spec/dummy/db/schema.rb +62 -0
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/development.log +0 -0
- data/spec/dummy/log/test.log +6623 -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/factories/barcode.rb +5 -0
- data/spec/factories/user.rb +31 -0
- data/spec/fixtures/roles.yml +21 -0
- data/spec/fixtures/user_has_roles.yml +41 -0
- data/spec/fixtures/users.yml +69 -0
- data/spec/spec_helper.rb +32 -0
- data/spec/support/controller_macros.rb +48 -0
- data/spec/support/devise.rb +4 -0
- metadata +263 -0
data/lib/enju_barcode.rb
ADDED
@@ -0,0 +1,479 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe BarcodesController do
|
4
|
+
fixtures :all
|
5
|
+
|
6
|
+
describe "GET index" do
|
7
|
+
before(:each) do
|
8
|
+
FactoryGirl.create(:barcode)
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "When logged in as Administrator" do
|
12
|
+
before(:each) do
|
13
|
+
sign_in FactoryGirl.create(:admin)
|
14
|
+
end
|
15
|
+
|
16
|
+
it "assigns all barcodes as @barcodes" do
|
17
|
+
get :index
|
18
|
+
assigns(:barcodes).should eq(Barcode.all)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "When logged in as Librarian" do
|
23
|
+
before(:each) do
|
24
|
+
sign_in FactoryGirl.create(:librarian)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "assigns all barcodes as @barcodes" do
|
28
|
+
get :index
|
29
|
+
assigns(:barcodes).should eq(Barcode.all)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "When logged in as User" do
|
34
|
+
before(:each) do
|
35
|
+
sign_in FactoryGirl.create(:user)
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should be forbidden" do
|
39
|
+
get :index
|
40
|
+
assigns(:barcodes).should be_empty
|
41
|
+
response.should be_forbidden
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe "When not logged in" do
|
46
|
+
it "assigns all barcodes as @barcodes" do
|
47
|
+
get :index
|
48
|
+
assigns(:barcodes).should be_empty
|
49
|
+
response.should redirect_to(new_user_session_url)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe "GET show" do
|
55
|
+
describe "When logged in as Administrator" do
|
56
|
+
before(:each) do
|
57
|
+
sign_in FactoryGirl.create(:admin)
|
58
|
+
end
|
59
|
+
|
60
|
+
it "assigns the requested barcode as @barcode" do
|
61
|
+
barcode = FactoryGirl.create(:barcode)
|
62
|
+
get :show, :id => barcode.id
|
63
|
+
assigns(:barcode).should eq(barcode)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
describe "When logged in as Librarian" do
|
68
|
+
before(:each) do
|
69
|
+
sign_in FactoryGirl.create(:librarian)
|
70
|
+
end
|
71
|
+
|
72
|
+
it "assigns the requested barcode as @barcode" do
|
73
|
+
barcode = FactoryGirl.create(:barcode)
|
74
|
+
get :show, :id => barcode.id
|
75
|
+
assigns(:barcode).should eq(barcode)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
describe "When logged in as User" do
|
80
|
+
before(:each) do
|
81
|
+
sign_in FactoryGirl.create(:user)
|
82
|
+
end
|
83
|
+
|
84
|
+
it "assigns the requested barcode as @barcode" do
|
85
|
+
barcode = FactoryGirl.create(:barcode)
|
86
|
+
get :show, :id => barcode.id
|
87
|
+
assigns(:barcode).should eq(barcode)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
describe "When not logged in" do
|
92
|
+
it "assigns the requested barcode as @barcode" do
|
93
|
+
barcode = FactoryGirl.create(:barcode)
|
94
|
+
get :show, :id => barcode.id
|
95
|
+
assigns(:barcode).should eq(barcode)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
describe "GET new" do
|
101
|
+
describe "When logged in as Administrator" do
|
102
|
+
before(:each) do
|
103
|
+
sign_in FactoryGirl.create(:admin)
|
104
|
+
end
|
105
|
+
|
106
|
+
it "assigns the requested barcode as @barcode" do
|
107
|
+
get :new
|
108
|
+
assigns(:barcode).should_not be_valid
|
109
|
+
response.should be_success
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
describe "When logged in as Librarian" do
|
114
|
+
before(:each) do
|
115
|
+
sign_in FactoryGirl.create(:librarian)
|
116
|
+
end
|
117
|
+
|
118
|
+
it "assigns the requested barcode as @barcode" do
|
119
|
+
get :new
|
120
|
+
assigns(:barcode).should_not be_valid
|
121
|
+
response.should be_success
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
describe "When logged in as User" do
|
126
|
+
before(:each) do
|
127
|
+
sign_in FactoryGirl.create(:user)
|
128
|
+
end
|
129
|
+
|
130
|
+
it "should not assign the requested barcode as @barcode" do
|
131
|
+
get :new
|
132
|
+
assigns(:barcode).should_not be_valid
|
133
|
+
response.should be_forbidden
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
describe "When not logged in" do
|
138
|
+
it "should not assign the requested barcode as @barcode" do
|
139
|
+
get :new
|
140
|
+
assigns(:barcode).should_not be_valid
|
141
|
+
response.should redirect_to(new_user_session_url)
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
describe "GET edit" do
|
147
|
+
describe "When logged in as Administrator" do
|
148
|
+
before(:each) do
|
149
|
+
sign_in FactoryGirl.create(:admin)
|
150
|
+
end
|
151
|
+
|
152
|
+
it "assigns the requested barcode as @barcode" do
|
153
|
+
barcode = FactoryGirl.create(:barcode)
|
154
|
+
get :edit, :id => barcode.id
|
155
|
+
assigns(:barcode).should eq(barcode)
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
describe "When logged in as Librarian" do
|
160
|
+
before(:each) do
|
161
|
+
sign_in FactoryGirl.create(:librarian)
|
162
|
+
end
|
163
|
+
|
164
|
+
it "assigns the requested barcode as @barcode" do
|
165
|
+
barcode = FactoryGirl.create(:barcode)
|
166
|
+
get :edit, :id => barcode.id
|
167
|
+
assigns(:barcode).should eq(barcode)
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
describe "When logged in as User" do
|
172
|
+
before(:each) do
|
173
|
+
sign_in FactoryGirl.create(:user)
|
174
|
+
end
|
175
|
+
|
176
|
+
it "assigns the requested barcode as @barcode" do
|
177
|
+
barcode = FactoryGirl.create(:barcode)
|
178
|
+
get :edit, :id => barcode.id
|
179
|
+
response.should be_forbidden
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
describe "When not logged in" do
|
184
|
+
it "should not assign the requested barcode as @barcode" do
|
185
|
+
barcode = FactoryGirl.create(:barcode)
|
186
|
+
get :edit, :id => barcode.id
|
187
|
+
response.should redirect_to(new_user_session_url)
|
188
|
+
end
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
describe "POST create" do
|
193
|
+
before(:each) do
|
194
|
+
@attrs = FactoryGirl.attributes_for(:barcode)
|
195
|
+
@invalid_attrs = {:code_word => ''}
|
196
|
+
end
|
197
|
+
|
198
|
+
describe "When logged in as Administrator" do
|
199
|
+
before(:each) do
|
200
|
+
sign_in FactoryGirl.create(:admin)
|
201
|
+
end
|
202
|
+
|
203
|
+
describe "with valid params" do
|
204
|
+
it "assigns a newly created barcode as @barcode" do
|
205
|
+
post :create, :barcode => @attrs
|
206
|
+
assigns(:barcode).should be_valid
|
207
|
+
end
|
208
|
+
|
209
|
+
it "redirects to the created patron" do
|
210
|
+
post :create, :barcode => @attrs
|
211
|
+
response.should redirect_to(assigns(:barcode))
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
215
|
+
describe "with invalid params" do
|
216
|
+
it "assigns a newly created but unsaved barcode as @barcode" do
|
217
|
+
post :create, :barcode => @invalid_attrs
|
218
|
+
assigns(:barcode).should_not be_valid
|
219
|
+
end
|
220
|
+
|
221
|
+
it "re-renders the 'new' template" do
|
222
|
+
post :create, :barcode => @invalid_attrs
|
223
|
+
response.should render_template("new")
|
224
|
+
end
|
225
|
+
end
|
226
|
+
end
|
227
|
+
|
228
|
+
describe "When logged in as Librarian" do
|
229
|
+
before(:each) do
|
230
|
+
sign_in FactoryGirl.create(:librarian)
|
231
|
+
end
|
232
|
+
|
233
|
+
describe "with valid params" do
|
234
|
+
it "assigns a newly created barcode as @barcode" do
|
235
|
+
post :create, :barcode => @attrs
|
236
|
+
assigns(:barcode).should be_valid
|
237
|
+
end
|
238
|
+
|
239
|
+
it "redirects to the created patron" do
|
240
|
+
post :create, :barcode => @attrs
|
241
|
+
response.should redirect_to(assigns(:barcode))
|
242
|
+
end
|
243
|
+
end
|
244
|
+
|
245
|
+
describe "with invalid params" do
|
246
|
+
it "assigns a newly created but unsaved barcode as @barcode" do
|
247
|
+
post :create, :barcode => @invalid_attrs
|
248
|
+
assigns(:barcode).should_not be_valid
|
249
|
+
end
|
250
|
+
|
251
|
+
it "re-renders the 'new' template" do
|
252
|
+
post :create, :barcode => @invalid_attrs
|
253
|
+
response.should render_template("new")
|
254
|
+
end
|
255
|
+
end
|
256
|
+
end
|
257
|
+
|
258
|
+
describe "When logged in as User" do
|
259
|
+
before(:each) do
|
260
|
+
sign_in FactoryGirl.create(:user)
|
261
|
+
end
|
262
|
+
|
263
|
+
describe "with valid params" do
|
264
|
+
it "assigns a newly created barcode as @barcode" do
|
265
|
+
post :create, :barcode => @attrs
|
266
|
+
assigns(:barcode).should be_valid
|
267
|
+
end
|
268
|
+
|
269
|
+
it "should be forbidden" do
|
270
|
+
post :create, :barcode => @attrs
|
271
|
+
response.should be_forbidden
|
272
|
+
end
|
273
|
+
end
|
274
|
+
|
275
|
+
describe "with invalid params" do
|
276
|
+
it "assigns a newly created but unsaved barcode as @barcode" do
|
277
|
+
post :create, :barcode => @invalid_attrs
|
278
|
+
assigns(:barcode).should_not be_valid
|
279
|
+
end
|
280
|
+
|
281
|
+
it "should be forbidden" do
|
282
|
+
post :create, :barcode => @invalid_attrs
|
283
|
+
response.should be_forbidden
|
284
|
+
end
|
285
|
+
end
|
286
|
+
end
|
287
|
+
|
288
|
+
describe "When not logged in" do
|
289
|
+
describe "with valid params" do
|
290
|
+
it "assigns a newly created barcode as @barcode" do
|
291
|
+
post :create, :barcode => @attrs
|
292
|
+
assigns(:barcode).should be_valid
|
293
|
+
end
|
294
|
+
|
295
|
+
it "should be forbidden" do
|
296
|
+
post :create, :barcode => @attrs
|
297
|
+
response.should redirect_to(new_user_session_url)
|
298
|
+
end
|
299
|
+
end
|
300
|
+
|
301
|
+
describe "with invalid params" do
|
302
|
+
it "assigns a newly created but unsaved barcode as @barcode" do
|
303
|
+
post :create, :barcode => @invalid_attrs
|
304
|
+
assigns(:barcode).should_not be_valid
|
305
|
+
end
|
306
|
+
|
307
|
+
it "should be forbidden" do
|
308
|
+
post :create, :barcode => @invalid_attrs
|
309
|
+
response.should redirect_to(new_user_session_url)
|
310
|
+
end
|
311
|
+
end
|
312
|
+
end
|
313
|
+
end
|
314
|
+
|
315
|
+
describe "PUT update" do
|
316
|
+
before(:each) do
|
317
|
+
@barcode = FactoryGirl.create(:barcode)
|
318
|
+
@attrs = FactoryGirl.attributes_for(:barcode)
|
319
|
+
@invalid_attrs = {:code_word => ''}
|
320
|
+
end
|
321
|
+
|
322
|
+
describe "When logged in as Administrator" do
|
323
|
+
before(:each) do
|
324
|
+
sign_in FactoryGirl.create(:admin)
|
325
|
+
end
|
326
|
+
|
327
|
+
describe "with valid params" do
|
328
|
+
it "updates the requested barcode" do
|
329
|
+
put :update, :id => @barcode.id, :barcode => @attrs
|
330
|
+
end
|
331
|
+
|
332
|
+
it "assigns the requested barcode as @barcode" do
|
333
|
+
put :update, :id => @barcode.id, :barcode => @attrs
|
334
|
+
assigns(:barcode).should eq(@barcode)
|
335
|
+
response.should redirect_to(@barcode)
|
336
|
+
end
|
337
|
+
end
|
338
|
+
|
339
|
+
describe "with invalid params" do
|
340
|
+
it "assigns the requested barcode as @barcode" do
|
341
|
+
put :update, :id => @barcode.id, :barcode => @invalid_attrs
|
342
|
+
response.should render_template("edit")
|
343
|
+
end
|
344
|
+
end
|
345
|
+
end
|
346
|
+
|
347
|
+
describe "When logged in as Librarian" do
|
348
|
+
before(:each) do
|
349
|
+
sign_in FactoryGirl.create(:librarian)
|
350
|
+
end
|
351
|
+
|
352
|
+
describe "with valid params" do
|
353
|
+
it "updates the requested barcode" do
|
354
|
+
put :update, :id => @barcode.id, :barcode => @attrs
|
355
|
+
end
|
356
|
+
|
357
|
+
it "assigns the requested barcode as @barcode" do
|
358
|
+
put :update, :id => @barcode.id, :barcode => @attrs
|
359
|
+
assigns(:barcode).should eq(@barcode)
|
360
|
+
response.should redirect_to(@barcode)
|
361
|
+
end
|
362
|
+
end
|
363
|
+
|
364
|
+
describe "with invalid params" do
|
365
|
+
it "assigns the requested barcode as @barcode" do
|
366
|
+
put :update, :id => @barcode.id, :barcode => @invalid_attrs
|
367
|
+
response.should render_template("edit")
|
368
|
+
end
|
369
|
+
end
|
370
|
+
end
|
371
|
+
|
372
|
+
describe "When logged in as User" do
|
373
|
+
before(:each) do
|
374
|
+
sign_in FactoryGirl.create(:user)
|
375
|
+
end
|
376
|
+
|
377
|
+
describe "with valid params" do
|
378
|
+
it "updates the requested barcode" do
|
379
|
+
put :update, :id => @barcode.id, :barcode => @attrs
|
380
|
+
end
|
381
|
+
|
382
|
+
it "assigns the requested barcode as @barcode" do
|
383
|
+
put :update, :id => @barcode.id, :barcode => @attrs
|
384
|
+
assigns(:barcode).should eq(@barcode)
|
385
|
+
response.should be_forbidden
|
386
|
+
end
|
387
|
+
end
|
388
|
+
|
389
|
+
describe "with invalid params" do
|
390
|
+
it "assigns the requested barcode as @barcode" do
|
391
|
+
put :update, :id => @barcode.id, :barcode => @invalid_attrs
|
392
|
+
response.should be_forbidden
|
393
|
+
end
|
394
|
+
end
|
395
|
+
end
|
396
|
+
|
397
|
+
describe "When not logged in" do
|
398
|
+
describe "with valid params" do
|
399
|
+
it "updates the requested barcode" do
|
400
|
+
put :update, :id => @barcode.id, :barcode => @attrs
|
401
|
+
end
|
402
|
+
|
403
|
+
it "should be forbidden" do
|
404
|
+
put :update, :id => @barcode.id, :barcode => @attrs
|
405
|
+
response.should redirect_to(new_user_session_url)
|
406
|
+
end
|
407
|
+
end
|
408
|
+
|
409
|
+
describe "with invalid params" do
|
410
|
+
it "assigns the requested barcode as @barcode" do
|
411
|
+
put :update, :id => @barcode.id, :barcode => @invalid_attrs
|
412
|
+
response.should redirect_to(new_user_session_url)
|
413
|
+
end
|
414
|
+
end
|
415
|
+
end
|
416
|
+
end
|
417
|
+
|
418
|
+
describe "DELETE destroy" do
|
419
|
+
before(:each) do
|
420
|
+
@barcode = FactoryGirl.create(:barcode)
|
421
|
+
end
|
422
|
+
|
423
|
+
describe "When logged in as Administrator" do
|
424
|
+
before(:each) do
|
425
|
+
sign_in FactoryGirl.create(:admin)
|
426
|
+
end
|
427
|
+
|
428
|
+
it "destroys the requested barcode" do
|
429
|
+
delete :destroy, :id => @barcode.id
|
430
|
+
end
|
431
|
+
|
432
|
+
it "redirects to the barcodes list" do
|
433
|
+
delete :destroy, :id => @barcode.id
|
434
|
+
response.should redirect_to(barcodes_url)
|
435
|
+
end
|
436
|
+
end
|
437
|
+
|
438
|
+
describe "When logged in as Librarian" do
|
439
|
+
before(:each) do
|
440
|
+
sign_in FactoryGirl.create(:librarian)
|
441
|
+
end
|
442
|
+
|
443
|
+
it "destroys the requested barcode" do
|
444
|
+
delete :destroy, :id => @barcode.id
|
445
|
+
end
|
446
|
+
|
447
|
+
it "redirects to the barcodes list" do
|
448
|
+
delete :destroy, :id => @barcode.id
|
449
|
+
response.should redirect_to(barcodes_url)
|
450
|
+
end
|
451
|
+
end
|
452
|
+
|
453
|
+
describe "When logged in as User" do
|
454
|
+
before(:each) do
|
455
|
+
sign_in FactoryGirl.create(:user)
|
456
|
+
end
|
457
|
+
|
458
|
+
it "destroys the requested barcode" do
|
459
|
+
delete :destroy, :id => @barcode.id
|
460
|
+
end
|
461
|
+
|
462
|
+
it "should be forbidden" do
|
463
|
+
delete :destroy, :id => @barcode.id
|
464
|
+
response.should be_forbidden
|
465
|
+
end
|
466
|
+
end
|
467
|
+
|
468
|
+
describe "When not logged in" do
|
469
|
+
it "destroys the requested barcode" do
|
470
|
+
delete :destroy, :id => @barcode.id
|
471
|
+
end
|
472
|
+
|
473
|
+
it "should be forbidden" do
|
474
|
+
delete :destroy, :id => @barcode.id
|
475
|
+
response.should redirect_to(new_user_session_url)
|
476
|
+
end
|
477
|
+
end
|
478
|
+
end
|
479
|
+
end
|