Skip to content

Commit

Permalink
Remove unused Google ID from developer
Browse files Browse the repository at this point in the history
  • Loading branch information
Jake Worth committed Dec 8, 2017
1 parent aa95fad commit 188d3b5
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 48 deletions.
5 changes: 2 additions & 3 deletions lib/tilex_web/controllers/auth_controller.ex
Expand Up @@ -32,16 +32,15 @@ defmodule TilexWeb.AuthController do
|> redirect(to: "/")
end

defp authenticate(%{info: info, uid: uid}) do
defp authenticate(%{info: info}) do
email = Map.get(info, :email)
name = Developer.format_username(Map.get(info, :name))

case String.match?(email, ~r/@#{Application.get_env(:tilex, :hosted_domain)}$/) do
true ->
attrs = %{
email: email,
username: name,
google_id: uid
username: name
}

Developer.find_or_create(Repo, attrs)
Expand Down
5 changes: 2 additions & 3 deletions lib/tilex_web/models/developer.ex
Expand Up @@ -8,7 +8,6 @@ defmodule Tilex.Developer do
schema "developers" do
field(:email, :string)
field(:username, :string)
field(:google_id, :string)
field(:twitter_handle, :string)
field(:admin, :boolean)
field(:editor, :string)
Expand All @@ -20,8 +19,8 @@ defmodule Tilex.Developer do

def changeset(struct, params \\ %{}) do
struct
|> cast(params, [:email, :username, :google_id, :twitter_handle, :editor])
|> validate_required([:email, :username, :google_id])
|> cast(params, [:email, :username, :twitter_handle, :editor])
|> validate_required([:email, :username])
|> clean_twitter_handle
end

Expand Down
15 changes: 15 additions & 0 deletions priv/repo/migrations/20171208181757_remove_google_id.exs
@@ -0,0 +1,15 @@
defmodule Tilex.Repo.Migrations.RemoveGoogleId do
use Ecto.Migration

def up do
execute """
alter table developers drop column google_id;
"""
end

def down do
execute """
alter table developers add column google_id varchar;
"""
end
end
58 changes: 27 additions & 31 deletions priv/repo/seeds.exs
Expand Up @@ -20,36 +20,32 @@ phoenix_channel = Repo.insert!(%Channel{name: "phoenix", twitter_hashtag: "phoen
elixir_channel = Repo.insert!(%Channel{name: "elixir", twitter_hashtag: "myelixirstatus"})
erlang_channel = Repo.insert!(%Channel{name: "erlang", twitter_hashtag: "erlang"})

developer= Repo.insert!(%Developer{email: "developer@hashrocket.com",
username: "rickyrocketeer",
google_id: "186823978541230597895"
})
developer =
Repo.insert!(%Developer{email: "developer@hashrocket.com", username: "rickyrocketeer"})

1..100
|> Enum.each(fn(_i) ->

Repo.insert!(%Post{
title: "Observing Change",
body: "A Gold Master Test in Practice",
channel: phoenix_channel,
developer: developer,
slug: Post.generate_slug()
})

Repo.insert!(%Post{
title: "Controlling Your Test Environment",
body: "Slow browser integration tests are a hard problem",
channel: elixir_channel,
developer: developer,
slug: Post.generate_slug()
})

Repo.insert!(%Post{
title: "Testing Elixir",
body: "A Rubyist's Journey",
channel: erlang_channel,
developer: developer,
slug: Post.generate_slug()
})

end)
|> Enum.each(fn _i ->
Repo.insert!(%Post{
title: "Observing Change",
body: "A Gold Master Test in Practice",
channel: phoenix_channel,
developer: developer,
slug: Post.generate_slug()
})

Repo.insert!(%Post{
title: "Controlling Your Test Environment",
body: "Slow browser integration tests are a hard problem",
channel: elixir_channel,
developer: developer,
slug: Post.generate_slug()
})

Repo.insert!(%Post{
title: "Testing Elixir",
body: "A Rubyist's Journey",
channel: erlang_channel,
developer: developer,
slug: Post.generate_slug()
})
end)
5 changes: 2 additions & 3 deletions test/controllers/auth_controller_test.exs
Expand Up @@ -17,7 +17,7 @@ defmodule Tilex.AuthControllerTest do
assert get_flash(conn, :info) == "Signed in with developer@hashrocket.com"

new_developer =
Tilex.Repo.get_by!(Tilex.Developer, google_id: "186823978541230597895")
Tilex.Repo.get_by!(Tilex.Developer, email: "developer@hashrocket.com")
assert new_developer.email == "developer@hashrocket.com"
assert new_developer.username == "rickyrocketeer"
end
Expand All @@ -26,10 +26,9 @@ defmodule Tilex.AuthControllerTest do
Factory.insert!(:developer,
email: "rebecca@hashrocket.com",
name: "Rebecca Rocketeer",
google_id: "126456978541230597123"
)
existing_developer =
Tilex.Repo.get_by!(Tilex.Developer, google_id: "126456978541230597123")
Tilex.Repo.get_by!(Tilex.Developer, email: "rebecca@hashrocket.com")
assert existing_developer.email == "rebecca@hashrocket.com"

ueberauth_auth =
Expand Down
14 changes: 6 additions & 8 deletions test/support/factory.ex
@@ -1,5 +1,4 @@
defmodule Tilex.Factory do

alias Tilex.{Channel, Developer, Post, Repo}
import Ecto.Query

Expand All @@ -16,15 +15,14 @@ defmodule Tilex.Factory do
body: "A body",
channel: find_first_or_build(:channel),
developer: find_first_or_build(:developer),
slug: Post.generate_slug(),
slug: Post.generate_slug()
}
end

def build(:developer) do
%Developer{
email: "developer@hashrocket.com",
username: "Ricky Rocketeer",
google_id: "186823978541230597895"
username: "Ricky Rocketeer"
}
end

Expand All @@ -33,14 +31,14 @@ defmodule Tilex.Factory do
end

def insert!(factory_name, attributes \\ []) do
Repo.insert! build(factory_name, attributes)
Repo.insert!(build(factory_name, attributes))
end

def insert_list!(factory_name, count, attributes \\ []) do
1..count
|> Enum.each(fn(_i) ->
Repo.insert! build(factory_name, attributes)
end)
|> Enum.each(fn _i ->
Repo.insert!(build(factory_name, attributes))
end)
end

defp find_first_or_build(:channel) do
Expand Down

0 comments on commit 188d3b5

Please sign in to comment.