Browse Source

Using dummy avatar internally

master
Pursuit 2 years ago
parent
commit
c5cf019f3a
  1. 6
      lib/iqrcode/accounts/user.ex
  2. 20
      lib/iqrcode/accounts/user_from_auth.ex
  3. 10
      test/iqrcode/accounts_test.exs

6
lib/iqrcode/accounts/user.ex

@ -5,7 +5,7 @@ defmodule Iqrcode.Accounts.User do
alias Iqrcode.Content.Qrcode
schema "users" do
#field :avatar, :string
field :avatar, :string
field :email, :string
field :name, :string
has_many :qrcodes, Qrcode
@ -16,8 +16,8 @@ defmodule Iqrcode.Accounts.User do
@doc false
def changeset(user, attrs) do
user
#|> cast(attrs, [:name, :avatar, :email])
#|> validate_required([:name, :avatar, :email])
|> cast(attrs, [:name, :avatar, :email])
|> validate_required([:name, :avatar, :email])
|> cast(attrs, [:name, :email])
|> validate_required([:name, :email])
end

20
lib/iqrcode/accounts/user_from_auth.ex

@ -13,17 +13,17 @@ defmodule UserFromAuth do
# github does it this way
#defp avatar_from_auth(%{info: %{urls: %{avatar_url: image}}}), do: image
defp avatar_from_auth(%{info: %{urls: %{avatar_url: image}}}), do: image
# facebook does it this way
#defp avatar_from_auth(%{info: %{image: image}}), do: image
facebook does it this way
defp avatar_from_auth(%{info: %{image: image}}), do: image
# default case if nothing matches
#defp avatar_from_auth(auth) do
# Logger.warn(auth.provider <> " needs to find an avatar URL!")
# Logger.debug(Jason.encode!(auth))
# nil
#end
default case if nothing matches
defp avatar_from_auth(auth) do
Logger.warn(auth.provider <> " needs to find an avatar URL!")
Logger.debug(Jason.encode!(auth))
nil
end
defp basic_info(auth) do
# Strips complex auth struct to fields in `user.ex`
@ -31,7 +31,7 @@ defmodule UserFromAuth do
%{
id: auth.uid,
name: name_from_auth(auth),
#avatar: avatar_from_auth(auth),
avatar: "none",#avatar_from_auth(auth),
email: email_from_auth(auth)
}
end

10
test/iqrcode/accounts_test.exs

@ -6,9 +6,9 @@ defmodule Iqrcode.AccountsTest do
describe "users" do
alias Iqrcode.Accounts.User
#@valid_attrs %{avatar: "some avatar", email: "some email", name: "some name"}
#@update_attrs %{avatar: "some updated avatar", email: "some updated email", name: "some updated name"}
#@invalid_attrs %{avatar: nil, email: nil, name: nil}
@valid_attrs %{avatar: "some avatar", email: "some email", name: "some name"}
@update_attrs %{avatar: "some updated avatar", email: "some updated email", name: "some updated name"}
@invalid_attrs %{avatar: nil, email: nil, name: nil}
@valid_attrs %{email: "some email", name: "some name"}
@update_attrs %{email: "some updated email", name: "some updated name"}
@invalid_attrs %{email: nil, name: nil}
@ -34,7 +34,7 @@ defmodule Iqrcode.AccountsTest do
test "create_user/1 with valid data creates a user" do
assert {:ok, %User{} = user} = Accounts.create_user(@valid_attrs)
#assert user.avatar == "some avatar"
assert user.avatar == "some avatar"
assert user.email == "some email"
assert user.name == "some name"
end
@ -46,7 +46,7 @@ defmodule Iqrcode.AccountsTest do
test "update_user/2 with valid data updates the user" do
user = user_fixture()
assert {:ok, %User{} = user} = Accounts.update_user(user, @update_attrs)
#assert user.avatar == "some updated avatar"
assert user.avatar == "some updated avatar"
assert user.email == "some updated email"
assert user.name == "some updated name"
end

Loading…
Cancel
Save