ruby on rails - wrong number of arguments (1 for 0) in rspec -
i problems tests after adding custom validation income model.
@member.incomes << [income.new(starting_date: '2015-01-01', amount: 1200, member: @member), income.new(starting_date: '2015-04-01', amount: 1400, member: @member)]
i following error: wrong number of arguments (1 0)
my observation debugger
:
first record correctly inserted, 2nd 1 getting error.
what i'm doing wrong - idea?
update:
concat method couldn't here.
more code:
income.rb validate :newly_added_income_is_also_the_newest? .... .. def newly_added_income_is_also_the_newest? latest_income = income.where(member: member_id).select{|i|i}.max(&:starting_date) return true if latest_income.nil? if !latest_income.nil? && latest_income.starting_date >= starting_date errors.add(:income, "newest income should latest income of member '#{member.full_name}''") end end
test: [budget] should incomes in between of start_date , end_date
@member.incomes.concat[income.new(starting_date: '2015-01-01', amount: 1200, member: @member), income.new(starting_date: '2015-04-01', amount: 1400, member: @member)] budget = factorygirl.create(:budget, donation: @donation, member: @member) expect(budget.get_all_incomes_for_budget_duration.size).to eq(3)
log1
1) budget tests budget based donation types [budget] should incomes in between of start_date , end_date failure/error: @member.incomes.concat[income.new(starting_date: '2015-01-01', amount: 1200, member: @member), typeerror: no implicit conversion of income integer # ./spec/models/budget_spec.rb:44:in `[]' # ./spec/models/budget_spec.rb:44:in `block (3 levels) in <top (required)>'
test2: [budget] should adapted promise income change between budget range (failed - 2)
it '[budget] should adapted promise income change between budget range', skip_before: true member.delete_all donation.delete_all member = factorygirl.create(:member) donation = factorygirl.create(:majlis_khuddam_donation) #income = factorygirl.create(:income, member: member) member.incomes << income.new(starting_date: '2015-01-01', amount: 1200, member_id: 12345) << income.new(starting_date: '2015-03-01', amount: 1000, member_id: 12345) budget = factorygirl.create(:budget, donation: donation, member: member) expect(budget.promise).to eq(123) end
log2
2) budget tests budget based donation types [budget] should adapted promise income change between budget range failure/error: income.new(starting_date: '2015-03-01', amount: 1000, member_id: 12345) argumenterror: wrong number of arguments (1 0) # /users/user/.rvm/gems/ruby-2.2.0@maalify/gems/activerecord-4.2.0/lib/active_record/attribute_methods.rb:48:in `__temp__374716274796e676f546164756' # ./app/models/income.rb:22:in `each' # ./app/models/income.rb:22:in `max' # ./app/models/income.rb:22:in `newly_added_income_is_also_the_newest?'
i believe error occurs here:
latest_income = income.where(member: member_id).select{|i|i}.max(&:starting_date)
max
method defined in enumerable
. not take argument, message "wrong number of arguments (1 0)".
you want method maximum
, defined in activerecord. takes column name:
latest_income = income.where(member: member_id).maximum(:starting_date)
Comments
Post a Comment