opensteam 0.9.2 → 0.9.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +53 -0
- data/README.rdoc +19 -10
- data/generators/opensteam/opensteam_generator.rb +27 -3
- data/generators/opensteam/templates/app/controllers/admin/configurations_controller.rb +85 -0
- data/generators/opensteam/templates/app/controllers/admin/inventories_controller.rb +1 -1
- data/generators/opensteam/templates/app/controllers/admin/invoices_controller.rb +35 -4
- data/generators/opensteam/templates/app/controllers/admin/orders_controller.rb +5 -4
- data/generators/opensteam/templates/app/controllers/admin/shipments_controller.rb +6 -3
- data/generators/opensteam/templates/app/controllers/admin/shipping_rate_groups_controller.rb +76 -0
- data/generators/opensteam/templates/app/controllers/admin/tax_groups_controller.rb +124 -0
- data/generators/opensteam/templates/app/controllers/admin/tax_rules_controller.rb +19 -0
- data/generators/opensteam/templates/app/controllers/admin/tax_zones_controller.rb +118 -0
- data/generators/opensteam/templates/app/controllers/admin/users_controller.rb +1 -1
- data/generators/opensteam/templates/app/controllers/admin_controller.rb +20 -0
- data/generators/opensteam/templates/app/controllers/carts_controller.rb +118 -0
- data/generators/opensteam/templates/app/controllers/checkout_controller.rb +119 -79
- data/generators/opensteam/templates/app/controllers/profile_controller.rb +2 -4
- data/generators/opensteam/templates/app/controllers/searches_controller.rb +1 -1
- data/generators/opensteam/templates/app/controllers/user_sessions_controller.rb +2 -1
- data/generators/opensteam/templates/app/controllers/users_controller.rb +10 -3
- data/generators/opensteam/templates/app/helpers/admin_helper.rb +15 -1
- data/generators/opensteam/templates/app/helpers/checkout_helper.rb +38 -0
- data/generators/opensteam/templates/app/helpers/webshop_helper.rb +6 -1
- data/generators/opensteam/templates/app/models/zone.rb +18 -0
- data/generators/opensteam/templates/app/views/admin/_menu.html.erb +18 -0
- data/generators/opensteam/templates/app/views/admin/catalog.html.erb +2 -3
- data/generators/opensteam/templates/app/views/admin/configurations/edit.html.erb +20 -0
- data/generators/opensteam/templates/app/views/admin/configurations/index.html.erb +22 -0
- data/generators/opensteam/templates/app/views/admin/configurations/new.html.erb +19 -0
- data/generators/opensteam/templates/app/views/admin/configurations/show.html.erb +13 -0
- data/generators/opensteam/templates/app/views/admin/filters/_filter.html.erb +1 -1
- data/generators/opensteam/templates/app/views/admin/index.html.erb +0 -19
- data/generators/opensteam/templates/app/views/admin/inventories/edit.html.erb +10 -6
- data/generators/opensteam/templates/app/views/admin/inventories/new.html.erb +5 -0
- data/generators/opensteam/templates/app/views/admin/inventories/show.html.erb +10 -6
- data/generators/opensteam/templates/app/views/admin/invoices/_invoice.html.erb +1 -0
- data/generators/opensteam/templates/app/views/admin/invoices/_invoice_fields.html.erb +52 -0
- data/generators/opensteam/templates/app/views/admin/invoices/new.html.erb +9 -37
- data/generators/opensteam/templates/app/views/admin/invoices/show.html.erb +10 -36
- data/generators/opensteam/templates/app/views/admin/invoices/show.pdf.prawn +59 -0
- data/generators/opensteam/templates/app/views/admin/order_config.html.erb +5 -0
- data/generators/opensteam/templates/app/views/admin/order_items/_item_entry.html.erb +9 -0
- data/generators/opensteam/templates/app/views/admin/order_items/_items_table.html.erb +16 -0
- data/generators/opensteam/templates/app/views/admin/orders/_order.html.erb +9 -9
- data/generators/opensteam/templates/app/views/admin/orders/_orders.html.erb +1 -1
- data/generators/opensteam/templates/app/views/admin/orders/show.html.erb +25 -9
- data/generators/opensteam/templates/app/views/admin/payment_types.html.erb +27 -0
- data/generators/opensteam/templates/app/views/admin/payments/_credit_card_payment.html.erb +26 -0
- data/generators/opensteam/templates/app/views/admin/payments/_credit_card_payment_info.html.erb +15 -0
- data/generators/opensteam/templates/app/views/admin/payments/_direct_debit_payment.html.erb +5 -0
- data/generators/opensteam/templates/app/views/admin/shipments/new.html.erb +45 -30
- data/generators/opensteam/templates/app/views/admin/shipments/show.html.erb +3 -3
- data/generators/opensteam/templates/app/views/admin/shipping_rate_groups/_payment_addition.html.erb +12 -0
- data/generators/opensteam/templates/app/views/admin/shipping_rate_groups/_rate.html.erb +16 -0
- data/generators/opensteam/templates/app/views/admin/shipping_rate_groups/edit.html.erb +63 -0
- data/generators/opensteam/templates/app/views/admin/shipping_rate_groups/index.html.erb +28 -0
- data/generators/opensteam/templates/app/views/admin/shipping_rate_groups/new.html.erb +60 -0
- data/generators/opensteam/templates/app/views/admin/shipping_rate_groups/show.html.erb +13 -0
- data/generators/opensteam/templates/app/views/admin/system.html.erb +5 -0
- data/generators/opensteam/templates/app/views/admin/tax_groups/_attributes.html.erb +11 -0
- data/generators/opensteam/templates/app/views/admin/tax_groups/_tax_groups.html.erb +17 -0
- data/generators/opensteam/templates/app/views/admin/tax_groups/_tax_groups_row.html.erb +12 -0
- data/generators/opensteam/templates/app/views/admin/tax_groups/_tax_rule.html.erb +14 -0
- data/generators/opensteam/templates/app/views/admin/tax_groups/edit.html.erb +26 -0
- data/generators/opensteam/templates/app/views/admin/tax_groups/index.html.erb +8 -0
- data/generators/opensteam/templates/app/views/admin/tax_groups/new.html.erb +27 -0
- data/generators/opensteam/templates/app/views/admin/tax_groups/show.html.erb +28 -0
- data/generators/opensteam/templates/app/views/admin/tax_zones/_attributes.html.erb +18 -0
- data/generators/opensteam/templates/app/views/admin/tax_zones/_tax_zone_row.html.erb +13 -0
- data/generators/opensteam/templates/app/views/admin/tax_zones/_tax_zones.html.erb +11 -0
- data/generators/opensteam/templates/app/views/admin/tax_zones/edit.html.erb +16 -0
- data/generators/opensteam/templates/app/views/admin/tax_zones/index.html.erb +16 -0
- data/generators/opensteam/templates/app/views/admin/tax_zones/new.html.erb +14 -0
- data/generators/opensteam/templates/app/views/admin/tax_zones/show.html.erb +15 -0
- data/generators/opensteam/templates/app/views/admin/users.html.erb +0 -1
- data/generators/opensteam/templates/app/views/admin/users/show.html.erb +10 -0
- data/generators/opensteam/templates/app/views/administration_mailer/order_customer.erb +1 -1
- data/generators/opensteam/templates/app/views/carts/_cart.html.erb +7 -0
- data/generators/opensteam/templates/app/views/carts/_cart_content.html.erb +45 -0
- data/generators/opensteam/templates/app/views/carts/create.rjs +3 -0
- data/generators/opensteam/templates/app/views/{cart → carts}/index.html.erb +0 -0
- data/generators/opensteam/templates/app/views/carts/update.rjs +11 -0
- data/generators/opensteam/templates/app/views/checkout/_address.html.erb +42 -0
- data/generators/opensteam/templates/app/views/checkout/_customer.html.erb +31 -0
- data/generators/opensteam/templates/app/views/checkout/_edit_checkout.html.erb +42 -0
- data/generators/opensteam/templates/app/views/checkout/_new_checkout.html.erb +44 -0
- data/generators/opensteam/templates/app/views/checkout/_shipping_buttons.html.erb +8 -0
- data/generators/opensteam/templates/app/views/checkout/edit.html.erb +7 -0
- data/generators/opensteam/templates/app/views/checkout/new.html.erb +11 -0
- data/generators/opensteam/templates/app/views/checkout/outro.html.erb +1 -4
- data/generators/opensteam/templates/app/views/checkout/show.html.erb +63 -0
- data/generators/opensteam/templates/app/views/common/_header_admin.html.erb +5 -0
- data/generators/opensteam/templates/app/views/layouts/admin.html.erb +28 -12
- data/generators/opensteam/templates/app/views/layouts/profile.html.erb +2 -2
- data/generators/opensteam/templates/app/views/layouts/webshop.html.erb +5 -4
- data/generators/opensteam/templates/app/views/payment/_advance_payment_payment.html.erb +1 -0
- data/generators/opensteam/templates/app/views/payment/_credit_card_payment.html.erb +37 -0
- data/generators/opensteam/templates/app/views/payment/_credit_card_payment_confirmation.html.erb +20 -0
- data/generators/opensteam/templates/app/views/payment/_direct_debit_payment.html.erb +5 -0
- data/generators/opensteam/templates/app/views/payment/_direct_debit_payment_confirmation.html.erb +5 -0
- data/generators/opensteam/templates/app/views/profile/index.html.erb +1 -1
- data/generators/opensteam/templates/app/views/profile/infos/edit.html.erb +20 -12
- data/generators/opensteam/templates/app/views/profile/infos/edit_password.html.erb +16 -12
- data/generators/opensteam/templates/app/views/profile/orders/_order.html.erb +1 -1
- data/generators/opensteam/templates/app/views/profile/orders/show.html.erb +10 -7
- data/generators/opensteam/templates/app/views/webshop/_inventory_content.html.erb +1 -0
- data/generators/opensteam/templates/app/views/webshop/show.html.erb +3 -1
- data/generators/opensteam/templates/config/initializers/init_states.rb +13 -24
- data/generators/opensteam/templates/config/initializers/opensteam.rb +41 -0
- data/generators/opensteam/templates/config/initializers/opensteam_model_tables.rb +49 -10
- data/generators/opensteam/templates/config/initializers/opensteam_security.rb +8 -0
- data/generators/opensteam/templates/config/initializers/payment_process.rb +37 -0
- data/generators/opensteam/templates/db/migrate/20080609095723_create_addresses.rb +8 -2
- data/generators/opensteam/templates/db/migrate/20080609095726_create_inventories.rb +6 -3
- data/generators/opensteam/templates/db/migrate/20080609095728_create_order_items.rb +12 -1
- data/generators/opensteam/templates/db/migrate/20080609095729_create_orders.rb +8 -12
- data/generators/opensteam/templates/db/migrate/20080609095730_create_payment_types.rb +2 -0
- data/generators/opensteam/templates/db/migrate/20080714131513_create_invoices.rb +2 -1
- data/generators/opensteam/templates/db/migrate/20080714131650_create_shipments.rb +3 -1
- data/generators/opensteam/templates/db/migrate/20080808075247_create_containers.rb +30 -0
- data/generators/opensteam/templates/db/migrate/20080808083011_create_container_items.rb +25 -0
- data/generators/opensteam/templates/db/migrate/20080812102727_create_tax_zones.rb +16 -0
- data/generators/opensteam/templates/db/migrate/20080812102858_create_tax_rules.rb +15 -0
- data/generators/opensteam/templates/db/migrate/20080812102956_create_tax_groups.rb +14 -0
- data/generators/opensteam/templates/db/migrate/20080831181436_create_configurations.rb +15 -0
- data/generators/opensteam/templates/db/migrate/20080903131506_create_payments.rb +22 -0
- data/generators/opensteam/templates/db/migrate/20080904133625_create_payment_transactions.rb +24 -0
- data/generators/opensteam/templates/db/migrate/20080916102341_create_zones.rb +19 -0
- data/generators/opensteam/templates/db/migrate/20080916134340_create_region_shipping_rates.rb +18 -0
- data/generators/opensteam/templates/db/migrate/20080916134523_create_shipping_rate_groups.rb +18 -0
- data/generators/opensteam/templates/db/migrate/20080916135226_create_shipping_payment_additions.rb +20 -0
- data/generators/opensteam/templates/db/migrate/20080916135228_init_opensteam_config.rb +60 -0
- data/generators/opensteam/templates/public/images/opensteam_black.jpg +0 -0
- data/generators/opensteam/templates/public/images/pdf.png +0 -0
- data/generators/opensteam/templates/public/images/shader.png +0 -0
- data/generators/opensteam/templates/public/index.html +1 -0
- data/generators/opensteam/templates/public/javascripts/opensteam.js +21 -21
- data/generators/opensteam/templates/public/stylesheets/opensteam_admin.css +291 -0
- data/generators/opensteam/templates/public/stylesheets/opensteam_white.css +47 -11
- data/generators/opensteam/templates/tasks/opensteam.rake +2 -12
- data/generators/opensteam/templates/test/fixtures/addresses.yml +26 -0
- data/generators/opensteam/templates/test/fixtures/configurations.yml +29 -0
- data/generators/opensteam/templates/test/fixtures/inventories.yml +32 -15
- data/generators/opensteam/templates/test/fixtures/profiles.yml +21 -0
- data/generators/opensteam/templates/test/fixtures/region_shipping_rates.yml +33 -0
- data/generators/opensteam/templates/test/fixtures/shipping_payment_additions.yml +91 -0
- data/generators/opensteam/templates/test/fixtures/shipping_rate_groups.yml +25 -0
- data/generators/opensteam/templates/test/fixtures/tax_groups.yml +13 -0
- data/generators/opensteam/templates/test/fixtures/tax_rules.yml +29 -0
- data/generators/opensteam/templates/test/fixtures/tax_zones.yml +33 -0
- data/generators/opensteam/templates/test/fixtures/users.yml +26 -0
- data/generators/opensteam/templates/test/fixtures/zones.yml +2707 -0
- data/generators/opensteam/templates/test/functional/carts_controller_test.rb +103 -0
- data/generators/opensteam/templates/test/test_helper.rb +38 -0
- data/generators/opensteam/templates/test/unit/container_test.rb +71 -0
- data/generators/opensteam/templates/test/unit/order_test.rb +93 -0
- data/generators/opensteam/templates/test/unit/payment_test.rb +220 -0
- data/generators/opensteam/templates/test/unit/product_test.rb +158 -0
- data/generators/opensteam/templates/vendor/plugins/prawnto/.gitignore +3 -0
- data/generators/opensteam/templates/vendor/plugins/prawnto/MIT-LICENSE +20 -0
- data/generators/opensteam/templates/vendor/plugins/prawnto/README +12 -0
- data/generators/opensteam/templates/vendor/plugins/prawnto/Rakefile +22 -0
- data/generators/opensteam/templates/vendor/plugins/prawnto/init.rb +6 -0
- data/generators/opensteam/templates/vendor/plugins/prawnto/lib/prawnto.rb +13 -0
- data/generators/opensteam/templates/vendor/plugins/prawnto/lib/prawnto/action_controller.rb +47 -0
- data/generators/opensteam/templates/vendor/plugins/prawnto/lib/prawnto/template_handler/base.rb +75 -0
- data/generators/opensteam/templates/vendor/plugins/prawnto/lib/prawnto/template_handler/raw.rb +54 -0
- data/generators/opensteam/templates/vendor/plugins/prawnto/tasks/prawnto_tasks.rake +4 -0
- data/generators/opensteam/templates/vendor/plugins/prawnto/test/action_controller_test.rb +36 -0
- data/generators/opensteam/templates/vendor/plugins/prawnto/test/base_template_handler_test.rb +58 -0
- data/generators/opensteam/templates/vendor/plugins/prawnto/test/raw_template_handler_test.rb +163 -0
- data/generators/opensteam/templates/vendor/plugins/prawnto/test/template_handler_test_mocks.rb +83 -0
- data/generators/opensteam_product/templates/views/admin/_attributes.html.erb +8 -3
- data/generators/opensteam_product/templates/views/admin/_inventories.html.erb +2 -0
- data/lib/opensteam.rb +0 -1
- data/lib/opensteam/base.rb +2 -1
- data/lib/opensteam/checkout.rb +3 -12
- data/lib/opensteam/config.rb +50 -2
- data/lib/opensteam/container.rb +196 -0
- data/lib/opensteam/extension_base.rb +19 -1
- data/lib/opensteam/finder.rb +1 -1
- data/lib/opensteam/helpers/config_table_helper.rb +18 -6
- data/lib/opensteam/initializer.rb +24 -4
- data/lib/opensteam/inventory_base.rb +6 -1
- data/lib/opensteam/invoice_base.rb +12 -13
- data/lib/opensteam/money.rb +230 -0
- data/lib/opensteam/order_base.rb +122 -48
- data/lib/opensteam/payment.rb +225 -0
- data/lib/opensteam/payment/advance_payment.rb +34 -0
- data/lib/opensteam/payment/credit_card_payment.rb +217 -0
- data/lib/opensteam/payment/direct_debit_payment.rb +53 -0
- data/lib/opensteam/product_base.rb +48 -12
- data/lib/opensteam/security.rb +54 -0
- data/lib/opensteam/shipment_base.rb +214 -6
- data/lib/opensteam/shopping_cart.rb +20 -300
- data/lib/opensteam/state_logic.rb +5 -3
- data/lib/opensteam/state_machine.rb +8 -3
- data/lib/opensteam/user_base.rb +48 -6
- data/lib/opensteam/version.rb +1 -1
- metadata +122 -16
- data/generators/opensteam/templates/app/controllers/cart_controller.rb +0 -94
- data/generators/opensteam/templates/app/views/admin/orders/_event.html.erb +0 -5
- data/generators/opensteam/templates/app/views/admin/orders/_order_item.html.erb +0 -10
- data/generators/opensteam/templates/app/views/cart/_cart.html.erb +0 -8
- data/generators/opensteam/templates/app/views/cart/_cart_content.html.erb +0 -20
- data/generators/opensteam/templates/app/views/cart/update.rjs +0 -1
- data/generators/opensteam/templates/app/views/checkout/payment.html.erb +0 -8
- data/generators/opensteam/templates/app/views/checkout/shipping.html.erb +0 -45
- data/generators/opensteam/templates/app/views/checkout/show_cart.html.erb +0 -13
- data/generators/opensteam/templates/app/views/checkout/update_cart_content.rjs +0 -2
- data/generators/opensteam/templates/app/views/profile/orders/_order_item.html.erb +0 -10
- data/generators/opensteam/templates/db/migrate/20080609095725_create_dummy_users.rb +0 -21
- data/lib/opensteam/cart_base.rb +0 -227
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
class CartsControllerTest < ActionController::TestCase
|
|
4
|
+
# Replace this with your real tests.
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def test_should_get_index
|
|
9
|
+
get :index
|
|
10
|
+
assert_response :success
|
|
11
|
+
|
|
12
|
+
assert( assigns(:cart) )
|
|
13
|
+
assert_equal(Cart, assigns(:cart).class )
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def test_should_create_item
|
|
17
|
+
post :create, :id => inventories( :inventory_00042).id
|
|
18
|
+
assert_response :redirect
|
|
19
|
+
#follow_redirect
|
|
20
|
+
#assert_response :success
|
|
21
|
+
|
|
22
|
+
assert( assigns(:cart), "not cart assigned")
|
|
23
|
+
assert_equal(1, assigns(:cart).items.size)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def test_should_update_incr_item
|
|
27
|
+
post :create, :id => inventories( :inventory_00042).id
|
|
28
|
+
assert_response :redirect
|
|
29
|
+
#follow_redirect
|
|
30
|
+
#assert_response :success
|
|
31
|
+
|
|
32
|
+
post :update, :id => 0, :incr => 1
|
|
33
|
+
assert_response :redirect
|
|
34
|
+
#follow_redirect
|
|
35
|
+
#assert_response :success
|
|
36
|
+
|
|
37
|
+
assert(assigns(:cart), "cart not assigned")
|
|
38
|
+
assert_equal(1, assigns(:cart).items.size)
|
|
39
|
+
assert_equal(2, assigns(:cart).items.first.quantity)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def test_should_update_decr_item
|
|
45
|
+
post :create, :id => inventories( :inventory_00042).id
|
|
46
|
+
assert_response :redirect
|
|
47
|
+
#follow_redirect
|
|
48
|
+
#assert_response :success
|
|
49
|
+
|
|
50
|
+
post :update, :id => 0, :incr => 1
|
|
51
|
+
assert_response :redirect
|
|
52
|
+
#follow_redirect
|
|
53
|
+
#assert_response :success
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
post :update, :id => 0, :decr => 1
|
|
57
|
+
assert_response :redirect
|
|
58
|
+
#follow_redirect
|
|
59
|
+
#assert_response :success
|
|
60
|
+
|
|
61
|
+
assert(assigns(:cart), "cart not assigned")
|
|
62
|
+
assert_equal(1, assigns(:cart).items.size)
|
|
63
|
+
assert_equal(1, assigns(:cart).items.first.quantity)
|
|
64
|
+
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def test_should_set_quantity
|
|
68
|
+
post :create, :id => inventories( :inventory_00042).id
|
|
69
|
+
assert_response :redirect
|
|
70
|
+
#follow_redirect
|
|
71
|
+
#assert_response :success
|
|
72
|
+
|
|
73
|
+
post :update, :quantity => {"0" => "123" }
|
|
74
|
+
assert_response :redirect
|
|
75
|
+
#follow_redirect
|
|
76
|
+
#assert_response :success
|
|
77
|
+
|
|
78
|
+
assert(assigns(:cart), "cart not assigned")
|
|
79
|
+
assert_equal(1, assigns(:cart).items.size)
|
|
80
|
+
assert_equal(123, assigns(:cart).items.first.quantity)
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def test_should_get_show
|
|
86
|
+
post :create, :id => inventories( :inventory_00042).id
|
|
87
|
+
assert_response :redirect
|
|
88
|
+
#follow_redirect
|
|
89
|
+
#assert_response :success
|
|
90
|
+
|
|
91
|
+
get :show, :id => 0
|
|
92
|
+
assert_response :success
|
|
93
|
+
|
|
94
|
+
assert_not_nil(assigns(:inventory))
|
|
95
|
+
assert_not_nil(assigns(:product))
|
|
96
|
+
assert_not_nil(assigns(:cart_details))
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def test_truth
|
|
101
|
+
assert true
|
|
102
|
+
end
|
|
103
|
+
end
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
ENV["RAILS_ENV"] = "test"
|
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
|
|
3
|
+
require 'test_help'
|
|
4
|
+
|
|
5
|
+
class Test::Unit::TestCase
|
|
6
|
+
# Transactional fixtures accelerate your tests by wrapping each test method
|
|
7
|
+
# in a transaction that's rolled back on completion. This ensures that the
|
|
8
|
+
# test database remains unchanged so your fixtures don't have to be reloaded
|
|
9
|
+
# between every test method. Fewer database queries means faster tests.
|
|
10
|
+
#
|
|
11
|
+
# Read Mike Clark's excellent walkthrough at
|
|
12
|
+
# http://clarkware.com/cgi/blosxom/2005/10/24#Rails10FastTesting
|
|
13
|
+
#
|
|
14
|
+
# Every Active Record database supports transactions except MyISAM tables
|
|
15
|
+
# in MySQL. Turn off transactional fixtures in this case; however, if you
|
|
16
|
+
# don't care one way or the other, switching from MyISAM to InnoDB tables
|
|
17
|
+
# is recommended.
|
|
18
|
+
#
|
|
19
|
+
# The only drawback to using transactional fixtures is when you actually
|
|
20
|
+
# need to test transactions. Since your test is bracketed by a transaction,
|
|
21
|
+
# any transactions started in your code will be automatically rolled back.
|
|
22
|
+
self.use_transactional_fixtures = true
|
|
23
|
+
|
|
24
|
+
# Instantiated fixtures are slow, but give you @david where otherwise you
|
|
25
|
+
# would need people(:david). If you don't want to migrate your existing
|
|
26
|
+
# test cases which use the @david style and don't mind the speed hit (each
|
|
27
|
+
# instantiated fixtures translates to a database query per test method),
|
|
28
|
+
# then set this back to true.
|
|
29
|
+
self.use_instantiated_fixtures = false
|
|
30
|
+
|
|
31
|
+
# Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
|
|
32
|
+
#
|
|
33
|
+
# Note: You'll currently still have to declare fixtures explicitly in integration tests
|
|
34
|
+
# -- they do not yet inherit this setting
|
|
35
|
+
fixtures :all
|
|
36
|
+
|
|
37
|
+
# Add more helper methods to be used by all tests here...
|
|
38
|
+
end
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
class ContainerTest < ActiveSupport::TestCase
|
|
4
|
+
|
|
5
|
+
fixtures :inventories
|
|
6
|
+
|
|
7
|
+
def setup
|
|
8
|
+
@cart = Cart.create
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def test_add_to_cart_and_increment
|
|
12
|
+
|
|
13
|
+
i = @cart.push( inventories( :inventory_00042) )
|
|
14
|
+
assert_not_nil(i)
|
|
15
|
+
|
|
16
|
+
i = @cart.push( inventories(:inventory_00042) )
|
|
17
|
+
assert_not_nil(i)
|
|
18
|
+
assert( i )
|
|
19
|
+
assert_equal( 2, @cart.items.first.quantity )
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def test_find_item
|
|
24
|
+
i = @cart.push( inventories( :inventory_00042) )
|
|
25
|
+
assert_not_nil(i)
|
|
26
|
+
@cart.reload
|
|
27
|
+
assert_equal(i, @cart[0] )
|
|
28
|
+
assert_equal(i, @cart.find_item( inventories( :inventory_00042) ) )
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def test_item_incr_and_decr_with_quantity_check
|
|
33
|
+
i = @cart.push( inventories( :inventory_00042) )
|
|
34
|
+
assert_not_nil(i)
|
|
35
|
+
|
|
36
|
+
assert( i.incr )
|
|
37
|
+
assert_equal(2, @cart.items.first.quantity )
|
|
38
|
+
|
|
39
|
+
assert(i.decr)
|
|
40
|
+
assert_equal(1, i.quantity)
|
|
41
|
+
|
|
42
|
+
assert(i.decr)
|
|
43
|
+
assert(@cart.reload.items.empty?, "items not empty!")
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def test_item_set_quantity
|
|
48
|
+
i = @cart.push( inventories( :inventory_00042) )
|
|
49
|
+
assert_not_nil(i)
|
|
50
|
+
|
|
51
|
+
assert( i.set_quantity(10) )
|
|
52
|
+
assert_equal(10, i.quantity )
|
|
53
|
+
|
|
54
|
+
assert( i.set_quantity(3) )
|
|
55
|
+
assert_equal(3, i.quantity )
|
|
56
|
+
|
|
57
|
+
assert( i.set_quantity(-13) )
|
|
58
|
+
assert(@cart.reload.items.empty?, "items not empty!")
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
# Replace this with your real tests.
|
|
68
|
+
def test_truth
|
|
69
|
+
assert true
|
|
70
|
+
end
|
|
71
|
+
end
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
Address = Opensteam::UserBase::Address
|
|
3
|
+
#User = Opensteam::UserBase::User
|
|
4
|
+
Profile = Opensteam::UserBase::Profile
|
|
5
|
+
|
|
6
|
+
class OrderTest < ActiveSupport::TestCase
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
fixtures :all
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def setup
|
|
13
|
+
@payment_address = addresses(:address_00001)
|
|
14
|
+
@shipping_address = addresses(:address_00002)
|
|
15
|
+
@user = users( :user_00002 )
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def test_order_new
|
|
19
|
+
assert_not_nil(new_order)
|
|
20
|
+
assert_equal([], new_order.items)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def test_save_and_addresses_and_customer_association
|
|
25
|
+
|
|
26
|
+
@order = new_order
|
|
27
|
+
assert( @order.save, "Could not save order")
|
|
28
|
+
|
|
29
|
+
@order.reload
|
|
30
|
+
assert_equal(@user, @order.customer)
|
|
31
|
+
assert_equal(@shipping_address, @order.shipping_address)
|
|
32
|
+
assert_equal(@payment_address, @order.payment_address)
|
|
33
|
+
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def test_move_items_from_cart_to_order
|
|
38
|
+
@inventory = inventories( :inventory_00042 )
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
@order = new_order
|
|
42
|
+
assert @order.save
|
|
43
|
+
|
|
44
|
+
@cart = init_cart
|
|
45
|
+
@cart.items.each do |i|
|
|
46
|
+
i.container = @order
|
|
47
|
+
i.save
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
assert( @cart.reload.items.empty? )
|
|
51
|
+
assert( @order.save )
|
|
52
|
+
@order.reload
|
|
53
|
+
assert( !@order.items.empty? )
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def test_order_create_and_initial_state
|
|
59
|
+
@order = new_order
|
|
60
|
+
assert @order.save
|
|
61
|
+
|
|
62
|
+
assert_equal( @order.class.initialstate.to_sym, @order.state.to_sym )
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def init_cart
|
|
70
|
+
returning( Cart.create ) do |cart|
|
|
71
|
+
cart.push( inventories( :inventory_00042 ) )
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def new_order
|
|
77
|
+
Opensteam::OrderBase::Order.new do |o|
|
|
78
|
+
o.customer = @user
|
|
79
|
+
o.payment_type = "bogus"
|
|
80
|
+
o.shipping_type = "Post"
|
|
81
|
+
o.real_shipping_address = @shipping_address
|
|
82
|
+
o.real_payment_address = @payment_address
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
# Replace this with your real tests.
|
|
90
|
+
def test_truth
|
|
91
|
+
assert true
|
|
92
|
+
end
|
|
93
|
+
end
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
Opensteam::Payment::CreditCardPayment.class_eval do
|
|
5
|
+
|
|
6
|
+
def execute_payment
|
|
7
|
+
return true
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
class PaymentTest < ActiveSupport::TestCase
|
|
14
|
+
# Replace this with your real tests.
|
|
15
|
+
|
|
16
|
+
def test_payment_base_class
|
|
17
|
+
|
|
18
|
+
assert_equal( Array, Opensteam::Payment::Base.payment_types.class )
|
|
19
|
+
assert_equal(:base, Opensteam::Payment::Base.payment_id )
|
|
20
|
+
|
|
21
|
+
assert_equal(Opensteam::Payment::CreditCardPayment,
|
|
22
|
+
Opensteam::Payment::Base[ :credit_card ] )
|
|
23
|
+
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def test_class_inheritable_attribute_for_payment_types
|
|
28
|
+
assert_equal( :credit_card, Opensteam::Payment::CreditCardPayment.payment_id )
|
|
29
|
+
assert_equal( :base, Opensteam::Payment::Base.payment_id )
|
|
30
|
+
|
|
31
|
+
Opensteam::Payment::Base.payment_id = "buha"
|
|
32
|
+
assert_equal( :credit_card, Opensteam::Payment::CreditCardPayment.payment_id )
|
|
33
|
+
assert_equal( "buha", Opensteam::Payment::Base.payment_id )
|
|
34
|
+
Opensteam::Payment::Base.payment_id = :base
|
|
35
|
+
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def test_payment_gateway
|
|
40
|
+
assert(ActiveMerchant::Billing::Base.test?, "ActiveMerchant not in test mode ..")
|
|
41
|
+
cc = Opensteam::Payment::CreditCardPayment.new do |c|
|
|
42
|
+
c.credit_card = credit_card
|
|
43
|
+
end
|
|
44
|
+
assert(cc.save, "Could not save CreditCardPayment Object")
|
|
45
|
+
assert_equal( Opensteam::Payment::CreditCardPayment.gateway_class, cc.gateway.class )
|
|
46
|
+
assert(cc.gateway.test?, "gateway not in test mode" )
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def test_payment_and_credit_card_association
|
|
52
|
+
ccp = Opensteam::Payment::CreditCardPayment.create
|
|
53
|
+
assert_equal([], ccp.transactions )
|
|
54
|
+
ccp = Opensteam::Payment::CreditCardPayment.create
|
|
55
|
+
cchash = { :first_name => 'testfirstname', :last_name => 'testlastname',
|
|
56
|
+
:number => '4111111111111111', :year => 2010, :month => 10, :brand => 'visa' }
|
|
57
|
+
|
|
58
|
+
cc = credit_card
|
|
59
|
+
|
|
60
|
+
if cc.class != ActiveMerchant::Billing::CreditCard
|
|
61
|
+
assert(cc.save )
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
ccp.credit_card = cc
|
|
66
|
+
assert(ccp.save, "Could not save CreditCardPayment")
|
|
67
|
+
assert_equal(cc, ccp.credit_card)
|
|
68
|
+
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def test_successfull_transaction_authorization_with_bogus_gateway
|
|
74
|
+
Opensteam::Payment::CreditCardPayment.gateway_class = ActiveMerchant::Billing::BogusGateway
|
|
75
|
+
|
|
76
|
+
ccp = Opensteam::Payment::CreditCardPayment.new do |c|
|
|
77
|
+
c.credit_card = credit_card( :number => "1" )
|
|
78
|
+
end
|
|
79
|
+
assert ccp.save, "Could not save Payment Object"
|
|
80
|
+
|
|
81
|
+
auth = ccp.authorize( 1.00 )
|
|
82
|
+
|
|
83
|
+
assert auth.success
|
|
84
|
+
assert_equal :authorize, auth.action.to_sym
|
|
85
|
+
assert_equal 100, auth.amount
|
|
86
|
+
assert_equal ActiveMerchant::Billing::BogusGateway::SUCCESS_MESSAGE, auth.message
|
|
87
|
+
assert_equal ActiveMerchant::Billing::BogusGateway::AUTHORIZATION, auth[:reference]
|
|
88
|
+
|
|
89
|
+
#assert_equal( :payment_authorized, ccp.state.to_sym )
|
|
90
|
+
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def test_failed_transaction_authorization_with_bogus_gateway
|
|
95
|
+
Opensteam::Payment::CreditCardPayment.gateway_class = ActiveMerchant::Billing::BogusGateway
|
|
96
|
+
|
|
97
|
+
ccp = Opensteam::Payment::CreditCardPayment.new do |c|
|
|
98
|
+
c.credit_card = credit_card( :number => "2" )
|
|
99
|
+
end
|
|
100
|
+
assert ccp.save, "Could not save Payment Object"
|
|
101
|
+
|
|
102
|
+
auth = ccp.authorize( 1.00 )
|
|
103
|
+
|
|
104
|
+
assert !auth.success
|
|
105
|
+
assert_equal :authorize, auth.action.to_sym
|
|
106
|
+
assert_equal ActiveMerchant::Billing::BogusGateway::FAILURE_MESSAGE, auth.message
|
|
107
|
+
|
|
108
|
+
#assert_equal( :payment_declined, ccp.state.to_sym )
|
|
109
|
+
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
def test_exception_during_transaction_authorization_with_bogus_gateway
|
|
114
|
+
Opensteam::Payment::CreditCardPayment.gateway_class = ActiveMerchant::Billing::BogusGateway
|
|
115
|
+
|
|
116
|
+
ccp = Opensteam::Payment::CreditCardPayment.new do |c|
|
|
117
|
+
c.credit_card = credit_card( :number => "3" )
|
|
118
|
+
end
|
|
119
|
+
assert ccp.save, "Could not save Payment Object"
|
|
120
|
+
|
|
121
|
+
auth = ccp.authorize( 1.00 )
|
|
122
|
+
|
|
123
|
+
assert !auth.success
|
|
124
|
+
assert_equal :authorize, auth.action.to_sym
|
|
125
|
+
assert_equal ActiveMerchant::Billing::BogusGateway::ERROR_MESSAGE, auth.message
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
def test_successfull_capture_transaction_with_bogus_gateway
|
|
130
|
+
Opensteam::Payment::CreditCardPayment.gateway_class = ActiveMerchant::Billing::BogusGateway
|
|
131
|
+
|
|
132
|
+
ccp = Opensteam::Payment::CreditCardPayment.new { |c| c.credit_card = credit_card }
|
|
133
|
+
|
|
134
|
+
assert(ccp.save, "Could not save Payment Object")
|
|
135
|
+
|
|
136
|
+
capt = ccp.capture( 1.00, '123' )
|
|
137
|
+
|
|
138
|
+
assert capt.success
|
|
139
|
+
assert_equal :capture, capt.action.to_sym
|
|
140
|
+
assert_equal ActiveMerchant::Billing::BogusGateway::SUCCESS_MESSAGE, capt.message
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
def test_failed_capture_transaction_with_bogus_gateway
|
|
146
|
+
Opensteam::Payment::CreditCardPayment.gateway_class = ActiveMerchant::Billing::BogusGateway
|
|
147
|
+
ccp = Opensteam::Payment::CreditCardPayment.new( :set_credit_card => credit_card_hash )
|
|
148
|
+
assert(ccp.save, "Could not save Payment Object")
|
|
149
|
+
|
|
150
|
+
capt = ccp.capture( 1.00, '2' )
|
|
151
|
+
|
|
152
|
+
assert !capt.success
|
|
153
|
+
assert_equal :capture, capt.action.to_sym
|
|
154
|
+
assert_equal ActiveMerchant::Billing::BogusGateway::FAILURE_MESSAGE, capt.message
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
def test_exception_during_capture_transaction_with_bogus_gateway
|
|
161
|
+
Opensteam::Payment::CreditCardPayment.gateway_class = ActiveMerchant::Billing::BogusGateway
|
|
162
|
+
ccp = Opensteam::Payment::CreditCardPayment.new
|
|
163
|
+
ccp.credit_card = credit_card
|
|
164
|
+
assert(ccp.save, "Could not save Payment Object")
|
|
165
|
+
|
|
166
|
+
capt = ccp.capture( 1.00, '1' )
|
|
167
|
+
|
|
168
|
+
assert !capt.success
|
|
169
|
+
assert_equal :capture, capt.action.to_sym
|
|
170
|
+
assert_equal ActiveMerchant::Billing::BogusGateway::CAPTURE_ERROR_MESSAGE,
|
|
171
|
+
capt.message
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
def test_create_credit_card_through_payment_object
|
|
177
|
+
Opensteam::Payment::CreditCardPayment.gateway_class = ActiveMerchant::Billing::BogusGateway
|
|
178
|
+
ccp = Opensteam::Payment::CreditCardPayment.new
|
|
179
|
+
ccp.set_credit_card = credit_card_hash
|
|
180
|
+
assert( ccp.save )
|
|
181
|
+
assert_not_nil( ccp.credit_card )
|
|
182
|
+
assert( ccp.errors.empty? )
|
|
183
|
+
assert( ccp.credit_card.errors.empty? )
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
end
|
|
187
|
+
|
|
188
|
+
def test_create_credit_card_through_payment_object_with_errors
|
|
189
|
+
Opensteam::Payment::CreditCardPayment.gateway_class = ActiveMerchant::Billing::BogusGateway
|
|
190
|
+
ccp = Opensteam::Payment::CreditCardPayment.new
|
|
191
|
+
ccp.set_credit_card = credit_card_hash( :month => "" )
|
|
192
|
+
assert( !ccp.save )
|
|
193
|
+
end
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
def credit_card_hash( options = {} )
|
|
198
|
+
{
|
|
199
|
+
:first_name => "testfirstname",
|
|
200
|
+
:last_name => "testlastname",
|
|
201
|
+
:number => '4111111111111111',
|
|
202
|
+
:month => 10,
|
|
203
|
+
:year => 2010,
|
|
204
|
+
:type => 'bogus'
|
|
205
|
+
}.update( options )
|
|
206
|
+
end
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
def credit_card( options = {} )
|
|
210
|
+
#Opensteam::Payment::CreditCard.new( credit_card_hash( options ) )
|
|
211
|
+
ActiveMerchant::Billing::CreditCard.new( credit_card_hash( options ) )
|
|
212
|
+
end
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
def test_truth
|
|
218
|
+
assert true
|
|
219
|
+
end
|
|
220
|
+
end
|