Skip to content

Commit

Permalink
Order#token should always delegate to the user, even when not anonymous.
Browse files Browse the repository at this point in the history
  • Loading branch information
schof authored and Zac Williams committed Sep 28, 2010
1 parent 175b836 commit bb24cea
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 10 deletions.
6 changes: 2 additions & 4 deletions auth/app/models/order_decorator.rb
@@ -1,4 +1,6 @@
Order.class_eval do
delegate :token, :to => :user

# Associates the specified user with the order and destroys any previous association with guest user if
# necessary.
def associate_user!(user)
Expand All @@ -8,10 +10,6 @@ def associate_user!(user)
save(:validate => false)
end

def token
user.token if user.anonymous?
end

validates_format_of :email, :with => Authlogic::Regex.email, :if => :require_email

end
7 changes: 1 addition & 6 deletions auth/spec/models/order_spec.rb
Expand Up @@ -3,16 +3,11 @@
describe Order do
let(:order) { Order.new }
context "#token" do
it "should be the same as the user's token when the user is a guest" do
it "should be the same as the user's token" do
user = mock_model(User, :anonymous? => true, :token => "foo")
order.user = user
order.token.should == user.token
end
it "should be nil when the user is registered" do
user = mock_model(User, :anonymous? => false, :token => "foo")
order.user = user
order.token.should be_nil
end
end
context "#associate_user!" do
let(:user) { mock_model User, :anonymous? => false, :email => 'spree@example.com' }
Expand Down

0 comments on commit bb24cea

Please sign in to comment.