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 trialJoel David Crouse
9,062 PointsStrange bug I need helping solving - Editing Todo Lists
Alright,
Following along with the Editing Todo Lists vid, I am coming across a bug that doesn't appear in the tutorial.
In my index.html.erb template I have added a dom_id to each todo_list
<% @todo_lists.each do |todo_list| %>
<div class="todo_list_item" id="<%= dom_id(todo_list) %>">
<div class="todo_list_item_details">
<%= todo_list.title %>
<%= todo_list.description %>
</div>
<div class="todo_list_item_actions">
<%= link_to 'Show', todo_list %>
<%= link_to 'Edit', edit_todo_list_path(todo_list) %>
<%= link_to 'Destroy', todo_list, method: :delete, data: { confirm: 'Are you sure?' } %>
</div>
</div>
<hr />
<% end %>
...and then I test that it works
it "updates the todo list successfully with valid enteries" do
todo_list = TodoList.create(title: "Grocery List", description: "Groceries to buy today.")
within "#todo_list_#{todo_list.id}" do
click_link "Edit"
end
fill_in "Title", with: "Tuesday's Grocery List"
fill_in "Description", description: "Groceries to buy on Tuesday."
click_button "Update Todo list"
todo_list.reload
expect(page).to have_content("Todo list was successfully updated.")
expect(todo_list.title).to eq("Tuesday's Grocery List")
expect(todo_list.description).to eq("Groceries to buy on Tuesday.")
end
...but it doesn't. I am getting a strange failure that says
1) Editing todo lists updates the todo list successfully with valid enteries
Failure/Error: within "#todo_list_#{todo_list.id}" do
Capybara::ElementNotFound:
Unable to find css "#todo_list_1"
# ./spec/features/todo_lists/edit_spec.rb:7:in `block (2 levels) in <top (required)>'
Any thoughts?
2 Answers
Maciej Czuchnowski
36,441 PointsYou don't seem to command capybara to first visit the proper page, something like this:
visit "/todo_lists"
before the "within".
Daniel Cardenas
Courses Plus Student 9,236 PointsI made all the corrections stated in the post but still get the same error; Unable to find css "#todo_list_"
Here is the code i currently have, any thoughts?
require 'spec_helper'
describe "Editing todo lists" do it "updates a todo list successfully with correct information" do todo_list = TodoList.create(title: "Get Shit Done", description: "Cook")
visit "/todo_lists"
within "#todo_list_#{todo_list.id}" do
click_link "Edit"
end
fill_in "Title", with: "New title"
fill_in "Description", with: "New description"
click_button "Update Todo list"
expect(page).to have_content("Todo list was successfully updated")
expect(todo_list.title).to eq("New title")
expect(todo_list.description).to eq("New description")
end
end
Joel David Crouse
9,062 PointsJoel David Crouse
9,062 PointsYou're right, looks like I neglected to do just that. Also looks like a made another mistake:
fill_in "Description", description: "Groceries to buy on Tuesday."
should be
fill_in "Description", with: "Groceries to buy on Tuesday."
Thx again Maciej