Using RSpec 2.6 / Rails 3.1 / Postgres:
I am writing a supporting module (in my lib/) that any AR model can include. I'd like to write spec for this module. It needs to be included by an AR::Base model, because it loads associations when included and relies on some AR methods, but i don't want to use my existing model when writing rspec for this module.
I would just like to create an arbitrary AR model, but obviously it would not have a table associated in the database and AR is dying. Here's kindda what I want to do:
class SomeRandomModel < ActiveRecord::Base
include MyModule
# simulate DB attributes that MyModule would be using
attr_accessor :foo, :bar, :baz
end
describe SomeRandomModel do
it '#some_method_in_my_module' do
srm = SomeRandomModel.new(:foo => 1)
srm.some_method_in_my_module.should eq(something)
end
end
Of course, i get some error in postgres about the relation not existing.
Thanks for your help!