rename content_type to time_span_type for archives
This commit is contained in:
parent
9134114c2e
commit
dfbe004122
7 changed files with 24 additions and 19 deletions
|
@ -2,12 +2,12 @@
|
||||||
#
|
#
|
||||||
# Table name: archives
|
# Table name: archives
|
||||||
#
|
#
|
||||||
# id :bigint not null, primary key
|
# id :bigint not null, primary key
|
||||||
# content_type :string not null
|
# month :date
|
||||||
# month :date
|
# status :string not null
|
||||||
# status :string not null
|
# time_span_type :string not null
|
||||||
# created_at :datetime not null
|
# created_at :datetime not null
|
||||||
# updated_at :datetime not null
|
# updated_at :datetime not null
|
||||||
#
|
#
|
||||||
class Archive < ApplicationRecord
|
class Archive < ApplicationRecord
|
||||||
include AASM
|
include AASM
|
||||||
|
@ -26,7 +26,7 @@ class Archive < ApplicationRecord
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
enum content_type: {
|
enum time_span_type: {
|
||||||
everything: 'everything',
|
everything: 'everything',
|
||||||
monthly: 'monthly'
|
monthly: 'monthly'
|
||||||
}
|
}
|
||||||
|
@ -50,7 +50,7 @@ class Archive < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def filename(procedure)
|
def filename(procedure)
|
||||||
if content_type == 'everything'
|
if time_span_type == 'everything'
|
||||||
"procedure-#{procedure.id}.zip"
|
"procedure-#{procedure.id}.zip"
|
||||||
else
|
else
|
||||||
"procedure-#{procedure.id}-mois-#{I18n.l(month, format: '%Y-%m')}.zip"
|
"procedure-#{procedure.id}-mois-#{I18n.l(month, format: '%Y-%m')}.zip"
|
||||||
|
|
|
@ -11,7 +11,7 @@ class ProcedureArchiveService
|
||||||
.where(procedure: @procedure)
|
.where(procedure: @procedure)
|
||||||
|
|
||||||
archive = Archive.for_groupe_instructeur(groupe_instructeurs).find_by(
|
archive = Archive.for_groupe_instructeur(groupe_instructeurs).find_by(
|
||||||
content_type: type,
|
time_span_type: type,
|
||||||
month: month
|
month: month
|
||||||
)
|
)
|
||||||
if archive.nil?
|
if archive.nil?
|
||||||
|
@ -25,7 +25,7 @@ class ProcedureArchiveService
|
||||||
end
|
end
|
||||||
|
|
||||||
def collect_files_archive(archive, instructeur)
|
def collect_files_archive(archive, instructeur)
|
||||||
if archive.content_type == 'everything'
|
if archive.time_span_type == 'everything'
|
||||||
dossiers = @procedure.dossiers.state_termine
|
dossiers = @procedure.dossiers.state_termine
|
||||||
else
|
else
|
||||||
dossiers = @procedure.dossiers.processed_in_month(archive.month)
|
dossiers = @procedure.dossiers.processed_in_month(archive.month)
|
||||||
|
|
|
@ -32,7 +32,7 @@
|
||||||
%tbody
|
%tbody
|
||||||
- if can_generate_archive?(@dossiers_termines, @poids_total)
|
- if can_generate_archive?(@dossiers_termines, @poids_total)
|
||||||
%tr
|
%tr
|
||||||
- matching_archive = @archives.find_by(content_type: 'everything')
|
- matching_archive = @archives.find_by(time_span_type: 'everything')
|
||||||
%td
|
%td
|
||||||
Tous les dossiers
|
Tous les dossiers
|
||||||
%td
|
%td
|
||||||
|
@ -60,7 +60,7 @@
|
||||||
- @archivable_months.each do |month|
|
- @archivable_months.each do |month|
|
||||||
- dossiers_termines = @procedure.dossiers.processed_in_month(month)
|
- dossiers_termines = @procedure.dossiers.processed_in_month(month)
|
||||||
- nb_dossiers_termines = dossiers_termines.count
|
- 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
|
%tr
|
||||||
%td
|
%td
|
||||||
= I18n.l(month, format: "%B %Y")
|
= I18n.l(month, format: "%B %Y")
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
class RenameContentTypeToToTimeSpanTypeForArchives < ActiveRecord::Migration[6.1]
|
||||||
|
def change
|
||||||
|
rename_column :archives, :content_type, :time_span_type
|
||||||
|
end
|
||||||
|
end
|
|
@ -10,7 +10,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# 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
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "plpgsql"
|
enable_extension "plpgsql"
|
||||||
|
@ -84,7 +84,7 @@ ActiveRecord::Schema.define(version: 2021_04_27_120002) do
|
||||||
create_table "archives", force: :cascade do |t|
|
create_table "archives", force: :cascade do |t|
|
||||||
t.string "status", null: false
|
t.string "status", null: false
|
||||||
t.date "month"
|
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 "created_at", precision: 6, null: false
|
||||||
t.datetime "updated_at", precision: 6, null: false
|
t.datetime "updated_at", precision: 6, null: false
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
FactoryBot.define do
|
FactoryBot.define do
|
||||||
factory :archive do
|
factory :archive do
|
||||||
content_type { 'everything' }
|
time_span_type { 'everything' }
|
||||||
groupe_instructeurs { [association(:groupe_instructeur)] }
|
groupe_instructeurs { [association(:groupe_instructeur)] }
|
||||||
|
|
||||||
trait :pending do
|
trait :pending do
|
||||||
|
|
|
@ -10,7 +10,7 @@ describe ProcedureArchiveService do
|
||||||
it 'creates a pending archive' do
|
it 'creates a pending archive' do
|
||||||
archive = service.create_pending_archive(instructeur, 'monthly', date_month)
|
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.month).to eq date_month
|
||||||
expect(archive.pending?).to be_truthy
|
expect(archive.pending?).to be_truthy
|
||||||
end
|
end
|
||||||
|
@ -20,7 +20,7 @@ describe ProcedureArchiveService do
|
||||||
it 'creates a pending archive' do
|
it 'creates a pending archive' do
|
||||||
archive = service.create_pending_archive(instructeur, 'everything')
|
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.month).to eq nil
|
||||||
expect(archive.pending?).to be_truthy
|
expect(archive.pending?).to be_truthy
|
||||||
end
|
end
|
||||||
|
@ -36,7 +36,7 @@ describe ProcedureArchiveService do
|
||||||
after { Timecop.return }
|
after { Timecop.return }
|
||||||
|
|
||||||
context 'for a specific month' do
|
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(:year) { 2021 }
|
||||||
let(:mailer) { double('mailer', deliver_later: true) }
|
let(:mailer) { double('mailer', deliver_later: true) }
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ describe ProcedureArchiveService do
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'for all months' do
|
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) }
|
let(:mailer) { double('mailer', deliver_later: true) }
|
||||||
|
|
||||||
it 'collect files' do
|
it 'collect files' do
|
||||||
|
|
Loading…
Add table
Reference in a new issue