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'編輯代碼 –