Note that there are some explanatory texts on larger screens.

plurals
  1. POrspec cannot find factory that is created in test
    primarykey
    data
    text
    <p>I have a <code>Factory</code> that creates a mock <code>order</code>. It has a <code>before_create</code> in the factory to create 3 models that are necessary for <code>after_create</code> callbacks when creating an <code>order</code>. The following factory code looks like this (I realize this is a little bit messy, but its what I have currently to try to get around my problem):</p> <pre><code> FactoryGirl.define do factory :order, :class =&gt; Spree::Order do # associations: association(:user, :factory =&gt; :user) association(:bill_address, :factory =&gt; :address) association(:ship_address, :factory =&gt; :address) completed_at nil bill_address_id nil ship_address_id nil email 'foo@example.com' before(:create) do |order| country = Spree::Country.find_by_id(214).blank? ? create(:country, :id =&gt; 214) : Spree::Country.find_by_id(214) state = create(:state, :country =&gt; country, :country_id =&gt; country.id) country.states = [state] FactoryGirl.create(:address, :id =&gt; 1072978592,:state =&gt; state, :country =&gt; country) if Spree::Address.find_by_id(1072978592).blank? end end end </code></pre> <p>However, when i run my tests, i keep getting errors like this:</p> <pre><code> 1) Spree::Calculator::DefaultTax#compute when given an order when no line items match the tax category should be 0 Failure/Error: let!(:order) { create(:order) } ActiveRecord::RecordInvalid: Validation failed: Country can't be blank # ./spec/models/calculator/default_tax_spec.rb:8:in `block (2 levels) in &lt;top (required)&gt;' </code></pre> <p>It's giving a validation error that the country can't be blank. I'm not sure what I'm doing wrong. I am assigning the country properly in the address and state. </p> <pre><code>rspec 2.13.0, factory_girl_rails 4.2.1 (factory _girl 4.2.0), ruby 1.9.3, rails 3.2.13 spree 1.2.4 </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload