diff options
Diffstat (limited to 'spec')
| -rw-r--r-- | spec/controllers/api/v1/internals/netex_imports_controller_spec.rb | 7 | ||||
| -rw-r--r-- | spec/controllers/exports_controller_spec.rb | 16 | ||||
| -rw-r--r-- | spec/controllers/routes_controller_spec.rb | 6 | ||||
| -rw-r--r-- | spec/factories/calendars.rb | 2 | ||||
| -rw-r--r-- | spec/features/connection_links_spec.rb | 9 | ||||
| -rw-r--r-- | spec/features/group_of_lines_spec.rb | 6 | ||||
| -rw-r--r-- | spec/models/calendar_observer_spec.rb | 28 | ||||
| -rw-r--r-- | spec/models/calendar_spec.rb | 2 | ||||
| -rw-r--r-- | spec/models/chouette/route/route_stop_points_spec.rb | 3 | ||||
| -rw-r--r-- | spec/models/export/base_spec.rb | 47 | ||||
| -rw-r--r-- | spec/models/import/import_spec.rb | 46 | ||||
| -rw-r--r-- | spec/support/shared_examples/compliance_control_validation.rb | 18 |
12 files changed, 124 insertions, 66 deletions
diff --git a/spec/controllers/api/v1/internals/netex_imports_controller_spec.rb b/spec/controllers/api/v1/internals/netex_imports_controller_spec.rb index ccdc258f4..b53ee3f05 100644 --- a/spec/controllers/api/v1/internals/netex_imports_controller_spec.rb +++ b/spec/controllers/api/v1/internals/netex_imports_controller_spec.rb @@ -1,6 +1,6 @@ RSpec.describe Api::V1::Internals::NetexImportsController, type: :controller do let(:import_1) { create :netex_import } - let(:import_2) { create :netex_import } + let(:import_2) { create :netex_import, status: "successful" } describe "GET #notify_parent" do context 'unauthenticated' do @@ -17,14 +17,14 @@ RSpec.describe Api::V1::Internals::NetexImportsController, type: :controller do describe "with existing record" do - before(:each) do + before(:each) do get :notify_parent, id: import_2.id, format: :json end it 'should be successful' do expect(response).to have_http_status 200 end - + it "calls #notify_parent on the import" do expect(import_2.reload.notified_parent_at).not_to be_nil end @@ -39,4 +39,3 @@ RSpec.describe Api::V1::Internals::NetexImportsController, type: :controller do end end end - diff --git a/spec/controllers/exports_controller_spec.rb b/spec/controllers/exports_controller_spec.rb index 3a67497ec..9d8dde4ff 100644 --- a/spec/controllers/exports_controller_spec.rb +++ b/spec/controllers/exports_controller_spec.rb @@ -2,7 +2,7 @@ RSpec.describe ExportsController, :type => :controller do login_user let(:workbench) { create :workbench } - let(:export) { create(:netex_export, workbench: workbench) } + let(:export) { create(:netex_export, workbench: workbench, referential: first_referential) } describe 'GET #new' do it 'should be successful if authorized' do @@ -21,7 +21,7 @@ RSpec.describe ExportsController, :type => :controller do let(:params){ {name: "foo"} } let(:request){ post :create, workbench_id: workbench.id, export: params } it 'should create no objects' do - expect{request}.to_not change{Export::Base.count} + expect{request}.to_not change{Export::Netex.count} end context "with full params" do @@ -29,11 +29,12 @@ RSpec.describe ExportsController, :type => :controller do name: "foo", type: "Export::Netex", duration: 12, - export_type: :line + export_type: :line, + referential_id: first_referential.id }} it 'should be successful' do - expect{request}.to change{Export::Base.count}.by(1) + expect{request}.to change{Export::Netex.count}.by(1) end it "displays a flash message" do @@ -51,7 +52,7 @@ RSpec.describe ExportsController, :type => :controller do }} it 'should be unsuccessful' do - expect{request}.to change{Export::Base.count}.by(0) + expect{request}.to change{Export::Netex.count}.by(0) end end @@ -59,11 +60,12 @@ RSpec.describe ExportsController, :type => :controller do let(:params){{ name: "foo", type: "Export::Workgroup", - duration: 90 + duration: 90, + referential_id: first_referential.id }} it 'should be successful' do - expect{request}.to change{Export::Base.count}.by(1) + expect{request}.to change{Export::Workgroup.count}.by(1) end end diff --git a/spec/controllers/routes_controller_spec.rb b/spec/controllers/routes_controller_spec.rb index f8e8697ec..e4dc6bc23 100644 --- a/spec/controllers/routes_controller_spec.rb +++ b/spec/controllers/routes_controller_spec.rb @@ -68,14 +68,8 @@ RSpec.describe RoutesController, type: :controller do end it_behaves_like "route, line and referential linked" - - it "assigns RouteMap.new(route) as @map" do - expect(assigns[:map]).to be_an_instance_of(RouteMap) - expect(assigns[:map].route).to eq(route) - end end - describe "POST /duplicate" do let!( :route_prime ){ route } diff --git a/spec/factories/calendars.rb b/spec/factories/calendars.rb index d9fd242d1..d78f230c6 100644 --- a/spec/factories/calendars.rb +++ b/spec/factories/calendars.rb @@ -1,7 +1,6 @@ FactoryGirl.define do factory :calendar do sequence(:name) { |n| "Calendar #{n}" } - sequence(:short_name) { |n| "Cal #{n}" } date_ranges { [generate(:date_range)] } sequence(:dates) { |n| [ Date.yesterday - n, Date.yesterday - 2*n ] } shared false @@ -14,4 +13,3 @@ FactoryGirl.define do date..(date+1) end end - diff --git a/spec/features/connection_links_spec.rb b/spec/features/connection_links_spec.rb index 2f6283dcd..7e95aeb13 100644 --- a/spec/features/connection_links_spec.rb +++ b/spec/features/connection_links_spec.rb @@ -1,3 +1,4 @@ +# coding: utf-8 RSpec.describe "ConnectionLinks", type: :feature do login_user @@ -19,14 +20,6 @@ RSpec.describe "ConnectionLinks", type: :feature do click_link "#{connection_links.first.name}" expect(page).to have_content(connection_links.first.name) end - - it "display map" do - allow(subject).to receive(:stop_areas).and_return(Array.new(2) { create(:stop_area) }) - visit referential_connection_links_path(referential) - click_link "#{connection_links.first.name}" - expect(page).to have_selector("#map.connection_link") - end - end describe "new" do diff --git a/spec/features/group_of_lines_spec.rb b/spec/features/group_of_lines_spec.rb index 8b88e6e9e..6b2f1968a 100644 --- a/spec/features/group_of_lines_spec.rb +++ b/spec/features/group_of_lines_spec.rb @@ -40,12 +40,6 @@ describe "Group of lines", :type => :feature do click_link subject.name expect(page).to have_content(subject.name) end - - it "display map" do - visit line_referential_group_of_lines_path(line_referential) - click_link "#{subject.name}" - expect(page).to have_selector("#map.group_of_line") - end end # Fixme #1780 diff --git a/spec/models/calendar_observer_spec.rb b/spec/models/calendar_observer_spec.rb index 4fba02bef..dd7034af4 100644 --- a/spec/models/calendar_observer_spec.rb +++ b/spec/models/calendar_observer_spec.rb @@ -1,8 +1,13 @@ require 'rails_helper' RSpec.describe CalendarObserver, type: :observer do - let(:calendar) { create(:calendar, shared: true) } - let(:user) { create(:user, organisation: create(:organisation)) } + let(:workgroup_1) { create :workgroup } + let(:workgroup_2) { create :workgroup } + + let(:calendar) { create(:calendar, shared: true, workgroup_id: workgroup_1.id) } + + let(:user_1) { create(:user, organisation: create(:organisation, workbenches: [create(:workbench, workgroup_id: workgroup_1.id)] )) } + let(:user_2) { create(:user, organisation: create(:organisation, workbenches: [create(:workbench, workgroup_id: workgroup_2.id)] )) } context 'after_update' do it 'should observe calendar updates' do @@ -12,14 +17,21 @@ RSpec.describe CalendarObserver, type: :observer do it 'should schedule mailer on calendar update' do calendar.name = 'edited_name' - expect(MailerJob).to receive(:perform_later).with 'CalendarMailer', 'updated', [calendar.id, user.id] + expect(MailerJob).to receive(:perform_later).with 'CalendarMailer', 'updated', [calendar.id, user_1.id] calendar.save end it 'should not schedule mailer for none shared calendar on update' do calendar = create(:calendar, shared: false) calendar.name = 'edited_name' - expect(MailerJob).to_not receive(:perform_later).with 'CalendarMailer', 'updated', [calendar.id, user.id] + expect(MailerJob).to_not receive(:perform_later).with 'CalendarMailer', 'updated', [calendar.id, user_1.id] + calendar.save + end + + it "should only send mail to user from the same workgroup" do + calendar.name = 'edited_name' + expect(MailerJob).to receive(:perform_later).with 'CalendarMailer', 'updated', [calendar.id, user_1.id] + expect(MailerJob).to_not receive(:perform_later).with 'CalendarMailer', 'updated', [calendar.id, user_2.id] calendar.save end end @@ -31,13 +43,13 @@ RSpec.describe CalendarObserver, type: :observer do end it 'should schedule mailer on calendar create' do - expect(MailerJob).to receive(:perform_later).with 'CalendarMailer', 'created', [anything, user.id] - build(:calendar, shared: true).save + expect(MailerJob).to receive(:perform_later).with 'CalendarMailer', 'created', [anything, user_1.id] + build(:calendar, shared: true, workgroup_id: workgroup_1.id).save end it 'should not schedule mailer for none shared calendar on create' do - expect(MailerJob).to_not receive(:perform_later).with 'CalendarMailer', 'created', [anything, user.id] - build(:calendar, shared: false).save + expect(MailerJob).to_not receive(:perform_later).with 'CalendarMailer', 'created', [anything, user_1.id] + build(:calendar, shared: false, workgroup_id: workgroup_1.id).save end end end diff --git a/spec/models/calendar_spec.rb b/spec/models/calendar_spec.rb index a5c0a7471..09ac0e416 100644 --- a/spec/models/calendar_spec.rb +++ b/spec/models/calendar_spec.rb @@ -4,8 +4,6 @@ RSpec.describe Calendar, :type => :model do it { is_expected.to validate_presence_of(:organisation) } 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 diff --git a/spec/models/chouette/route/route_stop_points_spec.rb b/spec/models/chouette/route/route_stop_points_spec.rb index 03c53b4cf..af26f017a 100644 --- a/spec/models/chouette/route/route_stop_points_spec.rb +++ b/spec/models/chouette/route/route_stop_points_spec.rb @@ -78,15 +78,16 @@ RSpec.describe Chouette::Route, :type => :model do end describe "#stop_points" do + let(:first_stop_point) { subject.stop_points.first} context "#find_by_stop_area" do context "when arg is first quay id" do - let(:first_stop_point) { subject.stop_points.first} it "should return first quay" do expect(subject.stop_points.find_by_stop_area( first_stop_point.stop_area_id)).to eq( first_stop_point) end end end end + describe "#stop_areas" do let(:line){ create(:line)} let(:route_1){ create(:route, :line => line)} diff --git a/spec/models/export/base_spec.rb b/spec/models/export/base_spec.rb index edc0788f2..3d10ecead 100644 --- a/spec/models/export/base_spec.rb +++ b/spec/models/export/base_spec.rb @@ -110,24 +110,49 @@ RSpec.describe Export::Base, type: :model do end describe "#notify_parent" do - it "must call #child_change on its parent" do - allow(netex_export).to receive(:update) + context "when export is finished" do + before do + netex_export.status = "successful" + netex_export.notified_parent_at = nil + end + + it "must call #child_change on its parent" do + allow(netex_export).to receive(:update) - expect(workgroup_export).to receive(:child_change) - netex_export.status = :foo - netex_export.notify_parent + expect(workgroup_export).to receive(:child_change) + netex_export.notified_parent_at = nil + netex_export.notify_parent + end + + it "must update the :notified_parent_at field of the child export" do + allow(workgroup_export).to receive(:child_change) + + Timecop.freeze(Time.now) do + netex_export.notify_parent + expect(netex_export.notified_parent_at.utc.strftime('%Y-%m-%d %H:%M:%S.%3N')).to eq Time.now.utc.strftime('%Y-%m-%d %H:%M:%S.%3N') + expect(netex_export.reload.notified_parent_at.utc.strftime('%Y-%m-%d %H:%M:%S.%3N')).to eq Time.now.utc.strftime('%Y-%m-%d %H:%M:%S.%3N') + end + end end - it "must update the :notified_parent_at field of the child export" do - allow(workgroup_export).to receive(:child_change) + context "when export is not finished" do + before do + netex_export.status = "running" + netex_export.notified_parent_at = nil + end - Timecop.freeze(Time.now) do - netex_export.status = :bar + it "must not call #child_change on its parent" do + allow(netex_export).to receive(:update) + + expect(workgroup_export).to_not receive(:child_change) + netex_export.notify_parent + end + it "must keep nil the :notified_parent_at field of the child export" do netex_export.notify_parent - expect(netex_export.notified_parent_at.strftime('%Y-%m-%d %H:%M:%S.%3N')).to eq Time.now.strftime('%Y-%m-%d %H:%M:%S.%3N') - expect(netex_export.reload.notified_parent_at.strftime('%Y-%m-%d %H:%M:%S.%3N')).to eq Time.now.strftime('%Y-%m-%d %H:%M:%S.%3N') + expect(netex_export.notified_parent_at).to be_nil end + end end diff --git a/spec/models/import/import_spec.rb b/spec/models/import/import_spec.rb index 102c0e1d6..b11c4922c 100644 --- a/spec/models/import/import_spec.rb +++ b/spec/models/import/import_spec.rb @@ -111,23 +111,47 @@ RSpec.describe Import::Base, type: :model do end describe "#notify_parent" do - it "must call #child_change on its parent" do - allow(netex_import).to receive(:update) + context "when import is finished" do + before do + netex_import.status = "successful" + netex_import.notified_parent_at = nil + end + + it "must call #child_change on its parent" do + allow(netex_import).to receive(:update) - expect(workbench_import).to receive(:child_change) - netex_import.status = :foo - netex_import.notify_parent + expect(workbench_import).to receive(:child_change) + netex_import.notify_parent + end + + it "must update the :notified_parent_at field of the child import" do + allow(workbench_import).to receive(:child_change) + Timecop.freeze(Time.now) do + netex_import.notify_parent + expect(netex_import.notified_parent_at.utc.strftime('%Y-%m-%d %H:%M:%S.%3N')).to eq Time.now.utc.strftime('%Y-%m-%d %H:%M:%S.%3N') + expect(netex_import.reload.notified_parent_at.utc.strftime('%Y-%m-%d %H:%M:%S.%3N')).to eq Time.now.utc.strftime('%Y-%m-%d %H:%M:%S.%3N') + end + end end - it "must update the :notified_parent_at field of the child import" do - allow(workbench_import).to receive(:child_change) - Timecop.freeze(Time.now) do - netex_import.status = :bar + context "when import is not finished" do + before do + netex_import.status = "running" + netex_import.notified_parent_at = nil + end + + it "must not call #child_change on its parent" do + allow(netex_import).to receive(:update) + + expect(workbench_import).to_not receive(:child_change) + netex_import.notify_parent + end + it "must keep nil the :notified_parent_at field of the child import" do netex_import.notify_parent - expect(netex_import.notified_parent_at.strftime('%Y-%m-%d %H:%M:%S.%3N')).to eq Time.now.strftime('%Y-%m-%d %H:%M:%S.%3N') - expect(netex_import.reload.notified_parent_at.strftime('%Y-%m-%d %H:%M:%S.%3N')).to eq Time.now.strftime('%Y-%m-%d %H:%M:%S.%3N') + expect(netex_import.notified_parent_at).to be_nil end + end end diff --git a/spec/support/shared_examples/compliance_control_validation.rb b/spec/support/shared_examples/compliance_control_validation.rb index b23c2984f..3a8232193 100644 --- a/spec/support/shared_examples/compliance_control_validation.rb +++ b/spec/support/shared_examples/compliance_control_validation.rb @@ -12,7 +12,25 @@ RSpec.shared_examples_for 'has min_max_values' do end end + context "is valid" do + it 'if minimum is well formatted' do + subject.minimum = "12" + expect_it.to be_valid + subject.minimum = "12.0" + expect_it.to be_valid + subject.minimum = "12.01" + expect_it.to be_valid + end + end + context "is invalid" do + it 'if minimum is not well formatted' do + subject.minimum = "AA" + expect_it.not_to be_valid + subject.minimum = "12." + expect_it.not_to be_valid + end + it 'if no value is provided' do subject.minimum = nil subject.maximum = nil |
