I''m trying to test code in a controller that needs to respond to
changes
in the database, but I''m having problems updating the model from the
functional test. Here''s a rough approximation of what I have:
def test_changes
get :list
assert_equal old_price = product(:myproduct).price, assigns(:items)[0].price
Product.find(product(:myproduct).id).update_attribute(''price'',
old_price + 100)
get :list
assert_equal old_price + 100, assigns(:items)[0].price
end
I can also try Product.find(1) (the fixture has an id of 1), and try separating
out .price += 100 and .save, with the same error happening on the line with
.save.
This is the error I''m getting:
1) Error:
test_changes(MyControllerTest):
TypeError: cannot convert String into Integer
/usr/lib/ruby/gems/1.8/gems/activerecord-1.13.0/lib/active_record/associations/association_proxy.rb:75:in
`[]''
/usr/lib/ruby/gems/1.8/gems/activerecord-1.13.0/lib/active_record/associations/association_proxy.rb:75:in
`send''
/usr/lib/ruby/gems/1.8/gems/activerecord-1.13.0/lib/active_record/associations/association_proxy.rb:75:in
`method_missing''
/usr/lib/ruby/gems/1.8/gems/activerecord-1.13.0/lib/active_record/associations/has_and_belongs_to_many_association.rb:81:in
`method_missing''
(eval):1:in `id''
/usr/lib/ruby/gems/1.8/gems/activerecord-1.13.0/lib/active_record/base.rb:1439:in
`update_without_lock''
/usr/lib/ruby/gems/1.8/gems/activerecord-1.13.0/lib/active_record/locking.rb:45:in
`update_without_callbacks''
/usr/lib/ruby/gems/1.8/gems/activerecord-1.13.0/lib/active_record/callbacks.rb:274:in
`update_without_timestamps''
/usr/lib/ruby/gems/1.8/gems/activerecord-1.13.0/lib/active_record/timestamp.rb:39:in
`update''
/usr/lib/ruby/gems/1.8/gems/activerecord-1.13.0/lib/active_record/base.rb:1431:in
`create_or_update_without_callbacks''
/usr/lib/ruby/gems/1.8/gems/activerecord-1.13.0/lib/active_record/callbacks.rb:249:in
`create_or_update''
/usr/lib/ruby/gems/1.8/gems/activerecord-1.13.0/lib/active_record/base.rb:1231:in
`save_without_validation''
/usr/lib/ruby/gems/1.8/gems/activerecord-1.13.0/lib/active_record/validations.rb:687:in
`save_without_transactions''
/usr/lib/ruby/gems/1.8/gems/activerecord-1.13.0/lib/active_record/transactions.rb:126:in
`save''
/usr/lib/ruby/gems/1.8/gems/activerecord-1.13.0/lib/active_record/transactions.rb:126:in
`transaction''
/usr/lib/ruby/gems/1.8/gems/activerecord-1.13.0/lib/active_record/transactions.rb:91:in
`transaction''
/usr/lib/ruby/gems/1.8/gems/activerecord-1.13.0/lib/active_record/transactions.rb:118:in
`transaction''
/usr/lib/ruby/gems/1.8/gems/activerecord-1.13.0/lib/active_record/transactions.rb:126:in
`save''
/usr/lib/ruby/gems/1.8/gems/activerecord-1.13.0/lib/active_record/validations.rb:709:in
`update_attribute''
./test/functional/my_controller_test.rb:XXX:in
''test_changes''
Any help solving this would be greatly appreciated!
Just a thought, but did you try ensurnig that old_price was an integer?
Product.find(product(:myproduct).id).update_attribute(''price'',
old_price.to_i + 100)
or even...
Product.find(product(:myproduct).id).update_attribute(''price'',
old_price.to_f + 100)
On Wed, 7 Dec 2005, rails-4dtGyw5agdmakBO8gow8eQ@public.gmane.org wrote:
> I''m trying to test code in a controller that needs to respond to
changes
> in the database, but I''m having problems updating the model from
the
> functional test. Here''s a rough approximation of what I have:
>
> def test_changes
> get :list
> assert_equal old_price = product(:myproduct).price,
assigns(:items)[0].price
>
Product.find(product(:myproduct).id).update_attribute(''price'',
old_price + 100)
> get :list
> assert_equal old_price + 100, assigns(:items)[0].price
> end
>
> I can also try Product.find(1) (the fixture has an id of 1), and try
separating out .price += 100 and .save, with the same error happening on the
line with .save.
>
> This is the error I''m getting:
>
> 1) Error:
> test_changes(MyControllerTest):
> TypeError: cannot convert String into Integer
>
/usr/lib/ruby/gems/1.8/gems/activerecord-1.13.0/lib/active_record/associations/association_proxy.rb:75:in
`[]''
>
/usr/lib/ruby/gems/1.8/gems/activerecord-1.13.0/lib/active_record/associations/association_proxy.rb:75:in
`send''
>
/usr/lib/ruby/gems/1.8/gems/activerecord-1.13.0/lib/active_record/associations/association_proxy.rb:75:in
`method_missing''
>
/usr/lib/ruby/gems/1.8/gems/activerecord-1.13.0/lib/active_record/associations/has_and_belongs_to_many_association.rb:81:in
`method_missing''
> (eval):1:in `id''
>
/usr/lib/ruby/gems/1.8/gems/activerecord-1.13.0/lib/active_record/base.rb:1439:in
`update_without_lock''
>
/usr/lib/ruby/gems/1.8/gems/activerecord-1.13.0/lib/active_record/locking.rb:45:in
`update_without_callbacks''
>
/usr/lib/ruby/gems/1.8/gems/activerecord-1.13.0/lib/active_record/callbacks.rb:274:in
`update_without_timestamps''
>
/usr/lib/ruby/gems/1.8/gems/activerecord-1.13.0/lib/active_record/timestamp.rb:39:in
`update''
>
/usr/lib/ruby/gems/1.8/gems/activerecord-1.13.0/lib/active_record/base.rb:1431:in
`create_or_update_without_callbacks''
>
/usr/lib/ruby/gems/1.8/gems/activerecord-1.13.0/lib/active_record/callbacks.rb:249:in
`create_or_update''
>
/usr/lib/ruby/gems/1.8/gems/activerecord-1.13.0/lib/active_record/base.rb:1231:in
`save_without_validation''
>
/usr/lib/ruby/gems/1.8/gems/activerecord-1.13.0/lib/active_record/validations.rb:687:in
`save_without_transactions''
>
/usr/lib/ruby/gems/1.8/gems/activerecord-1.13.0/lib/active_record/transactions.rb:126:in
`save''
>
/usr/lib/ruby/gems/1.8/gems/activerecord-1.13.0/lib/active_record/transactions.rb:126:in
`transaction''
>
/usr/lib/ruby/gems/1.8/gems/activerecord-1.13.0/lib/active_record/transactions.rb:91:in
`transaction''
>
/usr/lib/ruby/gems/1.8/gems/activerecord-1.13.0/lib/active_record/transactions.rb:118:in
`transaction''
>
/usr/lib/ruby/gems/1.8/gems/activerecord-1.13.0/lib/active_record/transactions.rb:126:in
`save''
>
/usr/lib/ruby/gems/1.8/gems/activerecord-1.13.0/lib/active_record/validations.rb:709:in
`update_attribute''
> ./test/functional/my_controller_test.rb:XXX:in
''test_changes''
>
> Any help solving this would be greatly appreciated!
> _______________________________________________
> Rails mailing list
> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
Actually, it was a mistake I made somewhere else, completely unrelated. The problem was all me. :) On Wed, Dec 07, 2005 at 01:19:50PM -0700, Ken Bowley wrote:> Just a thought, but did you try ensurnig that old_price was an integer? > > Product.find(product(:myproduct).id).update_attribute(''price'', > old_price.to_i + 100) > > or even... > > Product.find(product(:myproduct).id).update_attribute(''price'', > old_price.to_f + 100) > > On Wed, 7 Dec 2005, rails-4dtGyw5agdmakBO8gow8eQ@public.gmane.org wrote: > > >I''m trying to test code in a controller that needs to respond to changes > >in the database, but I''m having problems updating the model from the > >functional test. Here''s a rough approximation of what I have: > >...