views:

103

answers:

0

I wrote some tests for a several models and controllers of a Rails application using Shoulda macros, but one after another they each fail with the error

ActiveRecord::StatementInvalid: Mysql::Error: Duplicate entry '1' for key 1: INSERT INTO `replies` (`created_at`, `from_user`, `updated_at`, `read`, `text`, `tweeted_at`, `id`, `user_id`, `lead_id`) VALUES ('2010-02-18 09:36:12', 'MyString', '2010-02-18 09:36:12', 0, 'MyString', '2010-01-29 06:55:11', 1, 1, 1)

Replies belong to leads which belong to keywords (has_many), but I'm not even sure why Shoulda is attempting to create a reply for most of these tests (such as Keyword should_allow_values_for :radius, '25mi', '100km').

So there must be some implicit setup going on that's trying to create a whole environment for each test? And not doing very well at it, eh?

I'm not using any fixtures or anything like that (factory_girl is installed, but unused). Can anyone explain what's going on here?

Update:

Here's my test_helper.rb

ENV["RAILS_ENV"] = "test"
require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
require 'test_help'
require 'authlogic/test_case'

FakeWeb.allow_net_connect = false
Webrat.configure do |config|
  config.application_environment = :test
  config.mode = :rails
  config.open_error_files = false
end

class ActiveSupport::TestCase
  self.use_transactional_fixtures = true
  self.use_instantiated_fixtures  = false
  fixtures :all    
end

class ActionController::TestCase
  setup :activate_authlogic
end

and here's one of the unit tests (the first to run)

require 'test_helper'
class KeywordTest < ActiveSupport::TestCase
  should_belong_to :user
  should_have_many :leads
  should_allow_values_for :radius, '25mi', '100km'
  should_not_allow_values_for :radius, '25', 'mi', 'km'
  should_ensure_length_in_range :text, 0..30
end

Nothing fancy... I don't know where the reply is being created...