Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Michael Hartl's Rails tutorial chapter 12-- all 54 tests failed...?

So I'm at Michael Hartl's Rails Tutorial, chapter 12, listing 12.7.

I've written a few tests as followed by the book, but all 54 tests ended up with errors. The first few are:

ERROR["test_should_require_a_followed_id", RelationshipTest, 0.686335129]
 test_should_require_a_followed_id#RelationshipTest (0.69s)
ActiveRecord::RecordNotUnique:         ActiveRecord::RecordNotUnique: SQLite3::ConstraintException: UNIQUE constraint failed: relationships.follower_id, relationships.followed_id: INSERT INTO "relationships" ("follower_id", "followed_id", "created_at", "updated_at", "id") VALUES (1, 1, '2015-03-10 16:12:17', '2015-03-10 16:12:17', 298486374)


ERROR["test_should_be_valid", RelationshipTest, 0.835273632]
 test_should_be_valid#RelationshipTest (0.84s)
ActiveRecord::RecordNotUnique:         ActiveRecord::RecordNotUnique: SQLite3::ConstraintException: UNIQUE constraint failed: relationships.follower_id, relationships.followed_id: INSERT INTO "relationships" ("follower_id", "followed_id", "created_at", "updated_at", "id") VALUES (1, 1, '2015-03-10 16:12:17', '2015-03-10 16:12:17', 298486374)


ERROR["test_should_require_a_follower_id", RelationshipTest, 0.988648702]
 test_should_require_a_follower_id#RelationshipTest (0.99s)
ActiveRecord::RecordNotUnique:         ActiveRecord::RecordNotUnique: SQLite3::ConstraintException: UNIQUE constraint failed: relationships.follower_id, relationships.followed_id: INSERT INTO "relationships" ("follower_id", "followed_id", "created_at", "updated_at", "id") VALUES (1, 1, '2015-03-10 16:12:18', '2015-03-10 16:12:18', 298486374)


ERROR["test_password_resets", PasswordResetsTest, 1.071410052]
 test_password_resets#PasswordResetsTest (1.07s)
ActiveRecord::RecordNotUnique:         ActiveRecord::RecordNotUnique: SQLite3::ConstraintException: UNIQUE constraint failed: relationships.follower_id, relationships.followed_id: INSERT INTO "relationships" ("follower_id", "followed_id", "created_at", "updated_at", "id") VALUES (1, 1, '2015-03-10 16:12:18', '2015-03-10 16:12:18', 298486374)

and continues...

Here is my relationship_test.rb:

require 'test_helper'

class RelationshipTest < ActiveSupport::TestCase

  def setup
    @relationship = Relationship.new(follower_id: 1, followed_id: 2)
  end

  test "should be valid" do
    assert @relationship.valid?
  end

  test "should require a follower_id" do
    @relationship.follower_id = nil
    assert_not @relationship.valid?
  end

  test "should require a followed_id" do
    @relationship.followed_id = nil
    assert_not @relationship.valid?
  end
end

I have a suspicion that something may be wrong in relationship_test.rb, but I don't even know where to start with all these errors. Could someone point me in the right direction? Thank you.

like image 704
nyphur Avatar asked Feb 10 '23 17:02

nyphur


1 Answers

I've solved it.

My relationships.yml had:

one:
   follower_id: 1
   followed_id: 1

 two:
   follower_id: 1
   followed_id: 1

which was causing the tests to fail. I've commented them out and there were 0 errors, but one failure.

like image 143
nyphur Avatar answered Feb 13 '23 17:02

nyphur