<br><br><div><span class="gmail_quote">On 7/24/07, <b class="gmail_sendername">Ashley Moran</b> &lt;<a href="mailto:work@ashleymoran.me.uk">work@ashleymoran.me.uk</a>&gt; 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>&gt; Any hints as to how to do this without using fixtures?<br><br>I did this literally minutes ago.&nbsp;&nbsp;I don&#39;t use fixtures at all,<br>ever.&nbsp;&nbsp;Instead I put the data in the before block, eg:
<br><br>describe Purchase, &quot;assigned to a Quote that already has a saved<br>purchase&quot; do<br>&nbsp;&nbsp; before(:each) do<br>&nbsp;&nbsp;&nbsp;&nbsp; @dealer = Dealer.create!(:name =&gt;<br>&quot;Dealer1&quot;, :external_identifier =&gt; &quot;D123&quot;)
<br>&nbsp;&nbsp;&nbsp;&nbsp; @site = Site.create!(:hostname =&gt; &quot;<a href="http://my.host.name">my.host.name</a>&quot;, :dealer =&gt;<br>@dealer)<br><br>&nbsp;&nbsp;&nbsp;&nbsp; @provider = Provider.create!(:name =&gt; &quot;Provider1&quot;)<br>&nbsp;&nbsp;&nbsp;&nbsp; @product = 
Product.create!(:name =&gt; &quot;Product1&quot;, :provider =&gt;<br>@provider)<br>&nbsp;&nbsp;&nbsp;&nbsp; @applicant = Applicant.create!(:first_name =&gt; &quot;Fred&quot;, :last_name<br>=&gt; &quot;Flinstone&quot;, :email =&gt; &quot;<a href="mailto:fred@flinstone.com">
fred@flinstone.com</a>&quot;, :telephone_home =&gt;<br>&quot;01782 123456&quot;)<br>&nbsp;&nbsp;&nbsp;&nbsp; @quote_parameters = QuoteParameters.create!(:term =&gt;<br>36, :applicant =&gt; @applicant, :product =&gt; @product, :site =&gt; @site)
<br>&nbsp;&nbsp;&nbsp;&nbsp; @quote = InsuranceQuote.create!(:valid_until =&gt;<br>1.days.from_now, :quote_parameters =&gt; @quote_parameters, :premium =&gt;<br>250)<br>&nbsp;&nbsp;&nbsp;&nbsp; Purchase.create!(:quote =&gt; @quote, :amount_financed =&gt; 200)<br>
&nbsp;&nbsp; end<br><br>&nbsp;&nbsp; it &quot;should be invalid&quot; do<br>&nbsp;&nbsp;&nbsp;&nbsp; purchase = Purchase.new(:quote =&gt;<br>@quote, :amount_collected_by_card =&gt; &quot;value&quot;)<br>&nbsp;&nbsp;&nbsp;&nbsp; purchase.should_not be_valid<br>&nbsp;&nbsp;&nbsp;&nbsp; purchase.errors.on
(:quote_id).should_not be_nil<br>&nbsp;&nbsp; end<br>end<br><br>Comments welcome on whether this is a good way to do this.&nbsp;&nbsp;(I know<br>that the above doesn&#39;t test my database unique constraint, which I<br>don&#39;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.&nbsp; If I change what makes any of those objects valid, these supposedly unrelated specs will then break.&nbsp; 
<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>