Skip to content

Commit

Permalink
Remove Spree::User.anonymous!
Browse files Browse the repository at this point in the history
This appears to no longer have a use within Spree itself. Orders seem content to have an email associated with them, but no user associated
  • Loading branch information
radar committed Dec 16, 2013
1 parent c145eef commit 8156808
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 38 deletions.
2 changes: 1 addition & 1 deletion app/controllers/spree/admin/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def collection
{ :search => "#{params[:q].strip}%" })
.limit(params[:limit] || 100)
else
@search = Spree::User.registered.ransack(params[:q])
@search = Spree::User.ransack(params[:q])
@collection = @search.result.page(params[:page]).per(Spree::Config[:admin_products_per_page])
end
end
Expand Down
13 changes: 0 additions & 13 deletions app/models/spree/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,9 @@ class User < ActiveRecord::Base
roles_table_name = Role.table_name

scope :admin, lambda { includes(:spree_roles).where("#{roles_table_name}.name" => "admin") }
scope :registered, -> { where("#{users_table_name}.email NOT LIKE ?", "%@example.net") }

class DestroyWithOrdersError < StandardError; end

# Creates an anonymous user. An anonymous user is basically an auto-generated +User+ account that is created for the customer
# behind the scenes and its completely transparently to the customer. All +Orders+ must have a +User+ so this is necessary
# when adding to the "cart" (which is really an order) and before the customer has a chance to provide an email or to register.
def self.anonymous!
token = User.generate_token(:persistence_token)
User.create(:email => "#{token}@example.net", :password => token, :password_confirmation => token, :persistence_token => token)
end

def self.admin_created?
User.admin.count > 0
end
Expand All @@ -37,10 +28,6 @@ def admin?
has_spree_role?('admin')
end

def anonymous?
email =~ /@example.net$/ ? true : false
end

def send_reset_password_instructions
generate_reset_password_token!
UserMailer.reset_password_instructions(self.id).deliver
Expand Down
24 changes: 0 additions & 24 deletions spec/models/user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,6 @@
user.reset_password_token.should_not be_nil
end

context '#create' do
let(:user) { build(:user) }

it 'should not be anonymous' do
user.should_not be_anonymous
end
end

context '#destroy' do
it 'can not delete if it has completed orders' do
order = build(:order, :completed_at => Time.now)
Expand All @@ -33,20 +25,4 @@
end
end

context 'anonymous!' do
let(:user) { Spree::User.anonymous! }

it 'should create a new user' do
user.new_record?.should be_false
end

it 'should create a user with an example.net email' do
user.email.should =~ /@example.net$/
end

it 'should be anonymous' do
user.should be_anonymous
end
end

end

0 comments on commit 8156808

Please sign in to comment.