aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorVlatka Pavisic2017-04-11 15:35:01 +0200
committerVlatka Pavisic2017-04-11 15:35:01 +0200
commitaa481c087b162bc775b4418e205f91c5b6bead19 (patch)
tree914ba9b39e0338317bcc2bfd839f745647beda1a /spec
parent8adf909694b52959483818bf839d6e180015eb99 (diff)
downloadchouette-core-aa481c087b162bc775b4418e205f91c5b6bead19.tar.bz2
Refs #3047: Associate RoutingConstraintZone with StopPoints
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/route_stop_points_controller_spec.rb23
-rw-r--r--spec/factories/chouette_routing_constraint_zones.rb5
-rw-r--r--spec/features/lines_spec.rb8
-rw-r--r--spec/features/routes_spec.rb4
-rw-r--r--spec/models/chouette/routing_constraint_zone_spec.rb39
5 files changed, 69 insertions, 10 deletions
diff --git a/spec/controllers/route_stop_points_controller_spec.rb b/spec/controllers/route_stop_points_controller_spec.rb
new file mode 100644
index 000000000..2f5fa41c7
--- /dev/null
+++ b/spec/controllers/route_stop_points_controller_spec.rb
@@ -0,0 +1,23 @@
+require 'spec_helper'
+
+RSpec.describe RouteStopPointsController, type: :controller do
+ login_user
+
+ let(:referential) { Referential.first }
+ let!(:line) { create :line }
+ let!(:route) { create :route, line: line }
+
+ describe 'GET index' do
+ before(:each) { get :index, referential_id: referential.id, line_id: line.id, route_id: route.id, format: :json }
+
+ it 'returns HTTP success' do
+ expect(response).to be_success
+ end
+
+ it 'returns a JSON of stop areas' do
+ expect(response.body).to eq(route.stop_points.map { |sp| { id: sp.id, name: sp.name } }.to_json)
+ end
+ end
+end
+
+
diff --git a/spec/factories/chouette_routing_constraint_zones.rb b/spec/factories/chouette_routing_constraint_zones.rb
index 2f707e6a6..8ef2ddb43 100644
--- a/spec/factories/chouette_routing_constraint_zones.rb
+++ b/spec/factories/chouette_routing_constraint_zones.rb
@@ -1,7 +1,10 @@
FactoryGirl.define do
factory :routing_constraint_zone, class: Chouette::RoutingConstraintZone do
sequence(:name) { |n| "Routing constraint zone #{n}" }
- stop_area_ids { [create(:stop_area).id, create(:stop_area).id] }
association :route, factory: :route
+ after(:build) do |zone|
+ route = Chouette::Route.find(zone.route_id)
+ zone.stop_point_ids = route.stop_points.pluck(:id).first(2)
+ end
end
end
diff --git a/spec/features/lines_spec.rb b/spec/features/lines_spec.rb
index bbe3c757b..e7e1e601c 100644
--- a/spec/features/lines_spec.rb
+++ b/spec/features/lines_spec.rb
@@ -20,10 +20,10 @@ describe "Lines", :type => :feature do
end
it 'allows only R in CRUD' do
- expect(page).to have_content(I18n.t('actions.show'))
- expect(page).not_to have_content(I18n.t('actions.edit'))
- expect(page).not_to have_content(I18n.t('actions.destroy'))
- expect(page).not_to have_content(I18n.t('actions.add'))
+ expect(page).to have_link(I18n.t('actions.show'))
+ expect(page).not_to have_link(I18n.t('actions.edit'), href: edit_referential_line_path(referential, lines.first))
+ expect(page).not_to have_link(I18n.t('actions.destroy'), href: referential_line_path(referential, lines.first))
+ expect(page).not_to have_link(I18n.t('actions.add'), href: new_referential_line_path(referential))
end
context 'filtering' do
diff --git a/spec/features/routes_spec.rb b/spec/features/routes_spec.rb
index 36d0e8f87..4b90a6ec6 100644
--- a/spec/features/routes_spec.rb
+++ b/spec/features/routes_spec.rb
@@ -102,7 +102,7 @@ describe "Routes", :type => :feature do
it 'does not show edit buttons for routes' do
@user.update_attribute(:permissions, [])
visit referential_line_path(referential, line)
- expect(page).not_to have_content(I18n.t('actions.edit'))
+ expect(page).not_to have_link(I18n.t('actions.edit'), href: edit_referential_line_route_path(referential, line, route))
end
end
@@ -136,7 +136,7 @@ describe "Routes", :type => :feature do
it 'does not show destroy buttons for routes' do
@user.update_attribute(:permissions, [])
visit referential_line_path(referential, line)
- expect(page).not_to have_content(I18n.t('actions.destroy'))
+ expect(page).not_to have_link(I18n.t('actions.destroy'), href: referential_line_route_path(referential, line, route))
end
end
end
diff --git a/spec/models/chouette/routing_constraint_zone_spec.rb b/spec/models/chouette/routing_constraint_zone_spec.rb
index f737872bf..c83942456 100644
--- a/spec/models/chouette/routing_constraint_zone_spec.rb
+++ b/spec/models/chouette/routing_constraint_zone_spec.rb
@@ -5,9 +5,42 @@ describe Chouette::RoutingConstraintZone, type: :model do
subject { create(:routing_constraint_zone) }
it { is_expected.to validate_presence_of :name }
- it { is_expected.to validate_presence_of :stop_area_ids }
- it { is_expected.to validate_presence_of :route_id }
# shoulda matcher to validate length of array ?
- xit { is_expected.to validate_length_of(:stop_area_ids).is_at_least(2) }
+ xit { is_expected.to validate_length_of(:stop_point_ids).is_at_least(2) }
+
+ describe 'validations' do
+ it 'validates the presence of route_id' do
+ routing_constraint_zone = create(:routing_constraint_zone)
+ expect {
+ routing_constraint_zone.update!(route_id: nil)
+ }.to raise_error
+ end
+
+ it 'validates the presence of stop_point_ids' do
+ routing_constraint_zone = create(:routing_constraint_zone)
+ expect {
+ routing_constraint_zone.update!(stop_point_ids: [])
+ }.to raise_error(ActiveRecord::RecordInvalid)
+ end
+
+ it 'validates that stop points belong to the route' do
+ routing_constraint_zone = create(:routing_constraint_zone)
+ route = create(:route)
+ expect {
+ routing_constraint_zone.update!(route_id: route.id)
+ }.to raise_error(ActiveRecord::RecordInvalid)
+ end
+ end
+
+ describe 'deleted stop areas' do
+ it 'does not have them in stop_area_ids' do
+ routing_constraint_zone = create(:routing_constraint_zone)
+ stop_point = routing_constraint_zone.route.stop_points.last
+ routing_constraint_zone.stop_points << stop_point
+ routing_constraint_zone.save!
+ routing_constraint_zone.route.stop_points.last.destroy!
+ expect(routing_constraint_zone.stop_points.map(&:id)).not_to include(stop_point.id)
+ end
+ end
end