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 Write Our First Tests

Andreaus Perkins
Andreaus Perkins
14,402 Points

Can someone explain the difference between TodoList and todo_list, when you're trying to verify the existence of titles?

Can someone explain why we're using TodoList and not todo_list (or todo_lists)?

it "displays an error when the todo list has no title" do
        expect(TodoList.count).to eq(0)

Any help is appreciated.

6 Answers

Roberto Alicata
PLUS
Roberto Alicata
Courses Plus Student 39,959 Points

TodoList is the the name of the Model ( that inherits from ActiveRecord::Base ).

Roberto Alicata
PLUS
Roberto Alicata
Courses Plus Student 39,959 Points

The Test starts expecting there are no Todo List checking TodoList.count.

Then it continue trying to add a new Todo list but without a title, so we want it returns an error and the TodoList.count still be 0. In fact, if the todolist does not have a title no records are saved in the database.

Andreaus Perkins
Andreaus Perkins
14,402 Points

So why are we using "TodoList" instead of "todo_list"? I'm still confused. The app is named "odot", so I'm not sure where TodoList came from.

Andreaus Perkins
Andreaus Perkins
14,402 Points

So "TodoList.count" is checking the entire class for an entry?

Roberto Alicata
PLUS
Roberto Alicata
Courses Plus Student 39,959 Points

Yes it checks the TodoList table on the database. The TodoList is the class name for your model that was created when you wrote the command "rails generate scaffold todo_list ...." in the app/models/todo_list.rb

Thanks from me, too! Great answer.