aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/features/calendars_permissions_spec.rb4
-rw-r--r--spec/features/routing_constraint_zones_spec.rb4
-rw-r--r--spec/features/workbenches/workbenches_permissions_spec.rb4
-rw-r--r--spec/models/custom_field_spec.rb43
-rw-r--r--spec/models/merge_spec.rb35
-rw-r--r--spec/models/referential_metadata_spec.rb2
6 files changed, 77 insertions, 15 deletions
diff --git a/spec/features/calendars_permissions_spec.rb b/spec/features/calendars_permissions_spec.rb
index 656c0dd78..6b0b782db 100644
--- a/spec/features/calendars_permissions_spec.rb
+++ b/spec/features/calendars_permissions_spec.rb
@@ -57,14 +57,14 @@ RSpec.describe 'Calendars', type: :feature do
context 'if present → ' do
let( :permission ){ true }
it 'index shows an edit button' do
- expect(page).to have_css('a.btn.btn-default', text: 'Créer')
+ expect(page).to have_css('a.btn.btn-default', text: I18n.t('actions.add'))
end
end
context 'if absent → ' do
let( :permission ){ false }
it 'index does not show any edit button' do
- expect(page).not_to have_css('a.btn.btn-default', text: 'Créer')
+ expect(page).not_to have_css('a.btn.btn-default', text: I18n.t('actions.add'))
end
end
end
diff --git a/spec/features/routing_constraint_zones_spec.rb b/spec/features/routing_constraint_zones_spec.rb
index b116b38bd..b3286af82 100644
--- a/spec/features/routing_constraint_zones_spec.rb
+++ b/spec/features/routing_constraint_zones_spec.rb
@@ -20,7 +20,7 @@ describe 'RoutingConstraintZones', type: :feature do
context 'user has permission to create routing_constraint_zones' do
it 'shows a create link for routing_constraint_zones' do
- expect(page).to have_content(I18n.t('actions.new'))
+ expect(page).to have_content(I18n.t('actions.add'))
end
end
@@ -28,7 +28,7 @@ describe 'RoutingConstraintZones', type: :feature do
it 'does not show a create link for routing_constraint_zones' do
@user.update_attribute(:permissions, [])
visit referential_line_routing_constraint_zones_path(referential, line)
- expect(page).not_to have_content(I18n.t('actions.new'))
+ expect(page).not_to have_content(I18n.t('actions.add'))
end
end
diff --git a/spec/features/workbenches/workbenches_permissions_spec.rb b/spec/features/workbenches/workbenches_permissions_spec.rb
index 1c073a4c5..a48a6dc64 100644
--- a/spec/features/workbenches/workbenches_permissions_spec.rb
+++ b/spec/features/workbenches/workbenches_permissions_spec.rb
@@ -23,7 +23,7 @@ describe 'Workbenches', type: :feature do
it 'shows the corresponding button' do
expected_href = new_workbench_referential_path(workbench)
- expect( page ).to have_link('Créer', href: expected_href)
+ expect( page ).to have_link(I18n.t('actions.add'), href: expected_href)
end
end
@@ -31,7 +31,7 @@ describe 'Workbenches', type: :feature do
let( :permission ){ false }
it 'does not show the corresponding button' do
- expect( page ).not_to have_link('Créer')
+ expect( page ).not_to have_link(I18n.t('actions.add'))
end
end
# let!(:ready_referential) { create :referential, workbench: workbench, metadatas: referential_metadatas, ready: true, organisation: @user.organisation }
diff --git a/spec/models/custom_field_spec.rb b/spec/models/custom_field_spec.rb
index ce6ce9fa5..54fd4f9d8 100644
--- a/spec/models/custom_field_spec.rb
+++ b/spec/models/custom_field_spec.rb
@@ -3,6 +3,11 @@ require 'rails_helper'
RSpec.describe CustomField, type: :model do
let( :vj ){ create :vehicle_journey, custom_field_values: {energy: 99} }
+ let(:referential){ create :workbench_referential }
+ let(:workgroup){ referential.workgroup }
+ before do
+ referential.switch
+ end
context "validates" do
it { should validate_uniqueness_of(:name).scoped_to(:resource_type, :workgroup_id) }
@@ -18,14 +23,14 @@ RSpec.describe CustomField, type: :model do
end
context "custom fields for a resource" do
- let!( :fields ){ [create(:custom_field), create(:custom_field, code: :energy)] }
+ let!( :fields ){ [create(:custom_field, workgroup: workgroup), create(:custom_field, code: :energy, workgroup: workgroup)] }
let!( :instance_fields ){
{
fields[0].code => fields[0].slice(:code, :name, :field_type, :options).update(value: nil),
"energy" => fields[1].slice(:code, :name, :field_type, :options).update(value: 99)
}
}
- it { expect(Chouette::VehicleJourney.custom_fields).to eq(fields) }
+ it { expect(Chouette::VehicleJourney.custom_fields(workgroup)).to eq(fields) }
it {
instance_fields.each do |code, cf|
cf.each do |k, v|
@@ -37,14 +42,36 @@ RSpec.describe CustomField, type: :model do
context "custom field_values for a resource" do
before do
- create :custom_field, field_type: :integer, code: :energy, name: :energy
+ create :custom_field, field_type: :integer, code: :energy, name: :energy, workgroup: workgroup
end
it { expect(vj.custom_field_value("energy")).to eq(99) }
+
+ context "given different workgroups" do
+ let(:ref1){ create :workbench_referential }
+ let(:ref2){ create :workbench_referential }
+ before do
+ create :custom_field, field_type: :integer, code: :ref1_energy, name: :energy, workgroup: ref1.workgroup, options: {default: 12}
+ create :custom_field, field_type: :integer, code: :ref1_energy, name: :energy, workgroup: ref1.workgroup, options: {default: 12}, resource_type: "Company"
+ create :custom_field, field_type: :integer, code: :ref2_energy, name: :energy, workgroup: ref2.workgroup
+ end
+ it "should only initialize fields from the right workgroup" do
+ ref1.switch
+ expect(Chouette::VehicleJourney.new.custom_fields.keys).to eq ["ref1_energy"]
+ expect(Chouette::VehicleJourney.new.custom_field_values["ref1_energy"]).to eq 12
+ expect(Chouette::VehicleJourney.new(custom_field_values: {ref1_energy: 13}).custom_field_values["ref1_energy"]).to eq 13
+ line_referential = create(:line_referential, workgroup: ref1.workgroup)
+ expect(line_referential.companies.build(custom_field_values: {ref1_energy: "13"}).custom_field_values["ref1_energy"]).to eq 13
+
+ ref2.switch
+ expect(Chouette::VehicleJourney.new.custom_fields.keys).to eq ["ref2_energy"]
+ expect(Chouette::VehicleJourney.new.custom_field_values).to_not have_key "ref1_energy"
+ end
+ end
end
context "with a 'list' field_type" do
- let!(:field){ [create(:custom_field, code: :energy, field_type: 'list', options: {list_values: %w(foo bar baz)})] }
+ let!(:field){ [create(:custom_field, code: :energy, field_type: 'list', options: {list_values: %w(foo bar baz)}, workgroup: workgroup)] }
let!( :vj ){ create :vehicle_journey, custom_field_values: {energy: "1"} }
it "should cast the value" do
expect(vj.custom_fields[:energy].value).to eq 1
@@ -75,7 +102,7 @@ RSpec.describe CustomField, type: :model do
end
context "with an 'integer' field_type" do
- let!(:field){ [create(:custom_field, code: :energy, field_type: 'integer')] }
+ let!(:field){ [create(:custom_field, code: :energy, field_type: 'integer', workgroup: workgroup)] }
let!( :vj ){ create :vehicle_journey, custom_field_values: {energy: "99"} }
it "should cast the value" do
expect(vj.custom_fields[:energy].value).to eq 99
@@ -101,7 +128,7 @@ RSpec.describe CustomField, type: :model do
end
context "with a 'string' field_type" do
- let!(:field){ [create(:custom_field, code: :energy, field_type: 'string')] }
+ let!(:field){ [create(:custom_field, code: :energy, field_type: 'string', workgroup: workgroup)] }
let!( :vj ){ create :vehicle_journey, custom_field_values: {energy: 99} }
it "should cast the value" do
expect(vj.custom_fields[:energy].value).to eq '99'
@@ -109,7 +136,7 @@ RSpec.describe CustomField, type: :model do
end
context "with a 'attachment' field_type" do
- let!(:field){ [create(:custom_field, code: :energy, field_type: 'attachment')] }
+ let!(:field){ [create(:custom_field, code: :energy, field_type: 'attachment', workgroup: workgroup)] }
let( :vj ){ create :vehicle_journey, custom_field_values: {energy: File.open(Rails.root.join('spec', 'fixtures', 'users.json'))} }
it "should cast the value" do
expect(vj.custom_fields[:energy].value.class).to be CustomFieldAttachmentUploader
@@ -129,7 +156,7 @@ RSpec.describe CustomField, type: :model do
end
context "with a whitelist" do
- let!(:field){ [create(:custom_field, code: :energy, field_type: 'attachment', options: {extension_whitelist: %w(zip)})] }
+ let!(:field){ [create(:custom_field, code: :energy, field_type: 'attachment', options: {extension_whitelist: %w(zip)}, workgroup: workgroup)] }
it "should validate extension" do
expect(build(:vehicle_journey, custom_field_values: {energy: File.open(Rails.root.join('spec', 'fixtures', 'users.json'))})).to_not be_valid
expect(build(:vehicle_journey, custom_field_values: {energy: File.open(Rails.root.join('spec', 'fixtures', 'nozip.zip'))})).to be_valid
diff --git a/spec/models/merge_spec.rb b/spec/models/merge_spec.rb
index 95181a80e..685e675cd 100644
--- a/spec/models/merge_spec.rb
+++ b/spec/models/merge_spec.rb
@@ -22,6 +22,8 @@ RSpec.describe Merge do
factor = 1
stop_points_positions = {}
+ routing_constraint_zones = {}
+
referential.switch do
line_referential.lines.each do |line|
factor.times do
@@ -35,6 +37,16 @@ RSpec.describe Merge do
sp.set_list_position 0
end
route.reload.update_checksum!
+ checksum = route.checksum
+ routing_constraint_zones[route.id] = {}
+ 2.times do |i|
+ constraint_zone = create(:routing_constraint_zone, route: route)
+ if i > 0
+ constraint_zone.update stop_points: constraint_zone.stop_points[0...-1]
+ end
+ routing_constraint_zones[route.id][constraint_zone.checksum] = constraint_zone
+ end
+ expect(route.reload.checksum).to_not eq checksum
factor.times do
FactoryGirl.create :journey_pattern, route: route, stop_points: route.stop_points.sample(3)
end
@@ -54,7 +66,9 @@ RSpec.describe Merge do
specific_time_table = FactoryGirl.create :time_table
vehicle_journey.time_tables << specific_time_table
+ vehicle_journey.update ignored_routing_contraint_zone_ids: routing_constraint_zones[vehicle_journey.route.id].values.map(&:id)
end
+
end
merge = Merge.create!(workbench: referential.workbench, referentials: [referential, referential])
@@ -63,6 +77,27 @@ RSpec.describe Merge do
output = merge.output.current
output.switch
+ output.routes.each do |route|
+ stop_points = nil
+ old_route = nil
+ referential.switch do
+ old_route = Chouette::Route.find_by(checksum: route.checksum)
+ stop_points = {}
+ old_route.routing_constraint_zones.each do |constraint_zone|
+ stop_points[constraint_zone.checksum] = constraint_zone.stop_points.map(&:registration_number)
+ end
+ end
+ routing_constraint_zones[old_route.id].each do |checksum, constraint_zone|
+ new_constraint_zone = route.routing_constraint_zones.where(checksum: checksum).last
+ expect(new_constraint_zone).to be_present
+ expect(new_constraint_zone.stop_points.map(&:registration_number)).to eq stop_points[checksum]
+ end
+
+ route.vehicle_journeys.each do |vehicle_journey|
+ expect(vehicle_journey.ignored_routing_contraint_zones.size).to eq vehicle_journey.ignored_routing_contraint_zone_ids.size
+ end
+ end
+
# Let's check stop_point positions are respected
# This should be enforced by the checksum preservation though
output.journey_patterns.each do |journey_pattern|
diff --git a/spec/models/referential_metadata_spec.rb b/spec/models/referential_metadata_spec.rb
index 88a12b2bb..210f95e14 100644
--- a/spec/models/referential_metadata_spec.rb
+++ b/spec/models/referential_metadata_spec.rb
@@ -100,7 +100,7 @@ RSpec.describe ReferentialMetadata, :type => :model do
it "should validate that end is greather than or equlals to begin" do
expect(period(begin: "2016-11-21", end: "2016-11-22")).to be_valid
- expect(period(begin: "2016-11-21", end: "2016-11-21")).to_not be_valid
+ expect(period(begin: "2016-11-21", end: "2016-11-21")).to be_valid
expect(period(begin: "2016-11-22", end: "2016-11-21")).to_not be_valid
end