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
@@ -0,0 +1,129 @@
1
+ require 'spec/spec_helper'
2
+
3
+ describe Shop::Tags::Responses do
4
+
5
+ dataset :forms, :pages
6
+
7
+ it 'should describe these tags' do
8
+ Shop::Tags::Responses.tags.sort.should == [
9
+ 'response:checkout',
10
+ 'response:checkout:payment',
11
+ 'response:checkout:payment:if_success',
12
+ 'response:checkout:payment:unless_success'
13
+ ].sort
14
+ end
15
+
16
+ context 'responses' do
17
+
18
+ before :each do
19
+ login_as :customer
20
+ @order = shop_orders(:several_items)
21
+
22
+ mock_page_with_request_and_data
23
+ mock_response
24
+
25
+ mock.instance_of(ActiveMerchant::Billing::CreditCard).valid? { true }
26
+ mock_valid_form_checkout_request
27
+ @checkout = FormCheckout.new(@form, @page)
28
+ end
29
+
30
+ describe '<r:response:checkout>' do
31
+ context 'checkout exists' do
32
+ before :each do
33
+ @response.result[:results][:checkout] = @checkout.create
34
+ end
35
+ it 'should expand' do
36
+ tag = %{<r:response:checkout>success</r:response:checkout>}
37
+ exp = %{success}
38
+
39
+ pages(:home).should render(tag).as(exp)
40
+ end
41
+ end
42
+ context 'checkout does not exist' do
43
+ it 'should not expand' do
44
+ tag = %{<r:response:checkout>failure</r:response:checkout>}
45
+ exp = %{}
46
+
47
+ pages(:home).should render(tag).as(exp)
48
+ end
49
+ end
50
+ end
51
+
52
+ describe '<r:response:payment>' do
53
+ before :each do
54
+ @response.result[:results][:checkout] = @checkout.create
55
+ end
56
+ context 'payment success' do
57
+ it 'should expand' do
58
+ tag = %{<r:response:checkout:payment>success</r:response:checkout:payment>}
59
+ exp = %{success}
60
+
61
+ pages(:home).should render(tag).as(exp)
62
+ end
63
+ end
64
+ context 'payment failure' do
65
+ before :each do
66
+ @response.result[:results][:checkout][:payment] = false
67
+ end
68
+ it 'should expand' do
69
+ tag = %{<r:response:checkout:payment>success</r:response:checkout:payment>}
70
+ exp = %{success}
71
+
72
+ pages(:home).should render(tag).as(exp)
73
+ end
74
+ end
75
+ end
76
+
77
+ describe '<r:response:payment:if_success>' do
78
+ before :each do
79
+ @response.result[:results][:checkout] = @checkout.create
80
+ end
81
+ context 'payment success' do
82
+ it 'should expand' do
83
+ tag = %{<r:response:checkout:payment:if_success>success</r:response:checkout:payment:if_success>}
84
+ exp = %{success}
85
+
86
+ pages(:home).should render(tag).as(exp)
87
+ end
88
+ end
89
+ context 'payment failure' do
90
+ before :each do
91
+ @response.result[:results][:checkout][:payment] = false
92
+ end
93
+ it 'should not expand' do
94
+ tag = %{<r:response:checkout:payment:if_success>failure</r:response:checkout:payment:if_success>}
95
+ exp = %{}
96
+
97
+ pages(:home).should render(tag).as(exp)
98
+ end
99
+ end
100
+ end
101
+
102
+ describe '<r:response:payment:unless_success>' do
103
+ before :each do
104
+ @response.result[:results][:checkout] = @checkout.create
105
+ end
106
+ context 'payment failure' do
107
+ before :each do
108
+ @response.result[:results][:checkout][:payment] = false
109
+ end
110
+ it 'should expand' do
111
+ tag = %{<r:response:checkout:payment:unless_success>success</r:response:checkout:payment:unless_success>}
112
+ exp = %{success}
113
+
114
+ pages(:home).should render(tag).as(exp)
115
+ end
116
+ end
117
+ context 'payment success' do
118
+ it 'should not expand' do
119
+ tag = %{<r:response:checkout:payment:unless_success>failure</r:response:checkout:payment:unless_success>}
120
+ exp = %{}
121
+
122
+ pages(:home).should render(tag).as(exp)
123
+ end
124
+ end
125
+ end
126
+
127
+ end
128
+
129
+ end
@@ -5,372 +5,306 @@ describe FormCheckout do
5
5
  dataset :shop_orders, :pages, :forms, :shop_addresses
6
6
 
7
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
8
+ mock_page_with_request_and_data
27
9
  end
28
-
29
10
  describe '#create' do
30
11
  context 'addresses' do
31
- context 'address configured' do
12
+
13
+ context 'sending ids with user logged in' do
32
14
  before :each do
33
- @form[:config] = {
34
- :checkout => {
35
- :address => {
36
- :enabled => true
37
- }
38
- }
39
- }
15
+ login_as :customer # Will have existing addresses due to several_items
16
+ @order = shop_orders(:one_item)
17
+ mock_valid_form_checkout_request
40
18
  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
- }
19
+
20
+ context 'both billing and shipping' do
21
+ it 'should assign that address to the order billing and shipping' do
22
+ @data[:billing] = { :id => shop_orders(:several_items).billing.id }
23
+ @data[:shipping] = { :id => shop_orders(:several_items).shipping.id }
24
+
25
+ @checkout = FormCheckout.new(@form, @page)
26
+ result = @checkout.create
48
27
 
49
- @checkout = FormCheckout.new(@form, @page)
50
- @checkout.create
28
+ shop_orders(:one_item).billing.should === shop_addresses(:billing)
29
+ shop_orders(:one_item).shipping.should === shop_addresses(:shipping)
51
30
 
52
- shop_orders(:one_item).billing.should === shop_addresses(:billing)
53
- shop_orders(:one_item).shipping.should === shop_addresses(:shipping)
54
- end
31
+ result[:billing].should === true
32
+ result[:shipping].should === true
55
33
  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
- }
34
+ end
35
+
36
+ context 'just billing' do
37
+ it 'should assign shipping to be billing' do
38
+ # Set the order to have no shipping address
39
+ @data[:shipping] = {}
40
+
41
+ @checkout = FormCheckout.new(@form, @page)
42
+ result = @checkout.create
61
43
 
62
- @checkout = FormCheckout.new(@form, @page)
63
- @checkout.create
44
+ shop_orders(:one_item).billing.should === shop_addresses(:billing)
45
+ shop_orders(:one_item).shipping.should === shop_addresses(:billing)
64
46
 
65
- shop_orders(:one_item).billing.should === shop_addresses(:billing)
66
- shop_orders(:one_item).shipping.should === shop_addresses(:billing)
67
- end
47
+ result[:billing].should === true
48
+ result[:shipping].should === true
68
49
  end
69
50
  end
51
+ end
70
52
 
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
-
53
+ context 'sending ids without customer logged in' do
54
+ before :each do
55
+ @order = shop_orders(:one_item)
56
+ mock_valid_form_checkout_request
57
+ end
58
+ context 'both billing and shipping' do
59
+ it 'it should not assign those addresses' do
83
60
  @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'
61
+ result = @checkout.create
62
+
63
+ shop_orders(:one_item).billing.should be_nil
64
+ shop_orders(:one_item).shipping.should be_nil
65
+
66
+ result[:billing].should === false
67
+ result[:shipping].should === false
90
68
  end
91
69
  end
70
+ end
92
71
 
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
72
+ context 'sending ids as a bad customer' do
73
+ before :each do
74
+ login_as :bad_customer
75
+ @order = shop_orders(:one_item)
76
+ mock_valid_form_checkout_request
77
+ end
78
+ it 'should not assign those addresses' do
79
+ @checkout = FormCheckout.new(@form, @page)
80
+ result = @checkout.create
103
81
 
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
- }
82
+ shop_orders(:one_item).billing.should be_nil
83
+ shop_orders(:one_item).shipping.should be_nil
113
84
 
114
- @checkout = FormCheckout.new(@form, @page)
115
- @checkout.create
85
+ result[:billing].should === false
86
+ result[:shipping].should === false
87
+ end
88
+ end
89
+
90
+ context 'updating existing addresses' do
91
+ before :each do
92
+ login_as :customer
93
+ @order = shop_orders(:several_items)
94
+ mock_valid_form_checkout_request
95
+ end
96
+ it 'should keep them assigned and update them' do
97
+ @data[:billing] = { :name => 'new billing' }
98
+ @data[:shipping] = { :name => 'new shipping' }
116
99
 
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
- }
100
+ @checkout = FormCheckout.new(@form, @page)
101
+ result = @checkout.create
127
102
 
128
- @checkout = FormCheckout.new(@form, @page)
129
- @checkout.create
103
+ shop_addresses(:billing).name.should === 'new billing'
104
+ shop_addresses(:shipping).name.should === 'new shipping'
130
105
 
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
106
+ result[:billing].should === true
107
+ result[:shipping].should === true
135
108
  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
- }
109
+ end
110
+
111
+ context 'new addresses' do
112
+ before :each do
113
+ login_as :customer
114
+ @order = shop_orders(:one_item)
115
+ mock_valid_form_checkout_request
144
116
 
145
- @checkout = FormCheckout.new(@form, @page)
146
- result = @checkout.create
117
+ @data[:billing][:id] = nil
118
+ @data[:shipping][:id] = nil
119
+ end
120
+
121
+ context 'both billing and shipping sent' do
122
+ it 'should create new addresses' do
123
+ @checkout = FormCheckout.new(@form, @page)
124
+ result = @checkout.create
125
+
126
+ shop_orders(:one_item).billing.name.should === @data[:billing][:name]
127
+ shop_orders(:one_item).shipping.name.should === @data[:shipping][:name]
147
128
 
148
- result[:billing][:name].should === 'b_n'
149
- result[:shipping][:name].should === 's_n'
150
- end
129
+ result[:billing].should === true
130
+ result[:shipping].should === true
151
131
  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
- }
132
+ end
133
+
134
+ context 'only billing sent' do
135
+ it 'should copy billing to shipping' do
136
+ @data[:shipping] = {}
137
+
138
+ @checkout = FormCheckout.new(@form, @page)
139
+ result = @checkout.create
157
140
 
158
- @checkout = FormCheckout.new(@form, @page)
159
- result = @checkout.create
141
+ shop_orders(:one_item).billing.name.should === @data[:billing][:name]
142
+ shop_orders(:one_item).shipping.name.should === @data[:billing][:name]
160
143
 
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
- }
144
+ result[:billing].should === true
145
+ result[:shipping].should === true
146
+ end
147
+ end
148
+
149
+ context 'billing sent with same shipping' do
150
+ it 'should copy billing to shipping' do
151
+ @data[:shipping] = @data[:billing]
168
152
 
169
- @checkout = FormCheckout.new(@form, @page)
170
- result = @checkout.create
153
+ @checkout = FormCheckout.new(@form, @page)
154
+ result = @checkout.create
171
155
 
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
156
+ shop_orders(:one_item).shipping.should === shop_orders(:one_item).billing
178
157
 
179
- result[:billing].should === false
180
- result[:shipping].should === false
181
- end
158
+ result[:billing].should === true
159
+ result[:shipping].should === true
182
160
  end
183
161
  end
184
162
  end
185
-
186
- context 'not configured' do
163
+ end
164
+
165
+ context 'gateway' do
166
+ context 'configured correctly' do
187
167
  before :each do
188
- @form[:config] = {
189
- :checkout => {
190
- :address => {
191
- :enabled => true
192
- }
193
- }
194
- }
168
+ login_as :customer
169
+ @order = shop_orders(:one_item)
170
+
171
+ mock_valid_form_checkout_request
172
+ end
173
+
174
+ it 'should assign ActiveMerchant to testing mode' do
175
+ @checkout = FormCheckout.new(@form, @page)
176
+ @checkout.create
177
+
178
+ ActiveMerchant::Billing::Base.mode.should === :test
179
+ end
180
+
181
+ it 'should return true for payment results' do
182
+ mock.instance_of(ActiveMerchant::Billing::CreditCard).valid? { true }
183
+ @checkout = FormCheckout.new(@form, @page)
184
+ result = @checkout.create
185
+
186
+ result[:gateway].should === true
187
+ result[:card].should === true
188
+ result[:payment].should === true
195
189
  end
196
- it 'should not call on the Address methods' do
197
- @addresses = ShopAddress.all
198
-
190
+
191
+ it 'should assign a payment object' do
192
+ mock.instance_of(ActiveMerchant::Billing::CreditCard).valid? { true }
199
193
  @checkout = FormCheckout.new(@form, @page)
200
194
  result = @checkout.create
201
195
 
202
- ShopAddress.all.should === @addresses
196
+ @order.payment.card_number.should === "XXXX-XXXX-XXXX-1"
197
+ @order.payment.card_type.should === @data[:card][:type]
198
+ @order.payment.amount.should === @order.price
203
199
  end
204
200
  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
- }
201
+
202
+ context 'configured incorrectly' do
203
+ before :each do
204
+ login_as :customer
205
+ @order = shop_orders(:one_item)
206
+
207
+ mock_valid_form_checkout_request
208
+ end
209
+ context 'no gateway' do
210
+ it 'should return gateway false' do
211
+ mock.instance_of(ActiveMerchant::Billing::CreditCard).valid? { true }
212
+ @form[:extensions][:checkout][:gateway] = nil
213
+
214
+ @checkout = FormCheckout.new(@form, @page)
215
+ result = @checkout.create
228
216
 
229
- @gateway = Object.new
230
- @purchase = Object.new
231
- stub(@purchase).success? { true }
232
- stub(@purchase).message { 'success' }
217
+ result[:gateway].should === false
218
+ result[:card].should === false
219
+ result[:payment].should === false
233
220
 
234
- mock(ActiveMerchant::Billing::PayWayGateway).new(@form[:config][:checkout][:gateway][:credentials]) { @gateway }
235
- stub(@gateway).purchase(1000, nil, { :order_id => @order.id}) { @purchase }
221
+ @order.payment.should be_nil
236
222
  end
237
- it 'should assign ActiveMerchant to testing mode' do
238
- @checkout = FormCheckout.new(@form, @page)
239
- @checkout.create
223
+ end
240
224
 
241
- ActiveMerchant::Billing::Base.mode.should === :test
242
- end
243
-
244
- it 'should return gateway true' do
225
+ context 'no card' do
226
+ it 'should return card and payment false' do
227
+ mock.instance_of(ActiveMerchant::Billing::CreditCard).valid? { true }
228
+ @data[:card] = nil
229
+
245
230
  @checkout = FormCheckout.new(@form, @page)
246
231
  result = @checkout.create
247
232
 
248
233
  result[:gateway].should === true
234
+ result[:card].should === false
235
+ result[:payment].should === false
236
+
237
+ @order.payment.should be_nil
249
238
  end
250
239
  end
251
240
 
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
241
+ context 'invalid card' do
242
+ it 'should return card and payment false' do
243
+ mock.instance_of(ActiveMerchant::Billing::CreditCard).valid? { false }
263
244
 
264
- @checkout = FormCheckout.new(@form, @page)
265
- @checkout.create
266
- end
267
-
268
- it 'should return gateway false' do
269
245
  @checkout = FormCheckout.new(@form, @page)
270
246
  result = @checkout.create
271
247
 
272
- result[:gateway].should === false
248
+ result[:gateway].should === true
249
+ result[:card].should === false
250
+ result[:payment].should === false
251
+
252
+ @order.payment.should be_nil
273
253
  end
274
254
  end
275
255
  end
256
+ end
257
+
258
+ context 'mail' do
259
+ before :each do
260
+ mock.instance_of(ActiveMerchant::Billing::CreditCard).valid? { true }
261
+ end
276
262
 
277
- context 'card without test' do
263
+ context 'mail configured' do
278
264
  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
- }
265
+ login_as :customer
266
+ @order = shop_orders(:one_item)
297
267
 
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 }
268
+ mock_valid_form_checkout_request
304
269
  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
-
270
+ context 'payment successful' do
271
+ it 'should configure mail to be sent' do
355
272
  @checkout = FormCheckout.new(@form, @page)
356
- result = @checkout.create
273
+ @checkout.create
357
274
 
358
- result[:card].should == {
359
- :valid => true
360
- }
275
+ @form[:extensions][:mail][:to].should === shop_addresses(:billing).email
276
+ @form[:extensions][:mail][:recipient].should === shop_addresses(:billing).email
277
+ @form[:extensions][:mail][:subject].should === @form[:extensions][:checkout][:mail][:subject]
278
+ @form[:extensions][:mail][:bcc].should === @form[:extensions][:checkout][:mail][:bcc]
361
279
  end
362
- it 'should not return sensitive details' do
363
- stub(@card).valid? { true }
364
-
280
+ end
281
+
282
+ context 'payment unsuccesful' do
283
+ it 'should not configure mail to be sent' do
365
284
  @checkout = FormCheckout.new(@form, @page)
366
- result = @checkout.create
285
+ stub(@checkout).success? { false }
286
+ @checkout.create
367
287
 
368
- result[:card][:number].should === nil
369
- result[:card][:verification].should === nil
288
+ @form[:extensions][:mail].should be_nil
370
289
  end
371
290
  end
372
291
  end
373
292
 
293
+ context 'mail not configured' do
294
+ before :each do
295
+ login_as :customer
296
+ @order = shop_orders(:one_item)
297
+
298
+ mock_valid_form_checkout_request
299
+ @form[:extensions][:checkout][:mail] = nil
300
+ end
301
+ it 'should not configure mail to be sent' do
302
+ @checkout = FormCheckout.new(@form, @page)
303
+ result = @checkout.create
304
+
305
+ @form[:extensions][:mail].should be_nil
306
+ end
307
+ end
374
308
  end
375
309
  end
376
310
  end