diff options
| author | af83 | 2017-07-06 12:18:31 +0200 | 
|---|---|---|
| committer | af83 | 2017-07-06 12:18:31 +0200 | 
| commit | a78db962d1f25f569ff3e8294cd565137ede92d3 (patch) | |
| tree | a310f54f17077b7939365740fa694026cf839e9e | |
| parent | ebd292c7a6abaab5aeb90b37e34e21253184979f (diff) | |
| download | chouette-core-a78db962d1f25f569ff3e8294cd565137ede92d3.tar.bz2 | |
Change wording for clean up + add exclusive dates for between clean up
| -rw-r--r-- | app/assets/javascripts/cleanup.coffee | 11 | ||||
| -rw-r--r-- | app/models/clean_up.rb | 10 | ||||
| -rw-r--r-- | app/views/referentials/show.html.slim | 2 | ||||
| -rw-r--r-- | config/locales/clean_ups.en.yml | 11 | ||||
| -rw-r--r-- | config/locales/clean_ups.fr.yml | 20 | ||||
| -rw-r--r-- | spec/models/clean_up_spec.rb | 20 | 
6 files changed, 49 insertions, 25 deletions
diff --git a/app/assets/javascripts/cleanup.coffee b/app/assets/javascripts/cleanup.coffee index 169a006a9..7f6594018 100644 --- a/app/assets/javascripts/cleanup.coffee +++ b/app/assets/javascripts/cleanup.coffee @@ -2,8 +2,13 @@ $(document).on("change", 'input[name="clean_up[date_type]"]', (e) ->    type = $(this).val()    end_date = $('.cleanup_end_date_wrapper') -  if type == 'between' -    end_date.removeClass('hidden').show() -  else +  if type == 'before' +    end_date.hide() +    $("label[for='clean_up_begin_date_3i']").html("Date de fin de purge"); +  else if type == 'after'      end_date.hide() +    $("label[for='clean_up_begin_date_3i']").html("Date de début de purge"); +  else +    $("label[for='clean_up_begin_date_3i']").html("Date de début de purge"); +    end_date.show()  ) diff --git a/app/models/clean_up.rb b/app/models/clean_up.rb index cbcde72f5..75fedc732 100644 --- a/app/models/clean_up.rb +++ b/app/models/clean_up.rb @@ -6,8 +6,8 @@ class CleanUp < ActiveRecord::Base    enumerize :date_type, in: %i(between before after) -  validates :begin_date, presence: true -  validates :date_type, presence: true +  validates_presence_of :begin_date, message: :presence +  validates_presence_of :date_type, message: :presence    after_commit :perform_cleanup, :on => :create    def perform_cleanup @@ -30,7 +30,7 @@ class CleanUp < ActiveRecord::Base    end    def destroy_time_tables_between -    time_tables = Chouette::TimeTable.where('end_date <= ? AND start_date >= ?', self.end_date, self.begin_date) +    time_tables = Chouette::TimeTable.where('end_date < ? AND start_date > ?', self.end_date, self.begin_date)      self.destroy_time_tables(time_tables)    end @@ -53,7 +53,7 @@ class CleanUp < ActiveRecord::Base    end    def destroy_time_tables_dates_between -    Chouette::TimeTableDate.in_dates.where('date >= ? AND date <= ?', self.begin_date, self.end_date).destroy_all +    Chouette::TimeTableDate.in_dates.where('date > ? AND date < ?', self.begin_date, self.end_date).destroy_all    end    def destroy_time_tables_periods_before @@ -65,7 +65,7 @@ class CleanUp < ActiveRecord::Base    end    def destroy_time_tables_periods_between -    Chouette::TimeTablePeriod.where('period_start >= ? AND period_end <= ?', self.begin_date, self.end_date).destroy_all +    Chouette::TimeTablePeriod.where('period_start > ? AND period_end < ?', self.begin_date, self.end_date).destroy_all    end    def overlapping_periods diff --git a/app/views/referentials/show.html.slim b/app/views/referentials/show.html.slim index 81cd0ebfd..17ba8ad88 100644 --- a/app/views/referentials/show.html.slim +++ b/app/views/referentials/show.html.slim @@ -70,7 +70,7 @@              = f.input :date_type, as: :radio_buttons, label: false              = f.input :begin_date, as: :date, label: t('titles.clean_up.begin_date'),:wrapper_html => { class: 'date smart_date', title: t('titles.clean_up.begin_date') } -            = f.input :end_date, as: :date, label: t('titles.clean_up.end_date'), :wrapper_html => { class: 'date cleanup_end_date_wrapper hidden smert_date', title: t('titles.clean_up.end_date') } +            = f.input :end_date, as: :date, label: t('titles.clean_up.end_date'), :wrapper_html => { class: 'date cleanup_end_date_wrapper smart_date', title: t('titles.clean_up.end_date'), id: "end_date" }      .modal-footer        button.btn.btn-link type='button' data-dismiss='modal' Annuler diff --git a/config/locales/clean_ups.en.yml b/config/locales/clean_ups.en.yml index 148362c35..588eb55d5 100644 --- a/config/locales/clean_ups.en.yml +++ b/config/locales/clean_ups.en.yml @@ -22,3 +22,14 @@ en:        clean_up:          begin_date: "Begin date of clean up"          end_date: "End date of clean up" +  activerecord: +    errors: +      models: +        clean_up: +          attributes: +            date_type: +              presence: "A clean up must have a date type" +            begin_date: +              presence: "A clean up must have a begin date" +            end_date: +              presence: "A clean up must have a end date" diff --git a/config/locales/clean_ups.fr.yml b/config/locales/clean_ups.fr.yml index cb0ce3f1a..001c2b1cb 100644 --- a/config/locales/clean_ups.fr.yml +++ b/config/locales/clean_ups.fr.yml @@ -14,11 +14,21 @@ fr:          end_date: "Fin date limite : "    titles:      clean_up: -      begin_date: "Début date de la purge" -      end_date: "Fin date de la purge" - +      begin_date: "Date de début de la purge" +      end_date: "Date de fin de la purge"    formtastic:      titles:        clean_up: -        begin_date: "Début date de la purge" -        end_date: "Fin date de la purge" +        begin_date: "Date de début de la purge" +        end_date: "Date de fin de la purge" +  activerecord: +    errors: +      models: +        clean_up: +          attributes: +            date_type: +              presence: "Une purge doit avoir un type de renseigné" +            begin_date: +              presence: "Une purge doit avoir une date de début" +            end_date: +              presence: "Une purge doit avoir une date de fin" diff --git a/spec/models/clean_up_spec.rb b/spec/models/clean_up_spec.rb index 4dc692ab2..01440be0e 100644 --- a/spec/models/clean_up_spec.rb +++ b/spec/models/clean_up_spec.rb @@ -2,18 +2,17 @@ require 'rails_helper'  RSpec.describe CleanUp, :type => :model do -  it { should validate_presence_of(:begin_date) } -  it { should validate_presence_of(:date_type) } +  it { should validate_presence_of(:date_type).with_message(:presence) } +  it { should validate_presence_of(:begin_date).with_message(:presence) }    it { should belong_to(:referential) }    context '#exclude_dates_in_overlapping_period with :before date_type' do      let(:time_table) { create(:time_table) }      let(:period) { time_table.periods[0] } -    let(:cleaner) { create(:clean_up, date_type: :before) } +    let(:cleaner) { create(:clean_up, date_type: :before, begin_date: period.period_end) }      it 'should add exclude date into period for overlapping period' do        days_in_period = (period.period_start..period.period_end).count -      cleaner.begin_date = period.period_end        expect { cleaner.exclude_dates_in_overlapping_period(period) }.to change {          time_table.dates.where(in_out: false).count @@ -31,11 +30,10 @@ RSpec.describe CleanUp, :type => :model do    context '#exclude_dates_in_overlapping_period with :after date_type' do      let(:time_table) { create(:time_table) }      let(:period) { time_table.periods[0] } -    let(:cleaner) { create(:clean_up, date_type: :after) } +    let(:cleaner) { create(:clean_up, date_type: :after, begin_date: period.period_start + 1.day) }      it 'should add exclude date into period for overlapping period' do        days_in_period = (period.period_start..period.period_end).count -      cleaner.begin_date = period.period_start + 1.day        expect { cleaner.exclude_dates_in_overlapping_period(period) }.to change {          time_table.dates.where(in_out: false).count        }.by(days_in_period - 2) @@ -72,11 +70,11 @@ RSpec.describe CleanUp, :type => :model do    end    context '#overlapping_periods' do -    let(:cleaner) { create(:clean_up, date_type: :before, end_date: nil) }      let(:time_table) { create(:time_table) } +    let(:period) { time_table.periods[0] } +    let(:cleaner) { create(:clean_up, date_type: :before, begin_date: period.period_start) }      it 'should detect overlapping periods' do -      cleaner.begin_date = time_table.periods[0].period_start        expect(cleaner.overlapping_periods).to include(time_table.periods[0])      end @@ -128,7 +126,7 @@ RSpec.describe CleanUp, :type => :model do      it 'should destroy record' do        expect{ cleaner.destroy_time_tables_dates_between }.to change {          Chouette::TimeTableDate.count -      }.by(-time_table.dates.count) +      }.by(-time_table.dates.count + 2)      end      it 'should not destroy record not in range' do @@ -155,7 +153,7 @@ RSpec.describe CleanUp, :type => :model do    context '#destroy_time_tables_between' do      let!(:time_table) { create(:time_table ) } -    let(:cleaner) { create(:clean_up, date_type: :after, begin_date: time_table.start_date, end_date: time_table.end_date) } +    let(:cleaner) { create(:clean_up, date_type: :between, begin_date: time_table.start_date - 1.day, end_date: time_table.end_date + 1.day) }      it 'should destroy time_tables with validity period in purge range' do        expect{ cleaner.destroy_time_tables_between }.to change { @@ -240,7 +238,7 @@ RSpec.describe CleanUp, :type => :model do        }.by(-1)      end -    it 'should not destroy time_tables with end_date > purge begin date' do +    it 'should not destroy time_tables with end_date > purge begin_date' do        cleaner.begin_date = Date.today        expect{ cleaner.destroy_time_tables_before }.to_not change {          Chouette::TimeTable.count  | 
