Fixed #2398 - Missing custom object in database causes error on export in time_accounting

This commit is contained in:
Billy Zhou 2018-12-11 22:16:27 +08:00
parent 805bbcb542
commit 3ca697dab7
3 changed files with 24 additions and 0 deletions

View file

@ -219,6 +219,7 @@ class ReportsController < ApplicationController
# needs to be skipped # needs to be skipped
objects = ObjectManager::Attribute.where(editable: true, objects = ObjectManager::Attribute.where(editable: true,
active: true, active: true,
to_create: false,
object_lookup_id: ObjectLookup.lookup(name: 'Ticket').id) object_lookup_id: ObjectLookup.lookup(name: 'Ticket').id)
.pluck(:name, :display, :data_type, :data_option) .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 } } .map { |name, display, data_type, data_option| { name: name, display: display, data_type: data_type, data_option: data_option } }

View file

@ -165,6 +165,7 @@ class TimeAccountingsController < ApplicationController
] ]
objects = ObjectManager::Attribute.where(editable: true, objects = ObjectManager::Attribute.where(editable: true,
active: true, active: true,
to_create: false,
object_lookup_id: ObjectLookup.lookup(name: 'Ticket').id) object_lookup_id: ObjectLookup.lookup(name: 'Ticket').id)
.pluck(:name, :display, :data_type, :data_option) .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 } } .map { |name, display, data_type, data_option| { name: name, display: display, data_type: data_type, data_option: data_option } }

View file

@ -39,5 +39,27 @@ RSpec.describe 'Time Accounting API endpoints', type: :request do
expect(response['Content-Type']).to eq('application/vnd.ms-excel') expect(response['Content-Type']).to eq('application/vnd.ms-excel')
end end
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
end end