Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Ruby Build a Todo List Application with Rails 4 Build a Todo List Application with Rails 4 Deleting Todo Items

melrcm
melrcm
5,084 Points

Fails: InvalidAuthenticityToken in TodoItemsController#destroy ActionController::InvalidAuthenticityToken

delete_spec.rb output:

Failures:

  1) Deleting todo items is successful deleting
     Failure/Error: expect(page).to have_content("Todo list item was deleted")
       expected to find text "Todo list item was deleted" in "ActionController::InvalidAuthenticityToken in TodoItemsController#destroy ActionController::InvalidAuthenticityToken Rails.root: /Build To-do/odot Application Trace | Framework Trace | Full Trace Request Parameters: {\"todo_list_id\"=>\"5\", \"id\"=>\"9\"} Toggle session dump Toggle env dump Response Headers: None"
     # ./spec/features/todo_items/delete_spec.rb:20:in `block (2 levels) in <top (required)>'

Finished in 0.55339 seconds (files took 11.64 seconds to load)
1 example, 1 failure

Failed examples:

rspec ./spec/features/todo_items/delete_spec.rb:15 # Deleting todo items is successful deleting

delete_spec.rb:

require 'rails_helper'

describe "Deleting todo items" do
    let!(:todo_list) { TodoList.create(title: "Grocery list", description: "Groceries")}
    let!(:todo_item) { todo_list.todo_items.create(content: "Milk") }

    def visit_todo_list(list)
        visit "/todo_lists"
        within "#todo_list_#{list.id}" do
            click_link "List Items"
        end
    end

    it "is successful deleting" do
        visit_todo_list(todo_list)
        within("#todo_item_#{todo_item.id}") do
            click_link "Delete"
        end
        expect(page).to have_content("Todo list item was deleted")
        expect(TodoItem.count).to eq(0)
    end 

end