From 3ca697dab768b2eaf6ae801b1e418f0b39e17396 Mon Sep 17 00:00:00 2001 From: Billy Zhou Date: Tue, 11 Dec 2018 22:16:27 +0800 Subject: [PATCH] Fixed #2398 - Missing custom object in database causes error on export in time_accounting --- app/controllers/reports_controller.rb | 1 + .../time_accountings_controller.rb | 1 + spec/requests/time_accounting_spec.rb | 22 +++++++++++++++++++ 3 files changed, 24 insertions(+) diff --git a/app/controllers/reports_controller.rb b/app/controllers/reports_controller.rb index be1ae6a4c..350e65b6d 100644 --- a/app/controllers/reports_controller.rb +++ b/app/controllers/reports_controller.rb @@ -219,6 +219,7 @@ class ReportsController < ApplicationController # needs to be skipped objects = ObjectManager::Attribute.where(editable: true, active: true, + to_create: false, object_lookup_id: ObjectLookup.lookup(name: 'Ticket').id) .pluck(:name, :display, :data_type, :data_option) .map { |name, display, data_type, data_option| { name: name, display: display, data_type: data_type, data_option: data_option } } diff --git a/app/controllers/time_accountings_controller.rb b/app/controllers/time_accountings_controller.rb index 1d71789e3..002abbe88 100644 --- a/app/controllers/time_accountings_controller.rb +++ b/app/controllers/time_accountings_controller.rb @@ -165,6 +165,7 @@ class TimeAccountingsController < ApplicationController ] objects = ObjectManager::Attribute.where(editable: true, active: true, + to_create: false, object_lookup_id: ObjectLookup.lookup(name: 'Ticket').id) .pluck(:name, :display, :data_type, :data_option) .map { |name, display, data_type, data_option| { name: name, display: display, data_type: data_type, data_option: data_option } } diff --git a/spec/requests/time_accounting_spec.rb b/spec/requests/time_accounting_spec.rb index 096f9e9d2..56150f0cb 100644 --- a/spec/requests/time_accounting_spec.rb +++ b/spec/requests/time_accounting_spec.rb @@ -39,5 +39,27 @@ RSpec.describe 'Time Accounting API endpoints', type: :request do expect(response['Content-Type']).to eq('application/vnd.ms-excel') end end + + # Regression test for issue #2398 - Missing custom object in database causes error on export in time_accounting + # This test is identical to the above one, except with the added step of a pending migration in the beginning + context 'with pending attribute migrations, requesting a log report download' do + it 'responds with an Excel spreadsheet' do + ObjectManager::Attribute.add attributes_for :object_manager_attribute_select + + group = create(:group) + ticket = create(:ticket, state: Ticket::State.lookup(name: 'open'), customer: customer ) + article = create(:ticket_article, ticket: ticket, type: Ticket::Article::Type.lookup(name: 'note') ) + + create(:ticket_time_accounting, ticket_id: ticket.id, ticket_article_id: article.id) + + authenticated_as(admin) + get "/api/v1/time_accounting/log/by_ticket/#{year}/#{month}?download=true", params: {} + + expect(response).to have_http_status(200) + expect(response['Content-Disposition']).to be_truthy + expect(response['Content-Disposition']).to eq("attachment; filename=\"by_ticket-#{year}-#{month}.xls\"") + expect(response['Content-Type']).to eq('application/vnd.ms-excel') + end + end end end