There's an echo in my head

日々のメモ。

sorceryを使ったログインのテストをするときはupdate_attributesを使うこと

sorcery v0.9.0からソルトの生成とパスワードの暗号化の処理がbefore_saveからbefore_validationに移された。この影響で、テストのためにログインパスワードを上書きするときにupdate_attributeを使っているとログインできずにテストが落ちるようになった。

これはupdate_attributeがバリデーションをスキップするためにbefore_validationのフックが発火されないためだ。

対策としてはupdate_attributesもしくはupdate_attributes!を使えばいい。

module AuthenticationForFeatureRequest
  def login user, password = 'login'
    user.update_attributes password: password

    page.driver.post sessions_url, {email: user.email, password: password}
    visit root_url
  end
end

wikiのほうも更新しておいた

このブログに出てくるコードスニペッツは、引用あるいは断りがない限りMITライセンスです。