ActiveRecord::Base has a large ol API with several methods for finding and saving objects. For example, your AR::B objects can be created from several methods:
Foo.new(β¦)Foo.create(β¦)Foo.find(β¦)Foo.find_by_sql(β¦)Foo.find_[all_]by_*(β¦)bar.foos (associations)- ... and association search methods, of course
Similarly, the object in question can be saved in several different ways:
foo.create or foo.create!foo.save or foo.save!foo.update_attributes or foo.update_attributes!
Now, when writing unit tests, itβs good practice to drown out external method calls so that your test can focus on the business logic of the method in question. However, when it comes to working with AR::B objects - for example, in tests of a controller block - it seems that you need to fix one of the above methods, when in fact, regarding the business logic of the method, t be important, which you you take.
Do you need to associate the behavior of your method with its implementation, or am I missing something simple?
ruby-on-rails activerecord unit-testing stubbing
Gareth
source share