2016-02-20 42 views
0

「突然間」我得到這個錯誤,我找不出原因。RoR Minitest賽程:「找不到'id'= 5025348」/如何「測試」賽程?

  • 也許你看到的問題,或者...
  • 有沒有一種方法來「測試」的燈具?

ERROR [ 「test_should_redirect_create_when_not_logged_in」(...) ActiveRecord的:: RecordNotFound:6::無法與 'ID'= 415950658 測試/控制器/ text_posts_controller_test.rb發現在後`設置」

測試/控制器/ text_posts_controller_test.rb

require 'test_helper' 

class TextPostsControllerTest < ActionController::TestCase 

    # HERE IS THE PROBLEM @post 
    def setup 
    @post = posts(:text_post_archer) 
    end 

    # This test works fine 
    test "should redirect create when not logged in" do 
    assert_no_difference 'Post.count' do 
     post :create, text_post: { title: "Lorem ipsum", 
           body: "body", 
           type: "TextPost" } 
    end 
    assert_redirected_to login_url 
    end 

    test "should redirect destroy when not logged in" do 
    assert_no_difference 'Post.count' do 
     delete :destroy, id: @post 
    end 
    assert_redirected_to login_url 
    end 

(...) 
end 

個燈具:posts.yml

text_post: 
    title: "Title One" 
    body: "Body One" 
    type: TextPost 
    user: michael 
    created_at: <%= 10.minutes.ago %> 

text_post_archer: 
    title: "Title Two" 
    body: "Body Two" 
    type: TextPost 
    user: archer 
    created_at: <%= 10.minutes.ago %> 

image_post: 
    title: "Title Two" 
    url: "http://i.imgur.com/Y7syDEa.jpg" 
    type: ImagePost 
    user: archer 
    created_at: <%= 3.years.ago %> 

燈具:users.yml裏

michael: 
    name: Michael 
    email: [email protected] 
    password_digest: <%= User.digest('password') %> 
    admin: true 
    activated: true 
    activated_at: <%= Time.zone.now %> 

archer: 
    name: Sterling 
    email: [email protected] 
    password_digest: <%= User.digest('password') %> 
    activated: true 
    activated_at: <%= Time.zone.now %> 

schema.rb

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

    (...) 

    create_table "posts", force: :cascade do |t| 
    t.string "title" 
    t.text  "body" 
    t.string "url" 
    t.string "type" 
    t.integer "user_id" 
    t.datetime "created_at",     null: false 
    t.datetime "updated_at",     null: false 
    t.integer "comments_count", default: 0, null: false 
    t.string "picture" 
    end 

    add_index "posts", ["user_id", "created_at"], name: "index_posts_on_user_id_and_created_at" 
    add_index "posts", ["user_id"], name: "index_posts_on_user_id" 

    (...) 

    create_table "users", force: :cascade do |t| 
    t.string "name" 
    t.string "email" 
    t.datetime "created_at",      null: false 
    t.datetime "updated_at",      null: false 
    t.string "password_digest" 
    t.string "remember_digest" 
    t.boolean "admin",    default: false 
    t.string "activation_digest" 
    t.boolean "activated",   default: false 
    t.datetime "activated_at" 
    t.string "reset_digest" 
    t.datetime "reset_sent_at" 
    end 

    add_index "users", ["email"], name: "index_users_on_email", unique: true 

end 

text_post.rb:TextPost模型繼承郵政

class TextPost < Post 
     validates :body, presence: true, 
        length: { maximum: 12700 } 
end 

回答

0

它現在有效。我做了重置和一個新的種子。

耙分貝:遷移:復位

耙分貝:種子