Commit 23832710
Changed files (6)
app
controllers
api
models
db
spec
controllers
features
app/controllers/api/v1/logins_controller.rb
@@ -3,7 +3,7 @@ module Api
class LoginsController < ApplicationController
def create
@user = User.find_by_email(params[:email])
- if @user.valid_password?(params[:password])
+ if @user.authenticate(params[:password])
render json: { auth_token: @user.authentication_token }
else
render json: { auth_token: "" }
app/models/user.rb
@@ -1,5 +1,3 @@
-require 'bcrypt'
-
class User < ActiveRecord::Base
has_secure_password
before_save :ensure_authentication_token
db/schema.rb
@@ -31,8 +31,8 @@ ActiveRecord::Schema.define(version: 20141016000307) do
create_table "avatars", force: true do |t|
t.integer "user_id"
- t.datetime "created_at"
- t.datetime "updated_at"
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
t.string "avatar"
t.boolean "avatar_processing"
t.string "avatar_tmp"
@@ -85,8 +85,8 @@ ActiveRecord::Schema.define(version: 20141016000307) do
t.datetime "failed_at"
t.string "locked_by"
t.string "queue"
- t.datetime "created_at"
- t.datetime "updated_at"
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
end
add_index "delayed_jobs", ["priority", "run_at"], name: "delayed_jobs_priority", using: :btree
@@ -103,8 +103,8 @@ ActiveRecord::Schema.define(version: 20141016000307) do
create_table "interests", force: true do |t|
t.string "name"
- t.datetime "created_at"
- t.datetime "updated_at"
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
end
create_table "locations", id: :uuid, default: "uuid_generate_v4()", force: true do |t|
@@ -157,15 +157,13 @@ ActiveRecord::Schema.define(version: 20141016000307) do
t.integer "taggings_count", default: 0
end
- add_index "tags", ["name"], name: "index_tags_on_name", unique: true, using: :btree
-
create_table "tutorials", force: true do |t|
t.string "heading"
t.text "description"
t.string "url"
t.integer "user_id"
- t.datetime "created_at"
- t.datetime "updated_at"
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
t.string "image_url"
t.string "author"
t.string "author_url"
@@ -190,8 +188,8 @@ ActiveRecord::Schema.define(version: 20141016000307) do
add_index "user_sessions", ["user_id"], name: "index_user_sessions_on_user_id", using: :btree
create_table "users", force: true do |t|
- t.string "email", default: "", null: false
- t.string "password_digest", default: "", null: false
+ t.string "email", default: "", null: false
+ t.string "password_digest", limit: 128, default: "", null: false
t.string "reset_password_token"
t.datetime "reset_password_sent_at"
t.datetime "created_at"
@@ -203,7 +201,7 @@ ActiveRecord::Schema.define(version: 20141016000307) do
t.string "city"
t.string "authentication_token"
t.string "full_address"
- t.integer "creations_count", default: 0
+ t.integer "creations_count", default: 0
t.boolean "admin"
end
spec/controllers/api/v1/logins_controller_spec.rb
@@ -5,18 +5,18 @@ describe Api::V1::LoginsController do
let(:user) { create(:user) }
it "should return the auth token" do
- post :create, { :email => user.email, :password => 'password' }
- response.body.should == { auth_token: user.authentication_token }.to_json
+ post :create, { email: user.email, password: 'password' }
+ expect(response.body).to eql({ auth_token: user.authentication_token }.to_json)
end
end
context "when logging in with invalid credentials" do
let(:user) { create(:user) }
- before { post :create, { :email => user.email, :password => user.password.reverse } }
+ before { post :create, { email: user.email, password: user.password.reverse } }
it "should return an empty auth token" do
- response.body.should == { :auth_token => "" }.to_json
+ expect(response.body).to eql({ :auth_token => "" }.to_json)
end
end
end
spec/controllers/my/passwords_controller_spec.rb
@@ -32,11 +32,11 @@ describe My::PasswordsController do
let(:new_password) { 'booyakasham' }
before :each do
- put :update, :id => user.id, :user => { :password => new_password, :password_confirmation => new_password }
+ put :update, id: user.id, user: { password: new_password, password_confirmation: new_password }
end
it "should update the users password" do
- user.reload.valid_password?(new_password).should be_truthy
+ expect(user.reload.authenticate(new_password)).to be_truthy
end
end
end
spec/features/add_to_favorites_spec.rb
@@ -17,6 +17,6 @@ describe "adding a cake to your favorites", :js => true do
end
it "should redirect you to the cake after" do
- page.should have_content("Welcome to the fanclub!")
+ expect(page).to have_content("Welcome to the fanclub!")
end
end