Permalink
Browse files

Only strip strings in step definitions

This allows for cucumber transforms to create different data structrues
and still work with factory girl steps.

Closes #185
  • Loading branch information...
1 parent a50c703 commit 05ddd3d6b53da057eb2b9faf5897d27562391622 @joshuaclayton joshuaclayton committed Aug 22, 2011
@@ -198,3 +198,19 @@ Feature: Use step definitions generated by factories
Then I should find the following for the last user:
| id | name | admin |
| 123 | Joe | true |
+
+ Scenario: Transform parses string data into array before assigning to an association
+ Given the following tags exist:
+ | name |
+ | funky |
+ | cool |
+ | hip |
+ And the following post exists:
+ | title | tags |
+ | Tagged post | cool, hip |
+ Then the post "Tagged post" should have the following tags:
+ | name |
+ | cool |
+ | hip |
+ And the post "Tagged post" should not have the following tags:
+ | funky |
@@ -11,8 +11,30 @@
model_class.count.should == count.to_i
end
+Then /^the post "([^"]*)" should (not )?have the following tags?:$/ do |post_title, negate, table|
+ post = Post.find_by_title!(post_title)
+
+ table.hashes.each do |row|
+ tag = Tag.find_by_name(row[:name])
+
+ if negate
+ post.tags.should_not include(tag)
+ else
+ post.tags.should include(tag)
+ end
+ end
+end
+
+Transform /^table:(?:.*,)?tags(?:,.*)?$/ do |table|
+ table.map_column!("tags") do |tags|
+ tags.split(',').map {|tag| Tag.find_by_name! tag.strip }
+ end
+ table
+end
+
Before do
Post.delete_all
+ Tag.delete_all
User.delete_all
Category.delete_all
CategoryGroup.delete_all
@@ -21,6 +21,11 @@ def self.up
t.string :name
end
+ create_table :tags, :force => true do |t|
+ t.integer :post_id
+ t.string :name
+ end
+
create_table :users, :force => true do |t|
t.string :name
t.boolean :admin, :default => false, :null => false
@@ -43,6 +48,11 @@ class Category < ActiveRecord::Base
class Post < ActiveRecord::Base
belongs_to :author, :class_name => 'User'
belongs_to :category
+ has_many :tags
+end
+
+class Tag < ActiveRecord::Base
+ belongs_to :post
end
class NonActiveRecord
@@ -74,6 +84,9 @@ class NonActiveRecord
category
end
+ factory :tag do
+ post
+ end
# This is here to ensure that factory step definitions don't raise for a non-AR factory
factory :non_active_record do
end
@@ -21,7 +21,8 @@ def attributes(strategy = CreateAttributes)
private
def process_key_value(key, value)
- [key.downcase.gsub(' ', '_').to_sym, value.to_s.strip]
+ value = value.strip if value.is_a?(String)
+ [key.downcase.gsub(' ', '_').to_sym, value]
end
class AssociationManager

0 comments on commit 05ddd3d

Please sign in to comment.