-
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.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
84d7820
commit 3855d3d
Showing
10 changed files
with
192 additions
and
8 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
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,18 @@ | ||
language: elixir | ||
elixir: | ||
- 1.4.1 | ||
addons: | ||
postgresql: '9.4' | ||
apt: | ||
packages: | ||
- wkhtmltopdf | ||
env: | ||
- MIX_ENV=test | ||
before_script: | ||
- mix do ecto.create, ecto.migrate | ||
script: | ||
- mix do deps.get, compile --warnings-as-errors, coveralls.json | ||
after_success: | ||
- bash <(curl -s https://codecov.io/bash) | ||
notifications: | ||
email: false |
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,28 @@ | ||
codecov: | ||
codecov: | ||
token: d9616fef-dc91-4fb3-a919-a75b7f0ba079 | ||
notify: | ||
require_ci_to_pass: yes | ||
|
||
coverage: | ||
precision: 2 | ||
round: down | ||
range: "70...100" | ||
|
||
status: | ||
project: yes | ||
patch: yes | ||
changes: no | ||
|
||
parsers: | ||
gcov: | ||
branch_detection: | ||
conditional: yes | ||
loop: yes | ||
method: no | ||
macro: no | ||
|
||
comment: | ||
layout: "header, diff, sunburst" | ||
behavior: default | ||
require_changes: no |
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,13 @@ | ||
{ | ||
"coverage_options": { | ||
"minimum_coverage": 100 | ||
}, | ||
"skip_files": [ | ||
"web/channels", | ||
"lib/feedback.ex", | ||
"test/support/model_case.ex", | ||
"test/support/channel_case.ex", | ||
"web/web.ex", | ||
"web/views/error_helpers.ex" | ||
] | ||
} |
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
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
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,16 @@ | ||
defmodule Feedback.Repo.Migrations.CreateUser do | ||
use Ecto.Migration | ||
|
||
def change do | ||
create table(:users) do | ||
add :first_name, :string | ||
add :last_name, :string | ||
add :email, :string | ||
add :password_hash, :string | ||
|
||
timestamps() | ||
end | ||
|
||
create unique_index(:users, [:email]) | ||
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,48 @@ | ||
defmodule Feedback.UserTest do | ||
use Feedback.ModelCase, async: false | ||
alias Feedback.User | ||
alias Comeonin.Bcrypt | ||
|
||
@valid_attrs %{ | ||
email: "[email protected]", | ||
password: "secretshhh", | ||
password_hash: Bcrypt.hashpwsalt("secretshhh"), | ||
first_name: "First", | ||
last_name: "Last" | ||
} | ||
@invalid_attrs %{email: "[email protected]"} | ||
|
||
test "changeset with valid attributes" do | ||
changeset = User.changeset(%User{}, @valid_attrs) | ||
assert changeset.valid? | ||
end | ||
|
||
test "changeset with invalid attributes" do | ||
changeset = User.changeset(%User{}, @invalid_attrs) | ||
refute changeset.valid? | ||
end | ||
|
||
test "registration_changeset with valid attributes" do | ||
changeset = User.registration_changeset(%User{}, @valid_attrs) | ||
assert changeset.valid? | ||
end | ||
|
||
test "registration_changeset with invalid attributes" do | ||
changeset = User.registration_changeset(%User{}, @invalid_attrs) | ||
refute changeset.valid? | ||
end | ||
|
||
test "user schema" do | ||
actual = User.__schema__(:fields) | ||
expected = [ | ||
:id, | ||
:first_name, | ||
:last_name, | ||
:email, | ||
:password_hash, | ||
:inserted_at, | ||
:updated_at | ||
] | ||
assert actual == expected | ||
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,45 @@ | ||
defmodule Feedback.User do | ||
use Feedback.Web, :model | ||
alias Ecto.Changeset | ||
alias Comeonin.Bcrypt | ||
|
||
schema "users" do | ||
field :first_name, :string | ||
field :last_name, :string | ||
field :email, :string | ||
field :password, :string, virtual: true | ||
field :password_hash, :string | ||
|
||
timestamps() | ||
end | ||
|
||
def changeset(struct, params \\ :invalid) do | ||
struct | ||
|> cast(params, [:email, :first_name, :last_name, :password]) | ||
|> validate_format(:email, ~r/@/) | ||
|> validate_required([:email, :password, :first_name, :last_name]) | ||
|> unique_constraint(:email) | ||
end | ||
|
||
def registration_changeset(struct, params) do | ||
struct | ||
|> changeset(params) | ||
|> validate_password(params) | ||
|> put_pass_hash() | ||
end | ||
|
||
def validate_password(changeset, params) do | ||
changeset | ||
|> cast(params, [:password, :email]) | ||
|> validate_length(:password, min: 6, max: 100) | ||
end | ||
|
||
def put_pass_hash(changeset) do | ||
case changeset do | ||
%Changeset{valid?: true, changes: %{password: pass}} -> | ||
put_change(changeset, :password_hash, Bcrypt.hashpwsalt(pass)) | ||
_ -> | ||
changeset | ||
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