From c648844d08c924eb175456c2e70699627da6ade8 Mon Sep 17 00:00:00 2001 From: Ludovic 'Archivist' Lagouardette Date: Sun, 2 Sep 2018 19:58:36 +0200 Subject: [PATCH] Fixed issue #1 --- spec/sales_backend_spec.cr | 6 ++++++ src/sales_backend/address.cr | 6 ++++++ src/sales_backend/http/user.cr | 8 +++++++- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/spec/sales_backend_spec.cr b/spec/sales_backend_spec.cr index a5a6b20..8b5bc67 100644 --- a/spec/sales_backend_spec.cr +++ b/spec/sales_backend_spec.cr @@ -83,6 +83,12 @@ describe SalesBackend do address_state = Array(Address).from_json(Global.response.not_nil!.body) expected_address_state = Array(Address).from_json(new_address_str) (address_state.to_json == expected_address_state.to_json).should be_true + delete "/user/address", headers, new_address_str + Global.response.not_nil!.status_code.should eq(200) + get "/user/address", headers + Global.response.not_nil!.status_code.should eq(200) + address_state = Array(Address).from_json(Global.response.not_nil!.body) + address_state.size.should eq(0) get "/user/tokens", headers Global.response.not_nil!.status_code.should eq(200) diff --git a/src/sales_backend/address.cr b/src/sales_backend/address.cr index 7b9c3ba..4093577 100644 --- a/src/sales_backend/address.cr +++ b/src/sales_backend/address.cr @@ -48,4 +48,10 @@ class Address end return cmp end + def == (other : Address) + 0==(self<=>other) + end + def != (other : Address) + 0!=(self<=>other) + end end \ No newline at end of file diff --git a/src/sales_backend/http/user.cr b/src/sales_backend/http/user.cr index e049f46..23ab840 100644 --- a/src/sales_backend/http/user.cr +++ b/src/sales_backend/http/user.cr @@ -153,7 +153,13 @@ delete "/user/address" do |context| if old_list.nil? addresses=Array(Address).new else - addresses=old_list-addresses + addresses=old_list.select do |v| + isin=false + addresses.each do |va| + isin |= v==va + end + !isin + end end user_file.addresses=addresses File.write(Statics.data_path+"user/"+user.email,user_file.to_json)