← Back to Upcase

I am getting a strange error in my TDD Rails Workshop that I can't figure out

(Philip Bradley) #1

At about the 12.5 minute mark into the 3rd “lesson” on unit testing, we are told to run specs for the manage_todos_spec.rb and that they should be working.

This is right after changing this code on line 14. below. Strangely, I’m getting an odd error when I run the tests for manage_todos_spec.rb. I’ve compared my code to others who are slightly further along and can’t find what is different.

Any ideas?


                        |~                                                                                                                                                                     1 class TodosController < ApplicationController                                                                                                                                                                                                                                                                                                                             2                                                                                                                                                                                                                                                                                                                                                                           3   def index                                                                                                                                                                                                                                                                                                                                                               4     #@todos = Todo.all                                                                                                                                                                                                                                                                                                                                                    5     @todos = current_user.todos                                                                                                                                                                                                                                                                                                                                           6   end                                                                                                                                                                                                                                                                                                                                                                     7                                                                                                                                                                                                                                                                                                                                                                           8   def new                                                                                                                                                                                                                                                                                                                                                                 9     @todo = Todo.new                                                                                                                                                                                                                                                                                                                                                     10   end                                                                                                                                                                                                                                                                                                                                                                    11                                                                                                                                                                                                                                                                                                                                                                          12   def create                                                                                                                                                                                                                                                                                                                                                             13     @todo = Todo.new(params[:todo])                                                                                                                                                                                                                                                                                                                                      14     @todo.user = current_user                                                                                                                                                                                                                                                                                                                                          15     @todo.save                                                                                                                                                                                                                                                                                                                                                           16     redirect_to todos_path                                                                                                                                                                                                                                                                                                                                               17                                                                                                                                                                                                                                                                                                                                                                          18   end                                                                                                                                                                                                                                                                                                                                                                    19                                                                                                                                                                                                                                                                                                                                                                          20 end


  1. Manage todos create a new todo
    Failure/Error: sign_in
    SQLite3::SQLException: no such column: owner_email.current_email: SELECT “todos”.* FROM “todos” WHERE
    "owner_email".“current_email” = ‘person@example.com’ AND
    "owner_email".“todos” IN (NULL)

    ./app/views/todos/index.html.haml:2:in `_app_views_todos_index_html_haml__2802188835747511554_70281750326360’

    (eval):2:in `click_button’

    ./spec/support/sign_in_helpers.rb:10:in `sign_in_as’

    ./spec/support/sign_in_helpers.rb:4:in `sign_in’

    ./spec/integration/manage_todos_spec.rb:5:in `block (2 levels) in <top (required)>’

  2. Manage todos view only my todos
    Failure/Error: sign_in_as 'me@example.com’
    SQLite3::SQLException: no such column: owner_email.current_email: SELECT “todos”.* FROM “todos” WHERE
    "owner_email".“current_email” = ‘me@example.com’ AND
    "owner_email".“todos” IN (1)

    ./app/views/todos/index.html.haml:2:in `_app_views_todos_index_html_haml__2802188835747511554_70281750326360’

    (eval):2:in `click_button’

    ./spec/support/sign_in_helpers.rb:10:in `sign_in_as’

    ./spec/integration/manage_todos_spec.rb:15:in `block (2 levels) in <top (required)>’

Finished in 0.24281 seconds 2 examples, 2 failures

Failed examples:

rspec ./spec/integration/manage_todos_spec.rb:4 # Manage todos create
a new todo rspec ./spec/integration/manage_todos_spec.rb:13 # Manage
todos view only my todos

Randomized with seed 48209

(Ben Orenstein) #2

Looks like your test database is missing that column.

Have you prepared your test database with rake db:test:prepare after running the migrations?

(Philip Bradley) #3

I have indeed, sir. :smile:

rake db:migrate; rake db:test:prepare

I’ve opened up the console and created a user with an email address, and some todos with that email, and I can do fake_user.todos in the console without any trouble.

I’m mystified. Why in the error does it say "no such column ‘owner_email.current_email’. I’m new at deciphering this kind of thing. The way the lesson is set up, Todo is a model with a corresponding table in the db, with only two columns: description and owner_email.

sigh. I know this is hard to figure out via forum posts. I’ve spent 90m on it and I can put in some more. Frustrating b/c I was cruising through that lesson like Thelma and Louise.

(Lee Smith) #4

Looking at the SQL:

SELECT "todos".* FROM "todos" WHERE "owner_email"."current_email" = 'person@example.com' AND "owner_email"."todos" IN (NULL)

There is no join from the owner_emails table.

But it could be your not adding the user correctly.

@todo.user_id = current_user.id

Or maybe it should be

  @todo = Todo.new(params[:todo])
  @todo.user << current_user

Need to know more about your model relationships to give more help.


(Philip Bradley) #5

class Todo < ActiveRecord::Base
attr_accessible :description, :owner_email


class User
attr_reader :email

def initialize(email)
@email = email

def todos
Todo.where(owner_email: email)


What else might help out?

(Philip Bradley) #6

I found it; it was a small change in the application controller. thanks for the attention, though.



(Chris Bradley) #7


Do you remember what you changed? I’m having the exact same issue and can’t figure it out.


(Philip Bradley) #8

Chris I just went through to see if I had the project with its commit history, and I don’t. So sad.

That was a loser move on my part to not be specific in my post above. Sorry about that.

Here is an application controller from a todo app that I had; I’m not 100% sure it is the same one I was using doing the tutorial but you might compare it to what you have and see if anything jumps out at you:

class ApplicationController < ActionController::Base
     def sign_in_as(email)
       session[:current_email] = email
     def current_user
    helper_method :current_user


(Chris Bradley) #9

That’s what I have. Oh well…thanks for taking a look.

(Chris Bradley) #10

Oops, I should have copied and pasted what you sent. I had

def current_user

Notice the":" after session which is wrong. Anyway, that’s the difference. Thank you very much!