Note that there are some explanatory texts on larger screens.

plurals
  1. POActiveRecord reporting a failed validation, but there are no validations defined
    primarykey
    data
    text
    <p>I'm just starting to use RSpec with a new project (after being a minitest user for a while). I've created a single MVC, called contracts. Here is the model file:</p> <pre><code>class Contract &lt; ActiveRecord::Base attr_accessible :name, :number, :plannedStart, :actualStart, :plannedCompletion, :actualCompletion end </code></pre> <p>I've got a basic factory defined for Contracts (it was slightly more complex earlier, using sequence to generate novel names and numbers, but I removed all of that to try to simplify squashing this bug):</p> <pre><code>FactoryGirl.define do factory :contract do end end </code></pre> <p>Here are the specs (pretty much auto generated, except I added in the calls to the factory):</p> <pre><code>require File.dirname(__FILE__) + '/../spec_helper' describe ContractsController do render_views it "index action should render index template" do create(:contract) get :index response.should render_template(:index) end it "show action should render show template" do create(:contract) get :show, :id =&gt; Contract.first response.should render_template(:show) end it "new action should render new template" do get :new response.should render_template(:new) end it "create action should render new template when model is invalid" do Contract.any_instance.stubs(:valid?).returns(false) post :create response.should render_template(:new) end it "create action should redirect when model is valid" do Contract.any_instance.stubs(:valid?).returns(true) post :create response.should redirect_to(contract_url(assigns[:contract])) end it "edit action should render edit template" do create(:contract) get :edit, :id =&gt; Contract.first response.should render_template(:edit) end it "update action should render edit template when model is invalid" do create(:contract) Contract.any_instance.stubs(:valid?).returns(false) put :update, :id =&gt; Contract.first response.should render_template(:edit) end it "update action should redirect when model is valid" do create(:contract) create(:contract) Contract.any_instance.stubs(:valid?).returns(true) put :update, :id =&gt; Contract.first response.should redirect_to(contract_url(assigns[:contract])) end it "destroy action should destroy model and redirect to index action" do create(:contract) contract = Contract.first delete :destroy, :id =&gt; contract response.should redirect_to(contracts_url) Contract.exists?(contract.id).should be_false end end </code></pre> <p>When I run the spec, I get the following error message, but the number of these I get varies from run to run: </p> <pre><code>ActiveRecord::RecordInvalid: Validation failed: ./spec/controllers/contracts_controller_spec.rb:39:in `block (2 levels) in &lt;top (required)&gt;' ActiveRecord::RecordInvalid: Validation failed: ./spec/controllers/contracts_controller_spec.rb:45:in `block (2 levels) in &lt;top (required)&gt;' ActiveRecord::RecordInvalid: Validation failed: ./spec/controllers/contracts_controller_spec.rb:7:in `block (2 levels) in &lt;top (required)&gt;' 10 examples, 3 failures, 7 passed Finished in 0.360139 seconds /Users/jlee/.rvm/rubies/ruby-1.9.3-p194/bin/ruby -S rspec ./spec/controllers/contracts_controller_spec.rb ./spec/models/contract_spec.rb failed </code></pre> <p>I've implemented Databasecleaner just to make sure this wasn't some odd behavior problem relating to using transactions during testing, but to no avail. Suggestions? I have no validations defined, so its hard to understand how I could be failing validation.</p>
    singulars
    1. This table or related slice is empty.
    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