From 5b40c745f34f7a190b487fb9762cd00709d4b498 Mon Sep 17 00:00:00 2001 From: Bing Xie Date: Fri, 5 Aug 2016 16:48:55 +1000 Subject: [PATCH] Add address serializer to customer serializer --- app/serializers/api/admin/customer_serializer.rb | 13 ++++--------- app/views/admin/customers/index.html.haml | 4 ++-- spec/serializers/admin/customer_serializer_spec.rb | 3 ++- 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/app/serializers/api/admin/customer_serializer.rb b/app/serializers/api/admin/customer_serializer.rb index 93f66676d1..1c9d19306d 100644 --- a/app/serializers/api/admin/customer_serializer.rb +++ b/app/serializers/api/admin/customer_serializer.rb @@ -1,5 +1,8 @@ class Api::Admin::CustomerSerializer < ActiveModel::Serializer - attributes :id, :email, :enterprise_id, :user_id, :code, :tags, :tag_list, :name, :bill_address, :ship_address + attributes :id, :email, :enterprise_id, :user_id, :code, :tags, :tag_list, :name + + has_one :ship_address, serializer: Api::AddressSerializer + has_one :bill_address, serializer: Api::AddressSerializer def tag_list object.tag_list.join(",") @@ -11,12 +14,4 @@ class Api::Admin::CustomerSerializer < ActiveModel::Serializer tag_rule_map || { text: tag, rules: nil } end end - - def ship_address - object.ship_address.andand.address1 - end - - def bill_address - object.bill_address.andand.address1 - end end diff --git a/app/views/admin/customers/index.html.haml b/app/views/admin/customers/index.html.haml index 9fb243e0f8..9adf8812cb 100644 --- a/app/views/admin/customers/index.html.haml +++ b/app/views/admin/customers/index.html.haml @@ -86,8 +86,8 @@ .tag_watcher{ 'obj-for-update' => "customer", "attr-for-update" => "tag_list"} %tags_with_translation{ object: 'customer', 'find-tags' => 'findTags(query)' } %td.bill_address{ 'ng-show' => 'columns.bill_address.visible' } - %a{ href: '#', "ng-bind" => '::customer.bill_address | limitTo: 15', 'edit-address-dialog' => true } - %td.ship_address{ 'ng-show' => 'columns.ship_address.visible', "ng-bind" => '::customer.ship_address | limitTo: 15' } + %a{ href: '#', "ng-bind" => '::customer.bill_address.address1 | limitTo: 15', 'edit-address-dialog' => true } + %td.ship_address{ 'ng-show' => 'columns.ship_address.visible', "ng-bind" => '::customer.ship_address.address1 | limitTo: 15' } %td.actions %a{ 'ng-click' => "deleteCustomer(customer)", :class => "delete-customer icon-trash no-text" } diff --git a/spec/serializers/admin/customer_serializer_spec.rb b/spec/serializers/admin/customer_serializer_spec.rb index ad4b75db49..5694b1004f 100644 --- a/spec/serializers/admin/customer_serializer_spec.rb +++ b/spec/serializers/admin/customer_serializer_spec.rb @@ -12,7 +12,8 @@ describe Api::Admin::CustomerSerializer do expect(tags[0]).to eq({ "text" => 'one', "rules" => nil }) expect(tags[1]).to eq({ "text" => 'two', "rules" => 1 }) - expect(result['bill_address']).to eq customer.bill_address.address1 + expect(result['bill_address']['id']).to eq customer.bill_address.id + expect(result['bill_address']['address1']).to eq customer.bill_address.address1 expect(result['ship_address']).to be nil end end