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.
- data/README.md +9 -3
- data/Rakefile +1 -0
- data/VERSION +1 -1
- data/app/controllers/admin/shop/customers_controller.rb +35 -126
- data/app/controllers/shop/categories_controller.rb +1 -5
- data/app/controllers/shop/products_controller.rb +1 -1
- data/app/models/form_checkout.rb +198 -112
- data/app/models/shop_category.rb +3 -3
- data/app/models/shop_customer.rb +3 -12
- data/app/models/shop_order.rb +5 -3
- data/app/models/shop_payment.rb +0 -1
- data/app/models/shop_product.rb +3 -3
- data/app/views/admin/shop/customers/edit.html.haml +13 -0
- data/app/views/admin/shop/customers/edit/_fields.html.haml +33 -0
- data/app/views/admin/shop/customers/edit/_head.html.haml +2 -0
- data/app/views/admin/shop/customers/edit/_meta.html.haml +7 -0
- data/app/views/admin/shop/customers/edit/_parts.html.haml +4 -0
- data/app/views/admin/shop/customers/edit/_popups.html.haml +3 -0
- data/app/views/admin/shop/customers/edit/meta/_login.html.haml +5 -0
- data/app/views/admin/shop/customers/edit/meta/_password.html.haml +5 -0
- data/app/views/admin/shop/customers/edit/meta/_password_confirmation.html.haml +5 -0
- data/app/views/admin/shop/customers/edit/parts/_address.html.haml +7 -0
- data/app/views/admin/shop/customers/edit/parts/_addresses.html.haml +13 -0
- data/app/views/admin/shop/customers/edit/parts/_orders.html.haml +29 -0
- data/app/views/admin/shop/customers/index.html.haml +9 -35
- data/app/views/admin/shop/customers/index/_bottom.html.haml +4 -0
- data/app/views/admin/shop/customers/index/_customer.html.haml +9 -0
- data/app/views/admin/shop/customers/new.html.haml +11 -0
- data/app/views/admin/shop/customers/remove.html.haml +12 -0
- data/app/views/admin/shop/products/new.html.haml +1 -1
- data/config/locales/en.yml +37 -29
- data/config/routes.rb +2 -0
- data/db/migrate/20100927041219_remove_payment_methods.rb +16 -0
- data/db/migrate/20100927041624_change_payments_add_gateway.rb +11 -0
- data/db/migrate/20100927140446_change_payment_add_card_type_card_number.rb +11 -0
- data/db/seed.rb +1 -0
- data/db/seeds/forms.rb +179 -0
- data/db/{migrate/20100520033059_create_layouts.rb → seeds/layouts.rb} +19 -27
- data/db/seeds/snippets.rb +23 -0
- data/lib/shop/interface/customers.rb +34 -0
- data/lib/shop/tags/address.rb +1 -0
- data/lib/shop/tags/card.rb +51 -0
- data/lib/shop/tags/helpers.rb +53 -38
- data/lib/shop/tags/item.rb +1 -1
- data/lib/shop/tags/product.rb +23 -22
- data/lib/shop/tags/responses.rb +3 -3
- data/lib/tasks/shop_extension_tasks.rake +6 -0
- data/public/stylesheets/sass/admin/extensions/shop/index.sass +64 -0
- data/radiant-shop-extension.gemspec +37 -6
- data/shop_extension.rb +7 -2
- data/spec/datasets/forms.rb +112 -118
- data/spec/datasets/shop_customers.rb +30 -0
- data/spec/datasets/shop_orders.rb +7 -3
- data/spec/datasets/shop_products.rb +1 -0
- data/spec/lib/shop/tags/card_spec.rb +71 -0
- data/spec/lib/shop/tags/helpers_spec.rb +270 -283
- data/spec/lib/shop/tags/item_spec.rb +9 -0
- data/spec/lib/shop/tags/product_spec.rb +172 -158
- data/spec/lib/shop/tags/responses_spec.rb +129 -0
- data/spec/models/form_checkout_spec.rb +228 -294
- data/spec/models/shop_category_page_spec.rb +2 -2
- data/spec/models/shop_order_spec.rb +27 -20
- data/spec/models/shop_product_attachment_spec.rb +1 -0
- metadata +61 -17
- data/app/models/shop_payment_method.rb +0 -5
- data/db/migrate/20100903122123_create_forms.rb +0 -44
- 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
|
-
|
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
|
-
@
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
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
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
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 == @
|
36
|
+
result.should == [@category]
|
52
37
|
end
|
53
38
|
end
|
54
39
|
|
55
|
-
context '
|
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 == @
|
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 '
|
70
|
-
|
71
|
-
|
72
|
-
|
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 == @
|
66
|
+
result.should == [@category]
|
78
67
|
end
|
79
68
|
end
|
80
69
|
end
|
81
70
|
|
82
|
-
describe '#current_category
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
it 'should return the
|
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 == @
|
83
|
+
result.should == @category
|
101
84
|
end
|
102
85
|
end
|
103
|
-
|
104
|
-
|
105
|
-
|
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 == @
|
103
|
+
result.should == @category
|
109
104
|
end
|
110
105
|
end
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
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 == @
|
113
|
+
result.should == @category
|
118
114
|
end
|
119
115
|
end
|
120
|
-
|
121
|
-
|
122
|
-
|
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 == @
|
123
|
+
result.should == @category
|
126
124
|
end
|
127
125
|
end
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
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 == @
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
|
141
|
-
|
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
|
140
|
+
result.should be_nil
|
152
141
|
end
|
153
142
|
end
|
143
|
+
|
154
144
|
end
|
155
|
-
|
156
|
-
describe '#current_products
|
157
|
-
|
158
|
-
|
159
|
-
|
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 == @
|
168
|
+
result.should == @category.products
|
163
169
|
end
|
164
170
|
end
|
165
|
-
|
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 == @
|
188
|
+
result.should == [@product]
|
174
189
|
end
|
175
190
|
end
|
176
|
-
|
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 == @
|
187
|
-
end
|
188
|
-
end
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
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
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
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 == @
|
224
|
+
result.should == @product
|
247
225
|
end
|
248
226
|
end
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
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 == @
|
234
|
+
result.should == @product
|
256
235
|
end
|
257
236
|
end
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
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 == @
|
244
|
+
result.should == @product
|
278
245
|
end
|
279
246
|
end
|
247
|
+
|
280
248
|
end
|
281
249
|
|
282
|
-
describe '#current_order
|
283
|
-
|
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 == @
|
261
|
+
result.should == @order
|
289
262
|
end
|
290
263
|
end
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
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 == @
|
271
|
+
result.should == @order
|
301
272
|
end
|
302
273
|
end
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
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 == @
|
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
|
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
|
-
|
320
|
-
|
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 == @
|
305
|
+
result.should == @item
|
324
306
|
end
|
325
307
|
end
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
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 == @
|
316
|
+
result.should == @item
|
338
317
|
end
|
339
318
|
end
|
340
319
|
end
|
341
320
|
|
342
|
-
describe '#current_address
|
321
|
+
describe '#current_address' do
|
343
322
|
before :each do
|
344
|
-
@
|
323
|
+
@address = shop_addresses(:billing)
|
324
|
+
@tag.attr = { 'type' => 'billing' }
|
345
325
|
end
|
346
|
-
|
326
|
+
|
327
|
+
context 'billing address already exists and billing type was requested' do
|
347
328
|
before :each do
|
348
|
-
@
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
context '
|
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
|
363
|
+
result.should be_nil
|
377
364
|
end
|
378
365
|
end
|
379
366
|
end
|