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 Editing Todo Items

My tests keep failing.

this is my index.html.erb

<h1><%= @todo_list.title %></h1>

<ul class="todo_items"> <% @todo_list.todo_items.each do |todo_item| %> <li id="<%= dom_id(todo_item) %>"> <%= todo_item.content %> <%= link_to "Edit", edit_todo_list_todo_item_path(todo_item) %> </li> <% end %> </ul>

<p> <%= link_to "New Todo Item", new_toto_list_todo_item_path %> </p>

this is my edit spec.rb

require 'spec_helper'

describe "Editing 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 with valid content" do
    visit_todo_list(todo_list)
    within("#todo_item_#{todo_item.id}") do
        click_link "Edit"
end
fill_in "Content", with: "Lots of Milk"
click_button "Save"
expect(page).to have_content("Saved todo list item.")
todo_item.reload
expect(todo_item.content).to eq("Lots of Milk")

end

it "is unsuccessful with no content" do visit_todo_list(todo_list) within("#todo_item_#{todo_item.id}") do click_link "Edit" end fill_in "Content", with: "" click_button "Save" expect(page).to_not have_content("Saved todo list item.") expect(page).to have_content("Content can't be blank.") todo_item.reload expect(todo_item.content).to eq("Milk") end

it "is unsuccessful with not enough content" do visit_todo_list(todo_list) within("#todo_item_#{todo_item.id}") do click_link "Edit" end fill_in "Content", with: "" click_button "Save" expect(page).to_not have_content("Saved todo list item.") expect(page).to have_content("Content is too short.") todo_item.reload expect(todo_item.content).to eq("Milk") end

end

1 Answer

This is a dom selector: "#todo_item_#{todo_item.id}" and it is not present in your index

<tbody> <% @todo_lists.each do |todo_list| %> <tr id="<%= dom_id(todo_list) %>"> <td><%= todo_list.title %></td> <td><%= todo_list.description %></td> <td><%= link_to 'Show', todo_list %></td> <td><%= link_to 'Edit', edit_todo_list_path(todo_list) %></td> <td><%= link_to 'Destroy', todo_list, method: :delete, data: { confirm: 'Are you sure?' } %></td> </tr> <% end %> </tbody>

This might help