solidus_core 1.3.2 → 1.4.0.beta1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of solidus_core might be problematic. Click here for more details.

Files changed (139) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +15 -0
  3. data/app/helpers/spree/base_helper.rb +6 -2
  4. data/app/mailers/spree/base_mailer.rb +1 -1
  5. data/app/mailers/spree/carton_mailer.rb +1 -1
  6. data/app/mailers/spree/order_mailer.rb +2 -2
  7. data/app/mailers/spree/reimbursement_mailer.rb +7 -7
  8. data/app/mailers/spree/test_mailer.rb +3 -2
  9. data/app/models/concerns/spree/user_payment_source.rb +1 -1
  10. data/app/models/spree/address.rb +14 -4
  11. data/app/models/spree/adjustment.rb +11 -19
  12. data/app/models/spree/app_configuration.rb +23 -1
  13. data/app/models/spree/base.rb +9 -0
  14. data/app/models/spree/country.rb +2 -2
  15. data/app/models/spree/exchange.rb +1 -1
  16. data/app/models/spree/gateway.rb +1 -1
  17. data/app/models/spree/item_adjustments.rb +7 -0
  18. data/app/models/spree/line_item.rb +1 -13
  19. data/app/models/spree/order/checkout.rb +19 -16
  20. data/app/models/spree/order/payments.rb +0 -2
  21. data/app/models/spree/order.rb +7 -21
  22. data/app/models/spree/order_contents.rb +60 -4
  23. data/app/models/spree/order_merger.rb +2 -4
  24. data/app/models/spree/order_shipping.rb +1 -1
  25. data/app/models/spree/order_update_attributes.rb +0 -2
  26. data/app/models/spree/order_updater.rb +14 -11
  27. data/app/models/spree/payment.rb +2 -3
  28. data/app/models/spree/payment_create.rb +5 -2
  29. data/app/models/spree/payment_method/store_credit.rb +6 -5
  30. data/app/models/spree/product/scopes.rb +2 -1
  31. data/app/models/spree/product.rb +2 -5
  32. data/app/models/spree/promotion/actions/create_item_adjustments.rb +5 -3
  33. data/app/models/spree/promotion/actions/free_shipping.rb +1 -1
  34. data/app/models/spree/promotion/rules/option_value.rb +2 -3
  35. data/app/models/spree/promotion/rules/product.rb +9 -3
  36. data/app/models/spree/promotion/rules/taxon.rb +33 -7
  37. data/app/models/spree/promotion/rules/user.rb +2 -3
  38. data/app/models/spree/promotion.rb +16 -6
  39. data/app/models/spree/promotion_handler/coupon.rb +1 -1
  40. data/app/models/spree/shipment.rb +12 -16
  41. data/app/models/spree/stock/estimator.rb +1 -1
  42. data/app/models/spree/stock/package.rb +0 -1
  43. data/app/models/spree/stock_item.rb +2 -6
  44. data/app/models/spree/store.rb +2 -1
  45. data/app/models/spree/tax_rate.rb +1 -1
  46. data/app/models/spree/wallet/add_payment_sources_to_wallet.rb +29 -0
  47. data/app/models/spree/wallet/default_payment_builder.rb +26 -0
  48. data/app/views/spree/reimbursement_mailer/reimbursement_email.html.erb +46 -0
  49. data/app/views/spree/reimbursement_mailer/reimbursement_email.text.erb +1 -1
  50. data/app/views/spree/shared/_base_mailer_footer.html.erb +1 -20
  51. data/app/views/spree/shared/_base_mailer_header.html.erb +1 -31
  52. data/config/initializers/spree_user.rb +1 -1
  53. data/config/locales/en.yml +58 -34
  54. data/db/migrate/20130414000512_update_name_fields_on_spree_credit_cards.rb +1 -1
  55. data/db/migrate/20140601011216_set_shipment_total_for_users_upgrading.rb +15 -3
  56. data/db/migrate/20160527070401_rename_shipment_address_field.rb +7 -0
  57. data/db/migrate/20160616232103_remove_user_id_from_promotion_rules.rb +11 -0
  58. data/db/migrate/20160718205341_add_payment_id_index_to_spree_refunds.rb +5 -0
  59. data/db/migrate/20160718205859_add_reimbursement_id_index_to_spree_refunds.rb +5 -0
  60. data/lib/generators/spree/dummy/dummy_generator.rb +1 -1
  61. data/lib/generators/spree/dummy/templates/rails/database.yml +3 -1
  62. data/lib/generators/spree/dummy/templates/rails/test.rb +4 -2
  63. data/lib/generators/spree/install/install_generator.rb +6 -16
  64. data/lib/spree/core/controller_helpers/auth.rb +1 -1
  65. data/lib/spree/core/controller_helpers/common.rb +1 -1
  66. data/lib/spree/core/controller_helpers/order.rb +2 -2
  67. data/lib/spree/core/current_store.rb +5 -1
  68. data/lib/spree/core/delegate_belongs_to.rb +1 -1
  69. data/lib/spree/core/routes.rb +6 -32
  70. data/lib/spree/core/search/base.rb +2 -2
  71. data/lib/spree/core/stock_configuration.rb +6 -0
  72. data/lib/spree/core/version.rb +2 -2
  73. data/lib/spree/core.rb +2 -1
  74. data/lib/spree/i18n.rb +7 -0
  75. data/lib/spree/mailer_previews/carton_preview.rb +2 -1
  76. data/lib/spree/mailer_previews/order_preview.rb +8 -3
  77. data/lib/spree/mailer_previews/reimbursement_preview.rb +11 -0
  78. data/lib/spree/migrations.rb +13 -7
  79. data/lib/spree/permitted_attributes.rb +1 -1
  80. data/lib/spree/testing_support/capybara_ext.rb +6 -1
  81. data/lib/spree/testing_support/common_rake.rb +3 -7
  82. data/lib/spree/testing_support/controller_requests.rb +8 -0
  83. data/lib/spree/testing_support/factories/order_factory.rb +30 -8
  84. data/lib/spree/testing_support/factories/payment_factory.rb +1 -1
  85. data/lib/spree/testing_support/factories/product_factory.rb +6 -0
  86. data/lib/spree/testing_support/factories/reimbursement_factory.rb +1 -0
  87. data/lib/tasks/migrations/copy_shipped_shipments_to_cartons.rake +3 -1
  88. data/solidus_core.gemspec +3 -3
  89. data/spec/helpers/base_helper_spec.rb +18 -2
  90. data/spec/lib/i18n_spec.rb +4 -0
  91. data/spec/lib/spree/core/controller_helpers/order_spec.rb +16 -4
  92. data/spec/lib/spree/core/controller_helpers/payment_parameters_spec.rb +75 -59
  93. data/spec/lib/spree/core/delegate_belongs_to_spec.rb +1 -1
  94. data/spec/lib/spree/core/importer/order_spec.rb +4 -2
  95. data/spec/lib/spree/core/stock_configuration_spec.rb +17 -0
  96. data/spec/lib/spree/core/testing_support/factories/order_factory_spec.rb +195 -0
  97. data/spec/lib/spree/core/testing_support/factories/payment_factory_spec.rb +6 -0
  98. data/spec/lib/spree/core/testing_support/factories/reimbursement_factory_spec.rb +6 -0
  99. data/spec/lib/spree/migrations_spec.rb +3 -9
  100. data/spec/lib/tasks/migrations/copy_shipped_shipments_to_cartons_spec.rb +1 -1
  101. data/spec/mailers/carton_mailer_spec.rb +1 -1
  102. data/spec/mailers/order_mailer_spec.rb +2 -2
  103. data/spec/mailers/reimbursement_mailer_spec.rb +1 -1
  104. data/spec/models/spree/address_spec.rb +22 -0
  105. data/spec/models/spree/adjustment_spec.rb +0 -10
  106. data/spec/models/spree/carton_spec.rb +1 -1
  107. data/spec/models/spree/country_spec.rb +9 -1
  108. data/spec/models/spree/gateway/bogus_spec.rb +1 -1
  109. data/spec/models/spree/item_adjustments_spec.rb +33 -0
  110. data/spec/models/spree/line_item_spec.rb +2 -21
  111. data/spec/models/spree/order/checkout_spec.rb +32 -45
  112. data/spec/models/spree/order/payment_spec.rb +1 -16
  113. data/spec/models/spree/order_cancellations_spec.rb +8 -3
  114. data/spec/models/spree/order_contents_spec.rb +48 -0
  115. data/spec/models/spree/order_merger_spec.rb +8 -5
  116. data/spec/models/spree/order_shipping_spec.rb +3 -4
  117. data/spec/models/spree/order_spec.rb +23 -59
  118. data/spec/models/spree/order_update_attributes_spec.rb +1 -5
  119. data/spec/models/spree/order_updater_spec.rb +39 -11
  120. data/spec/models/spree/payment_create_spec.rb +61 -0
  121. data/spec/models/spree/payment_method/store_credit_spec.rb +23 -10
  122. data/spec/models/spree/payment_spec.rb +17 -4
  123. data/spec/models/spree/product_spec.rb +1 -1
  124. data/spec/models/spree/promotion/actions/create_item_adjustments_spec.rb +8 -13
  125. data/spec/models/spree/promotion/rules/product_spec.rb +33 -0
  126. data/spec/models/spree/promotion/rules/taxon_spec.rb +52 -8
  127. data/spec/models/spree/promotion_spec.rb +18 -12
  128. data/spec/models/spree/return_authorization_spec.rb +0 -16
  129. data/spec/models/spree/shipment_spec.rb +57 -36
  130. data/spec/models/spree/stock/coordinator_spec.rb +0 -5
  131. data/spec/models/spree/stock/package_spec.rb +0 -1
  132. data/spec/models/spree/stock_item_spec.rb +35 -145
  133. data/spec/models/spree/store_spec.rb +24 -10
  134. data/spec/models/spree/tax_rate_spec.rb +2 -2
  135. data/spec/models/spree/user_spec.rb +1 -1
  136. data/spec/models/spree/validations/db_maximum_length_validator_spec.rb +20 -12
  137. data/spec/support/concerns/working_factories.rb +4 -0
  138. metadata +30 -10
  139. data/config/routes.rb +0 -1
@@ -8,7 +8,7 @@ module Spree
8
8
  include ControllerHelpers::Pricing
9
9
 
10
10
  included do
11
- before_filter :set_current_order
11
+ before_action :set_current_order
12
12
 
13
13
  helper_method :current_order
14
14
  helper_method :simple_current_order
@@ -59,7 +59,7 @@ module Spree
59
59
 
60
60
  def set_current_order
61
61
  if try_spree_current_user && current_order
62
- try_spree_current_user.orders.incomplete.where('id != ?', current_order.id).each do |order|
62
+ try_spree_current_user.orders.by_store(current_store).incomplete.where('id != ?', current_order.id).each do |order|
63
63
  current_order.merge!(order, try_spree_current_user)
64
64
  end
65
65
  end
@@ -13,7 +13,11 @@ module Spree
13
13
  # looking up by the requesting server's name.
14
14
  # @return [Spree::Store]
15
15
  def store
16
- Spree::Store.current(store_key)
16
+ if store_key
17
+ Spree::Store.current(store_key)
18
+ else
19
+ Spree::Store.default
20
+ end
17
21
  end
18
22
 
19
23
  private
@@ -31,7 +31,7 @@ module DelegateBelongsTo
31
31
  # delegate_belongs_to :contact, [:defaults, :address, :fullname], :class_name => 'VCard'
32
32
  ##
33
33
  def delegate_belongs_to(association, *attrs)
34
- ActiveSupport::Deprecation.warn "delegate_belongs_to is deprecated. Instead use rails built in delegates.", caller
34
+ Spree::Deprecation.warn "delegate_belongs_to is deprecated. Instead use rails built in delegates.", caller
35
35
  opts = attrs.extract_options!
36
36
  initialize_association :belongs_to, association, opts
37
37
  attrs = get_association_column_names(association) if attrs.empty?
@@ -2,44 +2,18 @@ module Spree
2
2
  module Core
3
3
  class Engine < ::Rails::Engine
4
4
  def self.add_routes(&block)
5
- @spree_routes ||= []
6
-
7
- # Anything that causes the application's routes to be reloaded,
8
- # will cause this method to be called more than once
9
- # i.e. https://github.com/plataformatec/devise/blob/31971e69e6a1bcf6c7f01eaaa44f227c4af5d4d2/lib/devise/rails.rb#L14
10
- # In the case of Devise, this *only* happens in the production env
11
- # This coupled with Rails 4's insistence that routes are not drawn twice,
12
- # poses quite a serious problem.
13
- #
14
- # This is mainly why this whole file exists in the first place.
15
- #
16
- # Thus we need to make sure that the routes aren't drawn twice.
17
- unless @spree_routes.include?(block)
18
- @spree_routes << block
19
- end
5
+ Spree::Deprecation.warn "Spree::Core::Engine.add_routes is deprecated, use Spree::Core::Engine.routes.draw instead"
6
+ routes.draw(&block)
20
7
  end
21
8
 
22
9
  def self.append_routes(&block)
23
- @append_routes ||= []
24
- # See comment in add_routes.
25
- unless @append_routes.include?(block)
26
- @append_routes << block
27
- end
10
+ Spree::Deprecation.warn "Spree::Core::Engine.append_routes is deprecated, use Spree::Core::Engine.routes.append instead"
11
+ routes.append(&block)
28
12
  end
29
13
 
30
14
  def self.draw_routes(&block)
31
- @spree_routes ||= []
32
- @append_routes ||= []
33
- eval_block(block) if block_given?
34
- @spree_routes.each { |r| eval_block(&r) }
35
- @append_routes.each { |r| eval_block(&r) }
36
- # # Clear out routes so that they aren't drawn twice.
37
- @spree_routes = []
38
- @append_routes = []
39
- end
40
-
41
- def eval_block(&block)
42
- Spree::Core::Engine.routes.send :eval_block, block
15
+ Spree::Deprecation.warn "Spree::Core::Engine.draw_routes is deprecated, use Spree::Core::Engine.routes.draw instead"
16
+ routes.draw(&block)
43
17
  end
44
18
  end
45
19
  end
@@ -30,7 +30,7 @@ module Spree
30
30
  curr_page = page || 1
31
31
 
32
32
  unless Spree::Config.show_products_without_price
33
- @products = @products.joins(:prices).merge(Spree::Price.where(pricing_options.search_arguments)).uniq
33
+ @products = @products.joins(:prices).merge(Spree::Price.where(pricing_options.search_arguments)).distinct
34
34
  end
35
35
  @products = @products.page(curr_page).per(per_page)
36
36
  end
@@ -46,7 +46,7 @@ module Spree
46
46
  protected
47
47
 
48
48
  def get_base_scope
49
- base_scope = Spree::Product.available
49
+ base_scope = Spree::Product.display_includes.available
50
50
  base_scope = base_scope.in_taxon(taxon) unless taxon.blank?
51
51
  base_scope = get_products_conditions_for(base_scope, keywords)
52
52
  base_scope = add_search_scopes(base_scope)
@@ -1,8 +1,14 @@
1
1
  module Spree
2
2
  module Core
3
3
  class StockConfiguration
4
+ attr_writer :coordinator_class
4
5
  attr_writer :estimator_class
5
6
 
7
+ def coordinator_class
8
+ @coordinator_class ||= '::Spree::Stock::Coordinator'
9
+ @coordinator_class.constantize
10
+ end
11
+
6
12
  def estimator_class
7
13
  @estimator_class ||= '::Spree::Stock::Estimator'
8
14
  @estimator_class.constantize
@@ -1,11 +1,11 @@
1
1
  module Spree
2
2
  def self.version
3
- ActiveSupport::Deprecation.warn("Spree.version does not work and will be removed from solidus. Use Spree.solidus_version instead to determine the solidus version")
3
+ Spree::Deprecation.warn("Spree.version does not work and will be removed from solidus. Use Spree.solidus_version instead to determine the solidus version")
4
4
  "2.4.6.beta"
5
5
  end
6
6
 
7
7
  def self.solidus_version
8
- "1.3.2"
8
+ "1.4.0.beta1"
9
9
  end
10
10
 
11
11
  def self.solidus_gem_version
data/lib/spree/core.rb CHANGED
@@ -49,7 +49,7 @@ module Spree
49
49
  def self.const_missing(name)
50
50
  case name
51
51
  when :AdjustmentSource, :CalculatedAdjustments, :UserAddress, :UserPaymentSource
52
- ActiveSupport::Deprecation.warn("Spree::Core::#{name} is deprecated! Use Spree::#{name} instead.", caller)
52
+ Spree::Deprecation.warn("Spree::Core::#{name} is deprecated! Use Spree::#{name} instead.", caller)
53
53
  Spree.const_get(name)
54
54
  else
55
55
  super
@@ -99,5 +99,6 @@ require 'spree/deprecation'
99
99
 
100
100
  require 'spree/mailer_previews/order_preview'
101
101
  require 'spree/mailer_previews/carton_preview'
102
+ require 'spree/mailer_previews/reimbursement_preview'
102
103
 
103
104
  require 'spree/core/price_migrator'
data/lib/spree/i18n.rb CHANGED
@@ -6,9 +6,16 @@ module Spree
6
6
  include ActionView::Helpers::TranslationHelper
7
7
  end
8
8
 
9
+ # This value is used as a count for the pluralization helpers related to I18n
10
+ # ex: Spree::Order.model_name.human(count: Spree::I18N_GENERIC_PLURAL)
11
+ # Related to Solidus issue #1164, this is needed to avoid problems with
12
+ # some pluralization calculators
13
+ I18N_GENERIC_PLURAL = 2.1
14
+
9
15
  class << self
10
16
  # Add spree namespace and delegate to Rails TranslationHelper for some nice
11
17
  # extra functionality. e.g return reasonable strings for missing translations
18
+
12
19
  def translate(key, options = {})
13
20
  options[:scope] = [:spree, *options[:scope]]
14
21
  TranslationHelperWrapper.new.translate(key, options)
@@ -2,7 +2,8 @@ module Spree
2
2
  class MailerPreviews
3
3
  class CartonPreview < ActionMailer::Preview
4
4
  def shipped
5
- carton = Carton.first
5
+ carton = Carton.joins(:orders).last
6
+ raise "Your database needs at one shipped order with a carton to render this preview" unless carton
6
7
  Spree::Config.carton_shipped_email_class.shipped_email(order: carton.orders.first, carton: carton)
7
8
  end
8
9
  end
@@ -2,15 +2,20 @@ module Spree
2
2
  class MailerPreviews
3
3
  class OrderPreview < ActionMailer::Preview
4
4
  def confirm
5
- OrderMailer.confirm_email(Order.first)
5
+ order = Order.complete.last
6
+ raise "Your database needs at least one completed order to render this preview" unless order
7
+ OrderMailer.confirm_email(order)
6
8
  end
7
9
 
8
10
  def cancel
9
- OrderMailer.cancel_email(Order.first)
11
+ order = Order.with_state(:canceled).last
12
+ raise "Your database needs at least one cancelled order to render this preview" unless order
13
+ OrderMailer.cancel_email(order)
10
14
  end
11
15
 
12
16
  def inventory_cancellation
13
- order = Order.first
17
+ order = Spree::Order.joins(:inventory_units).merge(Spree::InventoryUnit.canceled).last
18
+ raise "Your database needs at least one order with a canceled inventory unit to render this preview" unless order
14
19
  OrderMailer.inventory_cancellation_email(order, [order.inventory_units.first])
15
20
  end
16
21
  end
@@ -0,0 +1,11 @@
1
+ module Spree
2
+ class MailerPreviews
3
+ class ReimbursementPreview < ActionMailer::Preview
4
+ def reimbursement
5
+ reimbursement = Reimbursement.last
6
+ raise "Your database needs at least one Reimbursement to render this preview" unless reimbursement
7
+ ReimbursementMailer.reimbursement_email(reimbursement)
8
+ end
9
+ end
10
+ end
11
+ end
@@ -22,13 +22,6 @@ module Spree
22
22
  # engine name on the file name
23
23
  def check
24
24
  if File.directory?(app_dir)
25
- engine_in_app = app_migrations.map do |file_name|
26
- name, engine = file_name.split(".", 2)
27
- next unless match_engine?(engine)
28
- name
29
- end.compact
30
-
31
- missing_migrations = engine_migrations.sort - engine_in_app.sort
32
25
  unless missing_migrations.empty?
33
26
  puts "[#{engine_name.capitalize} WARNING] Missing migrations."
34
27
  missing_migrations.each do |migration|
@@ -40,6 +33,19 @@ module Spree
40
33
  end
41
34
  end
42
35
 
36
+ def missing_migrations
37
+ @missing_migrations ||=
38
+ begin
39
+ engine_in_app = app_migrations.map do |file_name|
40
+ name, engine = file_name.split(".", 2)
41
+ next unless match_engine?(engine)
42
+ name
43
+ end.compact
44
+
45
+ engine_migrations.sort - engine_in_app.sort
46
+ end
47
+ end
48
+
43
49
  private
44
50
 
45
51
  def engine_migrations
@@ -45,7 +45,7 @@ module Spree
45
45
  @@address_book_attributes = address_attributes + [:default]
46
46
 
47
47
  @@checkout_attributes = [
48
- :coupon_code, :email, :shipping_method_id, :special_instructions, :use_billing
48
+ :coupon_code, :email, :special_instructions, :use_billing
49
49
  ]
50
50
 
51
51
  @@credit_card_update_attributes = [
@@ -26,11 +26,16 @@ module CapybaraExt
26
26
  end
27
27
 
28
28
  def select2_search(value, options)
29
+ options = {
30
+ search: value, # by default search for the value
31
+ select: true
32
+ }.merge(options)
29
33
  label = find_label_by_text(options[:from])
30
34
  within label.first(:xpath, ".//..") do
31
35
  options[:from] = "##{find('.select2-container')['id']}"
32
36
  end
33
- targetted_select2_search(value, options)
37
+ select2_search_without_selection(options[:search], from: options[:from])
38
+ select_select2_result(value) if options[:select]
34
39
  end
35
40
 
36
41
  def select2_search_without_selection(value, options)
@@ -17,24 +17,20 @@ namespace :common do
17
17
 
18
18
  puts "Setting up dummy database..."
19
19
 
20
- silence_stream(STDOUT) do
21
- sh "bundle exec rake db:drop db:create db:migrate"
22
- end
20
+ sh "bundle exec rake db:migrate VERBOSE=false"
23
21
 
24
22
  begin
25
23
  require "generators/#{ENV['LIB_NAME']}/install/install_generator"
26
24
  puts 'Running extension installation generator...'
27
25
  "#{ENV['LIB_NAME'].camelize}::Generators::InstallGenerator".constantize.start(["--auto-run-migrations"])
28
26
  rescue LoadError
29
- puts 'Skipping installation no generator to run...'
27
+ # No extension generator to run
30
28
  end
31
29
  end
32
30
 
33
31
  task :seed do |_t, _args|
34
32
  puts "Seeding ..."
35
33
 
36
- silence_stream(STDOUT) do
37
- sh "bundle exec rake db:seed RAILS_ENV=test"
38
- end
34
+ sh "bundle exec rake db:seed RAILS_ENV=test"
39
35
  end
40
36
  end
@@ -49,37 +49,45 @@ module Spree
49
49
  def spree_get(action, parameters = nil, session = nil, flash = nil)
50
50
  process_spree_action(action, parameters, session, flash, "GET")
51
51
  end
52
+ deprecate spree_get: :get, deprecator: Spree::Deprecation
52
53
 
53
54
  # Executes a request simulating POST HTTP method and set/volley the response
54
55
  def spree_post(action, parameters = nil, session = nil, flash = nil)
55
56
  process_spree_action(action, parameters, session, flash, "POST")
56
57
  end
58
+ deprecate spree_post: :post, deprecator: Spree::Deprecation
57
59
 
58
60
  # Executes a request simulating PUT HTTP method and set/volley the response
59
61
  def spree_put(action, parameters = nil, session = nil, flash = nil)
60
62
  process_spree_action(action, parameters, session, flash, "PUT")
61
63
  end
64
+ deprecate spree_put: :put, deprecator: Spree::Deprecation
62
65
 
63
66
  # Executes a request simulating DELETE HTTP method and set/volley the response
64
67
  def spree_delete(action, parameters = nil, session = nil, flash = nil)
65
68
  process_spree_action(action, parameters, session, flash, "DELETE")
66
69
  end
70
+ deprecate spree_delete: :delete, deprecator: Spree::Deprecation
67
71
 
68
72
  def spree_xhr_get(action, parameters = nil, session = nil, flash = nil)
69
73
  process_spree_xhr_action(action, parameters, session, flash, :get)
70
74
  end
75
+ deprecate spree_xhr_get: :get, deprecator: Spree::Deprecation
71
76
 
72
77
  def spree_xhr_post(action, parameters = nil, session = nil, flash = nil)
73
78
  process_spree_xhr_action(action, parameters, session, flash, :post)
74
79
  end
80
+ deprecate spree_xhr_post: :post, deprecator: Spree::Deprecation
75
81
 
76
82
  def spree_xhr_put(action, parameters = nil, session = nil, flash = nil)
77
83
  process_spree_xhr_action(action, parameters, session, flash, :put)
78
84
  end
85
+ deprecate spree_xhr_put: :put, deprecator: Spree::Deprecation
79
86
 
80
87
  def spree_xhr_delete(action, parameters = nil, session = nil, flash = nil)
81
88
  process_spree_xhr_action(action, parameters, session, flash, :delete)
82
89
  end
90
+ deprecate spree_xhr_delete: :delete, deprecator: Spree::Deprecation
83
91
 
84
92
  private
85
93
 
@@ -46,12 +46,31 @@ FactoryGirl.define do
46
46
  end
47
47
  order.line_items.reload
48
48
 
49
- create(:shipment, order: order, cost: evaluator.shipment_cost, shipping_method: evaluator.shipping_method, address: evaluator.ship_address, stock_location: evaluator.stock_location)
49
+ create(:shipment, order: order, cost: evaluator.shipment_cost, shipping_method: evaluator.shipping_method, stock_location: evaluator.stock_location)
50
50
  order.shipments.reload
51
51
 
52
52
  order.update!
53
53
  end
54
54
 
55
+ factory :order_ready_to_complete do
56
+ state 'confirm'
57
+ payment_state 'checkout'
58
+
59
+ transient do
60
+ payment_type :credit_card_payment
61
+ end
62
+
63
+ after(:create) do |order, evaluator|
64
+ create(evaluator.payment_type, {
65
+ amount: order.total,
66
+ order: order,
67
+ state: order.payment_state
68
+ })
69
+
70
+ order.payments.reload
71
+ end
72
+ end
73
+
55
74
  factory :completed_order_with_totals do
56
75
  state 'complete'
57
76
 
@@ -94,7 +113,7 @@ FactoryGirl.define do
94
113
  next unless evaluator.with_cartons
95
114
  Spree::Carton.create!(
96
115
  stock_location: shipment.stock_location,
97
- address: shipment.address,
116
+ address: order.ship_address,
98
117
  shipping_method: shipment.shipping_method,
99
118
  inventory_units: shipment.inventory_units,
100
119
  shipped_at: Time.current
@@ -108,19 +127,22 @@ FactoryGirl.define do
108
127
  end
109
128
  end
110
129
 
111
- factory :completed_order_with_promotion, parent: :completed_order_with_totals, class: "Spree::Order" do
130
+ factory :completed_order_with_promotion, parent: :order_with_line_items, class: "Spree::Order" do
112
131
  transient do
113
132
  promotion nil
114
- promotion_code nil
115
133
  end
116
134
 
117
135
  after(:create) do |order, evaluator|
118
136
  promotion = evaluator.promotion || create(:promotion, code: "test")
119
- promotion_code = evaluator.promotion_code || promotion.codes.first
137
+ promotion_code = promotion.codes.first || create(:promotion_code, promotion: promotion)
120
138
 
121
- promotion.actions.each do |action|
122
- action.perform({ order: order, promotion: promotion, promotion_code: promotion_code })
123
- end
139
+ promotion.activate(order: order, promotion_code: promotion_code)
140
+ order.order_promotions.create!(promotion: promotion, promotion_code: promotion_code)
141
+
142
+ # Complete the order after the promotion has been activated
143
+ order.refresh_shipment_rates
144
+ order.update_column(:completed_at, Time.current)
145
+ order.update_column(:state, "complete")
124
146
  end
125
147
  end
126
148
  end
@@ -6,7 +6,7 @@ require 'spree/testing_support/factories/store_credit_factory'
6
6
  FactoryGirl.define do
7
7
  factory :payment, aliases: [:credit_card_payment], class: Spree::Payment do
8
8
  association(:payment_method, factory: :credit_card_payment_method)
9
- association(:source, factory: :credit_card)
9
+ source { create(:credit_card, user: order.user) }
10
10
  order
11
11
  state 'checkout'
12
12
  response_code '12345'
@@ -32,6 +32,12 @@ FactoryGirl.define do
32
32
  after :create do |product|
33
33
  product.master.stock_items.first.adjust_count_on_hand(10)
34
34
  end
35
+
36
+ factory :product_not_backorderable do
37
+ after :create do |product|
38
+ product.master.stock_items.first.update_column(:backorderable, false)
39
+ end
40
+ end
35
41
  end
36
42
 
37
43
  factory :product_with_option_types do
@@ -13,6 +13,7 @@ FactoryGirl.define do
13
13
  if reimbursement.return_items.empty?
14
14
  reimbursement.return_items = reimbursement.customer_return.return_items
15
15
  end
16
+ reimbursement.total = reimbursement.return_items.map { |ri| ri.amount }.sum
16
17
  end
17
18
  end
18
19
  end
@@ -49,13 +49,15 @@ namespace 'spree:migrations:copy_shipped_shipments_to_cartons' do
49
49
  #{db_concat("'C'", 'spree_shipments.number')}, -- number
50
50
  spree_shipments.id, -- imported_from_shipment_id
51
51
  spree_shipments.stock_location_id,
52
- spree_shipments.address_id,
52
+ spree_orders.ship_address_id,
53
53
  spree_shipping_rates.shipping_method_id,
54
54
  spree_shipments.tracking,
55
55
  spree_shipments.shipped_at,
56
56
  '#{Time.current.to_s(:db)}', -- created_at
57
57
  '#{Time.current.to_s(:db)}' -- updated_at
58
58
  from spree_shipments
59
+ left join spree_orders
60
+ on spree_orders.id = spree_shipments.order_id
59
61
  left join spree_shipping_rates
60
62
  on spree_shipping_rates.shipment_id = spree_shipments.id
61
63
  and spree_shipping_rates.selected = #{Spree::Carton.connection.quoted_true}
data/solidus_core.gemspec CHANGED
@@ -21,7 +21,7 @@ Gem::Specification.new do |s|
21
21
 
22
22
  s.add_dependency 'activemerchant', '~> 1.48'
23
23
  s.add_dependency 'acts_as_list', '~> 0.3'
24
- s.add_dependency 'awesome_nested_set', '~> 3.0.1'
24
+ s.add_dependency 'awesome_nested_set', '~> 3.0', '>= 3.0.1'
25
25
  s.add_dependency 'carmen', '~> 1.0.0'
26
26
  s.add_dependency 'cancancan', '~> 1.10'
27
27
  s.add_dependency 'ffaker', '~> 2.0'
@@ -29,7 +29,7 @@ Gem::Specification.new do |s|
29
29
  s.add_dependency 'highline', '~> 1.6.18' # Necessary for the install generator
30
30
  s.add_dependency 'kaminari', '~> 0.15', '>= 0.15.1'
31
31
  s.add_dependency 'monetize', '~> 1.1'
32
- s.add_dependency 'paperclip', '~> 4.2.0'
32
+ s.add_dependency 'paperclip', '~> 4.2'
33
33
  s.add_dependency 'paranoia', '~> 2.1', '>= 2.1.4'
34
34
  s.add_dependency 'premailer-rails'
35
35
  s.add_dependency 'rails', '~> 4.2.5'
@@ -37,7 +37,7 @@ Gem::Specification.new do |s|
37
37
  s.add_dependency 'responders'
38
38
  s.add_dependency 'state_machines-activerecord', '~> 0.2'
39
39
  s.add_dependency 'stringex', '~> 1.5.1'
40
- s.add_dependency 'truncate_html', '0.9.2'
40
+ s.add_dependency 'truncate_html', '~> 0.9', '>= 0.9.2'
41
41
  s.add_dependency 'twitter_cldr', '~> 3.0'
42
42
 
43
43
  s.add_development_dependency 'email_spec', '~> 1.6'
@@ -60,7 +60,7 @@ describe Spree::BaseHelper, type: :helper do
60
60
  end
61
61
 
62
62
  it "should not raise errors when style exists" do
63
- ActiveSupport::Deprecation.silence do
63
+ Spree::Deprecation.silence do
64
64
  very_strange_image(product)
65
65
  end
66
66
  end
@@ -152,7 +152,7 @@ describe Spree::BaseHelper, type: :helper do
152
152
  end
153
153
 
154
154
  it "should not raise errors when helper method called" do
155
- ActiveSupport::Deprecation.silence do
155
+ Spree::Deprecation.silence do
156
156
  foobar_image(product)
157
157
  end
158
158
  end
@@ -167,4 +167,20 @@ describe Spree::BaseHelper, type: :helper do
167
167
  expect(pretty_time(DateTime.new(2012, 5, 6, 13, 33))).to eq "May 06, 2012 1:33 PM"
168
168
  end
169
169
  end
170
+
171
+ context "plural_resource_name" do
172
+ let(:plural_config) { Spree::I18N_GENERIC_PLURAL }
173
+ let(:base_class) { Spree::Product }
174
+
175
+ subject { plural_resource_name(base_class) }
176
+
177
+ it "should use ActiveModel::Naming module to pluralize model names" do
178
+ expect(subject).to eq base_class.model_name.human(count: plural_config)
179
+ end
180
+
181
+ it "should use the Spree::I18N_GENERIC_PLURAL constant" do
182
+ expect(base_class.model_name).to receive(:human).with(hash_including(count: plural_config))
183
+ subject
184
+ end
185
+ end
170
186
  end
@@ -40,6 +40,10 @@ describe "i18n" do
40
40
  expect(Spree.t(:missing_entry)).to include("<span")
41
41
  end
42
42
 
43
+ it "should have a Spree::I18N_GENERIC_PLURAL constant" do
44
+ expect(Spree::I18N_GENERIC_PLURAL).to eq 2.1
45
+ end
46
+
43
47
  context "missed + unused translations" do
44
48
  def key_with_locale(key)
45
49
  "#{key} (#{I18n.locale})"
@@ -66,14 +66,26 @@ describe Spree::Core::ControllerHelpers::Order, type: :controller do
66
66
  end
67
67
 
68
68
  describe '#set_current_order' do
69
- let(:incomplete_order) { create(:order, user: user) }
69
+ let(:incomplete_order) { create(:order, store: incomplete_order_store, user: user) }
70
70
 
71
71
  context 'when current order not equal to users incomplete orders' do
72
72
  before { allow(controller).to receive_messages(current_order: order, last_incomplete_order: incomplete_order, cookies: double(signed: { guest_token: 'guest_token' })) }
73
73
 
74
- it 'calls Spree::Order#merge! method' do
75
- expect(order).to receive(:merge!).with(incomplete_order, user)
76
- controller.set_current_order
74
+ context "an order from another store" do
75
+ let(:incomplete_order_store) { create(:store) }
76
+
77
+ it 'doesnt call Spree::Order#merge! method' do
78
+ expect(order).to_not receive(:merge!)
79
+ controller.set_current_order
80
+ end
81
+ end
82
+ context "an order from the same store" do
83
+ let(:incomplete_order_store) { store }
84
+
85
+ it 'calls Spree::Order#merge! method' do
86
+ expect(order).to receive(:merge!).with(incomplete_order, user)
87
+ controller.set_current_order
88
+ end
77
89
  end
78
90
  end
79
91
  end