mirror of
https://github.com/thoughtbot/factory_bot.git
synced 2022-11-09 11:43:51 -05:00
Fixes for step definitions involving factories with underscores
This commit is contained in:
parent
adce9df6c9
commit
da51a4e48d
3 changed files with 29 additions and 2 deletions
|
@ -74,3 +74,25 @@ Feature: Use step definitions generated by factories
|
|||
And I should find the following for the last user:
|
||||
| name |
|
||||
| John |
|
||||
|
||||
Scenario: create instances of a factory with an underscore in its name
|
||||
Given an admin user exists with a name of "John"
|
||||
Then I should find the following for the last user:
|
||||
| name | admin |
|
||||
| John | true |
|
||||
|
||||
Scenario: use true values when creating instances
|
||||
Given the following user exists:
|
||||
| name | admin |
|
||||
| Bill | true |
|
||||
Then I should find the following for the last user:
|
||||
| name | admin |
|
||||
| Bill | true |
|
||||
|
||||
Scenario: use false values when creating instances
|
||||
Given the following user exists:
|
||||
| name | admin |
|
||||
| Mike | false |
|
||||
Then I should find the following for the last user:
|
||||
| name | admin |
|
||||
| Mike | false |
|
||||
|
|
|
@ -13,6 +13,7 @@ class CreateSchema < ActiveRecord::Migration
|
|||
|
||||
create_table :users, :force => true do |t|
|
||||
t.string :name
|
||||
t.boolean :admin, :default => false, :null => false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -32,6 +33,10 @@ end
|
|||
Factory.define :user do |f|
|
||||
end
|
||||
|
||||
Factory.define :admin_user, :parent => :user do |f|
|
||||
f.admin true
|
||||
end
|
||||
|
||||
Factory.define :post do |f|
|
||||
f.association :author, :factory => :user
|
||||
end
|
||||
|
|
|
@ -42,11 +42,11 @@ Factory.factories.values.each do |factory|
|
|||
factory.build_class.columns.each do |column|
|
||||
human_column_name = column.name.downcase.gsub('_', ' ')
|
||||
Given /^an? #{factory.human_name} exists with an? #{human_column_name} of "([^"]*)"$/i do |value|
|
||||
Factory(factory.human_name, column.name => value)
|
||||
Factory(factory.factory_name, column.name => value)
|
||||
end
|
||||
|
||||
Given /^(\d+) #{factory.human_name}s exist with an? #{human_column_name} of "([^"]*)"$/i do |count, value|
|
||||
count.to_i.times { Factory(factory.human_name, column.name => value) }
|
||||
count.to_i.times { Factory(factory.factory_name, column.name => value) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue