ruby on rails - Rspec, shoulda, validate_uniqueness_of with scope and wrong error message -


i have following rspec test:

describe productlimit    before(:each)      @productlimit = factory.create(:productlimit, :user => factory.create(:user))   end    subject { @productlimit }    ...    { should validate_uniqueness_of(:price_cents).scoped_to(:direction_down, :currency, :market_id, :user_id) }   ... end 

but following confusing error:

1) productlimit       failure/error: { should validate_uniqueness_of(:price_cents).scoped_to(:direction_down, :currency, :market_id, :user_id) }        expected errors include "has been taken" when price_cents set 9530, got errors: ["direction_down has been taken (false)"] 

can me? don't understand why isn't working, because error message seems correct?

edit:

this happens in other situations well:

# product_spec.rb ... { should validate_numericality_of(:price).with_message("price_cents must greater 0 (0)") }    # rake spec:models failure/error: { should validate_numericality_of(:price).with_message("price_cents must greater 0 (0)") }    expected errors include "price_cents must greater 0 (0)" when price set "abcd", got errors: ["price_cents must greater 0 (0)"] 

to check validate_uniqueness_of(:field) should @ lease 1 record in database check uniquness constrain. here is....

before   @country = factorygirl.create(:country, :id =>"a0000007-0000-0000-0000-000000000009",:currency_id => "a0000006-0000-0000-0000-000000000004",:merchant_id => "a0000001-0000-0000-0000-000000000002",:country_code => 'can', :name => 'canada') end 

to validate uniqueness

it { should validate_uniqueness_of(:country_code)} 

it work out try out.


Comments

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

java - Output of Eclipse is rubbish -

jquery - Confused with JSON data and normal data in Django ajax request -