Skip to content

Commit

Permalink
Remove default "contributor" role from UserInvite
Browse files Browse the repository at this point in the history
  • Loading branch information
begedin committed Dec 29, 2017
1 parent 2ecd790 commit 751c37f
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 21 deletions.
2 changes: 1 addition & 1 deletion lib/code_corps/model/user_invite.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ defmodule CodeCorps.UserInvite do

schema "user_invites" do
field :email, :string, null: false
field :role, :string, default: "contributor"
field :role, :string
field :name, :string

belongs_to :project, CodeCorps.Project
Expand Down
12 changes: 6 additions & 6 deletions priv/repo/migrations/20171228163712_add_user_invites.exs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ defmodule CodeCorps.Repo.Migrations.AddUserInvites do

def change do
create table(:user_invites) do
add :email, :string, null: false
add :name, :string, null: true
add :role, :string, null: true, default: "contributor"
add(:email, :string, null: false)
add(:name, :string, null: true)
add(:role, :string, null: true)

add :inviter_id, references(:users)
add :invitee_id, references(:users)
add :project_id, references(:projects)
add(:inviter_id, references(:users))
add(:invitee_id, references(:users))
add(:project_id, references(:projects))

timestamps()
end
Expand Down
2 changes: 1 addition & 1 deletion priv/repo/structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1735,7 +1735,7 @@ CREATE TABLE user_invites (
id bigint NOT NULL,
email character varying(255) NOT NULL,
name character varying(255),
role character varying(255) DEFAULT 'contributor'::character varying,
role character varying(255),
inviter_id bigint,
invitee_id bigint,
project_id bigint,
Expand Down
15 changes: 2 additions & 13 deletions test/lib/code_corps/accounts/accounts_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -189,17 +189,6 @@ defmodule CodeCorps.AccountsTest do
assert user_invite.role == "admin"
end

test "defaults role to 'contributor'" do
%{id: inviter_id} = insert(:user)

{:ok, %UserInvite{} = user_invite} =
@base_attrs
|> Map.put(:inviter_id, inviter_id)
|> Accounts.create_invite

assert user_invite.role == "contributor"
end

test "does not allow invalid roles" do
%{id: inviter_id} = insert(:user)

Expand Down Expand Up @@ -285,13 +274,13 @@ defmodule CodeCorps.AccountsTest do

test "creates project membership if project provided" do
project = insert(:project)
invite = insert(:user_invite, invitee: nil, project: project)
invite = insert(:user_invite, invitee: nil, project: project, role: "admin")

{:ok, %User{} = user} =
@valid_user_params
|> Map.put("invite_id", invite.id)
|> Accounts.claim_invite
assert Repo.get_by(ProjectUser, user_id: user.id, project_id: project.id)
assert Repo.get_by(ProjectUser, user_id: user.id, project_id: project.id, role: "admin")
end

test "returns :invite_not_found if bad id provided" do
Expand Down

0 comments on commit 751c37f

Please sign in to comment.