1
0
Fork 0
mirror of https://github.com/thoughtbot/factory_bot.git synced 2022-11-09 11:43:51 -05:00

Run automatic cop fixes

This runs all of the automatic cops that came in since rubocop 0.68.
None of these changes were manual.
This commit is contained in:
Nate Holland 2019-05-12 21:39:55 -05:00 committed by Daniel Colson
parent 41468b09f3
commit 0e7c6e60f1
No known key found for this signature in database
GPG key ID: 88A364BBE77B1353
11 changed files with 29 additions and 27 deletions

View file

@ -16,6 +16,7 @@ module FactoryBot
else instance_exec(&block) else instance_exec(&block)
end end
raise SequenceAbuseError if FactoryBot::Sequence === value raise SequenceAbuseError if FactoryBot::Sequence === value
value value
} }
end end

View file

@ -24,7 +24,7 @@ module FactoryBot
end end
delegate :to_create, :skip_create, :constructor, :before, :after, delegate :to_create, :skip_create, :constructor, :before, :after,
:callback, :callbacks, to: :@definition :callback, :callbacks, to: :@definition
def initialize_with(&block) def initialize_with(&block)
@definition.define_constructor(&block) @definition.define_constructor(&block)

View file

@ -72,8 +72,8 @@ module FactoryBot
result = [] result = []
begin begin
FactoryBot.public_send(factory_strategy, factory.name) FactoryBot.public_send(factory_strategy, factory.name)
rescue StandardError => error rescue StandardError => e
result |= [FactoryError.new(error, factory)] result |= [FactoryError.new(e, factory)]
end end
result result
end end
@ -83,9 +83,9 @@ module FactoryBot
factory.definition.defined_traits.map(&:name).each do |trait_name| factory.definition.defined_traits.map(&:name).each do |trait_name|
begin begin
FactoryBot.public_send(factory_strategy, factory.name, trait_name) FactoryBot.public_send(factory_strategy, factory.name, trait_name)
rescue StandardError => error rescue StandardError => e
result |= result |=
[FactoryTraitError.new(error, factory, trait_name)] [FactoryTraitError.new(e, factory, trait_name)]
end end
end end
result result

View file

@ -8,7 +8,7 @@ module FactoryBot
end end
delegate :defined_traits, :callbacks, :attributes, :constructor, delegate :defined_traits, :callbacks, :attributes, :constructor,
:to_create, to: :definition :to_create, to: :definition
def compile; end def compile; end

View file

@ -21,8 +21,8 @@ module FactoryBot
def find(name) def find(name)
@items.fetch(name) @items.fetch(name)
rescue KeyError => key_error rescue KeyError => e
raise key_error_with_custom_message(key_error) raise key_error_with_custom_message(e)
end end
alias :[] :find alias :[] :find

View file

@ -5,8 +5,8 @@ describe "a generated attributes hash" do
define_model("User") define_model("User")
define_model("Comment") define_model("Comment")
define_model("Post", title: :string, define_model("Post", title: :string,
body: :string, body: :string,
summary: :string, summary: :string,
user_id: :integer) do user_id: :integer) do
belongs_to :user belongs_to :user

View file

@ -2,10 +2,10 @@ describe "a generated attributes hash where order matters" do
include FactoryBot::Syntax::Methods include FactoryBot::Syntax::Methods
before do before do
define_model("ParentModel", static: :integer, define_model("ParentModel", static: :integer,
evaluates_first: :integer, evaluates_first: :integer,
evaluates_second: :integer, evaluates_second: :integer,
evaluates_third: :integer) evaluates_third: :integer)
FactoryBot.define do FactoryBot.define do
factory :parent_model do factory :parent_model do

View file

@ -4,9 +4,9 @@ describe "a generated stub instance" do
before do before do
define_model("User") define_model("User")
define_model("Post", title: :string, define_model("Post", title: :string,
body: :string, body: :string,
age: :integer, age: :integer,
user_id: :integer, user_id: :integer,
draft: :boolean) do draft: :boolean) do
belongs_to :user belongs_to :user

View file

@ -1,13 +1,14 @@
describe "attribute overrides" do describe "attribute overrides" do
before do before do
define_model("User", admin: :boolean) define_model("User", admin: :boolean)
define_model("Post", title: :string, define_model("Post", title: :string,
secure: :boolean, secure: :boolean,
user_id: :integer) do user_id: :integer) do
belongs_to :user belongs_to :user
def secure=(value) def secure=(value)
return unless user&.admin? return unless user&.admin?
write_attribute(:secure, value) write_attribute(:secure, value)
end end
end end

View file

@ -1,12 +1,12 @@
describe "an instance generated by a factory with multiple traits" do describe "an instance generated by a factory with multiple traits" do
before do before do
define_model("User", define_model("User",
name: :string, name: :string,
admin: :boolean, admin: :boolean,
gender: :string, gender: :string,
email: :string, email: :string,
date_of_birth: :date, date_of_birth: :date,
great: :string) great: :string)
FactoryBot.define do FactoryBot.define do
factory :user_without_admin_scoping, class: User do factory :user_without_admin_scoping, class: User do

View file

@ -25,9 +25,9 @@ module DefineConstantMacros
connection.create_table(table_name, &block) connection.create_table(table_name, &block)
created_tables << table_name created_tables << table_name
connection connection
rescue Exception => exception # rubocop:disable Lint/RescueException rescue Exception => e # rubocop:disable Lint/RescueException
connection.execute("DROP TABLE IF EXISTS #{table_name}") connection.execute("DROP TABLE IF EXISTS #{table_name}")
raise exception raise e
end end
end end
@ -56,7 +56,7 @@ RSpec.configure do |config|
config.before(:all) do config.before(:all) do
ActiveRecord::Base.establish_connection( ActiveRecord::Base.establish_connection(
adapter: "sqlite3", adapter: "sqlite3",
database: ":memory:", database: ":memory:",
) )
end end