On 24 Jul 2007, at 14:07, Daniel N wrote:
> Any hints as to how to do this without using fixtures?
I did this literally minutes ago. I don't use fixtures at all,
ever. Instead I put the data in the before block, eg:
describe Purchase, "assigned to a Quote that already has a saved
purchase" do
before(:each) do
@dealer = Dealer.create!(:name =>
"Dealer1", :external_identifier => "D123")
@site = Site.create!(:hostname => "my.host.name", :dealer =>
@dealer)
@provider = Provider.create!(:name => "Provider1")
@product = Product.create!(:name => "Product1", :provider =>
@provider)
@applicant = Applicant.create!(:first_name => "Fred", :last_name
=> "Flinstone", :email => "[EMAIL PROTECTED]", :telephone_home =>
"01782 123456")
@quote_parameters = QuoteParameters.create!(:term =>
36, :applicant => @applicant, :product => @product, :site => @site)
@quote = InsuranceQuote.create!(:valid_until =>
1.days.from_now, :quote_parameters => @quote_parameters, :premium =>
250)
Purchase.create!(:quote => @quote, :amount_financed => 200)
end
it "should be invalid" do
purchase = Purchase.new(:quote =>
@quote, :amount_collected_by_card => "value")
purchase.should_not be_valid
purchase.errors.on(:quote_id).should_not be_nil
end
end
Comments welcome on whether this is a good way to do this. (I know
that the above doesn't test my database unique constraint, which I
don't do in this case come to think of it, but I try to keep DB specs
separate, hard as that may be sometimes.)
Ashley
_______________________________________________
rspec-users mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/rspec-users