radiant-shop-extension 0.9.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +6 -0
- data/Gemfile +26 -0
- data/Gemfile.lock +75 -0
- data/HISTORY.md +77 -0
- data/MIT-LICENSE +20 -0
- data/README.md +26 -0
- data/Rakefile +141 -0
- data/VERSION +1 -0
- data/app/.DS_Store +0 -0
- data/app/controllers/admin/shop/categories_controller.rb +206 -0
- data/app/controllers/admin/shop/customers_controller.rb +137 -0
- data/app/controllers/admin/shop/orders_controller.rb +171 -0
- data/app/controllers/admin/shop/products/images_controller.rb +144 -0
- data/app/controllers/admin/shop/products_controller.rb +217 -0
- data/app/controllers/admin/shops_controller.rb +9 -0
- data/app/controllers/shop/categories_controller.rb +49 -0
- data/app/controllers/shop/line_items_controller.rb +165 -0
- data/app/controllers/shop/orders_controller.rb +16 -0
- data/app/controllers/shop/products_controller.rb +48 -0
- data/app/models/form_checkout.rb +245 -0
- data/app/models/shop_address.rb +13 -0
- data/app/models/shop_addressable.rb +11 -0
- data/app/models/shop_category.rb +85 -0
- data/app/models/shop_category_page.rb +7 -0
- data/app/models/shop_customer.rb +27 -0
- data/app/models/shop_line_item.rb +32 -0
- data/app/models/shop_order.rb +108 -0
- data/app/models/shop_payment.rb +6 -0
- data/app/models/shop_payment_method.rb +5 -0
- data/app/models/shop_product.rb +87 -0
- data/app/models/shop_product_attachment.rb +30 -0
- data/app/models/shop_product_page.rb +7 -0
- data/app/views/.DS_Store +0 -0
- data/app/views/admin/.DS_Store +0 -0
- data/app/views/admin/pages/_shop_category.html.haml +4 -0
- data/app/views/admin/pages/_shop_product.html.haml +4 -0
- data/app/views/admin/shop/categories/edit.html.haml +12 -0
- data/app/views/admin/shop/categories/edit/_fields.html.haml +28 -0
- data/app/views/admin/shop/categories/edit/_head.html.haml +2 -0
- data/app/views/admin/shop/categories/edit/_meta.html.haml +7 -0
- data/app/views/admin/shop/categories/edit/_part.html.haml +3 -0
- data/app/views/admin/shop/categories/edit/_popup.html.haml +3 -0
- data/app/views/admin/shop/categories/edit/meta/_handle.html.haml +5 -0
- data/app/views/admin/shop/categories/edit/meta/_layouts.html.haml +10 -0
- data/app/views/admin/shop/categories/edit/parts/_description.html.haml +1 -0
- data/app/views/admin/shop/categories/index/_category.html.haml +16 -0
- data/app/views/admin/shop/categories/new.html.haml +10 -0
- data/app/views/admin/shop/categories/remove.html.haml +12 -0
- data/app/views/admin/shop/customers/index.html.haml +36 -0
- data/app/views/admin/shop/orders/index.html.haml +33 -0
- data/app/views/admin/shop/products/edit.html.haml +14 -0
- data/app/views/admin/shop/products/edit/_fields.html.haml +38 -0
- data/app/views/admin/shop/products/edit/_head.html.haml +2 -0
- data/app/views/admin/shop/products/edit/_image.html.haml +12 -0
- data/app/views/admin/shop/products/edit/_meta.html.haml +8 -0
- data/app/views/admin/shop/products/edit/_part.html.haml +3 -0
- data/app/views/admin/shop/products/edit/_popup.html.haml +3 -0
- data/app/views/admin/shop/products/edit/buttons/_browse_images.html.haml +1 -0
- data/app/views/admin/shop/products/edit/buttons/_new_image.html.haml +1 -0
- data/app/views/admin/shop/products/edit/meta/_category.html.haml +5 -0
- data/app/views/admin/shop/products/edit/meta/_sku.html.haml +5 -0
- data/app/views/admin/shop/products/edit/parts/_description.html.haml +1 -0
- data/app/views/admin/shop/products/edit/parts/_images.html.haml +5 -0
- data/app/views/admin/shop/products/edit/popups/_browse_images.html.haml +6 -0
- data/app/views/admin/shop/products/edit/popups/_new_image.html.haml +18 -0
- data/app/views/admin/shop/products/index.html.haml +10 -0
- data/app/views/admin/shop/products/index/_bottom.html.haml +5 -0
- data/app/views/admin/shop/products/index/_product.html.haml +13 -0
- data/app/views/admin/shop/products/new.html.haml +10 -0
- data/app/views/admin/shop/products/remove.html.haml +12 -0
- data/app/views/shop/categories/show.html.haml +1 -0
- data/app/views/shop/orders/show.html.haml +1 -0
- data/app/views/shop/products/index.html.haml +1 -0
- data/app/views/shop/products/show.html.haml +1 -0
- data/config/locales/en.yml +50 -0
- data/config/routes.rb +38 -0
- data/config/shop_cart.yml +16 -0
- data/cucumber.yml +1 -0
- data/db/migrate/20100311053701_initial.rb +153 -0
- data/db/migrate/20100520033059_create_layouts.rb +119 -0
- data/db/migrate/20100903122123_create_forms.rb +44 -0
- data/db/migrate/20100908063639_create_snippets.rb +22 -0
- data/features/support/env.rb +16 -0
- data/features/support/paths.rb +14 -0
- data/lib/shop/controllers/application_controller.rb +39 -0
- data/lib/shop/controllers/site_controller.rb +12 -0
- data/lib/shop/interface/products.rb +49 -0
- data/lib/shop/models/image.rb +14 -0
- data/lib/shop/models/page.rb +14 -0
- data/lib/shop/tags/address.rb +40 -0
- data/lib/shop/tags/cart.rb +49 -0
- data/lib/shop/tags/category.rb +83 -0
- data/lib/shop/tags/core.rb +12 -0
- data/lib/shop/tags/helpers.rb +142 -0
- data/lib/shop/tags/item.rb +109 -0
- data/lib/shop/tags/product.rb +109 -0
- data/lib/shop/tags/responses.rb +34 -0
- data/lib/tasks/shop_extension_tasks.rake +54 -0
- data/mockups/balsamiq/products-retro_fun_tshirt-more.bmml +0 -0
- data/mockups/balsamiq/products-retro_fun_tshirt.bmml +0 -0
- data/public/images/admin/extensions/shop/products/sort.png +0 -0
- data/public/javascripts/admin/extensions/shop/products/edit.js +115 -0
- data/public/javascripts/admin/extensions/shop/products/index.js +65 -0
- data/public/stylesheets/sass/admin/extensions/shop/edit.sass +86 -0
- data/public/stylesheets/sass/admin/extensions/shop/products/edit.sass +158 -0
- data/public/stylesheets/sass/admin/extensions/shop/products/index.sass +129 -0
- data/radiant-shop-extension.gemspec +245 -0
- data/shop_extension.rb +62 -0
- data/spec/controllers/admin/shop/categories_controller_spec.rb +443 -0
- data/spec/controllers/admin/shop/products/images_controller_spec.rb +477 -0
- data/spec/controllers/admin/shop/products_controller_spec.rb +394 -0
- data/spec/controllers/admin/shops_controller_spec.rb +19 -0
- data/spec/controllers/shop/categories_controller_spec.rb +42 -0
- data/spec/controllers/shop/line_items_controller_spec.rb +256 -0
- data/spec/controllers/shop/orders_controller_specs.rb +37 -0
- data/spec/controllers/shop/products_controller_spec.rb +51 -0
- data/spec/datasets/forms.rb +153 -0
- data/spec/datasets/images.rb +13 -0
- data/spec/datasets/shop_addresses.rb +27 -0
- data/spec/datasets/shop_categories.rb +13 -0
- data/spec/datasets/shop_line_items.rb +9 -0
- data/spec/datasets/shop_orders.rb +21 -0
- data/spec/datasets/shop_products.rb +34 -0
- data/spec/helpers/nested_tag_helper.rb +33 -0
- data/spec/lib/shop/models/image_spec.rb +28 -0
- data/spec/lib/shop/models/page_spec.rb +38 -0
- data/spec/lib/shop/tags/address_spec.rb +196 -0
- data/spec/lib/shop/tags/cart_spec.rb +169 -0
- data/spec/lib/shop/tags/category_spec.rb +201 -0
- data/spec/lib/shop/tags/core_spec.rb +16 -0
- data/spec/lib/shop/tags/helpers_spec.rb +381 -0
- data/spec/lib/shop/tags/item_spec.rb +313 -0
- data/spec/lib/shop/tags/product_spec.rb +334 -0
- data/spec/matchers/comparison.rb +72 -0
- data/spec/matchers/render_matcher.rb +33 -0
- data/spec/models/form_checkout_spec.rb +376 -0
- data/spec/models/shop_category_page_spec.rb +10 -0
- data/spec/models/shop_category_spec.rb +58 -0
- data/spec/models/shop_line_item_spec.rb +42 -0
- data/spec/models/shop_order_spec.rb +228 -0
- data/spec/models/shop_product_attachment_spec.rb +72 -0
- data/spec/models/shop_product_page_spec.rb +10 -0
- data/spec/models/shop_product_spec.rb +135 -0
- data/spec/spec.opts +6 -0
- data/spec/spec_helper.rb +22 -0
- data/vendor/plugins/acts_as_list/README +23 -0
- data/vendor/plugins/acts_as_list/init.rb +3 -0
- data/vendor/plugins/acts_as_list/lib/active_record/acts/list.rb +256 -0
- data/vendor/plugins/acts_as_list/test/list_test.rb +332 -0
- data/vendor/plugins/json_fields/.gitignore +3 -0
- data/vendor/plugins/json_fields/MIT-LICENSE +20 -0
- data/vendor/plugins/json_fields/README.rdoc +65 -0
- data/vendor/plugins/json_fields/Rakefile +55 -0
- data/vendor/plugins/json_fields/init.rb +2 -0
- data/vendor/plugins/json_fields/lib/json_fields.rb +99 -0
- data/vendor/plugins/json_fields/spec/lib/json_fields_spec.rb +124 -0
- data/vendor/plugins/json_fields/spec/spec.opts +6 -0
- data/vendor/plugins/json_fields/spec/spec_helper.rb +29 -0
- data/vendor/plugins/json_fields/spec/test_models.rb +12 -0
- metadata +324 -0
@@ -0,0 +1,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
|