Booking と呼ばれるモデルがあります。これは、いくつかの数値から合計を計算する必要があります (金額、デポジット、料金はすべて加算されます)。これらの引数が Faker で表示されるのに問題があります。
it "should calculate the total" do
myvar = FactoryGirl.create(:booking, :amount => 900, :deposit => 20, :fee => 8)
myvar.totalamount.should == 928
end
そして、ここに私の方法があります:
class Booking < ActiveRecord::Base
validates :to, :from, :amount, presence: true
def totalamount(amount,deposit,fee)
total = (amount + deposit + fee)
return total
end
end
エラーメッセージ:「引数の数が間違っています(3に対して0)」
ただし、 を実行するputs myvar.deposit
と、指定した値 - 20 が返されます。何が間違っていますか?
編集:予約用の私のFactoryビルドは次のとおりです。
FactoryGirl.define do
factory :booking do |b|
b.from { Faker::Lorem.sentence(word_count=3) }
b.to { Faker::Lorem.sentence(word_count=3) }
b.amount { Faker::Number.digit }
end
end