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,72 @@
1
+ #
2
+ # Comparison module taken from:
3
+ # http://gist.github.com/raw/474363/c5382272965f4653b7f9b9f9a8ec8968818aa141/comparison.rb
4
+ #
5
+ class Comparison
6
+ @@window = 64
7
+ @@prelude = 12
8
+
9
+ def self.window
10
+ @@window
11
+ end
12
+
13
+ def self.window=(val)
14
+ @@window = val
15
+ end
16
+
17
+ def self.prelude
18
+ @@prelude
19
+ end
20
+
21
+ def self.prelude=(val)
22
+ @@prelude = val
23
+ end
24
+
25
+ def initialize(expected, actual)
26
+ @expected = expected
27
+ @actual = actual
28
+ end
29
+
30
+ def same?
31
+ @expected == @actual
32
+ end
33
+
34
+ def different_at
35
+ if (@expected.nil? || @actual.nil?)
36
+ 0
37
+ else
38
+ i = 0
39
+ while (i < @expected.size && i < @actual.size)
40
+ if @expected[i] != @actual[i]
41
+ break
42
+ end
43
+ i += 1
44
+ end
45
+ return i
46
+ end
47
+ end
48
+
49
+ def message
50
+ "Strings differ at position #{different_at}:\n" +
51
+ "expected: #{chunk(@expected)}\n" +
52
+ " actual: #{chunk(@actual)}\n"
53
+ end
54
+
55
+ def chunk(s)
56
+ prefix, middle, suffix = "...", "", "..."
57
+
58
+ start = different_at - @@prelude
59
+ if start < 0
60
+ prefix = ""
61
+ start = 0
62
+ end
63
+
64
+ stop = start + @@window
65
+ if stop > s.size
66
+ suffix = ""
67
+ stop = s.size
68
+ end
69
+
70
+ [prefix, s[start...stop].inspect, suffix].join
71
+ end
72
+ end
@@ -0,0 +1,33 @@
1
+ #
2
+ # render(tag) might compare two very large strings, with lots of whitespace
3
+ # differences which would be hard to diagnose. So use the Comparison module to
4
+ # zero in on the bug.
5
+ #
6
+ module Spec::Rails::Matchers
7
+ class RenderTags
8
+
9
+ # Guard against double definitions
10
+ unless method_defined?(:_old_matches?)
11
+ alias_method :_old_matches?, :matches?
12
+ alias_method :_old_failure_message, :failure_message
13
+
14
+ # If comparison was just a straight '==' then redo the comparison
15
+ # using the comparison class, and save an error message
16
+ def matches?(page)
17
+ result = _old_matches? page
18
+ return result if result || !@expected || !@actual
19
+
20
+ comparison = Comparison.new(@expected, @actual)
21
+ @error_message = comparison.message
22
+ comparison.same?
23
+ end
24
+
25
+ # Return the error message from Comparison if it was saved
26
+ def failure_message
27
+ return @error_message unless @error_message.nil?
28
+ _old_failure_message
29
+ end
30
+ end
31
+
32
+ end
33
+ end
@@ -0,0 +1,376 @@
1
+ require 'spec/spec_helper'
2
+
3
+ describe FormCheckout do
4
+
5
+ dataset :shop_orders, :pages, :forms, :shop_addresses
6
+
7
+ before :each do
8
+ @form = forms(:checkout)
9
+ @page = pages(:home)
10
+ @order = shop_orders(:one_item)
11
+
12
+ @data = { }
13
+ @request = {
14
+ :session => {
15
+ :shop_order => @order.id
16
+ }
17
+ }
18
+
19
+ stub(@page).data { @data }
20
+ stub(@page).request { @request }
21
+ end
22
+
23
+ describe '#initialize' do
24
+ it 'should assign the instance variables' do
25
+
26
+ end
27
+ end
28
+
29
+ describe '#create' do
30
+ context 'addresses' do
31
+ context 'address configured' do
32
+ before :each do
33
+ @form[:config] = {
34
+ :checkout => {
35
+ :address => {
36
+ :enabled => true
37
+ }
38
+ }
39
+ }
40
+ end
41
+ context 'sending ids' do
42
+ context 'both billing and shipping' do
43
+ it 'should assign that address to the order billing and shipping' do
44
+ @data = {
45
+ 'billing' => { 'id' => shop_addresses(:billing).id },
46
+ 'shipping' => { 'id' => shop_addresses(:shipping).id }
47
+ }
48
+
49
+ @checkout = FormCheckout.new(@form, @page)
50
+ @checkout.create
51
+
52
+ shop_orders(:one_item).billing.should === shop_addresses(:billing)
53
+ shop_orders(:one_item).shipping.should === shop_addresses(:shipping)
54
+ end
55
+ end
56
+ context 'just billing' do
57
+ it 'should assign shipping to be billing' do
58
+ @data = {
59
+ 'billing' => { 'id' => shop_addresses(:billing).id }
60
+ }
61
+
62
+ @checkout = FormCheckout.new(@form, @page)
63
+ @checkout.create
64
+
65
+ shop_orders(:one_item).billing.should === shop_addresses(:billing)
66
+ shop_orders(:one_item).shipping.should === shop_addresses(:billing)
67
+ end
68
+ end
69
+ end
70
+
71
+ context 'existing addresses' do
72
+ it 'should keep them assigned and update them' do
73
+ shop_orders(:one_item).update_attributes({
74
+ :billing_id => shop_addresses(:billing).id,
75
+ :shipping_id => shop_addresses(:shipping).id,
76
+ })
77
+
78
+ @data = {
79
+ 'billing' => { 'name' => 'new billing' },
80
+ 'shipping' => { 'name' => 'new shipping' }
81
+ }
82
+
83
+ @checkout = FormCheckout.new(@form, @page)
84
+ @checkout.create
85
+
86
+ shop_orders(:one_item).billing.should === shop_addresses(:billing)
87
+ shop_addresses(:billing).name.should === 'new billing'
88
+ shop_orders(:one_item).shipping.should=== shop_addresses(:shipping)
89
+ shop_addresses(:shipping).name.should === 'new shipping'
90
+ end
91
+ end
92
+
93
+ context 'new addresses' do
94
+ context 'both billing and shipping sent' do
95
+ it 'should create new addresses' do
96
+ @data = {
97
+ 'billing' => { 'name' => 'b_n', 'email' => 'b_e', 'street' => 'b_s', 'city' => 'b_c', 'state' => 'b_s', 'country' => 'b_c', 'postcode' => 'b_p' },
98
+ 'shipping' => { 'name' => 's_n', 'email' => 's_e', 'street' => 's_s', 'city' => 's_c', 'state' => 's_s', 'country' => 's_c', 'postcode' => 's_p' }
99
+ }
100
+
101
+ @checkout = FormCheckout.new(@form, @page)
102
+ @checkout.create
103
+
104
+ shop_orders(:one_item).billing.name.should === 'b_n'
105
+ shop_orders(:one_item).shipping.name.should === 's_n'
106
+ end
107
+ end
108
+ context 'only billing sent' do
109
+ it 'should copy billing to shipping' do
110
+ @data = {
111
+ 'billing' => { 'name' => 'b_n', 'email' => 'b_e', 'street' => 'b_s', 'city' => 'b_c', 'state' => 'b_s', 'country' => 'b_c', 'postcode' => 'b_p' }
112
+ }
113
+
114
+ @checkout = FormCheckout.new(@form, @page)
115
+ @checkout.create
116
+
117
+ shop_orders(:one_item).billing.name.should === 'b_n'
118
+ shop_orders(:one_item).shipping.should === shop_orders(:one_item).billing
119
+ end
120
+ end
121
+ context 'billing sent with same shipping' do
122
+ it 'should copy billing to shipping' do
123
+ @data = {
124
+ 'billing' => { 'id' => shop_addresses(:billing).id, 'name' => 'b_n', 'email' => 'b_e', 'street' => 'b_s', 'city' => 'b_c', 'state' => 'b_s', 'country' => 'b_c', 'postcode' => 'b_p' },
125
+ 'shipping' => { 'id' => shop_addresses(:billing).id, 'name' => 'b_n', 'email' => 'b_e', 'street' => 'b_s', 'city' => 'b_c', 'state' => 'b_s', 'country' => 'b_c', 'postcode' => 'b_p' }
126
+ }
127
+
128
+ @checkout = FormCheckout.new(@form, @page)
129
+ @checkout.create
130
+
131
+ shop_orders(:one_item).billing.name.should === 'b_n'
132
+ shop_orders(:one_item).shipping.should === shop_orders(:one_item).billing
133
+ end
134
+ end
135
+ end
136
+
137
+ context 'result string' do
138
+ context 'success' do
139
+ it 'should return a success string' do
140
+ @data = {
141
+ 'billing' => { 'name' => 'b_n', 'email' => 'b_e', 'street' => 'b_s', 'city' => 'b_c', 'state' => 'b_s', 'country' => 'b_c', 'postcode' => 'b_p' },
142
+ 'shipping' => { 'name' => 's_n', 'email' => 's_e', 'street' => 's_s', 'city' => 's_c', 'state' => 's_s', 'country' => 's_c', 'postcode' => 's_p' }
143
+ }
144
+
145
+ @checkout = FormCheckout.new(@form, @page)
146
+ result = @checkout.create
147
+
148
+ result[:billing][:name].should === 'b_n'
149
+ result[:shipping][:name].should === 's_n'
150
+ end
151
+ end
152
+ context 'failure' do
153
+ it 'should set false to the nil billing' do
154
+ @data = {
155
+ 'shipping' => { 'name' => 's_n', 'email' => 's_e', 'street' => 's_s', 'city' => 's_c', 'state' => 's_s', 'country' => 's_c', 'postcode' => 's_p' }
156
+ }
157
+
158
+ @checkout = FormCheckout.new(@form, @page)
159
+ result = @checkout.create
160
+
161
+ result[:billing].should === false
162
+ result[:shipping].should_not === false
163
+ end
164
+ it 'should set billing to the nil shipping' do
165
+ @data = {
166
+ 'billing' => { 'name' => 'b_n', 'email' => 'b_e', 'street' => 'b_s', 'city' => 'b_c', 'state' => 'b_s', 'country' => 'b_c', 'postcode' => 'b_p' }
167
+ }
168
+
169
+ @checkout = FormCheckout.new(@form, @page)
170
+ result = @checkout.create
171
+
172
+ result[:billing].should_not === false
173
+ result[:shipping].should === result[:billing]
174
+ end
175
+ it 'should set false to the nil objects' do
176
+ @checkout = FormCheckout.new(@form, @page)
177
+ result = @checkout.create
178
+
179
+ result[:billing].should === false
180
+ result[:shipping].should === false
181
+ end
182
+ end
183
+ end
184
+ end
185
+
186
+ context 'not configured' do
187
+ before :each do
188
+ @form[:config] = {
189
+ :checkout => {
190
+ :address => {
191
+ :enabled => true
192
+ }
193
+ }
194
+ }
195
+ end
196
+ it 'should not call on the Address methods' do
197
+ @addresses = ShopAddress.all
198
+
199
+ @checkout = FormCheckout.new(@form, @page)
200
+ result = @checkout.create
201
+
202
+ ShopAddress.all.should === @addresses
203
+ end
204
+ end
205
+ end
206
+
207
+ context 'gateway' do
208
+ context 'merchant' do
209
+ context 'configured' do
210
+ before :each do
211
+ @form[:config] = {
212
+ :checkout => {
213
+ :test => true,
214
+ :gateway => {
215
+ :name => 'PayWay',
216
+ :credentials=> {
217
+ :username => 'abcdefgh',
218
+ :password => '12345678',
219
+ :pem => 'README',
220
+ :merchant => 'test'
221
+ }
222
+ }
223
+ }
224
+ }
225
+ @data = {
226
+ 'card' => { }
227
+ }
228
+
229
+ @gateway = Object.new
230
+ @purchase = Object.new
231
+ stub(@purchase).success? { true }
232
+ stub(@purchase).message { 'success' }
233
+
234
+ mock(ActiveMerchant::Billing::PayWayGateway).new(@form[:config][:checkout][:gateway][:credentials]) { @gateway }
235
+ stub(@gateway).purchase(1000, nil, { :order_id => @order.id}) { @purchase }
236
+ end
237
+ it 'should assign ActiveMerchant to testing mode' do
238
+ @checkout = FormCheckout.new(@form, @page)
239
+ @checkout.create
240
+
241
+ ActiveMerchant::Billing::Base.mode.should === :test
242
+ end
243
+
244
+ it 'should return gateway true' do
245
+ @checkout = FormCheckout.new(@form, @page)
246
+ result = @checkout.create
247
+
248
+ result[:gateway].should === true
249
+ end
250
+ end
251
+
252
+ context 'not configured' do
253
+ before :each do
254
+ @form[:config] = {
255
+ :checkout => {
256
+ :test => true
257
+ }
258
+ }
259
+ end
260
+
261
+ it 'should not call PayWayGateway' do
262
+ dont_allow(ActiveMerchant::Billing::PayWayGateway).new
263
+
264
+ @checkout = FormCheckout.new(@form, @page)
265
+ @checkout.create
266
+ end
267
+
268
+ it 'should return gateway false' do
269
+ @checkout = FormCheckout.new(@form, @page)
270
+ result = @checkout.create
271
+
272
+ result[:gateway].should === false
273
+ end
274
+ end
275
+ end
276
+
277
+ context 'card without test' do
278
+ before :each do
279
+ @form[:config] = {
280
+ :checkout => {
281
+ :gateway => {
282
+ :name => 'PayWay',
283
+ :credentials => {}
284
+ }
285
+ }
286
+ }
287
+ @data = {
288
+ 'card' => {
289
+ 'number' => 1234123412341234,
290
+ 'name' => 'Mr. Joe Bloggs',
291
+ 'verification' => 123,
292
+ 'month' => 1,
293
+ 'year' => 2009,
294
+ 'type' => 'visa'
295
+ }
296
+ }
297
+
298
+ @gateway = Object.new
299
+ @purchase = Object.new
300
+ stub(@purchase).success? { true }
301
+ stub(@purchase).message { 'success' }
302
+ mock(ActiveMerchant::Billing::PayWayGateway).new(@form[:config][:checkout][:gateway][:credentials]) { @gateway }
303
+ stub(@gateway).purchase(@order.price * 100, anything, { :order_id => @order.id }) { @purchase }
304
+ end
305
+ context 'configured' do
306
+ before :each do
307
+ @card = Object.new
308
+ stub(@card).valid? { true }
309
+
310
+ mock(ActiveMerchant::Billing::CreditCard).new({
311
+ :number => 1234123412341234,
312
+ :month => 1,
313
+ :year => 2009,
314
+ :first_name => 'Mr. Joe',
315
+ :last_name => 'Bloggs',
316
+ :verification_value => 123,
317
+ :type => 'visa'
318
+ }) { @card }
319
+ end
320
+ context 'should return card details' do
321
+ context 'valid' do
322
+ it 'should return valid' do
323
+ stub(@card).valid? { true }
324
+
325
+ @checkout = FormCheckout.new(@form, @page)
326
+ result = @checkout.create
327
+
328
+ result[:card][:valid].should === true
329
+ result[:payment][:success].should == true
330
+ result[:payment][:message].should == 'success'
331
+ end
332
+ it 'should set the order as paid' do
333
+ stub(@card).valid? { true }
334
+
335
+ @checkout = FormCheckout.new(@form, @page)
336
+ result = @checkout.create
337
+
338
+ shop_orders(:one_item).paid?.should === true
339
+ end
340
+ end
341
+ context 'invalid' do
342
+ it 'should return invalid' do
343
+ stub(@card).valid? { false }
344
+
345
+ @checkout = FormCheckout.new(@form, @page)
346
+ result = @checkout.create
347
+
348
+ result[:card][:valid].should === false
349
+ end
350
+ end
351
+ end
352
+ it 'should return relevant details' do
353
+ stub(@card).valid? { true }
354
+
355
+ @checkout = FormCheckout.new(@form, @page)
356
+ result = @checkout.create
357
+
358
+ result[:card].should == {
359
+ :valid => true
360
+ }
361
+ end
362
+ it 'should not return sensitive details' do
363
+ stub(@card).valid? { true }
364
+
365
+ @checkout = FormCheckout.new(@form, @page)
366
+ result = @checkout.create
367
+
368
+ result[:card][:number].should === nil
369
+ result[:card][:verification].should === nil
370
+ end
371
+ end
372
+ end
373
+
374
+ end
375
+ end
376
+ end