diff options
Diffstat (limited to 'spec')
103 files changed, 1104 insertions, 295 deletions
diff --git a/spec/controllers/compliance_check_sets_controller_spec.rb b/spec/controllers/compliance_check_sets_controller_spec.rb new file mode 100644 index 000000000..804b0a658 --- /dev/null +++ b/spec/controllers/compliance_check_sets_controller_spec.rb @@ -0,0 +1,22 @@ +require 'rails_helper' + +RSpec.describe ComplianceCheckSetsController, type: :controller do + login_user + + let(:compliance_check_set) { create :compliance_check_set } + + describe "GET show" do + it 'should be successful' do + get :show, workbench_id: compliance_check_set.workbench.id, id: compliance_check_set.id + expect(response).to be_success + end + end + + describe "GET index" do + it 'should be successful' do + get :index, workbench_id: compliance_check_set.workbench.id, id: compliance_check_set.id + expect(response).to be_success + end + end + +end diff --git a/spec/controllers/compliance_control_blocks_controller_spec.rb b/spec/controllers/compliance_control_blocks_controller_spec.rb new file mode 100644 index 000000000..54617e768 --- /dev/null +++ b/spec/controllers/compliance_control_blocks_controller_spec.rb @@ -0,0 +1,47 @@ +require 'rails_helper' + +RSpec.describe ComplianceControlBlocksController, type: :controller do + login_user + + + let(:compliance_control_block) { create(:compliance_control_block) } + let!(:compliance_control_set) { compliance_control_block.compliance_control_set } + let(:compliance_control_block_params) { compliance_control_block.as_json.merge(transport_mode: "bus") } + + describe 'GET #new' do + it 'should be successful' do + get :new, compliance_control_set_id: compliance_control_set.id, id: compliance_control_block.id + expect(response).to be_success + end + end + + describe 'POST #create' do + it 'should be successful' do + post :create, compliance_control_set_id: compliance_control_set.id, compliance_control_block: compliance_control_block_params + expect(response).to redirect_to compliance_control_set_path(compliance_control_set) + end + end + + describe 'GET #edit' do + it 'should be successful' do + get :edit, compliance_control_set_id: compliance_control_set.id, id: compliance_control_block.id + expect(response).to be_success + end + end + + describe 'POST #update' do + it 'should be successful' do + post :update, compliance_control_set_id: compliance_control_set.id, id: compliance_control_block.id, compliance_control_block: compliance_control_block_params + expect(response).to redirect_to compliance_control_set_path(compliance_control_set) + end + end + + describe 'DELETE #destroy' do + it 'should be successful' do + expect { + delete :destroy, compliance_control_set_id: compliance_control_set.id, id: compliance_control_block.id + }.to change(ComplianceControlBlock, :count).by(-1) + expect(response).to redirect_to compliance_control_set_path(compliance_control_set) + end + end +end diff --git a/spec/controllers/compliance_control_sets_controller_spec.rb b/spec/controllers/compliance_control_sets_controller_spec.rb index 25d0becfe..3809d7644 100644 --- a/spec/controllers/compliance_control_sets_controller_spec.rb +++ b/spec/controllers/compliance_control_sets_controller_spec.rb @@ -1,60 +1,60 @@ -require 'rails_helper' - -RSpec.describe ComplianceControlSetsController, type: :controller do - login_user - - let(:compliance_control_set) { create :compliance_control_set } - - describe "GET show" do - it 'should be successful' do - get :show, id: compliance_control_set.id - expect(response).to be_success - end - end - - describe "GET index" do - it 'should be successful' do - get :index, id: compliance_control_set.id - expect(response).to be_success - end - end - - describe "GET #edit" do - it 'should be successful' do - get :edit, id: compliance_control_set.id - expect(response).to be_success - end - end - - describe 'GET #new' do - it 'should be successful' do - get :new, id: compliance_control_set.id - expect(response).to be_success - end - end - - describe 'POST #create' do - it 'should be successful' do - post :create, compliance_control_set: build(:compliance_control_set).as_json - expect(response).to have_http_status(302) - # expect(flash[:notice]).to eq(I18n.t('notice.compliance_control.created')) - end - end - - describe 'POST #update' do - it 'should be successful' do - post :update, id: compliance_control_set.id, compliance_control_set: compliance_control_set.as_json - expect(response).to redirect_to compliance_control_set_path(compliance_control_set) - # expect(flash[:notice]).to eq(I18n.t('notice.compliance_control.updated')) - end - end - - describe 'DELETE #destroy' do - it 'should be successful' do - delete :destroy, id: compliance_control_set.id - # expect(flash[:notice]).to eq I18n.t('notice.compliance_control.destroyed') - end - end - - -end +# require 'rails_helper' +# +# RSpec.describe ComplianceControlSetsController, type: :controller do +# login_user +# +# let(:compliance_control_set) { create :compliance_control_set } +# +# describe "GET show" do +# it 'should be successful' do +# get :show, id: compliance_control_set.id +# expect(response).to be_success +# end +# end +# +# describe "GET index" do +# it 'should be successful' do +# get :index, id: compliance_control_set.id +# expect(response).to be_success +# end +# end +# +# describe "GET #edit" do +# it 'should be successful' do +# get :edit, id: compliance_control_set.id +# expect(response).to be_success +# end +# end +# +# describe 'GET #new' do +# it 'should be successful' do +# get :new, id: compliance_control_set.id +# expect(response).to be_success +# end +# end +# +# describe 'POST #create' do +# it 'should be successful' do +# post :create, compliance_control_set: build(:compliance_control_set).as_json +# expect(response).to have_http_status(302) +# # expect(flash[:notice]).to eq(I18n.t('notice.compliance_control.created')) +# end +# end +# +# describe 'POST #update' do +# it 'should be successful' do +# post :update, id: compliance_control_set.id, compliance_control_set: compliance_control_set.as_json +# expect(response).to redirect_to compliance_control_set_path(compliance_control_set) +# # expect(flash[:notice]).to eq(I18n.t('notice.compliance_control.updated')) +# end +# end +# +# describe 'DELETE #destroy' do +# it 'should be successful' do +# delete :destroy, id: compliance_control_set.id +# # expect(flash[:notice]).to eq I18n.t('notice.compliance_control.destroyed') +# end +# end +# +# +# end diff --git a/spec/controllers/compliance_controls_controller_spec.rb b/spec/controllers/compliance_controls_controller_spec.rb index 165c00329..34b27530d 100644 --- a/spec/controllers/compliance_controls_controller_spec.rb +++ b/spec/controllers/compliance_controls_controller_spec.rb @@ -1,10 +1,9 @@ -require 'rails_helper' - RSpec.describe ComplianceControlsController, type: :controller do login_user - let(:compliance_control) { create :compliance_control } - let(:compliance_control_set) { compliance_control.compliance_control_set } + + let(:compliance_control) { create(:generic_attribute_control_min_max) } + let!(:compliance_control_set) { compliance_control.compliance_control_set } describe "GET show" do it 'should be successful' do @@ -13,47 +12,48 @@ RSpec.describe ComplianceControlsController, type: :controller do end end - describe "GET index" do + describe 'GET #edit' do it 'should be successful' do - get :index, compliance_control_set_id: compliance_control_set.id + get :edit, compliance_control_set_id: compliance_control_set.id, id: compliance_control.id expect(response).to be_success end end - describe 'GET #edit' do + describe 'GET #new' do it 'should be successful' do - get :edit, compliance_control_set_id: compliance_control_set.id, id: compliance_control.id + get :new, compliance_control_set_id: compliance_control_set.id, sti_class: 'GenericAttributeControl::MinMax' expect(response).to be_success end end - describe 'GET #new' do + describe 'GET #select_type' do it 'should be successful' do - get :new, compliance_control_set_id: compliance_control_set.id + get :select_type, compliance_control_set_id: compliance_control_set.id expect(response).to be_success end end describe 'POST #create' do it 'should be successful' do - post :create, compliance_control_set_id: compliance_control_set.id, compliance_control: build(:compliance_control).as_json - expect(response).to have_http_status(302) - expect(flash[:notice]).to eq(I18n.t('notice.compliance_control.created')) + post :create, compliance_control_set_id: compliance_control_set.id, compliance_control: compliance_control.as_json.merge(type: 'GenericAttributeControl::MinMax') + # expect(response).to have_http_status(302) + # expect(response).to redirect_to compliance_control_set_path(compliance_control_set) end end describe 'POST #update' do it 'should be successful' do - post :update, compliance_control_set_id: compliance_control_set.id, id: compliance_control.id, compliance_control: compliance_control.as_json + post :update, compliance_control_set_id: compliance_control_set.id, id: compliance_control.id, compliance_control: compliance_control.as_json.merge(type: 'GenericAttributeControl::MinMax') expect(response).to redirect_to compliance_control_set_compliance_control_path(compliance_control_set, compliance_control) - expect(flash[:notice]).to eq(I18n.t('notice.compliance_control.updated')) end end describe 'DELETE #destroy' do it 'should be successful' do - delete :destroy, compliance_control_set_id: compliance_control_set.id, id: compliance_control.id - expect(flash[:notice]).to eq I18n.t('notice.compliance_control.destroyed') + expect { + delete :destroy, compliance_control_set_id: compliance_control_set.id, id: compliance_control.id + }.to change(GenericAttributeControl::MinMax, :count).by(-1) + expect(response).to have_http_status(302) end end end diff --git a/spec/controllers/imports_controller_spec.rb b/spec/controllers/imports_controller_spec.rb index f07190496..22be9f6ed 100644 --- a/spec/controllers/imports_controller_spec.rb +++ b/spec/controllers/imports_controller_spec.rb @@ -5,10 +5,16 @@ RSpec.describe ImportsController, :type => :controller do let(:import) { create :import, workbench: workbench } describe 'GET #new' do - it 'should be successful' do + it 'should be successful if authorized' do get :new, workbench_id: workbench.id expect(response).to be_success end + + it 'should be unsuccessful unless authorized' do + remove_permissions('imports.create', from_user: @user, save: true) + get :new, workbench_id: workbench.id + expect(response).not_to be_success + end end describe 'GET #download' do @@ -18,4 +24,5 @@ RSpec.describe ImportsController, :type => :controller do expect( response.body ).to eq(import.file.read) end end + end diff --git a/spec/controllers/rule_parameter_sets_controller_spec.rb b/spec/controllers/rule_parameter_sets_controller_spec.rb index a1d65e92e..0f57855b7 100644 --- a/spec/controllers/rule_parameter_sets_controller_spec.rb +++ b/spec/controllers/rule_parameter_sets_controller_spec.rb @@ -1,8 +1,8 @@ -require 'spec_helper' +# require 'spec_helper' -describe RuleParameterSetsController, :type => :controller do - login_user - let(:mode){"air"} +# describe RuleParameterSetsController, :type => :controller do +# login_user +# let(:mode){"air"} # shared_examples_for "organisation dependant" do # it "assigns rule_parameter_set.organisation as current organisation" do @@ -10,17 +10,17 @@ describe RuleParameterSetsController, :type => :controller do # end # end - describe "GET /index" do - before(:each) do - get :index - end - it "should assign rule_parameter_sets to organisation rule_parameter_sets" do - expect(assigns[:rule_parameter_sets].size).to eq(assigns[:rule_parameter_sets][0].organisation.rule_parameter_sets.size) - assigns[:rule_parameter_sets].each do |rps| - expect(rps.organisation.id).to eq(assigns[:rule_parameter_sets][0].organisation.id) - end - end - end + # describe "GET /index" do + # before(:each) do + # get :index + # end + # it "should assign rule_parameter_sets to organisation rule_parameter_sets" do + # expect(assigns[:rule_parameter_sets].size).to eq(assigns[:rule_parameter_sets][0].organisation.rule_parameter_sets.size) + # assigns[:rule_parameter_sets].each do |rps| + # expect(rps.organisation.id).to eq(assigns[:rule_parameter_sets][0].organisation.id) + # end + # end + # end # describe "GET /new" do # before(:each) do @@ -33,4 +33,4 @@ describe RuleParameterSetsController, :type => :controller do # end # end # end -end +# end diff --git a/spec/factories/compliance_check_messages.rb b/spec/factories/compliance_check_messages.rb index 1a047a242..e015fb121 100644 --- a/spec/factories/compliance_check_messages.rb +++ b/spec/factories/compliance_check_messages.rb @@ -2,6 +2,8 @@ FactoryGirl.define do factory :compliance_check_message do association :compliance_check association :compliance_check_resource + association :compliance_check_set + status 'OK' message_key "message_key" end end diff --git a/spec/factories/compliance_check_resources.rb b/spec/factories/compliance_check_resources.rb index 813153be2..5438bd48e 100644 --- a/spec/factories/compliance_check_resources.rb +++ b/spec/factories/compliance_check_resources.rb @@ -1,6 +1,7 @@ FactoryGirl.define do factory :compliance_check_resource do - status :new + association :compliance_check_set sequence(:name) { |n| "Compliance check resource #{n}" } + status 'OK' end end diff --git a/spec/factories/compliance_checks.rb b/spec/factories/compliance_checks.rb index 4009653da..526052329 100644 --- a/spec/factories/compliance_checks.rb +++ b/spec/factories/compliance_checks.rb @@ -2,8 +2,9 @@ FactoryGirl.define do factory :compliance_check do sequence(:name) { |n| "Compliance check #{n}" } type "Type" - criticity :info + criticity "warning" code "code" + origin_code "code" comment "Text" association :compliance_check_set association :compliance_check_block diff --git a/spec/factories/compliance_control_blocks.rb b/spec/factories/compliance_control_blocks.rb index 5bc45cc75..4785d8419 100644 --- a/spec/factories/compliance_control_blocks.rb +++ b/spec/factories/compliance_control_blocks.rb @@ -1,6 +1,7 @@ FactoryGirl.define do factory :compliance_control_block do sequence(:name) { |n| "Compliance control block #{n}" } + transport_mode "air" association :compliance_control_set end end diff --git a/spec/factories/compliance_controls.rb b/spec/factories/compliance_controls.rb index 8aa16b674..ced505565 100644 --- a/spec/factories/compliance_controls.rb +++ b/spec/factories/compliance_controls.rb @@ -1,11 +1,11 @@ FactoryGirl.define do factory :compliance_control do sequence(:name) { |n| "Compliance control #{n}" } - type "ComplianceControl" + type "GenericAttributeControl::MinMax" criticity :warning code "code" + origin_code "code" comment "Text" association :compliance_control_set - association :compliance_control_block end end diff --git a/spec/factories/compliance_controls/generic_factories.rb b/spec/factories/compliance_controls/generic_factories.rb new file mode 100644 index 000000000..ddcf6c116 --- /dev/null +++ b/spec/factories/compliance_controls/generic_factories.rb @@ -0,0 +1,20 @@ +FactoryGirl.define do + factory :generic_attribute_control_min_max, class: 'GenericAttributeControl::MinMax' do + sequence(:name) { |n| "MinMax control #{n}" } + association :compliance_control_set + target "route#name" + end + + factory :generic_attribute_control_pattern, class: 'GenericAttributeControl::Pattern' do + sequence(:name) { |n| "Pattern control #{n}" } + association :compliance_control_set + pattern "^(.)*$" + target "route#name" + end + + factory :generic_attribute_control_uniqueness, class: 'GenericAttributeControl::Uniqueness' do + sequence(:name) { |n| "Uniqueness control #{n}" } + association :compliance_control_set + target "route#name" + end +end diff --git a/spec/factories/compliance_controls/journey_pattern_control_factories.rb b/spec/factories/compliance_controls/journey_pattern_control_factories.rb new file mode 100644 index 000000000..874348d3f --- /dev/null +++ b/spec/factories/compliance_controls/journey_pattern_control_factories.rb @@ -0,0 +1,11 @@ +FactoryGirl.define do + + factory :journey_pattern_control_duplicates, class: 'JourneyPatternControl::Duplicates' do + association :compliance_control_set + end + + factory :journey_pattern_control_vehicle_journey, class: 'JourneyPatternControl::VehicleJourney' do + association :compliance_control_set + end + +end diff --git a/spec/factories/compliance_controls/line_control_factories.rb b/spec/factories/compliance_controls/line_control_factories.rb new file mode 100644 index 000000000..e6aa1a1a2 --- /dev/null +++ b/spec/factories/compliance_controls/line_control_factories.rb @@ -0,0 +1,6 @@ +FactoryGirl.define do + factory :line_control_route, class: 'LineControl::Route' do + association :compliance_control_set + end + +end diff --git a/spec/factories/compliance_controls/route_control_factories.rb b/spec/factories/compliance_controls/route_control_factories.rb new file mode 100644 index 000000000..1462ca635 --- /dev/null +++ b/spec/factories/compliance_controls/route_control_factories.rb @@ -0,0 +1,38 @@ +FactoryGirl.define do + + factory :route_control_duplicates, class: 'RouteControl::Duplicates' do + association :compliance_control_set + end + + factory :route_control_journey_pattern, class: 'RouteControl::JourneyPattern' do + association :compliance_control_set + end + + factory :route_control_minimum_length, class: 'RouteControl::MinimumLength' do + association :compliance_control_set + end + + factory :route_control_omnibus_journey_pattern, class: 'RouteControl::OmnibusJourneyPattern' do + association :compliance_control_set + end + + factory :route_control_opposite_route, class: 'RouteControl::OppositeRoute' do + association :compliance_control_set + end + + factory :route_control_opposite_route_terminus, class: 'RouteControl::OppositeRouteTerminus' do + association :compliance_control_set + end + + factory :route_control_stop_points_in_journey_pattern, class: 'RouteControl::StopPointsInJourneyPattern' do + association :compliance_control_set + end + + factory :route_control_unactivated_stop_points, class: 'RouteControl::UnactivatedStopPoints' do + association :compliance_control_set + end + + factory :route_control_zdl_stop_area, class: 'RouteControl::ZDLStopArea' do + association :compliance_control_set + end +end diff --git a/spec/factories/compliance_controls/routing_constraint_zone_control_factories.rb b/spec/factories/compliance_controls/routing_constraint_zone_control_factories.rb new file mode 100644 index 000000000..7ca6e4ecd --- /dev/null +++ b/spec/factories/compliance_controls/routing_constraint_zone_control_factories.rb @@ -0,0 +1,14 @@ +FactoryGirl.define do + factory :routing_constraint_zone_control_unactivated_stop_point, + class: 'routingConstraintZoneControl::UnactivatedStopPoint' do + association :compliance_control_set + end + + factory :routing_constraint_zone_control_minimum_length, class: 'routingConstraintZoneControl::MinimumLength' do + association :compliance_control_set + end + + factory :routing_constraint_zone_control_maximum_length, class: 'routingConstraintZoneControl::MaximumLength' do + association :compliance_control_set + end +end diff --git a/spec/factories/compliance_controls/vehicle_journey_control_factories.rb b/spec/factories/compliance_controls/vehicle_journey_control_factories.rb new file mode 100644 index 000000000..b9da530fb --- /dev/null +++ b/spec/factories/compliance_controls/vehicle_journey_control_factories.rb @@ -0,0 +1,22 @@ +FactoryGirl.define do + + factory :vehicle_journey_control_wating_time, class: 'VehicleJourneyControl::WaitingTime' do + association :compliance_control_set + end + + factory :vehicle_journey_control_delta, class: 'VehicleJourneyControl::Delta' do + association :compliance_control_set + end + + factory :vehicle_journey_control_speed, class: 'VehicleJourneyControl::Speed' do + association :compliance_control_set + end + + factory :vehicle_journey_control_time_table, class: 'VehicleJourneyControl::TimeTable' do + association :compliance_control_set + end + + factory :vehicle_journey_control_vehicle_journey_at_stops, class: 'VehicleJourneyControl::VehicleJourneyAtStops' do + association :compliance_control_set + end +end diff --git a/spec/factories/referential_suites.rb b/spec/factories/referential_suites.rb new file mode 100644 index 000000000..bb17b085c --- /dev/null +++ b/spec/factories/referential_suites.rb @@ -0,0 +1,3 @@ +FactoryGirl.define do + factory :referential_suite +end diff --git a/spec/factories/workbenches.rb b/spec/factories/workbenches.rb index d55141513..57bef2203 100644 --- a/spec/factories/workbenches.rb +++ b/spec/factories/workbenches.rb @@ -5,5 +5,6 @@ FactoryGirl.define do association :organisation association :line_referential association :stop_area_referential + association :output, factory: :referential_suite end end diff --git a/spec/features/api_keys/delete_api_key_feature_spec.rb b/spec/features/api_keys/delete_api_key_feature_spec.rb index b58e819a6..6bfc686af 100644 --- a/spec/features/api_keys/delete_api_key_feature_spec.rb +++ b/spec/features/api_keys/delete_api_key_feature_spec.rb @@ -10,7 +10,7 @@ RSpec.describe 'New API Key', type: :feature do xit 'complete workflow' do # /workbenches - visit workbenches_path + visit dashboard_path # the api_key is visible click_link edit_label @@ -23,7 +23,7 @@ RSpec.describe 'New API Key', type: :feature do # expect(Api::V1::ApiKey.where(id: api_key.id)).to be_empty # # check redirect and changed display - # expect(page.current_path).to eq(workbenches_path) + # expect(page.current_path).to eq(dashboard_path) # # deleted api_key's not shown anymore # expect( page ).not_to have_content(edit_label) end @@ -31,4 +31,3 @@ RSpec.describe 'New API Key', type: :feature do end end - 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 411c11aaf..256c4218b 100644 --- a/spec/features/api_keys/edit_api_key_feature_spec.rb +++ b/spec/features/api_keys/edit_api_key_feature_spec.rb @@ -1,4 +1,4 @@ -RSpec.describe 'New API Key', type: :feature do +RSpec.describe 'Edit API Key', type: :feature do login_user describe "api_keys#edit" do @@ -12,8 +12,7 @@ RSpec.describe 'New API Key', type: :feature do let( :unique_name ){ SecureRandom.uuid } it 'complete workflow' do - # /workbenches - visit workbenches_path + visit dashboard_path # api_key's new name does not exist yet expect( page ).not_to have_content(unique_name) # the api_key is visible @@ -28,7 +27,7 @@ RSpec.describe 'New API Key', type: :feature do expect(api_key.reload.name).to eq(unique_name) # check redirect and changed display - expect(page.current_path).to eq(workbenches_path) + expect(page.current_path).to eq(dashboard_path) # changed api_key's name exists now expect( page ).to have_content(unique_name) end @@ -36,4 +35,3 @@ RSpec.describe 'New API Key', type: :feature do end end - 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 eba873691..988690f3c 100644 --- a/spec/features/api_keys/new_api_key_feature_spec.rb +++ b/spec/features/api_keys/new_api_key_feature_spec.rb @@ -1,3 +1,4 @@ +# coding: utf-8 RSpec.describe 'New API Key', type: :feature do login_user @@ -13,21 +14,21 @@ RSpec.describe 'New API Key', type: :feature do it 'complete workflow' do # /workbenches - visit workbenches_path + visit dashboard_path expect(page).to have_link(create_label, href: new_api_key_path) # to be created api_key does not exist yet expect( page ).not_to have_content(unique_name) # /api_keys/new - click_link create_label - fill_in(name_label, with: unique_name) + click_link create_label + fill_in(name_label, with: unique_name) click_button validate_label # check impact on DB expect(last_api_key.name).to eq(unique_name) # check redirect and changed display - expect(page.current_path).to eq(workbenches_path) + expect(page.current_path).to eq(dashboard_path) # to be created api_key exists now expect( page ).to have_content(unique_name) end @@ -35,4 +36,3 @@ RSpec.describe 'New API Key', type: :feature do end end - diff --git a/spec/features/workbenches_spec.rb b/spec/features/workbenches_spec.rb index 14809dec1..e33f8c134 100644 --- a/spec/features/workbenches_spec.rb +++ b/spec/features/workbenches_spec.rb @@ -113,8 +113,8 @@ describe 'Workbenches', type: :feature do it 'should show results for referential in range' do dates = referential.validity_period.to_a - fill_validity_field dates[0], 'begin_gteq' - fill_validity_field dates[1], 'end_lteq' + fill_validity_field dates[0], 'start_date' + fill_validity_field dates[1], 'end_date' click_button I18n.t('actions.filter') expect(page).to have_content(referential.name) @@ -123,8 +123,8 @@ describe 'Workbenches', type: :feature do it 'should keep filtering on sort' do dates = referential.validity_period.to_a - fill_validity_field dates[0], 'begin_gteq' - fill_validity_field dates[1], 'end_lteq' + fill_validity_field dates[0], 'start_date' + fill_validity_field dates[1], 'end_date' click_button I18n.t('actions.filter') find('a[href*="&sort=validity_period"]').click @@ -134,8 +134,8 @@ describe 'Workbenches', type: :feature do end it 'should not show results for out off range' do - fill_validity_field(Date.today - 2.year, 'begin_gteq') - fill_validity_field(Date.today - 1.year, 'end_lteq') + fill_validity_field(Date.today - 2.year, 'start_date') + fill_validity_field(Date.today - 1.year, 'end_date') click_button I18n.t('actions.filter') expect(page).to_not have_content(referential.name) @@ -144,12 +144,12 @@ describe 'Workbenches', type: :feature do it 'should keep value on submit' do dates = referential.validity_period.to_a - ['begin_gteq', 'end_lteq'].each_with_index do |field, index| + ['start_date', 'end_date'].each_with_index do |field, index| fill_validity_field dates[index], field end click_button I18n.t('actions.filter') - ['begin_gteq', 'end_lteq'].each_with_index do |field, index| + ['start_date', 'end_date'].each_with_index do |field, index| expect(find("#q_validity_period_#{field}_3i").value).to eq dates[index].day.to_s expect(find("#q_validity_period_#{field}_2i").value).to eq dates[index].month.to_s expect(find("#q_validity_period_#{field}_1i").value).to eq dates[index].year.to_s diff --git a/spec/javascripts/journey_patterns/actions_spec.js b/spec/javascript/journey_patterns/actions_spec.js index 07f83ca1b..2542fa2f4 100644 --- a/spec/javascripts/journey_patterns/actions_spec.js +++ b/spec/javascript/journey_patterns/actions_spec.js @@ -1,4 +1,4 @@ -var actions = require('es6_browserified/journey_patterns/actions') +import actions from '../../../app/javascript/journey_patterns/actions' const dispatch = function(){} const currentPage = 1 diff --git a/spec/javascripts/journey_patterns/reducers/journey_patterns_spec.js b/spec/javascript/journey_patterns/reducers/journey_patterns_spec.js index df288e530..24780ab5a 100644 --- a/spec/javascripts/journey_patterns/reducers/journey_patterns_spec.js +++ b/spec/javascript/journey_patterns/reducers/journey_patterns_spec.js @@ -1,4 +1,5 @@ -var jpReducer = require('es6_browserified/journey_patterns/reducers/journeyPatterns') +import jpReducer from '../../../../app/javascript/journey_patterns/reducers/journeyPatterns' + let state = [] let fakeStopPoints = [{ area_type : "lda", diff --git a/spec/javascripts/journey_patterns/reducers/modal_spec.js b/spec/javascript/journey_patterns/reducers/modal_spec.js index 0bc7c9240..4031ea234 100644 --- a/spec/javascripts/journey_patterns/reducers/modal_spec.js +++ b/spec/javascript/journey_patterns/reducers/modal_spec.js @@ -1,4 +1,4 @@ -var modalReducer = require('es6_browserified/journey_patterns/reducers/modal') +import modalReducer from '../../../../app/javascript/journey_patterns/reducers/modal' let state = {} diff --git a/spec/javascripts/journey_patterns/reducers/pagination_spec.js b/spec/javascript/journey_patterns/reducers/pagination_spec.js index d0f9fef47..a3cd4bf0a 100644 --- a/spec/javascripts/journey_patterns/reducers/pagination_spec.js +++ b/spec/javascript/journey_patterns/reducers/pagination_spec.js @@ -1,4 +1,4 @@ -var reducer = require('es6_browserified/journey_patterns/reducers/pagination') +import reducer from '../../../../app/javascript/journey_patterns/reducers/pagination' const diff = 1 let state = { diff --git a/spec/javascripts/journey_patterns/reducers/status_spec.js b/spec/javascript/journey_patterns/reducers/status_spec.js index 91cbbb0b8..ab094088a 100644 --- a/spec/javascripts/journey_patterns/reducers/status_spec.js +++ b/spec/javascript/journey_patterns/reducers/status_spec.js @@ -1,4 +1,4 @@ -var statusReducer = require('es6_browserified/journey_patterns/reducers/status') +import statusReducer from '../../../../app/javascript/journey_patterns/reducers/status' let state = {} diff --git a/spec/javascripts/itineraries/actions_spec.js b/spec/javascript/routes/actions_spec.js index 2bae59987..507e1e0ed 100644 --- a/spec/javascripts/itineraries/actions_spec.js +++ b/spec/javascript/routes/actions_spec.js @@ -1,4 +1,4 @@ -var actions = require('es6_browserified/itineraries/actions') +import actions from '../../../app/javascript/routes/actions' describe('actions', () => { it('should create an action to add a stop', () => { diff --git a/spec/javascripts/itineraries/reducers/stop_points_spec.js b/spec/javascript/routes/reducers/stop_points_spec.js index 0331a424c..b375cdc2c 100644 --- a/spec/javascripts/itineraries/reducers/stop_points_spec.js +++ b/spec/javascript/routes/reducers/stop_points_spec.js @@ -1,4 +1,4 @@ -var stopPointsReducer = require('es6_browserified/itineraries/reducers/stopPoints') +import stopPointsReducer from '../../../../app/javascript/routes/reducers/stopPoints' let state = [] diff --git a/spec/javascripts/spec_helper.coffee b/spec/javascript/spec_helper.coffee index 9ff516885..9ff516885 100644 --- a/spec/javascripts/spec_helper.coffee +++ b/spec/javascript/spec_helper.coffee diff --git a/spec/javascripts/time_table/actions_spec.js b/spec/javascript/time_table/actions_spec.js index 00acac0d1..003b7f6b5 100644 --- a/spec/javascripts/time_table/actions_spec.js +++ b/spec/javascript/time_table/actions_spec.js @@ -1,4 +1,4 @@ -var actions = require('es6_browserified/time_tables/actions') +import actions from '../../../app/javascript/time_tables/actions' const dispatch = function(){} const dayTypes = [true, true, true, true, true, true, true] const day = { diff --git a/spec/javascripts/time_table/reducers/metas_spec.js b/spec/javascript/time_table/reducers/metas_spec.js index 5ec7a0034..374ad1814 100644 --- a/spec/javascripts/time_table/reducers/metas_spec.js +++ b/spec/javascript/time_table/reducers/metas_spec.js @@ -1,4 +1,4 @@ -var metasReducer = require('es6_browserified/time_tables/reducers/metas') +import metasReducer from '../../../../app/javascript/time_tables/reducers/metas' let state = {} diff --git a/spec/javascripts/time_table/reducers/modal_spec.js b/spec/javascript/time_table/reducers/modal_spec.js index 05d58a138..1794d2acd 100644 --- a/spec/javascripts/time_table/reducers/modal_spec.js +++ b/spec/javascript/time_table/reducers/modal_spec.js @@ -1,4 +1,4 @@ -var modalReducer = require('es6_browserified/time_tables/reducers/modal') +import modalReducer from '../../../../app/javascript/time_tables/reducers/modal' let state = {} diff --git a/spec/javascripts/time_table/reducers/pagination_spec.js b/spec/javascript/time_table/reducers/pagination_spec.js index 3c1edb9c5..5aa8d27a2 100644 --- a/spec/javascripts/time_table/reducers/pagination_spec.js +++ b/spec/javascript/time_table/reducers/pagination_spec.js @@ -1,4 +1,4 @@ -var paginationReducer = require('es6_browserified/time_tables/reducers/pagination') +import paginationReducer from '../../../../app/javascript/time_tables/reducers/pagination' const dispatch = function(){} diff --git a/spec/javascripts/time_table/reducers/status_spec.js b/spec/javascript/time_table/reducers/status_spec.js index f000324cc..63e4033f9 100644 --- a/spec/javascripts/time_table/reducers/status_spec.js +++ b/spec/javascript/time_table/reducers/status_spec.js @@ -1,4 +1,4 @@ -var statusReducer = require('es6_browserified/time_tables/reducers/status') +import statusReducer from '../../../../app/javascript/time_tables/reducers/status' let state = {} diff --git a/spec/javascripts/time_table/reducers/timetable_spec.js b/spec/javascript/time_table/reducers/timetable_spec.js index 21f6d236d..f0f9eaa8c 100644 --- a/spec/javascripts/time_table/reducers/timetable_spec.js +++ b/spec/javascript/time_table/reducers/timetable_spec.js @@ -1,5 +1,5 @@ require('whatwg-fetch') -var timetableReducer = require('es6_browserified/time_tables/reducers/timetable') +import timetableReducer from '../../../../app/javascript/time_tables/reducers/timetable' let state = {} const dispatch = function(){} @@ -22,6 +22,8 @@ let json = { time_table_dates: time_table_dates } + + describe('timetable reducer with empty state', () => { beforeEach(() => { state = { diff --git a/spec/javascripts/vehicle_journeys/actions_spec.js b/spec/javascript/vehicle_journeys/actions_spec.js index 707ae22cb..74765a7ef 100644 --- a/spec/javascripts/vehicle_journeys/actions_spec.js +++ b/spec/javascript/vehicle_journeys/actions_spec.js @@ -1,4 +1,4 @@ -var actions = require('es6_browserified/vehicle_journeys/actions') +import actions from '../../../app/javascript/vehicle_journeys/actions/index' const dispatch = function(){} const currentPage = 1 diff --git a/spec/javascripts/vehicle_journeys/reducers/filters_spec.js b/spec/javascript/vehicle_journeys/reducers/filters_spec.js index 0a6729c8b..207eaead4 100644 --- a/spec/javascripts/vehicle_journeys/reducers/filters_spec.js +++ b/spec/javascript/vehicle_journeys/reducers/filters_spec.js @@ -1,4 +1,4 @@ -var statusReducer = require('es6_browserified/vehicle_journeys/reducers/filters') +import statusReducer from '../../../../app/javascript/vehicle_journeys/reducers/filters' let state = {} diff --git a/spec/javascripts/vehicle_journeys/reducers/modal_spec.js b/spec/javascript/vehicle_journeys/reducers/modal_spec.js index 4530b5ee7..69de9168b 100644 --- a/spec/javascripts/vehicle_journeys/reducers/modal_spec.js +++ b/spec/javascript/vehicle_journeys/reducers/modal_spec.js @@ -1,4 +1,4 @@ -var modalReducer = require('es6_browserified/vehicle_journeys/reducers/modal') +import modalReducer from '../../../../app/javascript/vehicle_journeys/reducers/modal' let state = {} diff --git a/spec/javascripts/vehicle_journeys/reducers/pagination_spec.js b/spec/javascript/vehicle_journeys/reducers/pagination_spec.js index 57417a3b9..352997c7c 100644 --- a/spec/javascripts/vehicle_journeys/reducers/pagination_spec.js +++ b/spec/javascript/vehicle_journeys/reducers/pagination_spec.js @@ -1,4 +1,4 @@ -var reducer = require('es6_browserified/vehicle_journeys/reducers/pagination') +import reducer from '../../../../app/javascript/vehicle_journeys/reducers/pagination' const diff = 1 let state = { diff --git a/spec/javascripts/vehicle_journeys/reducers/status_spec.js b/spec/javascript/vehicle_journeys/reducers/status_spec.js index d48d48f4a..8fc0f557e 100644 --- a/spec/javascripts/vehicle_journeys/reducers/status_spec.js +++ b/spec/javascript/vehicle_journeys/reducers/status_spec.js @@ -1,4 +1,4 @@ -var statusReducer = require('es6_browserified/vehicle_journeys/reducers/status') +import statusReducer from '../../../../app/javascript/vehicle_journeys/reducers/status' let state = {} diff --git a/spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js b/spec/javascript/vehicle_journeys/reducers/vehicle_journeys_spec.js index 3b2137a2a..c02ab3398 100644 --- a/spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js +++ b/spec/javascript/vehicle_journeys/reducers/vehicle_journeys_spec.js @@ -1,4 +1,4 @@ -var vjReducer = require('es6_browserified/vehicle_journeys/reducers/vehicleJourneys') +import vjReducer from '../../../../app/javascript/vehicle_journeys/reducers/vehicleJourneys' let state = [] let stateModal = { diff --git a/spec/javascripts/spec_helper.js b/spec/javascripts/spec_helper.js deleted file mode 100644 index a0285cccf..000000000 --- a/spec/javascripts/spec_helper.js +++ /dev/null @@ -1,35 +0,0 @@ -// Teaspoon includes some support files, but you can use anything from your own support path too. -// require support/jasmine-jquery-1.7.0 -// require support/jasmine-jquery-2.0.0 -// require support/jasmine-jquery-2.1.0 -// require support/sinon -// require support/your-support-file -//= require jquery -//= require bootstrap-sass-official -require('es6-object-assign').polyfill(); -// -// PhantomJS (Teaspoons default driver) doesn't have support for Function.prototype.bind, which has caused confusion. -// Use this polyfill to avoid the confusion. -//= require support/phantomjs-shims -// -// You can require your own javascript files here. By default this will include everything in application, however you -// may get better load performance if you require the specific files that are being used in the spec that tests them. -//= require application -// -// Deferring execution -// If you're using CommonJS, RequireJS or some other asynchronous library you can defer execution. Call -// Teaspoon.execute() after everything has been loaded. Simple example of a timeout: -// -// Teaspoon.defer = true -// setTimeout(Teaspoon.execute, 1000) -// -// Matching files -// By default Teaspoon will look for files that match _spec.{js,js.coffee,.coffee}. Add a filename_spec.js file in your -// spec path and it'll be included in the default suite automatically. If you want to customize suites, check out the -// configuration in teaspoon_env.rb -// -// Manifest -// If you'd rather require your spec files manually (to control order for instance) you can disable the suite matcher in -// the configuration and use this file as a manifest. -// -// For more information: http://github.com/modeset/teaspoon diff --git a/spec/lib/compliance_control_set_copier_spec.rb b/spec/lib/compliance_control_set_copier_spec.rb new file mode 100644 index 000000000..a9e576cf7 --- /dev/null +++ b/spec/lib/compliance_control_set_copier_spec.rb @@ -0,0 +1,122 @@ +RSpec.describe ComplianceControlSetCopier do + + subject{ described_class.new } + + let( :cc_set ){ create :compliance_control_set } + + context 'Copying empty set' do + context 'incorrect organisation' do + # Assuring the organisation missmatch + before { referential.organisation_id = cc_set.organisation_id.succ } + it 'fails' do + expect{ subject.copy(cc_set.id, referential.id) }.to raise_error(ArgumentError) + end + it 'does not create any objects in the database' do + expect{ subject.copy(cc_set.id, referential.id) rescue nil }.to_not change{ComplianceCheckSet.count} + expect{ subject.copy(cc_set.id, referential.id) rescue nil }.to_not change{ComplianceCheckBlock.count} + expect{ subject.copy(cc_set.id, referential.id) rescue nil }.to_not change{ComplianceCheck.count} + end + end + + context 'correct organisation' do + let(:ref){ create :referential, organisation_id: cc_set.organisation_id } + + context 'Directed Acyclic Graph is copied correctly' do + let(:cc_blox){ + 3.times.map{ |_| create :compliance_control_block, compliance_control_set: cc_set } + } + let!(:direct_ccs){ + 3.times.map{ |n| create :compliance_control, compliance_control_set: cc_set, name: "direct #{n.succ}", code: "direct-#{n.succ}" } + } + # Needed to check we do not dulicate a node (compliance_control) twice + let!(:indirect_ccs){ + # Create 1 child for each block and also associate first of the direct ccs to the first block + # seconf of the direct css to the second block + cc_blox.take(2).zip(direct_ccs.take(2)).each do | cc_block, cc | + cc.update compliance_control_block_id: cc_block.id + end + cc_blox.each_with_index.map{ | cc_block, n | + create(:compliance_control, compliance_control_set: cc_set, compliance_control_block: cc_block, name: "indirect #{n.succ}", code: "indirect-#{n.succ}") + } + } + + let( :cck_set ){ ComplianceCheckSet.last } + let( :cck_blox ){ cck_set.compliance_check_blocks } + let( :ccks ){ cck_set.compliance_checks } + + it 'correctly creates a cck_set for a complete DAG' do + # Slowness of tests constrains us to create a minimum of objects in the DB, + # hence only one example :( + counts = object_counts + subject.copy(cc_set.id, ref.id) + + # Did not change the original objects + # Correct numbers + expect( ComplianceControlSet.count ).to eq(counts.cc_set_count) + expect( ComplianceControlBlock.count ).to eq(counts.cc_block_count) + expect( ComplianceControl.count ).to eq(counts.cc_count) + + expect( ComplianceCheckSet.count ).to eq(counts.cck_set_count + 1) + expect( cck_blox.count ).to eq(counts.cck_block_count + cc_blox.size) + expect( ccks.count ).to eq(counts.cck_count + direct_ccs.size + indirect_ccs.size) + + # Correcly associated + expect( cck_blox.map(&:compliance_checks).map(&:size) ) + .to eq([2, 2, 1]) + expect( ComplianceCheck.where(name: mk_name('direct 1')).first.compliance_check_block_id ) + .to eq( cck_blox.first.id ) + expect( ComplianceCheck.where(name: mk_name('direct 3')).first.compliance_check_block_id ).to be_nil + end + end + + context 'Node data is copied correctly' do + let( :cc_block ){ create :compliance_control_block, compliance_control_set: cc_set } + + let!( :control ){ create :compliance_control, + compliance_control_set: cc_set, + compliance_control_block: cc_block, + name: 'control' } + + let( :cck_set ) { ComplianceCheckSet.last } + let( :cck_block ) { ComplianceCheckBlock.last } + let( :cck ) { ComplianceCheck.last } + + it 'into the compliance_check nodes' do + subject.copy(cc_set.id, ref.id) + + # Set + expect( cck_set.name ).to eq(mk_name(cc_set.name)) + + # Block + expect( cck_block.name ).to eq(mk_name(cc_block.name)) + expect( cck_block.condition_attributes ).to eq(cc_block.condition_attributes) + + # Control/Check + att_names = %w{ control_attributes code criticity comment origin_code } + expected = control.attributes.values_at(*att_names) << mk_name(control.name) + actual = cck.attributes.values_at(*(att_names << 'name')) + + expect( actual ).to eq( expected ) + + end + end + + end + + + def object_counts + OpenStruct.new \ + cc_set_count: ComplianceControlSet.count, + cc_block_count: ComplianceControlBlock.count, + cc_count: ComplianceControl.count, + cck_set_count: ComplianceCheckSet.count, + cck_block_count: ComplianceCheckBlock.count, + cck_count: ComplianceCheck.count + end + + def mk_name name + [name, ref.name].join('-') + end + end + +end diff --git a/spec/models/chouette/transport_mode_spec.rb b/spec/models/chouette/transport_mode_spec.rb deleted file mode 100644 index 8f2b2eddb..000000000 --- a/spec/models/chouette/transport_mode_spec.rb +++ /dev/null @@ -1,64 +0,0 @@ -require 'spec_helper' - -describe Chouette::TransportMode, :type => :model do - - def mode(text_code = "test", numerical_code = nil) - numerical_code ||= 1 if text_code == "test" - Chouette::TransportMode.new(text_code, numerical_code) - end - - describe "#to_i" do - - it "should return numerical code" do - expect(mode("test", 1).to_i).to eq(1) - end - - end - - it "should return true to #test? when text code is 'test'" do - expect(mode("test")).to be_test - end - - it "should be equal when text codes are identical" do - expect(mode("test",1)).to eq(mode("test", 2)) - end - - describe ".new" do - - it "should find numerical code from text code" do - expect(mode("unknown").to_i).to eq(0) - end - - it "should find text code from numerical code" do - expect(mode(0)).to be_unknown - end - - it "should accept another mode" do - expect(Chouette::TransportMode.new(mode("test"))).to eq(mode("test")) - end - - end - - describe "#public_transport?" do - - it "should return false for interchange" do - expect(mode("interchange")).not_to be_public_transport - end - - it "should return true for other modes" do - expect(mode("unknown")).to be_public_transport - end - - end - - describe ".all" do - - Chouette::TransportMode.definitions.each do |text_code, numerical_code| - it "should include a TransportMode #{text_code}" do - expect(Chouette::TransportMode.all).to include(Chouette::TransportMode.new(text_code)) - end - end - - end - -end diff --git a/spec/models/compliance_check_block_spec.rb b/spec/models/compliance_check_block_spec.rb index f581d5085..a3d98d459 100644 --- a/spec/models/compliance_check_block_spec.rb +++ b/spec/models/compliance_check_block_spec.rb @@ -6,4 +6,5 @@ RSpec.describe ComplianceCheckBlock, type: :model do end it { should belong_to :compliance_check_set } + it { should have_many :compliance_checks } end diff --git a/spec/models/compliance_check_message_spec.rb b/spec/models/compliance_check_message_spec.rb index 8b424595e..b55537f95 100644 --- a/spec/models/compliance_check_message_spec.rb +++ b/spec/models/compliance_check_message_spec.rb @@ -1,5 +1,3 @@ -require 'rails_helper' - RSpec.describe ComplianceCheckMessage, type: :model do it 'should have a valid factory' do expect(FactoryGirl.build(:compliance_check_message)).to be_valid @@ -7,4 +5,5 @@ RSpec.describe ComplianceCheckMessage, type: :model do it { should belong_to :compliance_check } it { should belong_to :compliance_check_resource } + 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 index a9366bea2..40e209db0 100644 --- a/spec/models/compliance_check_resource_spec.rb +++ b/spec/models/compliance_check_resource_spec.rb @@ -4,4 +4,6 @@ RSpec.describe ComplianceCheckResource, type: :model do it 'should have a valid factory' do expect(FactoryGirl.build(:compliance_check_resource)).to be_valid end + + it { should validate_presence_of(:compliance_check_set) } end diff --git a/spec/models/compliance_check_set_spec.rb b/spec/models/compliance_check_set_spec.rb index 6e53c9def..8afea5b3e 100644 --- a/spec/models/compliance_check_set_spec.rb +++ b/spec/models/compliance_check_set_spec.rb @@ -9,4 +9,7 @@ RSpec.describe ComplianceCheckSet, type: :model do it { should belong_to :workbench } it { should belong_to :compliance_control_set } it { should belong_to :parent } + + it { should have_many :compliance_checks } + it { should have_many :compliance_check_blocks } end diff --git a/spec/models/compliance_check_spec.rb b/spec/models/compliance_check_spec.rb index 4fbc23d42..bd797ab09 100644 --- a/spec/models/compliance_check_spec.rb +++ b/spec/models/compliance_check_spec.rb @@ -1,14 +1,17 @@ -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 'has STI disabled' do + expect( described_class.inheritance_column ).to be_blank + 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 } + it { should validate_presence_of :origin_code } end diff --git a/spec/models/compliance_control_block_spec.rb b/spec/models/compliance_control_block_spec.rb index 248049b0c..c7440a5eb 100644 --- a/spec/models/compliance_control_block_spec.rb +++ b/spec/models/compliance_control_block_spec.rb @@ -1,9 +1,13 @@ require 'rails_helper' RSpec.describe ComplianceControlBlock, type: :model do + subject { create(:compliance_control_block) } + it 'should have a valid factory' do expect(FactoryGirl.build(:compliance_control_block)).to be_valid end it { should belong_to :compliance_control_set } + it { should have_many(:compliance_controls).dependent(:destroy) } + it { should validate_presence_of(:transport_mode) } end diff --git a/spec/models/compliance_control_class_level_defaults/generic_attribute_control/min_max_cccld_spec.rb b/spec/models/compliance_control_class_level_defaults/generic_attribute_control/min_max_cccld_spec.rb new file mode 100644 index 000000000..e39e5e4c0 --- /dev/null +++ b/spec/models/compliance_control_class_level_defaults/generic_attribute_control/min_max_cccld_spec.rb @@ -0,0 +1,7 @@ + +RSpec.describe GenericAttributeControl::MinMax, type: :model do + let( :default_code ){ "3-Generic-2" } + let( :factory ){ :generic_attribute_control_min_max } + + it_behaves_like 'ComplianceControl Class Level Defaults' +end diff --git a/spec/models/compliance_control_class_level_defaults/generic_attribute_control/parent_class_cccld_spec.rb b/spec/models/compliance_control_class_level_defaults/generic_attribute_control/parent_class_cccld_spec.rb new file mode 100644 index 000000000..f9c4373d5 --- /dev/null +++ b/spec/models/compliance_control_class_level_defaults/generic_attribute_control/parent_class_cccld_spec.rb @@ -0,0 +1,7 @@ +RSpec.describe ComplianceControl do + context 'class attributes' do + it 'are correctly set' do + expect( described_class ).to respond_to(:default_code) + end + end +end diff --git a/spec/models/compliance_control_class_level_defaults/generic_attribute_control/pattern_cccld_spec.rb b/spec/models/compliance_control_class_level_defaults/generic_attribute_control/pattern_cccld_spec.rb new file mode 100644 index 000000000..9610cc796 --- /dev/null +++ b/spec/models/compliance_control_class_level_defaults/generic_attribute_control/pattern_cccld_spec.rb @@ -0,0 +1,7 @@ + +RSpec.describe GenericAttributeControl::Pattern, type: :model do + let( :default_code ){ "3-Generic-1" } + let( :factory ){ :generic_attribute_control_pattern } + + it_behaves_like 'ComplianceControl Class Level Defaults' +end diff --git a/spec/models/compliance_control_class_level_defaults/generic_attribute_control/uniqueness_cccld_spec.rb b/spec/models/compliance_control_class_level_defaults/generic_attribute_control/uniqueness_cccld_spec.rb new file mode 100644 index 000000000..e4ab8d2cd --- /dev/null +++ b/spec/models/compliance_control_class_level_defaults/generic_attribute_control/uniqueness_cccld_spec.rb @@ -0,0 +1,7 @@ + +RSpec.describe GenericAttributeControl::Uniqueness, type: :model do + let( :default_code ){ "3-Generic-3" } + let( :factory ){ :generic_attribute_control_uniqueness } + + it_behaves_like 'ComplianceControl Class Level Defaults' +end diff --git a/spec/models/compliance_control_class_level_defaults/journey_pattern_control/duplicates_cccld_spec.rb b/spec/models/compliance_control_class_level_defaults/journey_pattern_control/duplicates_cccld_spec.rb new file mode 100644 index 000000000..89544937b --- /dev/null +++ b/spec/models/compliance_control_class_level_defaults/journey_pattern_control/duplicates_cccld_spec.rb @@ -0,0 +1,7 @@ + +RSpec.describe JourneyPatternControl::Duplicates, type: :model do + let( :default_code ){ "3-JourneyPattern-1" } + let( :factory ){ :journey_pattern_control_duplicates } + + it_behaves_like 'ComplianceControl Class Level Defaults' +end diff --git a/spec/models/compliance_control_class_level_defaults/journey_pattern_control/vehicle_journey_cccld_spec.rb b/spec/models/compliance_control_class_level_defaults/journey_pattern_control/vehicle_journey_cccld_spec.rb new file mode 100644 index 000000000..fb254ee31 --- /dev/null +++ b/spec/models/compliance_control_class_level_defaults/journey_pattern_control/vehicle_journey_cccld_spec.rb @@ -0,0 +1,7 @@ + +RSpec.describe JourneyPatternControl::VehicleJourney, type: :model do + let( :default_code ){ "3-JourneyPattern-2" } + let( :factory ){ :journey_pattern_control_vehicle_journey } + + it_behaves_like 'ComplianceControl Class Level Defaults' +end diff --git a/spec/models/compliance_control_class_level_defaults/line_control/route_cccld_spec.rb b/spec/models/compliance_control_class_level_defaults/line_control/route_cccld_spec.rb new file mode 100644 index 000000000..ab5fb1027 --- /dev/null +++ b/spec/models/compliance_control_class_level_defaults/line_control/route_cccld_spec.rb @@ -0,0 +1,7 @@ + +RSpec.describe LineControl::Route, type: :model do + let( :default_code ){ "3-Line-1" } + let( :factory ){ :line_control_route } + + it_behaves_like 'ComplianceControl Class Level Defaults' +end diff --git a/spec/models/compliance_control_class_level_defaults/route_control/duplicates_cccld_spec.rb b/spec/models/compliance_control_class_level_defaults/route_control/duplicates_cccld_spec.rb new file mode 100644 index 000000000..46531cc3b --- /dev/null +++ b/spec/models/compliance_control_class_level_defaults/route_control/duplicates_cccld_spec.rb @@ -0,0 +1,7 @@ + +RSpec.describe RouteControl::Duplicates, type: :model do + let( :default_code ){ "3-Route-4" } + let( :factory ){ :route_control_duplicates } + + it_behaves_like 'ComplianceControl Class Level Defaults' +end diff --git a/spec/models/compliance_control_class_level_defaults/route_control/journey_pattern_cccld_spec.rb b/spec/models/compliance_control_class_level_defaults/route_control/journey_pattern_cccld_spec.rb new file mode 100644 index 000000000..2bdd6e591 --- /dev/null +++ b/spec/models/compliance_control_class_level_defaults/route_control/journey_pattern_cccld_spec.rb @@ -0,0 +1,7 @@ + +RSpec.describe RouteControl::JourneyPattern, type: :model do + let( :default_code ){ "3-Route-3" } + let( :factory ){ :route_control_journey_pattern } + + it_behaves_like 'ComplianceControl Class Level Defaults' +end diff --git a/spec/models/compliance_control_class_level_defaults/route_control/minimum_length_cccld_spec.rb b/spec/models/compliance_control_class_level_defaults/route_control/minimum_length_cccld_spec.rb new file mode 100644 index 000000000..85bab4ac6 --- /dev/null +++ b/spec/models/compliance_control_class_level_defaults/route_control/minimum_length_cccld_spec.rb @@ -0,0 +1,7 @@ + +RSpec.describe RouteControl::MinimumLength, type: :model do + let( :default_code ){ "3-Route-6" } + let( :factory ){ :route_control_minimum_length } + + it_behaves_like 'ComplianceControl Class Level Defaults' +end diff --git a/spec/models/compliance_control_class_level_defaults/route_control/omnibus_journey_pattern_cccld_spec.rb b/spec/models/compliance_control_class_level_defaults/route_control/omnibus_journey_pattern_cccld_spec.rb new file mode 100644 index 000000000..3fb782e85 --- /dev/null +++ b/spec/models/compliance_control_class_level_defaults/route_control/omnibus_journey_pattern_cccld_spec.rb @@ -0,0 +1,7 @@ + +RSpec.describe RouteControl::OmnibusJourneyPattern, type: :model do + let( :default_code ){ "3-Route-9" } + let( :factory ){ :route_control_omnibus_journey_pattern } + + it_behaves_like 'ComplianceControl Class Level Defaults' +end diff --git a/spec/models/compliance_control_class_level_defaults/route_control/opposite_route_cccld_spec.rb b/spec/models/compliance_control_class_level_defaults/route_control/opposite_route_cccld_spec.rb new file mode 100644 index 000000000..7013ae269 --- /dev/null +++ b/spec/models/compliance_control_class_level_defaults/route_control/opposite_route_cccld_spec.rb @@ -0,0 +1,7 @@ + +RSpec.describe RouteControl::OppositeRoute, type: :model do + let( :default_code ){ "3-Route-2" } + let( :factory ){ :route_control_opposite_route } + + it_behaves_like 'ComplianceControl Class Level Defaults' +end diff --git a/spec/models/compliance_control_class_level_defaults/route_control/opposite_route_terminus_cccld_spec.rb b/spec/models/compliance_control_class_level_defaults/route_control/opposite_route_terminus_cccld_spec.rb new file mode 100644 index 000000000..a3a8d290d --- /dev/null +++ b/spec/models/compliance_control_class_level_defaults/route_control/opposite_route_terminus_cccld_spec.rb @@ -0,0 +1,7 @@ + +RSpec.describe RouteControl::OppositeRouteTerminus, type: :model do + let( :default_code ){ "3-Route-5" } + let( :factory ){ :route_control_opposite_route_terminus } + + it_behaves_like 'ComplianceControl Class Level Defaults' +end diff --git a/spec/models/compliance_control_class_level_defaults/route_control/stop_points_in_journey_pattern_cccld_spec.rb b/spec/models/compliance_control_class_level_defaults/route_control/stop_points_in_journey_pattern_cccld_spec.rb new file mode 100644 index 000000000..f8533aa06 --- /dev/null +++ b/spec/models/compliance_control_class_level_defaults/route_control/stop_points_in_journey_pattern_cccld_spec.rb @@ -0,0 +1,7 @@ + +RSpec.describe RouteControl::StopPointsInJourneyPattern, type: :model do + let( :default_code ){ "3-Route-8" } + let( :factory ){ :route_control_stop_points_in_journey_pattern } + + 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 new file mode 100644 index 000000000..bf725d743 --- /dev/null +++ b/spec/models/compliance_control_class_level_defaults/route_control/unactivated_stop_points_cccld_spec.rb @@ -0,0 +1,7 @@ + +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_class_level_defaults/route_control/zdl_stop_area_cccld_spec.rb b/spec/models/compliance_control_class_level_defaults/route_control/zdl_stop_area_cccld_spec.rb new file mode 100644 index 000000000..2b8a11bd1 --- /dev/null +++ b/spec/models/compliance_control_class_level_defaults/route_control/zdl_stop_area_cccld_spec.rb @@ -0,0 +1,7 @@ + +RSpec.describe RouteControl::ZDLStopArea, type: :model do + let( :default_code ){ "3-Route-1" } + let( :factory ){ :route_control_zdl_stop_area } + + it_behaves_like 'ComplianceControl Class Level Defaults' +end diff --git a/spec/models/compliance_control_class_level_defaults/routing_constraint_zone_control/maximum_length_cccld_spec.rb b/spec/models/compliance_control_class_level_defaults/routing_constraint_zone_control/maximum_length_cccld_spec.rb new file mode 100644 index 000000000..61896ef5e --- /dev/null +++ b/spec/models/compliance_control_class_level_defaults/routing_constraint_zone_control/maximum_length_cccld_spec.rb @@ -0,0 +1,7 @@ + +RSpec.describe RoutingConstraintZoneControl::MaximumLength, type: :model do + let( :default_code ){ "3-ITL-2" } + let( :factory ){ :routing_constraint_zone_control_maximum_length } + + it_behaves_like 'ComplianceControl Class Level Defaults' +end diff --git a/spec/models/compliance_control_class_level_defaults/routing_constraint_zone_control/minimum_length_cccld_spec.rb b/spec/models/compliance_control_class_level_defaults/routing_constraint_zone_control/minimum_length_cccld_spec.rb new file mode 100644 index 000000000..e930c2475 --- /dev/null +++ b/spec/models/compliance_control_class_level_defaults/routing_constraint_zone_control/minimum_length_cccld_spec.rb @@ -0,0 +1,7 @@ + +RSpec.describe RoutingConstraintZoneControl::MinimumLength, type: :model do + let( :default_code ){ "3-ITL-3" } + let( :factory ){ :routing_constraint_zone_control_minimum_length } + + it_behaves_like 'ComplianceControl Class Level Defaults' +end diff --git a/spec/models/compliance_control_class_level_defaults/routing_constraint_zone_control/unactivated_stop_point_cccld_spec.rb b/spec/models/compliance_control_class_level_defaults/routing_constraint_zone_control/unactivated_stop_point_cccld_spec.rb new file mode 100644 index 000000000..aba9b7fc1 --- /dev/null +++ b/spec/models/compliance_control_class_level_defaults/routing_constraint_zone_control/unactivated_stop_point_cccld_spec.rb @@ -0,0 +1,7 @@ + +RSpec.describe RoutingConstraintZoneControl::UnactivatedStopPoint, type: :model do + let( :default_code ){ "3-ITL-1" } + let( :factory ){ :routing_constraint_zone_control_unactivated_stop_point } + + it_behaves_like 'ComplianceControl Class Level Defaults' +end diff --git a/spec/models/compliance_control_class_level_defaults/vehicle_journey_control/delta_cccld_spec.rb b/spec/models/compliance_control_class_level_defaults/vehicle_journey_control/delta_cccld_spec.rb new file mode 100644 index 000000000..0d4bce7ca --- /dev/null +++ b/spec/models/compliance_control_class_level_defaults/vehicle_journey_control/delta_cccld_spec.rb @@ -0,0 +1,7 @@ + +RSpec.describe VehicleJourneyControl::Delta, type: :model do + let( :default_code ){ "3-VehicleJourney-3" } + let( :factory ){ :vehicle_journey_control_delta } + + it_behaves_like 'ComplianceControl Class Level Defaults' +end diff --git a/spec/models/compliance_control_class_level_defaults/vehicle_journey_control/speed_cccld_spec.rb b/spec/models/compliance_control_class_level_defaults/vehicle_journey_control/speed_cccld_spec.rb new file mode 100644 index 000000000..2a3cae9ff --- /dev/null +++ b/spec/models/compliance_control_class_level_defaults/vehicle_journey_control/speed_cccld_spec.rb @@ -0,0 +1,7 @@ + +RSpec.describe VehicleJourneyControl::Speed, type: :model do + let( :default_code ){ "3-VehicleJourney-2" } + let( :factory ){ :vehicle_journey_control_speed } + + it_behaves_like 'ComplianceControl Class Level Defaults' +end diff --git a/spec/models/compliance_control_class_level_defaults/vehicle_journey_control/time_table_cccld_spec.rb b/spec/models/compliance_control_class_level_defaults/vehicle_journey_control/time_table_cccld_spec.rb new file mode 100644 index 000000000..19dfe871d --- /dev/null +++ b/spec/models/compliance_control_class_level_defaults/vehicle_journey_control/time_table_cccld_spec.rb @@ -0,0 +1,7 @@ + +RSpec.describe VehicleJourneyControl::TimeTable, type: :model do + let( :default_code ){ "3-VehicleJourney-4" } + let( :factory ){ :vehicle_journey_control_time_table } + + it_behaves_like 'ComplianceControl Class Level Defaults' +end diff --git a/spec/models/compliance_control_class_level_defaults/vehicle_journey_control/vehicle_journey_at_stops_cccld_spec.rb b/spec/models/compliance_control_class_level_defaults/vehicle_journey_control/vehicle_journey_at_stops_cccld_spec.rb new file mode 100644 index 000000000..30b5893d5 --- /dev/null +++ b/spec/models/compliance_control_class_level_defaults/vehicle_journey_control/vehicle_journey_at_stops_cccld_spec.rb @@ -0,0 +1,7 @@ + +RSpec.describe VehicleJourneyControl::VehicleJourneyAtStops, type: :model do + let( :default_code ){ "3-VehicleJourney-5" } + let( :factory ){ :vehicle_journey_control_vehicle_journey_at_stops } + + it_behaves_like 'ComplianceControl Class Level Defaults' +end diff --git a/spec/models/compliance_control_class_level_defaults/vehicle_journey_control/waiting_time_cccld_spec.rb b/spec/models/compliance_control_class_level_defaults/vehicle_journey_control/waiting_time_cccld_spec.rb new file mode 100644 index 000000000..34058ef33 --- /dev/null +++ b/spec/models/compliance_control_class_level_defaults/vehicle_journey_control/waiting_time_cccld_spec.rb @@ -0,0 +1,7 @@ + +RSpec.describe VehicleJourneyControl::WaitingTime, type: :model do + let( :default_code ){ "3-VehicleJourney-1" } + let( :factory ){ :vehicle_journey_control_wating_time } + + 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 ededec5e0..04d1c418c 100644 --- a/spec/models/compliance_control_set_spec.rb +++ b/spec/models/compliance_control_set_spec.rb @@ -6,7 +6,8 @@ RSpec.describe ComplianceControlSet, type: :model do end it { should belong_to :organisation } - it { should have_many :compliance_controls } + it { should have_many(:compliance_controls).dependent(:destroy) } + it { should have_many(:compliance_control_blocks).dependent(:destroy) } it { should validate_presence_of :name } end diff --git a/spec/models/compliance_control_spec.rb b/spec/models/compliance_control_spec.rb index b00ff4c5a..db73dab21 100644 --- a/spec/models/compliance_control_spec.rb +++ b/spec/models/compliance_control_spec.rb @@ -1,14 +1,59 @@ -require 'rails_helper' - RSpec.describe ComplianceControl, type: :model do - it 'should have a valid factory' do - expect(FactoryGirl.build(:compliance_control)).to be_valid + + context 'standard validation' do + + let(:compliance_control) { build_stubbed :compliance_control } + + it 'should have a valid factory' do + expect(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' do + expect( build :compliance_control, name: '' ).to_not be_valid + end + it { should validate_presence_of :code } + it { should validate_presence_of :origin_code } + end - it { should belong_to :compliance_control_set } - it { should belong_to :compliance_control_block } + context 'validates that direct and indirect (via control_block) control_set are not different instances' do + + it 'not attached to control_block -> valid' do + compliance_control = create :compliance_control, compliance_control_block_id: nil + expect(compliance_control).to be_valid + end + + it 'attached to a control_block belonging to the same control_set -> valid' do + compliance_control_block = create :compliance_control_block + compliance_control = create :compliance_control, + compliance_control_block_id: compliance_control_block.id, + compliance_control_set_id: compliance_control_block.compliance_control_set.id # DO NOT change the last . to _ + # We need to be sure that is is not nil + expect(compliance_control).to be_valid + end - it { should validate_presence_of :criticity } - it { should validate_presence_of :name } - it { should validate_presence_of :code } + it 'attached to a control_block **not** belonging to the same control_set -> invalid' do + compliance_control_block = create :compliance_control_block + compliance_control = build :compliance_control, + compliance_control_block_id: compliance_control_block.id, + compliance_control_set_id: create( :compliance_control_set ).id + expect(compliance_control).to_not be_valid + + direct_name = compliance_control.compliance_control_set.name + indirect_name = compliance_control_block.compliance_control_set.name + expected_message = "Le contrôle ne peut pas être associé à un jeu de contrôle (id: #{direct_name}) différent de celui de son groupe (id: #{indirect_name})" + + selected_error_message = + compliance_control + .errors + .messages[:coherent_control_set] + .first + expect( selected_error_message ).to eq(expected_message) + end + end end diff --git a/spec/models/compliance_control_validations/genric_attribute_validation/min_max_validation_spec.rb b/spec/models/compliance_control_validations/genric_attribute_validation/min_max_validation_spec.rb new file mode 100644 index 000000000..276d09a92 --- /dev/null +++ b/spec/models/compliance_control_validations/genric_attribute_validation/min_max_validation_spec.rb @@ -0,0 +1,8 @@ +# RSpec.describe GenericAttributeControl::MinMax do + +# let( :factory ){ :generic_attribute_control_min_max } +# subject{ build factory } + +# it_behaves_like 'has min_max_values' + +# end diff --git a/spec/models/compliance_control_validations/genric_attribute_validation/pattern_validation_spec.rb b/spec/models/compliance_control_validations/genric_attribute_validation/pattern_validation_spec.rb new file mode 100644 index 000000000..f2814bfd4 --- /dev/null +++ b/spec/models/compliance_control_validations/genric_attribute_validation/pattern_validation_spec.rb @@ -0,0 +1,24 @@ +RSpec.describe GenericAttributeControl::Pattern do + + let( :factory ){ :generic_attribute_control_pattern } + subject{ build factory } + + context "is valid" do + it 'if the pattern contains a basic regex' do + subject.pattern = 'hel+o?' + expect_it.to be_valid + end + end + + context "is invalid" do + pending "Behavior to be defined" + # it 'if no pattern has been provided' do + # expect_it.not_to be_valid + # end + # it 'if the pattern is empty' do + # subject.pattern = ' ' + # expect_it.not_to be_valid + # end + + end +end diff --git a/spec/models/compliance_control_validations/vehicle_journey_validation/speed_validation_spec.rb b/spec/models/compliance_control_validations/vehicle_journey_validation/speed_validation_spec.rb new file mode 100644 index 000000000..88316ab37 --- /dev/null +++ b/spec/models/compliance_control_validations/vehicle_journey_validation/speed_validation_spec.rb @@ -0,0 +1,8 @@ +RSpec.describe VehicleJourneyControl::Speed do + + let( :factory ){ :vehicle_journey_control_speed } + subject{ build factory } + + it_behaves_like 'has min_max_values' + +end diff --git a/spec/models/line_referential_spec.rb b/spec/models/line_referential_spec.rb index 8472faaa0..8c6cb018b 100644 --- a/spec/models/line_referential_spec.rb +++ b/spec/models/line_referential_spec.rb @@ -12,7 +12,7 @@ RSpec.describe LineReferential, :type => :model do describe "#transport_modes" do it 'returns a list of all transport modes' do - expect(FactoryGirl.create(:line_referential).transport_modes).to eq( Chouette::TransportMode.all.select { |tm| tm.to_i > 0 } ) + expect(FactoryGirl.create(:line_referential).class.transport_modes).to match_array(StifTransportModeEnumerations.transport_modes ) end end end diff --git a/spec/models/organisation_spec.rb b/spec/models/organisation_spec.rb index b16324a56..1217666f7 100644 --- a/spec/models/organisation_spec.rb +++ b/spec/models/organisation_spec.rb @@ -6,10 +6,10 @@ describe Organisation, :type => :model do expect(FactoryGirl.build(:organisation)).to be_valid end - it "create a rule_parameter_set" do - organisation = create(:organisation) - expect(organisation.rule_parameter_sets.size).to eq(1) - end + # it "create a rule_parameter_set" do + # organisation = create(:organisation) + # expect(organisation.rule_parameter_sets.size).to eq(1) + # end describe "Portail sync" do let(:conf) { Rails.application.config.stif_portail_api } diff --git a/spec/models/vehicle_translation_spec.rb b/spec/models/vehicle_translation_spec.rb index d30cfa03e..4bbff7f49 100644 --- a/spec/models/vehicle_translation_spec.rb +++ b/spec/models/vehicle_translation_spec.rb @@ -9,7 +9,7 @@ describe VehicleTranslation, :type => :model do :journey_pattern => journey_pattern, :route => journey_pattern.route, # :company => company, - :transport_mode => Chouette::TransportMode.new("metro"), + :transport_mode => "metro", :published_journey_name => "dummy" )} subject {build(:vehicle_translation, diff --git a/spec/models/workbench_spec.rb b/spec/models/workbench_spec.rb index 84149ddb0..037537b60 100644 --- a/spec/models/workbench_spec.rb +++ b/spec/models/workbench_spec.rb @@ -11,6 +11,7 @@ RSpec.describe Workbench, :type => :model do it { should belong_to(:organisation) } it { should belong_to(:line_referential) } it { should belong_to(:stop_area_referential) } + it { should belong_to(:output).class_name('ReferentialSuite') } it { should have_many(:lines).through(:line_referential) } it { should have_many(:networks).through(:line_referential) } @@ -19,6 +20,15 @@ RSpec.describe Workbench, :type => :model do it { should have_many(:stop_areas).through(:stop_area_referential) } + it do + # This callback interferes with the validation test + Workbench.skip_callback(:validation, :before, :initialize_output) + + should validate_presence_of(:output) + + Workbench.set_callback(:validation, :before, :initialize_output) + end + context '.lines' do let!(:ids) { ['STIF:CODIFLIGNE:Line:C00840', 'STIF:CODIFLIGNE:Line:C00086'] } let!(:organisation) { create :organisation, sso_attributes: { functional_scope: ids.to_json } } @@ -33,4 +43,18 @@ RSpec.describe Workbench, :type => :model do expect(lines.map(&:objectid)).to include(*ids) end end + + describe ".create" do + it "must automatically create a ReferentialSuite when being created" do + workbench = Workbench.create + expect(workbench.output).to be_an_instance_of(ReferentialSuite) + end + + it "must not overwrite a given ReferentialSuite" do + referential_suite = create(:referential_suite) + workbench = create(:workbench, output: referential_suite) + + expect(workbench.output).to eq(referential_suite) + end + end end diff --git a/spec/policies/api_key_policy_spec.rb b/spec/policies/api_key_policy_spec.rb index f0242978e..3638a05b2 100644 --- a/spec/policies/api_key_policy_spec.rb +++ b/spec/policies/api_key_policy_spec.rb @@ -21,7 +21,7 @@ RSpec.describe ApiKeyPolicy do end context 'permission present → ' do it 'allows a user with a different organisation' do - add_permissions('api_keys.create', for_user: user) + add_permissions('api_keys.create', to_user: user) expect_it.to permit(user_context, record) end end @@ -40,7 +40,7 @@ RSpec.describe ApiKeyPolicy do context 'permission present → ' do before do - add_permissions('api_keys.update', for_user: user) + add_permissions('api_keys.update', to_user: user) end it 'denies a user with a different organisation' do diff --git a/spec/policies/import_policy_spec.rb b/spec/policies/import_policy_spec.rb new file mode 100644 index 000000000..fd9f3172c --- /dev/null +++ b/spec/policies/import_policy_spec.rb @@ -0,0 +1,41 @@ +RSpec.describe ImportPolicy, type: :policy do + + let( :record ){ build_stubbed :import } + before { stub_policy_scope(record) } + + # + # Non Destructive + # --------------- + + context 'Non Destructive actions →' do + permissions :index? do + it_behaves_like 'always allowed', 'anything', archived: true + end + permissions :show? do + it_behaves_like 'always allowed', 'anything', archived: true + end + end + + + # + # Destructive + # ----------- + + context 'Destructive actions →' do + permissions :create? do + it_behaves_like 'permitted policy', 'imports.create', archived: true + end + permissions :destroy? do + it_behaves_like 'permitted policy', 'imports.destroy', archived: true + end + permissions :edit? do + it_behaves_like 'permitted policy', 'imports.update', archived: true + end + permissions :new? do + it_behaves_like 'permitted policy', 'imports.create', archived: true + end + permissions :update? do + it_behaves_like 'permitted policy', 'imports.update', archived: true + end + end +end diff --git a/spec/policies/referential_policy_spec.rb b/spec/policies/referential_policy_spec.rb index 69d0eb17b..d00415fc6 100644 --- a/spec/policies/referential_policy_spec.rb +++ b/spec/policies/referential_policy_spec.rb @@ -9,7 +9,7 @@ RSpec.describe ReferentialPolicy, type: :policy do permissions :create? do it 'permissions present → allowed' do - add_permissions('referentials.create', for_user: user) + add_permissions('referentials.create', to_user: user) expect_it.to permit(user_context, record) end it 'permissions absent → forbidden' do @@ -19,7 +19,7 @@ RSpec.describe ReferentialPolicy, type: :policy do permissions :new? do it 'permissions present → allowed' do - add_permissions('referentials.create', for_user: user) + add_permissions('referentials.create', to_user: user) expect_it.to permit(user_context, record) end it 'permissions absent → forbidden' do @@ -53,7 +53,7 @@ RSpec.describe ReferentialPolicy, type: :policy do context 'permission present →' do before do - add_permissions('referentials.update', for_user: user) + add_permissions('referentials.update', to_user: user) end context 'same organisation →' do @@ -108,7 +108,7 @@ RSpec.describe ReferentialPolicy, type: :policy do context 'permission present →' do before do - add_permissions('referentials.update', for_user: user) + add_permissions('referentials.update', to_user: user) end context 'same organisation →' do diff --git a/spec/support/data_modifier.rb b/spec/support/data_modifier.rb new file mode 100644 index 000000000..2b3b00ac5 --- /dev/null +++ b/spec/support/data_modifier.rb @@ -0,0 +1,53 @@ +require_relative 'data_modifier/enum' +require_relative 'data_modifier/hash' +module Support + module DataModifier + module InstanceMethods + CannotModify = Class.new RuntimeError + + def advance_values(atts, *keys) + keys.inject(atts){ |h, k| h.merge( k => atts[k].next) } + end + + # return array of atts wich each value modified, unboxing + # values if needed + def modify_atts(base_atts) + base_atts.keys.map do | key | + modify_att base_atts, key + end.compact + end + + private + def modify_att atts, key + atts.merge(key => modify_value(atts[key])) + rescue CannotModify + nil + end + def modify_value value + case value + when String + "#{value}." + when Fixnum + value + 1 + when TrueClass + false + when FalseClass + true + when Float + value * 1.1 + when Date + value + 1.day + when Box + value.next.value + else + raise CannotModify + end + end + end + end +end + +RSpec.configure do | c | + c.include Support::DataModifier::InstanceMethods, type: :checksum + c.include Support::DataModifier::InstanceMethods, type: :model +end diff --git a/spec/support/data_modifier/bool.rb b/spec/support/data_modifier/bool.rb new file mode 100644 index 000000000..f4be9bd89 --- /dev/null +++ b/spec/support/data_modifier/bool.rb @@ -0,0 +1,18 @@ +require_relative 'box' + +module Support + module DataModifier + + class BoolBox + include Box + attr_reader :value + + def initialize value + @value = value + end + def next + self.class.new(!value) + end + end + end +end diff --git a/spec/support/data_modifier/box.rb b/spec/support/data_modifier/box.rb new file mode 100644 index 000000000..0847b628c --- /dev/null +++ b/spec/support/data_modifier/box.rb @@ -0,0 +1,21 @@ +require_relative 'hash' +module Support + module DataModifier + module Box + def next + raise "Need to implement #{__method__} in #{self.class}" + end + + class << self + def unbox atts + Hash.map_values(atts, method(:value_of)) + end + def value_of v + self === v ? v.value : v + end + end + end + + end +end + diff --git a/spec/support/data_modifier/enum.rb b/spec/support/data_modifier/enum.rb new file mode 100644 index 000000000..c8a6fe573 --- /dev/null +++ b/spec/support/data_modifier/enum.rb @@ -0,0 +1,19 @@ +require_relative 'box' + +module Support + module DataModifier + + class EnumBox + include Box + attr_reader :value, :values + + def initialize *enum_values + @values = enum_values + @value = @values.first + end + def next + self.class.new(*(@values[1..-1] << @values.first)) + end + end + end +end diff --git a/spec/support/data_modifier/hash.rb b/spec/support/data_modifier/hash.rb new file mode 100644 index 000000000..05da3cf4f --- /dev/null +++ b/spec/support/data_modifier/hash.rb @@ -0,0 +1,16 @@ +module Support + module DataModifier + module Hash extend self + def map_values hashy, f=nil, &fn + raise ArgumentError, "need block or function arg" unless f = fn || f + hashy.inject({}){ |h, (k,v)| h.merge(k => f.(v)) } + end + def first_values ary_hash + map_values(ary_hash, &:first) + end + def last_values ary_hash + map_values(ary_hash, &:last) + end + end + end +end diff --git a/spec/support/permissions.rb b/spec/support/permissions.rb index 467c07a32..7d09e16cb 100644 --- a/spec/support/permissions.rb +++ b/spec/support/permissions.rb @@ -13,18 +13,22 @@ module Support def _permitted_resources %w[ - api_keys - access_points - connection_links - calendars - footnotes - journey_patterns - referentials - routes - routing_constraint_zones - time_tables - vehicle_journeys - compliance_controls + access_points + connection_links + calendars + footnotes + imports + journey_patterns + referentials + routes + routing_constraint_zones + time_tables + vehicle_journeys + api_keys + compliance_controls + compliance_controls_sets + compliance_controls_blocks + compliance_check_sets ] end end diff --git a/spec/support/pundit/policies.rb b/spec/support/pundit/policies.rb index d5bb63243..a3489d9db 100644 --- a/spec/support/pundit/policies.rb +++ b/spec/support/pundit/policies.rb @@ -3,18 +3,18 @@ require 'pundit/rspec' module Support module Pundit module Policies - def add_permissions(*permissions, for_user:) - for_user.permissions ||= [] - for_user.permissions += permissions.flatten + def add_permissions(*permissions, to_user:) + to_user.permissions ||= [] + to_user.permissions += permissions.flatten end def create_user_context(user:, referential:) UserContext.new(user, referential: referential) end - def add_permissions(*permissions, for_user:) - for_user.permissions ||= [] - for_user.permissions += permissions.flatten + def remove_permissions(*permissions, from_user:, save: false) + from_user.permissions -= permissions.flatten + from_user.save! if save end end @@ -30,7 +30,7 @@ module Support end def with_user_permission(permission, &blk) it "with user permission #{permission.inspect}" do - add_permissions(permission, for_user: user) + add_permissions(permission, to_user: user) blk.() end end @@ -41,7 +41,7 @@ module Support perms, options = permissions.partition{|x| String === x} context "with permissions #{perms.inspect}...", *options do before do - add_permissions(*permissions, for_user: @user) + add_permissions(*permissions, to_user: @user) end instance_eval(&blk) end @@ -51,6 +51,7 @@ module Support end RSpec.configure do | c | + c.include Support::Pundit::Policies, type: :controller c.include Support::Pundit::Policies, type: :policy c.extend Support::Pundit::PoliciesMacros, type: :policy c.include Support::Pundit::Policies, type: :feature diff --git a/spec/support/pundit/shared_examples.rb b/spec/support/pundit/shared_examples.rb index 63a106759..49c6845da 100644 --- a/spec/support/pundit/shared_examples.rb +++ b/spec/support/pundit/shared_examples.rb @@ -18,7 +18,7 @@ RSpec.shared_examples 'always allowed' do context 'different organisations →' do before do - add_permissions(permission, for_user: user) + add_permissions(permission, to_user: user) end it "allows a user with a different organisation" do expect_it.to permit(user_context, record) @@ -51,7 +51,7 @@ RSpec.shared_examples 'always forbidden' do context 'different organisations →' do before do - add_permissions(permission, for_user: user) + add_permissions(permission, to_user: user) end it "denies a user with a different organisation" do expect_it.not_to permit(user_context, record) @@ -80,7 +80,7 @@ RSpec.shared_examples 'permitted policy and same organisation' do context 'permission present → ' do before do - add_permissions(permission, for_user: user) + add_permissions(permission, to_user: user) end it 'denies a user with a different organisation' do @@ -113,7 +113,7 @@ RSpec.shared_examples 'permitted policy' do context 'permission present → ' do before do - add_permissions(permission, for_user: user) + add_permissions(permission, to_user: user) end it 'allows user' do diff --git a/spec/support/random.rb b/spec/support/random.rb new file mode 100644 index 000000000..59e1a1475 --- /dev/null +++ b/spec/support/random.rb @@ -0,0 +1,30 @@ +module Support + module Random + + PRETTY_LARGE_INT = 1 << 30 + + def random_hex + SecureRandom.hex + end + + def random_element from + from[random_int(from.size)] + end + + def random_int max_plus_one=PRETTY_LARGE_INT + (random_number * max_plus_one).to_i + end + + def random_number + SecureRandom.random_number + end + + def random_string + SecureRandom.urlsafe_base64 + end + end +end + +RSpec.configure do | c | + c.include Support::Random +end diff --git a/spec/support/referential.rb b/spec/support/referential.rb index 3b74cb639..6f60bd86b 100644 --- a/spec/support/referential.rb +++ b/spec/support/referential.rb @@ -52,8 +52,21 @@ RSpec.configure do |config| referential.add_member organisation, owner: true end - 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 + workbench = FactoryGirl.create( + :workbench, + name: "Gestion de l'offre", + organisation: organisation, + line_referential: line_referential, + stop_area_referential: stop_area_referential + ) + referential = FactoryGirl.create( + :referential, + prefix: "first", + name: "first", + slug: "first", + organisation: organisation, + workbench: workbench + ) end config.before(:each) do diff --git a/spec/support/shared_examples/compliance_control_class_level_defaults.rb b/spec/support/shared_examples/compliance_control_class_level_defaults.rb new file mode 100644 index 000000000..276ac1ca5 --- /dev/null +++ b/spec/support/shared_examples/compliance_control_class_level_defaults.rb @@ -0,0 +1,42 @@ +require_relative '../data_modifier' + +H = Support::DataModifier::Hash +RSpec.shared_examples_for 'ComplianceControl Class Level Defaults' do + context 'class attributes' do + it 'are correctly set' do + expect( described_class.default_code).to eq(default_code) + end + end + context 'are used in instantiation' do + let( :record ){ create factory } + let( :default_att_names ){%w[ code origin_code ]} + + it 'all defaults' do + expect( record.attributes.values_at(*default_att_names )) + .to eq([ default_code, default_code]) + end + it 'but provided values are not overwritten by defaults' do + code = random_string + origin_code = random_string + # Remove each of the attributes from explicit initialisation to see + # its value provided by CCCWDA. + + # atts :: Map(String, (explicit_value, default_value)) + atts = { + 'code' => [code, default_code], + 'origin_code' => [origin_code, default_code], + } + atts.keys.each do |key| + # Replace key to be tested by default value + expected = H.first_values(atts).merge(key => atts[key].last) + expected_values = expected.values_at(*default_att_names) + # Remove key to be tested from atts passed to `#create` + construction_atts = H.first_values(atts).merge(key => nil).compact + explicit = create factory, construction_atts + + expect( explicit.attributes.values_at(*default_att_names )) + .to eq(expected_values) + end + end + end + end diff --git a/spec/support/shared_examples/compliance_control_validation.rb b/spec/support/shared_examples/compliance_control_validation.rb new file mode 100644 index 000000000..d4ab9f41d --- /dev/null +++ b/spec/support/shared_examples/compliance_control_validation.rb @@ -0,0 +1,43 @@ +RSpec.shared_examples_for 'has min_max_values' do + + context "is valid" do + it 'if no value is provided' do + expect_it.to be_valid + end + it 'if minimum is provided alone' do + subject.minimum = 42 + expect_it.to be_valid + end + it 'if maximum is provided alone' do + subject.maximum = 42 + expect_it.to be_valid + end + + it 'if maximum is not smaller than minimum' do + 100.times do + min = random_int + max = min + random_int(20) + subject.assign_attributes maximum: max, minimum: min + subject.assign_attributes maximum: min, minimum: min + expect_it.to be_valid + end + end + end + + context "is invalid" do + it 'if maximum is smaller than minimum' do + 100.times do + min = random_int + max = min - random_int(20) - 1 + subject.assign_attributes maximum: max, minimum: min + expect_it.not_to be_valid + end + end + + it 'and has a correct error message' do + subject.assign_attributes maximum: 1, minimum: 2 + expect_it.not_to be_valid + expect( subject.errors.messages[:min_max_values].first ).to match("la valeur de minimum (2) ne doit pas être superieur à la valuer du maximum (1)") + end + end +end diff --git a/spec/teaspoon_env.rb b/spec/teaspoon_env.rb index d9dd2cc47..da6697b28 100644 --- a/spec/teaspoon_env.rb +++ b/spec/teaspoon_env.rb @@ -10,11 +10,11 @@ Teaspoon.configure do |config| # Paths that will be appended to the Rails assets paths # Note: Relative to `config.root`. - config.asset_paths = ["spec/javascripts", "spec/javascripts/stylesheets"] + config.asset_paths = ["spec/javascript", "spec/javascript/stylesheets"] # Fixtures are rendered through a controller, which allows using HAML, RABL/JBuilder, etc. Files in these paths will # be rendered as fixtures. - config.fixture_paths = ["spec/javascripts/fixtures"] + config.fixture_paths = ["spec/javascript/fixtures"] # SUITES # @@ -38,7 +38,7 @@ Teaspoon.configure do |config| # Specify a file matcher as a regular expression and all matching files will be loaded when the suite is run. These # files need to be within an asset path. You can add asset paths using the `config.asset_paths`. - suite.matcher = "{spec/javascripts,app/assets}/**/*_spec.{js,js.coffee,coffee}" + suite.matcher = "{spec/javascript,app/javascript}/**/*_spec.{js,js.coffee,coffee}" # Load additional JS files, but requiring them in your spec helper is the preferred way to do this. #suite.javascripts = [] diff --git a/spec/views/vehicle_journeys/_form.html.erb_spec.rb b/spec/views/vehicle_journeys/_form.html.erb_spec.rb index bf25c8092..250da9567 100644 --- a/spec/views/vehicle_journeys/_form.html.erb_spec.rb +++ b/spec/views/vehicle_journeys/_form.html.erb_spec.rb @@ -7,14 +7,14 @@ describe "/vehicle_journeys/_form", :type => :view do let!(:route) { assign :route, create(:route, :line => line) } let!(:vehicle_journey) { assign :vehicle_journey, create(:vehicle_journey, :route => route) } - it "should render an input for transport_mode" do + xit "should render an input for transport_mode" do render partial: 'vehicle_journeys/form', locals: { vehicle_journey: vehicle_journey, form_url: referential_line_route_vehicle_journeys_path(referential, line, route, vehicle_journey) } expect(rendered).to have_selector( "select#vehicle_journey_transport_mode") do |node| - line.transport_modes.each do |mode| + line.class.transport_modes.each do |mode| expect(node).to have_selector("option", :text => mode.text_code) end end diff --git a/spec/workers/line_referential_sync_worker_spec.rb b/spec/workers/line_referential_sync_worker_spec.rb index f1a63c9db..f8d7eed91 100644 --- a/spec/workers/line_referential_sync_worker_spec.rb +++ b/spec/workers/line_referential_sync_worker_spec.rb @@ -1,4 +1,3 @@ -require 'rails_helper' RSpec.describe LineReferentialSyncWorker, type: :worker do let!(:line_referential_sync) { create :line_referential_sync } |
