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 Lists

My test on "Edit Todo_list" did not fail without the reloading database. Why?

I like to pause the video and guess at the code as Jason explains what it's going to do. I wrote my test without reloading the database and it passed immediately. Jason's failed because the page had the old title and description.

If I edit my expect(page) to expect the old text, it fails.

Also, why is the todo_list ID required if the database is wiped for each test? Wouldn't the edit page in the test environment only have a single list (the one i create in the test script?)

My code:

require 'spec_helper'

# Added to remove degradation error in rspec.
# Cab seems to be calling an obselete method.
RSpec.configure do |c|
c.expose_current_running_example_as :example
end


describe "Editing todo_lists" do

    it "updates a todo list successfully with correct information" do
        todo_list = TodoList.create(title: "Former Title", description: "This is the previous description.")


        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(page).to have_content("New title")
        expect(page).to have_content("New description")
    end 
end

1 Answer

Jason Seifer
STAFF
Jason Seifer
Treehouse Guest Teacher

Hey Chris Chambers you are correct about there being only one todo list in the database! The reason for the specification of the todo list id is in case we add another one, which is very common in applications. Your code above looks correct. The test will fail with the old information because when you call click_button "Update Todo list" the test will follow the redirect after the form submission.

Ok, just wanted to make sure I wasn't missing something. Thanks for the reply Jason!