diff options
| author | Luc Donnet | 2017-11-30 22:33:17 +0100 |
|---|---|---|
| committer | Luc Donnet | 2017-11-30 22:33:17 +0100 |
| commit | 4d9611d4cf1c9625536b63ea7942d9f8bf5147ae (patch) | |
| tree | 040ea7f70a71a163721a15fe7dbaf41246cd55f3 /spec | |
| parent | d69312d870880bde378d50d329fe2dbb523f84e6 (diff) | |
| parent | 8e80415f70e0c181643e522976b1cf8bf9f9abfd (diff) | |
| download | chouette-core-4d9611d4cf1c9625536b63ea7942d9f8bf5147ae.tar.bz2 | |
Merge branch 'master' into staging
Diffstat (limited to 'spec')
70 files changed, 317 insertions, 436 deletions
diff --git a/spec/controllers/devise/cas_sessions_controller_spec.rb b/spec/controllers/devise/cas_sessions_controller_spec.rb index e4436f6c1..934bc1da2 100644 --- a/spec/controllers/devise/cas_sessions_controller_spec.rb +++ b/spec/controllers/devise/cas_sessions_controller_spec.rb @@ -22,7 +22,7 @@ RSpec.describe Devise::CasSessionsController, type: :controller do it 'cannot login and will be redirected to the login page, with a corresponding message' do get :service - expect(controller).to set_flash[:alert].to(%r{IBOO}) + expect(controller).to set_flash[:alert].to(%r{Vous ne pouvez pas vous connecter car vous n'avez pas les permissions}) expect(response).to redirect_to "http://stif-portail-dev.af83.priv/sessions/logout?service=http%3A%2F%2Ftest.host%2Fusers%2Fservice" end end diff --git a/spec/controllers/routes_controller_spec.rb b/spec/controllers/routes_controller_spec.rb index fb29c8d73..f8e8697ec 100644 --- a/spec/controllers/routes_controller_spec.rb +++ b/spec/controllers/routes_controller_spec.rb @@ -1,5 +1,3 @@ -Route = Chouette::Route - RSpec.describe RoutesController, type: :controller do login_user @@ -87,10 +85,10 @@ RSpec.describe RoutesController, type: :controller do referential_id: route.line.line_referential_id, line_id: route.line_id, id: route.id - end.to change { Route.count }.by(1) + end.to change { Chouette::Route.count }.by(1) - expect(Route.last.name).to eq( I18n.t('activerecord.copy', name: route.name)) - expect(Route.last.published_name).to eq(route.published_name) + expect(Chouette::Route.last.name).to eq(I18n.t('activerecord.copy', name: route.name)) + expect(Chouette::Route.last.published_name).to eq(route.published_name) end end end diff --git a/spec/db/schema_spec.rb b/spec/db/schema_spec.rb index a7fe0a162..585636124 100644 --- a/spec/db/schema_spec.rb +++ b/spec/db/schema_spec.rb @@ -44,6 +44,6 @@ Diff: #{diff} def diff RSpec::Support::Differ.new( color: RSpec::Matchers.configuration.color? - ).diff_as_string(@original, @expected) + ).diff_as_string(@expected, @original) end end diff --git a/spec/decorators/company_decorator_spec.rb b/spec/decorators/company_decorator_spec.rb index a1df03449..557d98da1 100644 --- a/spec/decorators/company_decorator_spec.rb +++ b/spec/decorators/company_decorator_spec.rb @@ -1,2 +1,2 @@ -describe CompanyDecorator do +describe Chouette::CompanyDecorator do end diff --git a/spec/fabricators/user_fabricator.rb b/spec/fabricators/user_fabricator.rb index 04c1c6279..62eb82d51 100644 --- a/spec/fabricators/user_fabricator.rb +++ b/spec/fabricators/user_fabricator.rb @@ -5,4 +5,4 @@ Fabricator :user do password { 'password' } username { "#{FFaker::Name.first_name.parameterize}.#{FFaker::Name.last_name.parameterize}" } -end
\ No newline at end of file +end diff --git a/spec/factories/chouette_lines.rb b/spec/factories/chouette_lines.rb index 423ab99f2..95f760174 100644 --- a/spec/factories/chouette_lines.rb +++ b/spec/factories/chouette_lines.rb @@ -8,7 +8,7 @@ FactoryGirl.define do association :network, :factory => :network association :company, :factory => :company - + before(:create) do |line| line.line_referential ||= LineReferential.find_by! name: "first" end @@ -44,6 +44,11 @@ FactoryGirl.define do end + factory :line_with_after_commit do |line| + line.run_callbacks(:commit) + + end + end end diff --git a/spec/factories/chouette_routes.rb b/spec/factories/chouette_routes.rb index 4986ab70e..4e20059fe 100644 --- a/spec/factories/chouette_routes.rb +++ b/spec/factories/chouette_routes.rb @@ -33,6 +33,13 @@ FactoryGirl.define do end end + factory :route_with_after_commit do + sequence(:objectid) {nil} + after(:create) do |route| + route.run_callbacks(:commit) + end + end + end end diff --git a/spec/factories/compliance_controls/route_control_factories.rb b/spec/factories/compliance_controls/route_control_factories.rb index 1462ca635..35d8f481f 100644 --- a/spec/factories/compliance_controls/route_control_factories.rb +++ b/spec/factories/compliance_controls/route_control_factories.rb @@ -28,7 +28,7 @@ FactoryGirl.define do association :compliance_control_set end - factory :route_control_unactivated_stop_points, class: 'RouteControl::UnactivatedStopPoints' do + factory :route_control_unactivated_stop_point, class: 'RouteControl::UnactivatedStopPoint' do association :compliance_control_set end diff --git a/spec/factories/line_referentials.rb b/spec/factories/line_referentials.rb index cfce1399f..e9e6dce5a 100644 --- a/spec/factories/line_referentials.rb +++ b/spec/factories/line_referentials.rb @@ -1,5 +1,6 @@ FactoryGirl.define do factory :line_referential do sequence(:name) { |n| "Line Referential #{n}" } + objectid_format 'stif_codifligne' end end diff --git a/spec/factories/referentials.rb b/spec/factories/referentials.rb index a4155d181..0276a47be 100644 --- a/spec/factories/referentials.rb +++ b/spec/factories/referentials.rb @@ -8,6 +8,7 @@ FactoryGirl.define do association :organisation time_zone "Europe/Paris" ready { true } + objectid_format "stif_netex" factory :workbench_referential do association :workbench diff --git a/spec/factories/stop_area_referentials.rb b/spec/factories/stop_area_referentials.rb index c88819010..fcba996e4 100644 --- a/spec/factories/stop_area_referentials.rb +++ b/spec/factories/stop_area_referentials.rb @@ -1,5 +1,6 @@ FactoryGirl.define do factory :stop_area_referential, :class => StopAreaReferential do sequence(:name) { |n| "StopArea Referential #{n}" } + objectid_format 'stif_reflex' end end diff --git a/spec/factories/workbenches.rb b/spec/factories/workbenches.rb index 57bef2203..0f26559d8 100644 --- a/spec/factories/workbenches.rb +++ b/spec/factories/workbenches.rb @@ -1,6 +1,7 @@ FactoryGirl.define do factory :workbench do name "Gestion de l'offre" + objectid_format 'stif_netex' association :organisation association :line_referential diff --git a/spec/features/api_keys/edit_api_key_feature_spec.rb b/spec/features/api_keys/edit_api_key_feature_spec.rb index 256c4218b..9248e2b17 100644 --- a/spec/features/api_keys/edit_api_key_feature_spec.rb +++ b/spec/features/api_keys/edit_api_key_feature_spec.rb @@ -12,6 +12,8 @@ RSpec.describe 'Edit API Key', type: :feature do let( :unique_name ){ SecureRandom.uuid } it 'complete workflow' do + skip "Specific to STIF Dashboard" if Dashboard.default_class != Stif::Dashboard + visit dashboard_path # api_key's new name does not exist yet expect( page ).not_to have_content(unique_name) diff --git a/spec/features/api_keys/new_api_key_feature_spec.rb b/spec/features/api_keys/new_api_key_feature_spec.rb index 988690f3c..fc5497788 100644 --- a/spec/features/api_keys/new_api_key_feature_spec.rb +++ b/spec/features/api_keys/new_api_key_feature_spec.rb @@ -13,6 +13,8 @@ RSpec.describe 'New API Key', type: :feature do it 'complete workflow' do + skip "Specific to STIF Dashboard" if Dashboard.default_class != Stif::Dashboard + # /workbenches visit dashboard_path expect(page).to have_link(create_label, href: new_api_key_path) diff --git a/spec/helpers/table_builder_helper_spec.rb b/spec/helpers/table_builder_helper_spec.rb index a8854bf97..3b0a18379 100644 --- a/spec/helpers/table_builder_helper_spec.rb +++ b/spec/helpers/table_builder_helper_spec.rb @@ -214,7 +214,7 @@ describe TableBuilderHelper, type: :helper do </thead> <tbody> <tr> - <td>#{company.objectid.local_id}</td> + <td>#{company.get_objectid.local_id}</td> <td title="Voir"><a href="/referentials/#{referential.id}/companies/#{company.id}">#{company.name}</a></td> <td></td> <td></td> @@ -237,7 +237,7 @@ describe TableBuilderHelper, type: :helper do [ TableBuilderHelper::Column.new( name: 'ID Codif', - attribute: Proc.new { |n| n.try(:objectid).try(:local_id) }, + attribute: Proc.new { |n| n.try(:get_objectid).try(:local_id) }, sortable: false ), TableBuilderHelper::Column.new( @@ -327,7 +327,7 @@ describe TableBuilderHelper, type: :helper do </thead> <tbody> <tr> - <td>#{company.objectid.local_id}</td> + <td>#{company.get_objectid.local_id}</td> <td title="Voir"><a href="/referentials/#{referential.id}/companies/#{company.id}">#{company.name}</a></td> <td></td> <td></td> @@ -350,7 +350,7 @@ describe TableBuilderHelper, type: :helper do [ TableBuilderHelper::Column.new( name: 'ID Codif', - attribute: Proc.new { |n| n.try(:objectid).try(:local_id) } + attribute: Proc.new { |n| n.try(:get_objectid).try(:local_id) } ), TableBuilderHelper::Column.new( key: :name, diff --git a/spec/models/api/v1/api_key_spec.rb b/spec/models/api/v1/api_key_spec.rb index b700429d3..cc483a118 100644 --- a/spec/models/api/v1/api_key_spec.rb +++ b/spec/models/api/v1/api_key_spec.rb @@ -4,6 +4,7 @@ RSpec.describe Api::V1::ApiKey, type: :model do subject { create(:api_key) } it { should validate_presence_of :organisation } + it { is_expected.to be_versioned } it 'should have a valid factory' do expect(build(:api_key)).to be_valid diff --git a/spec/models/calendar_spec.rb b/spec/models/calendar_spec.rb index f5020ebf8..e71c2b081 100644 --- a/spec/models/calendar_spec.rb +++ b/spec/models/calendar_spec.rb @@ -6,6 +6,7 @@ RSpec.describe Calendar, :type => :model do it { is_expected.to validate_presence_of(:name) } it { is_expected.to validate_presence_of(:short_name) } it { is_expected.to validate_uniqueness_of(:short_name) } + it { is_expected.to be_versioned } describe '#to_time_table' do let(:calendar) { create(:calendar, date_ranges: [Date.today...(Date.today + 1.month)]) } @@ -29,7 +30,6 @@ RSpec.describe Calendar, :type => :model do end end - describe 'before_validation' do let(:calendar) { create(:calendar, date_ranges: []) } diff --git a/spec/models/chouette/access_link_spec.rb b/spec/models/chouette/access_link_spec.rb index 5a31b8f0c..ced99eb1d 100644 --- a/spec/models/chouette/access_link_spec.rb +++ b/spec/models/chouette/access_link_spec.rb @@ -4,10 +4,11 @@ describe Chouette::AccessLink, :type => :model do subject { create(:access_link) } it { is_expected.to validate_uniqueness_of :objectid } + it { is_expected.to be_versioned } - describe '#objectid' do - subject { super().objectid } - it { is_expected.to be_kind_of(Chouette::StifNetexObjectid) } + describe '#get_objectid' do + subject { super().get_objectid } + it {is_expected.to be_kind_of(Chouette::Objectid::StifNetex)} end it { is_expected.to validate_presence_of :name } diff --git a/spec/models/chouette/access_point_spec.rb b/spec/models/chouette/access_point_spec.rb index e0f4b1501..c734ecedf 100644 --- a/spec/models/chouette/access_point_spec.rb +++ b/spec/models/chouette/access_point_spec.rb @@ -4,13 +4,15 @@ describe Chouette::AccessPoint, :type => :model do subject { create(:access_point) } describe '#objectid' do - subject { super().objectid } - it { is_expected.to be_kind_of(Chouette::StifReflexObjectid) } + it "should have the same class as stop_area objectid" do + expect(subject.objectid.class).to eq(subject.stop_area.objectid.class) + end end it { is_expected.to validate_presence_of :name } it { is_expected.to validate_numericality_of :latitude } it { is_expected.to validate_numericality_of :longitude } + it { is_expected.to be_versioned } describe ".latitude" do it "should accept -90 value" do diff --git a/spec/models/chouette/company_spec.rb b/spec/models/chouette/company_spec.rb index a3101d79c..34b19eeda 100644 --- a/spec/models/chouette/company_spec.rb +++ b/spec/models/chouette/company_spec.rb @@ -3,6 +3,7 @@ require 'spec_helper' describe Chouette::Company, :type => :model do subject { create(:company) } it { should validate_presence_of :name } + it { is_expected.to be_versioned } describe "#nullables empty" do it "should set null empty nullable attributes" do diff --git a/spec/models/chouette/connection_link_spec.rb b/spec/models/chouette/connection_link_spec.rb index 57eb7d66c..4ab67d007 100644 --- a/spec/models/chouette/connection_link_spec.rb +++ b/spec/models/chouette/connection_link_spec.rb @@ -8,10 +8,11 @@ describe Chouette::ConnectionLink, :type => :model do subject { create(:connection_link) } it { is_expected.to validate_uniqueness_of :objectid } + it { is_expected.to be_versioned } - describe '#objectid' do - subject { super().objectid } - it { is_expected.to be_kind_of(Chouette::StifNetexObjectid) } + describe '#get_objectid' do + subject { super().get_objectid } + it {is_expected.to be_kind_of(Chouette::Objectid::StifNetex)} end it { is_expected.to validate_presence_of :name } diff --git a/spec/models/chouette/group_of_line_spec.rb b/spec/models/chouette/group_of_line_spec.rb index 29b4433c5..d43d75374 100644 --- a/spec/models/chouette/group_of_line_spec.rb +++ b/spec/models/chouette/group_of_line_spec.rb @@ -4,6 +4,7 @@ describe Chouette::GroupOfLine, :type => :model do subject { create(:group_of_line) } it { should validate_presence_of :name } + it { is_expected.to be_versioned } describe "#stop_areas" do let!(:line){create(:line, :group_of_lines => [subject])} diff --git a/spec/models/chouette/journey_pattern_spec.rb b/spec/models/chouette/journey_pattern_spec.rb index 047022ade..ea7c2a2e9 100644 --- a/spec/models/chouette/journey_pattern_spec.rb +++ b/spec/models/chouette/journey_pattern_spec.rb @@ -1,6 +1,8 @@ require 'spec_helper' describe Chouette::JourneyPattern, :type => :model do + it { is_expected.to be_versioned } + describe 'checksum' do it_behaves_like 'checksum support', :journey_pattern end diff --git a/spec/models/chouette/line_spec.rb b/spec/models/chouette/line_spec.rb index 2e5882012..056d5da9e 100644 --- a/spec/models/chouette/line_spec.rb +++ b/spec/models/chouette/line_spec.rb @@ -7,19 +7,15 @@ describe Chouette::Line, :type => :model do # it { is_expected.to validate_presence_of :network } # it { is_expected.to validate_presence_of :company } it { should validate_presence_of :name } + it { is_expected.to be_versioned } describe '#display_name' do it 'should display local_id, number, name and company name' do - display_name = "#{subject.objectid.local_id} - #{subject.number} - #{subject.name} - #{subject.company.try(:name)}" + display_name = "#{subject.get_objectid.local_id} - #{subject.number} - #{subject.name} - #{subject.company.try(:name)}" expect(subject.display_name).to eq(display_name) end end - describe '#objectid' do - subject { super().objectid } - it { is_expected.to be_kind_of(Chouette::StifCodifligneObjectid) } - end - # it { should validate_numericality_of :objectversion } # describe ".last_stop_areas_parents" do diff --git a/spec/models/chouette/network_spec.rb b/spec/models/chouette/network_spec.rb index 32bacc512..78a4150df 100644 --- a/spec/models/chouette/network_spec.rb +++ b/spec/models/chouette/network_spec.rb @@ -3,6 +3,7 @@ require 'spec_helper' describe Chouette::Network, :type => :model do subject { create(:network) } it { should validate_presence_of :name } + it { is_expected.to be_versioned } describe "#stop_areas" do let!(:line){create(:line, :network => subject)} diff --git a/spec/models/chouette/object_id_spec.rb b/spec/models/chouette/object_id_spec.rb deleted file mode 100644 index dd8b66388..000000000 --- a/spec/models/chouette/object_id_spec.rb +++ /dev/null @@ -1,149 +0,0 @@ -require 'spec_helper' - -describe Chouette::ObjectId, :type => :model do - - def objectid(value = "abc:StopArea:abc123") - Chouette::ObjectId.new value - end - - subject { objectid } - - context "when invalid" do - - subject { objectid("abc") } - - it { is_expected.not_to be_valid } - - describe '#parts' do - subject { super().parts } - it { is_expected.to be_nil } - end - - describe '#system_id' do - subject { super().system_id } - it { is_expected.to be_nil } - end - - end - - context "when with spaces in last part" do - - subject { objectid("abc:Line:Aze toto") } - - it { is_expected.not_to be_valid } - - - end - - context "when with spaces in first part" do - - subject { objectid("ae abc:Line:Aze") } - - it { is_expected.not_to be_valid } - - - end - - context "when with spaces in middle part" do - - subject { objectid("aeabc:Li ne:Aze") } - - it { is_expected.not_to be_valid } - - - end - - context "when invalid in first part" do - - subject { objectid("Abc_+19:Line:Abc") } - - it { is_expected.not_to be_valid } - end - - context "when invalid in middle part" do - - subject { objectid("Abc_19:Li56ne:Abc") } - - it { is_expected.not_to be_valid } - end - - context "when invalid in last part" do - - subject { objectid("Abc_19:Line:Ab+c") } - - it { is_expected.not_to be_valid } - end - context "when valid" do - - subject { objectid("Abc_19:Line:Abc_12-") } - - it { is_expected.to be_valid } - end - - describe "#parts" do - - it "should be the 3 parts of the ObjectId" do - expect(objectid("abc:StopArea:abc123").parts).to eq(%w{abc StopArea abc123}) - end - - end - - describe "#system_id" do - - it "should be the first ObjectId parts" do - expect(objectid("first:second:third").system_id).to eq("first") - end - - end - - describe "#object_type" do - - it "should be the second ObjectId parts" do - expect(objectid("first:second:third").object_type).to eq("second") - end - - end - - describe "#local_id" do - - it "should be the third ObjectId parts" do - expect(objectid("first:second:third").local_id).to eq("third") - end - - end - - it "should be valid when parts are found" do - allow(subject).to receive_messages :parts => "dummy" - expect(subject).to be_valid - end - - describe ".create" do - - let(:given_system_id) { "systemId" } - let(:given_object_type) { "objectType" } - let(:given_local_id) { "localId" } - - subject { Chouette::ObjectId.create(given_system_id, given_object_type, given_local_id) } - - it "should return ObjectId attributes" do - expect(subject.send(:system_id)).to eq(given_system_id) - expect(subject.send(:object_type)).to eq(given_object_type) - expect(subject.send(:local_id)).to eq(given_local_id) - end - - end - - describe ".new" do - - it "should return an existing ObjectId" do - expect(Chouette::ObjectId.new(objectid)).to eq(objectid) - end - - it "should create an empty ObjectId with nil" do - expect(Chouette::ObjectId.new(nil)).to be_empty - end - - end - - -end diff --git a/spec/models/chouette/objectid/netex_spec.rb b/spec/models/chouette/objectid/netex_spec.rb new file mode 100644 index 000000000..3aee13624 --- /dev/null +++ b/spec/models/chouette/objectid/netex_spec.rb @@ -0,0 +1,10 @@ +require 'spec_helper' + +describe Chouette::Objectid::Netex, :type => :model do + subject { Chouette::Objectid::Netex.new(object_type: 'Route', local_id: SecureRandom.uuid) } + it { should validate_presence_of :provider_id } + it { should validate_presence_of :object_type } + it { should validate_presence_of :local_id } + it { should validate_presence_of :creation_id } + it { is_expected.to be_valid } +end
\ No newline at end of file diff --git a/spec/models/chouette/objectid/stif_codifligne_spec.rb b/spec/models/chouette/objectid/stif_codifligne_spec.rb new file mode 100644 index 000000000..533af3556 --- /dev/null +++ b/spec/models/chouette/objectid/stif_codifligne_spec.rb @@ -0,0 +1,10 @@ +require 'spec_helper' + +describe Chouette::Objectid::StifCodifligne, :type => :model do + subject { Chouette::Objectid::StifCodifligne.new(object_type: 'Line', local_id: 'C02008', sync_id: 'CODIFLIGNE', provider_id: 'STIF') } + it { should validate_presence_of :provider_id } + it { should validate_presence_of :object_type } + it { should validate_presence_of :local_id } + it { should validate_presence_of :sync_id } + it { is_expected.to be_valid } +end
\ No newline at end of file diff --git a/spec/models/chouette/objectid/stif_netex_spec.rb b/spec/models/chouette/objectid/stif_netex_spec.rb new file mode 100644 index 000000000..1d361ca86 --- /dev/null +++ b/spec/models/chouette/objectid/stif_netex_spec.rb @@ -0,0 +1,10 @@ +require 'spec_helper' + +describe Chouette::Objectid::StifNetex, :type => :model do + subject { Chouette::Objectid::StifNetex.new(object_type: 'Route', local_id: '13') } + it { should validate_presence_of :provider_id } + it { should validate_presence_of :object_type } + it { should validate_presence_of :local_id } + it { should validate_presence_of :creation_id } + it { is_expected.to be_valid } +end
\ No newline at end of file diff --git a/spec/models/chouette/objectid/stif_reflex_spec.rb b/spec/models/chouette/objectid/stif_reflex_spec.rb new file mode 100644 index 000000000..0846f27fa --- /dev/null +++ b/spec/models/chouette/objectid/stif_reflex_spec.rb @@ -0,0 +1,11 @@ +require 'spec_helper' + +describe Chouette::Objectid::StifReflex, :type => :model do + subject { Chouette::Objectid::StifReflex.new(country_code: 'FR', zip_code: '78517', object_type: 'ZDL', local_id: '50015386', provider_id: 'STIF') } + it { should validate_presence_of :provider_id } + it { should validate_presence_of :object_type } + it { should validate_presence_of :local_id } + it { should validate_presence_of :country_code } + it { should validate_presence_of :zip_code } + it { is_expected.to be_valid } +end
\ No newline at end of file diff --git a/spec/models/chouette/route/route_base_spec.rb b/spec/models/chouette/route/route_base_spec.rb index cac2880e8..26f57eae5 100644 --- a/spec/models/chouette/route/route_base_spec.rb +++ b/spec/models/chouette/route/route_base_spec.rb @@ -5,11 +5,6 @@ RSpec.describe Chouette::Route, :type => :model do it_behaves_like 'checksum support', :route end - describe '#objectid' do - subject { super().objectid } - it { is_expected.to be_kind_of(Chouette::StifNetexObjectid) } - end - it { is_expected.to enumerize(:direction).in(:straight_forward, :backward, :clockwise, :counter_clockwise, :north, :north_west, :west, :south_west, :south, :south_east, :east, :north_east) } it { is_expected.to enumerize(:wayback).in(:outbound, :inbound) } @@ -20,6 +15,7 @@ RSpec.describe Chouette::Route, :type => :model do #it { is_expected.to validate_presence_of :direction_code } it { is_expected.to validate_inclusion_of(:direction).in_array(%i(straight_forward backward clockwise counter_clockwise north north_west west south_west south south_east east north_east)) } it { is_expected.to validate_inclusion_of(:wayback).in_array(%i(outbound inbound)) } + it { is_expected.to be_versioned } context "reordering methods" do let(:bad_stop_point_ids){subject.stop_points.map { |sp| sp.id + 1}} diff --git a/spec/models/chouette/route/route_duplication_spec.rb b/spec/models/chouette/route/route_duplication_spec.rb index 5bcd13fc8..ee45b5005 100644 --- a/spec/models/chouette/route/route_duplication_spec.rb +++ b/spec/models/chouette/route/route_duplication_spec.rb @@ -1,9 +1,4 @@ -# From Chouette import what we need ™ -Route = Chouette::Route -StopArea = Chouette::StopArea -StopPoint = Chouette::StopPoint - -RSpec.describe Route do +RSpec.describe Chouette::Route do let!( :route ){ create :route } @@ -11,7 +6,7 @@ RSpec.describe Route do describe 'properties' do it 'same attribute values' do route.duplicate - expect( values_for_create(Route.last, except: %w{objectid name checksum checksum_source}) ).to eq( values_for_create( route, except: %w{objectid name checksum checksum_source} ) ) + expect( values_for_create(Chouette::Route.last, except: %w{objectid name checksum checksum_source}) ).to eq( values_for_create( route, except: %w{objectid name checksum checksum_source} ) ) end it 'and others cannot' do expect{ route.duplicate name: 'YAN', line_id: 42 }.to raise_error(ArgumentError) @@ -23,13 +18,13 @@ RSpec.describe Route do describe 'side_effects' do it { - expect{ route.duplicate }.to change{Route.count}.by(1) + expect{ route.duplicate }.to change{Chouette::Route.count}.by(1) } it 'duplicates its stop points' do - expect{ route.duplicate }.to change{StopPoint.count}.by(route.stop_points.count) + expect{ route.duplicate }.to change{Chouette::StopPoint.count}.by(route.stop_points.count) end it 'does bot duplicate the stop areas' do - expect{ route.duplicate }.not_to change{StopArea.count} + expect{ route.duplicate }.not_to change{Chouette::StopArea.count} end end diff --git a/spec/models/chouette/routing_constraint_zone_spec.rb b/spec/models/chouette/routing_constraint_zone_spec.rb index c344642e6..8ebd8695c 100644 --- a/spec/models/chouette/routing_constraint_zone_spec.rb +++ b/spec/models/chouette/routing_constraint_zone_spec.rb @@ -7,6 +7,7 @@ describe Chouette::RoutingConstraintZone, type: :model do it { is_expected.to validate_presence_of :name } # shoulda matcher to validate length of array ? xit { is_expected.to validate_length_of(:stop_point_ids).is_at_least(2) } + it { is_expected.to be_versioned } describe 'checksum' do it_behaves_like 'checksum support', :routing_constraint_zone diff --git a/spec/models/chouette/stop_area_spec.rb b/spec/models/chouette/stop_area_spec.rb index a3a398bfb..c6aeafaf8 100644 --- a/spec/models/chouette/stop_area_spec.rb +++ b/spec/models/chouette/stop_area_spec.rb @@ -7,15 +7,11 @@ describe Chouette::StopArea, :type => :model do let!(:commercial_stop_point) { create :stop_area, :area_type => "lda" } let!(:stop_place) { create :stop_area, :area_type => "zdlp" } - describe '#objectid' do - subject { super().objectid } - it { should be_kind_of(Chouette::StifReflexObjectid) } - end - it { should belong_to(:stop_area_referential) } it { should validate_presence_of :name } it { should validate_numericality_of :latitude } it { should validate_numericality_of :longitude } + it { is_expected.to be_versioned } # describe ".latitude" do # it "should accept -90 value" do diff --git a/spec/models/chouette/stop_point_spec.rb b/spec/models/chouette/stop_point_spec.rb index 329e76a75..6b9e7727f 100644 --- a/spec/models/chouette/stop_point_spec.rb +++ b/spec/models/chouette/stop_point_spec.rb @@ -1,16 +1,14 @@ -# From Chouette import what we need ™ -StopPoint = Chouette::StopPoint - -describe StopPoint, :type => :model do +describe Chouette::StopPoint, :type => :model do let!(:vehicle_journey) { create(:vehicle_journey)} subject { Chouette::Route.find( vehicle_journey.route_id).stop_points.first } it { is_expected.to validate_uniqueness_of :objectid } it { is_expected.to validate_presence_of :stop_area } + it { is_expected.to be_versioned } describe '#objectid' do - subject { super().objectid } - it { is_expected.to be_kind_of(Chouette::StifNetexObjectid) } + subject { super().get_objectid } + it { is_expected.to be_kind_of(Chouette::Objectid::StifNetex) } end describe "#destroy" do @@ -44,7 +42,7 @@ describe StopPoint, :type => :model do let!( :new_route ){ create :route } it 'creates a new instance' do - expect{ subject.duplicate(for_route: new_route) }.to change{ StopPoint.count }.by(1) + expect{ subject.duplicate(for_route: new_route) }.to change{ Chouette::StopPoint.count }.by(1) end it 'new instance has a new route' do expect(subject.duplicate(for_route: new_route).route).to eq(new_route) diff --git a/spec/models/chouette/time_table_spec.rb b/spec/models/chouette/time_table_spec.rb index 761c39e5b..677308fc8 100644 --- a/spec/models/chouette/time_table_spec.rb +++ b/spec/models/chouette/time_table_spec.rb @@ -6,6 +6,7 @@ describe Chouette::TimeTable, :type => :model do it { is_expected.to validate_presence_of :comment } it { is_expected.to validate_uniqueness_of :objectid } + it { is_expected.to be_versioned } def create_time_table_periode time_table, start_date, end_date create(:time_table_period, time_table: time_table, :period_start => start_date, :period_end => end_date) diff --git a/spec/models/chouette/timeband_spec.rb b/spec/models/chouette/timeband_spec.rb index 1f812a6e2..b960c203f 100644 --- a/spec/models/chouette/timeband_spec.rb +++ b/spec/models/chouette/timeband_spec.rb @@ -1,6 +1,7 @@ require 'spec_helper' describe Chouette::Timeband, :type => :model do + it { is_expected.to be_versioned } describe '#create' do context 'when valid' do diff --git a/spec/models/chouette/trident_active_record_spec.rb b/spec/models/chouette/trident_active_record_spec.rb deleted file mode 100644 index d5e30594d..000000000 --- a/spec/models/chouette/trident_active_record_spec.rb +++ /dev/null @@ -1,57 +0,0 @@ -require 'spec_helper' - -describe Chouette::TridentActiveRecord, :type => :model do - subject { create(:time_table) } - - it { should validate_presence_of :objectid } - it { should validate_uniqueness_of :objectid } - - describe "#default_values" do - let(:object) { build(:time_table, objectid: nil) } - - it 'should fill __pending_id__' do - object.default_values - expect(object.objectid.include?('__pending_id__')).to be_truthy - end - end - - describe "#objectid" do - let(:object) { build(:time_table, objectid: nil) } - - it 'should build objectid on create' do - object.save - id = "#{object.provider_id}:#{object.model_name}:#{object.local_id}:#{object.boiv_id}" - expect(object.objectid).to eq(id) - end - - it 'should call build_objectid on after save' do - expect(object).to receive(:build_objectid) - object.save - end - - it 'should not build new objectid is already set' do - id = "first:TimeTable:1-1:LOC" - object.objectid = id - object.save - expect(object.objectid).to eq(id) - end - - it 'should call default_values on create' do - expect(object).to receive(:default_values) - object.save - end - - it 'should not call default_values on update' do - object = create(:time_table) - expect(object).to_not receive(:default_values) - object.touch - end - - it 'should create a new objectid when cleared' do - object.save - object.objectid = nil - object.save - expect(object.objectid).to be_truthy - end - end -end diff --git a/spec/models/chouette/vehicle_journey_at_stop_spec.rb b/spec/models/chouette/vehicle_journey_at_stop_spec.rb index 03e6fcb7d..df8a630fe 100644 --- a/spec/models/chouette/vehicle_journey_at_stop_spec.rb +++ b/spec/models/chouette/vehicle_journey_at_stop_spec.rb @@ -51,7 +51,7 @@ RSpec.describe Chouette::VehicleJourneyAtStop, type: :model do ) error_message = I18n.t( 'vehicle_journey_at_stops.errors.day_offset_must_not_exceed_max', - short_id: at_stop.vehicle_journey.objectid.short_id, + short_id: at_stop.vehicle_journey.get_objectid.short_id, max: bad_offset ) diff --git a/spec/models/chouette/vehicle_journey_spec.rb b/spec/models/chouette/vehicle_journey_spec.rb index 52f2ab42d..ac9b21ceb 100644 --- a/spec/models/chouette/vehicle_journey_spec.rb +++ b/spec/models/chouette/vehicle_journey_spec.rb @@ -1,6 +1,8 @@ require 'spec_helper' describe Chouette::VehicleJourney, :type => :model do + it { is_expected.to be_versioned } + it "must be valid with an at-stop day offset of 1" do vehicle_journey = create( :vehicle_journey, @@ -94,10 +96,13 @@ describe Chouette::VehicleJourney, :type => :model do expect { Chouette::VehicleJourney.state_update(route, collection) }.to change {Chouette::VehicleJourney.count}.by(1) + expect(collection.last['objectid']).not_to be_nil - vj = Chouette::VehicleJourney.find_by(objectid: collection.last['objectid']) - expect(vj.published_journey_name).to eq 'dummy' + obj = Chouette::VehicleJourney.last + obj.run_callbacks(:commit) + + expect(obj.published_journey_name).to eq 'dummy' end it 'should save vehicle_journey_at_stops of newly created vj' do diff --git a/spec/models/compliance_check_set_spec.rb b/spec/models/compliance_check_set_spec.rb index 0159d1c6b..b981a68bb 100644 --- a/spec/models/compliance_check_set_spec.rb +++ b/spec/models/compliance_check_set_spec.rb @@ -12,6 +12,7 @@ RSpec.describe ComplianceCheckSet, type: :model do it { should have_many :compliance_checks } it { should have_many :compliance_check_blocks } + it { is_expected.to be_versioned } describe "#update_status" do it "updates :status to successful when all resources are OK" do @@ -89,4 +90,13 @@ RSpec.describe ComplianceCheckSet, type: :model do expect(check_set.update_status).to be true end end + + describe 'possibility to delete the associated compliance_control_set' do + let!(:compliance_check_set) { create :compliance_check_set } + + it do + expect{ compliance_check_set.compliance_control_set.delete } + .to change{ ComplianceControlSet.count }.by(-1) + end + end end diff --git a/spec/models/compliance_check_spec.rb b/spec/models/compliance_check_spec.rb index bd797ab09..f83d78c29 100644 --- a/spec/models/compliance_check_spec.rb +++ b/spec/models/compliance_check_spec.rb @@ -1,4 +1,5 @@ RSpec.describe ComplianceCheck, type: :model do + it 'should have a valid factory' do expect(FactoryGirl.build(:compliance_check)).to be_valid end diff --git a/spec/models/compliance_control_class_level_defaults/route_control/unactivated_stop_point_cccld_spec.rb b/spec/models/compliance_control_class_level_defaults/route_control/unactivated_stop_point_cccld_spec.rb new file mode 100644 index 000000000..e9c335dea --- /dev/null +++ b/spec/models/compliance_control_class_level_defaults/route_control/unactivated_stop_point_cccld_spec.rb @@ -0,0 +1,7 @@ + +RSpec.describe RouteControl::UnactivatedStopPoint, type: :model do + let( :default_code ){ "3-Route-10" } + let( :factory ){ :route_control_unactivated_stop_point } + + it_behaves_like 'ComplianceControl Class Level Defaults' +end diff --git a/spec/models/compliance_control_class_level_defaults/route_control/unactivated_stop_points_cccld_spec.rb b/spec/models/compliance_control_class_level_defaults/route_control/unactivated_stop_points_cccld_spec.rb deleted file mode 100644 index bf725d743..000000000 --- a/spec/models/compliance_control_class_level_defaults/route_control/unactivated_stop_points_cccld_spec.rb +++ /dev/null @@ -1,7 +0,0 @@ - -RSpec.describe RouteControl::UnactivatedStopPoints, type: :model do - let( :default_code ){ "3-Route-10" } - let( :factory ){ :route_control_unactivated_stop_points } - - it_behaves_like 'ComplianceControl Class Level Defaults' -end diff --git a/spec/models/compliance_control_set_spec.rb b/spec/models/compliance_control_set_spec.rb index 04d1c418c..c157dcaf3 100644 --- a/spec/models/compliance_control_set_spec.rb +++ b/spec/models/compliance_control_set_spec.rb @@ -10,4 +10,5 @@ RSpec.describe ComplianceControlSet, type: :model do it { should have_many(:compliance_control_blocks).dependent(:destroy) } it { should validate_presence_of :name } + it { is_expected.to be_versioned } end diff --git a/spec/models/concerns/objectid_support_spec.rb b/spec/models/concerns/objectid_support_spec.rb new file mode 100644 index 000000000..fabeeec11 --- /dev/null +++ b/spec/models/concerns/objectid_support_spec.rb @@ -0,0 +1,138 @@ +RSpec.describe ObjectidSupport do + + context 'when referential has an objectid format of stif_netex' do + let(:object) { create(:time_table, objectid: nil) } + + context "#objectid_format" do + it "should be stif_netex" do + expect(object.referential.objectid_format).to eq('stif_netex') + end + end + + it 'should fill __pending_id__' do + expect(object.objectid.include?('__pending_id__')).to be_truthy + end + + context "#get_objectid" do + + before(:each) do + object.run_callbacks(:commit) + end + + it "should be valid" do + expect(object.get_objectid).to be_valid + end + + it "should have the same local id than the object" do + expect(object.get_objectid.local_id).to eq(object.local_id) + end + + it "should be a Chouette::Objectid::StifNetex" do + expect(object.get_objectid).to be_kind_of(Chouette::Objectid::StifNetex) + end + + context "#to_s" do + it "should return a string" do + expect(object.get_objectid.to_s).to be_kind_of(String) + end + + it "should be the same as the db attribute" do + expect(object.get_objectid.to_s).to eq(object.read_attribute(:objectid)) + expect(object.get_objectid.to_s).to eq(object.objectid) + end + + context "#objectid" do + + it 'should build objectid on create' do + object.save + object.run_callbacks(:commit) + objectid = object.get_objectid + id = "#{objectid.provider_id}:#{objectid.object_type}:#{objectid.local_id}:#{objectid.creation_id}" + expect(object.read_attribute(:objectid)).to eq(id) + end + + it 'should not build new objectid is already set' do + id = "first:TimeTable:1-1:LOC" + object.attributes = {objectid: id} + object.save + expect(object.objectid).to eq(id) + end + + it 'should create a new objectid when cleared' do + object.save + object.attributes = { objectid: nil} + object.save + expect(object.objectid).to be_truthy + end + end + end + end + end + + context 'when referential has an objectid format of netex' do + before(:all) do + Referential.first.update(objectid_format: 'netex') + end + + let(:object) { create(:time_table, objectid: nil) } + + + context "#objectid_format" do + it "should be netex" do + expect(object.referential.objectid_format).to eq('netex') + end + end + + context "#get_objectid" do + + it "should be valid" do + expect(object.get_objectid).to be_valid + end + + it "should have the same local id than the object" do + expect(object.get_objectid.local_id).to match(/\w+-\w+-\w+-\w+-\w+/) + end + + it "should be a Chouette::Objectid::StifNetex" do + expect(object.get_objectid).to be_kind_of(Chouette::Objectid::Netex) + end + + context "#to_s" do + it "should return a string" do + expect(object.get_objectid.to_s).to be_kind_of(String) + end + + it "should be the same as the db attribute" do + expect(object.get_objectid.to_s).to eq(object.read_attribute(:objectid)) + expect(object.get_objectid.to_s).to eq(object.objectid) + end + + context "#objectid" do + + it 'should build objectid on create' do + object.save + object.run_callbacks(:commit) + objectid = object.get_objectid + id = "#{objectid.provider_id}:#{objectid.object_type}:#{objectid.local_id}:#{objectid.creation_id}" + expect(object.read_attribute(:objectid)).to eq(id) + end + + it 'should not build new objectid is already set' do + id = "first:TimeTable:1-1:LOC" + object.attributes = {objectid: id} + object.save + expect(object.objectid).to eq(id) + end + + it 'should create a new objectid when cleared' do + object.save + object.attributes = { objectid: nil} + object.save + expect(object.objectid).to be_truthy + end + end + end + end + end + +end
\ No newline at end of file diff --git a/spec/models/line_referential_spec.rb b/spec/models/line_referential_spec.rb index 8f8714f8f..46434a7ab 100644 --- a/spec/models/line_referential_spec.rb +++ b/spec/models/line_referential_spec.rb @@ -7,5 +7,6 @@ RSpec.describe LineReferential, type: :model do it { is_expected.to have_many(:line_referential_syncs) } it { is_expected.to have_many(:workbenches) } it { should validate_presence_of(:sync_interval) } + it { should validate_presence_of(:objectid_format) } end diff --git a/spec/models/referential_spec.rb b/spec/models/referential_spec.rb index ad9c43010..d0b1d6447 100644 --- a/spec/models/referential_spec.rb +++ b/spec/models/referential_spec.rb @@ -12,6 +12,12 @@ describe Referential, :type => :model do it { should belong_to(:workbench) } it { should belong_to(:referential_suite) } + context "validation" do + subject { build_stubbed(:referential) } + + it { should validate_presence_of(:objectid_format) } + end + context ".referential_ids_in_periode" do it 'should retrieve referential id in periode range' do range = ref.metadatas.first.periodes.sample diff --git a/spec/models/stop_area_referential_spec.rb b/spec/models/stop_area_referential_spec.rb index 271badff8..dd2bdce20 100644 --- a/spec/models/stop_area_referential_spec.rb +++ b/spec/models/stop_area_referential_spec.rb @@ -7,4 +7,5 @@ RSpec.describe StopAreaReferential, :type => :model do it { is_expected.to have_many(:stop_area_referential_syncs) } it { is_expected.to have_many(:workbenches) } + it { should validate_presence_of(:objectid_format) } end diff --git a/spec/models/workbench_spec.rb b/spec/models/workbench_spec.rb index 037537b60..3b9ed6b07 100644 --- a/spec/models/workbench_spec.rb +++ b/spec/models/workbench_spec.rb @@ -7,6 +7,7 @@ RSpec.describe Workbench, :type => :model do it { should validate_presence_of(:name) } it { should validate_presence_of(:organisation) } + it { should validate_presence_of(:objectid_format) } it { should belong_to(:organisation) } it { should belong_to(:line_referential) } diff --git a/spec/policies/company_policy_spec.rb b/spec/policies/company_policy_spec.rb index 2d249a2be..e018902ca 100644 --- a/spec/policies/company_policy_spec.rb +++ b/spec/policies/company_policy_spec.rb @@ -1,3 +1,4 @@ +# coding: utf-8 RSpec.describe CompanyPolicy, type: :policy do let( :record ){ build_stubbed :company } @@ -24,19 +25,19 @@ RSpec.describe CompanyPolicy, type: :policy do context 'Destructive actions →' do permissions :create? do - it_behaves_like 'always forbidden', 'companies.create', archived: true + it_behaves_like 'permitted policy', 'companies.create' end permissions :destroy? do - it_behaves_like 'always forbidden', 'companies.destroy', archived: true + it_behaves_like 'permitted policy', 'companies.destroy' end permissions :edit? do - it_behaves_like 'always forbidden', 'companies.update', archived: true + it_behaves_like 'permitted policy', 'companies.update' end permissions :new? do - it_behaves_like 'always forbidden', 'companies.create', archived: true + it_behaves_like 'permitted policy', 'companies.create' end permissions :update? do - it_behaves_like 'always forbidden', 'companies.update', archived: true + it_behaves_like 'permitted policy', 'companies.update' end end end diff --git a/spec/policies/import_policy_spec.rb b/spec/policies/import_policy_spec.rb index fd9f3172c..9c7fca8a5 100644 --- a/spec/policies/import_policy_spec.rb +++ b/spec/policies/import_policy_spec.rb @@ -9,10 +9,10 @@ RSpec.describe ImportPolicy, type: :policy do context 'Non Destructive actions →' do permissions :index? do - it_behaves_like 'always allowed', 'anything', archived: true + it_behaves_like 'always allowed', 'anything' end permissions :show? do - it_behaves_like 'always allowed', 'anything', archived: true + it_behaves_like 'always allowed', 'anything' end end @@ -23,19 +23,19 @@ RSpec.describe ImportPolicy, type: :policy do context 'Destructive actions →' do permissions :create? do - it_behaves_like 'permitted policy', 'imports.create', archived: true + it_behaves_like 'permitted policy', 'imports.create' end permissions :destroy? do - it_behaves_like 'permitted policy', 'imports.destroy', archived: true + it_behaves_like 'always forbidden', 'imports.destroy' end permissions :edit? do - it_behaves_like 'permitted policy', 'imports.update', archived: true + it_behaves_like 'permitted policy', 'imports.update' end permissions :new? do - it_behaves_like 'permitted policy', 'imports.create', archived: true + it_behaves_like 'permitted policy', 'imports.create' end permissions :update? do - it_behaves_like 'permitted policy', 'imports.update', archived: true + it_behaves_like 'permitted policy', 'imports.update' end end end diff --git a/spec/policies/line_policy_spec.rb b/spec/policies/line_policy_spec.rb index 334073506..452606bcf 100644 --- a/spec/policies/line_policy_spec.rb +++ b/spec/policies/line_policy_spec.rb @@ -1,3 +1,4 @@ +# coding: utf-8 RSpec.describe LinePolicy, type: :policy do let( :record ){ build_stubbed :line } @@ -24,19 +25,19 @@ RSpec.describe LinePolicy, type: :policy do context 'Destructive actions →' do permissions :create? do - it_behaves_like 'always forbidden', 'lines.create', archived: true + it_behaves_like 'permitted policy', 'lines.create' end permissions :destroy? do - it_behaves_like 'always forbidden', 'lines.destroy', archived: true + it_behaves_like 'permitted policy', 'lines.destroy' end permissions :edit? do - it_behaves_like 'always forbidden', 'lines.update', archived: true + it_behaves_like 'permitted policy', 'lines.update' end permissions :new? do - it_behaves_like 'always forbidden', 'lines.create', archived: true + it_behaves_like 'permitted policy', 'lines.create' end permissions :update? do - it_behaves_like 'always forbidden', 'lines.update', archived: true + it_behaves_like 'permitted policy', 'lines.update' end end diff --git a/spec/policies/network_policy_spec.rb b/spec/policies/network_policy_spec.rb index ae4ffa03a..c09546c22 100644 --- a/spec/policies/network_policy_spec.rb +++ b/spec/policies/network_policy_spec.rb @@ -1,4 +1,4 @@ -RSpec.describe NetworkPolicy, type: :policy do +RSpec.describe Chouette::NetworkPolicy, type: :policy do let( :record ){ build_stubbed :network } before { stub_policy_scope(record) } diff --git a/spec/policies/route_policy_spec.rb b/spec/policies/route_policy_spec.rb index d7edceaef..df2e41a89 100644 --- a/spec/policies/route_policy_spec.rb +++ b/spec/policies/route_policy_spec.rb @@ -1,4 +1,4 @@ -RSpec.describe RoutePolicy, type: :policy do +RSpec.describe Chouette::RoutePolicy, type: :policy do let( :record ){ build_stubbed :route } diff --git a/spec/policies/stop_area_policy_spec.rb b/spec/policies/stop_area_policy_spec.rb index 8fe59c8e3..90835d1d8 100644 --- a/spec/policies/stop_area_policy_spec.rb +++ b/spec/policies/stop_area_policy_spec.rb @@ -1,3 +1,4 @@ +# coding: utf-8 RSpec.describe StopAreaPolicy, type: :policy do let( :record ){ build_stubbed :stop_area } @@ -24,19 +25,19 @@ RSpec.describe StopAreaPolicy, type: :policy do context 'Destructive actions →' do permissions :create? do - it_behaves_like 'always forbidden', 'stop_areas.create', archived: true + it_behaves_like 'permitted policy', 'stop_areas.create' end permissions :destroy? do - it_behaves_like 'always forbidden', 'stop_areas.destroy', archived: true + it_behaves_like 'permitted policy', 'stop_areas.destroy' end permissions :edit? do - it_behaves_like 'always forbidden', 'stop_areas.update', archived: true + it_behaves_like 'permitted policy', 'stop_areas.update' end permissions :new? do - it_behaves_like 'always forbidden', 'stop_areas.create', archived: true + it_behaves_like 'permitted policy', 'stop_areas.create' end permissions :update? do - it_behaves_like 'always forbidden', 'stop_areas.update', archived: true + it_behaves_like 'permitted policy', 'stop_areas.update' end end end diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 6d9f4a4a2..47578405e 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -3,6 +3,7 @@ ENV["RAILS_ENV"] ||= 'test' require 'spec_helper' require File.expand_path("../../config/environment", __FILE__) require 'rspec/rails' + # Add additional requires below this line. Rails is not loaded until this point! # Requires supporting ruby files with custom matchers and macros, etc, in diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 6b37b9fa8..9679952df 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -34,6 +34,7 @@ require 'webmock/rspec' require 'simplecov' require 'sidekiq/testing' Sidekiq::Testing.fake! +require 'paper_trail/frameworks/rspec' # Requires supporting ruby files with custom matchers and macros, etc, in # spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are diff --git a/spec/support/referential.rb b/spec/support/referential.rb index 6f60bd86b..b615491da 100644 --- a/spec/support/referential.rb +++ b/spec/support/referential.rb @@ -46,9 +46,11 @@ RSpec.configure do |config| organisation = Organisation.create!(code: "first", name: "first") line_referential = LineReferential.find_or_create_by(name: "first") do |referential| + referential.objectid_format = "stif_codifligne" referential.add_member organisation, owner: true end stop_area_referential = StopAreaReferential.find_or_create_by(name: "first") do |referential| + referential.objectid_format = "stif_reflex" referential.add_member organisation, owner: true end @@ -65,7 +67,8 @@ RSpec.configure do |config| name: "first", slug: "first", organisation: organisation, - workbench: workbench + workbench: workbench, + objectid_format: "stif_netex" ) end diff --git a/spec/views/companies/edit.html.erb_spec.rb b/spec/views/companies/edit.html.erb_spec.rb index 4566ed64c..8aaf705ab 100644 --- a/spec/views/companies/edit.html.erb_spec.rb +++ b/spec/views/companies/edit.html.erb_spec.rb @@ -6,13 +6,6 @@ describe "/companies/edit", :type => :view do let!(:companies) { Array.new(2) { create(:company) } } let!(:line_referential) { assign :line_referential, company.line_referential } - describe "test" do - it "should render h2 with the company name" do - render - expect(rendered).to have_selector("h2", :text => Regexp.new(company.name)) - end - end - describe "form" do it "should render input for name" do render @@ -21,5 +14,4 @@ describe "/companies/edit", :type => :view do end end end - end diff --git a/spec/views/companies/show.html.erb_spec.rb b/spec/views/companies/show.html.erb_spec.rb index dbc544f63..aeb93aebb 100644 --- a/spec/views/companies/show.html.erb_spec.rb +++ b/spec/views/companies/show.html.erb_spec.rb @@ -5,24 +5,8 @@ describe "/companies/show", :type => :view do let!(:company) { assign(:company, create(:company)) } let!(:line_referential) { assign :line_referential, company.line_referential } - it "should render h1 with the company name" do - render - expect(rendered).to have_selector("h1", :text => Regexp.new(company.name)) - end - # it "should display a map with class 'company'" do # render # expect(rendered).to have_selector("#map", :class => 'company') # end - - it "should render a link to edit the company" do - render - expect(rendered).to have_selector("a[href='#{view.edit_line_referential_company_path(line_referential, company)}']") - end - - it "should render a link to remove the company" do - render - expect(rendered).to have_selector("a[href='#{view.line_referential_company_path(line_referential, company)}']") - end - end diff --git a/spec/views/lines/edit.html.erb_spec.rb b/spec/views/lines/edit.html.erb_spec.rb index 6cd2940f5..2af4df10a 100644 --- a/spec/views/lines/edit.html.erb_spec.rb +++ b/spec/views/lines/edit.html.erb_spec.rb @@ -8,13 +8,6 @@ describe "/lines/edit", :type => :view do let!(:lines) { Array.new(2) { create(:line, :network => network, :company => company) } } let!(:line_referential) { assign :line_referential, line.line_referential } - describe "test" do - it "should render h2 with the group name" do - render - expect(rendered).to have_selector("h2", :text => Regexp.new(line.name)) - end - end - describe "form" do it "should render input for name" do render diff --git a/spec/views/lines/show.html.erb_spec.rb b/spec/views/lines/show.html.erb_spec.rb index 7bc120f1a..9649d9c8e 100644 --- a/spec/views/lines/show.html.erb_spec.rb +++ b/spec/views/lines/show.html.erb_spec.rb @@ -17,25 +17,4 @@ describe "/lines/show", :type => :view do before do allow(view).to receive_messages(current_organisation: referential.organisation) end - - it "should render h1 with the line name" do - render - expect(rendered).to have_selector("h1", :text => Regexp.new(line.name)) - end - - # it "should display a map with class 'line'" do - # render - # expect(rendered).to have_selector("#map", :class => 'line') - # end - # FIXME #2018 - xit "should render a link to edit the line" do - render - expect(rendered).to have_selector("a[href='#{view.edit_line_referential_line_path(line_referential, line)}']") - end - - it "should render a link to remove the line" do - render - expect(rendered).to have_selector("a[href='#{view.line_referential_line_path(line_referential, line)}']") - end - end diff --git a/spec/views/networks/edit.html.erb_spec.rb b/spec/views/networks/edit.html.erb_spec.rb index f77459837..aac6d4d28 100644 --- a/spec/views/networks/edit.html.erb_spec.rb +++ b/spec/views/networks/edit.html.erb_spec.rb @@ -5,13 +5,6 @@ describe "/networks/edit", :type => :view do let!(:network) { assign(:network, create(:network) ) } let!(:line_referential) { assign :line_referential, network.line_referential } - describe "test" do - it "should render h2 with the group name" do - render - expect(rendered).to have_selector("h2", :text => Regexp.new(network.name)) - end - end - describe "form" do it "should render input for name" do render diff --git a/spec/views/networks/show.html.erb_spec.rb b/spec/views/networks/show.html.erb_spec.rb index 72605fb46..3926ead14 100644 --- a/spec/views/networks/show.html.erb_spec.rb +++ b/spec/views/networks/show.html.erb_spec.rb @@ -11,24 +11,8 @@ describe "/networks/show", :type => :view do let!(:map) { assign(:map, double(:to_html => '<div id="map"/>'.html_safe)) } let!(:line_referential) { assign :line_referential, network.line_referential } - it "should render h1 with the network name" do - render - expect(rendered).to have_selector("h1", :text => Regexp.new(network.name)) - end - # it "should display a map with class 'network'" do # render # expect(rendered).to have_selector("#map") # end - - it "should render a link to edit the network" do - render - expect(rendered).to have_selector("a[href='#{view.edit_line_referential_network_path(line_referential, network)}']") - end - - it "should render a link to remove the network" do - render - expect(rendered).to have_selector("a[href='#{view.line_referential_network_path(line_referential, network)}']") - end - end diff --git a/spec/views/routes/show.html.erb_spec.rb b/spec/views/routes/show.html.erb_spec.rb index dae8c9ed3..3bbfaa799 100644 --- a/spec/views/routes/show.html.erb_spec.rb +++ b/spec/views/routes/show.html.erb_spec.rb @@ -22,20 +22,4 @@ RSpec.describe "/routes/show", type: :view do referential )) end - - it "should render h1 with the route name" do - render - expect(rendered).to have_selector("h1", :text => Regexp.new(route.name)) - end - - it "should render a link to edit the route" do - render - expect(rendered).to have_selector("a[href='#{view.edit_referential_line_route_path(referential, line, route)}']") - end - - it "should render a link to remove the route" do - render - expect(rendered).to have_selector("a[href='#{view.referential_line_route_path(referential, line, route)}']") - end - end diff --git a/spec/views/stop_areas/edit.html.erb_spec.rb b/spec/views/stop_areas/edit.html.erb_spec.rb index 664225203..5105bff4b 100644 --- a/spec/views/stop_areas/edit.html.erb_spec.rb +++ b/spec/views/stop_areas/edit.html.erb_spec.rb @@ -6,13 +6,6 @@ describe "/stop_areas/edit", :type => :view do let!(:stop_area) { assign(:stop_area, create(:stop_area)) } let!(:map) { assign(:map, double(:to_html => '<div id="map"/>'.html_safe)) } - describe "test" do - it "should render h2 with the group name" do - render - expect(rendered).to have_selector("h2", :text => Regexp.new(stop_area.name)) - end - end - describe "form" do it "should render input for name" do render diff --git a/spec/views/stop_areas/show.html.erb_spec.rb b/spec/views/stop_areas/show.html.erb_spec.rb index 6fd416128..693d9cf1f 100644 --- a/spec/views/stop_areas/show.html.erb_spec.rb +++ b/spec/views/stop_areas/show.html.erb_spec.rb @@ -7,24 +7,8 @@ describe "/stop_areas/show", :type => :view do let!(:access_points) { assign :access_points, [] } let!(:map) { assign(:map, double(:to_html => '<div id="map"/>'.html_safe)) } - it "should render h1 with the stop_area name" do - render - expect(rendered).to have_selector("h1", :text => Regexp.new(stop_area.name)) - end - # it "should display a map with class 'stop_area'" do # render # expect(rendered).to have_selector("#map", :class => 'stop_area') # end - - it "should render a link to edit the stop_area" do - render - expect(rendered).to have_selector("a[href='#{view.edit_stop_area_referential_stop_area_path(stop_area_referential, stop_area)}']") - end - - it "should render a link to remove the stop_area" do - render - expect(rendered).to have_selector("a[href='#{view.stop_area_referential_stop_area_path(stop_area_referential, stop_area)}']") - end - end diff --git a/spec/views/time_tables/edit.html.erb_spec.rb b/spec/views/time_tables/edit.html.erb_spec.rb index c84c5eb74..f431eab7b 100644 --- a/spec/views/time_tables/edit.html.erb_spec.rb +++ b/spec/views/time_tables/edit.html.erb_spec.rb @@ -3,13 +3,5 @@ require 'spec_helper' describe "/time_tables/edit", :type => :view do assign_referential let!(:time_table) { assign(:time_table, create(:time_table) ) } - - describe "test" do - it "should render h1 with the group comment" do - render - expect(rendered).to have_selector("h1", :text => Regexp.new(time_table.comment)) - end - end - # No more test for the form, as it is now managed by React/Redux. end diff --git a/spec/views/time_tables/show.html.erb_spec.rb b/spec/views/time_tables/show.html.erb_spec.rb index edfb3f3cc..100c74b90 100644 --- a/spec/views/time_tables/show.html.erb_spec.rb +++ b/spec/views/time_tables/show.html.erb_spec.rb @@ -17,20 +17,4 @@ describe "/time_tables/show", :type => :view do before do allow(view).to receive_messages(current_organisation: referential.organisation) end - - it "should render h2 with the time_table comment" do - render - expect(rendered).to have_selector("h1", :text => Regexp.new(time_table.comment)) - end - - it "should render a link to edit the time_table" do - render - expect(rendered).to have_selector(" a[href='#{view.edit_referential_time_table_path(referential, time_table)}']") - end - - it "should render a link to remove the time_table" do - render - expect(rendered).to have_selector(" a[href='#{view.referential_time_table_path(referential, time_table)}']") - end - end |
