radiant-shop-extension 0.9.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (160) hide show
  1. data/.gitignore +6 -0
  2. data/Gemfile +26 -0
  3. data/Gemfile.lock +75 -0
  4. data/HISTORY.md +77 -0
  5. data/MIT-LICENSE +20 -0
  6. data/README.md +26 -0
  7. data/Rakefile +141 -0
  8. data/VERSION +1 -0
  9. data/app/.DS_Store +0 -0
  10. data/app/controllers/admin/shop/categories_controller.rb +206 -0
  11. data/app/controllers/admin/shop/customers_controller.rb +137 -0
  12. data/app/controllers/admin/shop/orders_controller.rb +171 -0
  13. data/app/controllers/admin/shop/products/images_controller.rb +144 -0
  14. data/app/controllers/admin/shop/products_controller.rb +217 -0
  15. data/app/controllers/admin/shops_controller.rb +9 -0
  16. data/app/controllers/shop/categories_controller.rb +49 -0
  17. data/app/controllers/shop/line_items_controller.rb +165 -0
  18. data/app/controllers/shop/orders_controller.rb +16 -0
  19. data/app/controllers/shop/products_controller.rb +48 -0
  20. data/app/models/form_checkout.rb +245 -0
  21. data/app/models/shop_address.rb +13 -0
  22. data/app/models/shop_addressable.rb +11 -0
  23. data/app/models/shop_category.rb +85 -0
  24. data/app/models/shop_category_page.rb +7 -0
  25. data/app/models/shop_customer.rb +27 -0
  26. data/app/models/shop_line_item.rb +32 -0
  27. data/app/models/shop_order.rb +108 -0
  28. data/app/models/shop_payment.rb +6 -0
  29. data/app/models/shop_payment_method.rb +5 -0
  30. data/app/models/shop_product.rb +87 -0
  31. data/app/models/shop_product_attachment.rb +30 -0
  32. data/app/models/shop_product_page.rb +7 -0
  33. data/app/views/.DS_Store +0 -0
  34. data/app/views/admin/.DS_Store +0 -0
  35. data/app/views/admin/pages/_shop_category.html.haml +4 -0
  36. data/app/views/admin/pages/_shop_product.html.haml +4 -0
  37. data/app/views/admin/shop/categories/edit.html.haml +12 -0
  38. data/app/views/admin/shop/categories/edit/_fields.html.haml +28 -0
  39. data/app/views/admin/shop/categories/edit/_head.html.haml +2 -0
  40. data/app/views/admin/shop/categories/edit/_meta.html.haml +7 -0
  41. data/app/views/admin/shop/categories/edit/_part.html.haml +3 -0
  42. data/app/views/admin/shop/categories/edit/_popup.html.haml +3 -0
  43. data/app/views/admin/shop/categories/edit/meta/_handle.html.haml +5 -0
  44. data/app/views/admin/shop/categories/edit/meta/_layouts.html.haml +10 -0
  45. data/app/views/admin/shop/categories/edit/parts/_description.html.haml +1 -0
  46. data/app/views/admin/shop/categories/index/_category.html.haml +16 -0
  47. data/app/views/admin/shop/categories/new.html.haml +10 -0
  48. data/app/views/admin/shop/categories/remove.html.haml +12 -0
  49. data/app/views/admin/shop/customers/index.html.haml +36 -0
  50. data/app/views/admin/shop/orders/index.html.haml +33 -0
  51. data/app/views/admin/shop/products/edit.html.haml +14 -0
  52. data/app/views/admin/shop/products/edit/_fields.html.haml +38 -0
  53. data/app/views/admin/shop/products/edit/_head.html.haml +2 -0
  54. data/app/views/admin/shop/products/edit/_image.html.haml +12 -0
  55. data/app/views/admin/shop/products/edit/_meta.html.haml +8 -0
  56. data/app/views/admin/shop/products/edit/_part.html.haml +3 -0
  57. data/app/views/admin/shop/products/edit/_popup.html.haml +3 -0
  58. data/app/views/admin/shop/products/edit/buttons/_browse_images.html.haml +1 -0
  59. data/app/views/admin/shop/products/edit/buttons/_new_image.html.haml +1 -0
  60. data/app/views/admin/shop/products/edit/meta/_category.html.haml +5 -0
  61. data/app/views/admin/shop/products/edit/meta/_sku.html.haml +5 -0
  62. data/app/views/admin/shop/products/edit/parts/_description.html.haml +1 -0
  63. data/app/views/admin/shop/products/edit/parts/_images.html.haml +5 -0
  64. data/app/views/admin/shop/products/edit/popups/_browse_images.html.haml +6 -0
  65. data/app/views/admin/shop/products/edit/popups/_new_image.html.haml +18 -0
  66. data/app/views/admin/shop/products/index.html.haml +10 -0
  67. data/app/views/admin/shop/products/index/_bottom.html.haml +5 -0
  68. data/app/views/admin/shop/products/index/_product.html.haml +13 -0
  69. data/app/views/admin/shop/products/new.html.haml +10 -0
  70. data/app/views/admin/shop/products/remove.html.haml +12 -0
  71. data/app/views/shop/categories/show.html.haml +1 -0
  72. data/app/views/shop/orders/show.html.haml +1 -0
  73. data/app/views/shop/products/index.html.haml +1 -0
  74. data/app/views/shop/products/show.html.haml +1 -0
  75. data/config/locales/en.yml +50 -0
  76. data/config/routes.rb +38 -0
  77. data/config/shop_cart.yml +16 -0
  78. data/cucumber.yml +1 -0
  79. data/db/migrate/20100311053701_initial.rb +153 -0
  80. data/db/migrate/20100520033059_create_layouts.rb +119 -0
  81. data/db/migrate/20100903122123_create_forms.rb +44 -0
  82. data/db/migrate/20100908063639_create_snippets.rb +22 -0
  83. data/features/support/env.rb +16 -0
  84. data/features/support/paths.rb +14 -0
  85. data/lib/shop/controllers/application_controller.rb +39 -0
  86. data/lib/shop/controllers/site_controller.rb +12 -0
  87. data/lib/shop/interface/products.rb +49 -0
  88. data/lib/shop/models/image.rb +14 -0
  89. data/lib/shop/models/page.rb +14 -0
  90. data/lib/shop/tags/address.rb +40 -0
  91. data/lib/shop/tags/cart.rb +49 -0
  92. data/lib/shop/tags/category.rb +83 -0
  93. data/lib/shop/tags/core.rb +12 -0
  94. data/lib/shop/tags/helpers.rb +142 -0
  95. data/lib/shop/tags/item.rb +109 -0
  96. data/lib/shop/tags/product.rb +109 -0
  97. data/lib/shop/tags/responses.rb +34 -0
  98. data/lib/tasks/shop_extension_tasks.rake +54 -0
  99. data/mockups/balsamiq/products-retro_fun_tshirt-more.bmml +0 -0
  100. data/mockups/balsamiq/products-retro_fun_tshirt.bmml +0 -0
  101. data/public/images/admin/extensions/shop/products/sort.png +0 -0
  102. data/public/javascripts/admin/extensions/shop/products/edit.js +115 -0
  103. data/public/javascripts/admin/extensions/shop/products/index.js +65 -0
  104. data/public/stylesheets/sass/admin/extensions/shop/edit.sass +86 -0
  105. data/public/stylesheets/sass/admin/extensions/shop/products/edit.sass +158 -0
  106. data/public/stylesheets/sass/admin/extensions/shop/products/index.sass +129 -0
  107. data/radiant-shop-extension.gemspec +245 -0
  108. data/shop_extension.rb +62 -0
  109. data/spec/controllers/admin/shop/categories_controller_spec.rb +443 -0
  110. data/spec/controllers/admin/shop/products/images_controller_spec.rb +477 -0
  111. data/spec/controllers/admin/shop/products_controller_spec.rb +394 -0
  112. data/spec/controllers/admin/shops_controller_spec.rb +19 -0
  113. data/spec/controllers/shop/categories_controller_spec.rb +42 -0
  114. data/spec/controllers/shop/line_items_controller_spec.rb +256 -0
  115. data/spec/controllers/shop/orders_controller_specs.rb +37 -0
  116. data/spec/controllers/shop/products_controller_spec.rb +51 -0
  117. data/spec/datasets/forms.rb +153 -0
  118. data/spec/datasets/images.rb +13 -0
  119. data/spec/datasets/shop_addresses.rb +27 -0
  120. data/spec/datasets/shop_categories.rb +13 -0
  121. data/spec/datasets/shop_line_items.rb +9 -0
  122. data/spec/datasets/shop_orders.rb +21 -0
  123. data/spec/datasets/shop_products.rb +34 -0
  124. data/spec/helpers/nested_tag_helper.rb +33 -0
  125. data/spec/lib/shop/models/image_spec.rb +28 -0
  126. data/spec/lib/shop/models/page_spec.rb +38 -0
  127. data/spec/lib/shop/tags/address_spec.rb +196 -0
  128. data/spec/lib/shop/tags/cart_spec.rb +169 -0
  129. data/spec/lib/shop/tags/category_spec.rb +201 -0
  130. data/spec/lib/shop/tags/core_spec.rb +16 -0
  131. data/spec/lib/shop/tags/helpers_spec.rb +381 -0
  132. data/spec/lib/shop/tags/item_spec.rb +313 -0
  133. data/spec/lib/shop/tags/product_spec.rb +334 -0
  134. data/spec/matchers/comparison.rb +72 -0
  135. data/spec/matchers/render_matcher.rb +33 -0
  136. data/spec/models/form_checkout_spec.rb +376 -0
  137. data/spec/models/shop_category_page_spec.rb +10 -0
  138. data/spec/models/shop_category_spec.rb +58 -0
  139. data/spec/models/shop_line_item_spec.rb +42 -0
  140. data/spec/models/shop_order_spec.rb +228 -0
  141. data/spec/models/shop_product_attachment_spec.rb +72 -0
  142. data/spec/models/shop_product_page_spec.rb +10 -0
  143. data/spec/models/shop_product_spec.rb +135 -0
  144. data/spec/spec.opts +6 -0
  145. data/spec/spec_helper.rb +22 -0
  146. data/vendor/plugins/acts_as_list/README +23 -0
  147. data/vendor/plugins/acts_as_list/init.rb +3 -0
  148. data/vendor/plugins/acts_as_list/lib/active_record/acts/list.rb +256 -0
  149. data/vendor/plugins/acts_as_list/test/list_test.rb +332 -0
  150. data/vendor/plugins/json_fields/.gitignore +3 -0
  151. data/vendor/plugins/json_fields/MIT-LICENSE +20 -0
  152. data/vendor/plugins/json_fields/README.rdoc +65 -0
  153. data/vendor/plugins/json_fields/Rakefile +55 -0
  154. data/vendor/plugins/json_fields/init.rb +2 -0
  155. data/vendor/plugins/json_fields/lib/json_fields.rb +99 -0
  156. data/vendor/plugins/json_fields/spec/lib/json_fields_spec.rb +124 -0
  157. data/vendor/plugins/json_fields/spec/spec.opts +6 -0
  158. data/vendor/plugins/json_fields/spec/spec_helper.rb +29 -0
  159. data/vendor/plugins/json_fields/spec/test_models.rb +12 -0
  160. metadata +324 -0
@@ -0,0 +1,201 @@
1
+ require 'spec/spec_helper'
2
+
3
+ describe Shop::Tags::Category do
4
+
5
+ dataset :pages
6
+
7
+ before(:each) do
8
+ category = Object.new
9
+ stub(category).id { 1 }
10
+
11
+ @shop_category = category
12
+ @shop_categories = [ category, category, category ]
13
+
14
+ product = Object.new
15
+ stub(product).id { 1 }
16
+
17
+ @shop_product = product
18
+ @shop_products = [ product, product, product ]
19
+ end
20
+
21
+ describe '<r:shop:if_categories>' do
22
+ context 'success' do
23
+ it 'should render' do
24
+ mock(Shop::Tags::Helpers).current_categories(anything) { @shop_categories }
25
+
26
+ tag = %{<r:shop:if_categories>success</r:shop:if_categories>}
27
+ expected = %{success}
28
+
29
+ pages(:home).should render(tag).as(expected)
30
+ end
31
+ end
32
+ context 'failure' do
33
+ it 'should not render' do
34
+ mock(Shop::Tags::Helpers).current_categories(anything) { [] }
35
+
36
+ tag = %{<r:shop:if_categories>failure</r:shop:if_categories>}
37
+ expected = %{}
38
+ pages(:home).should render(tag).as(expected)
39
+ end
40
+ end
41
+ end
42
+
43
+ describe '<r:shop:unless_categories>' do
44
+ context 'success' do
45
+ it 'should render' do
46
+ mock(Shop::Tags::Helpers).current_categories(anything) { [] }
47
+
48
+ tag = %{<r:shop:unless_categories>success</r:shop:unless_categories>}
49
+ expected = %{success}
50
+ pages(:home).should render(tag).as(expected)
51
+ end
52
+ end
53
+ context 'failure' do
54
+ it 'should not render' do
55
+ mock(Shop::Tags::Helpers).current_categories(anything) { @shop_products }
56
+
57
+ tag = %{<r:shop:unless_categories>failure</r:shop:unless_categories>}
58
+ expected = %{}
59
+ pages(:home).should render(tag).as(expected)
60
+ end
61
+ end
62
+ end
63
+
64
+ describe '<r:shop:categories>' do
65
+ it 'should render' do
66
+ mock(Shop::Tags::Helpers).current_categories(anything) { @shop_categories }
67
+ tag = %{<r:shop:categories>success</r:shop:categories>}
68
+ expected = %{success}
69
+
70
+ pages(:home).should render(tag).as(expected)
71
+ end
72
+ end
73
+
74
+ describe '<r:shop:category:if_current>' do
75
+ before :each do
76
+ mock(Shop::Tags::Helpers).current_category(anything) { @shop_category }
77
+ stub(@shop_category).id { 1 }
78
+ stub(@shop_category).handle { 'handle' }
79
+ end
80
+ context 'generated page' do
81
+ it 'should expand' do
82
+ page = pages(:home)
83
+ stub(page).slug { @shop_category.handle }
84
+
85
+ tag = %{<r:shop:category:if_current>success</r:shop:category:if_current>}
86
+ expected = %{success}
87
+
88
+ page.should render(tag).as(expected)
89
+ end
90
+ end
91
+ context 'custom page' do
92
+ it 'should expand' do
93
+ page = pages(:home)
94
+ stub(page).shop_category_id { @shop_category.id }
95
+
96
+ tag = %{<r:shop:category:if_current>success</r:shop:category:if_current>}
97
+ expected = %{success}
98
+
99
+ page.should render(tag).as(expected)
100
+ end
101
+ end
102
+ context 'product page' do
103
+ it 'should expand' do
104
+ mock(Shop::Tags::Helpers).current_product(anything) { @shop_product }
105
+ stub(@shop_product).category { @shop_category }
106
+
107
+ tag = %{<r:shop:product><r:category:if_current>success</r:category:if_current></r:shop:product>}
108
+ expected = %{success}
109
+
110
+ pages(:home).should render(tag).as(expected)
111
+ end
112
+ end
113
+ context 'failure' do
114
+ it 'should not expand' do
115
+ tag = %{<r:shop:category:if_current>failure</r:shop:category:if_current>}
116
+ expected = %{}
117
+
118
+ pages(:home).should render(tag).as(expected)
119
+ end
120
+ end
121
+ end
122
+
123
+ describe 'simple attributes' do
124
+ before :each do
125
+ mock(Shop::Tags::Helpers).current_category(anything) { @shop_category }
126
+ end
127
+ it 'should render <r:id />' do
128
+ stub(@shop_category).id { 1 }
129
+
130
+ tag = %{<r:shop:category:id />}
131
+ expected = %{1}
132
+ pages(:home).should render(tag).as(expected)
133
+ end
134
+ it 'should render <r:name />' do
135
+ stub(@shop_category).name { 'name' }
136
+
137
+ tag = %{<r:shop:category:name />}
138
+ expected = %{name}
139
+ pages(:home).should render(tag).as(expected)
140
+ end
141
+ it 'should render <r:handle />' do
142
+ stub(@shop_category).handle { 'handle' }
143
+
144
+ tag = %{<r:shop:category:handle />}
145
+ expected = %{handle}
146
+ pages(:home).should render(tag).as(expected)
147
+ end
148
+ it 'should render <r:slug />' do
149
+ stub(@shop_category).slug { 'slug' }
150
+
151
+ tag = %{<r:shop:category:slug />}
152
+ expected = %{slug}
153
+ pages(:home).should render(tag).as(expected)
154
+ end
155
+ end
156
+
157
+ describe '<r:description />' do
158
+ it 'should render a textile filtered result' do
159
+ mock(Shop::Tags::Helpers).current_category(anything) { @shop_category }
160
+ stub(@shop_category).description { '*bold*' }
161
+
162
+ tag = %{<r:shop:category:description />}
163
+ expected = %{<p><strong>bold</strong></p>}
164
+ pages(:home).should render(tag).as(expected)
165
+ end
166
+ end
167
+
168
+ describe '<r:link />' do
169
+ before :each do
170
+ mock(Shop::Tags::Helpers).current_category(anything) { @shop_category }
171
+ end
172
+
173
+ context 'standalone' do
174
+ before :each do
175
+ stub(@shop_category).slug { 'slug' }
176
+ stub(@shop_category).name { 'name' }
177
+ end
178
+ it 'should render an anchor element' do
179
+ tag = %{<r:shop:category:link />}
180
+ expected = %{<a href="slug">name</a>}
181
+ pages(:home).should render(tag).as(expected)
182
+ end
183
+ it 'should assign attributes' do
184
+ tag = %{<r:shop:category:link title="title" data-title="data-title"/>}
185
+ expected = %{<a href="slug" data-title="data-title" title="title">name</a>}
186
+ pages(:home).should render(tag).as(expected)
187
+ end
188
+ end
189
+
190
+ context 'wrapped' do
191
+ it 'should render an anchor element' do
192
+ stub(@shop_category).slug { 'slug' }
193
+
194
+ tag = %{<r:shop:category:link>title</r:shop:category:link>}
195
+ expected = %{<a href="slug">title</a>}
196
+ pages(:home).should render(tag).as(expected)
197
+ end
198
+ end
199
+ end
200
+
201
+ end
@@ -0,0 +1,16 @@
1
+ require 'spec/spec_helper'
2
+
3
+ describe Shop::Tags::Core do
4
+
5
+ dataset :pages
6
+
7
+ describe '<r:shop>' do
8
+ it 'should render' do
9
+ tag = %{<r:shop>success</r:shop>}
10
+ expected = %{success}
11
+
12
+ pages(:home).should render(tag).as(expected)
13
+ end
14
+ end
15
+
16
+ end
@@ -0,0 +1,381 @@
1
+ require 'spec/spec_helper'
2
+
3
+ describe Shop::Tags::Helpers do
4
+
5
+ dataset :pages
6
+
7
+ before :all do
8
+ @page = pages(:home)
9
+ end
10
+
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 }
40
+ end
41
+
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
+
50
+ result = Shop::Tags::Helpers.current_categories(@tag)
51
+ result.should == @shop_categories
52
+ end
53
+ end
54
+
55
+ context 'key => value' do
56
+ 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
+ result = Shop::Tags::Helpers.current_categories(@tag)
65
+ result.should == @shop_categories
66
+ end
67
+ end
68
+
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
+
76
+ result = Shop::Tags::Helpers.current_categories(@tag)
77
+ result.should == @shop_categories
78
+ end
79
+ end
80
+ end
81
+
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
+
99
+ result = Shop::Tags::Helpers.current_category(@tag)
100
+ result.should == @shop_category
101
+ end
102
+ 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
+
107
+ result = Shop::Tags::Helpers.current_category(@tag)
108
+ result.should == @shop_category
109
+ end
110
+ 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
+
116
+ result = Shop::Tags::Helpers.current_category(@tag)
117
+ result.should == @shop_category
118
+ end
119
+ end
120
+ context 'tag.locals.shop_category' do
121
+ it 'should return the matching category' do
122
+ stub(@locals).shop_category { @shop_category }
123
+
124
+ result = Shop::Tags::Helpers.current_category(@tag)
125
+ result.should == @shop_category
126
+ end
127
+ 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
+
135
+ 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
+
150
+ result = Shop::Tags::Helpers.current_category(@tag)
151
+ result.should == @shop_category
152
+ end
153
+ end
154
+ 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
+
161
+ result = Shop::Tags::Helpers.current_products(@tag)
162
+ result.should == @shop_products
163
+ end
164
+ end
165
+ context 'search query' do
166
+ 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
+ result = Shop::Tags::Helpers.current_products(@tag)
173
+ result.should == @shop_products
174
+ end
175
+ end
176
+ context 'key => value' do
177
+ 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
+ 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
224
+ end
225
+ end
226
+ end
227
+
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
+
245
+ result = Shop::Tags::Helpers.current_product(@tag)
246
+ result.should == @shop_product
247
+ end
248
+ 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
+
254
+ result = Shop::Tags::Helpers.current_product(@tag)
255
+ result.should == @shop_product
256
+ end
257
+ 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
+
276
+ result = Shop::Tags::Helpers.current_product(@tag)
277
+ result.should == @shop_product
278
+ end
279
+ end
280
+ end
281
+
282
+ describe '#current_order(tag)' do
283
+ context 'existing order' do
284
+ it 'should return the order' do
285
+ stub(@locals).shop_order { @shop_order }
286
+
287
+ result = Shop::Tags::Helpers.current_order(@tag)
288
+ result.should == @shop_order
289
+ end
290
+ 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
+
299
+ result = Shop::Tags::Helpers.current_order(@tag)
300
+ result.should == @shop_order
301
+ end
302
+ 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
+
311
+ result = Shop::Tags::Helpers.current_order(@tag)
312
+ result.should == @shop_order
313
+ end
314
+ end
315
+ end
316
+
317
+ describe '#current_line_item(tag)' do
318
+ context 'existing line item' do
319
+ it 'should return the line item' do
320
+ stub(@locals).shop_line_item { @shop_line_item }
321
+
322
+ result = Shop::Tags::Helpers.current_line_item(@tag)
323
+ result.should == @shop_line_item
324
+ end
325
+ 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
+
336
+ result = Shop::Tags::Helpers.current_line_item(@tag)
337
+ result.should == @shop_line_item
338
+ end
339
+ end
340
+ end
341
+
342
+ describe '#current_address(tag)' do
343
+ before :each do
344
+ @attrs['type'] = 'billing'
345
+ end
346
+ context 'address exists' do
347
+ 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
370
+ 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
+ result = Shop::Tags::Helpers.current_address(@tag)
376
+ result.should == nil
377
+ end
378
+ end
379
+ end
380
+
381
+ end