From 4e45a682fd6e93a54b273fda611091c6a286854d Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Tue, 3 Jun 2014 11:29:07 +1000 Subject: [PATCH] Do not show deleted products in order cycle admin --- .../admin/enterprises/_supplied_product.rabl | 10 ++++++++++ app/views/admin/enterprises/index.rabl | 11 +++-------- spec/views/admin/enterprises/index.rabl_spec.rb | 15 +++++++++++++++ 3 files changed, 28 insertions(+), 8 deletions(-) create mode 100644 app/views/admin/enterprises/_supplied_product.rabl create mode 100644 spec/views/admin/enterprises/index.rabl_spec.rb diff --git a/app/views/admin/enterprises/_supplied_product.rabl b/app/views/admin/enterprises/_supplied_product.rabl new file mode 100644 index 0000000000..268ff302d5 --- /dev/null +++ b/app/views/admin/enterprises/_supplied_product.rabl @@ -0,0 +1,10 @@ +object @product + +attributes :name +node(:supplier_name) { |p| p.supplier.andand.name } +node(:image_url) { |p| p.images.present? ? p.images.first.attachment.url(:mini) : nil } +node(:master_id) { |p| p.master.id } +child variants: :variants do |variant| + attributes :id + node(:label) { |v| v.options_text } +end diff --git a/app/views/admin/enterprises/index.rabl b/app/views/admin/enterprises/index.rabl index 9e1ee893d1..1342d6eb1a 100644 --- a/app/views/admin/enterprises/index.rabl +++ b/app/views/admin/enterprises/index.rabl @@ -2,13 +2,8 @@ collection @collection attributes :id, :name -child supplied_products: :supplied_products do |product| - attributes :name - node(:supplier_name) { |p| p.supplier.andand.name } - node(:image_url) { |p| p.images.present? ? p.images.first.attachment.url(:mini) : nil } - node(:master_id) { |p| p.master.id } - child variants: :variants do |variant| - attributes :id - node(:label) { |v| v.options_text } +node(:supplied_products) do |enterprise| + enterprise.supplied_products.not_deleted.map do |product| + partial 'admin/enterprises/supplied_product', object: product end end diff --git a/spec/views/admin/enterprises/index.rabl_spec.rb b/spec/views/admin/enterprises/index.rabl_spec.rb new file mode 100644 index 0000000000..e92388da61 --- /dev/null +++ b/spec/views/admin/enterprises/index.rabl_spec.rb @@ -0,0 +1,15 @@ +require 'spec_helper' + +describe "admin/enterprises/index.rabl" do + let(:enterprise) { create(:distributor_enterprise) } + let!(:product) { create(:simple_product, supplier: enterprise) } + let!(:deleted_product) { create(:simple_product, supplier: enterprise, deleted_at: Time.now) } + let(:render) { Rabl.render([enterprise], 'admin/enterprises/index', view_path: 'app/views', scope: RablHelper::FakeContext.instance) } + + describe "supplied products" do + it "does not render deleted products" do + render.should have_json_size(1).at_path '0/supplied_products' + render.should be_json_eql(product.master.id).at_path '0/supplied_products/0/master_id' + end + end +end