<br><br><div><span class="gmail_quote">On 7/24/07, <b class="gmail_sendername">Ashley Moran</b> <<a href="mailto:work@ashleymoran.me.uk">work@ashleymoran.me.uk</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>On 24 Jul 2007, at 14:07, Daniel N wrote:<br><br>> Any hints as to how to do this without using fixtures?<br><br>I did this literally minutes ago. I don't use fixtures at all,<br>ever. Instead I put the data in the before block, eg:
<br><br>describe Purchase, "assigned to a Quote that already has a saved<br>purchase" do<br> before(:each) do<br> @dealer = Dealer.create!(:name =><br>"Dealer1", :external_identifier => "D123")
<br> @site = Site.create!(:hostname => "<a href="http://my.host.name">my.host.name</a>", :dealer =><br>@dealer)<br><br> @provider = Provider.create!(:name => "Provider1")<br> @product =
Product.create!(:name => "Product1", :provider =><br>@provider)<br> @applicant = Applicant.create!(:first_name => "Fred", :last_name<br>=> "Flinstone", :email => "<a href="mailto:fred@flinstone.com">
fred@flinstone.com</a>", :telephone_home =><br>"01782 123456")<br> @quote_parameters = QuoteParameters.create!(:term =><br>36, :applicant => @applicant, :product => @product, :site => @site)
<br> @quote = InsuranceQuote.create!(:valid_until =><br>1.days.from_now, :quote_parameters => @quote_parameters, :premium =><br>250)<br> Purchase.create!(:quote => @quote, :amount_financed => 200)<br>
end<br><br> it "should be invalid" do<br> purchase = Purchase.new(:quote =><br>@quote, :amount_collected_by_card => "value")<br> purchase.should_not be_valid<br> purchase.errors.on
(:quote_id).should_not be_nil<br> end<br>end<br><br>Comments welcome on whether this is a good way to do this. (I know<br>that the above doesn't test my database unique constraint, which I<br>don't do in this case come to think of it, but I try to keep DB specs
<br>separate, hard as that may be sometimes.)<br><br>Ashley</blockquote><div><br>That looks like the kind of thing I was initially thinking of, but I started to think that having all those objects being created in a non-related spec could lead to trouble. If I change what makes any of those objects valid, these supposedly unrelated specs will then break.
<br><br>I want to try and keep everything seperate, but in this case it seems that things are interdependent.<br><br>Cheers<br>Daniel<br></div><br></div><br>