Tuesday, 15 April 2014

ruby on rails 3 - Rspec no Method error assignment -



ruby on rails 3 - Rspec no Method error assignment -

i apparently added new field client model known ct_ratio before running tests. when run tests on invoice spec, fail "no method error,ct_ratio="

customer.rb

class client < activerecord::base attr_accessible :billing_address, :customer_currency, :email, :first_name, :last_name, :mobile, :name, :payment_terms, :phase_type, :readings_attributes, :pays_vat, :ct_ratio before_validation self.ct_ratio ||= 1 end end

invoice_spec

describe invoice context 'create_item_from_readings' before :each @customer = factorygirl.create :customer @reading1 = @customer.readings.create! reading1: 100, date_of_reading: 30.days.ago @reading2 = @customer.readings.create! reading1: 200, date_of_reading: 20.days.ago @reading3 = @customer.readings.create! reading1: 500, date_of_reading: 10.days.ago @customer.stub(:unit_cost).and_return(100) end "should create invoice item reading" invoice = invoice.new customer: @customer, invoice_date: 15.days.ago, due_date: date.today item = invoice.create_item_from_readings item.rate.should == 100 item.amount.should == 100 * 100 item.description.should == "electricity used #{@reading1.date_of_reading.strftime('%d/%m/%y')} #{@reading2.date_of_reading.strftime('%d/%m/%y')} - 100 units" end

i added ct_ratio mill girl

require 'factory_girl' factorygirl.define mill :customer name 'test test' first_name "test" last_name "test" mobile "00000000" billing_address "kampala" payment_terms "immediate" phase_type "single phase" customer_currency "ugx" pays_vat false email "test@test.com" ct_ratio 1 end mill :reading |f| f.reading1 100 f.reading2 150 f.reading3 200 f.date_of_reading 30.days.ago end end

this mutual error when not running tests via rake , migration not run on test-database.

run rails_env=test rake db:migrate first , check out testsuite.

ruby-on-rails-3 rspec

No comments:

Post a Comment