Skip to content

Commit

Permalink
Clean up whitespace.
Browse files Browse the repository at this point in the history
  • Loading branch information
tristandunn committed Jun 7, 2010
1 parent f7ee81a commit 3e577f3
Show file tree
Hide file tree
Showing 13 changed files with 33 additions and 35 deletions.
2 changes: 1 addition & 1 deletion README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ Factory_girl makes available three callbacks for injecting some code:

Examples:

# Define a factory that calls the generate_hashed_password method after it is built
# Define a factory that calls the generate_hashed_password method after it is built
Factory.define :user do |u|
u.after_build { |user| do_something_to(user) }
end
Expand Down
2 changes: 1 addition & 1 deletion features/factory_girl_steps.feature
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ Feature: Use step definitions generated by factories
| name | admin |
| John | true |

Scenario: create a several instances of a factory with an underscore in its name
Scenario: create a several instances of a factory with an underscore in its name
Given 3 admin users exist
Then I should find the following for the last user:
| admin |
Expand Down
2 changes: 1 addition & 1 deletion lib/factory_girl/aliases.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class << self
# be substituded like with +String#sub+.
#
# Example:
#
#
# Factory.alias /(.*)_confirmation/, '\1'
#
# factory_girl starts with aliases for foreign keys, so that a :user
Expand Down
4 changes: 2 additions & 2 deletions lib/factory_girl/attribute.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class Factory
# * Defining an attribute twice in the same factory
class AttributeDefinitionError < RuntimeError
end

class Attribute #:nodoc:

attr_reader :name
Expand All @@ -16,7 +16,7 @@ def initialize(name)

if @name.to_s =~ /=$/
attribute_name = $`
raise AttributeDefinitionError,
raise AttributeDefinitionError,
"factory_girl uses 'f.#{attribute_name} value' syntax " +
"rather than 'f.#{attribute_name} = value'"
end
Expand Down
40 changes: 20 additions & 20 deletions lib/factory_girl/factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ class Factory
# Raised when a factory is defined that attempts to instantiate itself.
class AssociationDefinitionError < RuntimeError
end

# Raised when a callback is defined that has an invalid name
class InvalidCallbackNameError < RuntimeError
end

# Raised when a factory is defined with the same name as a previously-defined factory.
class DuplicateDefinitionError < RuntimeError
end

class << self
attr_accessor :factories #:nodoc:

Expand Down Expand Up @@ -56,32 +56,32 @@ def self.define (name, options = {})
yield(instance)
if parent = options.delete(:parent)
instance.inherit_from(Factory.factory_by_name(parent))
end
if self.factories[instance.factory_name]
end
if self.factories[instance.factory_name]
raise DuplicateDefinitionError, "Factory already defined: #{name}"
end
self.factories[instance.factory_name] = instance
end

def class_name #:nodoc:
@options[:class] || factory_name
end

def build_class #:nodoc:
@build_class ||= class_for(class_name)
end

def default_strategy #:nodoc:
@options[:default_strategy] || :create
end

def initialize (name, options = {}) #:nodoc:
assert_valid_options(options)
@factory_name = factory_name_for(name)
@options = options
@options = options
@attributes = []
end

def inherit_from(parent) #:nodoc:
@options[:class] ||= parent.class_name
parent.attributes.each do |attribute|
Expand Down Expand Up @@ -140,7 +140,7 @@ def add_attribute (name, value = nil, &block)
# f.add_attribute :name, 'Billy Idol'
# end
#
# are equivilent.
# are equivilent.
def method_missing (name, *args, &block)
add_attribute(name, *args, &block)
end
Expand Down Expand Up @@ -196,26 +196,26 @@ def sequence (name, &block)
s = Sequence.new(&block)
add_attribute(name) { s.next }
end

def after_build(&block)
callback(:after_build, &block)
end

def after_create(&block)
callback(:after_create, &block)
end

def after_stub(&block)
callback(:after_stub, &block)
end

def callback(name, &block)
unless [:after_build, :after_create, :after_stub].include?(name.to_sym)
raise InvalidCallbackNameError, "#{name} is not a valid callback name. Valid callback names are :after_build, :after_create, and :after_stub"
end
@attributes << Attribute::Callback.new(name.to_sym, block)
end

# Generates and returns a Hash of attributes from this factory. Attributes
# can be individually overridden by passing in a Hash of attribute => value
# pairs.
Expand All @@ -228,7 +228,7 @@ def callback(name, &block)
#
# Returns: +Hash+
# A set of attributes that can be used to build an instance of the class
# this factory generates.
# this factory generates.
def self.attributes_for (name, overrides = {})
factory_by_name(name).run(Proxy::AttributesFor, overrides)
end
Expand Down Expand Up @@ -268,7 +268,7 @@ def self.build (name, overrides = {})
def self.create (name, overrides = {})
factory_by_name(name).run(Proxy::Create, overrides)
end

# Generates and returns an object with all attributes from this factory
# stubbed out. Attributes can be individually overridden by passing in a Hash
# of attribute => value pairs.
Expand All @@ -284,7 +284,7 @@ def self.create (name, overrides = {})
def self.stub (name, overrides = {})
factory_by_name(name).run(Proxy::Stub, overrides)
end

# Executes the default strategy for the given factory. This is usually create,
# but it can be overridden for each factory.
#
Expand All @@ -296,7 +296,7 @@ def self.stub (name, overrides = {})
#
# Returns: +Object+
# The result of the default strategy.
def self.default_strategy (name, overrides = {})
def self.default_strategy (name, overrides = {})
self.send(factory_by_name(name).default_strategy, name, overrides)
end

Expand Down Expand Up @@ -367,13 +367,13 @@ def attribute_defined? (name)
end

def assert_valid_options(options)
invalid_keys = options.keys - [:class, :parent, :default_strategy]
invalid_keys = options.keys - [:class, :parent, :default_strategy]
unless invalid_keys == []
raise ArgumentError, "Unknown arguments: #{invalid_keys.inspect}"
end
assert_valid_strategy(options[:default_strategy]) if options[:default_strategy]
end

def assert_valid_strategy(strategy)
unless Factory::Proxy.const_defined? variable_name_to_class_name(strategy)
raise ArgumentError, "Unknown strategy: #{strategy}"
Expand Down
2 changes: 1 addition & 1 deletion lib/factory_girl/proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def run_callbacks(name)
# # Builds (but doesn't save) a Post and a User
# Factory.build(:post)
#
# # Builds and saves a User, builds a Post, assigns the User to the
# # Builds and saves a User, builds a Post, assigns the User to the
# # author association, and saves the User.
# Factory.create(:post)
#
Expand Down
2 changes: 1 addition & 1 deletion lib/factory_girl/proxy/stub.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class Factory
class Factory
class Proxy
class Stub < Proxy #:nodoc:
@@next_id = 1000
Expand Down
2 changes: 1 addition & 1 deletion lib/factory_girl/sequence.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class << self
# sequence.
#
# Example:
#
#
# Factory.sequence(:email) {|n| "somebody_#{n}@example.com" }
def self.sequence (name, &block)
self.sequences[name] = Sequence.new(&block)
Expand Down
1 change: 0 additions & 1 deletion lib/factory_girl/step_definitions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,3 @@ def convert_human_hash_to_attribute_hash(human_hash, associations = [])
end
end
end

1 change: 0 additions & 1 deletion lib/factory_girl/syntax/blueprint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,3 @@ def blueprint(&block)
end

ActiveRecord::Base.send(:include, Factory::Syntax::Blueprint::ActiveRecord)

2 changes: 1 addition & 1 deletion lib/factory_girl/syntax/make.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module Syntax
# Usage:
#
# require 'factory_girl/syntax/make'
#
#
# Factory.define :user do |factory|
# factory.name 'Billy Bob'
# factory.email 'billy@bob.example.com'
Expand Down
2 changes: 1 addition & 1 deletion spec/factory_girl/factory_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
end

it "should not allow a duplicate factory definition" do
lambda {
lambda {
2.times { Factory.define(@name) {|f| } }
}.should raise_error(Factory::DuplicateDefinitionError)
end
Expand Down
6 changes: 3 additions & 3 deletions spec/models.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ def self.up
end

create_table :posts, :force => true do |t|
t.string :name
t.string :name
t.integer :author_id
end

create_table :business, :force => true do |t|
t.string :name
t.string :name
t.integer :owner_id
end
end
Expand Down

0 comments on commit 3e577f3

Please sign in to comment.