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