spree_core 2.1.12 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (172) hide show
  1. checksums.yaml +4 -4
  2. data/app/helpers/spree/base_helper.rb +4 -7
  3. data/app/helpers/spree/products_helper.rb +11 -9
  4. data/app/helpers/spree/store_helper.rb +5 -0
  5. data/app/models/spree/ability.rb +4 -0
  6. data/app/models/spree/address.rb +6 -6
  7. data/app/models/spree/adjustment.rb +40 -61
  8. data/app/models/spree/app_configuration.rb +1 -14
  9. data/app/models/spree/calculator.rb +12 -4
  10. data/app/models/spree/calculator/default_tax.rb +42 -38
  11. data/app/models/spree/calculator/flat_percent_item_total.rb +2 -4
  12. data/app/models/spree/calculator/free_shipping.rb +5 -2
  13. data/app/models/spree/calculator/percent_on_line_item.rb +15 -0
  14. data/app/models/spree/calculator/percent_per_item.rb +3 -0
  15. data/app/models/spree/classification.rb +3 -2
  16. data/app/models/spree/credit_card.rb +7 -25
  17. data/app/models/spree/gateway/bogus.rb +5 -5
  18. data/app/models/spree/gateway/bogus_simple.rb +0 -8
  19. data/app/models/spree/image.rb +0 -9
  20. data/app/models/spree/inventory_unit.rb +10 -4
  21. data/app/models/spree/item_adjustments.rb +65 -0
  22. data/app/models/spree/legacy_user.rb +1 -0
  23. data/app/models/spree/line_item.rb +33 -13
  24. data/app/models/spree/option_type.rb +2 -2
  25. data/app/models/spree/option_value.rb +1 -1
  26. data/app/models/spree/order.rb +109 -89
  27. data/app/models/spree/order/checkout.rb +48 -0
  28. data/app/models/spree/order_contents.rb +72 -37
  29. data/app/models/spree/order_inventory.rb +65 -68
  30. data/app/models/spree/order_populator.rb +3 -17
  31. data/app/models/spree/order_updater.rb +63 -44
  32. data/app/models/spree/payment.rb +20 -5
  33. data/app/models/spree/payment/processing.rb +19 -25
  34. data/app/models/spree/payment_capture_event.rb +9 -0
  35. data/app/models/spree/payment_method/check.rb +0 -2
  36. data/app/models/spree/price.rb +1 -1
  37. data/app/models/spree/product.rb +14 -16
  38. data/app/models/spree/product/scopes.rb +4 -6
  39. data/app/models/spree/product_option_type.rb +2 -2
  40. data/app/models/spree/product_property.rb +2 -2
  41. data/app/models/spree/promotion.rb +71 -50
  42. data/app/models/spree/promotion/actions/create_adjustment.rb +31 -32
  43. data/app/models/spree/promotion/actions/create_item_adjustments.rb +83 -0
  44. data/app/models/spree/promotion/actions/free_shipping.rb +36 -0
  45. data/app/models/spree/promotion/rules/first_order.rb +4 -0
  46. data/app/models/spree/promotion/rules/item_total.rb +5 -1
  47. data/app/models/spree/promotion/rules/product.rb +4 -0
  48. data/app/models/spree/promotion/rules/user.rb +5 -6
  49. data/app/models/spree/promotion/rules/user_logged_in.rb +4 -0
  50. data/app/models/spree/promotion_action.rb +1 -5
  51. data/app/models/spree/promotion_handler/cart.rb +38 -0
  52. data/app/models/spree/promotion_handler/coupon.rb +76 -0
  53. data/app/models/spree/promotion_handler/free_shipping.rb +31 -0
  54. data/app/models/spree/promotion_handler/page.rb +24 -0
  55. data/app/models/spree/promotion_rule.rb +15 -7
  56. data/app/models/spree/property.rb +1 -1
  57. data/app/models/spree/return_authorization.rb +7 -1
  58. data/app/models/spree/shipment.rb +113 -49
  59. data/app/models/spree/shipping_calculator.rb +4 -5
  60. data/app/models/spree/shipping_category.rb +2 -2
  61. data/app/models/spree/shipping_method.rb +12 -6
  62. data/app/models/spree/shipping_rate.rb +27 -7
  63. data/app/models/spree/stock/availability_validator.rb +1 -1
  64. data/app/models/spree/stock/estimator.rb +13 -1
  65. data/app/models/spree/stock/package.rb +11 -7
  66. data/app/models/spree/stock/packer.rb +3 -3
  67. data/app/models/spree/stock/quantifier.rb +9 -1
  68. data/app/models/spree/stock_item.rb +11 -6
  69. data/app/models/spree/stock_movement.rb +1 -2
  70. data/app/models/spree/tax_category.rb +6 -1
  71. data/app/models/spree/tax_rate.rb +57 -49
  72. data/app/models/spree/taxon.rb +10 -5
  73. data/app/models/spree/taxonomy.rb +5 -2
  74. data/app/models/spree/variant.rb +33 -16
  75. data/app/models/spree/zone.rb +24 -24
  76. data/app/views/spree/shared/_routes.html.erb +3 -0
  77. data/config/locales/en.yml +42 -26
  78. data/db/migrate/20130213191427_create_default_stock.rb +3 -3
  79. data/db/migrate/20130413230529_add_name_to_spree_credit_cards.rb +5 -0
  80. data/db/migrate/20130414000512_update_name_fields_on_spree_credit_cards.rb +13 -0
  81. data/db/migrate/20130417120035_update_adjustment_states.rb +2 -2
  82. data/db/migrate/20130417123427_add_shipping_rates_to_shipments.rb +1 -1
  83. data/db/migrate/20130509115210_add_number_to_stock_transfer.rb +1 -1
  84. data/db/migrate/20130611054351_rename_shipping_methods_zones_to_spree_shipping_methods_zones.rb +0 -5
  85. data/db/migrate/20130802022321_migrate_tax_categories_to_line_items.rb +7 -5
  86. data/db/migrate/20130807024301_upgrade_adjustments.rb +39 -0
  87. data/db/migrate/20130807024302_rename_adjustment_fields.rb +17 -0
  88. data/db/migrate/20130813004002_add_shipment_total_to_spree_orders.rb +5 -0
  89. data/db/migrate/20130813232134_rename_activators_to_promotions.rb +5 -0
  90. data/db/migrate/20130815000406_add_adjustment_total_to_line_items.rb +5 -0
  91. data/db/migrate/20130815024413_add_adjustment_total_to_shipments.rb +5 -0
  92. data/db/migrate/20130828234942_add_tax_total_to_line_items_shipments_and_orders.rb +8 -0
  93. data/db/migrate/20130830001159_migrate_old_shipping_calculators.rb +1 -1
  94. data/db/migrate/20130903183026_add_code_to_spree_promotion_rules.rb +5 -0
  95. data/db/migrate/20130917024658_remove_promotions_event_name_field.rb +5 -0
  96. data/db/migrate/20130924040529_add_promo_total_to_line_items_and_shipments_and_orders.rb +7 -0
  97. data/db/migrate/20131001013410_remove_unused_credit_card_fields.rb +7 -3
  98. data/db/migrate/20131107132123_add_tax_category_to_variants.rb +6 -0
  99. data/db/migrate/20131118043959_add_included_to_adjustments.rb +5 -0
  100. data/db/migrate/20131118050234_rename_tax_total_fields.rb +11 -0
  101. data/db/migrate/20131118183431_add_line_item_id_to_spree_inventory_units.rb +21 -0
  102. data/db/migrate/20131127001002_add_position_to_classifications.rb +5 -0
  103. data/db/migrate/20131211112807_create_spree_orders_promotions.rb +8 -0
  104. data/db/migrate/20131218054603_add_item_count_to_spree_orders.rb +5 -0
  105. data/db/migrate/20140106224208_rename_permalink_to_slug_for_products.rb +5 -0
  106. data/db/migrate/20140124023232_rename_activator_id_in_rules_and_actions_to_promotion_id.rb +6 -0
  107. data/db/migrate/20140203161722_add_approver_id_and_approved_at_to_orders.rb +6 -0
  108. data/db/migrate/20140204115338_add_confirmation_delivered_to_spree_orders.rb +5 -0
  109. data/db/migrate/20140205120320_create_spree_payment_capture_events.rb +12 -0
  110. data/db/migrate/20140205144710_add_uncaptured_amount_to_payments.rb +5 -0
  111. data/db/migrate/20140207085910_add_tax_category_id_to_shipping_methods.rb +5 -0
  112. data/db/migrate/20140207093021_add_tax_rate_id_to_shipping_rates.rb +5 -0
  113. data/db/migrate/20140211040159_add_pre_tax_amount_to_line_items_and_shipments.rb +6 -0
  114. data/db/migrate/20140213184916_add_more_indexes.rb +13 -0
  115. data/db/migrate/20140219060952_add_considered_risky_to_orders.rb +5 -0
  116. data/lib/generators/spree/dummy/dummy_generator.rb +1 -6
  117. data/lib/generators/spree/install/install_generator.rb +6 -6
  118. data/lib/generators/spree/install/templates/{app/assets/javascripts/admin → vendor/assets/javascripts/spree/backend}/all.js +3 -3
  119. data/lib/generators/spree/install/templates/{app/assets/javascripts/store → vendor/assets/javascripts/spree/frontend}/all.js +3 -3
  120. data/lib/generators/spree/install/templates/{app/assets/stylesheets/store → vendor/assets/stylesheets/spree/backend}/all.css +3 -3
  121. data/lib/generators/spree/install/templates/{app/assets/stylesheets/admin → vendor/assets/stylesheets/spree/frontend}/all.css +3 -3
  122. data/lib/spree/core.rb +21 -8
  123. data/lib/spree/core/calculated_adjustments.rb +0 -40
  124. data/lib/spree/core/controller_helpers.rb +5 -0
  125. data/lib/spree/core/controller_helpers/auth.rb +2 -2
  126. data/lib/spree/core/controller_helpers/common.rb +0 -5
  127. data/lib/spree/core/controller_helpers/order.rb +8 -9
  128. data/lib/spree/core/engine.rb +10 -17
  129. data/lib/spree/core/permalinks.rb +1 -1
  130. data/lib/spree/core/product_duplicator.rb +3 -8
  131. data/lib/spree/core/user_address.rb +1 -1
  132. data/lib/spree/core/validators/email.rb +23 -1
  133. data/lib/spree/core/version.rb +1 -1
  134. data/lib/spree/money.rb +1 -1
  135. data/lib/spree/permitted_attributes.rb +2 -2
  136. data/lib/spree/testing_support/caching.rb +47 -0
  137. data/lib/spree/testing_support/factories/adjustment_factory.rb +11 -2
  138. data/lib/spree/testing_support/factories/credit_card_factory.rb +2 -1
  139. data/lib/spree/testing_support/factories/order_factory.rb +10 -5
  140. data/lib/spree/testing_support/factories/payment_factory.rb +2 -2
  141. data/lib/spree/testing_support/factories/payment_method_factory.rb +3 -3
  142. data/lib/spree/testing_support/factories/promotion_factory.rb +16 -1
  143. data/lib/spree/testing_support/factories/shipment_factory.rb +8 -4
  144. data/lib/spree/testing_support/factories/shipping_method_factory.rb +1 -3
  145. data/lib/spree/testing_support/factories/stock_factory.rb +1 -1
  146. data/lib/spree/testing_support/factories/tax_rate_factory.rb +2 -2
  147. data/lib/spree/testing_support/order_walkthrough.rb +1 -1
  148. data/lib/tasks/core.rake +2 -2
  149. data/vendor/assets/fonts/FontAwesome.otf +0 -0
  150. data/vendor/assets/fonts/fontawesome-webfont.eot +0 -0
  151. data/vendor/assets/fonts/fontawesome-webfont.svg +399 -0
  152. data/vendor/assets/fonts/fontawesome-webfont.ttf +0 -0
  153. data/vendor/assets/fonts/fontawesome-webfont.woff +0 -0
  154. data/vendor/assets/stylesheets/font-awesome.scss +1475 -0
  155. metadata +73 -44
  156. data/app/assets/javascripts/admin/handlebar_extensions.js +0 -9
  157. data/app/helpers/spree/admin/adjustments_helper.rb +0 -26
  158. data/app/helpers/spree/admin/images_helper.rb +0 -18
  159. data/app/helpers/spree/promotion_rules_helper.rb +0 -13
  160. data/app/models/spree/activator.rb +0 -29
  161. data/app/models/spree/calculator/per_item.rb +0 -41
  162. data/app/models/spree/stock/remaining_packer.rb +0 -22
  163. data/app/views/spree/payments/_payment.html.erb +0 -18
  164. data/db/migrate/20131118041203_add_tax_total_to_spree_orders.rb +0 -5
  165. data/db/migrate/20131118043021_add_order_id_to_spree_adjustments.rb +0 -6
  166. data/db/migrate/20131118074808_add_included_to_spree_adjustments.rb +0 -5
  167. data/db/migrate/20140415041315_add_user_id_created_by_id_index_to_order.rb +0 -5
  168. data/lib/spree/core/gateway_error.rb +0 -5
  169. data/lib/spree/core/preference_rescue.rb +0 -25
  170. data/lib/spree/core/s3_support.rb +0 -25
  171. data/lib/spree/promo/coupon_applicator.rb +0 -71
  172. data/lib/spree/testing_support/factories/activator_factory.rb +0 -8
@@ -20,46 +20,6 @@ module Spree
20
20
  self.calculator = klass.new if klass && !self.calculator.is_a?(klass)
21
21
  end
22
22
 
23
- # Creates a new adjustment for the target object (which is any class that has_many :adjustments) and
24
- # sets amount based on the calculator as applied to the calculable argument (Order, LineItems[], Shipment, etc.)
25
- # By default the adjustment will not be considered mandatory
26
- def create_adjustment(label, target, calculable, mandatory=false, state="closed")
27
- # Adjustment calculations done on Spree::Shipment objects MUST
28
- # be done on their to_package'd variants instead
29
- # It's only the package that contains the correct information.
30
- # See https://github.com/spree/spree_active_shipping/pull/96 et. al
31
- old_calculable = calculable
32
- calculable = calculable.to_package if calculable.is_a?(Spree::Shipment)
33
- amount = compute_amount(calculable)
34
- return if amount == 0 && !mandatory
35
- target.adjustments.create(
36
- :amount => amount,
37
- :source => old_calculable,
38
- :originator => self,
39
- :label => label,
40
- :mandatory => mandatory,
41
- :state => state
42
- )
43
- end
44
-
45
- # Updates the amount of the adjustment using our Calculator and calling the +compute+ method with the +calculable+
46
- # referenced passed to the method.
47
- def update_adjustment(adjustment, calculable)
48
- # Adjustment calculations done on Spree::Shipment objects MUST
49
- # be done on their to_package'd variants instead
50
- # It's only the package that contains the correct information.
51
- # See https://github.com/spree/spree_active_shipping/pull/96 et. al
52
- calculable = calculable.to_package if calculable.is_a?(Spree::Shipment)
53
- adjustment.update_column(:amount, compute_amount(calculable))
54
- end
55
-
56
- # Calculate the amount to be used when creating an adjustment
57
- # NOTE: May be overriden by classes where this module is included into.
58
- # Such as Spree::Promotion::Action::CreateAdjustment.
59
- def compute_amount(calculable)
60
- self.calculator.compute(calculable)
61
- end
62
-
63
23
  private
64
24
  def self.model_name_without_spree_namespace
65
25
  self.to_s.tableize.gsub('/', '_').sub('spree_', '')
@@ -1,3 +1,8 @@
1
+ require 'spree/core/controller_helpers/common'
2
+ require 'spree/core/controller_helpers/auth'
3
+ require 'spree/core/controller_helpers/respond_with'
4
+ require 'spree/core/controller_helpers/order'
5
+
1
6
  module Spree
2
7
  module Core
3
8
  module ControllerHelpers
@@ -8,7 +8,7 @@ module Spree
8
8
  helper_method :try_spree_current_user
9
9
 
10
10
  rescue_from CanCan::AccessDenied do |exception|
11
- redirect_unauthorized_access
11
+ unauthorized
12
12
  end
13
13
  end
14
14
 
@@ -20,7 +20,7 @@ module Spree
20
20
  # Redirect as appropriate when an access request fails. The default action is to redirect to the login screen.
21
21
  # Override this method in your controllers if you want to have special behavior in case the user is not authorized
22
22
  # to access the requested action. For example, a popup window might simply close itself.
23
- def redirect_unauthorized_access
23
+ def unauthorized
24
24
  if try_spree_current_user
25
25
  flash[:error] = Spree.t(:authorization_failure)
26
26
  redirect_to '/unauthorized'
@@ -14,11 +14,6 @@ module Spree
14
14
 
15
15
  protected
16
16
 
17
- # Convenience method for firing instrumentation events with the default payload hash
18
- def fire_event(name, extra_payload = {})
19
- ActiveSupport::Notifications.instrument(name, default_notification_payload.merge(extra_payload))
20
- end
21
-
22
17
  # Creates the hash that is sent as the payload for all notifications. Specific notifications will
23
18
  # add additional keys as appropriate. Override this method if you need additional data when
24
19
  # responding to a notification
@@ -4,16 +4,23 @@ module Spree
4
4
  module Order
5
5
  def self.included(base)
6
6
  base.class_eval do
7
+ helper_method :simple_current_order
7
8
  helper_method :current_order
8
9
  helper_method :current_currency
9
10
  before_filter :set_current_order
10
11
  end
11
12
  end
12
13
 
14
+ # Used in the link_to_cart helper.
15
+ def simple_current_order
16
+ @order ||= Spree::Order.find_by(id: session[:order_id], currency: current_currency)
17
+ end
18
+
13
19
  # The current incomplete order from the session for use in cart and during checkout
14
20
  def current_order(options = {})
15
21
  options[:create_order_if_necessary] ||= false
16
22
  options[:lock] ||= false
23
+
17
24
  return @current_order if @current_order
18
25
 
19
26
  if session[:order_id]
@@ -47,14 +54,6 @@ module Spree
47
54
  @order.associate_user!(try_spree_current_user) if @order.user.blank? || @order.email.blank?
48
55
  end
49
56
 
50
- # This will trigger any "first order" promotions to be triggered
51
- # Assuming of course that this session variable was set correctly in
52
- # the authentication provider's registrations controller
53
- if session[:spree_user_signup] && @order
54
- fire_event('spree.user.signup', user: try_spree_current_user, order: @order)
55
- session[:spree_user_signup] = nil
56
- end
57
-
58
57
  session[:guest_token] = nil
59
58
  end
60
59
 
@@ -74,7 +73,7 @@ module Spree
74
73
  end
75
74
 
76
75
  def ip_address
77
- request.remote_ip
76
+ request.env['HTTP_X_REAL_IP'] || request.env['REMOTE_ADDR']
78
77
  end
79
78
  end
80
79
  end
@@ -4,18 +4,6 @@ module Spree
4
4
  isolate_namespace Spree
5
5
  engine_name 'spree'
6
6
 
7
- config.autoload_paths += %W(#{config.root}/lib)
8
-
9
- config.after_initialize do
10
- ActiveSupport::Notifications.subscribe(/^spree\./) do |*args|
11
- event_name, start_time, end_time, id, payload = args
12
- Activator.active.event_name_starts_with(event_name).each do |activator|
13
- payload[:event_name] = event_name
14
- activator.activate(payload)
15
- end
16
- end
17
- end
18
-
19
7
  initializer "spree.environment", :before => :load_config_initializers do |app|
20
8
  app.config.spree = Spree::Core::Environment.new
21
9
  Spree::Config = app.config.spree.preferences #legacy access
@@ -71,9 +59,11 @@ module Spree
71
59
  Spree::Calculator::FlatPercentItemTotal,
72
60
  Spree::Calculator::FlatRate,
73
61
  Spree::Calculator::FlexiRate,
74
- Spree::Calculator::PerItem,
75
- Spree::Calculator::PercentPerItem,
76
- Spree::Calculator::FreeShipping
62
+ ]
63
+
64
+ app.config.spree.calculators.add_class('promotion_actions_create_item_adjustments')
65
+ app.config.spree.calculators.promotion_actions_create_item_adjustments = [
66
+ Spree::Calculator::PercentOnLineItem
77
67
  ]
78
68
  end
79
69
 
@@ -91,8 +81,11 @@ module Spree
91
81
  end
92
82
 
93
83
  initializer 'spree.promo.register.promotions.actions' do |app|
94
- app.config.spree.promotions.actions = [Spree::Promotion::Actions::CreateAdjustment,
95
- Spree::Promotion::Actions::CreateLineItems]
84
+ app.config.spree.promotions.actions = [
85
+ Promotion::Actions::CreateAdjustment,
86
+ Promotion::Actions::CreateItemAdjustments,
87
+ Promotion::Actions::CreateLineItems,
88
+ Promotion::Actions::FreeShipping]
96
89
  end
97
90
 
98
91
  # filter sensitive information during logging
@@ -68,4 +68,4 @@ module Spree
68
68
  end
69
69
 
70
70
  ActiveRecord::Base.send :include, Spree::Core::Permalinks
71
- ActiveRecord::Relation.send :include, Spree::Core::Permalinks
71
+ ActiveRecord::Relation.send :include, Spree::Core::Permalinks
@@ -2,12 +2,8 @@ module Spree
2
2
  class ProductDuplicator
3
3
  attr_accessor :product
4
4
 
5
- @@clone_images_default = true
6
- mattr_accessor :clone_images_default
7
-
8
- def initialize(product, include_images = @@clone_images_default)
5
+ def initialize(product)
9
6
  @product = product
10
- @include_images = include_images
11
7
  end
12
8
 
13
9
  def duplicate
@@ -27,7 +23,6 @@ module Spree
27
23
  def duplicate_product
28
24
  product.dup.tap do |new_product|
29
25
  new_product.name = "COPY OF #{product.name}"
30
- new_product.permalink = "copy-of-#{product.permalink}"
31
26
  new_product.taxons = product.taxons
32
27
  new_product.created_at = nil
33
28
  new_product.deleted_at = nil
@@ -43,7 +38,7 @@ module Spree
43
38
  master.dup.tap do |new_master|
44
39
  new_master.sku = "COPY OF #{master.sku}"
45
40
  new_master.deleted_at = nil
46
- new_master.images = master.images.map { |image| duplicate_image image } if @include_images
41
+ new_master.images = master.images.map { |image| duplicate_image image }
47
42
  new_master.price = master.price
48
43
  new_master.currency = master.currency
49
44
  end
@@ -53,7 +48,7 @@ module Spree
53
48
  new_variant = variant.dup
54
49
  new_variant.sku = "COPY OF #{new_variant.sku}"
55
50
  new_variant.deleted_at = nil
56
- new_variant.option_values = variant.option_values.map { |option_value| option_value}
51
+ new_variant.option_values = variant.option_values.map { |option_value| option_value.dup}
57
52
  new_variant
58
53
  end
59
54
 
@@ -27,4 +27,4 @@ module Spree
27
27
  end
28
28
  end
29
29
  end
30
- end
30
+ end
@@ -1,7 +1,29 @@
1
+ # Borrowed from http://my.rails-royce.org/2010/07/21/email-validation-in-ruby-on-rails-without-regexp/
2
+ # Mentioned in tweet here: https://twitter.com/_sohara/status/177120126083141633
3
+ require 'mail'
1
4
  class EmailValidator < ActiveModel::EachValidator
2
5
  def validate_each(record,attribute,value)
3
- unless value =~ /\A[^@\s]+@([^@\s]+\.)+[^@\s]+\z/
6
+ unless valid?(value)
4
7
  record.errors.add(attribute, :invalid, {:value => value}.merge!(options))
5
8
  end
6
9
  end
10
+
11
+ def valid?(email)
12
+ begin
13
+ m = Mail::Address.new(email)
14
+ # We must check that value contains a domain and that value is an email address
15
+ r = m.domain && m.address == email
16
+ t = m.__send__(:tree)
17
+ # We need to dig into treetop
18
+ # A valid domain must have dot_atom_text elements size > 1
19
+ # user@localhost is excluded
20
+ # treetop must respond to domain
21
+ # We exclude valid email values like <user@localhost.com>
22
+ # Hence we use m.__send__(tree).domain
23
+ r &&= (t.domain.dot_atom_text.elements.size > 1)
24
+ rescue Exception => e
25
+ r = false
26
+ end
27
+ r
28
+ end
7
29
  end
@@ -1,5 +1,5 @@
1
1
  module Spree
2
2
  def self.version
3
- "2.1.12"
3
+ "2.2.0"
4
4
  end
5
5
  end
@@ -30,7 +30,7 @@ module Spree
30
30
 
31
31
  # Check the first character for a currency symbol, alternatively get it
32
32
  # from the stated currency string
33
- c = if ::Monetize.assume_from_symbol && i =~ /^(\$|€|£)/
33
+ c = if ::Money.assume_from_symbol && i =~ /^(\$|€|£)/
34
34
  case i
35
35
  when /^\$/ then "USD"
36
36
  when /^€/ then "EUR"
@@ -27,7 +27,7 @@ module Spree
27
27
  mattr_reader *ATTRIBUTES
28
28
 
29
29
  @@address_attributes = [
30
- :id, :firstname, :lastname, :address1, :address2,
30
+ :firstname, :lastname, :address1, :address2,
31
31
  :city, :country_id, :state_id, :zipcode, :phone,
32
32
  :state_name, :alternative_phone, :company,
33
33
  :country => [:iso, :name, :iso3, :iso_name],
@@ -68,7 +68,7 @@ module Spree
68
68
  # month / year may be provided by some sources, or others may elect to use one field
69
69
  @@source_attributes = [
70
70
  :number, :month, :year, :expiry, :verification_value,
71
- :first_name, :last_name, :cc_type, :gateway_customer_profile_id,
71
+ :first_name, :last_name, :cc_type, :gateway_customer_profile_id,
72
72
  :gateway_payment_profile_id, :last_digits, :name]
73
73
 
74
74
  @@stock_item_attributes = [:variant, :stock_location, :backorderable, :variant_id]
@@ -0,0 +1,47 @@
1
+ module Spree
2
+ module TestingSupport
3
+ module Caching
4
+ def cache_writes
5
+ @cache_write_events
6
+ end
7
+
8
+ def assert_written_to_cache(key)
9
+ unless @cache_write_events.detect { |event| event[:key].starts_with?(key) }
10
+ fail %Q{Expected to find #{key} in the cache, but didn't.
11
+
12
+ Cache writes:
13
+ #{@cache_write_events.join("\n")}
14
+ }
15
+ end
16
+ end
17
+
18
+ def clear_cache_events
19
+ @cache_read_events = []
20
+ @cache_write_events = []
21
+ end
22
+ end
23
+ end
24
+ end
25
+
26
+ RSpec.configure do |config|
27
+ config.include Spree::TestingSupport::Caching, :caching => true
28
+
29
+ config.before(:each, :caching => true) do
30
+ ActionController::Base.perform_caching = true
31
+
32
+ ActiveSupport::Notifications.subscribe("read_fragment.action_controller") do |event, start_time, finish_time, _, details|
33
+ @cache_read_events ||= []
34
+ @cache_read_events << details
35
+ end
36
+
37
+ ActiveSupport::Notifications.subscribe("write_fragment.action_controller") do |event, start_time, finish_time, _, details|
38
+ @cache_write_events ||= []
39
+ @cache_write_events << details
40
+ end
41
+ end
42
+
43
+ config.after(:each, :caching => true) do
44
+ ActionController::Base.perform_caching = false
45
+ Rails.cache.clear
46
+ end
47
+ end
@@ -3,15 +3,24 @@ FactoryGirl.define do
3
3
  association(:adjustable, factory: :order)
4
4
  amount 100.0
5
5
  label 'Shipping'
6
- association(:source, factory: :shipment)
6
+ association(:source, factory: :tax_rate)
7
7
  eligible true
8
8
  end
9
9
 
10
- factory :line_item_adjustment, class: Spree::Adjustment do
10
+ factory :tax_adjustment, class: Spree::Adjustment do
11
11
  association(:adjustable, factory: :line_item)
12
12
  amount 10.0
13
13
  label 'VAT 5%'
14
14
  association(:source, factory: :tax_rate)
15
15
  eligible true
16
+
17
+ after(:create) do |adjustment|
18
+ # Set correct tax category, so that adjustment amount is not 0
19
+ if adjustment.adjustable.is_a?(Spree::LineItem)
20
+ adjustment.source.tax_category = adjustment.adjustable.tax_category
21
+ adjustment.source.save
22
+ adjustment.update!
23
+ end
24
+ end
16
25
  end
17
26
  end
@@ -7,7 +7,8 @@ FactoryGirl.define do
7
7
  factory :credit_card, class: TestCard do
8
8
  verification_value 123
9
9
  month 12
10
- year { 1.year.from_now.year }
10
+ year { Time.now.year }
11
11
  number '4111111111111111'
12
+ name 'Spree Commerce'
12
13
  end
13
14
  end
@@ -21,20 +21,27 @@ FactoryGirl.define do
21
21
  end
22
22
 
23
23
  after(:create) do |order, evaluator|
24
+ create_list(:line_item, evaluator.line_items_count, order: order)
25
+ order.line_items.reload
26
+
24
27
  create(:shipment, order: order)
25
28
  order.shipments.reload
26
29
 
27
- create_list(:line_item, evaluator.line_items_count, order: order)
28
- order.line_items.reload
29
30
  order.update!
30
31
  end
31
32
 
32
33
  factory :completed_order_with_totals do
33
34
  state 'complete'
34
- completed_at { Time.now }
35
35
 
36
36
  after(:create) do |order|
37
37
  order.refresh_shipment_rates
38
+ order.update_column(:completed_at, Time.now)
39
+ end
40
+
41
+ factory :completed_order_with_pending_payment do
42
+ after(:create) do |order|
43
+ create(:payment, amount: order.total, order: order)
44
+ end
38
45
  end
39
46
 
40
47
  factory :order_ready_to_ship do
@@ -52,8 +59,6 @@ FactoryGirl.define do
52
59
 
53
60
  factory :shipped_order do
54
61
  after(:create) do |order|
55
- order.update_totals # To ensure we have the right total
56
- create(:payment, amount: order.total, order: order, state: 'completed')
57
62
  order.shipments.each do |shipment|
58
63
  shipment.inventory_units.each { |u| u.update_column('state', 'shipped') }
59
64
  shipment.update_column('state', 'shipped')
@@ -1,7 +1,7 @@
1
1
  FactoryGirl.define do
2
2
  factory :payment, class: Spree::Payment do
3
3
  amount 45.75
4
- association(:payment_method, factory: :bogus_payment_method)
4
+ association(:payment_method, factory: :credit_card_payment_method)
5
5
  association(:source, factory: :credit_card)
6
6
  order
7
7
  state 'checkout'
@@ -10,7 +10,7 @@ FactoryGirl.define do
10
10
 
11
11
  factory :check_payment, class: Spree::Payment do
12
12
  amount 45.75
13
- payment_method
13
+ association(:payment_method, factory: :check_payment_method)
14
14
  order
15
15
  end
16
16
  end