spree_core 2.1.1 → 2.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/spree/base_controller.rb +1 -2
  3. data/app/helpers/spree/products_helper.rb +8 -3
  4. data/app/mailers/spree/base_mailer.rb +5 -0
  5. data/app/models/spree/ability.rb +0 -3
  6. data/app/models/spree/adjustment.rb +2 -1
  7. data/app/models/spree/app_configuration.rb +2 -0
  8. data/app/models/spree/classification.rb +3 -0
  9. data/app/models/spree/country.rb +2 -1
  10. data/app/models/spree/image.rb +1 -1
  11. data/app/models/spree/line_item.rb +2 -0
  12. data/app/models/spree/order.rb +33 -16
  13. data/app/models/spree/order/checkout.rb +1 -1
  14. data/app/models/spree/payment.rb +14 -2
  15. data/app/models/spree/payment/processing.rb +3 -3
  16. data/app/models/spree/preferences/configuration.rb +5 -1
  17. data/app/models/spree/preferences/preferable.rb +5 -1
  18. data/app/models/spree/preferences/store.rb +14 -15
  19. data/app/models/spree/product.rb +4 -3
  20. data/app/models/spree/product/scopes.rb +7 -14
  21. data/app/models/spree/return_authorization.rb +3 -6
  22. data/app/models/spree/shipment.rb +4 -1
  23. data/app/models/spree/state.rb +1 -0
  24. data/app/models/spree/stock/availability_validator.rb +1 -1
  25. data/app/models/spree/stock/estimator.rb +26 -26
  26. data/app/models/spree/stock/quantifier.rb +1 -1
  27. data/app/models/spree/stock_item.rb +11 -7
  28. data/app/models/spree/variant.rb +4 -3
  29. data/config/locales/en.yml +8 -2
  30. data/config/routes.rb +1 -0
  31. data/db/default/spree/countries.rb +26 -26
  32. data/db/migrate/20130213191427_create_default_stock.rb +5 -2
  33. data/db/migrate/20130830001033_add_shipping_category_to_shipping_methods_and_products.rb +15 -0
  34. data/db/migrate/20130830001159_migrate_old_shipping_calculators.rb +19 -0
  35. data/db/migrate/20130909115621_change_states_required_for_countries.rb +9 -0
  36. data/db/migrate/20131001013410_remove_unused_credit_card_fields.rb +12 -0
  37. data/lib/spree/core/controller_helpers/order.rb +1 -1
  38. data/lib/spree/core/controller_helpers/ssl.rb +22 -13
  39. data/lib/spree/core/engine.rb +2 -10
  40. data/lib/spree/core/permalinks.rb +1 -5
  41. data/lib/spree/core/preference_rescue.rb +25 -0
  42. data/lib/spree/core/product_filters.rb +34 -38
  43. data/lib/spree/core/routes.rb +48 -0
  44. data/lib/spree/core/version.rb +1 -1
  45. data/lib/spree/money.rb +4 -0
  46. data/lib/spree/permitted_attributes.rb +1 -1
  47. data/lib/spree/testing_support/factories/credit_card_factory.rb +1 -1
  48. metadata +15 -9
  49. data/app/views/spree/shared/_address.html.erb +0 -38
@@ -4,10 +4,13 @@ class CreateDefaultStock < ActiveRecord::Migration
4
4
  Spree::StockItem.skip_callback(:save, :after, :process_backorders)
5
5
  location = Spree::StockLocation.new(name: 'default')
6
6
  location.save(validate: false)
7
+
7
8
  Spree::Variant.all.each do |variant|
8
- stock_item = location.stock_items.build(variant: variant)
9
+ stock_item = Spree::StockItem.unscoped.build(stock_location: location, variant: variant)
9
10
  stock_item.send(:count_on_hand=, variant.count_on_hand)
10
- stock_item.save!
11
+ # Avoid running default_scope defined by acts_as_paranoid, related to #3805,
12
+ # validations would run a query with a delete_at column tha might not be present yet
13
+ stock_item.save! validate: false
11
14
  end
12
15
 
13
16
  remove_column :spree_variants, :count_on_hand
@@ -0,0 +1,15 @@
1
+ class AddShippingCategoryToShippingMethodsAndProducts < ActiveRecord::Migration
2
+ def up
3
+ default_category = Spree::ShippingCategory.first
4
+ default_category ||= Spree::ShippingCategory.create!(:name => "Default")
5
+
6
+ Spree::ShippingMethod.all.each do |method|
7
+ method.shipping_categories << default_category if method.shipping_categories.blank?
8
+ end
9
+
10
+ Spree::Product.where(shipping_category_id: nil).update_all(shipping_category_id: default_category.id)
11
+ end
12
+
13
+ def down
14
+ end
15
+ end
@@ -0,0 +1,19 @@
1
+ class MigrateOldShippingCalculators < ActiveRecord::Migration
2
+ def up
3
+ Spree::ShippingMethod.all.each do |shipping_method|
4
+ old_calculator = shipping_method.calculator
5
+ next if old_calculator.class < Spree::ShippingCalculator # We don't want to mess with new shipping calculators
6
+ new_calculator = eval("Spree::Calculator::Shipping::#{old_calculator.class.name.demodulize}").new
7
+ new_calculator.preferences.keys.each do |pref|
8
+ # Preferences can't be read/set by name, you have to prefix preferred_
9
+ pref_method = "preferred_#{pref}"
10
+ new_calculator.send("#{pref_method}=", old_calculator.send(pref_method))
11
+ end
12
+ new_calculator.calculable = old_calculator.calculable
13
+ new_calculator.save
14
+ end
15
+ end
16
+
17
+ def down
18
+ end
19
+ end
@@ -0,0 +1,9 @@
1
+ class ChangeStatesRequiredForCountries < ActiveRecord::Migration
2
+ def up
3
+ change_column_default :spree_countries, :states_required, false
4
+ end
5
+
6
+ def down
7
+ change_column_default :spree_countries, :states_required, true
8
+ end
9
+ end
@@ -0,0 +1,12 @@
1
+ class RemoveUnusedCreditCardFields < ActiveRecord::Migration
2
+ def up
3
+ remove_column :spree_credit_cards, :start_month
4
+ remove_column :spree_credit_cards, :start_year
5
+ remove_column :spree_credit_cards, :issue_number
6
+ end
7
+ def down
8
+ add_column :spree_credit_cards, :start_month, :string
9
+ add_column :spree_credit_cards, :start_year, :string
10
+ add_column :spree_credit_cards, :issue_number, :string
11
+ end
12
+ end
@@ -59,7 +59,7 @@ module Spree
59
59
  if session[:order_id].nil? && last_incomplete_order
60
60
  session[:order_id] = last_incomplete_order.id
61
61
  elsif current_order(true) && last_incomplete_order && current_order != last_incomplete_order
62
- current_order.merge!(last_incomplete_order)
62
+ current_order.merge!(last_incomplete_order, user)
63
63
  end
64
64
  end
65
65
  end
@@ -6,20 +6,20 @@ module Spree
6
6
 
7
7
  included do
8
8
  before_filter :force_non_ssl_redirect, :if => Proc.new { Spree::Config[:redirect_https_to_http] }
9
+ class_attribute :ssl_allowed_actions
9
10
 
10
11
  def self.ssl_allowed(*actions)
11
- class_attribute :ssl_allowed_actions
12
- self.ssl_allowed_actions = actions
12
+ self.ssl_allowed_actions ||= []
13
+ self.ssl_allowed_actions.concat actions
13
14
  end
14
15
 
15
16
  def self.ssl_required(*actions)
16
- class_attribute :ssl_required_actions
17
- self.ssl_required_actions = actions
17
+ ssl_allowed *actions
18
18
  if ssl_supported?
19
- if ssl_required_actions.empty? or Rails.application.config.force_ssl
19
+ if actions.empty? or Rails.application.config.force_ssl
20
20
  force_ssl
21
21
  else
22
- force_ssl :only => ssl_required_actions
22
+ force_ssl :only => actions
23
23
  end
24
24
  end
25
25
  end
@@ -31,19 +31,28 @@ module Spree
31
31
  end
32
32
 
33
33
  private
34
+ def ssl_allowed?
35
+ (!ssl_allowed_actions.nil? && (ssl_allowed_actions.empty? || ssl_allowed_actions.include?(action_name.to_sym)))
36
+ end
34
37
 
35
38
  # Redirect the existing request to use the HTTP protocol.
36
39
  #
37
40
  # ==== Parameters
38
41
  # * <tt>host</tt> - Redirect to a different host name
39
42
  def force_non_ssl_redirect(host = nil)
40
- return true if defined?(ssl_allowed_actions) and ssl_allowed_actions.include?(action_name.to_sym)
41
- if request.ssl? and (!defined?(ssl_required_actions) or !ssl_required_actions.include?(action_name.to_sym))
42
- redirect_options = {:protocol => 'http://', :status => :moved_permanently}
43
- redirect_options.merge!(:host => host) if host
44
- redirect_options.merge!(:params => request.query_parameters)
45
- flash.keep if respond_to?(:flash)
46
- redirect_to redirect_options
43
+ if request.ssl? && !ssl_allowed?
44
+ if request.get?
45
+ redirect_options = {
46
+ :protocol => 'http://',
47
+ :host => host || request.host,
48
+ :path => request.fullpath,
49
+ }
50
+ flash.keep if respond_to?(:flash)
51
+ insecure_url = ActionDispatch::Http::URL.url_for(redirect_options)
52
+ redirect_to insecure_url, :status => :moved_permanently
53
+ else
54
+ render :text => Spree.t(:change_protocol, :scope => :ssl), :status => :upgrade_required
55
+ end
47
56
  end
48
57
  end
49
58
  end
@@ -16,16 +16,6 @@ module Spree
16
16
  end
17
17
  end
18
18
 
19
- # We need to reload the routes here due to how Spree sets them up.
20
- # The different facets of Spree (backend, frontend, etc.) append/prepend
21
- # routes to Core *after* Core has been loaded.
22
- #
23
- # So we wait until after initialization is complete to do one final reload.
24
- # This then makes the appended/prepended routes available to the application.
25
- config.after_initialize do
26
- Rails.application.routes_reloader.reload!
27
- end
28
-
29
19
  initializer "spree.environment", :before => :load_config_initializers do |app|
30
20
  app.config.spree = Spree::Core::Environment.new
31
21
  Spree::Config = app.config.spree.preferences #legacy access
@@ -111,3 +101,5 @@ module Spree
111
101
  end
112
102
  end
113
103
  end
104
+
105
+ require 'spree/core/routes'
@@ -14,11 +14,7 @@ module Spree
14
14
  options[:field] ||= :permalink
15
15
  self.permalink_options = options
16
16
 
17
- if self.connected?
18
- if self.table_exists? && self.column_names.include?(permalink_options[:field].to_s)
19
- before_validation(:on => :create) { save_permalink }
20
- end
21
- end
17
+ before_validation(:on => :create) { save_permalink }
22
18
  end
23
19
 
24
20
  def find_by_param(value, *args)
@@ -0,0 +1,25 @@
1
+ module Spree
2
+ class OldPrefs < ActiveRecord::Base
3
+ self.table_name = "spree_preferences"
4
+ belongs_to :owner, :polymorphic => true
5
+ attr_accessor :owner_klass
6
+ end
7
+
8
+ class PreferenceRescue
9
+ def self.try
10
+ OldPrefs.where(:key => nil).each do |old_pref|
11
+ next unless owner = (old_pref.owner rescue nil)
12
+ unless old_pref.owner_type == "Spree::Activator" || old_pref.owner_type == "Spree::Configuration"
13
+ begin
14
+ old_pref.key = [owner.class.name, old_pref.name, owner.id].join('::').underscore
15
+ old_pref.value_type = owner.preference_type(old_pref.name)
16
+ puts "Migrating Preference: #{old_pref.key}"
17
+ old_pref.save
18
+ rescue NoMethodError => ex
19
+ puts ex.message
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -97,28 +97,26 @@ module Spree
97
97
  # the (uniquely named) field "p_brand.value". There's also a test for brand info
98
98
  # being blank: note that this relies on with_property doing a left outer join
99
99
  # rather than an inner join.
100
- if Spree::Property.table_exists?
101
- Spree::Product.add_search_scope :brand_any do |*opts|
102
- conds = opts.map {|o| ProductFilters.brand_filter[:conds][o]}.reject { |c| c.nil? }
103
- scope = conds.shift
104
- conds.each do |new_scope|
105
- scope = scope.or(new_scope)
106
- end
107
- Spree::Product.with_property('brand').where(scope)
100
+ Spree::Product.add_search_scope :brand_any do |*opts|
101
+ conds = opts.map {|o| ProductFilters.brand_filter[:conds][o]}.reject { |c| c.nil? }
102
+ scope = conds.shift
103
+ conds.each do |new_scope|
104
+ scope = scope.or(new_scope)
108
105
  end
106
+ Spree::Product.with_property('brand').where(scope)
107
+ end
109
108
 
110
- def ProductFilters.brand_filter
111
- brand_property = Spree::Property.find_by(name: 'brand')
112
- brands = brand_property ? Spree::ProductProperty.where(property_id: brand_property.id).pluck(:value).uniq.map(&:to_s) : []
113
- pp = Spree::ProductProperty.arel_table
114
- conds = Hash[*brands.map { |b| [b, pp[:value].eq(b)] }.flatten]
115
- {
116
- name: 'Brands',
117
- scope: :brand_any,
118
- conds: conds,
119
- labels: (brands.sort).map { |k| [k, k] }
120
- }
121
- end
109
+ def ProductFilters.brand_filter
110
+ brand_property = Spree::Property.find_by(name: 'brand')
111
+ brands = brand_property ? Spree::ProductProperty.where(property_id: brand_property.id).pluck(:value).uniq.map(&:to_s) : []
112
+ pp = Spree::ProductProperty.arel_table
113
+ conds = Hash[*brands.map { |b| [b, pp[:value].eq(b)] }.flatten]
114
+ {
115
+ name: 'Brands',
116
+ scope: :brand_any,
117
+ conds: conds,
118
+ labels: (brands.sort).map { |k| [k, k] }
119
+ }
122
120
  end
123
121
 
124
122
  # Example: a parameterized filter
@@ -140,25 +138,23 @@ module Spree
140
138
  #
141
139
  # The brand-finding code can be simplified if a few more named scopes were added to
142
140
  # the product properties model.
143
- if Spree::Property.table_exists?
144
- Spree::Product.add_search_scope :selective_brand_any do |*opts|
145
- Spree::Product.brand_any(*opts)
146
- end
141
+ Spree::Product.add_search_scope :selective_brand_any do |*opts|
142
+ Spree::Product.brand_any(*opts)
143
+ end
147
144
 
148
- def ProductFilters.selective_brand_filter(taxon = nil)
149
- taxon ||= Spree::Taxonomy.first.root
150
- brand_property = Spree::Property.find_by(name: 'brand')
151
- scope = Spree::ProductProperty.where(property: brand_property).
152
- joins(product: :taxons).
153
- where("#{Spree::Taxon.table_name}.id" => [taxon] + taxon.descendants).
154
- scoped
155
- brands = scope.pluck(:value).uniq
156
- {
157
- name: 'Applicable Brands',
158
- scope: :selective_brand_any,
159
- labels: brands.sort.map { |k| [k, k] }
160
- }
161
- end
145
+ def ProductFilters.selective_brand_filter(taxon = nil)
146
+ taxon ||= Spree::Taxonomy.first.root
147
+ brand_property = Spree::Property.find_by(name: 'brand')
148
+ scope = Spree::ProductProperty.where(property: brand_property).
149
+ joins(product: :taxons).
150
+ where("#{Spree::Taxon.table_name}.id" => [taxon] + taxon.descendants).
151
+ scoped
152
+ brands = scope.pluck(:value).uniq
153
+ {
154
+ name: 'Applicable Brands',
155
+ scope: :selective_brand_any,
156
+ labels: brands.sort.map { |k| [k, k] }
157
+ }
162
158
  end
163
159
 
164
160
  # Provide filtering on the immediate children of a taxon
@@ -0,0 +1,48 @@
1
+ module Spree
2
+ module Core
3
+ class Engine < ::Rails::Engine
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
20
+ end
21
+
22
+ 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
28
+ end
29
+
30
+ 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
+ private
42
+
43
+ def eval_block(&block)
44
+ Spree::Core::Engine.routes.eval_block(block)
45
+ end
46
+ end
47
+ end
48
+ end
@@ -1,5 +1,5 @@
1
1
  module Spree
2
2
  def self.version
3
- "2.1.1"
3
+ "2.1.2"
4
4
  end
5
5
  end
data/lib/spree/money.rb CHANGED
@@ -33,6 +33,10 @@ module Spree
33
33
  output
34
34
  end
35
35
 
36
+ def as_json(*)
37
+ to_s
38
+ end
39
+
36
40
  def ==(obj)
37
41
  @money == obj.money
38
42
  end
@@ -31,7 +31,7 @@ module Spree
31
31
  :city, :country_id, :state_id, :zipcode, :phone,
32
32
  :state_name, :alternative_phone, :company]
33
33
 
34
- @@checkout_attributes = [:email, :use_billing, :shipping_method_id, :coupon_code]
34
+ @@checkout_attributes = [:email, :use_billing, :shipping_method_id, :coupon_code, :special_instructions]
35
35
 
36
36
  @@image_attributes = [:alt, :attachment, :position, :viewable_type, :viewable_id]
37
37
 
@@ -7,7 +7,7 @@ FactoryGirl.define do
7
7
  factory :credit_card, class: TestCard do
8
8
  verification_value 123
9
9
  month 12
10
- year 2013
10
+ year { Time.now.year }
11
11
  number '4111111111111111'
12
12
  end
13
13
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spree_core
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.1
4
+ version: 2.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sean Schofield
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-17 00:00:00.000000000 Z
11
+ date: 2013-10-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemerchant
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 1.34.0
19
+ version: 1.39.2
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 1.34.0
26
+ version: 1.39.2
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: acts_as_list
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - ~>
46
46
  - !ruby/object:Gem::Version
47
- version: 3.0.0.rc.1
47
+ version: 3.0.0.rc.2
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - ~>
53
53
  - !ruby/object:Gem::Version
54
- version: 3.0.0.rc.1
54
+ version: 3.0.0.rc.2
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: aws-sdk
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -168,14 +168,14 @@ dependencies:
168
168
  name: money
169
169
  requirement: !ruby/object:Gem::Requirement
170
170
  requirements:
171
- - - '='
171
+ - - '>='
172
172
  - !ruby/object:Gem::Version
173
173
  version: 5.1.1
174
174
  type: :runtime
175
175
  prerelease: false
176
176
  version_requirements: !ruby/object:Gem::Requirement
177
177
  requirements:
178
- - - '='
178
+ - - '>='
179
179
  - !ruby/object:Gem::Version
180
180
  version: 5.1.1
181
181
  - !ruby/object:Gem::Dependency
@@ -416,13 +416,13 @@ files:
416
416
  - app/views/spree/order_mailer/cancel_email.text.erb
417
417
  - app/views/spree/order_mailer/confirm_email.text.erb
418
418
  - app/views/spree/payments/_payment.html.erb
419
- - app/views/spree/shared/_address.html.erb
420
419
  - app/views/spree/shared/_error_messages.html.erb
421
420
  - app/views/spree/shared/_routes.html.erb
422
421
  - app/views/spree/shipment_mailer/shipped_email.text.erb
423
422
  - app/views/spree/test_mailer/test_email.text.erb
424
423
  - config/initializers/user_class_extensions.rb
425
424
  - config/locales/en.yml
425
+ - config/routes.rb
426
426
  - lib/generators/spree/custom_user/custom_user_generator.rb
427
427
  - lib/generators/spree/custom_user/templates/authentication_helpers.rb.tt
428
428
  - lib/generators/spree/custom_user/templates/initializer.rb.tt
@@ -460,8 +460,10 @@ files:
460
460
  - lib/spree/core/mail_interceptor.rb
461
461
  - lib/spree/core/mail_settings.rb
462
462
  - lib/spree/core/permalinks.rb
463
+ - lib/spree/core/preference_rescue.rb
463
464
  - lib/spree/core/product_duplicator.rb
464
465
  - lib/spree/core/product_filters.rb
466
+ - lib/spree/core/routes.rb
465
467
  - lib/spree/core/s3_support.rb
466
468
  - lib/spree/core/search/base.rb
467
469
  - lib/spree/core/token_resource.rb
@@ -618,7 +620,11 @@ files:
618
620
  - db/migrate/20130809164330_add_admin_name_column_to_spree_stock_locations.rb
619
621
  - db/migrate/20130813140619_expand_order_number_size.rb
620
622
  - db/migrate/20130826062534_add_depth_to_spree_taxons.rb
623
+ - db/migrate/20130830001033_add_shipping_category_to_shipping_methods_and_products.rb
624
+ - db/migrate/20130830001159_migrate_old_shipping_calculators.rb
625
+ - db/migrate/20130909115621_change_states_required_for_countries.rb
621
626
  - db/migrate/20130915032339_add_deleted_at_to_spree_stock_items.rb
627
+ - db/migrate/20131001013410_remove_unused_credit_card_fields.rb
622
628
  - db/seeds.rb
623
629
  - vendor/assets/javascripts/jquery-migrate-1.0.0.js
624
630
  - vendor/assets/javascripts/jquery.payment.js