Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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