-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
160 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
class User < ActiveRecord::Base | ||
has_secure_password | ||
|
||
validates :first_name, presence: true | ||
validates :last_name, presence: true | ||
validates :email, presence: true | ||
validates :city, presence: true | ||
validates :state, presence: true | ||
validates :country, presence: true | ||
validates :password, length: { minimum: 8 } | ||
validates :email, format: { | ||
with: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i, on: :create | ||
} | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
class CreateUsers < ActiveRecord::Migration | ||
def change | ||
create_table :users do |t| | ||
t.string :name | ||
t.string :email | ||
t.string :password_digest | ||
t.boolean :email_confirmed | ||
t.string :confirm_digest | ||
t.string :reset_digest | ||
t.datetime :reset_sent_at | ||
|
||
t.timestamps null: false | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class RenameUserNameToFirstName < ActiveRecord::Migration | ||
def change | ||
rename_column :users, :name, :first_name | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class AddLastNameToUser < ActiveRecord::Migration | ||
def change | ||
add_column :users, :last_name, :string | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class AddCityToUser < ActiveRecord::Migration | ||
def change | ||
add_column :users, :city, :string | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class AddStateToUser < ActiveRecord::Migration | ||
def change | ||
add_column :users, :state, :string | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class AddCountryToUser < ActiveRecord::Migration | ||
def change | ||
add_column :users, :country, :string | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# encoding: UTF-8 | ||
# This file is auto-generated from the current state of the database. Instead | ||
# of editing this file, please use the migrations feature of Active Record to | ||
# incrementally modify your database, and then regenerate this schema definition. | ||
# | ||
# Note that this schema.rb definition is the authoritative source for your | ||
# database schema. If you need to create the application database on another | ||
# system, you should be using db:schema:load, not running all the migrations | ||
# from scratch. The latter is a flawed and unsustainable approach (the more migrations | ||
# you'll amass, the slower it'll run and the greater likelihood for issues). | ||
# | ||
# It's strongly recommended that you check this file into your version control system. | ||
|
||
ActiveRecord::Schema.define(version: 20151203030146) do | ||
|
||
# These are extensions that must be enabled in order to support this database | ||
enable_extension "plpgsql" | ||
|
||
create_table "users", force: :cascade do |t| | ||
t.string "first_name" | ||
t.string "email" | ||
t.string "password_digest" | ||
t.boolean "email_confirmed" | ||
t.string "confirm_digest" | ||
t.string "reset_digest" | ||
t.datetime "reset_sent_at" | ||
t.datetime "created_at", null: false | ||
t.datetime "updated_at", null: false | ||
t.string "last_name" | ||
t.string "city" | ||
t.string "state" | ||
t.string "country" | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
FactoryGirl.define do | ||
factory :confirmed_user, class: User do | ||
first_name Faker::Name.first_name | ||
last_name Faker::Name.last_name | ||
email Faker::Internet.email | ||
city Faker::Address.city | ||
state Faker::Address.state | ||
country Faker::Address.country | ||
email_confirmed true | ||
end | ||
|
||
factory :unconfirmed_user, class: User do | ||
first_name Faker::Name.first_name | ||
last_name Faker::Name.last_name | ||
email Faker::Internet.email | ||
city Faker::Address.city | ||
state Faker::Address.state | ||
country Faker::Address.country | ||
password "helloworld" | ||
email_confirmed false | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
require "rails_helper" | ||
|
||
RSpec.describe User do | ||
required_props = %i( | ||
first_name | ||
last_name | ||
city | ||
state | ||
country | ||
password | ||
) | ||
|
||
properties = required_props + %i( | ||
password_digest | ||
email_confirmed | ||
confirm_digest | ||
reset_digest | ||
reset_sent_at | ||
) | ||
|
||
describe "properties" do | ||
properties.each do |prop| | ||
it "has an accessor for #{prop}" do | ||
expect { subject.send(prop) }.to_not raise_error | ||
end | ||
end | ||
end | ||
|
||
describe "validations" do | ||
required_props.each do |prop| | ||
it "rejects a new user without a `#{prop}`" do | ||
user = FactoryGirl.build(:unconfirmed_user) | ||
user.send("#{prop}=", nil) | ||
expect(user.save).to be_falsy | ||
end | ||
end | ||
|
||
it "validates password length" do | ||
user = FactoryGirl.build(:unconfirmed_user, password: "xxx") | ||
expect(user.save).to be_falsy | ||
end | ||
|
||
it "valudates email format" do | ||
user = FactoryGirl.build(:unconfirmed_user, email: "xxx.xxx") | ||
expect(user.save).to be_falsy | ||
end | ||
end | ||
end |