I want to use current_user (of devise) inside the factories I create using factory_girl.
My environment contains: Ruby 1.8.7 / Rails 2.3.5 / Devise / Cucumber / Pickle / Factory Girl
I've the following models
User:
has_many :for_me, :class_name => "Task", ....details
has_many :from_me, :class_name => "Task", ....details
Task:
belongs_to :assigner, :class_name => "User", ....details
belongs_to :assignee, :class_name => "User", ....details
I'm testing the following scenario:
Given the following users exist
| email | password |
| u1@d.com | 123456 |
| u1@d.com | 123456 |
And users are confirmed
And I am on the sign in page
And I am logged in as "u1@d.com" with password "123456"
When I fill in "task[description]" with "description 1"
And I press "task_submit"
Then I should see "description 1"
The factories I have are:
Factory.define :user do |f|
f.first_name 'user_fn'
f.last_name 'user_ln'
f.sequence(:username) {|n| "user_#{n}"}
f.sequence(:email) {|n| "user_#{n}@domain.com"}
f.password 开发者_如何学Python '123456'
f.mobile_number '0123456798'
end
Factory.define :task do |f|
f.association :assignee, xxxxxxx
f.association :assigner, :factory => :user
end
My problem is that I want to use current_user of devise instead of the xxxxxxx
You can't code it directly within the Factory I guess.
Try this:
Factory(:task, :assignee => current_user)
精彩评论