Permalink
Browse files

Added more User specs related to tokens. Fixed a few require and gems…

…pecs related to the new spree_auth gem.
  • Loading branch information...
1 parent 44d6319 commit 93ea614f28095214751df79840fc4d335a82f986 @schof schof committed Aug 10, 2010
@@ -1,13 +1,14 @@
User.class_eval do
alias_attribute :token, :api_key
- before_save :generate_token
+ before_validation :generate_token
+ validates_presence_of :token
def generate_token
- self.token = secure_digest(Time.now, (1..10).map{ rand.to_s })
+ self.token ||= secure_digest(Time.now, (1..10).map{ rand.to_s })
end
def regenerate_token!
- self.update_attribute(:token, secure_digest(Time.now, (1..10).map{ rand.to_s }))
+ self.update_attribute(:api_key, secure_digest(Time.now, (1..10).map{ rand.to_s }))
end
private
View
@@ -1,4 +1,5 @@
require 'spree_core'
+require 'cancan'
module SpreeAuth
class Engine < Rails::Engine
@@ -8,7 +8,16 @@
user.token.should_not be_nil
end
end
- context "#regenerate_token!" do
- it "should change the token"
+ context "with token" do
+ let(:user) { User.create(:email => "foo@bar.com", :password => "secret", :password_confirmation => "secret") }
+ let(:original_token) { user.token }
+ pending "#regenerate_token! should change the token" do
+ user.regenerate_token!
+ user.token.should_not == original_token
+ end
+ it "#save should not change the value of the token" do
+ user.save
+ user.token.should == original_token
+ end
end
end
View
@@ -20,4 +20,5 @@ Gem::Specification.new do |s|
s.has_rdoc = true
s.add_dependency('spree_core', version)
+ s.add_dependency('cancan', '>= 1.3.0')
end
View
@@ -38,7 +38,6 @@
require 'acts_as_list'
require 'resource_controller'
require 'searchlogic'
-require 'cancan'
require 'spree_core/delegate_belongs_to'
require 'spree_core/theme_support'
View
@@ -37,5 +37,4 @@ Gem::Specification.new do |s|
s.add_dependency('rd_searchlogic')
s.add_dependency('activemerchant', '>= 1.7.1')
s.add_dependency('will_paginate', '>= 3.0.pre')
- s.add_dependency('cancan', '>= 1.3.0')
end
View
@@ -1,13 +1,7 @@
require 'spree_core'
+require 'spree_auth'
require 'spree_api'
require 'spree_dashboard'
require 'spree_payment_gateway'
require 'spree_promotions'
-require 'spree_sample'
-
-begin
- # contains site specific logic for overriding spree stuff
- require 'spree_site'
-rescue Exception
- # no big deal - we can generate one using 'rails g spree:site'
-end
+require 'spree_sample'

0 comments on commit 93ea614

Please sign in to comment.