diff options
| author | Robert | 2017-11-02 08:20:08 +0100 | 
|---|---|---|
| committer | Robert | 2017-11-03 14:44:56 +0100 | 
| commit | 6c24de52de8481c84e83c414563953cad13e869d (patch) | |
| tree | 4282d67e9cd415c8d47c4bb19740128651e8f34e | |
| parent | c3c32ae541cfb018877af964f122b15f6f15b984 (diff) | |
| download | chouette-core-6c24de52de8481c84e83c414563953cad13e869d.tar.bz2 | |
    Refs:#4802@0.5h;
      CodeReview:
      - Exchange fr and en translation files for referential_suites
      - Consistent usage of `jeu de donées` and `espace de travail` dans les *fr.yml
    Fixes: #4802@0.2h; Replaying former work. To identify spec regression
        Step 3: Added validation of reference_suite#new/current
                Made all specs pass
| -rw-r--r-- | app/models/referential_suite.rb | 13 | ||||
| -rw-r--r-- | config/locales/referential_suites.en.yml | 6 | ||||
| -rw-r--r-- | config/locales/referential_suites.fr.yml | 6 | ||||
| -rw-r--r-- | config/locales/referentials.fr.yml | 6 | ||||
| -rw-r--r-- | config/locales/workbenches.en.yml | 6 | ||||
| -rw-r--r-- | config/locales/workbenches.fr.yml | 6 | ||||
| -rw-r--r-- | spec/models/referential_suite/referential_suite_current_new_spec.rb | 64 | 
7 files changed, 92 insertions, 15 deletions
| diff --git a/app/models/referential_suite.rb b/app/models/referential_suite.rb index 9fd25ef3f..93c2c3f36 100644 --- a/app/models/referential_suite.rb +++ b/app/models/referential_suite.rb @@ -1,6 +1,19 @@  class ReferentialSuite < ActiveRecord::Base    belongs_to :new, class_name: 'Referential' +  validate def validate_consistent_new +    return true if new_id.nil? +    return true if new.referential_suite_id == id +    errors.add(:inconsistent_new, +               I18n.t('referential_suites.errors.inconsistent_new', name: new.name)) +  end +    belongs_to :current, class_name: 'Referential' +  validate def validate_consistent_current +    return true if current_id.nil? +    return true if current.referential_suite_id == id +    errors.add(:inconsistent_current, +               I18n.t('referential_suites.errors.inconsistent_current', name: current.name)) +  end    has_many :referentials  end diff --git a/config/locales/referential_suites.en.yml b/config/locales/referential_suites.en.yml index 9cb1e33d3..aa6fef0e2 100644 --- a/config/locales/referential_suites.en.yml +++ b/config/locales/referential_suites.en.yml @@ -1,5 +1,5 @@ -en: +fr:    referential_suites:      errors: -      inconsistent_current: "Le current referential (%{name}) n'appartient pas à cette referential suite" -      inconsistent_new: "Le new referential (%{name}) n'appartient pas à cette referential suite" +      inconsistent_current: "The current referential (%{name}) does not belong to this referential suite" +      inconsistent_new: "The new referential (%{name}) does not belong to this referential suite" diff --git a/config/locales/referential_suites.fr.yml b/config/locales/referential_suites.fr.yml index aa6fef0e2..9cb1e33d3 100644 --- a/config/locales/referential_suites.fr.yml +++ b/config/locales/referential_suites.fr.yml @@ -1,5 +1,5 @@ -fr: +en:    referential_suites:      errors: -      inconsistent_current: "The current referential (%{name}) does not belong to this referential suite" -      inconsistent_new: "The new referential (%{name}) does not belong to this referential suite" +      inconsistent_current: "Le current referential (%{name}) n'appartient pas à cette referential suite" +      inconsistent_new: "Le new referential (%{name}) n'appartient pas à cette referential suite" diff --git a/config/locales/referentials.fr.yml b/config/locales/referentials.fr.yml index a033b8ca5..bec1e87d8 100644 --- a/config/locales/referentials.fr.yml +++ b/config/locales/referentials.fr.yml @@ -2,7 +2,7 @@ fr:    referentials:      filters:        name_or_number_or_objectid: 'Indiquez un nom de ligne, nom court ou objectid' -      name: 'Indiquez un nom de référentiel...' +      name: 'Indiquez un nom de jeu de données...'        line: 'Indiquez une ligne...'      search_no_results: 'Aucun jeu de données ne correspond à votre recherche'      error_period_filter: "Le filtre par période doit contenir une date de début et de fin valides" @@ -103,8 +103,8 @@ fr:        referential:          slug: "caractères autorisés : alphanumériques minuscules et 'souligné' et doit commencer par une lettre"          prefix: "caractères autorisés : alphanumériques et 'souligné'" -        upper_corner: "latitude,longitude dans le référentiel WGS84, le séparateur de décimales est 'point'" -        lower_corner: "latitude,longitude dans le référentiel WGS84, le séparateur de décimales est 'point'" +        upper_corner: "latitude,longitude dans le jeu de données WGS84, le séparateur de décimales est 'point'" +        lower_corner: "latitude,longitude dans le jeu de données WGS84, le séparateur de décimales est 'point'"    simple_form:      labels: diff --git a/config/locales/workbenches.en.yml b/config/locales/workbenches.en.yml index 051ef1c96..3a2fcd598 100644 --- a/config/locales/workbenches.en.yml +++ b/config/locales/workbenches.en.yml @@ -11,9 +11,9 @@ en:          see: "See the list"          no_content: "No content yet."      referential_count: -      zero: "Currently, there is no referential in your workbench" -      one: "Currently, there is one referential in your workbench" -      other: "Currently, there are #{count} referentials in your workbench" +      zero: "There is no referential in your workbench" +      one: "There is one referential in your workbench" +      other: "There are #{count} referentials in your workbench"    activerecord:      models:        workbench: diff --git a/config/locales/workbenches.fr.yml b/config/locales/workbenches.fr.yml index 7a614efc5..0f8a516e3 100644 --- a/config/locales/workbenches.fr.yml +++ b/config/locales/workbenches.fr.yml @@ -1,9 +1,9 @@  fr:    workbenches:      referential_count: -      zero: "Aucun jeu de données à l'heure actuelle" -      one: "1 jeu de données à l'heure actuelle" -      other: "#{count} jeux de données à l'heure actuelle" +      zero: "Aucun jeu de données dans cet espace de travail" +      one: "1 jeu de données dans cet espace de travail" +      other: "#{count} jeux de données dans cet espace de travail"    activerecord:      models:        workbench: diff --git a/spec/models/referential_suite/referential_suite_current_new_spec.rb b/spec/models/referential_suite/referential_suite_current_new_spec.rb new file mode 100644 index 000000000..a910a12da --- /dev/null +++ b/spec/models/referential_suite/referential_suite_current_new_spec.rb @@ -0,0 +1,64 @@ +RSpec.describe ReferentialSuite do + +  describe 'Normalisation of current and new towards a proper Referential' do + +    subject { create :referential_suite, new: nil, current: nil } + +    describe 'valid' do +      context 'current and new nil' do +        it do +          expect_it.to be_valid +        end +      end + +      context 'current nil and new pointing correctly back' do +        let( :child ){ create :referential, referential_suite: subject } +        it do +          subject.new_id = child.id +          expect_it.to be_valid +        end +      end + +      context 'new nil and current pointing correctly back' do +        let( :child ){ create :referential, referential_suite: subject } +        it do +          subject.current_id = child.id +          expect_it.to be_valid +        end +      end + +      context 'new and current pointing correctly back' do +        let( :child ){ create :referential, referential_suite: subject } +        let( :sibbling ){ create :referential, referential_suite: subject } +        it do +          subject.current_id = child.id +          subject.new_id = sibbling.id +          expect_it.to be_valid +        end +      end +    end + +    describe 'invalid' do +      context 'current points to incorrect referential(not a child), new is nil' do +        let( :current ){ create :referential } +        it do +          subject.current_id = current.id +          expect_it.not_to be_valid +          expect( subject.errors.messages[:inconsistent_new] ).to be_nil +          expect( subject.errors.messages[:inconsistent_current].first ).to match(%r<#{current.name}>) +        end +      end +      context 'current points to correct referential, new to incorrect referential(not a child)' do +        let( :current ){ create :referential, referential_suite: subject } +        let( :new ){ create :referential, referential_suite: create( :referential_suite ) } +        it do +          subject.current_id = current.id +          subject.new_id = new.id +          expect_it.not_to be_valid +          expect( subject.errors.messages[:inconsistent_current] ).to be_nil +          expect( subject.errors.messages[:inconsistent_new].first ).to match(%r<#{new.name}>) +        end +      end +    end +  end +end | 
