# Stubbing out ActiveRecord models

**URL:** <https://www.ruby-forum.com/t/stubbing-out-activerecord-models/67105>\
**Category:** Rails\
**Created:** [August 31, 2006, 5:34pm UTC](https://www.ruby-forum.com/t/stubbing-out-activerecord-models/67105 "2006-08-31T17:34:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![bryan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/db5fbb/32.png) [@bryan](https://www.ruby-forum.com/u/bryan)\
**Post date:** [August 31, 2006, 5:34pm UTC](https://www.ruby-forum.com/t/stubbing-out-activerecord-models/67105/1 "2006-08-31T17:34:24Z")

</div>

I have an active record model which roughly looks like this:

require ‘soap/rpc/driver’  
class Job \< ActiveRecord::Base  
def self.submit(item)  
… do soap call …  
… create Job …  
return job  
end

def status(status\_type)  
… do soap call …  
return soap\_message  
end  
end

I’m trying to stub it out under test/mock/tests/job.rb.

class EnvoyJob

def self.submit(item)  
j = Job.create({:foo =\> item, :bar =\> ‘constant value for  
testing’})  
end

def availability(status\_type)  
case status\_type  
when 1  
item = {“Local Channel” =\> “1 mile”, “LoopCost” =\> 918.24 }  
return item.to\_yaml  
end  
end

end

This code doesn’t work. What do I need to do to mock out an  
ActiveRecord model?

---

<div class="post-metadata">

**Author:** ![bryan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/db5fbb/32.png) [@bryan](https://www.ruby-forum.com/u/bryan)\
**Post date:** [August 31, 2006, 5:50pm UTC](https://www.ruby-forum.com/t/stubbing-out-activerecord-models/67105/2 "2006-08-31T17:50:27Z")

</div>

On 31/08/06, Bryan L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> end
> 
> ```
> end
> 
> ```
> 
> end
> 
> end
> 
> This code doesn’t work. What do I need to do to mock out an  
> ActiveRecord model?
> 
> >

You need to name the mock class the same as the class you want to mock.

–  
James.

> **[James Mead](https://jamesmead.org/)**
>
> Ruby Developer, author of Mocha, and ex-Antarctic Hero.
