Update deprecated #find_or_create_by_* methods

This commit is contained in:
Matt-Yorkley
2019-12-20 15:44:10 +01:00
committed by Luis Ramos
parent 6dd982532c
commit 30558485de
20 changed files with 26 additions and 26 deletions

View File

@@ -8,6 +8,6 @@ class DefaultShippingCategory
end
def self.find_or_create
Spree::ShippingCategory.find_or_create_by_name(NAME)
Spree::ShippingCategory.find_or_create_by(name: NAME)
end
end

View File

@@ -14,6 +14,6 @@ class DefaultStockLocation
end
def self.find_or_create
Spree::StockLocation.find_or_create_by_name(NAME)
Spree::StockLocation.find_or_create_by(name: NAME)
end
end

View File

@@ -59,7 +59,7 @@ def create_admin_user
admin.skip_confirmation!
admin.skip_confirmation_notification!
if admin.save
role = Spree::Role.find_or_create_by_name 'admin'
role = Spree::Role.find_or_create_by(name: 'admin')
admin.spree_roles << role
admin.save
say "Done!"

View File

@@ -14,7 +14,7 @@ module Addressing
end
def zone
zone = Spree::Zone.find_or_create_by_name!(ENV.fetch('CHECKOUT_ZONE'))
zone = Spree::Zone.find_or_create_by!(name: ENV.fetch('CHECKOUT_ZONE'))
zone.members.create!(zoneable: country) unless zone.zoneables.include?(country)
zone
end

View File

@@ -11,7 +11,7 @@ class EnterpriseFactory
name = data[:name]
log "- #{name}"
data[:long_description] = data[:long_description].strip_heredoc.tr("\n", " ")
Enterprise.create_with(data).find_or_create_by_name!(name)
Enterprise.create_with(data).find_or_create_by!(name: name)
end
end

View File

@@ -18,7 +18,7 @@ class InventoryFactory
enterprise: shop,
variant: product.variants.first,
visible: true
).find_or_create_by_variant_id!(product.variants.first.id)
).find_or_create_by!(variant_id: product.variants.first.id)
create_override(shop, product)
end
@@ -29,6 +29,6 @@ class InventoryFactory
price: 12,
on_demand: false,
count_on_hand: 5
).find_or_create_by_variant_id!(product.variants.first.id)
).find_or_create_by!(variant_id: product.variants.first.id)
end
end

View File

@@ -75,7 +75,7 @@ class ProductFactory
shipping_category: DefaultShippingCategory.find_or_create,
tax_category_id: find_or_create_tax_category.id
)
product = Spree::Product.create_with(params).find_or_create_by_name!(params[:name])
product = Spree::Product.create_with(params).find_or_create_by!(name: params[:name])
product.variants.first.update_attribute :on_demand, true
product
end

View File

@@ -49,7 +49,7 @@ class ShippingMethodFactory
params[:distributor_ids] = [enterprise.id]
method = enterprise.shipping_methods.new(params)
method.zones << zone
method.shipping_categories << Spree::ShippingCategory.find_or_create_by_name('Default')
method.shipping_categories << Spree::ShippingCategory.find_or_create_by(name: 'Default')
method.save!
method
end

View File

@@ -5,7 +5,7 @@ class TaxonFactory
def create_samples
log "Creating taxonomies:"
taxonomy = Spree::Taxonomy.find_or_create_by_name!('Products')
taxonomy = Spree::Taxonomy.find_or_create_by!(name: 'Products')
taxons = ['Vegetables', 'Fruit', 'Oils', 'Preserves and Sauces', 'Dairy', 'Meat and Fish']
taxons.each do |taxon_name|
create_taxon(taxonomy, taxon_name)

View File

@@ -34,7 +34,7 @@ class UserFactory
password_confirmation: password,
confirmation_sent_at: Time.zone.now,
confirmed_at: Time.zone.now
).find_or_create_by_email!(email)
).find_or_create_by!(email: email)
[name, user]
end
end

View File

@@ -291,7 +291,7 @@ module Admin
let(:user) { create_enterprise_user }
let(:admin_user) do
user = create(:user)
user.spree_roles << Spree::Role.find_or_create_by_name!('admin')
user.spree_roles << Spree::Role.find_or_create_by!(name: 'admin')
user
end
let(:order_cycle) { create(:simple_order_cycle) }

View File

@@ -13,13 +13,13 @@ describe Spree::Admin::UsersController do
end
it 'should grant access to users with an admin role' do
user.spree_roles << Spree::Role.find_or_create_by_name('admin')
user.spree_roles << Spree::Role.find_or_create_by(name: 'admin')
spree_post :index
expect(response).to render_template :index
end
it "allows admins to update a user's API key" do
user.spree_roles << Spree::Role.find_or_create_by_name('admin')
user.spree_roles << Spree::Role.find_or_create_by(name: 'admin')
expect(test_user).to receive(:generate_spree_api_key!).and_return(true)
puts user.id
puts test_user.id
@@ -28,21 +28,21 @@ describe Spree::Admin::UsersController do
end
it "allows admins to clear a user's API key" do
user.spree_roles << Spree::Role.find_or_create_by_name('admin')
user.spree_roles << Spree::Role.find_or_create_by(name: 'admin')
expect(test_user).to receive(:clear_spree_api_key!).and_return(true)
spree_put :clear_api_key, id: test_user.id
expect(response).to redirect_to(spree.edit_admin_user_path(test_user))
end
it 'should deny access to users with an bar role' do
user.spree_roles << Spree::Role.find_or_create_by_name('bar')
user.spree_roles << Spree::Role.find_or_create_by(name: 'bar')
Spree::Ability.register_ability(BarAbility)
spree_post :index
expect(response).to redirect_to('/unauthorized')
end
it 'should deny access to users with an bar role' do
user.spree_roles << Spree::Role.find_or_create_by_name('bar')
user.spree_roles << Spree::Role.find_or_create_by(name: 'bar')
Spree::Ability.register_ability(BarAbility)
spree_post :update, id: '9'
expect(response).to redirect_to('/unauthorized')

View File

@@ -31,6 +31,6 @@ end
FactoryBot.modify do
factory :shipment, class: Spree::Shipment do
# keeps test shipments unique per order
initialize_with { Spree::Shipment.find_or_create_by_order_id(order.id) }
initialize_with { Spree::Shipment.find_or_create_by(order_id: order.id) }
end
end

View File

@@ -23,7 +23,7 @@ FactoryBot.modify do
confirmed_at '1970-01-01 00:00:01'
after(:create) do |user|
user.spree_roles << Spree::Role.find_or_create_by_name!('admin')
user.spree_roles << Spree::Role.find_or_create_by!(name: 'admin')
end
end
end

View File

@@ -3,7 +3,7 @@ require 'spec_helper'
feature 'Multilingual', js: true do
include AuthenticationWorkflow
include WebHelper
let(:admin_role) { Spree::Role.find_or_create_by_name!('admin') }
let(:admin_role) { Spree::Role.find_or_create_by!(name: 'admin') }
let(:admin_user) { create(:user) }
background do

View File

@@ -5,7 +5,7 @@ module OpenFoodNetwork
context "as a site admin" do
let(:user) do
user = create(:user)
user.spree_roles << Spree::Role.find_or_create_by_name!("admin")
user.spree_roles << Spree::Role.find_or_create_by!(name: 'admin')
user
end
subject { CustomersReport.new user, {}, true }

View File

@@ -7,7 +7,7 @@ module OpenFoodNetwork
context "as a site admin" do
let(:user) do
user = create(:user)
user.spree_roles << Spree::Role.find_or_create_by_name!("admin")
user.spree_roles << Spree::Role.find_or_create_by!(name: "admin")
user
end
subject { OrderCycleManagementReport.new user, {}, true }

View File

@@ -5,7 +5,7 @@ module OpenFoodNetwork
context "As a site admin" do
let(:user) do
user = create(:user)
user.spree_roles << Spree::Role.find_or_create_by_name!("admin")
user.spree_roles << Spree::Role.find_or_create_by!(name: 'admin')
user
end
subject do

View File

@@ -3,7 +3,7 @@ module OpenFoodNetwork
def login_as_admin
@admin_user ||= begin
user = create(:user)
user.spree_roles << Spree::Role.find_or_create_by_name!('admin')
user.spree_roles << Spree::Role.find_or_create_by!(name: 'admin')
user
end

View File

@@ -6,7 +6,7 @@ module AuthenticationWorkflow
end
def quick_login_as_admin
admin_role = Spree::Role.find_or_create_by_name!('admin')
admin_role = Spree::Role.find_or_create_by!(name: 'admin')
admin_user = create(:user,
password: 'passw0rd',
password_confirmation: 'passw0rd',
@@ -42,7 +42,7 @@ module AuthenticationWorkflow
end
def login_to_consumer_section
user_role = Spree::Role.find_or_create_by_name!('user')
user_role = Spree::Role.find_or_create_by!(name: 'user')
user = create_enterprise_user(
email: 'someone@ofn.org',
password: 'passw0rd',