Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix check for order.guest_token presence #1705

Merged
merged 3 commits into from
Feb 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions core/app/models/spree/order.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
require 'spree/order/checkout'

module Spree
# The customers cart until completed, then acts as permenent record of the transaction.
# The customers cart until completed, then acts as permanent record of the transaction.
#
# `Spree::Order` is the heart of the Solidus system, as it acts as the customer's
# cart as they shop. Once an order is complete, it serves as the
# permenent record of their purchase. It has many responsibilities:
# permanent record of their purchase. It has many responsibilities:
#
# * Records and validates attributes like `total` and relationships like
# `Spree::LineItem` as an ActiveRecord model.
Expand Down Expand Up @@ -111,6 +111,7 @@ def states

validates :email, presence: true, if: :require_email
validates :email, email: true, allow_blank: true
validates :guest_token, presence: { allow_nil: true }
validates :number, presence: true, uniqueness: { allow_blank: true }
validates :store_id, presence: true

Expand Down
2 changes: 1 addition & 1 deletion core/lib/spree/permission_sets/default_customer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def activate!
can :display, OptionValue
can :create, Order
can [:read, :update], Order do |order, token|
order.user == user || order.guest_token && token == order.guest_token
order.user == user || (order.guest_token.present? && token == order.guest_token)
end
can :create, ReturnAuthorization do |return_authorization|
return_authorization.order.user == user
Expand Down
20 changes: 20 additions & 0 deletions core/spec/lib/spree/permission_sets/default_customer_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
require 'spec_helper'

describe Spree::PermissionSets::DefaultCustomer do
context 'as Guest User' do
context 'for Order' do
context 'guest_token is empty string' do
let(:ability) { Spree::Ability.new(nil) }
let(:resource) { build(:order) }
let(:token) { '' }

it 'should not be allowed to read or update the order' do
allow(resource).to receive_messages(guest_token: '')

expect(ability).to_not be_able_to(:read, resource, token)
expect(ability).to_not be_able_to(:update, resource, token)
end
end
end
end
end