0
我对在Rails中测试非常新。我正在尝试为我的相册控制器中的索引操作创建一个非常基本的测试。我收到一个错误,不是在这个测试中,而是在我所有的测试中。错误看起来是这样的:Rails测试错误
bin/rails test test/controllers/albums_controller_test.rb:18
E
Error:
AlbumsControllerTest#test_should_get_edit:
ActiveRecord::RecordNotUnique: SQLite3::ConstraintException: UNIQUE constraintfailed: users.email: INSERT INTO "users" ("created_at", "updated_at", "id") VALUES ('2017-01-11 21:54:05.906006', '2017-01-11 21:54:05.906006', 298486374)
我所有的测试中得到这个错误,不只是这一个。这是我试图用上面的例子中运行测试:
require 'test_helper'
class AlbumTest < ActiveSupport::TestCase
test "index action should work" do
get :index
assert_response :success
end
end
这里是我的专辑控制器中的索引操作:
def index
@albums = Album.all.order(year: :desc).order(title: :asc)
end
不知道发生了什么事情。帮助将不胜感激!
你可以用'albums_controller_test.rb'编辑代码 –