Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Move attribute_names_for_model so steps are grouped together
  • Loading branch information
joshuaclayton committed Mar 30, 2012
1 parent 81c9f2c commit 4e2a672
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions lib/factory_girl/step_definitions.rb
Expand Up @@ -97,6 +97,16 @@ def initialize(human_hash_to_attributes_hash, key, value)
FactoryGirl.factories.each do |factory|
factory.compile
factory.human_names.each do |human_name|
attribute_names_for_model = if factory.build_class.respond_to?(:attribute_names)
factory.build_class.attribute_names
elsif factory.build_class.respond_to?(:columns)
factory.build_class.columns.map do |column|
column.respond_to?(:name) ? column.name : column.to_s
end
else
[]
end

Given /^the following (?:#{human_name}|#{human_name.pluralize}) exists?:?$/i do |table|
table.hashes.each do |human_hash|
attributes = convert_human_hash_to_attribute_hash(human_hash, factory.associations)
Expand All @@ -112,18 +122,9 @@ def initialize(human_hash_to_attributes_hash, key, value)
FactoryGirl.create_list(factory.name, count.to_i)
end

attribute_names = if factory.build_class.respond_to?(:attribute_names)
factory.build_class.attribute_names
elsif factory.build_class.respond_to?(:columns)
factory.build_class.columns.map do |column|
column.respond_to?(:name) ? column.name : column.to_s
end
else
[]
end

attribute_names.each do |attribute_name|
attribute_names_for_model.each do |attribute_name|
human_column_name = attribute_name.downcase.gsub('_', ' ')

Given /^an? #{human_name} exists with an? #{human_column_name} of "([^"]*)"$/i do |value|
FactoryGirl.create(factory.name, attribute_name => value)
end
Expand Down

0 comments on commit 4e2a672

Please sign in to comment.