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.
Files changed (213) hide show
  1. data/CHANGELOG +53 -0
  2. data/README.rdoc +19 -10
  3. data/generators/opensteam/opensteam_generator.rb +27 -3
  4. data/generators/opensteam/templates/app/controllers/admin/configurations_controller.rb +85 -0
  5. data/generators/opensteam/templates/app/controllers/admin/inventories_controller.rb +1 -1
  6. data/generators/opensteam/templates/app/controllers/admin/invoices_controller.rb +35 -4
  7. data/generators/opensteam/templates/app/controllers/admin/orders_controller.rb +5 -4
  8. data/generators/opensteam/templates/app/controllers/admin/shipments_controller.rb +6 -3
  9. data/generators/opensteam/templates/app/controllers/admin/shipping_rate_groups_controller.rb +76 -0
  10. data/generators/opensteam/templates/app/controllers/admin/tax_groups_controller.rb +124 -0
  11. data/generators/opensteam/templates/app/controllers/admin/tax_rules_controller.rb +19 -0
  12. data/generators/opensteam/templates/app/controllers/admin/tax_zones_controller.rb +118 -0
  13. data/generators/opensteam/templates/app/controllers/admin/users_controller.rb +1 -1
  14. data/generators/opensteam/templates/app/controllers/admin_controller.rb +20 -0
  15. data/generators/opensteam/templates/app/controllers/carts_controller.rb +118 -0
  16. data/generators/opensteam/templates/app/controllers/checkout_controller.rb +119 -79
  17. data/generators/opensteam/templates/app/controllers/profile_controller.rb +2 -4
  18. data/generators/opensteam/templates/app/controllers/searches_controller.rb +1 -1
  19. data/generators/opensteam/templates/app/controllers/user_sessions_controller.rb +2 -1
  20. data/generators/opensteam/templates/app/controllers/users_controller.rb +10 -3
  21. data/generators/opensteam/templates/app/helpers/admin_helper.rb +15 -1
  22. data/generators/opensteam/templates/app/helpers/checkout_helper.rb +38 -0
  23. data/generators/opensteam/templates/app/helpers/webshop_helper.rb +6 -1
  24. data/generators/opensteam/templates/app/models/zone.rb +18 -0
  25. data/generators/opensteam/templates/app/views/admin/_menu.html.erb +18 -0
  26. data/generators/opensteam/templates/app/views/admin/catalog.html.erb +2 -3
  27. data/generators/opensteam/templates/app/views/admin/configurations/edit.html.erb +20 -0
  28. data/generators/opensteam/templates/app/views/admin/configurations/index.html.erb +22 -0
  29. data/generators/opensteam/templates/app/views/admin/configurations/new.html.erb +19 -0
  30. data/generators/opensteam/templates/app/views/admin/configurations/show.html.erb +13 -0
  31. data/generators/opensteam/templates/app/views/admin/filters/_filter.html.erb +1 -1
  32. data/generators/opensteam/templates/app/views/admin/index.html.erb +0 -19
  33. data/generators/opensteam/templates/app/views/admin/inventories/edit.html.erb +10 -6
  34. data/generators/opensteam/templates/app/views/admin/inventories/new.html.erb +5 -0
  35. data/generators/opensteam/templates/app/views/admin/inventories/show.html.erb +10 -6
  36. data/generators/opensteam/templates/app/views/admin/invoices/_invoice.html.erb +1 -0
  37. data/generators/opensteam/templates/app/views/admin/invoices/_invoice_fields.html.erb +52 -0
  38. data/generators/opensteam/templates/app/views/admin/invoices/new.html.erb +9 -37
  39. data/generators/opensteam/templates/app/views/admin/invoices/show.html.erb +10 -36
  40. data/generators/opensteam/templates/app/views/admin/invoices/show.pdf.prawn +59 -0
  41. data/generators/opensteam/templates/app/views/admin/order_config.html.erb +5 -0
  42. data/generators/opensteam/templates/app/views/admin/order_items/_item_entry.html.erb +9 -0
  43. data/generators/opensteam/templates/app/views/admin/order_items/_items_table.html.erb +16 -0
  44. data/generators/opensteam/templates/app/views/admin/orders/_order.html.erb +9 -9
  45. data/generators/opensteam/templates/app/views/admin/orders/_orders.html.erb +1 -1
  46. data/generators/opensteam/templates/app/views/admin/orders/show.html.erb +25 -9
  47. data/generators/opensteam/templates/app/views/admin/payment_types.html.erb +27 -0
  48. data/generators/opensteam/templates/app/views/admin/payments/_credit_card_payment.html.erb +26 -0
  49. data/generators/opensteam/templates/app/views/admin/payments/_credit_card_payment_info.html.erb +15 -0
  50. data/generators/opensteam/templates/app/views/admin/payments/_direct_debit_payment.html.erb +5 -0
  51. data/generators/opensteam/templates/app/views/admin/shipments/new.html.erb +45 -30
  52. data/generators/opensteam/templates/app/views/admin/shipments/show.html.erb +3 -3
  53. data/generators/opensteam/templates/app/views/admin/shipping_rate_groups/_payment_addition.html.erb +12 -0
  54. data/generators/opensteam/templates/app/views/admin/shipping_rate_groups/_rate.html.erb +16 -0
  55. data/generators/opensteam/templates/app/views/admin/shipping_rate_groups/edit.html.erb +63 -0
  56. data/generators/opensteam/templates/app/views/admin/shipping_rate_groups/index.html.erb +28 -0
  57. data/generators/opensteam/templates/app/views/admin/shipping_rate_groups/new.html.erb +60 -0
  58. data/generators/opensteam/templates/app/views/admin/shipping_rate_groups/show.html.erb +13 -0
  59. data/generators/opensteam/templates/app/views/admin/system.html.erb +5 -0
  60. data/generators/opensteam/templates/app/views/admin/tax_groups/_attributes.html.erb +11 -0
  61. data/generators/opensteam/templates/app/views/admin/tax_groups/_tax_groups.html.erb +17 -0
  62. data/generators/opensteam/templates/app/views/admin/tax_groups/_tax_groups_row.html.erb +12 -0
  63. data/generators/opensteam/templates/app/views/admin/tax_groups/_tax_rule.html.erb +14 -0
  64. data/generators/opensteam/templates/app/views/admin/tax_groups/edit.html.erb +26 -0
  65. data/generators/opensteam/templates/app/views/admin/tax_groups/index.html.erb +8 -0
  66. data/generators/opensteam/templates/app/views/admin/tax_groups/new.html.erb +27 -0
  67. data/generators/opensteam/templates/app/views/admin/tax_groups/show.html.erb +28 -0
  68. data/generators/opensteam/templates/app/views/admin/tax_zones/_attributes.html.erb +18 -0
  69. data/generators/opensteam/templates/app/views/admin/tax_zones/_tax_zone_row.html.erb +13 -0
  70. data/generators/opensteam/templates/app/views/admin/tax_zones/_tax_zones.html.erb +11 -0
  71. data/generators/opensteam/templates/app/views/admin/tax_zones/edit.html.erb +16 -0
  72. data/generators/opensteam/templates/app/views/admin/tax_zones/index.html.erb +16 -0
  73. data/generators/opensteam/templates/app/views/admin/tax_zones/new.html.erb +14 -0
  74. data/generators/opensteam/templates/app/views/admin/tax_zones/show.html.erb +15 -0
  75. data/generators/opensteam/templates/app/views/admin/users.html.erb +0 -1
  76. data/generators/opensteam/templates/app/views/admin/users/show.html.erb +10 -0
  77. data/generators/opensteam/templates/app/views/administration_mailer/order_customer.erb +1 -1
  78. data/generators/opensteam/templates/app/views/carts/_cart.html.erb +7 -0
  79. data/generators/opensteam/templates/app/views/carts/_cart_content.html.erb +45 -0
  80. data/generators/opensteam/templates/app/views/carts/create.rjs +3 -0
  81. data/generators/opensteam/templates/app/views/{cart → carts}/index.html.erb +0 -0
  82. data/generators/opensteam/templates/app/views/carts/update.rjs +11 -0
  83. data/generators/opensteam/templates/app/views/checkout/_address.html.erb +42 -0
  84. data/generators/opensteam/templates/app/views/checkout/_customer.html.erb +31 -0
  85. data/generators/opensteam/templates/app/views/checkout/_edit_checkout.html.erb +42 -0
  86. data/generators/opensteam/templates/app/views/checkout/_new_checkout.html.erb +44 -0
  87. data/generators/opensteam/templates/app/views/checkout/_shipping_buttons.html.erb +8 -0
  88. data/generators/opensteam/templates/app/views/checkout/edit.html.erb +7 -0
  89. data/generators/opensteam/templates/app/views/checkout/new.html.erb +11 -0
  90. data/generators/opensteam/templates/app/views/checkout/outro.html.erb +1 -4
  91. data/generators/opensteam/templates/app/views/checkout/show.html.erb +63 -0
  92. data/generators/opensteam/templates/app/views/common/_header_admin.html.erb +5 -0
  93. data/generators/opensteam/templates/app/views/layouts/admin.html.erb +28 -12
  94. data/generators/opensteam/templates/app/views/layouts/profile.html.erb +2 -2
  95. data/generators/opensteam/templates/app/views/layouts/webshop.html.erb +5 -4
  96. data/generators/opensteam/templates/app/views/payment/_advance_payment_payment.html.erb +1 -0
  97. data/generators/opensteam/templates/app/views/payment/_credit_card_payment.html.erb +37 -0
  98. data/generators/opensteam/templates/app/views/payment/_credit_card_payment_confirmation.html.erb +20 -0
  99. data/generators/opensteam/templates/app/views/payment/_direct_debit_payment.html.erb +5 -0
  100. data/generators/opensteam/templates/app/views/payment/_direct_debit_payment_confirmation.html.erb +5 -0
  101. data/generators/opensteam/templates/app/views/profile/index.html.erb +1 -1
  102. data/generators/opensteam/templates/app/views/profile/infos/edit.html.erb +20 -12
  103. data/generators/opensteam/templates/app/views/profile/infos/edit_password.html.erb +16 -12
  104. data/generators/opensteam/templates/app/views/profile/orders/_order.html.erb +1 -1
  105. data/generators/opensteam/templates/app/views/profile/orders/show.html.erb +10 -7
  106. data/generators/opensteam/templates/app/views/webshop/_inventory_content.html.erb +1 -0
  107. data/generators/opensteam/templates/app/views/webshop/show.html.erb +3 -1
  108. data/generators/opensteam/templates/config/initializers/init_states.rb +13 -24
  109. data/generators/opensteam/templates/config/initializers/opensteam.rb +41 -0
  110. data/generators/opensteam/templates/config/initializers/opensteam_model_tables.rb +49 -10
  111. data/generators/opensteam/templates/config/initializers/opensteam_security.rb +8 -0
  112. data/generators/opensteam/templates/config/initializers/payment_process.rb +37 -0
  113. data/generators/opensteam/templates/db/migrate/20080609095723_create_addresses.rb +8 -2
  114. data/generators/opensteam/templates/db/migrate/20080609095726_create_inventories.rb +6 -3
  115. data/generators/opensteam/templates/db/migrate/20080609095728_create_order_items.rb +12 -1
  116. data/generators/opensteam/templates/db/migrate/20080609095729_create_orders.rb +8 -12
  117. data/generators/opensteam/templates/db/migrate/20080609095730_create_payment_types.rb +2 -0
  118. data/generators/opensteam/templates/db/migrate/20080714131513_create_invoices.rb +2 -1
  119. data/generators/opensteam/templates/db/migrate/20080714131650_create_shipments.rb +3 -1
  120. data/generators/opensteam/templates/db/migrate/20080808075247_create_containers.rb +30 -0
  121. data/generators/opensteam/templates/db/migrate/20080808083011_create_container_items.rb +25 -0
  122. data/generators/opensteam/templates/db/migrate/20080812102727_create_tax_zones.rb +16 -0
  123. data/generators/opensteam/templates/db/migrate/20080812102858_create_tax_rules.rb +15 -0
  124. data/generators/opensteam/templates/db/migrate/20080812102956_create_tax_groups.rb +14 -0
  125. data/generators/opensteam/templates/db/migrate/20080831181436_create_configurations.rb +15 -0
  126. data/generators/opensteam/templates/db/migrate/20080903131506_create_payments.rb +22 -0
  127. data/generators/opensteam/templates/db/migrate/20080904133625_create_payment_transactions.rb +24 -0
  128. data/generators/opensteam/templates/db/migrate/20080916102341_create_zones.rb +19 -0
  129. data/generators/opensteam/templates/db/migrate/20080916134340_create_region_shipping_rates.rb +18 -0
  130. data/generators/opensteam/templates/db/migrate/20080916134523_create_shipping_rate_groups.rb +18 -0
  131. data/generators/opensteam/templates/db/migrate/20080916135226_create_shipping_payment_additions.rb +20 -0
  132. data/generators/opensteam/templates/db/migrate/20080916135228_init_opensteam_config.rb +60 -0
  133. data/generators/opensteam/templates/public/images/opensteam_black.jpg +0 -0
  134. data/generators/opensteam/templates/public/images/pdf.png +0 -0
  135. data/generators/opensteam/templates/public/images/shader.png +0 -0
  136. data/generators/opensteam/templates/public/index.html +1 -0
  137. data/generators/opensteam/templates/public/javascripts/opensteam.js +21 -21
  138. data/generators/opensteam/templates/public/stylesheets/opensteam_admin.css +291 -0
  139. data/generators/opensteam/templates/public/stylesheets/opensteam_white.css +47 -11
  140. data/generators/opensteam/templates/tasks/opensteam.rake +2 -12
  141. data/generators/opensteam/templates/test/fixtures/addresses.yml +26 -0
  142. data/generators/opensteam/templates/test/fixtures/configurations.yml +29 -0
  143. data/generators/opensteam/templates/test/fixtures/inventories.yml +32 -15
  144. data/generators/opensteam/templates/test/fixtures/profiles.yml +21 -0
  145. data/generators/opensteam/templates/test/fixtures/region_shipping_rates.yml +33 -0
  146. data/generators/opensteam/templates/test/fixtures/shipping_payment_additions.yml +91 -0
  147. data/generators/opensteam/templates/test/fixtures/shipping_rate_groups.yml +25 -0
  148. data/generators/opensteam/templates/test/fixtures/tax_groups.yml +13 -0
  149. data/generators/opensteam/templates/test/fixtures/tax_rules.yml +29 -0
  150. data/generators/opensteam/templates/test/fixtures/tax_zones.yml +33 -0
  151. data/generators/opensteam/templates/test/fixtures/users.yml +26 -0
  152. data/generators/opensteam/templates/test/fixtures/zones.yml +2707 -0
  153. data/generators/opensteam/templates/test/functional/carts_controller_test.rb +103 -0
  154. data/generators/opensteam/templates/test/test_helper.rb +38 -0
  155. data/generators/opensteam/templates/test/unit/container_test.rb +71 -0
  156. data/generators/opensteam/templates/test/unit/order_test.rb +93 -0
  157. data/generators/opensteam/templates/test/unit/payment_test.rb +220 -0
  158. data/generators/opensteam/templates/test/unit/product_test.rb +158 -0
  159. data/generators/opensteam/templates/vendor/plugins/prawnto/.gitignore +3 -0
  160. data/generators/opensteam/templates/vendor/plugins/prawnto/MIT-LICENSE +20 -0
  161. data/generators/opensteam/templates/vendor/plugins/prawnto/README +12 -0
  162. data/generators/opensteam/templates/vendor/plugins/prawnto/Rakefile +22 -0
  163. data/generators/opensteam/templates/vendor/plugins/prawnto/init.rb +6 -0
  164. data/generators/opensteam/templates/vendor/plugins/prawnto/lib/prawnto.rb +13 -0
  165. data/generators/opensteam/templates/vendor/plugins/prawnto/lib/prawnto/action_controller.rb +47 -0
  166. data/generators/opensteam/templates/vendor/plugins/prawnto/lib/prawnto/template_handler/base.rb +75 -0
  167. data/generators/opensteam/templates/vendor/plugins/prawnto/lib/prawnto/template_handler/raw.rb +54 -0
  168. data/generators/opensteam/templates/vendor/plugins/prawnto/tasks/prawnto_tasks.rake +4 -0
  169. data/generators/opensteam/templates/vendor/plugins/prawnto/test/action_controller_test.rb +36 -0
  170. data/generators/opensteam/templates/vendor/plugins/prawnto/test/base_template_handler_test.rb +58 -0
  171. data/generators/opensteam/templates/vendor/plugins/prawnto/test/raw_template_handler_test.rb +163 -0
  172. data/generators/opensteam/templates/vendor/plugins/prawnto/test/template_handler_test_mocks.rb +83 -0
  173. data/generators/opensteam_product/templates/views/admin/_attributes.html.erb +8 -3
  174. data/generators/opensteam_product/templates/views/admin/_inventories.html.erb +2 -0
  175. data/lib/opensteam.rb +0 -1
  176. data/lib/opensteam/base.rb +2 -1
  177. data/lib/opensteam/checkout.rb +3 -12
  178. data/lib/opensteam/config.rb +50 -2
  179. data/lib/opensteam/container.rb +196 -0
  180. data/lib/opensteam/extension_base.rb +19 -1
  181. data/lib/opensteam/finder.rb +1 -1
  182. data/lib/opensteam/helpers/config_table_helper.rb +18 -6
  183. data/lib/opensteam/initializer.rb +24 -4
  184. data/lib/opensteam/inventory_base.rb +6 -1
  185. data/lib/opensteam/invoice_base.rb +12 -13
  186. data/lib/opensteam/money.rb +230 -0
  187. data/lib/opensteam/order_base.rb +122 -48
  188. data/lib/opensteam/payment.rb +225 -0
  189. data/lib/opensteam/payment/advance_payment.rb +34 -0
  190. data/lib/opensteam/payment/credit_card_payment.rb +217 -0
  191. data/lib/opensteam/payment/direct_debit_payment.rb +53 -0
  192. data/lib/opensteam/product_base.rb +48 -12
  193. data/lib/opensteam/security.rb +54 -0
  194. data/lib/opensteam/shipment_base.rb +214 -6
  195. data/lib/opensteam/shopping_cart.rb +20 -300
  196. data/lib/opensteam/state_logic.rb +5 -3
  197. data/lib/opensteam/state_machine.rb +8 -3
  198. data/lib/opensteam/user_base.rb +48 -6
  199. data/lib/opensteam/version.rb +1 -1
  200. metadata +122 -16
  201. data/generators/opensteam/templates/app/controllers/cart_controller.rb +0 -94
  202. data/generators/opensteam/templates/app/views/admin/orders/_event.html.erb +0 -5
  203. data/generators/opensteam/templates/app/views/admin/orders/_order_item.html.erb +0 -10
  204. data/generators/opensteam/templates/app/views/cart/_cart.html.erb +0 -8
  205. data/generators/opensteam/templates/app/views/cart/_cart_content.html.erb +0 -20
  206. data/generators/opensteam/templates/app/views/cart/update.rjs +0 -1
  207. data/generators/opensteam/templates/app/views/checkout/payment.html.erb +0 -8
  208. data/generators/opensteam/templates/app/views/checkout/shipping.html.erb +0 -45
  209. data/generators/opensteam/templates/app/views/checkout/show_cart.html.erb +0 -13
  210. data/generators/opensteam/templates/app/views/checkout/update_cart_content.rjs +0 -2
  211. data/generators/opensteam/templates/app/views/profile/orders/_order_item.html.erb +0 -10
  212. data/generators/opensteam/templates/db/migrate/20080609095725_create_dummy_users.rb +0 -21
  213. data/lib/opensteam/cart_base.rb +0 -227
@@ -0,0 +1,58 @@
1
+ require 'test/unit'
2
+ require File.dirname(__FILE__) + '/template_handler_test_mocks'
3
+ require File.dirname(__FILE__) + '/../lib/prawnto'
4
+ require File.dirname(__FILE__) + '/../init'
5
+
6
+
7
+ #TODO: ruby1.9: pull same testing scheme from Raw once we're on 1.9
8
+ class BaseTemplateHandlerTest < Test::Unit::TestCase
9
+ include TemplateHandlerTestMocks
10
+
11
+ def setup
12
+ @view = ActionView.new
13
+ @handler = Prawnto::TemplateHandler::Base.new(@view)
14
+ @controller = @view.controller
15
+ end
16
+
17
+ def test_prawnto_options_dsl_hash
18
+ @y = 3231; @x = 5322
19
+ @controller.prawnto :dsl=> {'x'=>:@x, :y=>'@y'}
20
+ @handler.pull_prawnto_options
21
+ source = @handler.build_source_to_establish_locals(Template.new(""))
22
+
23
+ assert_equal @x, eval(source + "\nx")
24
+ assert_equal @y, eval(source + "\ny")
25
+ end
26
+
27
+ def test_prawnto_options_dsl_array
28
+ @y = 3231; @x = 5322
29
+ @controller.prawnto :dsl=> ['x', :@y]
30
+ @handler.pull_prawnto_options
31
+ source = @handler.build_source_to_establish_locals(Template.new(""))
32
+
33
+ assert_equal @x, eval(source + "\nx")
34
+ assert_equal @y, eval(source + "\ny")
35
+ end
36
+
37
+ def test_headers_disposition_inline_and_filename
38
+ @controller.prawnto :filename=>'xxx.pdf', :inline=>true
39
+ @handler.pull_prawnto_options
40
+ @handler.set_disposition
41
+ assert_equal 'inline;filename=xxx.pdf', @view.headers['Content-Disposition']
42
+ end
43
+
44
+ def test_headers_disposition_attachment_and_filename
45
+ @controller.prawnto :filename=>'xxx.pdf', :inline=>false
46
+ @handler.pull_prawnto_options
47
+ @handler.set_disposition
48
+ assert_equal 'attachment;filename=xxx.pdf', @view.headers['Content-Disposition']
49
+ end
50
+
51
+ def test_headers_disposition_default
52
+ @handler.pull_prawnto_options
53
+ @handler.set_disposition
54
+ assert_equal 'inline', @view.headers['Content-Disposition']
55
+ end
56
+
57
+ end
58
+
@@ -0,0 +1,163 @@
1
+ # uncomment and edit below if you want to get off gem version
2
+ #$LOAD_PATH.unshift '~/cracklabs/vendor/gems/prawn-0.0.0.1/lib/' #to force picup of latest prawn (instead of stable gem)
3
+
4
+ require 'rubygems'
5
+ require 'action_controller'
6
+ require 'action_view'
7
+
8
+ require 'test/unit'
9
+ require File.dirname(__FILE__) + '/../lib/prawnto'
10
+ require File.dirname(__FILE__) + '/template_handler_test_mocks'
11
+
12
+
13
+ class RawTemplateHandlerTest < Test::Unit::TestCase
14
+ include TemplateHandlerTestMocks
15
+ class ::ApplicationHelper
16
+ end
17
+
18
+ def setup
19
+ @view = ActionView.new
20
+ @handler = Prawnto::TemplateHandler::Raw.new(@view)
21
+ end
22
+
23
+
24
+ def test_massage_template_source_header_comments
25
+ expected_commented_lines = [0,2,3]
26
+ source = <<EOS
27
+ require 'prawn'
28
+ require 'hello'
29
+ require "rubygems"
30
+ $LOAD_PATH.unshift blah blah
31
+ LOAD_PATH.unshift blah blah
32
+ EOS
33
+ output_lines = @handler.send(:massage_template_source, Template.new(source)).split("\n")
34
+ output_lines.each_with_index do |line, i|
35
+ method = expected_commented_lines.include?(i) ? :assert_match : :assert_no_match
36
+ self.send method, /^\s*\#/, line
37
+ end
38
+ end
39
+
40
+ def test_massage_template_source_generate
41
+ @handler.pull_prawnto_options
42
+ changed_lines = [0,2,3]
43
+ source = <<EOS
44
+ Prawn::Document.generate('hello.pdf') do |pdf|
45
+ end
46
+ EOS
47
+ output_lines = @handler.send(:massage_template_source, Template.new(source)).split("\n")
48
+ assert_match(/^\s*(\S+)\s*\=\s*Prawn\:\:Document\.new\(?\s*\)?\s*do\s*\|pdf\|/, output_lines.first)
49
+ variable = $1
50
+ assert_match(/^\s*\[(\S+)\.render\s*\,\s*\'hello\.pdf\'\s*\]\s*$/, output_lines.last)
51
+ assert_equal variable, $1
52
+ end
53
+
54
+ def test_massage_template_source_new
55
+ @handler.pull_prawnto_options
56
+ unchanged_lines = [0,1,2]
57
+ source = <<EOS
58
+ x = Prawn::Document.new do |pdf|
59
+ text.blah blah blah
60
+ end
61
+ x.render_file('hello.pdf')
62
+ EOS
63
+ source_lines = source.split("\n")
64
+ output_lines = @handler.send(:massage_template_source, Template.new(source)).split("\n")
65
+ output_lines.each_with_index do |line, i|
66
+ method = unchanged_lines.include?(i) ? :assert_equal : :assert_not_equal
67
+ self.send method, source_lines[i], line
68
+ end
69
+ assert_match(/^\s*\#\s*x\.render\_file\(\'hello.pdf\'\)/, output_lines[3])
70
+ assert_match(/^\s*\[\s*x\.render\s*\,\s*\'hello\.pdf\'\s*\]\s*$/, output_lines.last)
71
+ end
72
+
73
+ def test_massage_template_source_classes_methods
74
+ source = <<EOS
75
+ class Foo
76
+ def initialize
77
+ @foo = true
78
+ end
79
+ end
80
+
81
+ def bar(*args)
82
+ if args[0]==true
83
+ z = false
84
+ end
85
+ end
86
+ EOS
87
+ @handler.send :setup_run_environment
88
+ output_lines = @handler.send(:massage_template_source, Template.new(source)).split("\n")
89
+ output_lines.pop
90
+ output_lines.each {|l| assert_match(/^\s*$/, l)}
91
+ assert @handler.run_environment.methods(false).include?('bar')
92
+ assert class <<@handler.run_environment; self; end.constants.include?('Foo')
93
+ end
94
+
95
+ CURRENT_PATH = Pathname('.').realpath
96
+ PRAWN_PATH = Pathname(Prawn::BASEDIR).realpath
97
+ REFERENCE_PATH = Pathname('reference_pdfs').realpath
98
+ INPUT_PATH = PRAWN_PATH + 'examples'
99
+ IGNORE_LIST = %w(table_bench ruport_formatter page_geometry)
100
+ INPUTS = INPUT_PATH.children.select {|p| p.extname==".rb" && !IGNORE_LIST.include?(p.basename('.rb').to_s)}
101
+
102
+ def self.ensure_reference_pdfs_are_recent
103
+ head_lines = (INPUT_PATH + "../.git/HEAD").read.split("\n")
104
+ head_hash = Hash[*head_lines.map {|line| line.split(':').map{|v| v.strip}}.flatten]
105
+ head_version = (INPUT_PATH + "../.git" + head_hash['ref'])
106
+
107
+ REFERENCE_PATH.mkpath
108
+ current_version = REFERENCE_PATH + 'HEAD'
109
+ if !current_version.exist? || current_version.read!=head_version.read
110
+ puts "\n!!!! reference pdfs are determined to be old-- repopulating...\n\n"
111
+ require 'fileutils'
112
+ FileUtils.instance_eval do
113
+ rm REFERENCE_PATH + '*', :force=>true
114
+ INPUTS.each do |path|
115
+ pre_brood = INPUT_PATH.children
116
+ cd INPUT_PATH
117
+ system("ruby #{path.basename}")
118
+ post_brood = INPUT_PATH.children
119
+ new_kids = post_brood - pre_brood
120
+ new_kids.each {|p| mv p, REFERENCE_PATH + p.basename}
121
+ cd CURRENT_PATH
122
+ end
123
+ cp head_version, current_version
124
+ end
125
+ else
126
+ puts "\n reference pdfs are current-- continuing...\n"
127
+ end
128
+ end
129
+
130
+ #TODO: ruby 1.9: uncomment below line when on 1.9
131
+ #ensure_reference_pdfs_are_recent
132
+
133
+
134
+ def assert_renders_correctly(name, path)
135
+ input_source = path.read
136
+ output_source = @handler.compile(Template.new(input_source))
137
+ value = @view.instance_eval output_source
138
+ reference = (REFERENCE_PATH + @view.prawnto_options[:filename]).read
139
+
140
+ message = "template: #{name}\n"
141
+ message += ">"*30 + " original template: " + ">"*20 + "\n"
142
+ message += input_source + "\n"*2
143
+ message += ">"*30 + " manipulated template: " + ">"*20 + "\n"
144
+ message += output_source + "\n" + "<"*60 + "\n"
145
+
146
+ assert_equal reference, value, message
147
+ end
148
+
149
+ #!!! Can't actually verify pdf equality until ruby 1.9
150
+ # (cuz hash orders are messed up otherwise and no other way to test equality at the moment)
151
+ INPUTS.each do |path|
152
+ name = path.basename('.rb')
153
+ define_method "test_template_should_render_correctly [template: #{name}] " do
154
+ # assert_renders_correctly name, path
155
+ assert true
156
+ end
157
+ end
158
+
159
+
160
+
161
+
162
+ end
163
+
@@ -0,0 +1,83 @@
1
+ require File.dirname(__FILE__) + '/../lib/prawnto'
2
+
3
+ module TemplateHandlerTestMocks
4
+
5
+ class Template
6
+ attr_reader :source, :locals, :filename
7
+
8
+ def initialize(source, locals={})
9
+ @source = source
10
+ @locals = locals
11
+ @filename = "blah.pdf"
12
+ end
13
+ end
14
+
15
+
16
+ class Response
17
+ def initialize
18
+ @headers = {}
19
+ end
20
+
21
+ def headers
22
+ @headers
23
+ end
24
+
25
+ def content_type=(value)
26
+ end
27
+ end
28
+
29
+ class Request
30
+ def env
31
+ {}
32
+ end
33
+ end
34
+
35
+ class ActionController
36
+ def self.before_filter(method)
37
+ @@init_method = method
38
+ end
39
+
40
+ def initialize
41
+ eval @@init_method.to_s
42
+ end
43
+
44
+ include Prawnto::ActionController
45
+
46
+ def response
47
+ @response ||= Response.new
48
+ end
49
+
50
+ def request
51
+ @request ||= Request.new
52
+ end
53
+
54
+ def headers
55
+ response.headers
56
+ end
57
+ end
58
+
59
+ class ActionView
60
+ def controller
61
+ @controller ||= ActionController.new
62
+ end
63
+
64
+ def response
65
+ controller.response
66
+ end
67
+
68
+ def request
69
+ controller.request
70
+ end
71
+
72
+ def headers
73
+ controller.headers
74
+ end
75
+
76
+ def prawnto_options
77
+ controller.get_instance_variable(:@prawnto_options)
78
+ end
79
+ end
80
+
81
+
82
+ end
83
+
@@ -1,21 +1,26 @@
1
+ <%% field_set_tag do %>
1
2
  <% for attribute in attributes -%>
2
3
  <p>
3
- <b><%= attribute.column.human_name %></b><br />
4
+ <%%= f.label :<%= attribute.name %> %>
4
5
  <%%= f.<%= attribute.field_type %> :<%= attribute.name %> %>
5
6
  </p>
6
7
 
7
8
  <% end -%>
9
+ <%% end %>
10
+
11
+ <%% field_set_tag do %>
8
12
  <%% @properties.each_pair do |prop_name,prop_array| %>
9
13
  <u><%%=h prop_name %></u><br />
10
14
  <%% for property in prop_array %>
11
- <%%=h property.name %> <%%= check_box_tag "<%= file_name %>[set_properties][#{prop_name}][#{property.id}]", 1,
15
+ <%%=h property.name %> <%%= check_box_tag "<%= file_name %>[set_properties][#{prop_name}][]", property.id,
12
16
  @<%= file_name %>.properties.include?(property) %> |
13
17
  <%% end %>
14
18
  <br /><br />
19
+ <%% end %>
15
20
  <%% end %>
16
21
  <br />
17
22
  <br />Products:<br />
18
23
  <%%= render :partial => "admin/<%= table_name %>/get_products" %>
19
24
  <p>
20
25
  <%%= f.submit button_name %>
21
- </p>
26
+ </p>
@@ -6,6 +6,7 @@
6
6
  <th>Price</th>
7
7
  <th>Storage</th>
8
8
  <th>BackOrdered</th>
9
+ <th>Tax Group</th>
9
10
  </tr>
10
11
  <% for inventory in @inventories %>
11
12
  <tr>
@@ -15,6 +16,7 @@
15
16
  <td><%=h inventory.price %></td>
16
17
  <td><%=h inventory.storage %></td>
17
18
  <td><%=h inventory.back_ordered == 0 ? "false" : "true" %></td>
19
+ <td><%=h inventory.tax_group ? inventory.tax_group.name : '' %></td>
18
20
 
19
21
  <td><%= link_to "show inventory", admin_inventory_path( inventory) %></td>
20
22
  <td><%= link_to "edit inventory", edit_admin_inventory_path( inventory ) %></td>
data/lib/opensteam.rb CHANGED
@@ -29,7 +29,6 @@ Opensteam::Initializer.run do |config|
29
29
  end
30
30
 
31
31
 
32
-
33
32
  Order = Opensteam::OrderBase::Order
34
33
  Invoice = Opensteam::InvoiceBase::Invoice
35
34
  Shipment = Opensteam::ShipmentBase::Shipment
@@ -28,8 +28,9 @@ Base Module for openSteam
28
28
  =end
29
29
  module Base
30
30
 
31
+ # DEPRECATED !
31
32
  # Extension for the Product-Inventory association
32
- module ExistByPropertiesExtension
33
+ module ExistByPropertiesExtension #:nodoc:
33
34
 
34
35
  # checks if an Inventory-Objects exists, which is associated with the given properties
35
36
  def exist_by_properties?( p )
@@ -37,7 +37,7 @@ module Opensteam
37
37
  module Checkout
38
38
 
39
39
 
40
- def self.included(base)
40
+ def self.included(base) #:nodoc:
41
41
  base.extend(ClassMethods)
42
42
  base.class_eval do
43
43
  include InstanceMethods
@@ -45,7 +45,7 @@ module Opensteam
45
45
  end
46
46
  end
47
47
 
48
- module ClassMethods
48
+ module ClassMethods #:nodoc:
49
49
 
50
50
  end
51
51
 
@@ -65,16 +65,7 @@ module Opensteam
65
65
  redirect_to_step(:finish)
66
66
  end
67
67
 
68
-
69
- # create the checkout flow
70
- #
71
- # define an init-method in your CheckoutController:
72
- # def init
73
- # create_checkout_flow do |c|
74
- # c.on :start, :intro
75
- # c.on :finish, :controller => "petstore", :action => "index"
76
- # end
77
- # end
68
+
78
69
  def create_checkout_flow( target = self )
79
70
  yield target if block_given?
80
71
  end
@@ -17,7 +17,6 @@
17
17
  module Opensteam
18
18
 
19
19
 
20
-
21
20
  # Config Module for Opensteam
22
21
  #
23
22
  #
@@ -28,6 +27,49 @@ module Opensteam
28
27
 
29
28
  ORDER_INITIAL_STATE = :pending
30
29
 
30
+ class << self ;
31
+
32
+ def [](name)
33
+ Base[ name ]
34
+ end
35
+
36
+ def []=(key,val)
37
+ Base[ key ] = val
38
+ end
39
+
40
+
41
+ end
42
+
43
+
44
+
45
+ class Base < ActiveRecord::Base #:nodoc:
46
+ self.table_name = "configurations"
47
+
48
+ class << self ;
49
+
50
+ def []=( k,v )
51
+ if c = find_by_key( k.to_s.downcase )
52
+ c.update_attribute( :value, v )
53
+ else
54
+ c = create( :key => k.to_s.downcase, :value => v )
55
+ end
56
+ c
57
+ end
58
+
59
+ def [](name)
60
+ find_by_key( name.to_s.downcase ).value
61
+ rescue
62
+ ""
63
+ end
64
+ end
65
+
66
+ end
67
+
68
+
69
+
70
+
71
+
72
+
31
73
  module Errors
32
74
  # generic error class
33
75
  class OpensteamError < StandardError
@@ -47,6 +89,8 @@ module Opensteam
47
89
 
48
90
  end
49
91
 
92
+
93
+
50
94
 
51
95
  module UUIDHelper
52
96
  require 'rubygems'
@@ -65,4 +109,8 @@ module Opensteam
65
109
 
66
110
  end
67
111
 
68
- end
112
+ end
113
+
114
+
115
+ Configuration = Opensteam::Config::Base
116
+