Skip to content

Commit

Permalink
Fully qualify dashboard template paths
Browse files Browse the repository at this point in the history
Allows concern to be included in different modules
  • Loading branch information
xaun authored and x4d3 committed Nov 9, 2017
1 parent 46839bf commit 5610e79
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -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
Expand All @@ -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'

Expand Down Expand Up @@ -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'

Expand Down

0 comments on commit 5610e79

Please sign in to comment.