radiant-shop-extension 0.9.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +6 -0
- data/Gemfile +26 -0
- data/Gemfile.lock +75 -0
- data/HISTORY.md +77 -0
- data/MIT-LICENSE +20 -0
- data/README.md +26 -0
- data/Rakefile +141 -0
- data/VERSION +1 -0
- data/app/.DS_Store +0 -0
- data/app/controllers/admin/shop/categories_controller.rb +206 -0
- data/app/controllers/admin/shop/customers_controller.rb +137 -0
- data/app/controllers/admin/shop/orders_controller.rb +171 -0
- data/app/controllers/admin/shop/products/images_controller.rb +144 -0
- data/app/controllers/admin/shop/products_controller.rb +217 -0
- data/app/controllers/admin/shops_controller.rb +9 -0
- data/app/controllers/shop/categories_controller.rb +49 -0
- data/app/controllers/shop/line_items_controller.rb +165 -0
- data/app/controllers/shop/orders_controller.rb +16 -0
- data/app/controllers/shop/products_controller.rb +48 -0
- data/app/models/form_checkout.rb +245 -0
- data/app/models/shop_address.rb +13 -0
- data/app/models/shop_addressable.rb +11 -0
- data/app/models/shop_category.rb +85 -0
- data/app/models/shop_category_page.rb +7 -0
- data/app/models/shop_customer.rb +27 -0
- data/app/models/shop_line_item.rb +32 -0
- data/app/models/shop_order.rb +108 -0
- data/app/models/shop_payment.rb +6 -0
- data/app/models/shop_payment_method.rb +5 -0
- data/app/models/shop_product.rb +87 -0
- data/app/models/shop_product_attachment.rb +30 -0
- data/app/models/shop_product_page.rb +7 -0
- data/app/views/.DS_Store +0 -0
- data/app/views/admin/.DS_Store +0 -0
- data/app/views/admin/pages/_shop_category.html.haml +4 -0
- data/app/views/admin/pages/_shop_product.html.haml +4 -0
- data/app/views/admin/shop/categories/edit.html.haml +12 -0
- data/app/views/admin/shop/categories/edit/_fields.html.haml +28 -0
- data/app/views/admin/shop/categories/edit/_head.html.haml +2 -0
- data/app/views/admin/shop/categories/edit/_meta.html.haml +7 -0
- data/app/views/admin/shop/categories/edit/_part.html.haml +3 -0
- data/app/views/admin/shop/categories/edit/_popup.html.haml +3 -0
- data/app/views/admin/shop/categories/edit/meta/_handle.html.haml +5 -0
- data/app/views/admin/shop/categories/edit/meta/_layouts.html.haml +10 -0
- data/app/views/admin/shop/categories/edit/parts/_description.html.haml +1 -0
- data/app/views/admin/shop/categories/index/_category.html.haml +16 -0
- data/app/views/admin/shop/categories/new.html.haml +10 -0
- data/app/views/admin/shop/categories/remove.html.haml +12 -0
- data/app/views/admin/shop/customers/index.html.haml +36 -0
- data/app/views/admin/shop/orders/index.html.haml +33 -0
- data/app/views/admin/shop/products/edit.html.haml +14 -0
- data/app/views/admin/shop/products/edit/_fields.html.haml +38 -0
- data/app/views/admin/shop/products/edit/_head.html.haml +2 -0
- data/app/views/admin/shop/products/edit/_image.html.haml +12 -0
- data/app/views/admin/shop/products/edit/_meta.html.haml +8 -0
- data/app/views/admin/shop/products/edit/_part.html.haml +3 -0
- data/app/views/admin/shop/products/edit/_popup.html.haml +3 -0
- data/app/views/admin/shop/products/edit/buttons/_browse_images.html.haml +1 -0
- data/app/views/admin/shop/products/edit/buttons/_new_image.html.haml +1 -0
- data/app/views/admin/shop/products/edit/meta/_category.html.haml +5 -0
- data/app/views/admin/shop/products/edit/meta/_sku.html.haml +5 -0
- data/app/views/admin/shop/products/edit/parts/_description.html.haml +1 -0
- data/app/views/admin/shop/products/edit/parts/_images.html.haml +5 -0
- data/app/views/admin/shop/products/edit/popups/_browse_images.html.haml +6 -0
- data/app/views/admin/shop/products/edit/popups/_new_image.html.haml +18 -0
- data/app/views/admin/shop/products/index.html.haml +10 -0
- data/app/views/admin/shop/products/index/_bottom.html.haml +5 -0
- data/app/views/admin/shop/products/index/_product.html.haml +13 -0
- data/app/views/admin/shop/products/new.html.haml +10 -0
- data/app/views/admin/shop/products/remove.html.haml +12 -0
- data/app/views/shop/categories/show.html.haml +1 -0
- data/app/views/shop/orders/show.html.haml +1 -0
- data/app/views/shop/products/index.html.haml +1 -0
- data/app/views/shop/products/show.html.haml +1 -0
- data/config/locales/en.yml +50 -0
- data/config/routes.rb +38 -0
- data/config/shop_cart.yml +16 -0
- data/cucumber.yml +1 -0
- data/db/migrate/20100311053701_initial.rb +153 -0
- data/db/migrate/20100520033059_create_layouts.rb +119 -0
- data/db/migrate/20100903122123_create_forms.rb +44 -0
- data/db/migrate/20100908063639_create_snippets.rb +22 -0
- data/features/support/env.rb +16 -0
- data/features/support/paths.rb +14 -0
- data/lib/shop/controllers/application_controller.rb +39 -0
- data/lib/shop/controllers/site_controller.rb +12 -0
- data/lib/shop/interface/products.rb +49 -0
- data/lib/shop/models/image.rb +14 -0
- data/lib/shop/models/page.rb +14 -0
- data/lib/shop/tags/address.rb +40 -0
- data/lib/shop/tags/cart.rb +49 -0
- data/lib/shop/tags/category.rb +83 -0
- data/lib/shop/tags/core.rb +12 -0
- data/lib/shop/tags/helpers.rb +142 -0
- data/lib/shop/tags/item.rb +109 -0
- data/lib/shop/tags/product.rb +109 -0
- data/lib/shop/tags/responses.rb +34 -0
- data/lib/tasks/shop_extension_tasks.rake +54 -0
- data/mockups/balsamiq/products-retro_fun_tshirt-more.bmml +0 -0
- data/mockups/balsamiq/products-retro_fun_tshirt.bmml +0 -0
- data/public/images/admin/extensions/shop/products/sort.png +0 -0
- data/public/javascripts/admin/extensions/shop/products/edit.js +115 -0
- data/public/javascripts/admin/extensions/shop/products/index.js +65 -0
- data/public/stylesheets/sass/admin/extensions/shop/edit.sass +86 -0
- data/public/stylesheets/sass/admin/extensions/shop/products/edit.sass +158 -0
- data/public/stylesheets/sass/admin/extensions/shop/products/index.sass +129 -0
- data/radiant-shop-extension.gemspec +245 -0
- data/shop_extension.rb +62 -0
- data/spec/controllers/admin/shop/categories_controller_spec.rb +443 -0
- data/spec/controllers/admin/shop/products/images_controller_spec.rb +477 -0
- data/spec/controllers/admin/shop/products_controller_spec.rb +394 -0
- data/spec/controllers/admin/shops_controller_spec.rb +19 -0
- data/spec/controllers/shop/categories_controller_spec.rb +42 -0
- data/spec/controllers/shop/line_items_controller_spec.rb +256 -0
- data/spec/controllers/shop/orders_controller_specs.rb +37 -0
- data/spec/controllers/shop/products_controller_spec.rb +51 -0
- data/spec/datasets/forms.rb +153 -0
- data/spec/datasets/images.rb +13 -0
- data/spec/datasets/shop_addresses.rb +27 -0
- data/spec/datasets/shop_categories.rb +13 -0
- data/spec/datasets/shop_line_items.rb +9 -0
- data/spec/datasets/shop_orders.rb +21 -0
- data/spec/datasets/shop_products.rb +34 -0
- data/spec/helpers/nested_tag_helper.rb +33 -0
- data/spec/lib/shop/models/image_spec.rb +28 -0
- data/spec/lib/shop/models/page_spec.rb +38 -0
- data/spec/lib/shop/tags/address_spec.rb +196 -0
- data/spec/lib/shop/tags/cart_spec.rb +169 -0
- data/spec/lib/shop/tags/category_spec.rb +201 -0
- data/spec/lib/shop/tags/core_spec.rb +16 -0
- data/spec/lib/shop/tags/helpers_spec.rb +381 -0
- data/spec/lib/shop/tags/item_spec.rb +313 -0
- data/spec/lib/shop/tags/product_spec.rb +334 -0
- data/spec/matchers/comparison.rb +72 -0
- data/spec/matchers/render_matcher.rb +33 -0
- data/spec/models/form_checkout_spec.rb +376 -0
- data/spec/models/shop_category_page_spec.rb +10 -0
- data/spec/models/shop_category_spec.rb +58 -0
- data/spec/models/shop_line_item_spec.rb +42 -0
- data/spec/models/shop_order_spec.rb +228 -0
- data/spec/models/shop_product_attachment_spec.rb +72 -0
- data/spec/models/shop_product_page_spec.rb +10 -0
- data/spec/models/shop_product_spec.rb +135 -0
- data/spec/spec.opts +6 -0
- data/spec/spec_helper.rb +22 -0
- data/vendor/plugins/acts_as_list/README +23 -0
- data/vendor/plugins/acts_as_list/init.rb +3 -0
- data/vendor/plugins/acts_as_list/lib/active_record/acts/list.rb +256 -0
- data/vendor/plugins/acts_as_list/test/list_test.rb +332 -0
- data/vendor/plugins/json_fields/.gitignore +3 -0
- data/vendor/plugins/json_fields/MIT-LICENSE +20 -0
- data/vendor/plugins/json_fields/README.rdoc +65 -0
- data/vendor/plugins/json_fields/Rakefile +55 -0
- data/vendor/plugins/json_fields/init.rb +2 -0
- data/vendor/plugins/json_fields/lib/json_fields.rb +99 -0
- data/vendor/plugins/json_fields/spec/lib/json_fields_spec.rb +124 -0
- data/vendor/plugins/json_fields/spec/spec.opts +6 -0
- data/vendor/plugins/json_fields/spec/spec_helper.rb +29 -0
- data/vendor/plugins/json_fields/spec/test_models.rb +12 -0
- metadata +324 -0
@@ -0,0 +1,313 @@
|
|
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::Item do
|
8
|
+
|
9
|
+
dataset :pages
|
10
|
+
|
11
|
+
it 'should describe these tags' do
|
12
|
+
Shop::Tags::Item.tags.sort.should == [
|
13
|
+
'shop:cart:if_items',
|
14
|
+
'shop:cart:unless_items',
|
15
|
+
'shop:cart:items',
|
16
|
+
'shop:cart:items:each',
|
17
|
+
'shop:cart:item',
|
18
|
+
'shop:cart:item:id',
|
19
|
+
'shop:cart:item:quantity',
|
20
|
+
'shop:cart:item:name',
|
21
|
+
'shop:cart:item:link',
|
22
|
+
'shop:cart:item:price',
|
23
|
+
'shop:cart:item:weight',
|
24
|
+
'shop:cart:item:remove'].sort
|
25
|
+
end
|
26
|
+
|
27
|
+
before :all do
|
28
|
+
@page = pages(:home)
|
29
|
+
end
|
30
|
+
|
31
|
+
before :each do
|
32
|
+
order = Object.new
|
33
|
+
stub(order).id { 1 }
|
34
|
+
@shop_order = order
|
35
|
+
|
36
|
+
item = Object.new
|
37
|
+
stub(item).id { 1 }
|
38
|
+
@shop_line_item = item
|
39
|
+
|
40
|
+
product = Object.new
|
41
|
+
stub(product).id { 1 }
|
42
|
+
@shop_product = product
|
43
|
+
|
44
|
+
stub(@shop_line_item).item { @shop_product }
|
45
|
+
stub(@shop_line_item).order { @shop_order }
|
46
|
+
|
47
|
+
@shop_line_items = [ @shop_line_item, @shop_line_item, @shop_line_item ]
|
48
|
+
stub(@shop_order).line_items { @shop_line_items }
|
49
|
+
end
|
50
|
+
|
51
|
+
context 'within a cart' do
|
52
|
+
|
53
|
+
before :each do
|
54
|
+
mock(Shop::Tags::Helpers).current_order(anything) { @shop_order }
|
55
|
+
end
|
56
|
+
|
57
|
+
context 'group of items' do
|
58
|
+
describe '<r:shop:cart:if_items>' do
|
59
|
+
context 'success' do
|
60
|
+
it 'should render' do
|
61
|
+
tag = %{<r:shop:cart:if_items>success</r:shop:cart:if_items>}
|
62
|
+
expected = %{success}
|
63
|
+
@page.should render(tag).as(expected)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
context 'failure' do
|
67
|
+
it 'should render' do
|
68
|
+
stub(@shop_order).line_items { [] }
|
69
|
+
|
70
|
+
tag = %{<r:shop:cart:if_items>failure</r:shop:cart:if_items>}
|
71
|
+
expected = %{}
|
72
|
+
@page.should render(tag).as(expected)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
describe '<r:shop:cart:unless_items>' do
|
78
|
+
context 'success' do
|
79
|
+
it 'should render' do
|
80
|
+
stub(@shop_order).line_items { [] }
|
81
|
+
|
82
|
+
tag = %{<r:shop:cart:unless_items>success</r:shop:cart:unless_items>}
|
83
|
+
expected = %{success}
|
84
|
+
@page.should render(tag).as(expected)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
context 'failure' do
|
88
|
+
it 'should render' do
|
89
|
+
tag = %{<r:shop:cart:unless_items>failure</r:shop:cart:unless_items>}
|
90
|
+
expected = %{}
|
91
|
+
@page.should render(tag).as(expected)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
describe '<r:shop:cart:items>' do
|
97
|
+
context 'items exist' do
|
98
|
+
it 'should render' do
|
99
|
+
tag = %{<r:shop:cart:items>success</r:shop:cart:items>}
|
100
|
+
expected = %{success}
|
101
|
+
|
102
|
+
@page.should render(tag).as(expected)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
context 'items dont exist' do
|
107
|
+
it 'should render' do
|
108
|
+
tag = %{<r:shop:cart:items>success</r:shop:cart:items>}
|
109
|
+
expected = %{success}
|
110
|
+
|
111
|
+
@page.should render(tag).as(expected)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
describe '<r:shop:cart:items:each' do
|
117
|
+
context 'success' do
|
118
|
+
it 'should render' do
|
119
|
+
tag = %{<r:shop:cart:items:each>.a.</r:shop:cart:items:each>}
|
120
|
+
expected = %{.a..a..a.}
|
121
|
+
|
122
|
+
@page.should render(tag).as(expected)
|
123
|
+
end
|
124
|
+
it 'should assign the local item' do
|
125
|
+
tag = %{<r:shop:cart:items:each><r:item:id /></r:shop:cart:items:each>}
|
126
|
+
expected = %{111}
|
127
|
+
|
128
|
+
@page.should render(tag).as(expected)
|
129
|
+
end
|
130
|
+
it 'should assign the local product' do
|
131
|
+
tag = %{<r:shop:cart:items:each><r:product:id /></r:shop:cart:items:each>}
|
132
|
+
expected = %{111}
|
133
|
+
|
134
|
+
@page.should render(tag).as(expected)
|
135
|
+
end
|
136
|
+
end
|
137
|
+
context 'failure' do
|
138
|
+
it 'should not render' do
|
139
|
+
stub(@shop_order).line_items { [] }
|
140
|
+
|
141
|
+
tag = %{<r:shop:cart:items:each></r:shop:cart:items:each>}
|
142
|
+
expected = %{}
|
143
|
+
|
144
|
+
@page.should render(tag).as(expected)
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
context 'a single item' do
|
151
|
+
describe '<r:shop:cart:item>' do
|
152
|
+
context 'success' do
|
153
|
+
it 'should render' do
|
154
|
+
mock(Shop::Tags::Helpers).current_line_item(anything) { @shop_line_item }
|
155
|
+
|
156
|
+
tag = %{<r:shop:cart:item>success</r:shop:cart:item>}
|
157
|
+
expected = %{success}
|
158
|
+
|
159
|
+
@page.should render(tag).as(expected)
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
context 'failure' do
|
164
|
+
it 'should not render' do
|
165
|
+
mock(Shop::Tags::Helpers).current_line_item(anything) { nil }
|
166
|
+
tag = %{<r:shop:cart:item>failure</r:shop:cart:item>}
|
167
|
+
expected = %{}
|
168
|
+
|
169
|
+
@page.should render(tag).as(expected)
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
describe 'simple attributes' do
|
174
|
+
before :each do
|
175
|
+
mock(Shop::Tags::Helpers).current_line_item(anything) { @shop_line_item }
|
176
|
+
end
|
177
|
+
it 'should render <r:id />' do
|
178
|
+
stub(@shop_line_item).id { 1 }
|
179
|
+
|
180
|
+
tag = %{<r:shop:cart:item:id />}
|
181
|
+
expected = %{1}
|
182
|
+
|
183
|
+
@page.should render(tag).as(expected)
|
184
|
+
end
|
185
|
+
it 'should render <r:quantity />' do
|
186
|
+
stub(@shop_line_item).quantity { 1 }
|
187
|
+
|
188
|
+
tag = %{<r:shop:cart:item:quantity />}
|
189
|
+
expected = %{1}
|
190
|
+
|
191
|
+
@page.should render(tag).as(expected)
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
describe 'item attributes' do
|
196
|
+
before :each do
|
197
|
+
mock(Shop::Tags::Helpers).current_line_item(anything) { @shop_line_item }
|
198
|
+
end
|
199
|
+
it 'should render <r:name />' do
|
200
|
+
stub(@shop_line_item).item.stub!.name { 'name' }
|
201
|
+
|
202
|
+
tag = %{<r:shop:cart:item:name />}
|
203
|
+
expected = %{name}
|
204
|
+
|
205
|
+
@page.should render(tag).as(expected)
|
206
|
+
end
|
207
|
+
it 'should render <r:weight />' do
|
208
|
+
stub(@shop_line_item).item.stub!.weight { 100 }
|
209
|
+
|
210
|
+
tag = %{<r:shop:cart:item:weight />}
|
211
|
+
expected = %{100}
|
212
|
+
|
213
|
+
@page.should render(tag).as(expected)
|
214
|
+
end
|
215
|
+
end
|
216
|
+
|
217
|
+
describe '<r:shop:cart:item:link />' do
|
218
|
+
before :each do
|
219
|
+
mock(Shop::Tags::Helpers).current_line_item(anything) { @shop_line_item }
|
220
|
+
end
|
221
|
+
|
222
|
+
context 'standalone' do
|
223
|
+
before :each do
|
224
|
+
item = Object.new
|
225
|
+
stub(@shop_line_item).item { item }
|
226
|
+
stub(item).slug { 'slug' }
|
227
|
+
stub(item).name { 'name' }
|
228
|
+
end
|
229
|
+
it 'should render an anchor element' do
|
230
|
+
tag = %{<r:shop:cart:item:link />}
|
231
|
+
expected = %{<a href="slug">name</a>}
|
232
|
+
pages(:home).should render(tag).as(expected)
|
233
|
+
end
|
234
|
+
it 'should assign attributes' do
|
235
|
+
tag = %{<r:shop:cart:item:link title="title" data-title="data-title"/>}
|
236
|
+
expected = %{<a href="slug" data-title="data-title" title="title">name</a>}
|
237
|
+
pages(:home).should render(tag).as(expected)
|
238
|
+
end
|
239
|
+
end
|
240
|
+
|
241
|
+
context 'wrapped' do
|
242
|
+
it 'should render an anchor element' do
|
243
|
+
item = Object.new
|
244
|
+
stub(@shop_line_item).item { item }
|
245
|
+
stub(item).slug { 'slug' }
|
246
|
+
|
247
|
+
tag = %{<r:shop:cart:item:link>title</r:shop:cart:item:link>}
|
248
|
+
expected = %{<a href="slug">title</a>}
|
249
|
+
pages(:home).should render(tag).as(expected)
|
250
|
+
end
|
251
|
+
end
|
252
|
+
end
|
253
|
+
|
254
|
+
describe '<r:shop:cart:item:price />' do
|
255
|
+
before :each do
|
256
|
+
mock(Shop::Tags::Helpers).current_line_item(anything) { @shop_line_item }
|
257
|
+
|
258
|
+
stub(@shop_line_item).price { 1234.34567890 }
|
259
|
+
end
|
260
|
+
|
261
|
+
it 'should render a standard price' do
|
262
|
+
tag = %{<r:shop:cart:item:price />}
|
263
|
+
expected = %{$1,234.35}
|
264
|
+
|
265
|
+
@page.should render(tag).as(expected)
|
266
|
+
end
|
267
|
+
|
268
|
+
it 'should render a high precision price' do
|
269
|
+
tag = %{<r:shop:cart:item:price precision="8"/>}
|
270
|
+
expected = %{$1,234.34567890}
|
271
|
+
|
272
|
+
@page.should render(tag).as(expected)
|
273
|
+
end
|
274
|
+
|
275
|
+
it 'should render a custom format' do
|
276
|
+
tag = %{<r:shop:cart:item:price unit="%" separator="-" delimiter="+" />}
|
277
|
+
expected = %{%1+234-35}
|
278
|
+
|
279
|
+
@page.should render(tag).as(expected)
|
280
|
+
end
|
281
|
+
end
|
282
|
+
|
283
|
+
describe '<r:shop:cart:item:remove />' do
|
284
|
+
before :each do
|
285
|
+
mock(Shop::Tags::Helpers).current_line_item(anything) { @shop_line_item }
|
286
|
+
end
|
287
|
+
|
288
|
+
context 'standalone' do
|
289
|
+
it 'should render an anchor element' do
|
290
|
+
tag = %{<r:shop:cart:item:remove />}
|
291
|
+
expected = %{<a href="/#{Radiant::Config['shop.url_prefix']}/cart/items/#{@shop_line_item.id}/destroy">remove</a>}
|
292
|
+
pages(:home).should render(tag).as(expected)
|
293
|
+
end
|
294
|
+
it 'should assign attributes' do
|
295
|
+
tag = %{<r:shop:cart:item:remove title="title" data-title="data-title"/>}
|
296
|
+
expected = %{<a href="/#{Radiant::Config['shop.url_prefix']}/cart/items/#{@shop_line_item.id}/destroy" data-title="data-title" title="title">remove</a>}
|
297
|
+
pages(:home).should render(tag).as(expected)
|
298
|
+
end
|
299
|
+
end
|
300
|
+
|
301
|
+
context 'wrapped' do
|
302
|
+
it 'should render an anchor element' do
|
303
|
+
tag = %{<r:shop:cart:item:remove>get rid of me</r:shop:cart:item:remove>}
|
304
|
+
expected = %{<a href="/#{Radiant::Config['shop.url_prefix']}/cart/items/#{@shop_line_item.id}/destroy">get rid of me</a>}
|
305
|
+
pages(:home).should render(tag).as(expected)
|
306
|
+
end
|
307
|
+
end
|
308
|
+
end
|
309
|
+
|
310
|
+
end
|
311
|
+
end
|
312
|
+
end
|
313
|
+
end
|
@@ -0,0 +1,334 @@
|
|
1
|
+
require 'spec/spec_helper'
|
2
|
+
|
3
|
+
describe Shop::Tags::Product do
|
4
|
+
|
5
|
+
dataset :pages
|
6
|
+
|
7
|
+
it 'should describe these tags' do
|
8
|
+
Shop::Tags::Product.tags.sort.should == [
|
9
|
+
'shop:if_products',
|
10
|
+
'shop:unless_products',
|
11
|
+
'shop:products',
|
12
|
+
'shop:products:each',
|
13
|
+
'shop:product',
|
14
|
+
'shop:product:id',
|
15
|
+
'shop:product:name',
|
16
|
+
'shop:product:price',
|
17
|
+
'shop:product:sku',
|
18
|
+
'shop:product:slug',
|
19
|
+
'shop:product:description',
|
20
|
+
'shop:product:link',
|
21
|
+
'shop:product:if_images',
|
22
|
+
'shop:product:unless_images',
|
23
|
+
'shop:product:images',
|
24
|
+
'shop:product:images:each'].sort
|
25
|
+
end
|
26
|
+
|
27
|
+
before(:each) do
|
28
|
+
product = Object.new
|
29
|
+
stub(product).id { 1 }
|
30
|
+
|
31
|
+
@shop_product = product
|
32
|
+
@shop_products = [ product, product, product ]
|
33
|
+
|
34
|
+
image = Object.new
|
35
|
+
stub(image).id { 1 }
|
36
|
+
|
37
|
+
@image = image
|
38
|
+
@images = [ image, image, image ]
|
39
|
+
end
|
40
|
+
|
41
|
+
describe '<r:shop:if_products>' do
|
42
|
+
context 'success' do
|
43
|
+
it 'should render' do
|
44
|
+
mock(Shop::Tags::Helpers).current_products(anything) { @shop_products }
|
45
|
+
|
46
|
+
tag = %{<r:shop:if_products>success</r:shop:if_products>}
|
47
|
+
expected = %{success}
|
48
|
+
pages(:home).should render(tag).as(expected)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
context 'failure' do
|
52
|
+
it 'should not render' do
|
53
|
+
mock(Shop::Tags::Helpers).current_products(anything) { [] }
|
54
|
+
|
55
|
+
tag = %{<r:shop:if_products>failure</r:shop:if_products>}
|
56
|
+
expected = %{}
|
57
|
+
pages(:home).should render(tag).as(expected)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe '<r:shop:unless_products>' do
|
63
|
+
context 'success' do
|
64
|
+
it 'should render' do
|
65
|
+
mock(Shop::Tags::Helpers).current_products(anything) { [] }
|
66
|
+
|
67
|
+
tag = %{<r:shop:unless_products>success</r:shop:unless_products>}
|
68
|
+
expected = %{success}
|
69
|
+
pages(:home).should render(tag).as(expected)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
context 'failure' do
|
73
|
+
it 'should not render' do
|
74
|
+
mock(Shop::Tags::Helpers).current_products(anything) { @shop_products }
|
75
|
+
|
76
|
+
tag = %{<r:shop:unless_products>failure</r:shop:unless_products>}
|
77
|
+
expected = %{}
|
78
|
+
pages(:home).should render(tag).as(expected)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
describe '<r:shop:products>' do
|
84
|
+
it 'should render' do
|
85
|
+
tag = %{<r:shop:products>success</r:shop:products>}
|
86
|
+
expected = %{success}
|
87
|
+
|
88
|
+
pages(:home).should render(tag).as(expected)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
describe '<r:shop:products:each>' do
|
93
|
+
context 'success' do
|
94
|
+
it 'should not render' do
|
95
|
+
mock(Shop::Tags::Helpers).current_products(anything) { @shop_products }
|
96
|
+
|
97
|
+
tag = %{<r:shop:products:each>.a.</r:shop:products:each>}
|
98
|
+
expected = %{.a..a..a.}
|
99
|
+
pages(:home).should render(tag).as(expected)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
context 'failure' do
|
103
|
+
it 'should not render' do
|
104
|
+
mock(Shop::Tags::Helpers).current_products(anything) { [] }
|
105
|
+
|
106
|
+
tag = %{<r:shop:products:each>failure</r:shop:products:each>}
|
107
|
+
expected = %{}
|
108
|
+
pages(:home).should render(tag).as(expected)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
describe '<r:shop:product>' do
|
114
|
+
context 'success' do
|
115
|
+
it 'should render' do
|
116
|
+
mock(Shop::Tags::Helpers).current_product(anything) { @shop_product }
|
117
|
+
|
118
|
+
tag = %{<r:shop:product>success</r:shop:product>}
|
119
|
+
expected = %{success}
|
120
|
+
pages(:home).should render(tag).as(expected)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
context 'failure' do
|
124
|
+
it 'should not render' do
|
125
|
+
mock(Shop::Tags::Helpers).current_product(anything) { nil }
|
126
|
+
|
127
|
+
tag = %{<r:shop:product>failure</r:shop:product>}
|
128
|
+
expected = %{}
|
129
|
+
pages(:home).should render(tag).as(expected)
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
describe 'simple attributes' do
|
134
|
+
before :each do
|
135
|
+
mock(Shop::Tags::Helpers).current_product(anything) { @shop_product }
|
136
|
+
end
|
137
|
+
it 'should render <r:id />' do
|
138
|
+
stub(@shop_product).id { 1 }
|
139
|
+
|
140
|
+
tag = %{<r:shop:product:id />}
|
141
|
+
expected = %{1}
|
142
|
+
pages(:home).should render(tag).as(expected)
|
143
|
+
end
|
144
|
+
it 'should render <r:name />' do
|
145
|
+
stub(@shop_product).name { 'name' }
|
146
|
+
|
147
|
+
tag = %{<r:shop:product:name />}
|
148
|
+
expected = %{name}
|
149
|
+
pages(:home).should render(tag).as(expected)
|
150
|
+
end
|
151
|
+
it 'should render <r:sku />' do
|
152
|
+
stub(@shop_product).sku { 'sku' }
|
153
|
+
|
154
|
+
tag = %{<r:shop:product:sku />}
|
155
|
+
expected = %{sku}
|
156
|
+
pages(:home).should render(tag).as(expected)
|
157
|
+
end
|
158
|
+
it 'should render <r:slug />' do
|
159
|
+
stub(@shop_product).slug { 'slug' }
|
160
|
+
|
161
|
+
tag = %{<r:shop:product:slug />}
|
162
|
+
expected = %{slug}
|
163
|
+
pages(:home).should render(tag).as(expected)
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
describe '<r:shop:product:description />' do
|
168
|
+
it 'should render a textile filtered result' do
|
169
|
+
mock(Shop::Tags::Helpers).current_product(anything) { @shop_product }
|
170
|
+
stub(@shop_product).description { '*bold*' }
|
171
|
+
|
172
|
+
tag = %{<r:shop:product:description />}
|
173
|
+
expected = %{<p><strong>bold</strong></p>}
|
174
|
+
pages(:home).should render(tag).as(expected)
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
describe '<r:link />' do
|
179
|
+
before :each do
|
180
|
+
mock(Shop::Tags::Helpers).current_product(anything) { @shop_product }
|
181
|
+
end
|
182
|
+
|
183
|
+
context 'standalone' do
|
184
|
+
before :each do
|
185
|
+
stub(@shop_product).slug { 'slug' }
|
186
|
+
stub(@shop_product).name { 'name' }
|
187
|
+
end
|
188
|
+
it 'should render an anchor element' do
|
189
|
+
tag = %{<r:shop:product:link />}
|
190
|
+
expected = %{<a href="slug">name</a>}
|
191
|
+
pages(:home).should render(tag).as(expected)
|
192
|
+
end
|
193
|
+
it 'should assign attributes' do
|
194
|
+
tag = %{<r:shop:product:link title="title" data-title="data-title"/>}
|
195
|
+
expected = %{<a href="slug" data-title="data-title" title="title">name</a>}
|
196
|
+
pages(:home).should render(tag).as(expected)
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
context 'wrapped' do
|
201
|
+
it 'should render an anchor element' do
|
202
|
+
stub(@shop_product).slug { 'slug' }
|
203
|
+
|
204
|
+
tag = %{<r:shop:product:link>title</r:shop:product:link>}
|
205
|
+
expected = %{<a href="slug">title</a>}
|
206
|
+
pages(:home).should render(tag).as(expected)
|
207
|
+
end
|
208
|
+
end
|
209
|
+
end
|
210
|
+
|
211
|
+
describe '<r:price />' do
|
212
|
+
before :each do
|
213
|
+
mock(Shop::Tags::Helpers).current_product(anything) { @shop_product }
|
214
|
+
stub(@shop_product).price { 1234.34567890 }
|
215
|
+
end
|
216
|
+
|
217
|
+
it 'should render a standard price' do
|
218
|
+
tag = %{<r:shop:product:price />}
|
219
|
+
expected = %{$1,234.35}
|
220
|
+
pages(:home).should render(tag).as(expected)
|
221
|
+
end
|
222
|
+
|
223
|
+
it 'should render a high precision price' do
|
224
|
+
tag = %{<r:shop:product:price precision="8"/>}
|
225
|
+
expected = %{$1,234.34567890}
|
226
|
+
pages(:home).should render(tag).as(expected)
|
227
|
+
end
|
228
|
+
|
229
|
+
it 'should render a custom format' do
|
230
|
+
tag = %{<r:shop:product:price unit="%" separator="-" delimiter="+" />}
|
231
|
+
expected = %{%1+234-35}
|
232
|
+
pages(:home).should render(tag).as(expected)
|
233
|
+
end
|
234
|
+
end
|
235
|
+
|
236
|
+
describe '<r:shop:product:if_images>' do
|
237
|
+
before :each do
|
238
|
+
mock(Shop::Tags::Helpers).current_product(anything) { @shop_product }
|
239
|
+
end
|
240
|
+
|
241
|
+
context 'success' do
|
242
|
+
it 'should render' do
|
243
|
+
stub(@shop_product).images { @images }
|
244
|
+
|
245
|
+
tag = %{<r:shop:product:if_images>success</r:shop:product:if_images>}
|
246
|
+
expected = %{success}
|
247
|
+
pages(:home).should render(tag).as(expected)
|
248
|
+
end
|
249
|
+
end
|
250
|
+
|
251
|
+
context 'failure' do
|
252
|
+
it 'should not render' do
|
253
|
+
stub(@shop_product).images { [] }
|
254
|
+
|
255
|
+
tag = %{<r:shop:product:if_images>failure</r:shop:product:if_images>}
|
256
|
+
expected = %{}
|
257
|
+
pages(:home).should render(tag).as(expected)
|
258
|
+
end
|
259
|
+
end
|
260
|
+
end
|
261
|
+
|
262
|
+
describe '<r:shop:product:unless_images>' do
|
263
|
+
before :each do
|
264
|
+
mock(Shop::Tags::Helpers).current_product(anything) { @shop_product }
|
265
|
+
end
|
266
|
+
|
267
|
+
context 'success' do
|
268
|
+
it 'should render' do
|
269
|
+
stub(@shop_product).images { [] }
|
270
|
+
|
271
|
+
tag = %{<r:shop:product:unless_images>success</r:shop:product:unless_images>}
|
272
|
+
expected = %{success}
|
273
|
+
pages(:home).should render(tag).as(expected)
|
274
|
+
end
|
275
|
+
end
|
276
|
+
|
277
|
+
context 'failure' do
|
278
|
+
it 'should not render' do
|
279
|
+
stub(@shop_product).images { @images }
|
280
|
+
|
281
|
+
tag = %{<r:shop:product:unless_images>failure</r:shop:product:unless_images>}
|
282
|
+
expected = %{}
|
283
|
+
pages(:home).should render(tag).as(expected)
|
284
|
+
end
|
285
|
+
end
|
286
|
+
end
|
287
|
+
|
288
|
+
describe '<r:shop:product:images>' do
|
289
|
+
before :each do
|
290
|
+
mock(Shop::Tags::Helpers).current_product(anything) { @shop_product }
|
291
|
+
end
|
292
|
+
it 'should render' do
|
293
|
+
tag = %{<r:shop:product:images>success</r:shop:product:images>}
|
294
|
+
expected = %{success}
|
295
|
+
|
296
|
+
pages(:home).should render(tag).as(expected)
|
297
|
+
end
|
298
|
+
end
|
299
|
+
|
300
|
+
describe '<r:shop:product:images:each>' do
|
301
|
+
before :each do
|
302
|
+
mock(Shop::Tags::Helpers).current_product(anything) { @shop_product }
|
303
|
+
end
|
304
|
+
context 'success' do
|
305
|
+
before :each do
|
306
|
+
stub(@shop_product).images { @images }
|
307
|
+
end
|
308
|
+
it 'should render' do
|
309
|
+
tag = %{<r:shop:product:images:each>.a.</r:shop:product:images:each>}
|
310
|
+
expected = %{.a..a..a.}
|
311
|
+
|
312
|
+
pages(:home).should render(tag).as(expected)
|
313
|
+
end
|
314
|
+
it 'should assign the local image' do
|
315
|
+
tag = %{<r:shop:product:images:each><r:image:id /></r:shop:product:images:each>}
|
316
|
+
expected = %{111}
|
317
|
+
|
318
|
+
pages(:home).should render(tag).as(expected)
|
319
|
+
end
|
320
|
+
end
|
321
|
+
context 'failure' do
|
322
|
+
it 'should not render' do
|
323
|
+
stub(@shop_product).images { [] }
|
324
|
+
|
325
|
+
tag = %{<r:shop:product:images:each>failure</r:shop:product:images:each>}
|
326
|
+
expected = %{}
|
327
|
+
pages(:home).should render(tag).as(expected)
|
328
|
+
end
|
329
|
+
end
|
330
|
+
end
|
331
|
+
|
332
|
+
end
|
333
|
+
|
334
|
+
end
|