diff --git a/app/controllers/spree/admin/users_controller.rb b/app/controllers/spree/admin/users_controller.rb index 8ebd40cbfc..a1db20605c 100644 --- a/app/controllers/spree/admin/users_controller.rb +++ b/app/controllers/spree/admin/users_controller.rb @@ -76,7 +76,6 @@ module Spree return @collection if @collection.present? if request.xhr? && params[:q].present? - # Disabling proper nested include here due to rails 3.1 bug @collection = Spree::User. includes(:bill_address, :ship_address). where("spree_users.email #{LIKE} :search @@ -91,7 +90,7 @@ module Spree 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]). diff --git a/app/models/spree/user.rb b/app/models/spree/user.rb index c5bc3e9010..814ba38a6c 100644 --- a/app/models/spree/user.rb +++ b/app/models/spree/user.rb @@ -14,7 +14,6 @@ module Spree 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") } has_many :enterprise_roles, dependent: :destroy has_many :enterprises, through: :enterprise_roles @@ -43,16 +42,6 @@ module Spree 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 it's transparent to the customer. - # All +Orders+ must have a +User+ so this is necessary when adding to the "cart" (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 @@ -61,10 +50,6 @@ module Spree 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(id).deliver @@ -162,14 +147,6 @@ module Spree SecureRandom.base64(15).tr('+/=', '-_ ').strip.delete("\n") end - # Generate a token by looping and ensuring does not already exist. - def self.generate_token(column) - loop do - token = friendly_token - break token unless find(:first, conditions: { column => token }) - end - end - def limit_owned_enterprises return unless owned_enterprises.size > enterprise_limit diff --git a/spec/features/consumer/producers_spec.rb b/spec/features/consumer/producers_spec.rb index f8d7e3bb57..11d2e52cf6 100644 --- a/spec/features/consumer/producers_spec.rb +++ b/spec/features/consumer/producers_spec.rb @@ -22,10 +22,6 @@ feature ' let(:shop) { create(:distributor_enterprise) } let!(:er) { create(:enterprise_relationship, parent: shop, child: producer1) } - before :each do - use_api_as_unauthenticated_user - end - before do product1.set_property 'Organic', 'NASAA 12345' product2.set_property 'Biodynamic', 'ABC123' diff --git a/spec/features/consumer/shopping/orders_spec.rb b/spec/features/consumer/shopping/orders_spec.rb index e9b342c1c7..2bb40d6dd5 100644 --- a/spec/features/consumer/shopping/orders_spec.rb +++ b/spec/features/consumer/shopping/orders_spec.rb @@ -31,7 +31,14 @@ feature "Order Management", js: true do end context "when checking out as an anonymous guest" do - let(:user) { Spree::User.anonymous! } + let!(:customer) { nil } + let!(:order) do + create(:order_with_credit_payment, + user: nil, + email: "guest@user.com", + distributor: distributor, + order_cycle: order_cycle) + end it "allows the user to see the details" do # Cannot load the page without token diff --git a/spec/features/consumer/shops_spec.rb b/spec/features/consumer/shops_spec.rb index 87db26883c..891ba07e8b 100644 --- a/spec/features/consumer/shops_spec.rb +++ b/spec/features/consumer/shops_spec.rb @@ -14,10 +14,6 @@ feature 'Shops', js: true do let!(:producer) { create(:supplier_enterprise) } let!(:er) { create(:enterprise_relationship, parent: distributor, child: producer) } - before :each do - use_api_as_unauthenticated_user - end - before do producer.set_producer_property 'Organic', 'NASAA 12345' end diff --git a/spec/models/spree/user_spec.rb b/spec/models/spree/user_spec.rb index d73042c67a..f9fcd95056 100644 --- a/spec/models/spree/user_spec.rb +++ b/spec/models/spree/user_spec.rb @@ -188,14 +188,6 @@ describe Spree.user_class do expect(create(:user).admin?).to be_falsey end - context '#create' do - let(:user) { build(:user) } - - it 'should not be anonymous' do - expect(user).not_to be_anonymous - end - end - context '#destroy' do it 'can not delete if it has completed orders' do order = build(:order, completed_at: Time.zone.now) @@ -205,20 +197,4 @@ describe Spree.user_class do expect { user.destroy }.to raise_exception(Spree::User::DestroyWithOrdersError) end end - - context 'anonymous!' do - let(:user) { Spree::User.anonymous! } - - it 'should create a new user' do - expect(user.new_record?).to be_falsey - end - - it 'should create a user with an example.net email' do - expect(user.email).to match(/@example.net$/) - end - - it 'should be anonymous' do - expect(user).to be_anonymous - end - end end diff --git a/spec/support/request/authentication_workflow.rb b/spec/support/request/authentication_workflow.rb index 842a215508..0eb32e3e7a 100644 --- a/spec/support/request/authentication_workflow.rb +++ b/spec/support/request/authentication_workflow.rb @@ -68,12 +68,6 @@ module AuthenticationWorkflow fill_in "password", with: user.password click_button "Login" end - - def use_api_as_unauthenticated_user - allow_any_instance_of(Api::BaseController).to receive(:spree_current_user) { - Spree::User.anonymous! - } - end end RSpec.configure do |config|