Permalink
Browse files

Require "model-NN" ID format for mock adapter

  • Loading branch information...
1 parent 246e443 commit 5d0879192ffea1857075c5c05adec4f4aa8d1833 @evanmiller evanmiller committed Aug 9, 2012
Showing with 8 additions and 1 deletion.
  1. +8 −1 src/boss_db_mock_controller.erl
@@ -46,9 +46,16 @@ handle_call({incr, Id, Amount}, _From, [{Dict, IdCounter}|OldState]) ->
{reply, NewValue, [{dict:store(Id, NewValue, Dict), IdCounter}|OldState]};
handle_call({save_record, Record}, _From, [{Dict, IdCounter}|OldState]) ->
Type = element(1, Record),
+ TypeString = atom_to_list(Type),
{Id, IdCounter1} = case Record:id() of
id -> {lists:concat([Type, "-", IdCounter]), IdCounter + 1};
- Other -> {Other, IdCounter}
+ ExistingId ->
+ [TypeString, IdNum] = string:tokens(ExistingId, "-"),
+ Max = case list_to_integer(IdNum) of
+ N when N > IdCounter -> N;
+ _ -> IdCounter
+ end,
+ {lists:concat([Type, "-", IdNum]), Max + 1}
end,
NewAttributes = lists:map(fun
({id, _}) ->

0 comments on commit 5d08791

Please sign in to comment.