This repository was archived by the owner on Jul 24, 2020. It is now read-only.
File tree 2 files changed +29
-0
lines changed
2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ class ApplicationController < ActionController::Base
18
18
c . before_filter :fix_cart_date
19
19
c . before_filter :set_view_mode
20
20
c . before_filter :check_view_mode
21
+ c . before_filter :make_cart_compatible
21
22
end
22
23
23
24
helper_method :current_user
@@ -114,6 +115,15 @@ def fix_cart_date
114
115
cart . fix_due_date
115
116
end
116
117
118
+ # If user's session has an old Cart object that stores items in Array rather
119
+ # than a Hash (see #587), regenerate the Cart.
120
+ # TODO: Remove in ~2015, when nobody could conceivably run the old app?
121
+ def make_cart_compatible
122
+ unless session [ :cart ] . items . is_a? Hash
123
+ session [ :cart ] = Cart . new
124
+ end
125
+ end
126
+
117
127
#-------- end before_filter methods --------#
118
128
119
129
def update_cart
Original file line number Diff line number Diff line change @@ -48,6 +48,24 @@ def method_requiring_user
48
48
controller . stub ( :fix_cart_date )
49
49
controller . stub ( :set_view_mode )
50
50
controller . stub ( :current_user )
51
+ controller . stub ( :make_cart_compatible )
52
+ end
53
+
54
+ describe 'make_cart_compatible' do
55
+ before ( :each ) do
56
+ controller . unstub ( :make_cart_compatible )
57
+ end
58
+ it 'replaces the cart if items is an Array' do
59
+ session [ :cart ] = FactoryGirl . build ( :cart , items : [ 1 ] )
60
+ get :index
61
+ session [ :cart ] . items . should be_a ( Hash )
62
+ session [ :cart ] . items . should be_empty
63
+ session [ :cart ] . items . should_not be_a ( Array )
64
+ end
65
+ it 'leaves the cart alone if items is a Hash' do
66
+ session [ :cart ] = FactoryGirl . build ( :cart_with_items )
67
+ expect { get :index } . to_not change { session [ :cart ] . items }
68
+ end
51
69
end
52
70
53
71
describe 'app_setup_check' do
@@ -243,6 +261,7 @@ def method_requiring_user
243
261
controller . stub ( :fix_cart_date )
244
262
controller . stub ( :set_view_mode )
245
263
controller . stub ( :current_user )
264
+ controller . stub ( :make_cart_compatible )
246
265
end
247
266
248
267
#TODO - This may involve rewriting the method somewhat
You can’t perform that action at this time.
0 commit comments