← Back to Upcase

Refactor to User Model

(Upcase ) #1

This is a companion discussion topic for the original entry at https://thoughtbot.com/upcase/videos/refactor-to-user-model

(Gonzalo Quero) #2

Shouldn’t we be unit testing the new User model before writing it? If we’re doing TDD, it feels a bit wrong to use only the features to test this.

(Hunter Stevens) #3

Is there a reason why we don’t create a User model with has_many :todos?

I mean, doing that would require more steps:

  • Create a User migration with email:string and has_many :todos
  • Create a Todo migration that removes email and adds a reference to user
    • For production, we would first run a task that creates users/associations based on emails currently stored in todos.
  • We can still look for session[:current_email], but we can change that to session[:user_id], since we need to locate a User record on session create.

I guess using a Ruby class is the most minimal code required to get the tests to pass, and offering the minimal amount of changes. Could that be the reason then?