aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/routes_controller_spec.rb51
-rw-r--r--spec/factories/compliance_check_blocks.rb6
-rw-r--r--spec/factories/compliance_check_resources.rb6
-rw-r--r--spec/factories/compliance_check_results.rb7
-rw-r--r--spec/factories/compliance_check_sets.rb8
-rw-r--r--spec/factories/compliance_checks.rb11
-rw-r--r--spec/factories/compliance_control_blocks.rb6
-rw-r--r--spec/factories/compliance_control_sets.rb6
-rw-r--r--spec/factories/compliance_controls.rb11
-rw-r--r--spec/factories/import_messages.rb7
-rw-r--r--spec/factories/workbenches.rb4
-rw-r--r--spec/features/referentials_spec.rb67
-rw-r--r--spec/features/users/user_edit_spec.rb1
-rw-r--r--spec/features/users/user_index_spec.rb1
-rw-r--r--spec/features/users/user_show_spec.rb2
-rw-r--r--spec/models/chouette/route/route_duplication_spec.rb52
-rw-r--r--spec/models/chouette/stop_point_spec.rb19
-rw-r--r--spec/models/compliance_check_block_spec.rb9
-rw-r--r--spec/models/compliance_check_resource_spec.rb7
-rw-r--r--spec/models/compliance_check_result_spec.rb10
-rw-r--r--spec/models/compliance_check_set_spec.rb12
-rw-r--r--spec/models/compliance_check_spec.rb14
-rw-r--r--spec/models/compliance_control_block_spec.rb9
-rw-r--r--spec/models/compliance_control_set_spec.rb9
-rw-r--r--spec/models/compliance_control_spec.rb14
-rw-r--r--spec/models/import_spec.rb35
-rw-r--r--spec/models/referential_metadata_spec.rb4
-rw-r--r--spec/policies/route_policy_spec.rb4
-rw-r--r--spec/routing/routes_routing_spec.rb12
-rw-r--r--spec/support/helpers/model_compare_helpers.rb15
-rw-r--r--spec/support/referential.rb2
31 files changed, 390 insertions, 31 deletions
diff --git a/spec/controllers/routes_controller_spec.rb b/spec/controllers/routes_controller_spec.rb
index 000b799db..336f20945 100644
--- a/spec/controllers/routes_controller_spec.rb
+++ b/spec/controllers/routes_controller_spec.rb
@@ -1,7 +1,9 @@
-RSpec.describe RoutesController, :type => :controller do
+Route = Chouette::Route
+
+RSpec.describe RoutesController, type: :controller do
login_user
- let!(:route) { create(:route) }
+ let(:route) { create(:route) }
it { is_expected.to be_kind_of(ChouetteController) }
@@ -10,6 +12,7 @@ RSpec.describe RoutesController, :type => :controller do
# expect(response).to redirect_to( referential_line_path(referential,route.line) )
end
end
+
shared_examples_for "line and referential linked" do
it "assigns route.line as @line" do
expect(assigns[:line]).to eq(route.line)
@@ -19,6 +22,7 @@ RSpec.describe RoutesController, :type => :controller do
expect(assigns[:referential]).to eq(referential)
end
end
+
shared_examples_for "route, line and referential linked" do
it "assigns route as @route" do
expect(assigns[:route]).to eq(route)
@@ -28,8 +32,8 @@ RSpec.describe RoutesController, :type => :controller do
describe "GET /index" do
before(:each) do
- get :index, :line_id => route.line_id,
- :referential_id => referential.id
+ get :index, line_id: route.line_id,
+ referential_id: referential.id
end
it_behaves_like "line and referential linked"
@@ -38,9 +42,9 @@ RSpec.describe RoutesController, :type => :controller do
describe "POST /create" do
before(:each) do
- post :create, :line_id => route.line_id,
- :referential_id => referential.id,
- :route => { :name => "changed"}
+ post :create, line_id: route.line_id,
+ referential_id: referential.id,
+ route: { name: "changed"}
end
it_behaves_like "line and referential linked"
@@ -49,9 +53,9 @@ RSpec.describe RoutesController, :type => :controller do
describe "PUT /update" do
before(:each) do
- put :update, :id => route.id, :line_id => route.line_id,
- :referential_id => referential.id,
- :route => route.attributes
+ put :update, id: route.id, line_id: route.line_id,
+ referential_id: referential.id,
+ route: route.attributes
end
it_behaves_like "route, line and referential linked"
@@ -60,9 +64,9 @@ RSpec.describe RoutesController, :type => :controller do
describe "GET /show" do
before(:each) do
- get :show, :id => route.id,
- :line_id => route.line_id,
- :referential_id => referential.id
+ get :show, id: route.id,
+ line_id: route.line_id,
+ referential_id: referential.id
end
it_behaves_like "route, line and referential linked"
@@ -71,11 +75,22 @@ RSpec.describe RoutesController, :type => :controller do
expect(assigns[:map]).to be_an_instance_of(RouteMap)
expect(assigns[:map].route).to eq(route)
end
-
- #it "assigns route.stop_points.paginate(:page => nil) as @stop_points" do
- # expect(assigns[:stop_points]).to eq(route.stop_points.paginate(:page => nil))
- #end
end
-end
+ describe "POST /duplicate" do
+ let!( :route_prime ){ route }
+
+ it "creates a new route" do
+ expect do
+ post :duplicate,
+ referential_id: route.line.line_referential_id,
+ line_id: route.line_id,
+ id: route.id
+ end.to change { Route.count }.by(1)
+
+ expect(Route.last.name).to eq(route.name)
+ expect(Route.last.published_name).to eq(route.published_name)
+ end
+ end
+end
diff --git a/spec/factories/compliance_check_blocks.rb b/spec/factories/compliance_check_blocks.rb
new file mode 100644
index 000000000..0bd23c0d6
--- /dev/null
+++ b/spec/factories/compliance_check_blocks.rb
@@ -0,0 +1,6 @@
+FactoryGirl.define do
+ factory :compliance_check_block do
+ sequence(:name) { |n| "Compliance check block #{n}" }
+ association :compliance_check_set
+ end
+end
diff --git a/spec/factories/compliance_check_resources.rb b/spec/factories/compliance_check_resources.rb
new file mode 100644
index 000000000..813153be2
--- /dev/null
+++ b/spec/factories/compliance_check_resources.rb
@@ -0,0 +1,6 @@
+FactoryGirl.define do
+ factory :compliance_check_resource do
+ status :new
+ sequence(:name) { |n| "Compliance check resource #{n}" }
+ end
+end
diff --git a/spec/factories/compliance_check_results.rb b/spec/factories/compliance_check_results.rb
new file mode 100644
index 000000000..a56d77ce4
--- /dev/null
+++ b/spec/factories/compliance_check_results.rb
@@ -0,0 +1,7 @@
+FactoryGirl.define do
+ factory :compliance_check_result do
+ association :compliance_check
+ association :compliance_check_resource
+ message_key "message_key"
+ end
+end
diff --git a/spec/factories/compliance_check_sets.rb b/spec/factories/compliance_check_sets.rb
new file mode 100644
index 000000000..9fd6ef4e0
--- /dev/null
+++ b/spec/factories/compliance_check_sets.rb
@@ -0,0 +1,8 @@
+FactoryGirl.define do
+ factory :compliance_check_set do
+ status :new
+ association :referential
+ association :compliance_control_set
+ association :workbench
+ end
+end
diff --git a/spec/factories/compliance_checks.rb b/spec/factories/compliance_checks.rb
new file mode 100644
index 000000000..4009653da
--- /dev/null
+++ b/spec/factories/compliance_checks.rb
@@ -0,0 +1,11 @@
+FactoryGirl.define do
+ factory :compliance_check do
+ sequence(:name) { |n| "Compliance check #{n}" }
+ type "Type"
+ criticity :info
+ code "code"
+ comment "Text"
+ association :compliance_check_set
+ association :compliance_check_block
+ end
+end
diff --git a/spec/factories/compliance_control_blocks.rb b/spec/factories/compliance_control_blocks.rb
new file mode 100644
index 000000000..5bc45cc75
--- /dev/null
+++ b/spec/factories/compliance_control_blocks.rb
@@ -0,0 +1,6 @@
+FactoryGirl.define do
+ factory :compliance_control_block do
+ sequence(:name) { |n| "Compliance control block #{n}" }
+ association :compliance_control_set
+ end
+end
diff --git a/spec/factories/compliance_control_sets.rb b/spec/factories/compliance_control_sets.rb
new file mode 100644
index 000000000..5e4acf3c4
--- /dev/null
+++ b/spec/factories/compliance_control_sets.rb
@@ -0,0 +1,6 @@
+FactoryGirl.define do
+ factory :compliance_control_set do
+ sequence(:name) { |n| "Compliance control set #{n}" }
+ association :organisation
+ end
+end
diff --git a/spec/factories/compliance_controls.rb b/spec/factories/compliance_controls.rb
new file mode 100644
index 000000000..28b760383
--- /dev/null
+++ b/spec/factories/compliance_controls.rb
@@ -0,0 +1,11 @@
+FactoryGirl.define do
+ factory :compliance_control do
+ sequence(:name) { |n| "Compliance control #{n}" }
+ type "Type"
+ criticity :info
+ code "code"
+ comment "Text"
+ association :compliance_control_set
+ association :compliance_control_block
+ end
+end
diff --git a/spec/factories/import_messages.rb b/spec/factories/import_messages.rb
new file mode 100644
index 000000000..75f80566c
--- /dev/null
+++ b/spec/factories/import_messages.rb
@@ -0,0 +1,7 @@
+FactoryGirl.define do
+ factory :import_message do
+ association :import
+ association :resource, factory: :import_resource
+ criticity :info
+ end
+end
diff --git a/spec/factories/workbenches.rb b/spec/factories/workbenches.rb
index f51e7d94c..d55141513 100644
--- a/spec/factories/workbenches.rb
+++ b/spec/factories/workbenches.rb
@@ -1,8 +1,8 @@
FactoryGirl.define do
factory :workbench do
- sequence(:name) { |n| "Workbench #{n}" }
+ name "Gestion de l'offre"
- association :organisation, :factory => :organisation
+ association :organisation
association :line_referential
association :stop_area_referential
end
diff --git a/spec/features/referentials_spec.rb b/spec/features/referentials_spec.rb
index 337271fea..a38577aba 100644
--- a/spec/features/referentials_spec.rb
+++ b/spec/features/referentials_spec.rb
@@ -120,6 +120,73 @@ describe "Referentials", :type => :feature do
end
+ describe "new_from" do
+ # let(:cloning)
+ let(:worker) { ReferentialCloningWorker.new }
+
+ let(:line) { create(:line_with_stop_areas) }
+ let(:jp) { create(:journey_pattern, route: line.routes.first) }
+ let(:tt) { create(:time_table) }
+ let(:vj) { create(:vehicle_journey, journey_pattern: jp, time_table: tt) }
+ let(:ref_metadata) { create(:referential_metadata, lines: [line], referential: referential) }
+
+ context "when user is from the same organisation" do
+
+ xit "should" do
+ visit new_referential_path(from: referential.id, current_workbench_id: @user.organisation.workbenches.first.id)
+
+ select "2018", :from => "referential_metadatas_attributes_0_periods_attributes_0_begin_1i"
+
+ select "2018", :from => "referential_metadatas_attributes_0_periods_attributes_0_end_1i"
+
+ click_button "Valider"
+
+ clone = Referential.where(name: "Copie de first")
+
+ expect(clone.lines).to include(line)
+ expect(clone.lines.first.routes).to match_array(referential.lines.first.routes)
+
+ clone_jp = clone.lines.first.routes.first.journey_patterns
+ expect(clone_jp).to include(jp)
+
+ clone_vj = clone.lines.first.routes.first.journey_patterns.first.vehicle_journeys
+ expect(clone_vj).to include(vj)
+
+ clone_tt = clone.lines.first.routes.first.journey_patterns.first.vehicle_journeys.first.time_tables
+ expect(clone_tt).to include(tt)
+ end
+
+ # it "should have the lines from source" do
+ # expect(clone.lines).to include(line)
+ # end
+ #
+ # it "should have the routes from source" do
+ # expect(clone.lines.first.routes).to match_array(referential.lines.first.routes)
+ # end
+ #
+ # it "should have the journey patterns from source" do
+ # clone_jp = clone.lines.first.routes.first.journey_patterns
+ # expect(clone_jp).to include(jp)
+ # end
+ #
+ # it "should have the vehicle journeys from source" do
+ # clone_vj = clone.lines.first.routes.first.journey_patterns.first.vehicle_journeys
+ # expect(clone_vj).to include(vj)
+ # end
+ #
+ # it "should have the timetables from source" do
+ # clone_tt = clone.lines.first.routes.first.journey_patterns.first.vehicle_journeys.first.time_tables
+ # expect(clone_tt).to include(tt)
+ # end
+ end
+
+ # context "when user is from another organisation" do
+ # before :each do
+ #
+ # end
+ # end
+ end
+
describe "destroy" do
let(:referential) { create(:referential, :organisation => @user.organisation) }
diff --git a/spec/features/users/user_edit_spec.rb b/spec/features/users/user_edit_spec.rb
index 4b083a226..14995d8e5 100644
--- a/spec/features/users/user_edit_spec.rb
+++ b/spec/features/users/user_edit_spec.rb
@@ -36,6 +36,7 @@ feature 'User edit', :devise do
# Then I see my own 'edit profile' page
scenario "user cannot cannot edit another user's profile", :me do
me = FactoryGirl.create(:user)
+ me.organisation.workbenches << create(:workbench)
other = FactoryGirl.create(:user, email: 'other@example.com')
login_as(me, :scope => :user)
visit edit_user_registration_path(other)
diff --git a/spec/features/users/user_index_spec.rb b/spec/features/users/user_index_spec.rb
index 2a9199da3..b2dbdbb51 100644
--- a/spec/features/users/user_index_spec.rb
+++ b/spec/features/users/user_index_spec.rb
@@ -19,6 +19,7 @@ feature 'User index page', :devise do
# Then I see my own email address
scenario 'user sees own email address' do
user = create(:user)
+ user.organisation.workbenches << create(:workbench)
login_as(user, scope: :user)
visit organisation_path
expect(page).to have_content user.name.truncate(15)
diff --git a/spec/features/users/user_show_spec.rb b/spec/features/users/user_show_spec.rb
index d840d752c..ae3c25933 100644
--- a/spec/features/users/user_show_spec.rb
+++ b/spec/features/users/user_show_spec.rb
@@ -19,6 +19,7 @@ feature 'User profile page', :devise do
# Then I see my own email address
scenario 'user sees own profile' do
user = FactoryGirl.create(:user)
+ user.organisation.workbenches << create(:workbench)
login_as(user, :scope => :user)
visit organisation_user_path(user)
# FIXME ref #819
@@ -32,6 +33,7 @@ feature 'User profile page', :devise do
# Then I see an 'access denied' message
scenario "user cannot see another user's profile" do
me = FactoryGirl.create(:user)
+ me.organisation.workbenches << create(:workbench)
other = FactoryGirl.create(:user, email: 'other@example.com', :organisation => me.organisation)
login_as(me, :scope => :user)
Capybara.current_session.driver.header 'Referer', authenticated_root_path
diff --git a/spec/models/chouette/route/route_duplication_spec.rb b/spec/models/chouette/route/route_duplication_spec.rb
new file mode 100644
index 000000000..6645b909f
--- /dev/null
+++ b/spec/models/chouette/route/route_duplication_spec.rb
@@ -0,0 +1,52 @@
+# From Chouette import what we need ™
+Route = Chouette::Route
+StopArea = Chouette::StopArea
+StopPoint = Chouette::StopPoint
+
+RSpec.describe Route do
+
+ let!( :route ){ create :route }
+
+ context '#duplicate' do
+ describe 'properties' do
+ it 'same attribute values' do
+ route.duplicate
+ expect( values_for_create(Route.last, except: %w{objectid}) ).to eq( values_for_create( route, except: %w{objectid} ) )
+ end
+ it 'and others cannot' do
+ expect{ route.duplicate name: 'YAN', line_id: 42 }.to raise_error(ArgumentError)
+ end
+ it 'same associated stop_areeas' do
+ expect( route.duplicate.stop_areas.pluck(:id) ).to eq(route.stop_areas.pluck(:id))
+ end
+ end
+
+ describe 'side_effects' do
+ it {
+ expect{ route.duplicate }.to change{Route.count}.by(1)
+ }
+ it 'duplicates its stop points' do
+ expect{ route.duplicate }.to change{StopPoint.count}.by(route.stop_points.count)
+ end
+ it 'does bot duplicate the stop areas' do
+ expect{ route.duplicate }.not_to change{StopArea.count}
+ end
+ end
+
+ describe 'is idempotent, concerning' do
+ let( :first_duplicate ){ route.duplicate }
+ let( :second_duplicate ){ first_duplicate.reload.duplicate }
+
+ it 'the required attributes' do
+ expect( values_for_create(first_duplicate, except: %w{objectid}) ).to eq( values_for_create( second_duplicate, except: %w{objectid} ) )
+ end
+
+ it 'the stop areas' do
+ expect( first_duplicate.stop_areas.pluck(:id) ).to eq( route.stop_areas.pluck(:id) )
+ expect( second_duplicate.stop_areas.pluck(:id) ).to eq( first_duplicate.stop_areas.pluck(:id) )
+ end
+
+ end
+ end
+
+end
diff --git a/spec/models/chouette/stop_point_spec.rb b/spec/models/chouette/stop_point_spec.rb
index 5eae8caf0..329e76a75 100644
--- a/spec/models/chouette/stop_point_spec.rb
+++ b/spec/models/chouette/stop_point_spec.rb
@@ -1,6 +1,7 @@
-require 'spec_helper'
+# From Chouette import what we need ™
+StopPoint = Chouette::StopPoint
-describe Chouette::StopPoint, :type => :model do
+describe StopPoint, :type => :model do
let!(:vehicle_journey) { create(:vehicle_journey)}
subject { Chouette::Route.find( vehicle_journey.route_id).stop_points.first }
@@ -38,4 +39,18 @@ describe Chouette::StopPoint, :type => :model do
expect(jpsp_stop_point_ids(@vehicle.journey_pattern_id)).not_to include(@stop_point.id)
end
end
+
+ describe '#duplicate' 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)
+ end
+ it 'new instance has a new route' do
+ expect(subject.duplicate(for_route: new_route).route).to eq(new_route)
+ end
+ it 'and old stop_area' do
+ expect(subject.duplicate(for_route: new_route).stop_area).to eq(subject.stop_area)
+ end
+ end
end
diff --git a/spec/models/compliance_check_block_spec.rb b/spec/models/compliance_check_block_spec.rb
new file mode 100644
index 000000000..f581d5085
--- /dev/null
+++ b/spec/models/compliance_check_block_spec.rb
@@ -0,0 +1,9 @@
+require 'rails_helper'
+
+RSpec.describe ComplianceCheckBlock, type: :model do
+ it 'should have a valid factory' do
+ expect(FactoryGirl.build(:compliance_check_block)).to be_valid
+ end
+
+ it { should belong_to :compliance_check_set }
+end
diff --git a/spec/models/compliance_check_resource_spec.rb b/spec/models/compliance_check_resource_spec.rb
new file mode 100644
index 000000000..a9366bea2
--- /dev/null
+++ b/spec/models/compliance_check_resource_spec.rb
@@ -0,0 +1,7 @@
+require 'rails_helper'
+
+RSpec.describe ComplianceCheckResource, type: :model do
+ it 'should have a valid factory' do
+ expect(FactoryGirl.build(:compliance_check_resource)).to be_valid
+ end
+end
diff --git a/spec/models/compliance_check_result_spec.rb b/spec/models/compliance_check_result_spec.rb
new file mode 100644
index 000000000..95586862f
--- /dev/null
+++ b/spec/models/compliance_check_result_spec.rb
@@ -0,0 +1,10 @@
+require 'rails_helper'
+
+RSpec.describe ComplianceCheckResult, type: :model do
+ it 'should have a valid factory' do
+ expect(FactoryGirl.build(:compliance_check_result)).to be_valid
+ end
+
+ it { should belong_to :compliance_check }
+ it { should belong_to :compliance_check_resource }
+end
diff --git a/spec/models/compliance_check_set_spec.rb b/spec/models/compliance_check_set_spec.rb
new file mode 100644
index 000000000..6e53c9def
--- /dev/null
+++ b/spec/models/compliance_check_set_spec.rb
@@ -0,0 +1,12 @@
+require 'rails_helper'
+
+RSpec.describe ComplianceCheckSet, type: :model do
+ it 'should have a valid factory' do
+ expect(FactoryGirl.build(:compliance_check_set)).to be_valid
+ end
+
+ it { should belong_to :referential }
+ it { should belong_to :workbench }
+ it { should belong_to :compliance_control_set }
+ it { should belong_to :parent }
+end
diff --git a/spec/models/compliance_check_spec.rb b/spec/models/compliance_check_spec.rb
new file mode 100644
index 000000000..4fbc23d42
--- /dev/null
+++ b/spec/models/compliance_check_spec.rb
@@ -0,0 +1,14 @@
+require 'rails_helper'
+
+RSpec.describe ComplianceCheck, type: :model do
+ it 'should have a valid factory' do
+ expect(FactoryGirl.build(:compliance_check)).to be_valid
+ end
+
+ it { should belong_to :compliance_check_set }
+ it { should belong_to :compliance_check_block }
+
+ it { should validate_presence_of :criticity }
+ it { should validate_presence_of :name }
+ it { should validate_presence_of :code }
+end
diff --git a/spec/models/compliance_control_block_spec.rb b/spec/models/compliance_control_block_spec.rb
new file mode 100644
index 000000000..248049b0c
--- /dev/null
+++ b/spec/models/compliance_control_block_spec.rb
@@ -0,0 +1,9 @@
+require 'rails_helper'
+
+RSpec.describe ComplianceControlBlock, type: :model do
+ it 'should have a valid factory' do
+ expect(FactoryGirl.build(:compliance_control_block)).to be_valid
+ end
+
+ it { should belong_to :compliance_control_set }
+end
diff --git a/spec/models/compliance_control_set_spec.rb b/spec/models/compliance_control_set_spec.rb
new file mode 100644
index 000000000..fb46bc65a
--- /dev/null
+++ b/spec/models/compliance_control_set_spec.rb
@@ -0,0 +1,9 @@
+require 'rails_helper'
+
+RSpec.describe ComplianceControlSet, type: :model do
+ it 'should have a valid factory' do
+ expect(FactoryGirl.build(:compliance_control_set)).to be_valid
+ end
+
+ it { should belong_to :organisation }
+end
diff --git a/spec/models/compliance_control_spec.rb b/spec/models/compliance_control_spec.rb
new file mode 100644
index 000000000..b00ff4c5a
--- /dev/null
+++ b/spec/models/compliance_control_spec.rb
@@ -0,0 +1,14 @@
+require 'rails_helper'
+
+RSpec.describe ComplianceControl, type: :model do
+ it 'should have a valid factory' do
+ expect(FactoryGirl.build(:compliance_control)).to be_valid
+ end
+
+ it { should belong_to :compliance_control_set }
+ it { should belong_to :compliance_control_block }
+
+ it { should validate_presence_of :criticity }
+ it { should validate_presence_of :name }
+ it { should validate_presence_of :code }
+end
diff --git a/spec/models/import_spec.rb b/spec/models/import_spec.rb
index 477d269e0..cd5a30982 100644
--- a/spec/models/import_spec.rb
+++ b/spec/models/import_spec.rb
@@ -26,12 +26,35 @@ RSpec.describe Import, type: :model do
)
end
- # describe "#destroy" do
- # it "must call #destroy on imports children and then import_messages, import_resources linked" do
- # TODO
- #
- # end
- # end
+ describe "#destroy" do
+ it "must destroy all child imports" do
+ workbench_import = create(:workbench_import)
+ create(:netex_import, parent: workbench_import)
+
+ workbench_import.destroy
+
+ expect(workbench_import).to be_destroyed
+ expect(NetexImport.count).to eq(0)
+ end
+
+ it "must destroy all associated ImportMessages" do
+ import = create(:import)
+ create(:import_resource, import: import)
+
+ import.destroy
+
+ expect(ImportResource.count).to eq(0)
+ end
+
+ it "must destroy all associated ImportResources" do
+ import = create(:import)
+ create(:import_message, import: import)
+
+ import.destroy
+
+ expect(ImportMessage.count).to eq(0)
+ end
+ end
describe "#notify_parent" do
it "must call #child_change on its parent" do
diff --git a/spec/models/referential_metadata_spec.rb b/spec/models/referential_metadata_spec.rb
index 775e6f228..291ed974a 100644
--- a/spec/models/referential_metadata_spec.rb
+++ b/spec/models/referential_metadata_spec.rb
@@ -30,8 +30,8 @@ RSpec.describe ReferentialMetadata, :type => :model do
expect(new_referential_metadata.referential).to be(nil)
end
- it "should have the same referential_source" do
- expect(new_referential_metadata.referential_source).to eq(referential_metadata.referential_source)
+ it "should have the right referential_source" do
+ expect(new_referential_metadata.referential_source).to eq(referential_metadata.referential)
end
end
diff --git a/spec/policies/route_policy_spec.rb b/spec/policies/route_policy_spec.rb
index 243d85acb..d7edceaef 100644
--- a/spec/policies/route_policy_spec.rb
+++ b/spec/policies/route_policy_spec.rb
@@ -6,6 +6,10 @@ RSpec.describe RoutePolicy, type: :policy do
it_behaves_like 'permitted policy and same organisation', 'routes.create', archived: true
end
+ permissions :duplicate? do
+ it_behaves_like 'permitted policy and same organisation', 'routes.create', archived: true
+ end
+
permissions :destroy? do
it_behaves_like 'permitted policy and same organisation', 'routes.destroy', archived: true
end
diff --git a/spec/routing/routes_routing_spec.rb b/spec/routing/routes_routing_spec.rb
new file mode 100644
index 000000000..311de9f39
--- /dev/null
+++ b/spec/routing/routes_routing_spec.rb
@@ -0,0 +1,12 @@
+RSpec.describe "routes for Routes", type: :routing do
+ context "routes /referentials/:id/lines/:id/routes/:id/duplicate" do
+
+ let( :controller ){ {controller: 'routes', referential_id: ':referential_id', line_id: ':line_id', id: ':id'} }
+
+ it 'with method post to #post_duplicate' do
+ expect(
+ post: '/referentials/:referential_id/lines/:line_id/routes/:id/duplicate'
+ ).to route_to controller.merge(action: 'duplicate')
+ end
+ end
+end
diff --git a/spec/support/helpers/model_compare_helpers.rb b/spec/support/helpers/model_compare_helpers.rb
new file mode 100644
index 000000000..a10892af0
--- /dev/null
+++ b/spec/support/helpers/model_compare_helpers.rb
@@ -0,0 +1,15 @@
+module Support::ModelCompareHelpers
+
+ def values_for_create obj, **overrides
+ except = overrides.delete(:except) || []
+ keys = obj.attributes.keys - except - %w{id created_at updated_at}
+ overrides.inject(obj.attributes.slice(*keys)){ |atts, (k,v)|
+ atts.merge k.to_s => v
+ }
+ end
+
+end
+
+RSpec.configure do | rspec |
+ rspec.include Support::ModelCompareHelpers, type: :model
+end
diff --git a/spec/support/referential.rb b/spec/support/referential.rb
index c431856b8..3b74cb639 100644
--- a/spec/support/referential.rb
+++ b/spec/support/referential.rb
@@ -52,7 +52,7 @@ RSpec.configure do |config|
referential.add_member organisation, owner: true
end
- workbench = Workbench.create!(:name => "first", organisation: organisation, line_referential: line_referential, stop_area_referential: stop_area_referential)
+ workbench = Workbench.create!(:name => "Gestion de l'offre", organisation: organisation, line_referential: line_referential, stop_area_referential: stop_area_referential)
referential = Referential.create! prefix: "first", name: "first", slug: "first", organisation: organisation, workbench: workbench
end