[Ref #144] Don't use Procedure.published anymore

This commit is contained in:
gregoirenovel 2017-07-11 14:21:10 +02:00
parent c2459da05b
commit f55b7914cf
12 changed files with 56 additions and 52 deletions

View file

@ -32,8 +32,8 @@ class Procedure < ActiveRecord::Base
mount_uploader :logo, ProcedureLogoUploader
default_scope { where(hidden_at: nil) }
scope :published, -> { where(published: true) }
scope :not_published, -> { where(published: false) }
scope :published, -> { where.not(published_at: nil) }
scope :not_published, -> { where(published_at: nil) }
scope :archived, -> { where(archived: true) }
scope :not_archived, -> { where(archived: false) }
scope :by_libelle, -> { order(libelle: :asc) }
@ -107,7 +107,7 @@ class Procedure < ActiveRecord::Base
types_de_champ_private: :drop_down_list
})
procedure.archived = false
procedure.published = false
procedure.published_at = nil
procedure.logo_secure_token = nil
procedure.remote_logo_url = self.logo_url
@ -121,10 +121,15 @@ class Procedure < ActiveRecord::Base
end
def publish!(path)
self.update_attributes!({ published: true, archived: false, published_at: Time.now })
self.update_attributes!({ published_at: Time.now, archived: false })
ProcedurePath.create!(path: path, procedure: self, administrateur: self.administrateur)
end
# FIXME: remove once the published colummn has been deleted
def published?
published_at.present?
end
def archive
self.update_attributes!(archived: true, archived_at: Time.now)
end

View file

@ -2,8 +2,8 @@ require 'spec_helper'
describe Admin::PiecesJustificativesController, type: :controller do
let(:admin) { create(:administrateur) }
let(:published) { false }
let(:procedure) { create(:procedure, administrateur: admin, published: published) }
let(:published_at) { nil }
let(:procedure) { create(:procedure, administrateur: admin, published_at: published_at) }
before do
sign_in admin
end
@ -19,7 +19,7 @@ describe Admin::PiecesJustificativesController, type: :controller do
end
context 'when procedure is published' do
let(:published) { true }
let(:published_at) { Time.now }
it { is_expected.to redirect_to admin_procedure_path id: procedure_id }
end

View file

@ -54,9 +54,9 @@ describe Admin::ProceduresController, type: :controller do
end
describe 'DELETE #destroy' do
let(:procedure_draft) { create :procedure, published: false, archived: false }
let(:procedure_published) { create :procedure, published: true, archived: false }
let(:procedure_archived) { create :procedure, published: false, archived: true }
let(:procedure_draft) { create :procedure, published_at: nil, archived: false }
let(:procedure_published) { create :procedure, published_at: Time.now, archived: false }
let(:procedure_archived) { create :procedure, published_at: nil, archived: true }
subject { delete :destroy, params: {id: procedure.id} }
@ -94,8 +94,8 @@ describe Admin::ProceduresController, type: :controller do
end
describe 'GET #edit' do
let(:published) { false }
let(:procedure) { create(:procedure, administrateur: admin, published: published) }
let(:published_at) { nil }
let(:procedure) { create(:procedure, administrateur: admin, published_at: published_at) }
let(:procedure_id) { procedure.id }
subject { get :edit, params: {id: procedure_id} }
@ -115,7 +115,7 @@ describe Admin::ProceduresController, type: :controller do
end
context 'when procedure is published' do
let(:published) { true }
let(:published_at) { Time.now }
it { is_expected.to have_http_status(:success) }
end
@ -297,7 +297,7 @@ describe Admin::ProceduresController, type: :controller do
let(:procedure_path) { 'new_path' }
it 'publish the given procedure' do
expect(procedure.published).to be_truthy
expect(procedure.published?).to be_truthy
expect(procedure.path).to eq(procedure_path)
expect(response.status).to eq 200
expect(flash[:notice]).to have_content 'Procédure publiée'
@ -308,14 +308,14 @@ describe Admin::ProceduresController, type: :controller do
let(:procedure_path) { procedure2.path }
it 'publish the given procedure' do
expect(procedure.published).to be_truthy
expect(procedure.published?).to be_truthy
expect(procedure.path).to eq(procedure_path)
expect(response.status).to eq 200
expect(flash[:notice]).to have_content 'Procédure publiée'
end
it 'archive previous procedure' do
expect(procedure2.published).to be_truthy
expect(procedure2.published?).to be_truthy
expect(procedure2.archived).to be_truthy
expect(procedure2.path).to be_nil
end
@ -325,13 +325,13 @@ describe Admin::ProceduresController, type: :controller do
let(:procedure_path) { procedure3.path }
it 'does not publish the given procedure' do
expect(procedure.published).to be_falsey
expect(procedure.published?).to be_falsey
expect(procedure.path).to be_nil
expect(response.status).to eq 200
end
it 'previous procedure remains published' do
expect(procedure2.published).to be_truthy
expect(procedure2.published?).to be_truthy
expect(procedure2.archived).to be_falsey
expect(procedure2.path).to match(/fake_path/)
end
@ -341,7 +341,7 @@ describe Admin::ProceduresController, type: :controller do
let(:procedure_path) { 'Invalid Procedure Path' }
it 'does not publish the given procedure' do
expect(procedure.published).to be_falsey
expect(procedure.published?).to be_falsey
expect(procedure.path).to be_nil
expect(response).to redirect_to :admin_procedures
expect(flash[:alert]).to have_content 'Lien de la procédure invalide'

View file

@ -9,8 +9,8 @@ describe Admin::TypesDeChampController, type: :controller do
end
describe 'GET #show' do
let(:published) { false }
let(:procedure) { create(:procedure, administrateur: admin, published: published) }
let(:published_at) { nil }
let(:procedure) { create(:procedure, administrateur: admin, published_at: published_at) }
let(:procedure_id) { procedure.id }
subject { get :show, params: {procedure_id: procedure_id} }
@ -21,7 +21,7 @@ describe Admin::TypesDeChampController, type: :controller do
end
context 'when procedure is published' do
let(:published) { true }
let(:published_at) { Time.now }
it { is_expected.to redirect_to admin_procedure_path id: procedure_id }
end

View file

@ -9,8 +9,8 @@ describe Admin::TypesDeChampPrivateController, type: :controller do
end
describe 'GET #show' do
let(:published) { false }
let(:procedure) { create(:procedure, administrateur: admin, published: published) }
let(:published_at) { nil }
let(:procedure) { create(:procedure, administrateur: admin, published_at: published_at) }
let(:procedure_id) { procedure.id }
subject { get :show, params: {procedure_id: procedure_id} }
@ -21,7 +21,7 @@ describe Admin::TypesDeChampPrivateController, type: :controller do
end
context 'when procedure is published' do
let(:published) { true }
let(:published_at) { Time.now }
it { is_expected.to redirect_to admin_procedure_path id: procedure_id }
end

View file

@ -118,18 +118,18 @@ describe StatsController, type: :controller do
before do
3.times do
create(:procedure, published: true, administrateur: administrateur_1)
create(:procedure, published_at: Time.now, administrateur: administrateur_1)
end
2.times do
create(:procedure, published: true, administrateur: administrateur_2)
create(:procedure, published_at: Time.now, administrateur: administrateur_2)
end
8.times do
create(:procedure, published: true, administrateur: administrateur_3)
create(:procedure, published_at: Time.now, administrateur: administrateur_3)
end
create(:procedure, published: true, administrateur: administrateur_4)
create(:procedure, published_at: Time.now, administrateur: administrateur_4)
end
let(:association){ Procedure.all }

View file

@ -140,7 +140,7 @@ describe Users::DossiersController, type: :controller do
end
context 'when procedure is not published' do
let(:procedure) { create(:procedure, published: false) }
let(:procedure) { create(:procedure, published_at: nil) }
before do
sign_in user

View file

@ -220,7 +220,7 @@ describe Users::SessionsController, type: :controller do
end
context 'when procedure is not published' do
let(:procedure) { create :procedure, published: false }
let(:procedure) { create :procedure, published_at: nil }
before do
session["user_return_to"] = "?procedure_id=#{procedure.id}"
end
@ -230,7 +230,7 @@ describe Users::SessionsController, type: :controller do
end
context 'when procedure_id exist' do
let(:procedure) { create :procedure, published: true }
let(:procedure) { create :procedure, published_at: Time.now }
before do
session["user_return_to"] = "?procedure_id=#{procedure.id}"

View file

@ -6,7 +6,7 @@ FactoryGirl.define do
description "Demande de subvention à l'intention des associations"
organisation "Orga SGMAP"
direction "direction SGMAP"
published false
published_at nil
cerfa_flag false
administrateur { create(:administrateur) }

View file

@ -2,8 +2,8 @@ require 'spec_helper'
feature 'procedure locked' do
let(:administrateur) { create(:administrateur) }
let(:published) { false }
let(:procedure) { create(:procedure, administrateur: administrateur, published: published) }
let (:published_at) { nil }
let(:procedure) { create(:procedure, administrateur: administrateur, published_at: published_at) }
before do
login_as administrateur, scope: :administrateur

View file

@ -370,14 +370,14 @@ describe Gestionnaire, type: :model do
end
context 'when no procedure published was active last week' do
let!(:procedure) { create(:procedure, gestionnaires: [gestionnaire2], libelle: 'procedure', published: true) }
let!(:procedure) { create(:procedure, gestionnaires: [gestionnaire2], libelle: 'procedure', published_at: Time.now) }
context 'when the gestionnaire has no notifications' do
it { is_expected.to eq(nil) }
end
end
context 'when a procedure published was active' do
let!(:procedure) { create(:procedure, gestionnaires: [gestionnaire2], libelle: 'procedure', published: true) }
let!(:procedure) { create(:procedure, gestionnaires: [gestionnaire2], libelle: 'procedure', published_at: Time.now) }
let(:procedure_overview) { double('procedure_overview', 'had_some_activities?'.to_sym => true) }
before :each do
@ -388,7 +388,7 @@ describe Gestionnaire, type: :model do
end
context 'when a procedure not published was active with no notifications' do
let!(:procedure) { create(:procedure, gestionnaires: [gestionnaire2], libelle: 'procedure', published: false) }
let!(:procedure) { create(:procedure, gestionnaires: [gestionnaire2], libelle: 'procedure', published_at: nil) }
let(:procedure_overview) { double('procedure_overview', 'had_some_activities?'.to_sym => true) }
before :each do

View file

@ -97,45 +97,45 @@ describe Procedure do
end
describe 'locked?' do
let(:procedure) { create(:procedure, published: published) }
let(:procedure) { create(:procedure, published_at: published_at) }
subject { procedure.locked? }
context 'when procedure is in draft status' do
let(:published) { false }
let(:published_at) { nil }
it { is_expected.to be_falsey }
end
context 'when procedure is in draft status' do
let(:published) { true }
let(:published_at) { Time.now }
it { is_expected.to be_truthy }
end
end
describe 'active' do
let(:procedure) { create(:procedure, published: published, archived: archived) }
let(:procedure) { create(:procedure, published_at: published_at, archived: archived) }
subject { Procedure.active(procedure.id) }
context 'when procedure is in draft status and not archived' do
let(:published) { false }
let(:published_at) { nil }
let(:archived) { false }
it { expect { subject }.to raise_error(ActiveRecord::RecordNotFound) }
end
context 'when procedure is published and not archived' do
let(:published) { true }
let(:published_at) { Time.now }
let(:archived) { false }
it { is_expected.to be_truthy }
end
context 'when procedure is published and archived' do
let(:published) { true }
let(:published_at) { Time.now }
let(:archived) { true }
it { expect { subject }.to raise_error(ActiveRecord::RecordNotFound) }
end
context 'when procedure is in draft status and archived' do
let(:published) { false }
let(:published_at) { nil }
let(:archived) { true }
it { expect { subject }.to raise_error(ActiveRecord::RecordNotFound) }
end
@ -143,8 +143,8 @@ describe Procedure do
describe 'clone' do
let(:archived) { false }
let(:published) { false }
let(:procedure) { create(:procedure, archived: archived, published: published, received_mail: received_mail) }
let(:published_at) { nil }
let(:procedure) { create(:procedure, archived: archived, published_at: published_at, received_mail: received_mail) }
let!(:type_de_champ_0) { create(:type_de_champ_public, procedure: procedure, order_place: 0) }
let!(:type_de_champ_1) { create(:type_de_champ_public, procedure: procedure, order_place: 1) }
let!(:type_de_champ_2) { create(:type_de_champ_public, :type_drop_down_list, procedure: procedure, order_place: 2) }
@ -214,10 +214,10 @@ describe Procedure do
describe 'procedure status is reset' do
let(:archived) { true }
let(:published) { true }
let(:published_at) { Time.now }
it 'Not published nor archived' do
expect(subject.archived).to be_falsey
expect(subject.published).to be_falsey
expect(subject.published_at).to be_nil
expect(subject.path).to be_nil
end
end
@ -232,7 +232,6 @@ describe Procedure do
procedure.publish!("example-path")
end
it { expect(procedure.published).to eq(true) }
it { expect(procedure.archived).to eq(false) }
it { expect(procedure.published_at).to eq(now) }
it { expect(ProcedurePath.find_by_path("example-path")).to be }
@ -254,7 +253,7 @@ describe Procedure do
procedure.reload
end
it { expect(procedure.published).to be_truthy }
it { expect(procedure.published?).to be_truthy }
it { expect(procedure.archived).to be_truthy }
it { expect(procedure.archived_at).to eq(now) }