Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix #239] Add extra options to doc configuration. #249

Merged
merged 3 commits into from
Aug 4, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/blog/src/blog_author.erl
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,12 @@ set(Key, Value, Author) when is_atom(Key), is_list(Author) ->
%% sumo behavior follows.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% @doc Part of the sumo_doc behavior.
-spec sumo_wakeup(sumo:doc()) -> author().
-spec sumo_wakeup(sumo:model()) -> author().
sumo_wakeup(Data) ->
maps:to_list(Data).

%% @doc Part of the sumo_doc behavior.
-spec sumo_sleep(author()) -> sumo:doc().
-spec sumo_sleep(author()) -> sumo:model().
sumo_sleep(Author) ->
maps:from_list(Author).

Expand Down
4 changes: 2 additions & 2 deletions examples/blog/src/blog_post.erl
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,12 @@ set(Key, Value, Post) when is_atom(Key), is_list(Post) ->
%% sumo behavior follows.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% @doc Part of the sumo_doc behavior.
-spec sumo_wakeup(sumo:doc()) -> post().
-spec sumo_wakeup(sumo:model()) -> post().
sumo_wakeup(Data) ->
maps:to_list(Data).

%% @doc Part of the sumo_doc behavior.
-spec sumo_sleep(post()) -> sumo:doc().
-spec sumo_sleep(post()) -> sumo:model().
sumo_sleep(Post) ->
maps:from_list(Post).

Expand Down
4 changes: 2 additions & 2 deletions examples/blog/src/blog_reader.erl
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,12 @@ set(Key, Value, Reader) when is_atom(Key), is_list(Reader) ->
%% sumo behavior follows.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% @doc Part of the sumo_doc behavior.
-spec sumo_wakeup(sumo:doc()) -> reader().
-spec sumo_wakeup(sumo:model()) -> reader().
sumo_wakeup(Data) ->
maps:to_list(Data).

%% @doc Part of the sumo_doc behavior.
-spec sumo_sleep(reader()) -> sumo:doc().
-spec sumo_sleep(reader()) -> sumo:model().
sumo_sleep(Reader) ->
maps:from_list(Reader).

Expand Down
4 changes: 2 additions & 2 deletions examples/blog/src/blog_vote.erl
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,12 @@ get(Key, Vote) when is_atom(Key), is_list(Vote) ->
%% sumo behavior follows.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% @doc Part of the sumo_doc behavior.
-spec sumo_wakeup(sumo:doc()) -> vote().
-spec sumo_wakeup(sumo:model()) -> vote().
sumo_wakeup(Data) ->
maps:to_list(Data).

%% @doc Part of the sumo_doc behavior.
-spec sumo_sleep(vote()) -> sumo:doc().
-spec sumo_sleep(vote()) -> sumo:model().
sumo_sleep(Vote) ->
maps:from_list(Vote).

Expand Down
4 changes: 2 additions & 2 deletions examples/elastic-blog/src/blog_author.erl
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,12 @@ set(Key, Value, Author) when is_atom(Key), is_list(Author) ->
%% sumo behavior follows.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% @doc Part of the sumo_doc behavior.
-spec sumo_wakeup(sumo:doc()) -> author().
-spec sumo_wakeup(sumo:model()) -> author().
sumo_wakeup(Data) ->
maps:to_list(Data).

%% @doc Part of the sumo_doc behavior.
-spec sumo_sleep(author()) -> sumo:doc().
-spec sumo_sleep(author()) -> sumo:model().
sumo_sleep(Author) ->
maps:from_list(Author).

Expand Down
4 changes: 2 additions & 2 deletions examples/elastic-blog/src/blog_post.erl
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,12 @@ set(Key, Value, Post) when is_atom(Key), is_list(Post) ->
%% sumo behavior follows.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% @doc Part of the sumo_doc behavior.
-spec sumo_wakeup(sumo:doc()) -> post().
-spec sumo_wakeup(sumo:model()) -> post().
sumo_wakeup(Data) ->
maps:to_list(Data).

%% @doc Part of the sumo_doc behavior.
-spec sumo_sleep(post()) -> sumo:doc().
-spec sumo_sleep(post()) -> sumo:model().
sumo_sleep(Post) ->
maps:from_list(Post).

Expand Down
4 changes: 2 additions & 2 deletions examples/elastic-blog/src/blog_reader.erl
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,12 @@ set(Key, Value, Reader) when is_atom(Key), is_list(Reader) ->
%% sumo behavior follows.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% @doc Part of the sumo_doc behavior.
-spec sumo_wakeup(sumo:doc()) -> reader().
-spec sumo_wakeup(sumo:model()) -> reader().
sumo_wakeup(Data) ->
maps:to_list(Data).

%% @doc Part of the sumo_doc behavior.
-spec sumo_sleep(reader()) -> sumo:doc().
-spec sumo_sleep(reader()) -> sumo:model().
sumo_sleep(Reader) ->
maps:from_list(Reader).

Expand Down
4 changes: 2 additions & 2 deletions examples/elastic-blog/src/blog_vote.erl
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,12 @@ get(Key, Vote) when is_atom(Key), is_list(Vote) ->
%% sumo behavior follows.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% @doc Part of the sumo_doc behavior.
-spec sumo_wakeup(sumo:doc()) -> vote().
-spec sumo_wakeup(sumo:model()) -> vote().
sumo_wakeup(Data) ->
maps:to_list(Data).

%% @doc Part of the sumo_doc behavior.
-spec sumo_sleep(vote()) -> sumo:doc().
-spec sumo_sleep(vote()) -> sumo:model().
sumo_sleep(Vote) ->
maps:from_list(Vote).

Expand Down
93 changes: 49 additions & 44 deletions src/adapter_test_helpers/sumo_basic_test_helper.erl
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,28 @@

-spec find(config()) -> ok.
find(Config) ->
{_, Module} = lists:keyfind(module, 1, Config),
{_, Name} = lists:keyfind(name, 1, Config),
Module = sumo_config:get_prop_value(Name, module),

[First, Second | _] = sumo:find_all(Module),
First = sumo:find(Module, Module:id(First)),
Second = sumo:find(Module, Module:id(Second)),
notfound = sumo:find(Module, 0),
[First, Second | _] = sumo:find_all(Name),
First = sumo:find(Name, Module:id(First)),
Second = sumo:find(Name, Module:id(Second)),
notfound = sumo:find(Name, 0),
ok.

-spec find_all(config()) -> ok.
find_all(Config) ->
{_, Module} = lists:keyfind(module, 1, Config),
{_, Name} = lists:keyfind(name, 1, Config),

[_, _, _, _, _, _, _, _] = sumo:find_all(Module),
[_, _, _, _, _, _, _, _] = sumo:find_all(Name),
ok.

-spec find_by(config()) -> ok.
find_by(Config) ->
{_, Module} = lists:keyfind(module, 1, Config),
{_, Name} = lists:keyfind(name, 1, Config),
Module = sumo_config:get_prop_value(Name, module),

Results = sumo:find_by(Module, [{last_name, <<"D">>}]),
Results = sumo:find_by(Name, [{last_name, <<"D">>}]),
[_, _] = Results,
SortFun = fun(A, B) -> Module:name(A) < Module:name(B) end,
[First, Second | _] = lists:sort(SortFun, Results),
Expand All @@ -56,8 +58,9 @@ find_by(Config) ->
undefined = Module:description(First),
{Today, _} = Module:created_at(First),
% Check that it returns what we have inserted
[LastPerson | _NothingElse] =
sumo:find_by(Module, [{last_name, <<"LastName">>}]),
[LastPerson | _NothingElse] = sumo:find_by(Name, [
{last_name, <<"LastName">>}
]),
<<"Name">> = Module:name(LastPerson),
<<"LastName">> = Module:last_name(LastPerson),
3 = Module:age(LastPerson),
Expand All @@ -72,53 +75,54 @@ find_by(Config) ->

%% Check find_by ID
FirstId = Module:id(First),
[First1] = sumo:find_by(Module, [{id, FirstId}]),
[First1] = sumo:find_by(
Module, [{last_name, <<"D">>}, {id, FirstId}]),
[] = sumo:find_by(Module, [{name, <<"NotB">>}, {id, FirstId}]),
[First1] = sumo:find_by(Name, [{id, FirstId}]),
[First1] = sumo:find_by(Name, [{last_name, <<"D">>}, {id, FirstId}]),
[] = sumo:find_by(Name, [{name, <<"NotB">>}, {id, FirstId}]),
First1 = First,
%% Check pagination
Results1 = sumo:find_by(Module, [], 3, 1),
Results1 = sumo:find_by(Name, [], 3, 1),
[_, _, _] = Results1,

%% This test is #177 github issue related
[_, _, _, _, _, _, _, _] = sumo:find_by(Module, []),
Robot = sumo:find_by(Module, [{name, <<"Model T-2000">>}]),
[_, _, _, _, _, _, _, _] = sumo:find_by(Name, []),
Robot = sumo:find_by(Name, [{name, <<"Model T-2000">>}]),
[_] = Robot,
ok.

-spec delete_all(config()) -> ok.
delete_all(Config) ->
{_, Module} = lists:keyfind(module, 1, Config),
{_, Name} = lists:keyfind(name, 1, Config),

sumo:delete_all(Module),
[] = sumo:find_all(Module),
sumo:delete_all(Name),
[] = sumo:find_all(Name),
ok.

-spec delete(config()) -> ok.
delete(Config) ->
{_, Module} = lists:keyfind(module, 1, Config),
{_, Name} = lists:keyfind(name, 1, Config),
Module = sumo_config:get_prop_value(Name, module),

%% delete_by
2 = sumo:delete_by(Module, [{last_name, <<"D">>}]),
Results = sumo:find_by(Module, [{last_name, <<"D">>}]),
2 = sumo:delete_by(Name, [{last_name, <<"D">>}]),
Results = sumo:find_by(Name, [{last_name, <<"D">>}]),
[] = Results,

%% delete
[First | _ ] = All = sumo:find_all(Module),
[First | _ ] = All = sumo:find_all(Name),
Id = Module:id(First),
sumo:delete(Module, Id),
NewAll = sumo:find_all(Module),
sumo:delete(Name, Id),
NewAll = sumo:find_all(Name),
[_] = All -- NewAll,
ok.

-spec check_proper_dates(config()) -> ok.
check_proper_dates(Config) ->
{_, Module} = lists:keyfind(module, 1, Config),
{_, Name} = lists:keyfind(name, 1, Config),
Module = sumo_config:get_prop_value(Name, module),

[P0] = sumo:find_by(Module, [{name, <<"A">>}]),
P1 = sumo:find(Module, Module:id(P0)),
[P2 | _] = sumo:find_all(Module),
[P0] = sumo:find_by(Name, [{name, <<"A">>}]),
P1 = sumo:find(Name, Module:id(P0)),
[P2 | _] = sumo:find_all(Name),

{Date, _} = calendar:universal_time(),

Expand All @@ -129,26 +133,27 @@ check_proper_dates(Config) ->
Date = Module:birthdate(P2),
{Date, {_, _, _}} = Module:created_at(P2),

Person = sumo:persist(Module, Module:new(<<"X">>, <<"Z">>, 6)),
Person = sumo:persist(Name, Module:new(<<"X">>, <<"Z">>, 6)),
Date = Module:birthdate(Person),
ok.

-spec init_store(module()) -> ok.
init_store(Module) ->
sumo:create_schema(Module),
sumo:delete_all(Module),
-spec init_store(atom()) -> ok.
init_store(Name) ->
sumo:create_schema(Name),
Module = sumo_config:get_prop_value(Name, module),
sumo:delete_all(Name),

sumo:persist(Module, Module:new(<<"A">>, <<"E">>, 6)),
sumo:persist(Module, Module:new(<<"B">>, <<"D">>, 3)),
sumo:persist(Module, Module:new(<<"C">>, <<"C">>, 5)),
sumo:persist(Module, Module:new(<<"D">>, <<"D">>, 4)),
sumo:persist(Module, Module:new(<<"E">>, <<"A">>, 2)),
sumo:persist(Module, Module:new(<<"F">>, <<"E">>, 1)),
sumo:persist(Module, Module:new(<<"Model T-2000">>, <<"undefined">>, 7)),
sumo:persist(Name, Module:new(<<"A">>, <<"E">>, 6)),
sumo:persist(Name, Module:new(<<"B">>, <<"D">>, 3)),
sumo:persist(Name, Module:new(<<"C">>, <<"C">>, 5)),
sumo:persist(Name, Module:new(<<"D">>, <<"D">>, 4)),
sumo:persist(Name, Module:new(<<"E">>, <<"A">>, 2)),
sumo:persist(Name, Module:new(<<"F">>, <<"E">>, 1)),
sumo:persist(Name, Module:new(<<"Model T-2000">>, <<"undefined">>, 7)),

{Date, _} = calendar:universal_time(),
sumo:persist(
Module,
Name,
Module:new(
<<"Name">>,
<<"LastName">>,
Expand Down
Loading