-
Notifications
You must be signed in to change notification settings - Fork 38
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
[#182] Fixed sumo_store_riak to support date/datetime fields. #183
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,8 @@ | |
find_all/1, | ||
find_by/1, | ||
delete_all/1, | ||
delete/1 | ||
delete/1, | ||
check_datetime_fields/1 | ||
]). | ||
|
||
-define(EXCLUDED_FUNS, | ||
|
@@ -70,6 +71,11 @@ delete_all(_Config) -> | |
delete(_Config) -> | ||
run_all_stores(fun delete_module/1). | ||
|
||
check_datetime_fields(_Config) -> | ||
lists:foreach( | ||
fun do_check_datetime_fields/1, | ||
[sumo_test_people_riak]). | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We successfully managed to remove particular stores from the test suites. You should not have |
||
|
||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | ||
%%% Internal functions | ||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | ||
|
@@ -139,6 +145,20 @@ delete_module(Module) -> | |
|
||
1 = length(All) - length(NewAll). | ||
|
||
do_check_datetime_fields(Module) -> | ||
[P0] = sumo:find_by(Module, [{name, <<"A">>}]), | ||
P1 = sumo:find(Module, Module:id(P0)), | ||
[P2 | _] = sumo:find_all(Module), | ||
|
||
{Date, _} = calendar:universal_time(), | ||
|
||
Date = Module:date(P0), | ||
{Date, {_, _, _}} = Module:datetime(P0), | ||
Date = Module:date(P1), | ||
{Date, {_, _, _}} = Module:datetime(P1), | ||
Date = Module:date(P2), | ||
{Date, {_, _, _}} = Module:datetime(P2). | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should also test that setting a value (e.g. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should also test that using |
||
%%% Helper | ||
|
||
-spec run_all_stores(fun()) -> ok. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,34 @@ | ||
-module(sumo_test_people_riak). | ||
|
||
-behavior(sumo_doc). | ||
|
||
-include_lib("mixer/include/mixer.hrl"). | ||
-mixin([{sumo_test_people, | ||
[sumo_wakeup/1, | ||
sumo_sleep/1, | ||
new/2, | ||
new/3, | ||
new/4, | ||
name/1, | ||
id/1, | ||
age/1 | ||
] | ||
} | ||
]). | ||
|
||
-export([sumo_schema/0]). | ||
%%% sumo_db callbacks | ||
-export([ sumo_schema/0 | ||
, sumo_wakeup/1 | ||
, sumo_sleep/1 | ||
]). | ||
|
||
-export([ new/2 | ||
, new/3 | ||
, new/4 | ||
, name/1 | ||
, id/1 | ||
, age/1 | ||
, date/1 | ||
, datetime/1 | ||
]). | ||
|
||
-record(person, {id :: integer(), | ||
name :: string(), | ||
last_name :: string(), | ||
age :: integer(), | ||
address :: string(), | ||
date :: calendar:date(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Try not to call the fields in such a generic way (even for tests). Call them |
||
datetime :: calendar:datetime()}). | ||
|
||
-type person() :: #person{}. | ||
|
||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | ||
%%% sumo_doc callbacks | ||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | ||
|
||
-spec sumo_schema() -> sumo:schema(). | ||
sumo_schema() -> | ||
|
@@ -25,6 +37,64 @@ sumo_schema() -> | |
sumo:new_field(name, string, [{length, 255}, not_null]), | ||
sumo:new_field(last_name, string, [{length, 255}, not_null]), | ||
sumo:new_field(age, integer), | ||
sumo:new_field(address, string, [{length, 255}]) | ||
sumo:new_field(address, string, [{length, 255}]), | ||
sumo:new_field(date, date), | ||
sumo:new_field(datetime, datetime) | ||
], | ||
sumo:new_schema(?MODULE, Fields). | ||
|
||
-spec sumo_sleep(person()) -> sumo:doc(). | ||
sumo_sleep(Person) -> | ||
#{id => Person#person.id, | ||
name => Person#person.name, | ||
last_name => Person#person.last_name, | ||
age => Person#person.age, | ||
address => Person#person.address, | ||
date => Person#person.date, | ||
datetime => Person#person.datetime}. | ||
|
||
-spec sumo_wakeup(sumo:doc()) -> person(). | ||
sumo_wakeup(Person) -> | ||
#person{ | ||
id = maps:get(id, Person), | ||
name = maps:get(name, Person), | ||
last_name = maps:get(last_name, Person), | ||
age = maps:get(age, Person), | ||
address = maps:get(address, Person), | ||
date = maps:get(date, Person), | ||
datetime = maps:get(datetime, Person) | ||
}. | ||
|
||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | ||
%%% Exported | ||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | ||
|
||
new(Name, LastName) -> | ||
new(Name, LastName, undefined). | ||
|
||
new(Name, LastName, Age) -> | ||
new(Name, LastName, Age, undefined). | ||
|
||
new(Name, LastName, Age, Address) -> | ||
Datetime = {Date, _} = calendar:universal_time(), | ||
#person{name = Name, | ||
last_name = LastName, | ||
age = Age, | ||
address = Address, | ||
date = Date, | ||
datetime = Datetime}. | ||
|
||
name(Person) -> | ||
Person#person.name. | ||
|
||
id(Person) -> | ||
Person#person.id. | ||
|
||
age(Person) -> | ||
Person#person.age. | ||
|
||
date(Person) -> | ||
Person#person.date. | ||
|
||
datetime(Person) -> | ||
Person#person.datetime. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be solved better as function clauses instead of a case expression.