Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shoulda: Test validates_presence_of :on => :update

I'm using Shoulda in combination with Test::Unit on one of the projects I work on. The issue I'm running into is that I recently changed this:

class MyModel < ActiveRecord::Base
  validates_presence_of :attribute_one, :attribute_two
end

to this:

class MyModel < ActiveRecord::Base
  validates_presence_of :attribute_one
  validates_presence_of :attribute_two, :on => :update
end

Previously, my (passing) tests looked like this:

class MyModelTest < ActiveSupport::TestCase
  should_validate_presence_of :attribute_one, :attribute_two
end

As far as I can tell, there is no parameter to should_validate_presence_of that will cause this test to continue to pass with the changes specified above. Short of abandoning Shoulda when testing the requirement of :attribute_two, is there any way around this?

like image 499
jerhinesmith Avatar asked Jan 05 '10 21:01

jerhinesmith


1 Answers

What about something like this? (for shoulda-matchers-3.1.1)

subject { FactoryGirl.build(:your_model) }
it { is_expected.to validate_presence_of(:attribute_one) }
it { is_expected.to validate_presence_of(:attribute_two).on(:update) }
like image 74
jonnyjava.net Avatar answered Sep 28 '22 07:09

jonnyjava.net