Add the publiees scope on Procedure

This commit is contained in:
gregoirenovel 2017-07-11 15:52:06 +02:00
parent ab9cf1c351
commit fc2540649f
9 changed files with 13 additions and 12 deletions

View file

@ -6,7 +6,7 @@ class Admin::ProceduresController < AdminController
def index def index
@procedures = smart_listing_create :procedures, @procedures = smart_listing_create :procedures,
current_administrateur.procedures.published.not_archived.order(created_at: :desc), current_administrateur.procedures.publiees.order(created_at: :desc),
partial: "admin/procedures/list", partial: "admin/procedures/list",
array: true array: true

View file

@ -6,7 +6,7 @@ class DemoController < ApplicationController
return redirect_to root_path if Rails.env.production? return redirect_to root_path if Rails.env.production?
smart_listing_create :procedures, smart_listing_create :procedures,
Procedure.published.not_archived.order("id DESC"), Procedure.publiees.order("id DESC"),
partial: "demo/list", partial: "demo/list",
array: true array: true
end end

View file

@ -60,7 +60,7 @@ class Users::DossiersController < UsersController
end end
def new def new
procedure = Procedure.not_archived.published.find(params[:procedure_id]) procedure = Procedure.publiees.find(params[:procedure_id])
dossier = Dossier.create(procedure: procedure, user: current_user, state: 'draft') dossier = Dossier.create(procedure: procedure, user: current_user, state: 'draft')
siret = params[:siret] || current_user.siret siret = params[:siret] || current_user.siret

View file

@ -108,7 +108,7 @@ class Gestionnaire < ActiveRecord::Base
start_date = DateTime.now.beginning_of_week start_date = DateTime.now.beginning_of_week
active_procedure_overviews = procedures active_procedure_overviews = procedures
.published .publiees
.map { |procedure| procedure.procedure_overview(start_date) } .map { |procedure| procedure.procedure_overview(start_date) }
.select(&:had_some_activities?) .select(&:had_some_activities?)

View file

@ -32,6 +32,7 @@ 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 :publiees, -> { where.not(published_at: nil).where(archived_at: nil) }
scope :publiee_ou_archivee, -> { where.not(published_at: nil) } scope :publiee_ou_archivee, -> { where.not(published_at: nil) }
scope :not_published, -> { where(published_at: nil) } scope :not_published, -> { where(published_at: nil) }
scope :archived, -> { where.not(archived_at: nil) } scope :archived, -> { where.not(archived_at: nil) }
@ -64,7 +65,7 @@ class Procedure < ActiveRecord::Base
end end
def self.active id def self.active id
not_archived.published.find(id) publiees.find(id)
end end
def switch_types_de_champ index_of_first_element def switch_types_de_champ index_of_first_element

View file

@ -18,7 +18,7 @@
= admin.last_sign_in_at.localtime.strftime('%d/%m/%Y') = admin.last_sign_in_at.localtime.strftime('%d/%m/%Y')
) )
%td %td
= admin.procedures.published.count = admin.procedures.publiees.count
%td %td
- total_dossier = 0 - total_dossier = 0
- admin.procedures.each do |procedure| total_dossier += procedure.dossiers.state_not_brouillon.count end - admin.procedures.each do |procedure| total_dossier += procedure.dossiers.state_not_brouillon.count end

View file

@ -19,7 +19,7 @@
.procedure-list-element{ class: @active_class } .procedure-list-element{ class: @active_class }
Actives Actives
.badge.progress-bar-success .badge.progress-bar-success
= current_administrateur.procedures.published.not_archived.count = current_administrateur.procedures.publiees.count
%a#archived-procedures{ :href => "#{url_for :admin_procedures_archived}" } %a#archived-procedures{ :href => "#{url_for :admin_procedures_archived}" }
.procedure-list-element{ class: @archived_class } .procedure-list-element{ class: @archived_class }

View file

@ -2,7 +2,7 @@ class AutoArchiveProcedureWorker
include Sidekiq::Worker include Sidekiq::Worker
def perform(*args) def perform(*args)
Procedure.not_archived.where("auto_archive_on <= ?", Date.today).each do |procedure| Procedure.publiees.where("auto_archive_on <= ?", Date.today).each do |procedure|
procedure.dossiers.state_en_construction.each do |dossier| procedure.dossiers.state_en_construction.each do |dossier|
dossier.received! dossier.received!
end end

View file

@ -1,10 +1,10 @@
require 'rails_helper' require 'rails_helper'
RSpec.describe AutoArchiveProcedureWorker, type: :worker do RSpec.describe AutoArchiveProcedureWorker, type: :worker do
let!(:procedure) { create(:procedure, archived_at: nil, auto_archive_on: nil )} let!(:procedure) { create(:procedure, published_at: Time.now, archived_at: nil, auto_archive_on: nil )}
let!(:procedure_hier) { create(:procedure, archived_at: nil, auto_archive_on: 1.day.ago )} let!(:procedure_hier) { create(:procedure, published_at: Time.now, archived_at: nil, auto_archive_on: 1.day.ago )}
let!(:procedure_aujourdhui) { create(:procedure, archived_at: nil, auto_archive_on: Date.today )} let!(:procedure_aujourdhui) { create(:procedure, published_at: Time.now, archived_at: nil, auto_archive_on: Date.today )}
let!(:procedure_demain) { create(:procedure, archived_at: nil, auto_archive_on: 1.day.from_now )} let!(:procedure_demain) { create(:procedure, published_at: Time.now, archived_at: nil, auto_archive_on: 1.day.from_now )}
subject { AutoArchiveProcedureWorker.new.perform } subject { AutoArchiveProcedureWorker.new.perform }