2014-03-28 53 views
0

我有一列可以是正數也可以是負數,但從不爲零。我在做這似乎並沒有工作如下:Rails模型:驗證數字屬性不等於零

class Transaction < ActiveRecord::Base 
    validates :amount, presence: true 
    validates :amount, :numericality => { :not_equal_to => 0 } 
    . 
    . 
    . 

這是我的測試

let(:transaction) { FactoryGirl.build(:transaction) } 

it "is invalid if amount is zero" do 
    transaction.amount = 0 
    expect(transaction).to have(1).error_on(:amount) 
end 

這是我廠:

FactoryGirl.define do 
    factory :transaction do 
    sequence(:description) { |n| "Transaction #{n}" } 
    category_id nil 
    amount -100 
    notes nil 
    fund_id 1 
    end 
end 

什麼是查號方式是正面還是負面?還有什麼我做錯了嗎?

感謝

回答