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

Style cleanup

This commit is contained in:
Joshua Clayton 2012-05-05 01:14:21 -04:00
parent 092cde4953
commit 7234f9f07e
17 changed files with 56 additions and 62 deletions

View file

@ -1,16 +1,16 @@
require "set"
require "active_support/core_ext/module/delegation"
require "active_support/notifications"
require 'set'
require 'active_support/core_ext/module/delegation'
require 'active_support/notifications'
require 'factory_girl/errors'
require 'factory_girl/factory_runner'
require 'factory_girl/strategy_syntax_method_registrar'
require 'factory_girl/strategy_calculator'
require "factory_girl/strategy/build"
require "factory_girl/strategy/create"
require "factory_girl/strategy/attributes_for"
require "factory_girl/strategy/stub"
require "factory_girl/strategy/null"
require 'factory_girl/strategy/build'
require 'factory_girl/strategy/create'
require 'factory_girl/strategy/attributes_for'
require 'factory_girl/strategy/stub'
require 'factory_girl/strategy/null'
require 'factory_girl/disallows_duplicates_registry'
require 'factory_girl/registry'
require 'factory_girl/null_factory'
@ -39,7 +39,7 @@ require 'factory_girl/version'
module FactoryGirl
def self.factories
@factories ||= DisallowsDuplicatesRegistry.new(Registry.new("Factory"))
@factories ||= DisallowsDuplicatesRegistry.new(Registry.new('Factory'))
end
def self.register_factory(factory)
@ -54,7 +54,7 @@ module FactoryGirl
end
def self.sequences
@sequences ||= DisallowsDuplicatesRegistry.new(Registry.new("Sequence"))
@sequences ||= DisallowsDuplicatesRegistry.new(Registry.new('Sequence'))
end
def self.register_sequence(sequence)
@ -69,7 +69,7 @@ module FactoryGirl
end
def self.traits
@traits ||= DisallowsDuplicatesRegistry.new(Registry.new("Trait"))
@traits ||= DisallowsDuplicatesRegistry.new(Registry.new('Trait'))
end
def self.register_trait(trait)
@ -84,7 +84,7 @@ module FactoryGirl
end
def self.strategies
@strategies ||= Registry.new("Strategy")
@strategies ||= Registry.new('Strategy')
end
def self.register_strategy(strategy_name, strategy_class)

View file

@ -1,7 +1,7 @@
require "factory_girl/attribute/static"
require "factory_girl/attribute/dynamic"
require "factory_girl/attribute/association"
require "factory_girl/attribute/sequence"
require 'factory_girl/attribute/static'
require 'factory_girl/attribute/dynamic'
require 'factory_girl/attribute/association'
require 'factory_girl/attribute/sequence'
module FactoryGirl
class Attribute #:nodoc:

View file

@ -1,6 +1,5 @@
module FactoryGirl
class Attribute
class Sequence < Attribute
def initialize(name, sequence, ignored)
super(name, ignored)
@ -12,6 +11,5 @@ module FactoryGirl
-> { FactoryGirl.generate(sequence) }
end
end
end
end

View file

@ -1,7 +1,7 @@
require "factory_girl/declaration/static"
require "factory_girl/declaration/dynamic"
require "factory_girl/declaration/association"
require "factory_girl/declaration/implicit"
require 'factory_girl/declaration/static'
require 'factory_girl/declaration/dynamic'
require 'factory_girl/declaration/association'
require 'factory_girl/declaration/implicit'
module FactoryGirl
class Declaration

View file

@ -33,7 +33,7 @@ module FactoryGirl
# * value: +Object+
# If no block is given, this value will be used for this attribute.
def add_attribute(name, value = nil, &block)
raise AttributeDefinitionError, "Both value and block given" if value && block_given?
raise AttributeDefinitionError, 'Both value and block given' if value && block_given?
declaration = if block_given?
Declaration::Dynamic.new(name, @ignore, block)
@ -86,7 +86,7 @@ module FactoryGirl
elsif args.first.respond_to?(:has_key?) && args.first.has_key?(:factory)
association(name, *args)
elsif FactoryGirl.callback_names.include?(name)
callback_when, callback_name = name.to_s.split("_", 2)
callback_when, callback_name = name.to_s.split('_', 2)
ActiveSupport::Deprecation.warn "Calling #{name} is deprecated; use the syntax #{callback_when}(:#{callback_name}) {}", caller
@definition.add_callback(Callback.new(name, block))
else

View file

@ -1,4 +1,4 @@
require "observer"
require 'observer'
module FactoryGirl
class Evaluation
@ -9,12 +9,12 @@ module FactoryGirl
@to_create = to_create
end
delegate :object, :hash, to: :@attribute_assigner
def create(result_instance)
@to_create[result_instance]
end
delegate :object, :hash, to: :@attribute_assigner
def notify(name, result_instance)
changed
notify_observers(name, result_instance)

View file

@ -1,5 +1,5 @@
require "active_support/core_ext/hash/keys"
require "active_support/inflector"
require 'active_support/core_ext/hash/keys'
require 'active_support/inflector'
module FactoryGirl
class Factory

View file

@ -19,7 +19,7 @@ module FactoryGirl
instrumentation_payload = { name: @name, strategy: runner_strategy }
ActiveSupport::Notifications.instrument("factory_girl.run_factory", instrumentation_payload) do
ActiveSupport::Notifications.instrument('factory_girl.run_factory', instrumentation_payload) do
factory.run(runner_strategy, @overrides, &block)
end
end

View file

@ -11,7 +11,7 @@ module FactoryGirl
options = args.extract_options!
@value = args.first || 1
@aliases = options[:aliases] || []
@aliases = options.fetch(:aliases) { [] }
end
def next

View file

@ -36,23 +36,23 @@ module FactoryGirl
end
def save(*args)
raise "stubbed models are not allowed to access the database"
raise 'stubbed models are not allowed to access the database'
end
def destroy(*args)
raise "stubbed models are not allowed to access the database"
raise 'stubbed models are not allowed to access the database'
end
def connection
raise "stubbed models are not allowed to access the database"
raise 'stubbed models are not allowed to access the database'
end
def reload
raise "stubbed models are not allowed to access the database"
raise 'stubbed models are not allowed to access the database'
end
def update_attribute(*args)
raise "stubbed models are not allowed to access the database"
raise 'stubbed models are not allowed to access the database'
end
end
end

View file

@ -1,7 +1,8 @@
require "active_support/deprecation"
require "factory_girl/syntax/methods"
require "factory_girl/syntax/default"
require "factory_girl/syntax/vintage"
require 'active_support/deprecation'
require 'factory_girl/syntax/methods'
require 'factory_girl/syntax/default'
require 'factory_girl/syntax/vintage'
module FactoryGirl
# Provides alternate syntaxes for factory_girl. If you don't like the default

View file

@ -18,23 +18,19 @@ module FactoryGirl
# This syntax was derived from Pete Yandell's machinist.
module Blueprint
module ActiveRecord #:nodoc:
def self.included(base) # :nodoc:
base.extend ClassMethods
end
module ClassMethods #:nodoc:
def blueprint(&block)
ActiveSupport::Deprecation.warn "Model.blueprint is deprecated; use the FactoryGirl.define syntax instead", caller
ActiveSupport::Deprecation.warn 'Model.blueprint is deprecated; use the FactoryGirl.define syntax instead', caller
instance = Factory.new(name.underscore, class: self)
proxy = FactoryGirl::DefinitionProxy.new(instance)
proxy.instance_eval(&block)
FactoryGirl.register_factory(instance)
end
end
end
end
end

View file

@ -34,14 +34,13 @@ module FactoryGirl
# object_daddy.
module Generate
module ActiveRecord #:nodoc:
def self.included(base) # :nodoc:
base.extend ClassMethods
end
module ClassMethods #:nodoc:
def generate(overrides = {}, &block)
ActiveSupport::Deprecation.warn "Model.generate is deprecated; use the FactoryGirl.define syntax instead", caller
ActiveSupport::Deprecation.warn 'Model.generate is deprecated; use the FactoryGirl.define syntax instead', caller
instance = FactoryRunner.new(name.underscore, :build, [overrides]).run
instance.save
yield(instance) if block_given?
@ -49,14 +48,14 @@ module FactoryGirl
end
def generate!(overrides = {}, &block)
ActiveSupport::Deprecation.warn "Model.generate! is deprecated; use the FactoryGirl.define syntax instead", caller
ActiveSupport::Deprecation.warn 'Model.generate! is deprecated; use the FactoryGirl.define syntax instead', caller
instance = FactoryRunner.new(name.underscore, :create, [overrides]).run
yield(instance) if block_given?
instance
end
def spawn(overrides = {}, &block)
ActiveSupport::Deprecation.warn "Model.spawn is deprecated; use the FactoryGirl.define syntax instead", caller
ActiveSupport::Deprecation.warn 'Model.spawn is deprecated; use the FactoryGirl.define syntax instead', caller
instance = FactoryRunner.new(name.underscore, :build, [overrides]).run
yield(instance) if block_given?
instance

View file

@ -26,12 +26,12 @@ module FactoryGirl
module ClassMethods #:nodoc:
def make(overrides = {})
ActiveSupport::Deprecation.warn "Model.make is deprecated; use the FactoryGirl.define syntax instead", caller
ActiveSupport::Deprecation.warn 'Model.make is deprecated; use the FactoryGirl.define syntax instead', caller
FactoryRunner.new(name.underscore, :build, [overrides]).run
end
def make!(overrides = {})
ActiveSupport::Deprecation.warn "Model.make! is deprecated; use the FactoryGirl.define syntax instead", caller
ActiveSupport::Deprecation.warn 'Model.make! is deprecated; use the FactoryGirl.define syntax instead', caller
FactoryRunner.new(name.underscore, :create, [overrides]).run
end
end

View file

@ -26,7 +26,7 @@ module FactoryGirl
module Sham #:nodoc:
def self.method_missing(name, *args, &block)
if block_given?
ActiveSupport::Deprecation.warn "Sham.sequence is deprecated; use the FactoryGirl.define syntax instead", caller
ActiveSupport::Deprecation.warn 'Sham.sequence is deprecated; use the FactoryGirl.define syntax instead', caller
start_value = args.first
FactoryGirl.register_sequence(Sequence.new(name, start_value || 1, &block))
else

View file

@ -21,7 +21,7 @@ module FactoryGirl
# Yields: +Factory+
# The newly created factory.
def self.define(name, options = {})
ActiveSupport::Deprecation.warn "Factory.define is deprecated; use the FactoryGirl.define block syntax to declare your factory.", caller
ActiveSupport::Deprecation.warn 'Factory.define is deprecated; use the FactoryGirl.define block syntax to declare your factory.', caller
factory = FactoryGirl::Factory.new(name, options)
proxy = FactoryGirl::DefinitionProxy.new(factory)
yield(proxy)
@ -44,7 +44,7 @@ module FactoryGirl
#
# Factory.sequence(:email) {|n| "somebody_#{n}@example.com" }
def self.sequence(name, start_value = 1, &block)
ActiveSupport::Deprecation.warn "Factory.sequence is deprecated; use the FactoryGirl.define block syntax to declare your sequence.", caller
ActiveSupport::Deprecation.warn 'Factory.sequence is deprecated; use the FactoryGirl.define block syntax to declare your sequence.', caller
FactoryGirl.register_sequence(Sequence.new(name, start_value, &block))
end
@ -57,7 +57,7 @@ module FactoryGirl
# Returns:
# The next value in the sequence. (Object)
def self.next(name)
ActiveSupport::Deprecation.warn "Factory.next is deprecated; use FactoryGirl.generate instead.", caller
ActiveSupport::Deprecation.warn 'Factory.next is deprecated; use FactoryGirl.generate instead.', caller
FactoryGirl.generate(name)
end
@ -86,31 +86,31 @@ module FactoryGirl
# # will be used instead.
# Factory(:post, user_id: 1)
def self.alias(pattern, replace)
ActiveSupport::Deprecation.warn "Factory.alias is deprecated; use FactoryGirl.aliases << [pattern, replace] instead.", caller
ActiveSupport::Deprecation.warn 'Factory.alias is deprecated; use FactoryGirl.aliases << [pattern, replace] instead.', caller
FactoryGirl.aliases << [pattern, replace]
end
# Alias for FactoryGirl.attributes_for
def self.attributes_for(name, overrides = {})
ActiveSupport::Deprecation.warn "Factory.attributes_for is deprecated; use FactoryGirl.attributes_for instead.", caller
ActiveSupport::Deprecation.warn 'Factory.attributes_for is deprecated; use FactoryGirl.attributes_for instead.', caller
FactoryGirl.attributes_for(name, overrides)
end
# Alias for FactoryGirl.build
def self.build(name, overrides = {})
ActiveSupport::Deprecation.warn "Factory.build is deprecated; use FactoryGirl.build instead.", caller
ActiveSupport::Deprecation.warn 'Factory.build is deprecated; use FactoryGirl.build instead.', caller
FactoryGirl.build(name, overrides)
end
# Alias for FactoryGirl.create
def self.create(name, overrides = {})
ActiveSupport::Deprecation.warn "Factory.create is deprecated; use FactoryGirl.create instead.", caller
ActiveSupport::Deprecation.warn 'Factory.create is deprecated; use FactoryGirl.create instead.', caller
FactoryGirl.create(name, overrides)
end
# Alias for FactoryGirl.build_stubbed.
def self.stub(name, overrides = {})
ActiveSupport::Deprecation.warn "Factory.stub is deprecated; use FactoryGirl.build_stubbed instead.", caller
ActiveSupport::Deprecation.warn 'Factory.stub is deprecated; use FactoryGirl.build_stubbed instead.', caller
FactoryGirl.build_stubbed(name, overrides)
end
end
@ -120,7 +120,7 @@ module FactoryGirl
# Example:
# Factory(:user, name: 'Joe')
def Factory(name, attrs = {})
ActiveSupport::Deprecation.warn "Factory(:name) is deprecated; use FactoryGirl.create(:name) instead.", caller
ActiveSupport::Deprecation.warn 'Factory(:name) is deprecated; use FactoryGirl.create(:name) instead.', caller
FactoryGirl.create(name, attrs)
end
end

View file

@ -1,3 +1,3 @@
module FactoryGirl
VERSION = "3.2.0"
VERSION = '3.2.0'
end