deletes Manager
This commit is contained in:
committed by
Juanjo Bazán
parent
855763267f
commit
df14e979ca
@@ -1,12 +0,0 @@
|
||||
class Manager < ActiveRecord::Base
|
||||
validates :username, presence: true, uniqueness: true
|
||||
validates :password_digest, presence: true
|
||||
|
||||
has_secure_password
|
||||
|
||||
def self.valid_manager(username = nil, password = nil)
|
||||
return false unless username.present? && password.present?
|
||||
Manager.find_by(username: username).try(:authenticate, password)
|
||||
end
|
||||
|
||||
end
|
||||
16
db/migrate/20151015135154_destroy_manager.rb
Normal file
16
db/migrate/20151015135154_destroy_manager.rb
Normal file
@@ -0,0 +1,16 @@
|
||||
class DestroyManager < ActiveRecord::Migration
|
||||
def self.up
|
||||
drop_table :managers
|
||||
end
|
||||
|
||||
def self.down
|
||||
create_table :managers do |t|
|
||||
t.string :username, null: false
|
||||
t.string :password_digest, null: false
|
||||
t.timestamp :last_login_at
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
add_index :managers, [:username]
|
||||
end
|
||||
end
|
||||
12
db/schema.rb
12
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: 20151013145757) do
|
||||
ActiveRecord::Schema.define(version: 20151015135154) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
@@ -168,16 +168,6 @@ ActiveRecord::Schema.define(version: 20151013145757) do
|
||||
|
||||
add_index "locks", ["user_id"], name: "index_locks_on_user_id", using: :btree
|
||||
|
||||
create_table "managers", force: :cascade do |t|
|
||||
t.string "username", null: false
|
||||
t.string "password_digest", null: false
|
||||
t.datetime "last_login_at"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
end
|
||||
|
||||
add_index "managers", ["username"], name: "index_managers_on_username", using: :btree
|
||||
|
||||
create_table "moderators", force: :cascade do |t|
|
||||
t.integer "user_id"
|
||||
end
|
||||
|
||||
@@ -1,46 +0,0 @@
|
||||
require 'rails_helper'
|
||||
|
||||
describe Manager do
|
||||
|
||||
describe "valid?" do
|
||||
|
||||
let(:manager) { create(:manager) }
|
||||
|
||||
it "is false when username is blank" do
|
||||
manager.username = nil
|
||||
expect(manager).to_not be_valid
|
||||
end
|
||||
it "is false when password is blank" do
|
||||
manager.password_digest = nil
|
||||
expect(manager).to_not be_valid
|
||||
end
|
||||
|
||||
it "is true if username and password present" do
|
||||
expect(manager).to be_valid
|
||||
end
|
||||
end
|
||||
|
||||
describe "self.valid_manager" do
|
||||
before(:all) { create(:manager, username: "Silvia" ,password: "supersecret") }
|
||||
|
||||
it "is false when username is blank" do
|
||||
expect(Manager.valid_manager(nil, "supersecret")).to be_blank
|
||||
end
|
||||
it "is false when password is blank" do
|
||||
expect(Manager.valid_manager("Silvia", nil)).to be_blank
|
||||
end
|
||||
|
||||
it "is false if manager unexistent" do
|
||||
expect(Manager.valid_manager("Manager", "supersecret")).to be_blank
|
||||
end
|
||||
|
||||
it "is false if wrong password unexistent" do
|
||||
expect(Manager.valid_manager("Silvia", "wrong")).to be_blank
|
||||
end
|
||||
|
||||
it "is true if right username/password combination" do
|
||||
expect(Manager.valid_manager("Silvia", "supersecret")).to be_present
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user