aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorteddywing2017-11-06 12:36:17 +0100
committerGitHub2017-11-06 12:36:17 +0100
commit1b70d5584f59fb3afd47030904bc16daa9f200bc (patch)
treef90611dec75bf50a2a54e5ce37b469bac61220a2 /spec
parent94d240c3ae5511591452aa1a43c90811b0c571dd (diff)
parentea1cbc874aa6609c6217514640eb1eca20665d41 (diff)
downloadchouette-core-1b70d5584f59fb3afd47030904bc16daa9f200bc.tar.bz2
Merge pull request #109 from af83/4802-referential-model-normalisation
4802 referential model normalisation
Diffstat (limited to 'spec')
-rw-r--r--spec/factories/referentials.rb10
-rw-r--r--spec/features/workbenches_spec.rb12
-rw-r--r--spec/helpers/table_builder_helper_spec.rb2
-rw-r--r--spec/models/referential/referential_org_through_workbench_spec.rb44
-rw-r--r--spec/models/referential_spec.rb2
-rw-r--r--spec/models/referential_suite/referential_suite_current_new_spec.rb64
-rw-r--r--spec/models/referential_suite/referential_suite_spec.rb (renamed from spec/models/referential_suite_spec.rb)0
-rw-r--r--spec/requests/api/v1/netex_import_spec.rb2
8 files changed, 124 insertions, 12 deletions
diff --git a/spec/factories/referentials.rb b/spec/factories/referentials.rb
index 5348ad96b..a4155d181 100644
--- a/spec/factories/referentials.rb
+++ b/spec/factories/referentials.rb
@@ -3,11 +3,17 @@ FactoryGirl.define do
sequence(:name) { |n| "Test #{n}" }
sequence(:slug) { |n| "test_#{n}" }
sequence(:prefix) { |n| "test_#{n}" }
- association :organisation
- association :workbench
association :line_referential
association :stop_area_referential
+ association :organisation
time_zone "Europe/Paris"
ready { true }
+
+ factory :workbench_referential do
+ association :workbench
+ before :create do | ref |
+ ref.workbench.organisation = ref.organisation
+ end
+ end
end
end
diff --git a/spec/features/workbenches_spec.rb b/spec/features/workbenches_spec.rb
index e33f8c134..f1151a67b 100644
--- a/spec/features/workbenches_spec.rb
+++ b/spec/features/workbenches_spec.rb
@@ -1,6 +1,4 @@
-# coding: utf-8
-
-describe 'Workbenches', type: :feature do
+RSpec.describe 'Workbenches', type: :feature do
login_user
let(:line_ref) { create :line_referential }
@@ -8,7 +6,7 @@ describe 'Workbenches', type: :feature do
let(:ref_metadata) { create(:referential_metadata, lines: [line]) }
let!(:workbench) { create(:workbench, line_referential: line_ref, organisation: @user.organisation) }
- let!(:referential) { create :referential, workbench: workbench, metadatas: [ref_metadata], organisation: @user.organisation }
+ let!(:referential) { create :workbench_referential, workbench: workbench, metadatas: [ref_metadata], organisation: @user.organisation }
describe 'show' do
context 'ready' do
@@ -25,10 +23,10 @@ describe 'Workbenches', type: :feature do
end
context 'filtering' do
- let(:another_organisation) { create :organisation }
+ let!(:another_organisation) { create :organisation }
let(:another_line) { create :line, line_referential: line_ref }
let(:another_ref_metadata) { create(:referential_metadata, lines: [another_line]) }
- let!(:other_referential) { create :referential, workbench: workbench, metadatas: [another_ref_metadata], organisation: another_organisation}
+ let!(:other_referential) { create :workbench_referential, workbench: workbench, metadatas: [another_ref_metadata] }
before(:each) do
visit workbench_path(workbench)
@@ -53,7 +51,7 @@ describe 'Workbenches', type: :feature do
it 'should be possible to filter by multiple organisation' do
find("#q_organisation_name_eq_any_#{@user.organisation.name.parameterize.underscore}").set(true)
- find("#q_organisation_name_eq_any_#{another_organisation.name.parameterize.underscore}").set(true)
+ find("#q_organisation_name_eq_any_#{other_referential.organisation.name.parameterize.underscore}").set(true)
click_button I18n.t('actions.filter')
expect(page).to have_content(referential.name)
diff --git a/spec/helpers/table_builder_helper_spec.rb b/spec/helpers/table_builder_helper_spec.rb
index e17196a19..4d9808044 100644
--- a/spec/helpers/table_builder_helper_spec.rb
+++ b/spec/helpers/table_builder_helper_spec.rb
@@ -7,7 +7,7 @@ end
describe TableBuilderHelper, type: :helper do
describe "#table_builder_2" do
it "builds a table" do
- referential = build_stubbed(:referential)
+ referential = build_stubbed(:workbench_referential)
workbench = referential.workbench
user_context = UserContext.new(
diff --git a/spec/models/referential/referential_org_through_workbench_spec.rb b/spec/models/referential/referential_org_through_workbench_spec.rb
new file mode 100644
index 000000000..358a9e5e6
--- /dev/null
+++ b/spec/models/referential/referential_org_through_workbench_spec.rb
@@ -0,0 +1,44 @@
+RSpec.describe Referential do
+
+ describe 'Normalisation between Workbench and Organisation' do
+
+ context 'no workbench' do
+ subject{ create( :referential, workbench: nil ) }
+ it do
+ expect_it.to be_valid
+ end
+ end
+ context 'workbench with same organisation' do
+ let( :workbench ){ create :workbench}
+ subject do
+ create( :referential,
+ workbench: workbench,
+ organisation: workbench.organisation )
+ end
+ it do
+ expect_it.to be_valid
+ end
+ end
+
+ context 'workbench with different organisation' do
+ let( :workbench ){ create :workbench}
+ subject do
+ build( :referential, workbench: workbench)
+ end
+ before do
+ subject.organisation = build_stubbed(:organisation)
+ end
+ it 'is not valid' do
+ expect_it.not_to be_valid
+ end
+ it 'has correct error message' do
+ subject.valid?
+ errors = subject.errors.messages[:inconsistent_organisation]
+ expect(errors.grep(%r<#{subject.organisation.name}>)).not_to be_empty
+ expect(errors.grep(%r<#{workbench.organisation.name}>)).not_to be_empty
+ end
+ end
+
+ end
+
+end
diff --git a/spec/models/referential_spec.rb b/spec/models/referential_spec.rb
index bb8fabb2e..ad9c43010 100644
--- a/spec/models/referential_spec.rb
+++ b/spec/models/referential_spec.rb
@@ -1,7 +1,7 @@
require 'spec_helper'
describe Referential, :type => :model do
- let(:ref) { create :referential, metadatas: [create(:referential_metadata)] }
+ let(:ref) { create :workbench_referential, metadatas: [create(:referential_metadata)] }
# it "create a rule_parameter_set" do
# referential = create(:referential)
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
diff --git a/spec/models/referential_suite_spec.rb b/spec/models/referential_suite/referential_suite_spec.rb
index 771187b55..771187b55 100644
--- a/spec/models/referential_suite_spec.rb
+++ b/spec/models/referential_suite/referential_suite_spec.rb
diff --git a/spec/requests/api/v1/netex_import_spec.rb b/spec/requests/api/v1/netex_import_spec.rb
index b6728168e..a90e51e5b 100644
--- a/spec/requests/api/v1/netex_import_spec.rb
+++ b/spec/requests/api/v1/netex_import_spec.rb
@@ -2,7 +2,7 @@ RSpec.describe "NetexImport", type: :request do
describe 'POST netex_imports' do
- let( :referential ){ create :referential }
+ let( :referential ){ create :workbench_referential }
let( :workbench ){ referential.workbench }
let( :workbench_import ){ create :workbench_import }