rob_twf wrote:
>
>
> it "should validate that the postcode is correctly formatted" do
>
> Location.should_receive(:validates_as_uk_postcode).once.with(:post_code)
> load Location.source_file
> end
>
> That works nicely.
>
>
Looks like I was a bit eager. Loading the class in this way causes problems
with other validations. For example, I add a name attribute to my class and
validate it's length like this:
class Location < ActiveRecord::Base
validates_length_of :name, :in => 1..50
validates_as_uk_postcode :post_code
end
And have this additional specification:
it "should be invalid if the name is too long" do
@location.name => 'x' * 51
@location.should_not be_valid
@location.should have(1).error_on(:name)
end
(
This fails because the length validation occurs twice giving two (identical)
errors on :name. Removing the post code validation specification allows the
name length validation to work correctly.
So load() is causing the validation to be defined twice - is there any way
to avoid this?
--
View this message in context:
http://www.nabble.com/Spec-for-validation-plugin-tf4152378.html#a11828149
Sent from the rspec-users mailing list archive at Nabble.com.
_______________________________________________
rspec-users mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/rspec-users