rename content_type to time_span_type for archives

This commit is contained in:
Christophe Robillard 2021-04-27 18:54:58 +02:00
parent 9134114c2e
commit dfbe004122
7 changed files with 24 additions and 19 deletions

View file

@ -2,12 +2,12 @@
#
# Table name: archives
#
# id :bigint not null, primary key
# content_type :string not null
# month :date
# status :string not null
# created_at :datetime not null
# updated_at :datetime not null
# id :bigint not null, primary key
# month :date
# status :string not null
# time_span_type :string not null
# created_at :datetime not null
# updated_at :datetime not null
#
class Archive < ApplicationRecord
include AASM
@ -26,7 +26,7 @@ class Archive < ApplicationRecord
)
}
enum content_type: {
enum time_span_type: {
everything: 'everything',
monthly: 'monthly'
}
@ -50,7 +50,7 @@ class Archive < ApplicationRecord
end
def filename(procedure)
if content_type == 'everything'
if time_span_type == 'everything'
"procedure-#{procedure.id}.zip"
else
"procedure-#{procedure.id}-mois-#{I18n.l(month, format: '%Y-%m')}.zip"

View file

@ -11,7 +11,7 @@ class ProcedureArchiveService
.where(procedure: @procedure)
archive = Archive.for_groupe_instructeur(groupe_instructeurs).find_by(
content_type: type,
time_span_type: type,
month: month
)
if archive.nil?
@ -25,7 +25,7 @@ class ProcedureArchiveService
end
def collect_files_archive(archive, instructeur)
if archive.content_type == 'everything'
if archive.time_span_type == 'everything'
dossiers = @procedure.dossiers.state_termine
else
dossiers = @procedure.dossiers.processed_in_month(archive.month)

View file

@ -32,7 +32,7 @@
%tbody
- if can_generate_archive?(@dossiers_termines, @poids_total)
%tr
- matching_archive = @archives.find_by(content_type: 'everything')
- matching_archive = @archives.find_by(time_span_type: 'everything')
%td
Tous les dossiers
%td
@ -60,7 +60,7 @@
- @archivable_months.each do |month|
- dossiers_termines = @procedure.dossiers.processed_in_month(month)
- nb_dossiers_termines = dossiers_termines.count
- matching_archive = @archives.find_by(content_type: 'monthly', month: month)
- matching_archive = @archives.find_by(time_span_type: 'monthly', month: month)
%tr
%td
= I18n.l(month, format: "%B %Y")

View file

@ -0,0 +1,5 @@
class RenameContentTypeToToTimeSpanTypeForArchives < ActiveRecord::Migration[6.1]
def change
rename_column :archives, :content_type, :time_span_type
end
end

View file

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2021_04_27_120002) do
ActiveRecord::Schema.define(version: 2021_04_27_112642) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -84,7 +84,7 @@ ActiveRecord::Schema.define(version: 2021_04_27_120002) do
create_table "archives", force: :cascade do |t|
t.string "status", null: false
t.date "month"
t.string "content_type", null: false
t.string "time_span_type", null: false
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
end

View file

@ -1,6 +1,6 @@
FactoryBot.define do
factory :archive do
content_type { 'everything' }
time_span_type { 'everything' }
groupe_instructeurs { [association(:groupe_instructeur)] }
trait :pending do

View file

@ -10,7 +10,7 @@ describe ProcedureArchiveService do
it 'creates a pending archive' do
archive = service.create_pending_archive(instructeur, 'monthly', date_month)
expect(archive.content_type).to eq 'monthly'
expect(archive.time_span_type).to eq 'monthly'
expect(archive.month).to eq date_month
expect(archive.pending?).to be_truthy
end
@ -20,7 +20,7 @@ describe ProcedureArchiveService do
it 'creates a pending archive' do
archive = service.create_pending_archive(instructeur, 'everything')
expect(archive.content_type).to eq 'everything'
expect(archive.time_span_type).to eq 'everything'
expect(archive.month).to eq nil
expect(archive.pending?).to be_truthy
end
@ -36,7 +36,7 @@ describe ProcedureArchiveService do
after { Timecop.return }
context 'for a specific month' do
let(:archive) { create(:archive, content_type: 'monthly', status: 'pending', month: date_month) }
let(:archive) { create(:archive, time_span_type: 'monthly', status: 'pending', month: date_month) }
let(:year) { 2021 }
let(:mailer) { double('mailer', deliver_later: true) }
@ -56,7 +56,7 @@ describe ProcedureArchiveService do
end
context 'for all months' do
let(:archive) { create(:archive, content_type: 'everything', status: 'pending') }
let(:archive) { create(:archive, time_span_type: 'everything', status: 'pending') }
let(:mailer) { double('mailer', deliver_later: true) }
it 'collect files' do