Commit ac1caed5

mo khan <mo@mokhan.ca>
2014-08-14 03:09:09
rename Session to UserSession.
1 parent c716f5d
app/controllers/application_controller.rb
@@ -7,7 +7,7 @@ class ApplicationController < ActionController::Base
   helper_method :current_user, :user_signed_in?
 
   def user_session(session_id = cookies.signed[:cookie_monster])
-    Session.find_by(id: session_id)
+    UserSession.find_by(id: session_id)
   end
 
   def current_user
app/controllers/sessions_controller.rb
@@ -1,10 +1,10 @@
 class SessionsController < ApplicationController
   def new
-    @session = Session.new
+    @session = UserSession.new
   end
 
   def create
-    if @session = Session.login(session_params[:username], session_params[:password])
+    if @session = UserSession.login(session_params[:username], session_params[:password])
       cookies.signed[:cookie_monster] = @session.id
       redirect_to my_dashboard_path
     else
app/models/session.rb → app/models/user_session.rb
@@ -1,4 +1,4 @@
-class Session < ActiveRecord::Base
+class UserSession < ActiveRecord::Base
   belongs_to :user
 
   class << self
db/migrate/20140814030250_rename_sessions_to_user_sessions.rb
@@ -0,0 +1,5 @@
+class RenameSessionsToUserSessions < ActiveRecord::Migration
+  def change
+    rename_table :sessions, :user_sessions
+  end
+end
db/schema.rb
@@ -11,7 +11,7 @@
 #
 # It's strongly recommended that you check this file into your version control system.
 
-ActiveRecord::Schema.define(version: 20140807003036) do
+ActiveRecord::Schema.define(version: 20140814030250) do
 
   # These are extensions that must be enabled in order to support this database
   enable_extension "plpgsql"
@@ -124,12 +124,6 @@ ActiveRecord::Schema.define(version: 20140807003036) do
 
   add_index "photos", ["creation_id"], name: "index_photos_on_creation_id", using: :btree
 
-  create_table "sessions", id: :uuid, default: "uuid_generate_v4()", force: true do |t|
-    t.integer  "user_id"
-    t.datetime "created_at"
-    t.datetime "updated_at"
-  end
-
   create_table "taggings", force: true do |t|
     t.integer  "tag_id"
     t.integer  "taggable_id"
@@ -164,6 +158,12 @@ ActiveRecord::Schema.define(version: 20140807003036) do
 
   add_index "tutorials", ["user_id"], name: "index_tutorials_on_user_id", using: :btree
 
+  create_table "user_sessions", id: :uuid, default: "uuid_generate_v4()", force: true do |t|
+    t.integer  "user_id"
+    t.datetime "created_at"
+    t.datetime "updated_at"
+  end
+
   create_table "users", force: true do |t|
     t.string   "email",                              default: "", null: false
     t.string   "encrypted_password",     limit: 128, default: "", null: false
spec/controllers/sessions_controller_spec.rb
@@ -11,12 +11,12 @@ describe SessionsController do
 
   describe "#create" do
     context "when the username and password is correct" do
-      let(:user_session) { build(:session, id: SecureRandom.uuid) }
+      let(:user_session) { build(:user_session, id: SecureRandom.uuid) }
       let(:username) { "joe" }
       let(:password) { "password" }
 
       before :each do
-        Session.stub(:login).with(username, password).and_return(user_session)
+        UserSession.stub(:login).with(username, password).and_return(user_session)
         post :create, session: { username: username, password: password }
       end
 
@@ -32,7 +32,7 @@ describe SessionsController do
 
     context "when the username is not known" do
       before :each do
-        Session.stub(:login).and_return(nil)
+        UserSession.stub(:login).and_return(nil)
       end
 
       it "returns an error" do
spec/models/session_spec.rb → spec/models/user_session_spec.rb
@@ -1,10 +1,10 @@
 require "rails_helper"
 
-describe Session do
+describe UserSession do
   describe ".login" do
     context "when the email is not known" do
       it "returns false" do
-        expect(Session.login('blah@example.com', 'password')).to be_falsey
+        expect(UserSession.login('blah@example.com', 'password')).to be_falsey
       end
     end
 
@@ -18,13 +18,13 @@ describe Session do
 
       context "when the password is incorrect" do
         it "returns false" do
-          expect(Session.login(user.email, 'blah')).to be_falsey
+          expect(UserSession.login(user.email, 'blah')).to be_falsey
         end
       end
 
       context "when the password is correct" do
         it "returns a new session" do
-          result = Session.login(user.email, 'password')
+          result = UserSession.login(user.email, 'password')
           expect(result).to be_truthy
           expect(result).to_not be_new_record
           expect(result.user).to eql(user)
spec/support/devise_helper.rb
@@ -1,7 +1,7 @@
 module DeviseHelper
   module Controllers
     def http_login(user)
-      new_session = Session.new
+      new_session = UserSession.new
       controller.stub(:authenticate!).and_return(new_session)
       controller.stub(:current_user).and_return(user)
     end
spec/factories.rb
@@ -21,7 +21,7 @@ FactoryGirl.define do
     association :category
   end
 
-  factory :session, class: Session do
+  factory :user_session, class: UserSession do
   end
 
   factory :favorite do