spree_core 2.3.2 → 2.3.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b7bfe527c1516e5d8393c4cb6a23bf795bff2f8d
4
- data.tar.gz: dd9c6e528157dd843740ff2cd5bc86d6fa906192
3
+ metadata.gz: 7b180601af90a25cab2272036e7e46087ad23181
4
+ data.tar.gz: 9380b234a2c586b66ca775c79d6299d9d65c5b0b
5
5
  SHA512:
6
- metadata.gz: 0fb13c6c497d8ab9d920e6f950a532e16524f305e2591e82b12bd1ae1aa47d53f2a8ca0fd293d588c8b8ed32d3bac49c2a2cfef851a1ba9b237b7149994c9f60
7
- data.tar.gz: 5ea8cacb10c49bf4afaa936a9ae348d13979a1f30855214e491aff0abf9ca9ba3f495f7d38c295a1266b4be9ab26e5adbf47c5dc464b72fc0555b2fc2740f1d8
6
+ metadata.gz: b175161e97670be7b65499e3b07b105f62847bd5ee18a7f07cfb83215c0756d6ff99bb617986ffcb860dfecc440df8f63b9313048cc6e7bcdac7428e58c9c3fc
7
+ data.tar.gz: a3a4564276563192dc89b30e225aff9b28ccc5c1ddaeb0696403f6a8a062df67267fe152154c15f7cc0274c0cccf7408131a430c679d4ad6c7e2fbd0b8ac3ce6
@@ -7,7 +7,8 @@ class window.Spree
7
7
  "<%= Rails.application.routes.url_helpers.spree_path %>"
8
8
 
9
9
  @pathFor: (path) ->
10
- "#{window.location.origin}#{@mountedAt()}#{path}"
10
+ locationOrigin = "#{window.location.protocol}//#{window.location.hostname}" + (if window.location.port then ":#{window.location.port}" else "")
11
+ "#{locationOrigin}#{@mountedAt()}#{path}"
11
12
 
12
13
  # Helper function to take a URL and add query parameters to it
13
14
  # Uses the JSUri library from here: https://code.google.com/p/jsuri/
@@ -46,10 +46,6 @@ module Spree
46
46
  can [:read, :update], Order do |order, token|
47
47
  order.user == user || order.guest_token && token == order.guest_token
48
48
  end
49
- can [:create, :read], Address
50
- can :update, Address do |address|
51
- user.bill_address == address || user.ship_address == address
52
- end
53
49
  can :display, CreditCard, user_id: user.id
54
50
  can :display, Product
55
51
  can :display, ProductProperty
@@ -629,14 +629,12 @@ module Spree
629
629
  end
630
630
  end
631
631
 
632
- def after_cancel
633
- shipments.each { |shipment| shipment.cancel! }
634
- payments.completed.each { |payment| payment.cancel! }
635
-
636
- send_cancel_email
637
- self.update_column(:payment_state, 'credit_owed') unless shipped?
638
- self.update!
639
- end
632
+ def after_cancel
633
+ shipments.each { |shipment| shipment.cancel! }
634
+ payments.completed.each { |payment| payment.cancel! }
635
+ send_cancel_email
636
+ self.update!
637
+ end
640
638
 
641
639
  def send_cancel_email
642
640
  OrderMailer.cancel_email(self.id).deliver
@@ -71,7 +71,7 @@ module Spree
71
71
 
72
72
  if states[:payment]
73
73
  before_transition to: :complete do |order|
74
- if order.payment_required? && order.payments.empty?
74
+ if order.payment_required? && order.payments.valid.empty?
75
75
  order.errors.add(:base, Spree.t(:no_payment_found))
76
76
  false
77
77
  elsif order.payment_required?
@@ -96,6 +96,7 @@ module Spree
96
96
  if states[:delivery]
97
97
  before_transition to: :delivery, do: :create_proposed_shipments
98
98
  before_transition to: :delivery, do: :ensure_available_shipping_rates
99
+ before_transition to: :delivery, do: :set_shipments_cost
99
100
  before_transition from: :delivery, do: :apply_free_shipping_promotions
100
101
  end
101
102
 
@@ -11,7 +11,6 @@ module Spree
11
11
 
12
12
  def populate(variant_id, quantity)
13
13
  attempt_cart_add(variant_id, quantity)
14
- order.ensure_updated_shipments
15
14
  valid?
16
15
  end
17
16
 
@@ -26,7 +25,7 @@ module Spree
26
25
  # 2,147,483,647 is crazy.
27
26
  # See issue #2695.
28
27
  if quantity > 2_147_483_647
29
- errors.add(:base, Spree.t(:please_enter_reasonable_quantity, :scope => :order_populator))
28
+ errors.add(:base, Spree.t(:please_enter_reasonable_quantity, scope: :order_populator))
30
29
  return false
31
30
  end
32
31
 
@@ -168,6 +168,7 @@ module Spree
168
168
  order.payment_state = 'paid' if !order.outstanding_balance?
169
169
  end
170
170
  order.state_changed('payment') if last_state != order.payment_state
171
+ order.payment_state
171
172
  end
172
173
 
173
174
  private
@@ -23,12 +23,16 @@ module Spree
23
23
 
24
24
  # update the order totals, etc.
25
25
  after_save :update_order
26
+
26
27
  # invalidate previously entered payments
27
28
  after_create :invalidate_old_payments
28
29
 
29
30
  attr_accessor :source_attributes, :request_env
30
31
 
31
32
  after_initialize :build_source
33
+ after_rollback :persist_invalid
34
+
35
+ validates :amount, numericality: true
32
36
 
33
37
  default_scope -> { order("#{self.table_name}.created_at") }
34
38
 
@@ -41,10 +45,6 @@ module Spree
41
45
  scope :risky, -> { where("avs_response IN (?) OR (cvv_response_code IS NOT NULL and cvv_response_code != 'M') OR state = 'failed'", RISKY_AVS_CODES) }
42
46
  scope :valid, -> { where.not(state: %w(failed invalid)) }
43
47
 
44
- after_rollback :persist_invalid
45
-
46
- validates :amount, numericality: true
47
-
48
48
  def persist_invalid
49
49
  return unless ['failed', 'invalid'].include?(state)
50
50
  state_will_change!
@@ -81,6 +81,9 @@ module Spree
81
81
  end
82
82
 
83
83
  def credit!(credit_amount=nil)
84
+ raise Core::GatewayError.new(Spree.t(:payment_processing_failed)) if processing?
85
+
86
+ started_processing!
84
87
  protect_from_connection_error do
85
88
  check_environment
86
89
 
@@ -97,6 +100,7 @@ module Spree
97
100
  record_response(response)
98
101
 
99
102
  if response.success?
103
+ self.update_column(:state, 'completed')
100
104
  self.class.create!(
101
105
  :order => order,
102
106
  :source => self,
@@ -121,7 +125,6 @@ module Spree
121
125
 
122
126
  def partial_credit(amount)
123
127
  return if amount > credit_allowed
124
- started_processing!
125
128
  credit!(amount)
126
129
  end
127
130
 
@@ -273,11 +273,22 @@ module Spree
273
273
  end
274
274
 
275
275
  # there's a weird quirk with the delegate stuff that does not automatically save the delegate object
276
- # when saving so we force a save using a hook.
276
+ # when saving so we force a save using a hook
277
+ # Fix for issue #5306
277
278
  def save_master
278
- if master && (master.changed? || master.new_record? || (master.default_price && (master.default_price.changed? || master.default_price.new_record?)))
279
- master.save
280
- @nested_changes = true
279
+ begin
280
+ if master && (master.changed? || master.new_record? || (master.default_price && (master.default_price.changed? || master.default_price.new_record?)))
281
+ master.save!
282
+ @nested_changes = true
283
+ end
284
+
285
+ # If the master cannot be saved, the Product object will get its errors
286
+ # and will be destroyed
287
+ rescue ActiveRecord::RecordInvalid
288
+ master.errors.each do |att, error|
289
+ self.errors.add(att, error)
290
+ end
291
+ raise
281
292
  end
282
293
  end
283
294
 
@@ -4,7 +4,8 @@ module Spree
4
4
  belongs_to :property, class_name: 'Spree::Property', inverse_of: :product_properties
5
5
 
6
6
  validates :property, presence: true
7
- validates :value, length: { maximum: 255 }
7
+
8
+ validates_with Spree::Validations::DbMaximumLengthValidator, field: :value
8
9
 
9
10
  default_scope -> { order("#{self.table_name}.position") }
10
11
 
@@ -23,6 +23,7 @@ module Spree
23
23
  before_save :normalize_blank_values
24
24
 
25
25
  scope :coupons, ->{ where("#{table_name}.code IS NOT NULL") }
26
+ scope :applied, -> { joins(:orders).uniq }
26
27
 
27
28
  def self.advertised
28
29
  where(advertise: true)
@@ -0,0 +1,22 @@
1
+ module Spree
2
+ module Validations
3
+ ##
4
+ # Validates a field based on the maximum length of the underlying DB field, if there is one.
5
+ class DbMaximumLengthValidator < ActiveModel::Validator
6
+
7
+ def initialize(options)
8
+ super
9
+ @field = options[:field].to_s
10
+ raise ArgumentError.new("a field must be specified to the validator") if @field.blank?
11
+ end
12
+
13
+ def validate(record)
14
+ limit = record.class.columns_hash[@field].limit
15
+ value = record[@field.to_sym]
16
+ if value && limit && value.to_s.length > limit
17
+ record.errors.add(@field.to_sym, :too_long, count: limit)
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -14,7 +14,15 @@ module Spree
14
14
 
15
15
  # Used in the link_to_cart helper.
16
16
  def simple_current_order
17
- @simple_current_order ||= Spree::Order.incomplete.find_by(current_order_params)
17
+
18
+ return @simple_current_order if @simple_current_order
19
+
20
+ @simple_current_order = find_order_by_token_or_user
21
+
22
+ if @simple_current_order
23
+ @simple_current_order.last_ip_address = ip_address
24
+ return @simple_current_order
25
+ end
18
26
  end
19
27
 
20
28
  # The current incomplete order from the guest_token for use in cart and during checkout
@@ -24,15 +32,9 @@ module Spree
24
32
 
25
33
  return @current_order if @current_order
26
34
 
27
- # Find any incomplete orders for the guest_token
28
- @current_order = Spree::Order.incomplete.includes(:adjustments).lock(options[:lock]).find_by(current_order_params)
35
+ @current_order = find_order_by_token_or_user(options)
29
36
 
30
- # Find any incomplete orders for the current user
31
- if @current_order.nil? && try_spree_current_user
32
- @current_order = Spree::Order.incomplete.order('id DESC').where({ currency: current_currency, user_id: try_spree_current_user.try(:id)}).first
33
- end
34
-
35
- if options[:create_order_if_necessary] and (@current_order.nil? or @current_order.completed?)
37
+ if options[:create_order_if_necessary] && (@current_order.nil? || @current_order.completed?)
36
38
  @current_order = Spree::Order.new(current_order_params)
37
39
  @current_order.user ||= try_spree_current_user
38
40
  # See issue #3346 for reasons why this line is here
@@ -79,6 +81,20 @@ module Spree
79
81
  def current_order_params
80
82
  { currency: current_currency, guest_token: cookies.signed[:guest_token], user_id: try_spree_current_user.try(:id) }
81
83
  end
84
+
85
+ def find_order_by_token_or_user(options={})
86
+
87
+ # Find any incomplete orders for the guest_token
88
+ order = Spree::Order.incomplete.includes(:adjustments).lock(options[:lock]).find_by(current_order_params)
89
+
90
+ # Find any incomplete orders for the current user
91
+ if order.nil? && try_spree_current_user
92
+ order = Spree::Order.incomplete.order('id DESC').where({ currency: current_currency, user_id: try_spree_current_user.try(:id)}).first
93
+ end
94
+
95
+ order
96
+ end
97
+
82
98
  end
83
99
  end
84
100
  end
@@ -13,10 +13,9 @@ module Spree
13
13
  end
14
14
 
15
15
  def retrieve_products
16
- @products_scope = get_base_scope
16
+ @products = get_base_scope
17
17
  curr_page = page || 1
18
18
 
19
- @products = @products_scope.includes([:master => :prices])
20
19
  unless Spree::Config.show_products_without_price
21
20
  @products = @products.where("spree_prices.amount IS NOT NULL").where("spree_prices.currency" => current_currency)
22
21
  end
@@ -37,9 +36,18 @@ module Spree
37
36
  base_scope = base_scope.in_taxon(taxon) unless taxon.blank?
38
37
  base_scope = get_products_conditions_for(base_scope, keywords)
39
38
  base_scope = add_search_scopes(base_scope)
39
+ base_scope = add_eagerload_scopes(base_scope)
40
40
  base_scope
41
41
  end
42
42
 
43
+ def add_eagerload_scopes scope
44
+ if include_images
45
+ scope.eager_load({master: [:prices, :images]})
46
+ else
47
+ scope.includes(master: :prices)
48
+ end
49
+ end
50
+
43
51
  def add_search_scopes(base_scope)
44
52
  search.each do |name, scope_attribute|
45
53
  scope_name = name.to_sym
@@ -64,6 +72,7 @@ module Spree
64
72
  @properties[:taxon] = params[:taxon].blank? ? nil : Spree::Taxon.find(params[:taxon])
65
73
  @properties[:keywords] = params[:keywords]
66
74
  @properties[:search] = params[:search]
75
+ @properties[:include_images] = params[:include_images]
67
76
 
68
77
  per_page = params[:per_page].to_i
69
78
  @properties[:per_page] = per_page > 0 ? per_page : Spree::Config[:products_per_page]
@@ -1,29 +1,7 @@
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'
4
1
  class EmailValidator < ActiveModel::EachValidator
5
2
  def validate_each(record,attribute,value)
6
- unless valid?(value)
3
+ unless value =~ /\A[^@\s]+@([^@\s]+\.)+[^@\s]+\z/
7
4
  record.errors.add(attribute, :invalid, {:value => value}.merge!(options))
8
5
  end
9
6
  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
29
7
  end
@@ -1,5 +1,5 @@
1
1
  module Spree
2
2
  def self.version
3
- "2.3.2"
3
+ '2.3.3'
4
4
  end
5
5
  end
@@ -13,7 +13,7 @@ module CapybaraExt
13
13
  end
14
14
 
15
15
  def within_row(num, &block)
16
- if example.metadata[:js]
16
+ if RSpec.current_example.metadata[:js]
17
17
  within("table.index tbody tr:nth-child(#{num})", &block)
18
18
  else
19
19
  within(:xpath, all("table.index tbody tr")[num-1].path, &block)
@@ -21,7 +21,7 @@ module CapybaraExt
21
21
  end
22
22
 
23
23
  def column_text(num)
24
- if example.metadata[:js]
24
+ if RSpec.current_example.metadata[:js]
25
25
  find("td:nth-child(#{num})").text
26
26
  else
27
27
  all("td")[num-1].text
@@ -133,7 +133,7 @@ RSpec::Matchers.define :have_meta do |name, expected|
133
133
  has_css?("meta[name='#{name}'][content='#{expected}']", visible: false)
134
134
  end
135
135
 
136
- failure_message_for_should do |actual|
136
+ failure_message do |actual|
137
137
  actual = first("meta[name='#{name}']")
138
138
  if actual
139
139
  "expected that meta #{name} would have content='#{expected}' but was '#{actual[:content]}'"
@@ -148,7 +148,7 @@ RSpec::Matchers.define :have_title do |expected|
148
148
  has_css?("title", :text => expected, visible: false)
149
149
  end
150
150
 
151
- failure_message_for_should do |actual|
151
+ failure_message do |actual|
152
152
  actual = first("title")
153
153
  if actual
154
154
  "expected that title would have been '#{expected}' but was '#{actual.text}'"
@@ -20,7 +20,7 @@ class OrderWalkthrough
20
20
  end
21
21
  end
22
22
 
23
- order = Spree::Order.create!(:email => "spree@example.com")
23
+ order = Spree::Order.create!(email: "spree@example.com")
24
24
  add_line_item!(order)
25
25
  order.next!
26
26
 
@@ -50,7 +50,7 @@ class OrderWalkthrough
50
50
  end
51
51
 
52
52
  def self.payment(order)
53
- order.payments.create!(:payment_method => Spree::PaymentMethod.first, :amount => order.total)
53
+ order.payments.create!(payment_method: Spree::PaymentMethod.first, amount: order.total)
54
54
  # TODO: maybe look at some way of making this payment_state change automatic
55
55
  order.payment_state = 'paid'
56
56
  order.next!
@@ -65,4 +65,3 @@ class OrderWalkthrough
65
65
  end
66
66
 
67
67
  end
68
-
@@ -22,8 +22,8 @@ module Spree
22
22
  end
23
23
 
24
24
  def assert_preference_unset(preference)
25
- find("#preferences_#{preference}")['checked'].should be_false
26
- Spree::Config[preference].should be_false
25
+ find("#preferences_#{preference}")['checked'].should be false
26
+ Spree::Config[preference].should be false
27
27
  end
28
28
  end
29
29
  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.3.2
4
+ version: 2.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sean Schofield
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-29 00:00:00.000000000 Z
11
+ date: 2014-09-19 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.43.1
19
+ version: 1.44.1
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.43.1
26
+ version: 1.44.1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: acts_as_list
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -445,6 +445,7 @@ files:
445
445
  - app/models/spree/taxon.rb
446
446
  - app/models/spree/taxonomy.rb
447
447
  - app/models/spree/tracker.rb
448
+ - app/models/spree/validations/db_maximum_length_validator.rb
448
449
  - app/models/spree/variant.rb
449
450
  - app/models/spree/variant/scopes.rb
450
451
  - app/models/spree/zone.rb