我有一個控制器,這使得測試:無法在rspec控制器測試中設置Devise用戶屬性sign_in_count。它被重置爲0控制器
@first_login = (@user.sign_in_count == 1)
,我需要與在rspec的規範色器件設置它:
我已經試過這四個理念:在所有這些用戶是等生成:user = Factory(:member)
[參閱下面的工廠]
user.stubs(:sign_in_count).returns(1)
sign_in user
get 'index'
user.sign_in_count = 1
sign_in user # here user.sign_in_count == 1
get 'index' # here user.sign_in_count == 1
sign_in user
sign_in user
get 'index'
sign_in user
user.sign_in_count = 1
get 'index'
但是在控制器每次中,色器件特定用戶屬性被置零/零-ED進行。
reset_password_token: nil, reset_password_sent_at: nil,
remember_created_at: nil, sign_in_count: 0, current_sign_in_at: nil,
last_sign_in_at: nil, current_sign_in_ip: nil, last_sign_in_ip: nil
任何想法爲什麼?
[規格/ factories.rb - factory_girl]
Factory.define :member, :class => User do |c|
c.password "a123456h"
c.first_name "Jack"
c.last_name "Lee"
c.email "[email protected]"
c.address_street "123 Main"
c.address_city "Anytown"
c.address_state "NV"
c.address_zip "40455"
c.address_country "USA"
c.when_account_created 2.days.ago
c.change_password_count 3
c.forgot_password_count 2
c.created_at 2.days.ago
c.updated_at 10.hours.ago
end
你是如何創建用戶實例的?你使用燈具還是工廠女孩? – 2011-06-05 19:21:07
我已經用factory_girl和手工創建了實例。控制器似乎得到了不同於我們設置的用戶。 – JAWspeak 2011-06-06 19:53:11