fix(test): ensure calendar_share table in ACL-related eunit suites.
Harden core_calendar_share get/list when table missing. Refs EventHub/EventHubBack#73
This commit is contained in:
@@ -41,18 +41,31 @@ upsert(CalendarId, UserId, Rights, Mirror) ->
|
|||||||
-spec get(CalendarId :: binary(), UserId :: binary()) ->
|
-spec get(CalendarId :: binary(), UserId :: binary()) ->
|
||||||
{ok, #calendar_share{}} | {error, not_found}.
|
{ok, #calendar_share{}} | {error, not_found}.
|
||||||
get(CalendarId, UserId) ->
|
get(CalendarId, UserId) ->
|
||||||
case find_dirty(CalendarId, UserId) of
|
try find_dirty(CalendarId, UserId) of
|
||||||
[Rec] -> {ok, Rec};
|
[Rec] -> {ok, Rec};
|
||||||
[] -> {error, not_found}
|
[] -> {error, not_found}
|
||||||
|
catch
|
||||||
|
exit:{aborted, {no_exists, _}} -> {error, not_found};
|
||||||
|
error:_ -> {error, not_found}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
-spec list_by_calendar(CalendarId :: binary()) -> [#calendar_share{}].
|
-spec list_by_calendar(CalendarId :: binary()) -> [#calendar_share{}].
|
||||||
list_by_calendar(CalendarId) ->
|
list_by_calendar(CalendarId) ->
|
||||||
mnesia:dirty_match_object(#calendar_share{calendar_id = CalendarId, _ = '_'}).
|
try
|
||||||
|
mnesia:dirty_match_object(#calendar_share{calendar_id = CalendarId, _ = '_'})
|
||||||
|
catch
|
||||||
|
exit:{aborted, {no_exists, _}} -> [];
|
||||||
|
error:_ -> []
|
||||||
|
end.
|
||||||
|
|
||||||
-spec list_by_user(UserId :: binary()) -> [#calendar_share{}].
|
-spec list_by_user(UserId :: binary()) -> [#calendar_share{}].
|
||||||
list_by_user(UserId) ->
|
list_by_user(UserId) ->
|
||||||
mnesia:dirty_match_object(#calendar_share{user_id = UserId, _ = '_'}).
|
try
|
||||||
|
mnesia:dirty_match_object(#calendar_share{user_id = UserId, _ = '_'})
|
||||||
|
catch
|
||||||
|
exit:{aborted, {no_exists, _}} -> [];
|
||||||
|
error:_ -> []
|
||||||
|
end.
|
||||||
|
|
||||||
-spec delete(CalendarId :: binary(), UserId :: binary()) -> ok | {error, not_found | term()}.
|
-spec delete(CalendarId :: binary(), UserId :: binary()) -> ok | {error, not_found | term()}.
|
||||||
delete(CalendarId, UserId) ->
|
delete(CalendarId, UserId) ->
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
-include_lib("eunit/include/eunit.hrl").
|
-include_lib("eunit/include/eunit.hrl").
|
||||||
-include("records.hrl").
|
-include("records.hrl").
|
||||||
|
|
||||||
-define(TABLES, [user, calendar, event, booking, admin, subscription]).
|
-define(TABLES, [user, calendar, event, booking, admin, subscription, calendar_share]).
|
||||||
|
|
||||||
setup() ->
|
setup() ->
|
||||||
eh_test_support:start_mnesia(),
|
eh_test_support:start_mnesia(),
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
-include("records.hrl").
|
-include("records.hrl").
|
||||||
|
|
||||||
-define(TABLES, [user, calendar, event, booking, admin, subscription, calendar_specialist,
|
-define(TABLES, [user, calendar, event, booking, admin, subscription, calendar_specialist,
|
||||||
recurrence_exception, notification, push_subscription]).
|
recurrence_exception, notification, push_subscription, calendar_share]).
|
||||||
|
|
||||||
setup() ->
|
setup() ->
|
||||||
eh_test_support:start_mnesia(),
|
eh_test_support:start_mnesia(),
|
||||||
|
|||||||
@@ -21,9 +21,15 @@ setup() ->
|
|||||||
{attributes, record_info(fields, calendar_specialist)},
|
{attributes, record_info(fields, calendar_specialist)},
|
||||||
{ram_copies, [node()]}
|
{ram_copies, [node()]}
|
||||||
]),
|
]),
|
||||||
|
mnesia:create_table(calendar_share, [
|
||||||
|
{attributes, record_info(fields, calendar_share)},
|
||||||
|
{ram_copies, [node()]},
|
||||||
|
{index, [calendar_id, user_id]}
|
||||||
|
]),
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
cleanup(_) ->
|
cleanup(_) ->
|
||||||
|
mnesia:delete_table(calendar_share),
|
||||||
mnesia:delete_table(calendar_specialist),
|
mnesia:delete_table(calendar_specialist),
|
||||||
mnesia:delete_table(subscription),
|
mnesia:delete_table(subscription),
|
||||||
mnesia:delete_table(calendar),
|
mnesia:delete_table(calendar),
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
-include_lib("eunit/include/eunit.hrl").
|
-include_lib("eunit/include/eunit.hrl").
|
||||||
-include("records.hrl").
|
-include("records.hrl").
|
||||||
|
|
||||||
-define(TABLES, [user, calendar, event, recurrence_exception]).
|
-define(TABLES, [user, calendar, event, recurrence_exception, calendar_share]).
|
||||||
|
|
||||||
setup() ->
|
setup() ->
|
||||||
eh_test_support:start_mnesia(),
|
eh_test_support:start_mnesia(),
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
-include_lib("eunit/include/eunit.hrl").
|
-include_lib("eunit/include/eunit.hrl").
|
||||||
-include("records.hrl").
|
-include("records.hrl").
|
||||||
|
|
||||||
-define(TABLES, [user, calendar, event, calendar_specialist, subscription]).
|
-define(TABLES, [user, calendar, event, calendar_specialist, subscription, calendar_share]).
|
||||||
|
|
||||||
setup() ->
|
setup() ->
|
||||||
eh_test_support:start_mnesia(),
|
eh_test_support:start_mnesia(),
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
-include_lib("eunit/include/eunit.hrl").
|
-include_lib("eunit/include/eunit.hrl").
|
||||||
-include("records.hrl").
|
-include("records.hrl").
|
||||||
|
|
||||||
-define(TABLES, [user, calendar, calendar_specialist, subscription, event]).
|
-define(TABLES, [user, calendar, calendar_specialist, subscription, event, calendar_share]).
|
||||||
|
|
||||||
setup() ->
|
setup() ->
|
||||||
eh_test_support:start_mnesia(),
|
eh_test_support:start_mnesia(),
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
-include_lib("eunit/include/eunit.hrl").
|
-include_lib("eunit/include/eunit.hrl").
|
||||||
-include("records.hrl").
|
-include("records.hrl").
|
||||||
|
|
||||||
-define(TABLES, [user, calendar, event, subscription]).
|
-define(TABLES, [user, calendar, event, subscription, calendar_share]).
|
||||||
|
|
||||||
setup() ->
|
setup() ->
|
||||||
eh_test_support:start_mnesia(),
|
eh_test_support:start_mnesia(),
|
||||||
|
|||||||
Reference in New Issue
Block a user