[rspec-devel] [ rspec-Bugs-6594 ] trunk doesn't always rollback new records after controller specs

noreply at rubyforge.org noreply at rubyforge.org
Thu Nov 9 21:28:55 EST 2006


Bugs item #6594, was opened at 2006-11-09 21:28
You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=3149&aid=6594&group_id=797

Category: rails plugin
Group: None
Status: Open
Resolution: None
Priority: 3
Submitted By: Jay Levitt (jaylev)
Assigned to: Nobody (None)
Summary: trunk doesn't always rollback new records after controller specs

Initial Comment:
Given the rails app below:

spec spec/models/person_spec.rb works.
spec spec/controllers/test_controller_spec.rb spec/models/person_spec.rb fails with "ActiveRecord::RecordInvalid in 'A Person should create reggie'
Validation failed: Name has already been taken" because the record already exists by the time it gets to person_spec.


# testapp/db/migrate/001_create_people.rb
class CreatePeople < ActiveRecord::Migration
  def self.up
    create_table "people" do |t|
      t.column "name", :string
    end
  end

  def self.down
  end
end

# testapp/models/person.rb
class Person < ActiveRecord::Base
  validates_uniqueness_of :name
end

# testapp/controllers/test_controller.rb
class TestController < ActionController::Base

  def new 
    p = Person.new
    p.name = "reggie"
    p.save! 
    render :text => "created reggie"
  end
end

# spec/models/person_spec.rb
require File.dirname(__FILE__) + '/../spec_helper'

context "A Person" do
  specify "should create reggie" do
    p = Person.new
    p.name = "reggie"
    p.save!
  end
end

# spec/controllers/test_controller.rb
require File.dirname(__FILE__) + '/../spec_helper'

context "the test app" do
  controller_name :test

  specify "should create reggie" do
    get 'new'
    response.body.should_match /created/
  end
end


----------------------------------------------------------------------

You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=3149&aid=6594&group_id=797


More information about the rspec-devel mailing list