2017-01-01 78 views
0

我之前沒有使用過Devise。我的網站只是bootstrap,HTML,樣式和一些靜態頁面。我是using this Gemfile我所有的測試都通過了,直到我跑rake db:migrate。我按照這個順序運行這些步驟。將Devise Gem添加到新的Rails項目中創建測試用戶錯誤

  • add gem 'devise',運行bundle install。 (測試綠色)
  • 運行rails generate devise:install,加入閃光燈的通知(測試綠色)
  • 添加action_mailer默認線,以每文檔(測試綠色)
  • 運行rails generate devise user(測試慣於由於未決遷移運行開發,測試和生產ENV )
  • 檢查每個文檔的新模型,但沒有更改默認值。
  • 運行rails db:migrate(測試紅色)運行此創建一個test.sqlite3文件在我的數據庫文件夾

我現在收到此錯誤:

ActiveRecord::RecordNotUnique: ActiveRecord::RecordNotUnique: SQLite3::ConstraintException: UNIQUE constraint failed: users.email: INSERT INTO "users" ("created_at", "updated_at", "id") VALUES ('2017-01-01 22:14:19.589023', '2017-01-01 22:14:19.589023', 298486374)

在我所有的試驗。這是奇怪的,因爲我還沒有創建任何測試,除了檢查,如果HTML元素存在和鏈接工作,但仍然做任何測試...

似乎爲了通過uniquiness約束我需要一個用戶,但我沒有創建任何。它也與SQLite有關。我怎麼能通過這個測試通過,在當前點Devise。我基本上使用Hartl教程作爲指導。我記得我們有一個創建假用戶的步驟,但這不是那一刻的目的?

require 'test_helper' 

class StaticPagesControllerTest < ActionDispatch::IntegrationTest 

    def setup 
    @title = "FFP" 
    end 

    test "should get root" do 
    get root_url 
    assert_response :success 
    assert_select "title", @title 
    end 
end  

這是我的Schema目前。

ActiveRecord::Schema.define(version: 20170101224251) do 

    create_table "users", force: :cascade do |t| 
    t.string "email",     default: "", null: false 
    t.string "encrypted_password",  default: "", null: false 
    t.string "reset_password_token" 
    t.datetime "reset_password_sent_at" 
    t.datetime "remember_created_at" 
    t.integer "sign_in_count",   default: 0, null: false 
    t.datetime "current_sign_in_at" 
    t.datetime "last_sign_in_at" 
    t.string "current_sign_in_ip" 
    t.string "last_sign_in_ip" 
    t.datetime "created_at",       null: false 
    t.datetime "updated_at",       null: false 
    t.string "provider" 
    t.string "uid" 
    t.index ["email"], name: "index_users_on_email", unique: true 
    t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true 
    end 

end 
+0

聽起來你已經在user.email字段中有兩個值是重複的,請刪除其中一個違規值並重試。 –

+0

當您嘗試向已具有重複值的現有列添加唯一約束時,或者您嘗試將值插入已具有該值的字段時,會發生此錯誤。 –

+1

設計添加user.email的唯一性。我想在某個地方你嘗試創建一個沒有電子郵件地址的用戶。 – tomtomtom

回答

相關問題