Spa*_*000 4 ruby ruby-on-rails ruby-on-rails-3 railstutorial.org ruby-on-rails-4
所以我参加了Michael Hartl的Rails教程,第12章,列出了12.7.
我已经写了一些测试,但是所有的54个测试最终都出现了错误.前几个是:
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)
Run Code Online (Sandbox Code Playgroud)
继续......
这是我的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
Run Code Online (Sandbox Code Playgroud)
我怀疑在relationship_test.rb中可能有什么问题,但我甚至不知道从哪里开始所有这些错误.有人能指出我正确的方向吗?谢谢.
我已经解决了.
我relationships.yml有:
one:
follower_id: 1
followed_id: 1
two:
follower_id: 1
followed_id: 1
Run Code Online (Sandbox Code Playgroud)
这导致测试失败.我已将它们评论出来,并且有0个错误,但有一个失败.
| 归档时间: |
|
| 查看次数: |
836 次 |
| 最近记录: |