From 5610e7967bdf83f7f0a4f860f2b8e26320d67dfa Mon Sep 17 00:00:00 2001 From: Xaun Lopez Date: Tue, 31 Oct 2017 16:37:31 +0000 Subject: [PATCH] Fully qualify dashboard template paths Allows concern to be included in different modules --- .../v1/impac/dashboards/index.json.jbuilder | 3 ++- .../v1/impac/dashboards/show.json.jbuilder | 3 ++- .../jpi/v1/impac/dashboards_controller.rb | 21 ++++++++++++------- .../v1/impac/dashboards_controller_spec.rb | 9 ++++---- 4 files changed, 22 insertions(+), 14 deletions(-) diff --git a/api/app/views/mno_enterprise/jpi/v1/impac/dashboards/index.json.jbuilder b/api/app/views/mno_enterprise/jpi/v1/impac/dashboards/index.json.jbuilder index 7620a1b53..9f1948b37 100644 --- a/api/app/views/mno_enterprise/jpi/v1/impac/dashboards/index.json.jbuilder +++ b/api/app/views/mno_enterprise/jpi/v1/impac/dashboards/index.json.jbuilder @@ -1 +1,2 @@ -json.array! @dashboards, partial: 'dashboard', as: :dashboard +# Fully qualify template path to allow concern to be included in different modules +json.array! @dashboards, partial: 'mno_enterprise/jpi/v1/impac/dashboards/dashboard', as: :dashboard diff --git a/api/app/views/mno_enterprise/jpi/v1/impac/dashboards/show.json.jbuilder b/api/app/views/mno_enterprise/jpi/v1/impac/dashboards/show.json.jbuilder index bb62d73d5..90c23430f 100644 --- a/api/app/views/mno_enterprise/jpi/v1/impac/dashboards/show.json.jbuilder +++ b/api/app/views/mno_enterprise/jpi/v1/impac/dashboards/show.json.jbuilder @@ -1 +1,2 @@ -json.partial! 'dashboard', dashboard: @dashboard +# Fully qualify template path to allow concern to be included in different modules +json.partial! 'mno_enterprise/jpi/v1/impac/dashboards/dashboard', dashboard: @dashboard diff --git a/api/lib/mno_enterprise/concerns/controllers/jpi/v1/impac/dashboards_controller.rb b/api/lib/mno_enterprise/concerns/controllers/jpi/v1/impac/dashboards_controller.rb index 01a17a48f..41700ae06 100644 --- a/api/lib/mno_enterprise/concerns/controllers/jpi/v1/impac/dashboards_controller.rb +++ b/api/lib/mno_enterprise/concerns/controllers/jpi/v1/impac/dashboards_controller.rb @@ -18,12 +18,18 @@ module MnoEnterprise::Concerns::Controllers::Jpi::V1::Impac::DashboardsControlle # GET /mnoe/jpi/v1/impac/dashboards def index dashboards + + # Fully qualify template path to allow concern to be included in different modules + render template: 'mno_enterprise/jpi/v1/impac/dashboards/index' end # GET /mnoe/jpi/v1/impac/dashboards/1 # -> GET /api/mnoe/v1/users/1/dashboards def show render_not_found('dashboard') unless dashboard(*DASHBOARD_DEPENDENCIES) + + # Fully qualify template path to allow concern to be included in different modules + render template: 'mno_enterprise/jpi/v1/impac/dashboards/show' end # POST /mnoe/jpi/v1/impac/dashboards @@ -36,7 +42,9 @@ def create dashboard.save! MnoEnterprise::EventLogger.info('dashboard_create', current_user.id, 'Dashboard Creation', dashboard) @dashboard = dashboard.load_required(*DASHBOARD_DEPENDENCIES) - render 'show' + + # Fully qualify template path to allow concern to be included in different modules + render template: 'mno_enterprise/jpi/v1/impac/dashboards/show' end # PUT /mnoe/jpi/v1/impac/dashboards/1 @@ -50,7 +58,9 @@ def update # Reload Dashboard @dashboard = dashboard.load_required(DASHBOARD_DEPENDENCIES) - render 'show' + + # Fully qualify template path to allow concern to be included in different modules + render template: 'mno_enterprise/jpi/v1/impac/dashboards/show' end # DELETE /mnoe/jpi/v1/impac/dashboards/1 @@ -80,14 +90,11 @@ def copy private def dashboard(*included) - @dashboard ||= MnoEnterprise::Dashboard.where(id: params[:id]) - .includes(included) - .first + @dashboard ||= MnoEnterprise::Dashboard.includes(included).find(params[:id]).first end def dashboards - @dashboards ||= MnoEnterprise::Dashboard.where(owner_id: current_user.id) - .includes(*DASHBOARD_DEPENDENCIES) + @dashboards ||= MnoEnterprise::Dashboard.includes(*DASHBOARD_DEPENDENCIES).where(owner_id: current_user.id) end def templates diff --git a/api/spec/controllers/mno_enterprise/jpi/v1/impac/dashboards_controller_spec.rb b/api/spec/controllers/mno_enterprise/jpi/v1/impac/dashboards_controller_spec.rb index f7b41e054..7b0561c17 100644 --- a/api/spec/controllers/mno_enterprise/jpi/v1/impac/dashboards_controller_spec.rb +++ b/api/spec/controllers/mno_enterprise/jpi/v1/impac/dashboards_controller_spec.rb @@ -104,7 +104,7 @@ def hash_for_kpi(kpi) describe 'GET #show' do before do - stub_api_v2(:get, "/dashboards/#{dashboard.id}", dashboard, dashboard_dependencies, {filter: {owner_id: user.id}}) + stub_api_v2(:get, "/dashboards/#{dashboard.id}", dashboard, dashboard_dependencies) end subject { get :show, id: dashboard.id } @@ -154,7 +154,6 @@ def hash_for_kpi(kpi) expect(errors[:errors][:message]).to eq('Internal server error') end end - end describe 'PUT #update' do @@ -164,8 +163,8 @@ def hash_for_kpi(kpi) before do # TODO: APIv2 Improve contrroller code to do less requests? stub_api_v2(:get, "/dashboards/#{dashboard.id}", [dashboard], dashboard_dependencies) - stub_api_v2(:get, "/dashboards/#{dashboard.id}", [dashboard], [], filter: { owner_id: user.id }) - stub_api_v2(:get, "/dashboards/#{dashboard.id}", [dashboard], dashboard_dependencies, filter: { owner_id: user.id }) + stub_api_v2(:get, "/dashboards/#{dashboard.id}", [dashboard]) + stub_api_v2(:get, "/dashboards/#{dashboard.id}", [dashboard], dashboard_dependencies) end it_behaves_like 'jpi v1 protected action' @@ -194,7 +193,7 @@ def hash_for_kpi(kpi) subject { delete :destroy, id: dashboard.id } let!(:stub) { stub_api_v2(:delete, "/dashboards/#{dashboard.id}") } before do - stub_api_v2(:get, "/dashboards/#{dashboard.id}", [dashboard], [], filter: { owner_id: user.id }) + stub_api_v2(:get, "/dashboards/#{dashboard.id}", [dashboard]) end it_behaves_like 'jpi v1 protected action'