Skip to content

Commit

Permalink
Fixed #2398 - Missing custom object in database causes error on expor…
Browse files Browse the repository at this point in the history
…t in time_accounting

(cherry picked from commit 3ca697d)
  • Loading branch information
Billy Zhou committed Dec 17, 2018
1 parent b36f6e2 commit 9bcd07c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/controllers/reports_controller.rb
Expand Up @@ -219,6 +219,7 @@ def sheet(profile, title, result)
# 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 } }
Expand Down
1 change: 1 addition & 0 deletions app/controllers/time_accountings_controller.rb
Expand Up @@ -165,6 +165,7 @@ def by_ticket
]
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 } }
Expand Down
22 changes: 22 additions & 0 deletions spec/requests/time_accounting_spec.rb
Expand Up @@ -39,5 +39,27 @@
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

0 comments on commit 9bcd07c

Please sign in to comment.