enju_circulation 0.0.34 → 0.0.35
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/app/controllers/checked_items_controller.rb +1 -1
- data/app/controllers/checkins_controller.rb +1 -0
- data/app/controllers/checkouts_controller.rb +19 -3
- data/app/models/checkout.rb +6 -2
- data/app/views/checked_items/_list.html.erb +1 -1
- data/app/views/checkouts/_index_user.html.erb +4 -2
- data/app/views/reserves/index.html.erb +1 -1
- data/config/locales/translation_en.yml +1 -0
- data/config/locales/translation_ja.yml +1 -0
- data/config/routes.rb +3 -1
- data/lib/enju_circulation/version.rb +1 -1
- data/spec/controllers/checkouts_controller_spec.rb +36 -0
- data/spec/dummy/app/controllers/baskets_controller.rb +1 -1
- data/spec/dummy/app/models/ability.rb +1 -1
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/models/checkout_spec.rb +8 -0
- metadata +2 -6
- data/spec/controllers/baskets_controller_spec.rb +0 -379
- data/spec/models/basket_spec.rb +0 -25
@@ -56,7 +56,7 @@ class CheckedItemsController < ApplicationController
|
|
56
56
|
@checked_item.basket = @basket
|
57
57
|
@checked_item.librarian = current_user
|
58
58
|
|
59
|
-
flash[:message] =
|
59
|
+
flash[:message] = ''
|
60
60
|
item_identifier = @checked_item.item_identifier.to_s.strip
|
61
61
|
unless item_identifier.blank?
|
62
62
|
item = Item.where(:item_identifier => item_identifier).first
|
@@ -1,8 +1,8 @@
|
|
1
1
|
class CheckoutsController < ApplicationController
|
2
2
|
before_filter :store_location, :only => :index
|
3
|
-
load_and_authorize_resource :except => :index
|
4
|
-
authorize_resource :only => :index
|
5
|
-
before_filter :get_user, :only => :index
|
3
|
+
load_and_authorize_resource :except => [:index, :remove_all]
|
4
|
+
authorize_resource :only => [:index, :remove_all]
|
5
|
+
before_filter :get_user, :only => [:index, :remove_all]
|
6
6
|
helper_method :get_item
|
7
7
|
after_filter :convert_charset, :only => :index
|
8
8
|
cache_sweeper :circulation_sweeper, :only => [:create, :update, :destroy]
|
@@ -133,4 +133,20 @@ class CheckoutsController < ApplicationController
|
|
133
133
|
format.json { head :no_content }
|
134
134
|
end
|
135
135
|
end
|
136
|
+
|
137
|
+
def remove_all
|
138
|
+
if @user
|
139
|
+
unless current_user.has_role?('Librarian')
|
140
|
+
if @user != current_user
|
141
|
+
access_denied; return
|
142
|
+
end
|
143
|
+
end
|
144
|
+
Checkout.remove_all_history(@user)
|
145
|
+
end
|
146
|
+
|
147
|
+
respond_to do |format|
|
148
|
+
format.html { redirect_to checkouts_url, :notice => t('controller.successfully_deleted', :model => t('activerecord.models.checkout')) }
|
149
|
+
format.json { head :no_content }
|
150
|
+
end
|
151
|
+
end
|
136
152
|
end
|
data/app/models/checkout.rb
CHANGED
@@ -28,8 +28,8 @@ class Checkout < ActiveRecord::Base
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def is_not_checked?
|
31
|
-
checkout = Checkout.not_returned.
|
32
|
-
unless checkout.
|
31
|
+
checkout = Checkout.not_returned.where(:item_id => item_id)
|
32
|
+
unless checkout.empty?
|
33
33
|
errors[:base] << I18n.t('activerecord.errors.messages.checkin.already_checked_out')
|
34
34
|
end
|
35
35
|
end
|
@@ -107,6 +107,10 @@ class Checkout < ActiveRecord::Base
|
|
107
107
|
end
|
108
108
|
queues.size
|
109
109
|
end
|
110
|
+
|
111
|
+
def self.remove_all_history(user)
|
112
|
+
user.checkouts.update_all(:user_id => nil)
|
113
|
+
end
|
110
114
|
end
|
111
115
|
|
112
116
|
# == Schema Information
|
@@ -1,4 +1,4 @@
|
|
1
|
-
<div style="color: red"><%= flash[:message]
|
1
|
+
<div style="color: red"><%= flash[:message] -%></div>
|
2
2
|
|
3
3
|
<div class="search_form">
|
4
4
|
<%= form_for :checked_item, :html => {:method => :post}, :url => basket_checked_items_path(@basket), :remote => true do |f| -%>
|
@@ -50,6 +50,8 @@
|
|
50
50
|
<%= link_to (image_tag 'icons/page_white_excel.png', :size => '16x16', :alt => 'CSV', :class => 'icon'), user_checkouts_path(user, :format => :csv, :locale => @locale.to_s) -%>
|
51
51
|
</li>
|
52
52
|
<%- end -%>
|
53
|
-
</
|
54
|
-
|
53
|
+
</ul>
|
54
|
+
<ul>
|
55
|
+
<li><%= link_to t('checkout.remove_all_history'), checkouts_path, :method => :delete %></li>
|
56
|
+
</ul>
|
55
57
|
</div>
|
@@ -1,4 +1,4 @@
|
|
1
|
-
<div style="color: red"><%= flash[:message]
|
1
|
+
<div style="color: red"><%= flash[:message] -%></div>
|
2
2
|
<div id="content_detail" class="ui-corner-all">
|
3
3
|
<h1 class="title"><%= t('page.listing', :model => t('activerecord.models.reserve')) -%></h1>
|
4
4
|
<div id="content_list">
|
@@ -122,6 +122,7 @@ en:
|
|
122
122
|
checkout: "Checkout!"
|
123
123
|
ignore_restriction: "Ignore restriction"
|
124
124
|
already_checked_out: "This item is already checked out."
|
125
|
+
already_checked_out_try_again: "Item already checked out. Try again."
|
125
126
|
checkout:
|
126
127
|
user_checkout: "%{login_name}'s checkouts"
|
127
128
|
library_group_checkout: "Checkouts in %{library_group_name}"
|
@@ -120,6 +120,7 @@ ja:
|
|
120
120
|
checkout: "上記の資料を貸し出す"
|
121
121
|
ignore_restriction: "制限を無視する"
|
122
122
|
already_checked_out: "この資料はすでに貸し出されています。"
|
123
|
+
already_checked_out_try_again: "資料はすでに貸し出されています。もう一度やり直してください。"
|
123
124
|
checkout:
|
124
125
|
user_checkout: "%{login_name} さんの貸出資料"
|
125
126
|
library_group_checkout: "%{library_group_name} での貸出"
|
data/config/routes.rb
CHANGED
@@ -8,7 +8,9 @@ Rails.application.routes.draw do
|
|
8
8
|
resources :checkins
|
9
9
|
end
|
10
10
|
resources :users do
|
11
|
-
resources :checkouts, :only => :index
|
11
|
+
resources :checkouts, :only => :index do
|
12
|
+
put :remove_all, :on => :collection
|
13
|
+
end
|
12
14
|
resources :reserves, :only => :index
|
13
15
|
resources :baskets, :only => :index
|
14
16
|
end
|
@@ -264,6 +264,18 @@ describe CheckoutsController do
|
|
264
264
|
put :update, :id => 'missing', :checkout => { }
|
265
265
|
response.should be_missing
|
266
266
|
end
|
267
|
+
|
268
|
+
it "should remove its own checkout history" do
|
269
|
+
put :remove_all, :user_id => users(:user1).username
|
270
|
+
users(:user1).checkouts.count.should eq 0
|
271
|
+
response.should redirect_to checkouts_url
|
272
|
+
end
|
273
|
+
|
274
|
+
it "should not remove other checkout history" do
|
275
|
+
put :remove_all, :user_id => users(:user2).username
|
276
|
+
users(:user1).checkouts.count.should_not eq 0
|
277
|
+
response.should redirect_to checkouts_url
|
278
|
+
end
|
267
279
|
end
|
268
280
|
|
269
281
|
describe "When logged in as Librarian" do
|
@@ -303,6 +315,18 @@ describe CheckoutsController do
|
|
303
315
|
put :update, :id => 1, :checkout => { }
|
304
316
|
response.should redirect_to checkout_url(assigns(:checkout))
|
305
317
|
end
|
318
|
+
|
319
|
+
it "should remove its own checkout history" do
|
320
|
+
put :remove_all, :user_id => users(:user1).username
|
321
|
+
users(:user1).checkouts.count.should eq 0
|
322
|
+
response.should redirect_to checkouts_url
|
323
|
+
end
|
324
|
+
|
325
|
+
it "should not remove other checkout history" do
|
326
|
+
put :remove_all, :user_id => users(:user2).username
|
327
|
+
users(:user1).checkouts.count.should_not eq 0
|
328
|
+
response.should redirect_to checkouts_url
|
329
|
+
end
|
306
330
|
end
|
307
331
|
|
308
332
|
describe "When logged in as User" do
|
@@ -349,6 +373,18 @@ describe CheckoutsController do
|
|
349
373
|
assigns(:checkout).should_not be_valid
|
350
374
|
response.should be_success
|
351
375
|
end
|
376
|
+
|
377
|
+
it "should remove its own checkout history" do
|
378
|
+
put :remove_all, :user_id => users(:user1).username
|
379
|
+
assigns(:user).checkouts.count.should eq 0
|
380
|
+
response.should redirect_to checkouts_url
|
381
|
+
end
|
382
|
+
|
383
|
+
it "should not remove other checkout history" do
|
384
|
+
put :remove_all, :user_id => users(:admin).username
|
385
|
+
assigns(:user).checkouts.count.should_not eq 0
|
386
|
+
response.should be_forbidden
|
387
|
+
end
|
352
388
|
end
|
353
389
|
|
354
390
|
describe "When not logged in" do
|
@@ -56,7 +56,7 @@ class BasketsController < ApplicationController
|
|
56
56
|
|
57
57
|
respond_to do |format|
|
58
58
|
if @basket.save
|
59
|
-
format.html { redirect_to
|
59
|
+
format.html { redirect_to new_basket_checked_item_url(@basket), :notice => t('controller.successfully_created', :model => t('activerecord.models.basket')) }
|
60
60
|
format.json { render :json => @basket, :status => :created, :location => @basket }
|
61
61
|
else
|
62
62
|
format.html { render :action => "new" }
|
@@ -71,7 +71,7 @@ class Ability
|
|
71
71
|
manifestation.items.empty? and !manifestation.periodical_master? and !manifestation.is_reserved?
|
72
72
|
end
|
73
73
|
when 'User'
|
74
|
-
can [:index, :create], Checkout
|
74
|
+
can [:index, :create, :remove_all], Checkout
|
75
75
|
can [:show, :update, :destroy], Checkout do |checkout|
|
76
76
|
checkout.user == user
|
77
77
|
end
|
Binary file
|
data/spec/dummy/db/test.sqlite3
CHANGED
Binary file
|
@@ -46,6 +46,14 @@ describe Checkout do
|
|
46
46
|
it "should respond to send_overdue_notification" do
|
47
47
|
Checkout.send_overdue_notification.should eq 1
|
48
48
|
end
|
49
|
+
|
50
|
+
it "should destroy all history" do
|
51
|
+
user = users(:user1)
|
52
|
+
old_count = Checkout.count
|
53
|
+
Checkout.remove_all_history(user)
|
54
|
+
user.checkouts.count.should eq 0
|
55
|
+
Checkout.count.should eq old_count
|
56
|
+
end
|
49
57
|
end
|
50
58
|
|
51
59
|
# == Schema Information
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: enju_circulation
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.35
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-05-
|
12
|
+
date: 2012-05-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -529,7 +529,6 @@ files:
|
|
529
529
|
- MIT-LICENSE
|
530
530
|
- Rakefile
|
531
531
|
- README.rdoc
|
532
|
-
- spec/controllers/baskets_controller_spec.rb
|
533
532
|
- spec/controllers/carrier_type_has_checkout_types_controller_spec.rb
|
534
533
|
- spec/controllers/checked_items_controller_spec.rb
|
535
534
|
- spec/controllers/checkins_controller_spec.rb
|
@@ -714,7 +713,6 @@ files:
|
|
714
713
|
- spec/fixtures/user_has_roles.yml
|
715
714
|
- spec/fixtures/user_reserve_stats.yml
|
716
715
|
- spec/fixtures/users.yml
|
717
|
-
- spec/models/basket_spec.rb
|
718
716
|
- spec/models/carrier_type_has_checkout_type_spec.rb
|
719
717
|
- spec/models/checked_item_spec.rb
|
720
718
|
- spec/models/checkin_spec.rb
|
@@ -761,7 +759,6 @@ signing_key:
|
|
761
759
|
specification_version: 3
|
762
760
|
summary: enju_circulation plugin
|
763
761
|
test_files:
|
764
|
-
- spec/controllers/baskets_controller_spec.rb
|
765
762
|
- spec/controllers/carrier_type_has_checkout_types_controller_spec.rb
|
766
763
|
- spec/controllers/checked_items_controller_spec.rb
|
767
764
|
- spec/controllers/checkins_controller_spec.rb
|
@@ -946,7 +943,6 @@ test_files:
|
|
946
943
|
- spec/fixtures/user_has_roles.yml
|
947
944
|
- spec/fixtures/user_reserve_stats.yml
|
948
945
|
- spec/fixtures/users.yml
|
949
|
-
- spec/models/basket_spec.rb
|
950
946
|
- spec/models/carrier_type_has_checkout_type_spec.rb
|
951
947
|
- spec/models/checked_item_spec.rb
|
952
948
|
- spec/models/checkin_spec.rb
|
@@ -1,379 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe BasketsController do
|
4
|
-
fixtures :all
|
5
|
-
|
6
|
-
describe "GET index" do
|
7
|
-
describe "When logged in as Administrator" do
|
8
|
-
login_admin
|
9
|
-
|
10
|
-
it "assigns all baskets as @baskets" do
|
11
|
-
get :index, :user_id => users(:user1).username
|
12
|
-
assigns(:baskets).should_not be_empty
|
13
|
-
response.should be_success
|
14
|
-
end
|
15
|
-
|
16
|
-
it "should get index without user_id" do
|
17
|
-
get :index
|
18
|
-
response.should be_success
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
describe "When logged in as Librarian" do
|
23
|
-
login_librarian
|
24
|
-
|
25
|
-
it "assigns all baskets as @baskets" do
|
26
|
-
get :index, :user_id => users(:user1).username
|
27
|
-
assigns(:baskets).should_not be_empty
|
28
|
-
response.should be_success
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
describe "When logged in as User" do
|
33
|
-
login_user
|
34
|
-
|
35
|
-
it "assigns all baskets as @baskets" do
|
36
|
-
get :index, :user_id => users(:user1).username
|
37
|
-
assigns(:baskets).should be_empty
|
38
|
-
response.should be_forbidden
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
describe "When not logged in" do
|
43
|
-
it "assigns all baskets as @baskets" do
|
44
|
-
get :index, :user_id => users(:user1).username
|
45
|
-
assigns(:baskets).should be_empty
|
46
|
-
response.should redirect_to(new_user_session_url)
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
describe "GET show" do
|
52
|
-
describe "When logged in as Administrator" do
|
53
|
-
login_admin
|
54
|
-
|
55
|
-
it "assigns the requested basket as @basket" do
|
56
|
-
get :show, :id => 1, :user_id => users(:admin).username
|
57
|
-
assigns(:basket).should eq(Basket.find(1))
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
describe "When logged in as Librarian" do
|
62
|
-
login_librarian
|
63
|
-
|
64
|
-
it "assigns the requested basket as @basket" do
|
65
|
-
get :show, :id => 1, :user_id => users(:admin).username
|
66
|
-
assigns(:basket).should eq(Basket.find(1))
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
describe "When logged in as User" do
|
71
|
-
login_user
|
72
|
-
|
73
|
-
it "assigns the requested basket as @basket" do
|
74
|
-
get :show, :id => 1, :user_id => users(:admin).username
|
75
|
-
assigns(:basket).should eq(Basket.find(1))
|
76
|
-
response.should be_forbidden
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
describe "When not logged in" do
|
81
|
-
it "assigns the requested basket as @basket" do
|
82
|
-
get :show, :id => 1, :user_id => users(:admin).username
|
83
|
-
assigns(:basket).should eq(Basket.find(1))
|
84
|
-
response.should redirect_to(new_user_session_url)
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
describe "GET new" do
|
90
|
-
describe "When logged in as Administrator" do
|
91
|
-
login_admin
|
92
|
-
|
93
|
-
it "assigns the requested basket as @basket" do
|
94
|
-
get :new
|
95
|
-
assigns(:basket).should_not be_valid
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
describe "When logged in as Librarian" do
|
100
|
-
login_librarian
|
101
|
-
|
102
|
-
it "assigns the requested basket as @basket" do
|
103
|
-
get :new
|
104
|
-
assigns(:basket).should_not be_valid
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
describe "When logged in as User" do
|
109
|
-
login_user
|
110
|
-
|
111
|
-
it "should not assign the requested basket as @basket" do
|
112
|
-
get :new
|
113
|
-
assigns(:basket).should_not be_valid
|
114
|
-
response.should be_forbidden
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
|
-
describe "When not logged in" do
|
119
|
-
it "should not assign the requested basket as @basket" do
|
120
|
-
get :new
|
121
|
-
assigns(:basket).should_not be_valid
|
122
|
-
response.should redirect_to(new_user_session_url)
|
123
|
-
end
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
|
-
describe "GET edit" do
|
128
|
-
describe "When logged in as Administrator" do
|
129
|
-
login_admin
|
130
|
-
before(:each) do
|
131
|
-
@basket = baskets(:basket_00001)
|
132
|
-
end
|
133
|
-
|
134
|
-
it "assigns the requested basket as @basket" do
|
135
|
-
get :edit, :id => @basket.id
|
136
|
-
assigns(:basket).should eq(@basket)
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
describe "When logged in as Librarian" do
|
141
|
-
login_librarian
|
142
|
-
before(:each) do
|
143
|
-
@basket = baskets(:basket_00001)
|
144
|
-
end
|
145
|
-
|
146
|
-
it "assigns the requested basket as @basket" do
|
147
|
-
get :edit, :id => @basket.id
|
148
|
-
assigns(:basket).should eq(@basket)
|
149
|
-
end
|
150
|
-
end
|
151
|
-
|
152
|
-
describe "When logged in as User" do
|
153
|
-
login_user
|
154
|
-
before(:each) do
|
155
|
-
@basket = baskets(:basket_00001)
|
156
|
-
end
|
157
|
-
|
158
|
-
it "should not assign the requested basket as @basket" do
|
159
|
-
get :edit, :id => @basket.id
|
160
|
-
assigns(:basket).should eq(@basket)
|
161
|
-
response.should be_forbidden
|
162
|
-
end
|
163
|
-
end
|
164
|
-
|
165
|
-
describe "When not logged in" do
|
166
|
-
before(:each) do
|
167
|
-
@basket = baskets(:basket_00001)
|
168
|
-
end
|
169
|
-
|
170
|
-
it "should not assign the requested basket as @basket" do
|
171
|
-
get :edit, :id => @basket.id
|
172
|
-
assigns(:basket).should eq(@basket)
|
173
|
-
response.should redirect_to new_user_session_url
|
174
|
-
end
|
175
|
-
end
|
176
|
-
end
|
177
|
-
|
178
|
-
describe "POST create" do
|
179
|
-
before(:each) do
|
180
|
-
@attrs = {:user_number => users(:user1).user_number }
|
181
|
-
@invalid_attrs = {:user_number => 'invalid'}
|
182
|
-
end
|
183
|
-
|
184
|
-
describe "When logged in as Administrator" do
|
185
|
-
login_admin
|
186
|
-
|
187
|
-
describe "with valid params" do
|
188
|
-
it "assigns a newly created basket as @basket" do
|
189
|
-
post :create, :basket => {:user_number => users(:user1).user_number }
|
190
|
-
assigns(:basket).should be_valid
|
191
|
-
end
|
192
|
-
end
|
193
|
-
|
194
|
-
describe "with blank params" do
|
195
|
-
it "assigns a newly created basket as @basket" do
|
196
|
-
post :create, :basket => { }
|
197
|
-
assigns(:basket).should_not be_valid
|
198
|
-
end
|
199
|
-
end
|
200
|
-
|
201
|
-
describe "with invalid params" do
|
202
|
-
it "assigns a newly created basket as @basket" do
|
203
|
-
post :create, :basket => @invalid_attrs
|
204
|
-
assigns(:basket).should_not be_valid
|
205
|
-
end
|
206
|
-
end
|
207
|
-
end
|
208
|
-
|
209
|
-
describe "When logged in as Librarian" do
|
210
|
-
login_librarian
|
211
|
-
|
212
|
-
describe "with valid params" do
|
213
|
-
it "assigns a newly created basket as @basket" do
|
214
|
-
post :create, :basket => {:user_number => users(:user1).user_number }
|
215
|
-
assigns(:basket).should be_valid
|
216
|
-
end
|
217
|
-
end
|
218
|
-
|
219
|
-
describe "with blank params" do
|
220
|
-
it "assigns a newly created basket as @basket" do
|
221
|
-
post :create, :basket => { }
|
222
|
-
assigns(:basket).should_not be_valid
|
223
|
-
end
|
224
|
-
end
|
225
|
-
|
226
|
-
describe "with invalid params" do
|
227
|
-
it "assigns a newly created basket as @basket" do
|
228
|
-
post :create, :basket => @invalid_attrs
|
229
|
-
assigns(:basket).should_not be_valid
|
230
|
-
end
|
231
|
-
end
|
232
|
-
|
233
|
-
it "should not create basket when user is suspended" do
|
234
|
-
post :create, :basket => {:user_number => users(:user4).user_number }
|
235
|
-
assigns(:basket).should_not be_valid
|
236
|
-
assigns(:basket).errors["base"].include?(I18n.t('basket.this_account_is_suspended')).should be_true
|
237
|
-
response.should be_success
|
238
|
-
end
|
239
|
-
|
240
|
-
it "should not create basket when user is not found" do
|
241
|
-
post :create, :basket => {:user_number => 'not found' }
|
242
|
-
assigns(:basket).should_not be_valid
|
243
|
-
assigns(:basket).errors["base"].include?(I18n.t('user.not_found')).should be_true
|
244
|
-
response.should be_success
|
245
|
-
end
|
246
|
-
|
247
|
-
it "should not create basket without user_number" do
|
248
|
-
post :create, :basket => { }
|
249
|
-
assigns(:basket).should_not be_valid
|
250
|
-
response.should be_success
|
251
|
-
end
|
252
|
-
|
253
|
-
it "should create basket" do
|
254
|
-
post :create, :basket => {:user_number => users(:user1).user_number }
|
255
|
-
assigns(:basket).should be_valid
|
256
|
-
response.should redirect_to basket_checked_items_url(assigns(:basket))
|
257
|
-
end
|
258
|
-
|
259
|
-
it "should not create basket without user_number" do
|
260
|
-
post :create, :basket => { }
|
261
|
-
assigns(:basket).should_not be_valid
|
262
|
-
response.should be_success
|
263
|
-
end
|
264
|
-
end
|
265
|
-
|
266
|
-
describe "When logged in as User" do
|
267
|
-
login_user
|
268
|
-
|
269
|
-
describe "with valid params" do
|
270
|
-
it "assigns a newly created basket as @basket" do
|
271
|
-
post :create, :basket => {:user_number => users(:user1).user_number }
|
272
|
-
assigns(:basket).should_not be_valid
|
273
|
-
end
|
274
|
-
|
275
|
-
it "should be forbidden" do
|
276
|
-
post :create, :basket => {:user_number => users(:user1).user_number }
|
277
|
-
response.should be_forbidden
|
278
|
-
end
|
279
|
-
end
|
280
|
-
|
281
|
-
it "should not create basket" do
|
282
|
-
post :create, :basket => {:user_number => users(:user1).user_number }
|
283
|
-
response.should be_forbidden
|
284
|
-
end
|
285
|
-
end
|
286
|
-
|
287
|
-
describe "When not logged in" do
|
288
|
-
describe "with blank params" do
|
289
|
-
it "assigns a newly created basket as @basket" do
|
290
|
-
post :create, :basket => { }
|
291
|
-
assigns(:basket).should_not be_valid
|
292
|
-
end
|
293
|
-
|
294
|
-
it "should be redirected to new_user_session_url" do
|
295
|
-
post :create, :basket => { }
|
296
|
-
assigns(:basket).should_not be_valid
|
297
|
-
assert_response :redirect
|
298
|
-
response.should redirect_to new_user_session_url
|
299
|
-
end
|
300
|
-
end
|
301
|
-
end
|
302
|
-
end
|
303
|
-
|
304
|
-
describe "PUT update" do
|
305
|
-
before(:each) do
|
306
|
-
@attrs = {:user_id => users(:user1).username}
|
307
|
-
end
|
308
|
-
|
309
|
-
describe "When logged in as Librarian" do
|
310
|
-
login_librarian
|
311
|
-
|
312
|
-
describe "with valid params" do
|
313
|
-
it "updates the requested basket" do
|
314
|
-
put :update, :id => 8, :basket => @attrs
|
315
|
-
end
|
316
|
-
|
317
|
-
it "assigns the requested basket as @basket" do
|
318
|
-
put :update, :id => 8, :basket => @attrs
|
319
|
-
assigns(:basket).checkouts.first.item.circulation_status.name.should eq 'On Loan'
|
320
|
-
response.should redirect_to(user_checkouts_url(assigns(:basket).user))
|
321
|
-
end
|
322
|
-
end
|
323
|
-
end
|
324
|
-
end
|
325
|
-
|
326
|
-
describe "DELETE destroy" do
|
327
|
-
before(:each) do
|
328
|
-
@basket = FactoryGirl.create(:basket)
|
329
|
-
end
|
330
|
-
|
331
|
-
describe "When logged in as Administrator" do
|
332
|
-
login_fixture_admin
|
333
|
-
|
334
|
-
it "should destroy basket without user_id" do
|
335
|
-
delete :destroy, :id => 1, :basket => {:user_id => nil}, :user_id => users(:user1).username
|
336
|
-
response.should redirect_to user_checkouts_url(assigns(:basket).user)
|
337
|
-
end
|
338
|
-
|
339
|
-
it "should destroy basket" do
|
340
|
-
delete :destroy, :id => 1, :basket => { }, :user_id => users(:user1).username
|
341
|
-
response.should redirect_to user_checkouts_url(assigns(:basket).user)
|
342
|
-
end
|
343
|
-
end
|
344
|
-
|
345
|
-
describe "When logged in as Librarian" do
|
346
|
-
login_fixture_librarian
|
347
|
-
|
348
|
-
it "should destroy basket without user_id" do
|
349
|
-
delete :destroy, :id => 1, :basket => {:user_id => nil}, :user_id => users(:user1).username
|
350
|
-
response.should redirect_to user_checkouts_url(assigns(:basket).user)
|
351
|
-
end
|
352
|
-
|
353
|
-
it "should destroy basket" do
|
354
|
-
delete :destroy, :id => 1, :basket => { }, :user_id => users(:user1).username
|
355
|
-
response.should redirect_to user_checkouts_url(assigns(:basket).user)
|
356
|
-
end
|
357
|
-
end
|
358
|
-
|
359
|
-
describe "When logged in as User" do
|
360
|
-
login_fixture_user
|
361
|
-
|
362
|
-
it "should not destroy basket" do
|
363
|
-
delete :destroy, :id => 3, :user_id => users(:user1).username
|
364
|
-
response.should be_forbidden
|
365
|
-
end
|
366
|
-
end
|
367
|
-
|
368
|
-
describe "When not logged in" do
|
369
|
-
it "destroys the requested basket" do
|
370
|
-
delete :destroy, :id => @basket.id
|
371
|
-
end
|
372
|
-
|
373
|
-
it "should be forbidden" do
|
374
|
-
delete :destroy, :id => @basket.id
|
375
|
-
response.should redirect_to new_user_session_url
|
376
|
-
end
|
377
|
-
end
|
378
|
-
end
|
379
|
-
end
|
data/spec/models/basket_spec.rb
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
require 'spec_helper'
|
3
|
-
|
4
|
-
describe Basket do
|
5
|
-
#pending "add some examples to (or delete) #{__FILE__}"
|
6
|
-
fixtures :all
|
7
|
-
|
8
|
-
it "should not create basket when user is not active" do
|
9
|
-
Basket.create(:user => users(:user4)).id.should be_nil
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
# == Schema Information
|
14
|
-
#
|
15
|
-
# Table name: baskets
|
16
|
-
#
|
17
|
-
# id :integer not null, primary key
|
18
|
-
# user_id :integer
|
19
|
-
# note :text
|
20
|
-
# type :string(255)
|
21
|
-
# lock_version :integer default(0), not null
|
22
|
-
# created_at :datetime
|
23
|
-
# updated_at :datetime
|
24
|
-
#
|
25
|
-
|