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,158 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
class ProductTest < ActiveSupport::TestCase
|
|
4
|
+
|
|
5
|
+
fixtures :inventories
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def test_table_prefix
|
|
9
|
+
assert_equal( Opensteam::Config::PRODUCT_BASE_TABLE_PREFIX.to_s, DogFood.table_prefix )
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def test_create_product_without_properties
|
|
13
|
+
c = Animal.new( :type => "Dog" )
|
|
14
|
+
assert( c.save )
|
|
15
|
+
assert_equal(0, c.inventories.size)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
c = Animal.new( :type => "Dog", :set_properties => [] )
|
|
19
|
+
assert( c.save )
|
|
20
|
+
assert_equal(1, c.inventories.size)
|
|
21
|
+
assert_equal(0, c.inventories.first.storage)
|
|
22
|
+
assert_equal(0, c.inventories.first.active )
|
|
23
|
+
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def test_create_product_with_properties
|
|
28
|
+
weights = [ Weight.first.id.to_s ]
|
|
29
|
+
dog_kinds = [ DogKind.first.id.to_s ]
|
|
30
|
+
c = DogFood.new( :name => "ttest", :set_properties => { "weight" => weights, "dog_kinds" => dog_kinds } )
|
|
31
|
+
|
|
32
|
+
assert( c.save )
|
|
33
|
+
assert_equal(1, c.inventories.size)
|
|
34
|
+
assert_equal(0, c.inventories.first.storage)
|
|
35
|
+
assert_equal(0, c.inventories.first.active )
|
|
36
|
+
|
|
37
|
+
assert_equal( 2, Array( c.properties ).size )
|
|
38
|
+
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def test_create_product_with_invalid_properties
|
|
43
|
+
assert_raise(Opensteam::Config::Errors::NotAProperty ) {
|
|
44
|
+
DogFood.new( :name => "test", :set_properties => { "string" => [ 1,2 ] } )
|
|
45
|
+
}
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def test_add_properties
|
|
49
|
+
c = DogFood.new( :name => "test" )
|
|
50
|
+
assert( c.save )
|
|
51
|
+
|
|
52
|
+
c.add_properties( [ Weight.first ] )
|
|
53
|
+
assert_equal(1, Array( c.properties ).size )
|
|
54
|
+
assert_equal(1, Array( c.inventories ).size )
|
|
55
|
+
assert_equal(c.inventories, c.inventories( [Weight.first] ) )
|
|
56
|
+
|
|
57
|
+
c.add_properties( [ Weight.first ] )
|
|
58
|
+
assert_equal(1, Array( c.properties ).size )
|
|
59
|
+
assert_equal(1, Array( c.inventories ).size )
|
|
60
|
+
assert_equal(c.inventories, c.inventories( [Weight.first] ) )
|
|
61
|
+
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def test_edit_product_and_update_properties
|
|
65
|
+
weights = [ Weight.first.id.to_s, Weight.last.id.to_s ]
|
|
66
|
+
dog_kinds = [ DogKind.first.id.to_s, DogKind.last.id.to_s ]
|
|
67
|
+
assert_not_nil( c = DogFood.new( :name => "ttest", :set_properties => { "weight" => weights, "dog_kinds" => dog_kinds } ) )
|
|
68
|
+
assert c.save
|
|
69
|
+
assert_equal(4, c.inventories.size)
|
|
70
|
+
assert_equal(4, Array( c.properties ).size )
|
|
71
|
+
dd = [ DogKind.last.id.to_s ]
|
|
72
|
+
c.set_properties = { "weight" => weights, "dog_kinds" => dd }
|
|
73
|
+
c.reload
|
|
74
|
+
assert_equal(2, c.inventories.size )
|
|
75
|
+
assert_equal(3, Array(c.properties).size )
|
|
76
|
+
assert_equal([], c.inventories( [Weight.first, DogKind.first]))
|
|
77
|
+
assert(!Array(c.properties).include?( DogKind.first ) )
|
|
78
|
+
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def test_delete_inventory_by_properties
|
|
83
|
+
c = DogFood.new( :name => "test" )
|
|
84
|
+
assert( c.save )
|
|
85
|
+
|
|
86
|
+
c.add_properties( [ Weight.first ] )
|
|
87
|
+
assert_equal(1, Array( c.properties ).size )
|
|
88
|
+
assert_equal(1, Array( c.inventories ).size )
|
|
89
|
+
assert_equal(c.inventories, c.inventories( [Weight.first] ) )
|
|
90
|
+
|
|
91
|
+
c.del_properties( Weight.first )
|
|
92
|
+
c.reload
|
|
93
|
+
assert_equal(0, Array( c.properties ).size )
|
|
94
|
+
assert_equal(0, Array( c.inventories ).size )
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def test_create_product_with_properties_and_perm
|
|
99
|
+
weights = [ Weight.first.id.to_s, Weight.last.id.to_s ]
|
|
100
|
+
dog_kinds = [ DogKind.first.id.to_s, DogKind.last.id.to_s ]
|
|
101
|
+
c = DogFood.new( :name => "ttest", :set_properties => { "weight" => weights, "dog_kinds" => dog_kinds } )
|
|
102
|
+
|
|
103
|
+
assert( c.save )
|
|
104
|
+
assert_equal(4, c.inventories.size)
|
|
105
|
+
assert_equal(0, c.inventories.first.storage)
|
|
106
|
+
assert_equal(0, c.inventories.last.active )
|
|
107
|
+
|
|
108
|
+
assert_equal( 4, Array( c.properties ).size )
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
def test_create_product_and_verify_inventory_search
|
|
114
|
+
weights = [ Weight.first.id.to_s, Weight.last.id.to_s ]
|
|
115
|
+
dog_kinds = [ DogKind.first.id.to_s, DogKind.last.id.to_s ]
|
|
116
|
+
|
|
117
|
+
c = DogFood.new( :name => "ttest", :set_properties => { "weight" => weights, "dog_kinds" => dog_kinds } )
|
|
118
|
+
assert c
|
|
119
|
+
assert c.save
|
|
120
|
+
|
|
121
|
+
assert_equal(4, c.inventories.size)
|
|
122
|
+
assert_equal(0, c.inventories.first.storage)
|
|
123
|
+
assert_equal(0, c.inventories.last.active )
|
|
124
|
+
assert_equal( 4, Array( c.properties ).size )
|
|
125
|
+
|
|
126
|
+
i = c.inventories.first
|
|
127
|
+
|
|
128
|
+
assert_equal([i], c.inventories( i.properties ) )
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
def test_create_product_and_test_crud_inventory
|
|
135
|
+
weights = [ Weight.first.id.to_s, Weight.last.id.to_s ]
|
|
136
|
+
dog_kinds = [ DogKind.first.id.to_s, DogKind.last.id.to_s ]
|
|
137
|
+
|
|
138
|
+
c = DogFood.new( :name => "ttest", :set_properties => { "weight" => weights, "dog_kinds" => dog_kinds } )
|
|
139
|
+
assert c
|
|
140
|
+
assert c.save
|
|
141
|
+
|
|
142
|
+
assert c.inventories.first.update_attributes( :storage => 123, :active => 1 )
|
|
143
|
+
c.selected_inventory = c.inventories.first
|
|
144
|
+
assert_not_nil( c.selected_inventories )
|
|
145
|
+
assert c.is_available?
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
# Replace this with your real tests.
|
|
155
|
+
def test_truth
|
|
156
|
+
assert true
|
|
157
|
+
end
|
|
158
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Copyright (c) 2008 cracklabs.com
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
4
|
+
a copy of this software and associated documentation files (the
|
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
9
|
+
the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be
|
|
12
|
+
included in all copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
Prawnto
|
|
2
|
+
=======
|
|
3
|
+
|
|
4
|
+
a rails (2.1) plugin, providing templating abilities
|
|
5
|
+
for generating pdf files leveraging the new kick-ass prawn library
|
|
6
|
+
|
|
7
|
+
full documentation/demos at: http://cracklabs.com/prawnto
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
Copyright (c) 2008 cracklabs.com, released under the MIT license
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
require 'rake'
|
|
2
|
+
require 'rake/testtask'
|
|
3
|
+
require 'rake/rdoctask'
|
|
4
|
+
|
|
5
|
+
desc 'Default: run unit tests.'
|
|
6
|
+
task :default => :test
|
|
7
|
+
|
|
8
|
+
desc 'Test the prawnto plugin.'
|
|
9
|
+
Rake::TestTask.new(:test) do |t|
|
|
10
|
+
t.libs << 'lib'
|
|
11
|
+
t.pattern = 'test/**/*_test.rb'
|
|
12
|
+
t.verbose = true
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
desc 'Generate documentation for the prawnto plugin.'
|
|
16
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
|
17
|
+
rdoc.rdoc_dir = 'rdoc'
|
|
18
|
+
rdoc.title = 'Prawnto'
|
|
19
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
|
20
|
+
rdoc.rdoc_files.include('README')
|
|
21
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
|
22
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
require 'prawn'
|
|
2
|
+
require 'prawnto/action_controller'
|
|
3
|
+
|
|
4
|
+
require 'prawnto/template_handler/base'
|
|
5
|
+
require 'prawnto/template_handler/raw'
|
|
6
|
+
|
|
7
|
+
# for now applying to all Controllers
|
|
8
|
+
# however, could reduce footprint by letting user mixin (i.e. include) only into controllers that need it
|
|
9
|
+
# but does it really matter performance wise to include in a controller that doesn't need it? doubtful-- depends how much of a hit the before_filter is i guess..
|
|
10
|
+
class ActionController::Base
|
|
11
|
+
include Prawnto::ActionController
|
|
12
|
+
end
|
|
13
|
+
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
module Prawnto
|
|
2
|
+
module ActionController
|
|
3
|
+
|
|
4
|
+
def self.included(base)
|
|
5
|
+
base.extend ClassMethods
|
|
6
|
+
base.before_filter :reset_prawnto_options
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
module ClassMethods
|
|
10
|
+
def prawnto(options)
|
|
11
|
+
prawn_options, prawnto_options = breakdown_prawnto_options options
|
|
12
|
+
write_inheritable_hash(:prawn, prawn_options)
|
|
13
|
+
write_inheritable_hash(:prawnto, prawnto_options)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
private
|
|
17
|
+
|
|
18
|
+
def breakdown_prawnto_options(options)
|
|
19
|
+
prawnto_options = options.dup
|
|
20
|
+
prawn_options = (prawnto_options.delete(:prawn) || {}).dup
|
|
21
|
+
[prawn_options, prawnto_options]
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def prawnto(options)
|
|
26
|
+
@prawnto_options.merge! options
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
private
|
|
31
|
+
|
|
32
|
+
def reset_prawnto_options
|
|
33
|
+
@prawnto_options = {:inline=> true}
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def compute_prawnto_options
|
|
37
|
+
@prawnto_options ||= reset_prawnto_options
|
|
38
|
+
@prawnto_options[:prawn] ||= {}
|
|
39
|
+
@prawnto_options[:prawn].merge!(self.class.read_inheritable_attribute(:prawn) || {}) {|k,o,n| o}
|
|
40
|
+
@prawnto_options.merge!(self.class.read_inheritable_attribute(:prawnto) || {}) {|k,o,n| o}
|
|
41
|
+
@prawnto_options
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
|
data/generators/opensteam/templates/vendor/plugins/prawnto/lib/prawnto/template_handler/base.rb
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
module Prawnto
|
|
2
|
+
module TemplateHandler
|
|
3
|
+
class Base < ActionView::TemplateHandler
|
|
4
|
+
|
|
5
|
+
attr_reader :prawnto_options
|
|
6
|
+
|
|
7
|
+
# TODO: kept around from railspdf-- maybe not needed anymore? should check.
|
|
8
|
+
def ie_request?
|
|
9
|
+
@view.request.env['HTTP_USER_AGENT'] =~ /msie/i
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
# TODO: kept around from railspdf-- maybe not needed anymore? should check.
|
|
13
|
+
def set_pragma
|
|
14
|
+
@view.headers['Pragma'] ||= ie_request? ? 'no-cache' : ''
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
# TODO: kept around from railspdf-- maybe not needed anymore? should check.
|
|
18
|
+
def set_cache_control
|
|
19
|
+
@view.headers['Cache-Control'] ||= ie_request? ? 'no-cache, must-revalidate' : ''
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def set_content_type
|
|
23
|
+
@view.response.content_type = Mime::PDF
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def set_disposition
|
|
27
|
+
inline = 'attachment'
|
|
28
|
+
# inline = @prawnto_options[:inline] ? 'inline' : 'attachment'
|
|
29
|
+
filename = @prawnto_options[:filename] ? "filename=#{@prawnto_options[:filename]}" : nil
|
|
30
|
+
@view.headers["Content-Disposition"] = [inline,filename].compact.join(';')
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def build_headers
|
|
34
|
+
set_pragma
|
|
35
|
+
set_cache_control
|
|
36
|
+
set_content_type
|
|
37
|
+
set_disposition
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def build_source_to_establish_locals(template)
|
|
41
|
+
prawnto_locals = {}
|
|
42
|
+
if dsl = @prawnto_options[:dsl]
|
|
43
|
+
if dsl.kind_of?(Array)
|
|
44
|
+
dsl.each {|v| v = v.to_s.gsub(/^@/,''); prawnto_locals[v]="@#{v}"}
|
|
45
|
+
elsif dsl.kind_of?(Hash)
|
|
46
|
+
prawnto_locals.merge!(dsl)
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
prawnto_locals.merge!(template.locals)
|
|
50
|
+
prawnto_locals.map {|k,v| "#{k} = #{v};"}.join("")
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def pull_prawnto_options
|
|
54
|
+
@prawnto_options = @view.controller.send :compute_prawnto_options
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def render(template)
|
|
58
|
+
pull_prawnto_options
|
|
59
|
+
build_headers
|
|
60
|
+
|
|
61
|
+
source = build_source_to_establish_locals(template)
|
|
62
|
+
if @prawnto_options[:dsl]
|
|
63
|
+
source += "pdf.instance_eval do\n#{template.source}\nend"
|
|
64
|
+
else
|
|
65
|
+
source += "\n#{template.source}"
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
pdf = Prawn::Document.new(@prawnto_options[:prawn])
|
|
69
|
+
@view.instance_eval source, template.filename, 1
|
|
70
|
+
pdf.render
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
end
|
data/generators/opensteam/templates/vendor/plugins/prawnto/lib/prawnto/template_handler/raw.rb
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
module Prawnto
|
|
2
|
+
module TemplateHandler
|
|
3
|
+
class Raw < Base
|
|
4
|
+
|
|
5
|
+
attr_reader :run_environment
|
|
6
|
+
|
|
7
|
+
GENERATE_REGULAR_EXPRESSION = /^\s*Prawn\:\:Document\.generate(\(?)(.*?)(\,(.*))?(\s*\)?\s+do(.*?))$/m
|
|
8
|
+
RENDER_FILE_REGULAR_EXPRESSION = /(\w+)\.render_file\(?(.*?)\)?\s*$/
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def render(template)
|
|
12
|
+
setup_run_environment
|
|
13
|
+
pull_prawnto_options
|
|
14
|
+
source,filename = massage_template_source(template)
|
|
15
|
+
@prawnto_options[:filename] = filename if filename
|
|
16
|
+
build_headers
|
|
17
|
+
@run_environment.instance_eval(source, template.filename, 0) #run in anonymous class
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
protected
|
|
22
|
+
|
|
23
|
+
def setup_run_environment
|
|
24
|
+
@run_environment = Object.new
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def massage_template_source(template)
|
|
28
|
+
source = template.source
|
|
29
|
+
variable_name = '_pdf'
|
|
30
|
+
filename = nil
|
|
31
|
+
|
|
32
|
+
source.gsub! /^(\s*?)(\$LOAD_PATH)/, '\1#\2'
|
|
33
|
+
source.gsub! /^(\s*?)(require\(?\s*['"]rubygems['"]\s*\)?\s*)$/, '\1#\2'
|
|
34
|
+
source.gsub! /^(\s*?)(require\(?\s*['"]prawn['"]\s*\)?\s*)$/, '\1#\2'
|
|
35
|
+
|
|
36
|
+
if (source =~ GENERATE_REGULAR_EXPRESSION)
|
|
37
|
+
filename = $2
|
|
38
|
+
source.sub! GENERATE_REGULAR_EXPRESSION, "#{variable_name} = Prawn::Document.new\\1\\4\\5"
|
|
39
|
+
elsif (source =~ RENDER_FILE_REGULAR_EXPRESSION)
|
|
40
|
+
variable_name = $1
|
|
41
|
+
filename = $2
|
|
42
|
+
source.sub! RENDER_FILE_REGULAR_EXPRESSION, '#\0'
|
|
43
|
+
end
|
|
44
|
+
source.gsub! /^(\s*)(class\s|def\s).*?\n\1end/m do |match|
|
|
45
|
+
eval "class <<@run_environment; #{match}; end;"
|
|
46
|
+
"\n" * match.count("\n")
|
|
47
|
+
end
|
|
48
|
+
source += "\n[#{variable_name}.render,#{filename}]\n"
|
|
49
|
+
source
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
require 'rubygems'
|
|
2
|
+
require 'action_controller'
|
|
3
|
+
require 'action_view'
|
|
4
|
+
|
|
5
|
+
require 'test/unit'
|
|
6
|
+
require File.dirname(__FILE__) + '/../lib/prawnto'
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class ActionControllerTest < Test::Unit::TestCase
|
|
10
|
+
|
|
11
|
+
def setup
|
|
12
|
+
@controller_class = Class.new(ActionController::Base)
|
|
13
|
+
|
|
14
|
+
# for some reason using the following as a block in the preceding statement is somehow different?
|
|
15
|
+
@controller_class.module_eval do
|
|
16
|
+
prawnto :inline=>true, :prawn=>{:page_orientation=>:landscape}
|
|
17
|
+
|
|
18
|
+
def test
|
|
19
|
+
prawnto :inline=>false, :prawn=>{:page_size=>'A4'}
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def test_inheritable_options
|
|
25
|
+
assert_equal({:page_orientation=>:landscape}, @controller_class.read_inheritable_attribute(:prawn))
|
|
26
|
+
assert_equal({:inline=>true}, @controller_class.read_inheritable_attribute(:prawnto))
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def test_computed_options
|
|
30
|
+
controller = @controller_class.new
|
|
31
|
+
controller.test
|
|
32
|
+
assert_equal({:inline=>false, :prawn=>{:page_orientation=>:landscape, :page_size=>'A4'}}, controller.send(:compute_prawnto_options))
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
end
|
|
36
|
+
|