Merge pull request #4941 from luisramos0/devise

[Spree 2.1] Delete unnecessary code related to spree_auth_devise
This commit is contained in:
Pau Pérez Fabregat
2020-03-12 12:48:59 +01:00
committed by GitHub
7 changed files with 9 additions and 64 deletions

View File

@@ -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]).

View File

@@ -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

View File

@@ -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'

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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|