私はそのようなプロファイルモデルを持っています。
class Profile < ActiveRecord::Base
attr_accessible :first_name, :last_name
belongs_to :user
validates :user, presence: true
validates :first_name, presence: true, on: :update
validates :last_name, presence: true, on: :update
end
profile.should_not be_valid
first_nameとlast_nameの検証をテストするためにいくつかのrspecテストを作成したいのですが、モデルテストで更新時にのみ実行する方法がわかりません。何かのようなもの;
it "should be invalid without a first name on update" do
profile = FactoryGirl.build :profile
profile.first_name = nil
profile_should_not be_valid
end
更新アクションと作成アクションを区別せず、これに関するrspecドキュメントに何も表示されません。確かに、テストするのはかなり一般的なことです。