Cucumber step definitions with blank association columns work intelligently
This commit is contained in:
parent
e00389b510
commit
2cfc4813fa
|
@ -60,6 +60,18 @@ Feature: Use step definitions generated by factories
|
|||
| a title | 123 |
|
||||
And there should be 1 user
|
||||
|
||||
Scenario: create post with and without a category association
|
||||
Given the following users exist:
|
||||
| ID | Name |
|
||||
| 123 | Joe |
|
||||
And the following posts exist:
|
||||
| Title | Author | Category |
|
||||
| a title | Name: Joe | Name: programming |
|
||||
| a title without a category | Name: Joe | |
|
||||
Then I should find the following for the last post:
|
||||
| title | category_id |
|
||||
| a title without a category | |
|
||||
|
||||
Scenario: create a user without attributes
|
||||
Given a user exists
|
||||
Then there should be 1 user
|
||||
|
|
|
@ -7,10 +7,15 @@ class CreateSchema < ActiveRecord::Migration
|
|||
def self.up
|
||||
create_table :posts, :force => true do |t|
|
||||
t.integer :author_id
|
||||
t.integer :category_id
|
||||
t.string :title
|
||||
t.string :body
|
||||
end
|
||||
|
||||
create_table :categories, :force => true do |t|
|
||||
t.string :name
|
||||
end
|
||||
|
||||
create_table :users, :force => true do |t|
|
||||
t.string :name
|
||||
t.boolean :admin, :default => false, :null => false
|
||||
|
@ -23,8 +28,12 @@ CreateSchema.suppress_messages { CreateSchema.migrate(:up) }
|
|||
class User < ActiveRecord::Base
|
||||
end
|
||||
|
||||
class Category < ActiveRecord::Base
|
||||
end
|
||||
|
||||
class Post < ActiveRecord::Base
|
||||
belongs_to :author, :class_name => 'User'
|
||||
belongs_to :category
|
||||
end
|
||||
|
||||
class NonActiveRecord
|
||||
|
@ -37,8 +46,13 @@ Factory.define :admin_user, :parent => :user do |f|
|
|||
f.admin true
|
||||
end
|
||||
|
||||
Factory.define :category do |f|
|
||||
f.name "programming"
|
||||
end
|
||||
|
||||
Factory.define :post do |f|
|
||||
f.association :author, :factory => :user
|
||||
f.association :category
|
||||
end
|
||||
|
||||
# This is here to ensure that factory step definitions don't raise for a non-AR factory
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
module FactoryGirlStepHelpers
|
||||
def convert_association_string_to_instance(factory_name, assignment)
|
||||
attribute, value = assignment.split(':', 2)
|
||||
return if value.blank?
|
||||
attributes = convert_human_hash_to_attribute_hash(attribute => value.strip)
|
||||
factory = Factory.factory_by_name(factory_name)
|
||||
model_class = factory.build_class
|
||||
|
|
Loading…
Reference in New Issue