Skip to content

Commit

Permalink
fix a few tests related to reports
Browse files Browse the repository at this point in the history
  • Loading branch information
anderson-mj committed Sep 11, 2024
1 parent e3884eb commit c9b00a1
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion app/models/report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ class Report < ApplicationRecord
attr_accessor :identifier
# relations
belongs_to :user, foreign_key: "generated_by_id"
belongs_to :carrierwave_file, foreign_key: "carrierwave_file_id", class_name: "CarrierWave::Storage::ActiveRecord::ActiveRecordFile"
belongs_to :carrierwave_file, foreign_key: "carrierwave_file_id", class_name: "CarrierWave::Storage::ActiveRecord::ActiveRecordFile", optional: true
end
2 changes: 1 addition & 1 deletion lib/tasks/maintenance.rake
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace :maintenance do
expired_reports.map do |expired_report|
carrierwave_file = expired_report.carrierwave_file
expired_report.update!(carrierwave_file_id: nil)
carrierwave_file.delete!
carrierwave_file.delete
end

Rails.logger.info "[Reports] #{Time.now.to_fs} Finished removing reports"
Expand Down
3 changes: 2 additions & 1 deletion spec/factories/factory_report_configurations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use_at_schedule { false }
text { "MyText" }
image { "MyString" }
signature_footer { false }
signature_type { 1 }
expiration_in_months { nil }
end
end
4 changes: 2 additions & 2 deletions spec/features/report_configurations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@
it "should show table" do
expect(page).to have_content "Configurações de relatório"
expect(page.all("tr th").map(&:text)).to eq [
"Nome", "Prioridade", "Header", "Rodapé com assinatura", "Usar em relatórios", "Usar no histórico", "Usar no boletim", "Usar no quadro de horários", ""
"Nome", "Prioridade", "Header", "Tipo de Assinatura", "Usar em relatórios", "Usar no histórico", "Usar no boletim", "Usar no quadro de horários", "Validade (meses)", ""
]
end

it "should sort the list by name, asc" do
expect(page.all("tr td.name-column").map(&:text)).to eq ["Boletim", "Histórico", "Padrão"]
expect(page.all("tr td.name-column").map(&:text)).to eq %w[Boletim Histórico Padrão]
end
end

Expand Down
7 changes: 7 additions & 0 deletions spec/models/report_configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,12 @@
it { should validate_presence_of(:x) }
it { should validate_presence_of(:y) }
it { should validate_presence_of(:scale) }
it { should validate_numericality_of(:expiration_in_months).only_integer.is_greater_than(0).allow_nil }
it "expiration_in_months_only_for_qr_code" do
query.signature_type = "manual"
query.expiration_in_months = 1
query.valid?
expect(query.errors[:expiration_in_months]).to include(I18n.t("activerecord.errors.models.report_configuration.attributes.expiration_in_months.only_for_qr_code"))
end
end
end

0 comments on commit c9b00a1

Please sign in to comment.