Created
November 30, 2016 06:54
-
-
Save kiennt/382a2c86df380708e7ed61a80259b8b3 to your computer and use it in GitHub Desktop.
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
defmodule Kipatest.AccessToken do | |
use Kipatest.Web, :model | |
@type t :: %{__struct__: atom} | |
@primary_key {:id, Ecto.UUID, autogenerate: true} | |
schema "access_tokens" do | |
field :is_valid, :boolean, default: true | |
field :refresh_token, Ecto.UUID, autogenerate: true | |
field :expired_at, Timex.Ecto.DateTime | |
field :refresh_token_expired_at, Timex.Ecto.DateTime | |
belongs_to :user, Kipatest.User | |
timestamps() | |
end | |
@spec new_token(User.t) :: Changeset.t | |
def new_token(user) do | |
%AccessToken{} | |
|> change | |
|> put_change(:expired_at, Timex.shift(Timex.now, days: 60)) | |
|> put_change(:refresh_token_expired_at, Timex.shift(Timex.now, days: 120)) | |
|> put_assoc(:user, user) | |
end | |
@spec new_token(AccessToken.t) :: true | false | |
def is_expired(token) do | |
Timex.diff(Timex.now, token.expired_at) > 0 | |
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
access_token.ex:19: Function new_token/1 has no local return | |
access_token.ex:21: The call 'Elixir.Ecto.Changeset':change(#{'__meta__':=#{'__struct__':='Elixir.Ecto.Schema.Metadata', 'context':='nil', 'source':={'nil',<<_:104>>}, 'state':='built'}, '__struct__':='Elixir.Kipatest.AccessToken', 'expired_at':='nil', 'id':='nil', 'inserted_at':='nil', 'is_valid':='true', 'refresh_token':='nil', 'refresh_token_expired_at':='nil', 'updated_at':='nil', 'user':=#{'__cardinality__':='one', '__field__':='user', '__owner__':='Elixir.Kipatest.AccessToken', '__struct__':='Elixir.Ecto.Association.NotLoaded'}, 'user_id':='nil'}) will never return since it differs in the 1st argument from the success typing arguments: ({map(),[{atom(),_}] | map()} | #{'__struct__':=atom(), 'action'=>'delete' | 'insert' | 'nil' | 'replace' | 'update', 'changes'=>#{atom()=>_}, 'constraints'=>[#{'constraint':=binary(), 'field':=atom(), 'match':='exact' | 'suffix', 'message':={_,_}, 'type':='unique'}], 'data'=>'nil' | #{'__struct__':=atom()}, 'empty_values'=>_, 'errors'=>[{atom(),{_,_}}], 'filters'=>#{atom()=>_}, 'params'=>'nil' | #{binary()=>_}, 'prepare'=>[fun((map()) -> map())], 'repo'=>atom(), 'required'=>[atom()], 'types'=>'nil' | #{atom()=>atom() | {'array',_} | {'embed',map()} | {'in',_} | {'map',_}}, 'valid?'=>boolean(), 'validations'=>[{atom(),_}]}) | |
organization.ex:14: Function create_changeset/1 has no local return | |
organization.ex:15: The call 'Elixir.Ecto.Changeset':change(#{'__meta__':=#{'__struct__':='Elixir.Ecto.Schema.Metadata', 'context':='nil', 'source':={'nil',<<_:104>>}, 'state':='built'}, '__struct__':='Elixir.Kipatest.Organization', 'id':='nil', 'inserted_at':='nil', 'name':='nil', 'owner':=#{'__cardinality__':='one', '__field__':='owner', '__owner__':='Elixir.Kipatest.Organization', '__struct__':='Elixir.Ecto.Association.NotLoaded'}, 'owner_id':='nil', 'updated_at':='nil'},[{'name',_},...]) breaks the contract ('Elixir.Ecto.Schema':t() | t() | {data(),types()},#{atom()=>term()} | 'Elixir.Keyword':t()) -> t() | no_return() | |
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
defmodule Kipatest.Organization do | |
use Kipatest.Web, :model | |
@type t :: %{__struct__: atom} | |
schema "organizations" do | |
field :name, :string | |
belongs_to :owner, Kipatest.User | |
timestamps() | |
end | |
@spec create_changeset(User.t) :: Changeset.t | |
def create_changeset(user) do | |
%Organization{} |> change(name: user.name) |> put_assoc(:owner, user) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is bug from Ecto 2.0.6
We fix it by change
@type t :: %{__struc__: atom}
to@type t :: struct
in Ecto library