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
@@ -18,6 +18,7 @@ describe Shop::Tags::Item do
18
18
  'shop:cart:item:id',
19
19
  'shop:cart:item:quantity',
20
20
  'shop:cart:item:name',
21
+ 'shop:cart:item:sku',
21
22
  'shop:cart:item:link',
22
23
  'shop:cart:item:price',
23
24
  'shop:cart:item:weight',
@@ -204,6 +205,14 @@ describe Shop::Tags::Item do
204
205
 
205
206
  @page.should render(tag).as(expected)
206
207
  end
208
+ it 'should render <r:sku />' do
209
+ stub(@shop_line_item).item.stub!.sku { 'sku' }
210
+
211
+ tag = %{<r:shop:cart:item:sku />}
212
+ expected = %{sku}
213
+
214
+ @page.should render(tag).as(expected)
215
+ end
207
216
  it 'should render <r:weight />' do
208
217
  stub(@shop_line_item).item.stub!.weight { 100 }
209
218
 
@@ -2,7 +2,7 @@ require 'spec/spec_helper'
2
2
 
3
3
  describe Shop::Tags::Product do
4
4
 
5
- dataset :pages
5
+ dataset :pages, :shop_products
6
6
 
7
7
  it 'should describe these tags' do
8
8
  Shop::Tags::Product.tags.sort.should == [
@@ -18,313 +18,327 @@ describe Shop::Tags::Product do
18
18
  'shop:product:slug',
19
19
  'shop:product:description',
20
20
  'shop:product:link',
21
- 'shop:product:if_images',
22
- 'shop:product:unless_images',
23
21
  'shop:product:images',
22
+ 'shop:product:images:if_images',
23
+ 'shop:product:images:unless_images',
24
24
  'shop:product:images:each'].sort
25
25
  end
26
+
27
+ before :all do
28
+ @page = pages(:home)
29
+ end
26
30
 
27
31
  before(:each) do
28
- product = Object.new
29
- stub(product).id { 1 }
30
-
31
- @shop_product = product
32
- @shop_products = [ product, product, product ]
32
+ @product = shop_products(:soft_bread)
33
+ @products = [ shop_products(:soft_bread), shop_products(:crusty_bread) ]
33
34
 
34
- image = Object.new
35
- stub(image).id { 1 }
36
-
37
- @image = image
38
- @images = [ image, image, image ]
35
+ @image = images(:soft_bread_front)
36
+ @images = [ images(:soft_bread_front), images(:soft_bread_back), images(:soft_bread_top) ]
39
37
  end
40
38
 
41
39
  describe '<r:shop:if_products>' do
42
40
  context 'success' do
41
+ before :each do
42
+ mock(Shop::Tags::Helpers).current_products(anything) { @products }
43
+ end
44
+
43
45
  it 'should render' do
44
- mock(Shop::Tags::Helpers).current_products(anything) { @shop_products }
45
-
46
46
  tag = %{<r:shop:if_products>success</r:shop:if_products>}
47
- expected = %{success}
48
- pages(:home).should render(tag).as(expected)
47
+ exp = %{success}
48
+ @page.should render(tag).as(exp)
49
49
  end
50
50
  end
51
+
51
52
  context 'failure' do
52
- it 'should not render' do
53
+ before :each do
53
54
  mock(Shop::Tags::Helpers).current_products(anything) { [] }
54
-
55
+ end
56
+
57
+ it 'should not render' do
55
58
  tag = %{<r:shop:if_products>failure</r:shop:if_products>}
56
- expected = %{}
57
- pages(:home).should render(tag).as(expected)
59
+ exp = %{}
60
+ @page.should render(tag).as(exp)
58
61
  end
59
62
  end
60
63
  end
61
64
 
62
65
  describe '<r:shop:unless_products>' do
63
66
  context 'success' do
64
- it 'should render' do
67
+ before :each do
65
68
  mock(Shop::Tags::Helpers).current_products(anything) { [] }
66
-
69
+ end
70
+
71
+ it 'should render' do
67
72
  tag = %{<r:shop:unless_products>success</r:shop:unless_products>}
68
- expected = %{success}
69
- pages(:home).should render(tag).as(expected)
73
+ exp = %{success}
74
+ @page.should render(tag).as(exp)
70
75
  end
71
76
  end
77
+
72
78
  context 'failure' do
79
+ before :each do
80
+ mock(Shop::Tags::Helpers).current_products(anything) { @products }
81
+ end
82
+
73
83
  it 'should not render' do
74
- mock(Shop::Tags::Helpers).current_products(anything) { @shop_products }
75
-
76
84
  tag = %{<r:shop:unless_products>failure</r:shop:unless_products>}
77
- expected = %{}
78
- pages(:home).should render(tag).as(expected)
85
+ exp = %{}
86
+ @page.should render(tag).as(exp)
79
87
  end
80
88
  end
81
89
  end
82
90
 
83
91
  describe '<r:shop:products>' do
84
- it 'should render' do
85
- tag = %{<r:shop:products>success</r:shop:products>}
86
- expected = %{success}
92
+ context 'no products exist' do
93
+ before :each do
94
+ mock(Shop::Tags::Helpers).current_products(anything) { [] }
95
+ end
96
+
97
+ it 'should render' do
98
+ tag = %{<r:shop:products>success</r:shop:products>}
99
+ exp = %{success}
100
+
101
+ @page.should render(tag).as(exp)
102
+ end
103
+ end
104
+
105
+ context 'products exist' do
106
+ before :each do
107
+ mock(Shop::Tags::Helpers).current_products(anything) { @products }
108
+ end
87
109
 
88
- pages(:home).should render(tag).as(expected)
110
+ it 'should render' do
111
+ tag = %{<r:shop:products>success</r:shop:products>}
112
+ exp = %{success}
113
+
114
+ @page.should render(tag).as(exp)
115
+ end
89
116
  end
90
117
  end
91
118
 
92
119
  describe '<r:shop:products:each>' do
93
120
  context 'success' do
121
+ before :each do
122
+ mock(Shop::Tags::Helpers).current_products(anything) { @products }
123
+ end
124
+
94
125
  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)
126
+ tag = %{<r:shop:products:each><r:product:id /></r:shop:products:each>}
127
+ exp = @products.map{ |p| p.id }.join('')
128
+ @page.should render(tag).as(exp)
100
129
  end
101
130
  end
131
+
102
132
  context 'failure' do
103
- it 'should not render' do
133
+ before :each do
104
134
  mock(Shop::Tags::Helpers).current_products(anything) { [] }
105
-
135
+ end
136
+
137
+ it 'should not render' do
106
138
  tag = %{<r:shop:products:each>failure</r:shop:products:each>}
107
- expected = %{}
108
- pages(:home).should render(tag).as(expected)
139
+ exp = %{}
140
+ @page.should render(tag).as(exp)
109
141
  end
110
142
  end
111
143
  end
112
144
 
113
145
  describe '<r:shop:product>' do
114
- context 'success' do
146
+ context 'product exists in the context' do
147
+ before :each do
148
+ mock(Shop::Tags::Helpers).current_product(anything) { @products }
149
+ end
150
+
115
151
  it 'should render' do
116
- mock(Shop::Tags::Helpers).current_product(anything) { @shop_product }
117
-
118
152
  tag = %{<r:shop:product>success</r:shop:product>}
119
- expected = %{success}
120
- pages(:home).should render(tag).as(expected)
153
+ exp = %{success}
154
+ @page.should render(tag).as(exp)
121
155
  end
122
156
  end
123
- context 'failure' do
157
+
158
+ context 'product does not exist in the context' do
159
+ before :each do
160
+ mock(Shop::Tags::Helpers).current_product(anything) { [] }
161
+ end
162
+
124
163
  it 'should not render' do
125
- mock(Shop::Tags::Helpers).current_product(anything) { nil }
126
-
127
164
  tag = %{<r:shop:product>failure</r:shop:product>}
128
- expected = %{}
129
- pages(:home).should render(tag).as(expected)
165
+ exp = %{}
166
+ @page.should render(tag).as(exp)
130
167
  end
131
168
  end
132
169
 
133
- describe 'simple attributes' do
170
+ context '#attributes' do
134
171
  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)
172
+ mock(Shop::Tags::Helpers).current_product(anything) { @product }
164
173
  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)
174
+
175
+ describe '<r:id />' do
176
+ it 'should render the product id' do
177
+ tag = %{<r:shop:product:id />}
178
+ exp = @product.id.to_s
179
+ @page.should render(tag).as(exp)
180
+ end
181
+ end
182
+ describe '<r:name />' do
183
+ it 'should render the product name' do
184
+ tag = %{<r:shop:product:name />}
185
+ exp = @product.name
186
+ @page.should render(tag).as(exp)
187
+ end
188
+ end
189
+ describe '<r:sku />' do
190
+ it 'should render the product sku' do
191
+ tag = %{<r:shop:product:sku />}
192
+ exp = @product.sku
193
+ @page.should render(tag).as(exp)
194
+ end
195
+ end
196
+ describe '<r:slug />' do
197
+ it 'should render the product slug' do
198
+ tag = %{<r:shop:product:slug />}
199
+ exp = @product.slug
200
+ @page.should render(tag).as(exp)
201
+ end
202
+ end
203
+ describe '<r:description />' do
204
+ it 'should render a textile filtered description' do
205
+ tag = %{<r:shop:product:description />}
206
+ exp = TextileFilter.filter(@product.description)
207
+ @page.should render(tag).as(exp)
208
+ end
175
209
  end
176
210
  end
177
211
 
178
212
  describe '<r:link />' do
179
213
  before :each do
180
- mock(Shop::Tags::Helpers).current_product(anything) { @shop_product }
214
+ mock(Shop::Tags::Helpers).current_product(anything) { @product }
181
215
  end
182
216
 
183
217
  context 'standalone' do
184
- before :each do
185
- stub(@shop_product).slug { 'slug' }
186
- stub(@shop_product).name { 'name' }
187
- end
188
218
  it 'should render an anchor element' do
189
219
  tag = %{<r:shop:product:link />}
190
- expected = %{<a href="slug">name</a>}
191
- pages(:home).should render(tag).as(expected)
220
+ exp = %{<a href="#{@product.slug}">#{@product.name}</a>}
221
+ @page.should render(tag).as(exp)
192
222
  end
193
223
  it 'should assign attributes' do
194
224
  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)
225
+ exp = %{<a href="#{@product.slug}" data-title="data-title" title="title">#{@product.name}</a>}
226
+ @page.should render(tag).as(exp)
197
227
  end
198
228
  end
199
229
 
200
230
  context 'wrapped' do
201
231
  it 'should render an anchor element' do
202
- stub(@shop_product).slug { 'slug' }
203
-
204
232
  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)
233
+ exp = %{<a href="#{@product.slug}">title</a>}
234
+ @page.should render(tag).as(exp)
207
235
  end
208
236
  end
209
237
  end
210
238
 
211
239
  describe '<r:price />' do
212
240
  before :each do
213
- mock(Shop::Tags::Helpers).current_product(anything) { @shop_product }
214
- stub(@shop_product).price { 1234.34567890 }
241
+ mock(Shop::Tags::Helpers).current_product(anything) { @product }
242
+ stub(@product).price { 1234.34567890 }
215
243
  end
216
244
 
217
245
  it 'should render a standard price' do
218
246
  tag = %{<r:shop:product:price />}
219
- expected = %{$1,234.35}
220
- pages(:home).should render(tag).as(expected)
247
+ exp = %{$1,234.35}
248
+ @page.should render(tag).as(exp)
221
249
  end
222
250
 
223
251
  it 'should render a high precision price' do
224
252
  tag = %{<r:shop:product:price precision="8"/>}
225
- expected = %{$1,234.34567890}
226
- pages(:home).should render(tag).as(expected)
253
+ exp = %{$1,234.34567890}
254
+ @page.should render(tag).as(exp)
227
255
  end
228
256
 
229
257
  it 'should render a custom format' do
230
258
  tag = %{<r:shop:product:price unit="%" separator="-" delimiter="+" />}
231
- expected = %{%1+234-35}
232
- pages(:home).should render(tag).as(expected)
259
+ exp = %{%1+234-35}
260
+ @page.should render(tag).as(exp)
233
261
  end
234
262
  end
235
263
 
236
- describe '<r:shop:product:if_images>' do
264
+ describe '<r:shop:product:images:if_images>' do
237
265
  before :each do
238
- mock(Shop::Tags::Helpers).current_product(anything) { @shop_product }
266
+ mock(Shop::Tags::Helpers).current_product(anything) { @product }
239
267
  end
240
268
 
241
269
  context 'success' do
242
270
  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)
271
+ tag = %{<r:shop:product:images:if_images>success</r:shop:product:images:if_images>}
272
+ exp = %{success}
273
+ @page.should render(tag).as(exp)
248
274
  end
249
275
  end
250
-
251
276
  context 'failure' do
252
277
  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)
278
+ @product.images.delete_all
279
+
280
+ tag = %{<r:shop:product:images:if_images>failure</r:shop:product:images:if_images>}
281
+ exp = %{}
282
+ @page.should render(tag).as(exp)
258
283
  end
259
284
  end
260
285
  end
261
286
 
262
- describe '<r:shop:product:unless_images>' do
287
+ describe '<r:shop:product:images:unless_images>' do
263
288
  before :each do
264
- mock(Shop::Tags::Helpers).current_product(anything) { @shop_product }
289
+ mock(Shop::Tags::Helpers).current_product(anything) { @product }
265
290
  end
266
291
 
267
292
  context 'success' do
268
293
  it 'should render' do
269
- stub(@shop_product).images { [] }
294
+ @product.images.delete_all
270
295
 
271
- tag = %{<r:shop:product:unless_images>success</r:shop:product:unless_images>}
272
- expected = %{success}
273
- pages(:home).should render(tag).as(expected)
296
+ tag = %{<r:shop:product:images:unless_images>success</r:shop:product:images:unless_images>}
297
+ exp = %{success}
298
+ @page.should render(tag).as(exp)
274
299
  end
275
300
  end
276
301
 
277
302
  context 'failure' do
278
303
  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)
304
+ tag = %{<r:shop:product:images:unless_images>failure</r:shop:product:images:unless_images>}
305
+ exp = %{}
306
+ @page.should render(tag).as(exp)
284
307
  end
285
308
  end
286
309
  end
287
310
 
288
311
  describe '<r:shop:product:images>' do
289
312
  before :each do
290
- mock(Shop::Tags::Helpers).current_product(anything) { @shop_product }
313
+ mock(Shop::Tags::Helpers).current_product(anything) { @product }
291
314
  end
315
+
292
316
  it 'should render' do
293
317
  tag = %{<r:shop:product:images>success</r:shop:product:images>}
294
- expected = %{success}
295
-
296
- pages(:home).should render(tag).as(expected)
318
+ exp = %{success}
319
+ @page.should render(tag).as(exp)
297
320
  end
298
321
  end
299
322
 
300
323
  describe '<r:shop:product:images:each>' do
301
324
  before :each do
302
- mock(Shop::Tags::Helpers).current_product(anything) { @shop_product }
325
+ mock(Shop::Tags::Helpers).current_product(anything) { @product }
303
326
  end
327
+
304
328
  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
329
+ it 'should assign the local image for each' do
315
330
  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)
331
+ exp = @product.attachments.map{ |i| i.id }.join('')
332
+ @page.should render(tag).as(exp)
319
333
  end
320
334
  end
321
335
  context 'failure' do
322
336
  it 'should not render' do
323
- stub(@shop_product).images { [] }
337
+ @product.images.delete_all
324
338
 
325
339
  tag = %{<r:shop:product:images:each>failure</r:shop:product:images:each>}
326
- expected = %{}
327
- pages(:home).should render(tag).as(expected)
340
+ exp = %{}
341
+ @page.should render(tag).as(exp)
328
342
  end
329
343
  end
330
344
  end