pull/9782/head
Oliver Günther 3 years ago
parent 2c5a12c19e
commit 0942947234
No known key found for this signature in database
GPG Key ID: A3A8BDAD7C0C552C
  1. 4
      .rubocop.yml
  2. 55
      app/controllers/work_packages_controller.rb
  3. 2
      app/models/exports/concerns/csv.rb
  4. 2
      app/workers/exports/export_job.rb
  5. 2
      modules/xls_export/app/models/xls_export/concerns/spreadsheet_builder.rb
  6. 12
      modules/xls_export/spec/lib/custom_field_xls_export_spec.rb
  7. 4
      spec/features/projects/export_spec.rb
  8. 2
      spec/models/projects/exporter/exportable_project_context.rb
  9. 4
      spec/workers/work_packages/exports/export_job_spec.rb

@ -26,6 +26,10 @@ Layout/LineLength:
Layout/MultilineMethodCallIndentation:
Enabled: false
# Rubymine doesn't support the same indentation style
# and will auto-format against it with our editorconfig
Layout/MultilineOperationIndentation:
Enabled: false
Lint/AmbiguousOperator:
Enabled: false

@ -87,9 +87,9 @@ class WorkPackagesController < ApplicationController
def export_list(mime_type)
job_id = WorkPackages::Exports::ScheduleService
.new(user: current_user)
.call(query: @query, mime_type: mime_type, params: params)
.result
.new(user: current_user)
.call(query: @query, mime_type: mime_type, params: params)
.result
if request.headers['Accept']&.include?('application/json')
render json: { job_id: job_id }
@ -100,8 +100,8 @@ class WorkPackagesController < ApplicationController
def export_single(mime_type)
exporter = Exports::Register
.single_exporter(WorkPackage, mime_type)
.new(work_package, params)
.single_exporter(WorkPackage, mime_type)
.new(work_package, params)
export = exporter.export!
send_data(export.content, type: export.mime_type, filename: export.title)
@ -131,7 +131,7 @@ class WorkPackagesController < ApplicationController
def protect_from_unauthorized_export
if (supported_list_formats + %w[atom]).include?(params[:format]) &&
!User.current.allowed_to?(:export_work_packages, @project, global: @project.nil?)
!User.current.allowed_to?(:export_work_packages, @project, global: @project.nil?)
deny_access
false
@ -177,19 +177,19 @@ class WorkPackagesController < ApplicationController
def journals
@journals ||= begin
order =
if current_user.wants_comments_in_reverse_order?
Journal.arel_table['created_at'].desc
else
Journal.arel_table['created_at'].asc
end
work_package
.journals
.changing
.includes(:user)
.order(order).to_a
end
order =
if current_user.wants_comments_in_reverse_order?
Journal.arel_table['created_at'].desc
else
Journal.arel_table['created_at'].asc
end
work_package
.journals
.changing
.includes(:user)
.order(order).to_a
end
end
def index_redirect_path
@ -202,14 +202,15 @@ class WorkPackagesController < ApplicationController
def load_work_packages
@results = @query.results
@work_packages = if @query.valid?
@results
.work_packages
.page(page_param)
.per_page(per_page_param)
else
[]
end
@work_packages =
if @query.valid?
@results
.work_packages
.page(page_param)
.per_page(per_page_param)
else
[]
end
end
def login_back_url_params

@ -61,7 +61,7 @@ module Exports
# fetch all headers
def csv_headers
headers = columns.map { |c| c[:caption] }
headers = columns.pluck(:caption)
# because of
# https://support.microsoft.com/en-us/help/323626/-sylk-file-format-is-not-valid-error-message-when-you-open-file

@ -85,7 +85,7 @@ module Exports
end
def with_tempfile(title, content)
name_parts = [title[0..title.rindex('.') - 1], title[title.rindex('.')..-1]]
name_parts = [title[0..title.rindex('.') - 1], title[title.rindex('.')..]]
Tempfile.create(name_parts, encoding: content.encoding) do |file|
file.write content

@ -79,7 +79,7 @@ module XlsExport
def xls_export_filename
sane_filename(
"#{Setting.app_title} #{spreadsheet_title} \
#{format_time_as_date(Time.now, '%Y-%m-%d')}.xls"
#{format_time_as_date(Time.zone.now, '%Y-%m-%d')}.xls"
)
end
end

@ -16,12 +16,6 @@ describe "WorkPackageXlsExport Custom Fields" do
)
end
def custom_values_for(*values)
values.map do |str|
custom_field.custom_options.find { |co| co.value == str }.try(:id)
end
end
let(:work_package1) do
wp = FactoryBot.create :work_package, project: project, type: type
wp.custom_field_values = {
@ -66,6 +60,12 @@ describe "WorkPackageXlsExport Custom Fields" do
Spreadsheet.open(io).worksheets.first
end
def custom_values_for(*values)
values.map do |str|
custom_field.custom_options.find { |co| co.value == str }.try(:id)
end
end
it 'produces the valid XLS result' do
expect(query.columns.map(&:name)).to eq [:subject, :"cf_#{custom_field.id}"]
expect(sheet.rows.first.take(2)).to eq ['Subject', 'Ingredients']

@ -50,9 +50,9 @@ describe 'project export', type: :feature, js: true do
DownloadList.clear
end
subject { @download_list.refresh_from(page).latest_downloaded_content }
subject { @download_list.refresh_from(page).latest_downloaded_content } # rubocop:disable RSpec/InstanceVariable
def export!(expect_success = true)
def export!(expect_success: true)
index_page.click_more_menu_item 'Export'
click_on export_type

@ -56,7 +56,7 @@ shared_context 'with a project with an arrangement of custom fields' do
p.send(:"custom_field_#{float_cf.id}=", 4.5)
p.send(:"custom_field_#{text_cf.id}=", 'Some **long** text')
p.send(:"custom_field_#{string_cf.id}=", 'Some small text')
p.send(:"custom_field_#{date_cf.id}=", Date.today)
p.send(:"custom_field_#{date_cf.id}=", Time.zone.today)
p.send(:"custom_field_#{user_cf.id}=", other_user)
p.build_status(code: :off_track)

@ -64,7 +64,7 @@ describe WorkPackages::Exports::ExportJob do
mime_type: "application/octet-stream")
end
let(:service) { double('attachments create service') }
let(:service) { double('attachments create service') } # rubocop:disable RSpec/VerifiedDoubles
let(:exporter_instance) { instance_double(exporter) }
it 'exports' do
@ -106,7 +106,7 @@ describe WorkPackages::Exports::ExportJob do
let(:exporter) { WorkPackage::PDFExport::WorkPackageListToPdf }
it 'updates the query from attributes' do
expect(exporter)
allow(exporter)
.to receive(:new) do |query, _options|
expect(query.group_by).to eq 'assigned_to'
end

Loading…
Cancel
Save