Permalink
Browse files

Clean up whitespace.

  • Loading branch information...
tristandunn committed Jun 7, 2010
1 parent f7ee81a commit 3e577f3cd5ff2408ce5a7f9a468313ced65b57fd
View
@@ -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
@@ -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 |
@@ -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
@@ -6,7 +6,7 @@ class Factory
# * Defining an attribute twice in the same factory
class AttributeDefinitionError < RuntimeError
end
-
+
class Attribute #:nodoc:
attr_reader :name
@@ -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
@@ -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:
@@ -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|
@@ -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
@@ -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.
@@ -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
@@ -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.
@@ -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.
#
@@ -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
@@ -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}"
@@ -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)
#
@@ -1,4 +1,4 @@
-class Factory
+class Factory
class Proxy
class Stub < Proxy #:nodoc:
@@next_id = 1000
@@ -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)
@@ -51,4 +51,3 @@ def convert_human_hash_to_attribute_hash(human_hash, associations = [])
end
end
end
-
@@ -39,4 +39,3 @@ def blueprint(&block)
end
ActiveRecord::Base.send(:include, Factory::Syntax::Blueprint::ActiveRecord)
-
@@ -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'
@@ -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
View
@@ -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

0 comments on commit 3e577f3

Please sign in to comment.