我正在通過Mike Hartl的神話般的Rails教程(V3)的第9章。一切都順利進行,直到我嘗試爲users_index頁面設置集成測試。Rails(hartl教程)表用戶沒有列名爲
相關的文件,我所知道的:
users.yml裏
michael:
name: Michael Example
email: [email protected]
password_digest: <%= User.digest('password') %>
archer:
name: Sterling Archer
email: [email protected]
password_digest: <%= User.digest('password') %>
lana:
name: Lana Kane
email: [email protected]
password_digest: <%= User.digest('password') %>
mallory:
name: Mallory Archer
email: [email protected]
password_digest: <%= User.digest('password') %>
<% 30.times do |n| %>
user_<%= n %>:
name: <%= "User #{n}" %>
email: <%= "user-#{n}@example.com" %>
password_digest: <%= User.digest('password') %>
<% end %>
編輯:在users.yml裏那最後一塊肯定是涉及不知何故,當我刪除它測試的其餘部分通過很好......但我認爲它是與這個代碼交互的數據庫,我不確定如何去調試它。
users_index_test.rb:
require 'test_helper'
class UsersIndexTest < ActionDispatch::IntegrationTest
def setup
@user = users(:michael)
end
test "index including pagination" do
log_in_as(@user)
get users_path
assert_template 'users/index'
assert_select 'div.pagination'
User.paginate(page: 1).each do |user|
assert_select 'a[href=?]', user_path(user), text: user.name
end
end
end
據我所知,這些匹配的文本和參考實現,但是當我
bundle exec rake test
我得到的輸出,就像這對所有34個測試在套件:
ERROR["test_should_redirect_edit_when_not_logged_in" UsersControllerTest, 2015-09-02 14:05:27 +0000]
test_should_redirect_edit_when_not_logged_in#UsersControllerTest (1441202727.48s)
ActiveRecord::StatementInvalid: ActiveRecord::StatementInvalid: SQLite3::SQLException: table users has no column named user_0: INSERT INTO "users" ("name", "email", "password_digest", "user_0", "user_1", "user_2", "user_3", "user_4", "user_5", "user_6", "user_7", "user_8", "user_9", "user_10", "user_11", "user_12", "user_13", "user_14", "user_15", "user_16", "user_17", "user_18", "user_19", "user_20", "user_21", "user_22", "user_23", "user_24", "user_25", "user_26", "user_27", "user_28", "user_29", "created_at", "updated_at", "id") VALUES ('User 29', '[email protected]', '$2a$04$WuzW.yzF5SQELTCJdmvA2ubopDH0BA305WKiysdCI1pkzlCPv.v/.', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '2015-09-02 20:42:20', '2015-09-02 20:42:20', 785162917)
東西顯然是關閉的,但我沒有足夠的經驗與r以追蹤它。我發現的最接近的問題給出了類似的輸出(「SQLite3 :: SQLException:表用戶沒有列名......」),但我看到的解決方案通常涉及yaml間距與選項卡(我一定要檢查後,我在前面的教程中)。
你的yaml文件是否真的沒有縮進? –
它是,但使用空格,我明白在YAML中沒問題(當它僅僅是條目1和2時它當然沒問題)。 我只是試圖消除所有空白(行)之前,我得到不同的錯誤: 錯誤[ 「test_current_user_returns_nil_when_remember_digest_is_wrong」,SessionsHelperTest,2015年9月2日14時05分27秒+0000] test_current_user_returns_nil_when_remember_digest_is_wrong#SessionsHelperTest(1441202727.45 s) ActiveRecord :: Fixture :: FormatError:ActiveRecord :: Fixture :: FormatError:ActiveRecord :: Fixture :: FormatError - 對我而言,你說的是對的,比較現在的問題? – starseed