And then if you need for your integration tests real models which will respond as real models and have database identification, you probably might find useful the following trick. Add the following strings into your spec_helper.rb file.
module Dummyficator
def dummy_inst(klass, attrs={ })
inst = klass.new attrs
inst.stub!(:valid?).and_return(true)
inst.save
inst
end
end
include Dummyficator
After this you'll be able to create dummy model instances in your specs like that
describe Group, "with users" do
before do
@group = dummy_inst Group
@group << dummy_inst User
@group << dummy_inst User, :username => 'dummy'
end
it "should have two users" do
@group.should have(2).users
end
it "should not destroy users" do
@group.destroy
User.find_by_username('dummy').should_not be_nil
end
end
This way you will be able to create new and new database records which will behave just as they should except the validation, so you can concentrate on the models relations not worrying about the models validation.