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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -220,7 +220,7 @@ describe Users::SessionsController, type: :controller do
end end
context 'when procedure is not published' do context 'when procedure is not published' do
let(:procedure) { create :procedure, published: false } let(:procedure) { create :procedure, published_at: nil }
before do before do
session["user_return_to"] = "?procedure_id=#{procedure.id}" session["user_return_to"] = "?procedure_id=#{procedure.id}"
end end
@ -230,7 +230,7 @@ describe Users::SessionsController, type: :controller do
end end
context 'when procedure_id exist' do context 'when procedure_id exist' do
let(:procedure) { create :procedure, published: true } let(:procedure) { create :procedure, published_at: Time.now }
before do before do
session["user_return_to"] = "?procedure_id=#{procedure.id}" 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" description "Demande de subvention à l'intention des associations"
organisation "Orga SGMAP" organisation "Orga SGMAP"
direction "direction SGMAP" direction "direction SGMAP"
published false published_at nil
cerfa_flag false cerfa_flag false
administrateur { create(:administrateur) } administrateur { create(:administrateur) }

View file

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

View file

@ -370,14 +370,14 @@ describe Gestionnaire, type: :model do
end end
context 'when no procedure published was active last week' do 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 context 'when the gestionnaire has no notifications' do
it { is_expected.to eq(nil) } it { is_expected.to eq(nil) }
end end
end end
context 'when a procedure published was active' do 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) } let(:procedure_overview) { double('procedure_overview', 'had_some_activities?'.to_sym => true) }
before :each do before :each do
@ -388,7 +388,7 @@ describe Gestionnaire, type: :model do
end end
context 'when a procedure not published was active with no notifications' do 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) } let(:procedure_overview) { double('procedure_overview', 'had_some_activities?'.to_sym => true) }
before :each do before :each do

View file

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