diff --git a/Gemfile b/Gemfile index 0d0aa2bf7..7fe3f3a66 100644 --- a/Gemfile +++ b/Gemfile @@ -68,6 +68,7 @@ group :test do gem 'shoulda-matchers', require: false gem 'simplecov', require: false gem 'poltergeist' + gem 'timecop' end group :development, :test do diff --git a/Gemfile.lock b/Gemfile.lock index 7c9013dfa..6db37841d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -292,6 +292,7 @@ GEM thor (0.19.1) thread_safe (0.3.5) tilt (1.4.1) + timecop (0.7.3) turbolinks (2.5.3) coffee-rails tzinfo (1.2.2) @@ -365,6 +366,7 @@ DEPENDENCIES simplecov spring spring-commands-rspec + timecop turbolinks uglifier (>= 1.3.0) unicorn diff --git a/app/controllers/backoffice_controller.rb b/app/controllers/backoffice_controller.rb index 77a827ac2..47070b837 100644 --- a/app/controllers/backoffice_controller.rb +++ b/app/controllers/backoffice_controller.rb @@ -2,6 +2,6 @@ class BackofficeController < ApplicationController def index redirect_to(controller: '/gestionnaires/sessions', action: :new) unless gestionnaire_signed_in? + @dossiers = Dossier.all.decorate end - end \ No newline at end of file diff --git a/app/decorators/dossier_decorator.rb b/app/decorators/dossier_decorator.rb index dc3e3911d..c3c99e64e 100644 --- a/app/decorators/dossier_decorator.rb +++ b/app/decorators/dossier_decorator.rb @@ -6,4 +6,8 @@ class DossierDecorator < Draper::Decorator rescue 'dd/mm/YYYY' end + + def last_update + updated_at.localtime.strftime('%d/%m/%Y %H:%M') + end end diff --git a/app/views/backoffice/index.html.haml b/app/views/backoffice/index.html.haml index 3f08ead4e..d79639e54 100644 --- a/app/views/backoffice/index.html.haml +++ b/app/views/backoffice/index.html.haml @@ -7,8 +7,9 @@ %th Dossier %th etat %th Date de mise à jour - %row - %td Demande de subventions - %td dossier n°34 Demande de subvention - %td Mise à jour - %td 24/12/2015 \ No newline at end of file + - @dossiers.each do |dossier| + %tr + %td= dossier.procedure.libelle + %td= dossier.nom_projet + %td Mise à jour + %td= dossier.last_update \ No newline at end of file diff --git a/config/locales/fr.yml b/config/locales/fr.yml index d62c4a248..6591b7048 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -77,4 +77,6 @@ fr: not_locked: "n'était pas verrouillé(e)" not_saved: one: "1 erreur a empêché ce(tte) %{resource} d'être sauvegardé(e) :" - other: "%{count} erreurs ont empêché ce(tte) %{resource} d'être sauvegardé(e) :" \ No newline at end of file + other: "%{count} erreurs ont empêché ce(tte) %{resource} d'être sauvegardé(e) :" + + diff --git a/db/migrate/20150922085811_add_time_stamp_to_dossier.rb b/db/migrate/20150922085811_add_time_stamp_to_dossier.rb index 02f746a9d..0e00467da 100644 --- a/db/migrate/20150922085811_add_time_stamp_to_dossier.rb +++ b/db/migrate/20150922085811_add_time_stamp_to_dossier.rb @@ -1,6 +1,6 @@ class AddTimeStampToDossier < ActiveRecord::Migration def change - add_column :dossiers, :created_at, :datetime - add_column :dossiers, :updated_at, :datetime + add_column :dossiers, :created_at, :datetime, default: Time.now + add_column :dossiers, :updated_at, :datetime, default: Time.now end end diff --git a/db/schema.rb b/db/schema.rb index d65a06484..0433c7a4f 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -47,8 +47,8 @@ ActiveRecord::Schema.define(version: 20150922110719) do t.boolean "dossier_termine" t.integer "procedure_id" t.date "date_previsionnelle" - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", default: '2015-09-22 09:25:29' + t.datetime "updated_at", default: '2015-09-22 09:25:29' end add_index "dossiers", ["procedure_id"], name: "index_dossiers_on_procedure_id", using: :btree diff --git a/spec/decorators/dossier_decorator_spec.rb b/spec/decorators/dossier_decorator_spec.rb index 23830d251..90c53f6b0 100644 --- a/spec/decorators/dossier_decorator_spec.rb +++ b/spec/decorators/dossier_decorator_spec.rb @@ -1,4 +1,10 @@ require 'spec_helper' describe DossierDecorator do + let(:dossier) { create(:dossier) } + subject { dossier.decorate } + describe 'last_update' do + subject { Timecop.freeze(Time.new(2015, 12, 24, 14, 10)) { super().last_update } } + it { is_expected.to eq('24/12/2015 14:10') } + end end diff --git a/spec/factories/procedure.rb b/spec/factories/procedure.rb index 3b34c775a..48945fd2d 100644 --- a/spec/factories/procedure.rb +++ b/spec/factories/procedure.rb @@ -1,8 +1,8 @@ FactoryGirl.define do factory :procedure do - libelle 'Demande de subvention' - description 'Description demande de subvention' lien_demarche 'http://localhost' + libelle 'Demande de subvention' + description "Demande de subvention à l'intention des associations" trait :with_two_type_de_piece_justificative do after(:build) do |procedure, _evaluator| diff --git a/spec/features/backoffice/connection_spec.rb b/spec/features/backoffice/connection_spec.rb index d08d13b72..e6d1dbeea 100644 --- a/spec/features/backoffice/connection_spec.rb +++ b/spec/features/backoffice/connection_spec.rb @@ -1,6 +1,8 @@ require 'spec_helper' feature 'when gestionnaire come to /backoffice and is not authenticated' do + let(:procedure) { create(:procedure) } + let!(:dossier) { create(:dossier, procedure: procedure) } before do visit backoffice_path end diff --git a/spec/views/backoffice/index.html.haml_spec.rb b/spec/views/backoffice/index.html.haml_spec.rb index 192d777bd..2981cfa76 100644 --- a/spec/views/backoffice/index.html.haml_spec.rb +++ b/spec/views/backoffice/index.html.haml_spec.rb @@ -1,9 +1,16 @@ require 'spec_helper' describe 'backoffice/index.html.haml', type: :view do + let!(:procedure) { create(:procedure) } + let!(:decorated_dossier) { create(:dossier, procedure: procedure).decorate } before do + assign(:dossiers, [decorated_dossier]) render end - it { expect(rendered).to have_css('#backoffice') } - + subject { rendered } + it { is_expected.to have_css('#backoffice') } + it { is_expected.to have_content('Demande de subvention') } + it { is_expected.to have_content(procedure.libelle) } + it { is_expected.to have_content(decorated_dossier.nom_projet) } + it { is_expected.to have_content(decorated_dossier.last_update) } end \ No newline at end of file