radiant-shop-extension 0.9.3 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. data/README.md +9 -3
  2. data/Rakefile +1 -0
  3. data/VERSION +1 -1
  4. data/app/controllers/admin/shop/customers_controller.rb +35 -126
  5. data/app/controllers/shop/categories_controller.rb +1 -5
  6. data/app/controllers/shop/products_controller.rb +1 -1
  7. data/app/models/form_checkout.rb +198 -112
  8. data/app/models/shop_category.rb +3 -3
  9. data/app/models/shop_customer.rb +3 -12
  10. data/app/models/shop_order.rb +5 -3
  11. data/app/models/shop_payment.rb +0 -1
  12. data/app/models/shop_product.rb +3 -3
  13. data/app/views/admin/shop/customers/edit.html.haml +13 -0
  14. data/app/views/admin/shop/customers/edit/_fields.html.haml +33 -0
  15. data/app/views/admin/shop/customers/edit/_head.html.haml +2 -0
  16. data/app/views/admin/shop/customers/edit/_meta.html.haml +7 -0
  17. data/app/views/admin/shop/customers/edit/_parts.html.haml +4 -0
  18. data/app/views/admin/shop/customers/edit/_popups.html.haml +3 -0
  19. data/app/views/admin/shop/customers/edit/meta/_login.html.haml +5 -0
  20. data/app/views/admin/shop/customers/edit/meta/_password.html.haml +5 -0
  21. data/app/views/admin/shop/customers/edit/meta/_password_confirmation.html.haml +5 -0
  22. data/app/views/admin/shop/customers/edit/parts/_address.html.haml +7 -0
  23. data/app/views/admin/shop/customers/edit/parts/_addresses.html.haml +13 -0
  24. data/app/views/admin/shop/customers/edit/parts/_orders.html.haml +29 -0
  25. data/app/views/admin/shop/customers/index.html.haml +9 -35
  26. data/app/views/admin/shop/customers/index/_bottom.html.haml +4 -0
  27. data/app/views/admin/shop/customers/index/_customer.html.haml +9 -0
  28. data/app/views/admin/shop/customers/new.html.haml +11 -0
  29. data/app/views/admin/shop/customers/remove.html.haml +12 -0
  30. data/app/views/admin/shop/products/new.html.haml +1 -1
  31. data/config/locales/en.yml +37 -29
  32. data/config/routes.rb +2 -0
  33. data/db/migrate/20100927041219_remove_payment_methods.rb +16 -0
  34. data/db/migrate/20100927041624_change_payments_add_gateway.rb +11 -0
  35. data/db/migrate/20100927140446_change_payment_add_card_type_card_number.rb +11 -0
  36. data/db/seed.rb +1 -0
  37. data/db/seeds/forms.rb +179 -0
  38. data/db/{migrate/20100520033059_create_layouts.rb → seeds/layouts.rb} +19 -27
  39. data/db/seeds/snippets.rb +23 -0
  40. data/lib/shop/interface/customers.rb +34 -0
  41. data/lib/shop/tags/address.rb +1 -0
  42. data/lib/shop/tags/card.rb +51 -0
  43. data/lib/shop/tags/helpers.rb +53 -38
  44. data/lib/shop/tags/item.rb +1 -1
  45. data/lib/shop/tags/product.rb +23 -22
  46. data/lib/shop/tags/responses.rb +3 -3
  47. data/lib/tasks/shop_extension_tasks.rake +6 -0
  48. data/public/stylesheets/sass/admin/extensions/shop/index.sass +64 -0
  49. data/radiant-shop-extension.gemspec +37 -6
  50. data/shop_extension.rb +7 -2
  51. data/spec/datasets/forms.rb +112 -118
  52. data/spec/datasets/shop_customers.rb +30 -0
  53. data/spec/datasets/shop_orders.rb +7 -3
  54. data/spec/datasets/shop_products.rb +1 -0
  55. data/spec/lib/shop/tags/card_spec.rb +71 -0
  56. data/spec/lib/shop/tags/helpers_spec.rb +270 -283
  57. data/spec/lib/shop/tags/item_spec.rb +9 -0
  58. data/spec/lib/shop/tags/product_spec.rb +172 -158
  59. data/spec/lib/shop/tags/responses_spec.rb +129 -0
  60. data/spec/models/form_checkout_spec.rb +228 -294
  61. data/spec/models/shop_category_page_spec.rb +2 -2
  62. data/spec/models/shop_order_spec.rb +27 -20
  63. data/spec/models/shop_product_attachment_spec.rb +1 -0
  64. metadata +61 -17
  65. data/app/models/shop_payment_method.rb +0 -5
  66. data/db/migrate/20100903122123_create_forms.rb +0 -44
  67. data/db/migrate/20100908063639_create_snippets.rb +0 -22
@@ -0,0 +1,30 @@
1
+ class ShopCustomersDataset < Dataset::Base
2
+ def load
3
+ create_model :shop_customer, :customer,
4
+ :name => 'customer',
5
+ :email => 'customer@example.com',
6
+ :login => 'customer',
7
+ :password => 'radiant',
8
+ :password_confirmation => 'radiant'
9
+
10
+ create_model :shop_customer, :bad_customer,
11
+ :name => 'bad customer',
12
+ :email => 'bad_customer@example.com',
13
+ :login => 'bad customer',
14
+ :password => 'radiant',
15
+ :password_confirmation => 'radiant'
16
+ end
17
+
18
+ helpers do
19
+ def login_as(user)
20
+ login_user = user.is_a?(User) ? user : users(user)
21
+ flunk "Can't login as non-existing user #{user.to_s}." unless login_user
22
+ UserActionObserver.current_user = login_user
23
+ login_user
24
+ end
25
+
26
+ def logout
27
+ UserActionObserver.current_user = nil
28
+ end
29
+ end
30
+ end
@@ -1,11 +1,15 @@
1
1
  class ShopOrdersDataset < Dataset::Base
2
2
 
3
- uses :shop_products
3
+ uses :shop_products, :shop_customers, :shop_addresses
4
4
 
5
5
  def load
6
6
  create_record :shop_order, :empty
7
- create_record :shop_order, :one_item
8
- create_record :shop_order, :several_items
7
+ create_record :shop_order, :one_item,
8
+ :customer => shop_customers(:customer)
9
+ create_record :shop_order, :several_items,
10
+ :customer => shop_customers(:customer),
11
+ :billing => shop_addresses(:billing),
12
+ :shipping => shop_addresses(:shipping)
9
13
 
10
14
  create_record :shop_line_item, :crusty_bread, :item_id => shop_products(:crusty_bread).id, :item_type => 'ShopProduct'
11
15
  create_record :shop_line_item, :soft_bread, :item_id => shop_products(:soft_bread).id, :item_type => 'ShopProduct'
@@ -13,6 +13,7 @@ class ShopProductsDataset < Dataset::Base
13
13
  create_record :shop_product, "#{product.to_s}_#{category.to_s}".to_sym,
14
14
  :name => "#{product.to_s} #{category.to_s}",
15
15
  :sku => "#{product.to_s}_#{category.to_s}",
16
+ :description => "*#{product.to_s}*",
16
17
  :price => i + 1 * 10,
17
18
  :position => i + 1,
18
19
  :weight => i + 10 * 3,
@@ -0,0 +1,71 @@
1
+ require 'spec/spec_helper'
2
+ require 'spec/helpers/nested_tag_helper'
3
+
4
+ #
5
+ # Test for Shop Line Item Tags
6
+ #
7
+ describe Shop::Tags::Card do
8
+
9
+ dataset :pages
10
+
11
+ before :all do
12
+ @page = pages(:home)
13
+ end
14
+
15
+ it 'should describe these tags' do
16
+ Shop::Tags::Card.tags.sort.should == [
17
+ 'form:card',
18
+ 'form:card:type',
19
+ 'form:card:month',
20
+ 'form:card:year'].sort
21
+ end
22
+
23
+ describe 'form:card:type' do
24
+ it 'should output the card types' do
25
+ tag = %{<r:form:card:type />}
26
+ exp = %{<select name="card[type]" id="card_type">
27
+ <option value="amex">American Express</option>
28
+ <option value="diners">Diners Club</option>
29
+ <option value="mastercard">Master Card</option>
30
+ <option value="visa">Visa</option>
31
+ </select>}
32
+
33
+ @page.should render(tag).as(exp)
34
+ end
35
+ end
36
+
37
+ describe 'form:card:month' do
38
+ it 'should output the card months' do
39
+ tag = %{<r:form:card:month />}
40
+ exp = %{<select name="card[month]" id="card_month">
41
+ <option value="01">01 - January</option>
42
+ <option value="02">02 - February</option>
43
+ <option value="03">03 - March</option>
44
+ <option value="04">04 - April</option>
45
+ <option value="05">05 - May</option>
46
+ <option value="06">06 - June</option>
47
+ <option value="07">07 - July</option>
48
+ <option value="08">08 - August</option>
49
+ <option value="09">09 - September</option>
50
+ <option value="10">10 - October</option>
51
+ <option value="11">11 - November</option>
52
+ <option value="12">12 - December</option>
53
+ </select>}
54
+
55
+ @page.should render(tag).as(exp)
56
+ end
57
+ end
58
+
59
+ describe 'form:card:year' do
60
+ it 'should output the card years' do
61
+ tag = %{<r:form:card:year />}
62
+ exp = %{<select name="card[year]" id="card_year">\n}
63
+ (Time.new.year ... Time.new.year + 10).each do |year|
64
+ exp << %{<option value="#{year}">#{year}</option>\n}
65
+ end
66
+ exp << %{</select>}
67
+ @page.should render(tag).as(exp)
68
+ end
69
+ end
70
+
71
+ end
@@ -2,378 +2,365 @@ require 'spec/spec_helper'
2
2
 
3
3
  describe Shop::Tags::Helpers do
4
4
 
5
- dataset :pages
5
+ dataset :pages, :shop_products, :shop_orders, :shop_addresses
6
6
 
7
7
  before :all do
8
8
  @page = pages(:home)
9
9
  end
10
10
 
11
11
  before(:each) do
12
- @locals = Object.new
13
- stub(@locals).page { @page }
14
-
15
- @attrs = {}
16
-
17
- @tag = Object.new
18
- stub(@tag).attr { @attrs }
19
- stub(@tag).locals { @locals }
20
-
21
- category = Object.new
22
- @shop_category = category
23
- @shop_categories = [ @shop_category, @shop_category, @shop_category ]
24
-
25
- product = Object.new
26
- @shop_product = product
27
- @shop_products = [ @shop_product, @shop_product, @shop_product ]
28
-
29
- order = Object.new
30
- @shop_order = order
31
-
32
- item = Object.new
33
- @shop_line_item = item
34
- @shop_line_items = [ @shop_line_item, @shop_line_item, @shop_line_item ]
35
-
36
- stub(@shop_product).category { @shop_category }
37
- stub(@shop_category).products { @shop_products }
38
- stub(@shop_line_item).product { @shop_product }
39
- stub(@shop_order).line_items { @shop_line_items }
12
+ @tag = OpenStruct.new({
13
+ :attr => {},
14
+ :locals => OpenStruct.new({
15
+ :page => OpenStruct.new({
16
+ :params => {},
17
+ :request => OpenStruct.new({
18
+ :session => {}
19
+ })
20
+ })
21
+ })
22
+ })
40
23
  end
41
24
 
42
- describe '#current_categories(tag)' do
43
- context 'search query' do
44
- it 'should return matching categories' do
45
- stub(@locals).shop_categories { [] }
46
- stub(@page).params { {'query'=>'term'} }
47
-
48
- mock(ShopCategory).search('term') { @shop_categories }
49
-
25
+ describe '#current_categories' do
26
+ before :each do
27
+ @category = shop_categories(:bread)
28
+ end
29
+
30
+ context 'categories previously set' do
31
+ before :each do
32
+ @tag.locals.shop_categories = [@category]
33
+ end
34
+ it 'should return categories' do
50
35
  result = Shop::Tags::Helpers.current_categories(@tag)
51
- result.should == @shop_categories
36
+ result.should == [@category]
52
37
  end
53
38
  end
54
39
 
55
- context 'key => value' do
40
+ context 'search query sent to page' do
41
+ before :each do
42
+ @tag.locals.page.params = { 'query' => @category.handle }
43
+ end
56
44
  it 'should return matching categories' do
57
- stub(@locals).shop_categories { [] }
58
- stub(@page).params { {} }
59
- @attrs['key'] = 'find'
60
- @attrs['value'] = 'me'
61
-
62
- mock(ShopCategory).all(:conditions => { :find => 'me' }) { @shop_categories }
63
-
64
45
  result = Shop::Tags::Helpers.current_categories(@tag)
65
- result.should == @shop_categories
46
+ result.should == [@category]
47
+ end
48
+ end
49
+
50
+ context 'key and value sent' do
51
+ before :each do
52
+ @tag.attr = { 'key' => 'handle', 'value' => @category.handle }
53
+ end
54
+ it 'should return the matching categories' do
55
+ result = Shop::Tags::Helpers.current_categories(@tag)
56
+ result.should == [@category]
66
57
  end
67
58
  end
68
59
 
69
- context 'all results' do
70
- it 'should return all categories' do
71
- stub(@locals).shop_categories { [] }
72
- stub(@page).params { {} }
73
-
74
- mock(ShopCategory).all { @shop_categories }
75
-
60
+ context 'nothing additional sent' do
61
+ before :each do
62
+ mock(ShopCategory).all { [@category] }
63
+ end
64
+ it 'should return all categories in the database' do
76
65
  result = Shop::Tags::Helpers.current_categories(@tag)
77
- result.should == @shop_categories
66
+ result.should == [@category]
78
67
  end
79
68
  end
80
69
  end
81
70
 
82
- describe '#current_category(tag)' do
83
- context 'parameters' do
84
- it 'should be calling an object with those attributes' do
85
- object = ShopCategory.new
86
- object.attributes.include?('handle').should == true
87
- object.attributes.include?('name').should == true
88
- object.attributes.include?('position').should == true
89
- end
90
- end
91
- context 'key => value' do
92
- it 'should return the matching category' do
93
- stub(@locals).shop_category { nil }
94
- @attrs['key'] = 'find'
95
- @attrs['value'] = 'me'
96
-
97
- mock(ShopCategory).first(:conditions => { :find => 'me' }) { @shop_category }
98
-
71
+ describe '#current_category' do
72
+ before :each do
73
+ @category = shop_categories(:bread)
74
+ @product = shop_categories(:bread).products.first
75
+ end
76
+
77
+ context 'category previously set' do
78
+ before :each do
79
+ @tag.locals.shop_category = @category
80
+ end
81
+ it 'should return the existing category' do
99
82
  result = Shop::Tags::Helpers.current_category(@tag)
100
- result.should == @shop_category
83
+ result.should == @category
101
84
  end
102
85
  end
103
- context 'tag.locals.page.shop_category' do
104
- it 'should return the matching category' do
105
- stub(@locals).shop_category { @shop_category }
106
-
86
+
87
+ context 'product previously set' do
88
+ before :each do
89
+ @tag.locals.shop_product = @product
90
+ end
91
+ it 'should return the category of the product attached to the page' do
92
+ result = Shop::Tags::Helpers.current_category(@tag)
93
+ result.should == @category
94
+ end
95
+ end
96
+
97
+ context 'key and value sent' do
98
+ before :each do
99
+ @tag.attr = { 'key' => 'handle', 'value' => @category.handle }
100
+ end
101
+ it 'should return the matching categories' do
107
102
  result = Shop::Tags::Helpers.current_category(@tag)
108
- result.should == @shop_category
103
+ result.should == @category
109
104
  end
110
105
  end
111
- context 'tag.locals.page.shop_product' do
112
- it 'should return the matching category' do
113
- stub(@locals).shop_category { nil }
114
- stub(@page).shop_product { @shop_product }
115
-
106
+
107
+ context 'the current page has a product attached to it' do
108
+ before :each do
109
+ @tag.locals.page.shop_product = @product
110
+ end
111
+ it 'should return the category of the product attached to the page' do
116
112
  result = Shop::Tags::Helpers.current_category(@tag)
117
- result.should == @shop_category
113
+ result.should == @category
118
114
  end
119
115
  end
120
- context 'tag.locals.shop_category' do
121
- it 'should return the matching category' do
122
- stub(@locals).shop_category { @shop_category }
123
-
116
+
117
+ context 'the current page slug matches the category handle' do
118
+ before :each do
119
+ @tag.locals.page.slug = @category.handle
120
+ end
121
+ it 'should return the category with that handle' do
124
122
  result = Shop::Tags::Helpers.current_category(@tag)
125
- result.should == @shop_category
123
+ result.should == @category
126
124
  end
127
125
  end
128
- context 'tag.locals.shop_product' do
129
- it 'should return the matching category' do
130
- stub(@page).shop_category { nil }
131
- stub(@page).shop_product { nil }
132
- stub(@locals).shop_category { nil }
133
- stub(@locals).shop_product { @shop_product }
134
-
126
+
127
+ context 'the current page has a category attached to it' do
128
+ before :each do
129
+ @tag.locals.page.shop_category = @category
130
+ end
131
+ it 'should return the category attached to the page' do
135
132
  result = Shop::Tags::Helpers.current_category(@tag)
136
- result.should == @shop_category
137
- end
138
- end
139
- context 'Using page slug' do
140
- it 'should return the matching category' do
141
- stub(@shop_category).handle { 'bob' }
142
- stub(@page).shop_category { nil }
143
- stub(@page).shop_product { nil }
144
- stub(@locals).shop_category { nil }
145
- stub(@locals).shop_product { nil }
146
- stub(@page).slug { @shop_category.handle }
147
-
148
- mock(ShopCategory).find(:first, {:conditions=>{:handle=>@shop_category.handle}}) { @shop_category }
149
-
133
+ result.should == @category
134
+ end
135
+ end
136
+
137
+ context 'nothing available to find the category' do
138
+ it 'should return nil' do
150
139
  result = Shop::Tags::Helpers.current_category(@tag)
151
- result.should == @shop_category
140
+ result.should be_nil
152
141
  end
153
142
  end
143
+
154
144
  end
155
-
156
- describe '#current_products(tag)' do
157
- context 'tag.locals.shop_products' do
158
- it 'should return matching products' do
159
- stub(@locals).shop_products { @shop_products }
160
-
145
+
146
+ describe '#current_products' do
147
+ before :each do
148
+ @product = shop_products(:soft_bread)
149
+ @category = shop_categories(:bread)
150
+ end
151
+
152
+ context 'products previously set' do
153
+ before :each do
154
+ @tag.locals.shop_products = [ @product ]
155
+ end
156
+ it 'should return the existing categories' do
157
+ result = Shop::Tags::Helpers.current_products(@tag)
158
+ result.should == [@product]
159
+ end
160
+ end
161
+
162
+ context 'category previously set' do
163
+ before :each do
164
+ @tag.locals.shop_category = @category
165
+ end
166
+ it 'should return the categorys products' do
161
167
  result = Shop::Tags::Helpers.current_products(@tag)
162
- result.should == @shop_products
168
+ result.should == @category.products
163
169
  end
164
170
  end
165
- context 'search query' do
171
+
172
+ context 'the current page has a category attached to it' do
173
+ before :each do
174
+ @tag.locals.page.shop_category = @category
175
+ end
176
+ it 'should return the products of the category attached to the page' do
177
+ result = Shop::Tags::Helpers.current_products(@tag)
178
+ result.should == @category.products
179
+ end
180
+ end
181
+
182
+ context 'search query sent to page' do
183
+ before :each do
184
+ @tag.locals.page.params = { 'query' => @product.sku }
185
+ end
166
186
  it 'should return matching products' do
167
- stub(@locals).shop_products { [] }
168
- stub(@page).params { {'query'=>'term'} }
169
-
170
- mock(ShopProduct).search('term') { @shop_products }
171
-
172
187
  result = Shop::Tags::Helpers.current_products(@tag)
173
- result.should == @shop_products
188
+ result.should == [@product]
174
189
  end
175
190
  end
176
- context 'key => value' do
191
+
192
+ context 'key and value sent' do
193
+ before :each do
194
+ @tag.attr = { 'key' => 'sku', 'value' => @product.sku }
195
+ end
177
196
  it 'should return the matching products' do
178
- stub(@locals).shop_products { [] }
179
- stub(@page).params { {} }
180
- @attrs['key'] = 'find'
181
- @attrs['value'] = 'me'
182
-
183
- mock(ShopProduct).all(:conditions => { :find => 'me' }) { @shop_products }
184
-
185
197
  result = Shop::Tags::Helpers.current_products(@tag)
186
- result.should == @shop_products
187
- end
188
- end
189
- context 'no query' do
190
- context 'tag.locals.page.shop_category' do
191
- it 'should return all products in that category' do
192
- stub(@page).params { { } }
193
- stub(@locals).shop_products { [] }
194
- stub(@page).shop_category { @shop_category }
195
-
196
- result = Shop::Tags::Helpers.current_products(@tag)
197
- result.should == @shop_category.products
198
- end
199
- end
200
-
201
- context 'tag.locals.shop_category' do
202
- it 'should return all products in that category' do
203
- stub(@locals).shop_products { [] }
204
- stub(@page).params { { } }
205
- stub(@page).shop_category { nil }
206
- stub(@locals).shop_category { @shop_category }
207
-
208
- result = Shop::Tags::Helpers.current_products(@tag)
209
- result.should == @shop_category.products
210
- end
211
- end
212
-
213
- context 'all results' do
214
- it 'should return all products' do
215
- stub(@page).params { {} }
216
- stub(@locals).shop_products { {} }
217
- stub(@page).shop_category { nil }
218
- stub(@locals).shop_category { nil }
219
- mock(ShopProduct).all { @shop_products }
220
-
221
- result = Shop::Tags::Helpers.current_products(@tag)
222
- result.should == @shop_products
223
- end
198
+ result.should == [@product]
199
+ end
200
+ end
201
+
202
+ context 'nothing additional sent' do
203
+ before :each do
204
+ mock(ShopProduct).all { [@product] }
205
+ end
206
+ it 'should return all products in the database' do
207
+ result = Shop::Tags::Helpers.current_products(@tag)
208
+ result.should == [@product]
224
209
  end
225
210
  end
226
211
  end
227
212
 
228
- describe '#current_product(tag)' do
229
- context 'parameters' do
230
- it 'should be calling an object with those attributes' do
231
- object = ShopProduct.new
232
- object.attributes.include?('sku').should == true
233
- object.attributes.include?('name').should == true
234
- object.attributes.include?('position').should == true
235
- end
236
- end
237
- context 'key => value' do
238
- it 'should return the matching product' do
239
- stub(@locals).shop_product { nil }
240
- @attrs['key'] = 'find'
241
- @attrs['value'] = 'me'
242
-
243
- mock(ShopProduct).first(:conditions => { :find => 'me' }) { @shop_product }
244
-
213
+ describe '#current_product' do
214
+ before :each do
215
+ @product = shop_products(:soft_bread)
216
+ end
217
+
218
+ context 'product previously set' do
219
+ before :each do
220
+ @tag.locals.shop_product = @product
221
+ end
222
+ it 'should return the product attached to the page' do
245
223
  result = Shop::Tags::Helpers.current_product(@tag)
246
- result.should == @shop_product
224
+ result.should == @product
247
225
  end
248
226
  end
249
- context 'tag.locals.page.shop_product' do
250
- it 'should return the matching product' do
251
- stub(@locals).shop_product { nil }
252
- stub(@page).shop_product { @shop_product }
253
-
227
+
228
+ context 'key and value sent' do
229
+ before :each do
230
+ @tag.attr = { 'key' => 'sku', 'value' => @product.sku }
231
+ end
232
+ it 'should return the matching categories' do
254
233
  result = Shop::Tags::Helpers.current_product(@tag)
255
- result.should == @shop_product
234
+ result.should == @product
256
235
  end
257
236
  end
258
- context 'tag.locals.shop_product' do
259
- it 'should return the matching product' do
260
- stub(@locals).shop_product { @shop_product }
261
-
262
- result = Shop::Tags::Helpers.current_product(@tag)
263
- result.should == @shop_product
264
- end
265
- end
266
- context 'Using page slug' do
267
- it 'should return the matching category' do
268
- stub(@shop_product).sku { 'bob' }
269
-
270
- stub(@page).shop_product { nil }
271
- stub(@locals).shop_product { nil }
272
- stub(@page).slug { @shop_product.sku }
273
-
274
- mock(ShopProduct).find(:first, {:conditions=>{:sku=>@shop_product.sku}}) { @shop_product }
275
-
237
+
238
+ context 'the current page has a product attached to it' do
239
+ before :each do
240
+ @tag.locals.page.shop_product = @product
241
+ end
242
+ it 'should return the product attached to the page' do
276
243
  result = Shop::Tags::Helpers.current_product(@tag)
277
- result.should == @shop_product
244
+ result.should == @product
278
245
  end
279
246
  end
247
+
280
248
  end
281
249
 
282
- describe '#current_order(tag)' do
283
- context 'existing order' do
250
+ describe '#current_order' do
251
+ before :each do
252
+ @order = shop_orders(:one_item)
253
+ end
254
+
255
+ context 'order previously set' do
256
+ before :each do
257
+ @tag.locals.shop_order = @order
258
+ end
284
259
  it 'should return the order' do
285
- stub(@locals).shop_order { @shop_order }
286
-
287
260
  result = Shop::Tags::Helpers.current_order(@tag)
288
- result.should == @shop_order
261
+ result.should == @order
289
262
  end
290
263
  end
291
- context 'using order id' do
292
- it 'should return the order' do
293
- stub(@locals).shop_order { nil }
294
- stub(@shop_order).id { 1 }
295
- mock(ShopOrder).find(@shop_order.id) { @shop_order }
296
-
297
- @attrs['id'] = @shop_order.id
298
-
264
+
265
+ context 'key and value sent' do
266
+ before :each do
267
+ @tag.attr = { 'key' => 'id', 'value' => @order.id }
268
+ end
269
+ it 'should return the matching order' do
299
270
  result = Shop::Tags::Helpers.current_order(@tag)
300
- result.should == @shop_order
271
+ result.should == @order
301
272
  end
302
273
  end
303
- context 'using request object' do
304
- it 'should return the order' do
305
- stub(@locals).shop_order { nil }
306
- stub(@shop_order).id { 1 }
307
- stub(@page).request.stub!.session { { :shop_order => @shop_order.id } }
308
-
309
- mock(ShopOrder).find(@shop_order.id) { @shop_order }
310
-
274
+
275
+ context 'session contains the order id' do
276
+ before :each do
277
+ @tag.locals.page.request.session[:shop_order] = @order.id
278
+ end
279
+ it 'should return the order with that id' do
311
280
  result = Shop::Tags::Helpers.current_order(@tag)
312
- result.should == @shop_order
281
+ result.should == @order
313
282
  end
314
283
  end
284
+
285
+ context 'nothing available to find the product' do
286
+ it 'should return nil' do
287
+ result = Shop::Tags::Helpers.current_order(@tag)
288
+ result.should be_nil
289
+ end
290
+ end
291
+
315
292
  end
316
293
 
317
- describe '#current_line_item(tag)' do
294
+ describe '#current_line_item' do
295
+ before :each do
296
+ @item = shop_line_items(:crusty_bread)
297
+ end
298
+
318
299
  context 'existing line item' do
319
- it 'should return the line item' do
320
- stub(@locals).shop_line_item { @shop_line_item }
321
-
300
+ before :each do
301
+ @tag.locals.shop_line_item = @item
302
+ end
303
+ it 'should return that existing line item' do
322
304
  result = Shop::Tags::Helpers.current_line_item(@tag)
323
- result.should == @shop_line_item
305
+ result.should == @item
324
306
  end
325
307
  end
326
- context 'existing line item' do
327
- it 'using the current item' do
328
- stub(@shop_product).id { 1 }
329
-
330
- stub(@locals).shop_line_item { nil }
331
- stub(@locals).shop_order { @shop_order }
332
- stub(@locals).shop_product { @shop_product }
333
-
334
- mock(@shop_line_items).find_by_item_id(@shop_product.id) { @shop_line_item }
335
-
308
+
309
+ context 'existing product and category' do
310
+ before :each do
311
+ @tag.locals.shop_order = shop_orders(:one_item)
312
+ @tag.locals.shop_product = shop_products(:crusty_bread)
313
+ end
314
+ it 'should return the item linking the two' do
336
315
  result = Shop::Tags::Helpers.current_line_item(@tag)
337
- result.should == @shop_line_item
316
+ result.should == @item
338
317
  end
339
318
  end
340
319
  end
341
320
 
342
- describe '#current_address(tag)' do
321
+ describe '#current_address' do
343
322
  before :each do
344
- @attrs['type'] = 'billing'
323
+ @address = shop_addresses(:billing)
324
+ @tag.attr = { 'type' => 'billing' }
345
325
  end
346
- context 'address exists' do
326
+
327
+ context 'billing address already exists and billing type was requested' do
347
328
  before :each do
348
- @billing = Object.new
349
- stub(@shop_order).billing { @billing }
350
- stub(@locals).shop_order { @shop_order }
351
- end
352
- context 'tag exists' do
353
- it 'should return the address' do
354
- stub(@locals).address { @billing }
355
-
356
- result = Shop::Tags::Helpers.current_address(@tag)
357
- result.should == @billing
358
- end
359
- end
360
- context 'tag doesnt exist' do
361
- it 'should return that billing address' do
362
- stub(@locals).address { nil }
363
-
364
- result = Shop::Tags::Helpers.current_address(@tag)
365
- result.should == @billing
366
- end
367
- end
368
- end
369
- context 'address does not exist' do
329
+ @tag.locals.address = @address
330
+ @tag.locals.address_type = 'billing'
331
+ end
332
+ it 'should return the existing address' do
333
+ result = Shop::Tags::Helpers.current_address(@tag)
334
+ result.should == @address
335
+ end
336
+ end
337
+
338
+ context 'current_order exists and has billing' do
339
+ before :each do
340
+ @order = shop_orders(:one_item)
341
+ @order.update_attribute(:billing_id, @address.id)
342
+ @tag.locals.shop_order = @order
343
+ end
344
+ it 'should return the order billing address' do
345
+ result = Shop::Tags::Helpers.current_address(@tag)
346
+ result.should == @address
347
+ end
348
+ end
349
+
350
+ context 'current order exists and doesnt have billing' do
351
+ before :each do
352
+ @order = shop_orders(:one_item)
353
+ end
354
+ it 'should return nil' do
355
+ result = Shop::Tags::Helpers.current_address(@tag)
356
+ result.should be_nil
357
+ end
358
+ end
359
+
360
+ context 'no order exists' do
370
361
  it 'should return nil' do
371
- stub(@locals).address { nil }
372
- stub(@shop_order).billing { nil }
373
- stub(@locals).shop_order { @shop_order }
374
-
375
362
  result = Shop::Tags::Helpers.current_address(@tag)
376
- result.should == nil
363
+ result.should be_nil
377
364
  end
378
365
  end
379
366
  end