diff options
| author | cedricnjanga | 2017-11-22 10:20:03 +0100 |
|---|---|---|
| committer | cedricnjanga | 2017-11-22 10:20:03 +0100 |
| commit | eec1d9e43509a1677d346584ee24cd3ee6f8c124 (patch) | |
| tree | 5ea0ffc28a65f7178e5f11ae19cff353139d3159 /spec | |
| parent | 577204834de4dfcd1851fc9b5f85558eaa141a89 (diff) | |
| parent | f01e81604053e9cbdaf4b84534214e37fbfcae5e (diff) | |
| download | chouette-core-eec1d9e43509a1677d346584ee24cd3ee6f8c124.tar.bz2 | |
Merge branch 'master' into 4941-refactoring_object_id
Diffstat (limited to 'spec')
| -rw-r--r-- | spec/controllers/compliance_check_sets_controller_spec.rb | 4 | ||||
| -rw-r--r-- | spec/controllers/rule_parameter_sets_controller_spec.rb | 36 | ||||
| -rw-r--r-- | spec/db/schema_spec.rb | 49 | ||||
| -rw-r--r-- | spec/factories/compliance_control_blocks.rb | 3 | ||||
| -rw-r--r-- | spec/factories/netex_imports.rb | 2 | ||||
| -rw-r--r-- | spec/factories/rule_parameter_sets.rb | 9 | ||||
| -rw-r--r-- | spec/features/compliance_check_sets_spec.rb | 110 | ||||
| -rw-r--r-- | spec/features/compliance_control_sets_spec.rb | 16 | ||||
| -rw-r--r-- | spec/models/compliance_check_block_spec.rb | 17 | ||||
| -rw-r--r-- | spec/models/compliance_control_block_spec.rb | 17 | ||||
| -rw-r--r-- | spec/models/import/netex_import_spec.rb | 33 | ||||
| -rw-r--r-- | spec/models/import_spec.rb | 16 | ||||
| -rw-r--r-- | spec/models/line_referential_spec.rb | 9 | ||||
| -rw-r--r-- | spec/models/netex_import_spec.rb | 39 | ||||
| -rw-r--r-- | spec/models/rule_parameter_set_spec.rb | 49 | ||||
| -rw-r--r-- | spec/support/breadcrumb_features.rb | 15 | ||||
| -rw-r--r-- | spec/support/webmock/helpers.rb | 5 | ||||
| -rw-r--r-- | spec/support/with_commit.rb | 10 | ||||
| -rw-r--r-- | spec/views/rule_parameter_sets/new.html.erb_spec.rb | 27 |
19 files changed, 313 insertions, 153 deletions
diff --git a/spec/controllers/compliance_check_sets_controller_spec.rb b/spec/controllers/compliance_check_sets_controller_spec.rb index 804b0a658..3ddb1dad1 100644 --- a/spec/controllers/compliance_check_sets_controller_spec.rb +++ b/spec/controllers/compliance_check_sets_controller_spec.rb @@ -5,9 +5,9 @@ RSpec.describe ComplianceCheckSetsController, type: :controller do let(:compliance_check_set) { create :compliance_check_set } - describe "GET show" do + describe "GET executed" do it 'should be successful' do - get :show, workbench_id: compliance_check_set.workbench.id, id: compliance_check_set.id + get :executed, workbench_id: compliance_check_set.workbench.id, id: compliance_check_set.id expect(response).to be_success end end diff --git a/spec/controllers/rule_parameter_sets_controller_spec.rb b/spec/controllers/rule_parameter_sets_controller_spec.rb deleted file mode 100644 index 0f57855b7..000000000 --- a/spec/controllers/rule_parameter_sets_controller_spec.rb +++ /dev/null @@ -1,36 +0,0 @@ -# require 'spec_helper' - -# 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 - # expect(assigns[:organisation]).to eq(assigns[:organisation].rule_parameter_sets[0].organisation) - # 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 - # get :new - # end - # it_behaves_like "organisation dependant" - # it "should assign rule_parameter_set with default params" do - # RuleParameterSet.default_params.each do |k,v| - # expect(assigns[:rule_parameter_set].send( k )).to eq(v) - # end - # end - # end -# end diff --git a/spec/db/schema_spec.rb b/spec/db/schema_spec.rb new file mode 100644 index 000000000..a7fe0a162 --- /dev/null +++ b/spec/db/schema_spec.rb @@ -0,0 +1,49 @@ +RSpec.describe ActiveRecord::Schema do + it "uses type `bigint` for primary and foreign keys" do + expect('db/schema.rb').to use_bigint_keys + end +end + + +RSpec::Matchers.define :use_bigint_keys do + match do |filename| + @original = "" + @expected = "" + + File.open(filename, 'r') do |f| + f.each_line do |line| + expected_line = line + + # Primary key + if line =~ /create_table\s/ && + !(line =~ /id: \s+ (?: :bigserial | false)/x) + expected_line = line.sub(/(create_table\s"\w+",\s)/, '\1id: :bigserial, ') + end + + # Foreign key + if line =~ /t\.integer\s+"\w+_id"/ && + !(line =~ /limit: 8/) + expected_line = line.sub(/(t.integer\s+"\w+")/, '\1, limit: 8') + end + + @original += line + @expected += expected_line + end + end + + @original == @expected + end + + failure_message do |filename| + <<-EOS +expected #{filename.inspect} to use bigint keys +Diff: #{diff} + EOS + end + + def diff + RSpec::Support::Differ.new( + color: RSpec::Matchers.configuration.color? + ).diff_as_string(@original, @expected) + end +end diff --git a/spec/factories/compliance_control_blocks.rb b/spec/factories/compliance_control_blocks.rb index 4785d8419..94773d4b3 100644 --- a/spec/factories/compliance_control_blocks.rb +++ b/spec/factories/compliance_control_blocks.rb @@ -1,7 +1,8 @@ FactoryGirl.define do factory :compliance_control_block do sequence(:name) { |n| "Compliance control block #{n}" } - transport_mode "air" + transport_mode StifTransportModeEnumerations.transport_modes.first + transport_submode StifTransportSubmodeEnumerations.transport_submodes.first association :compliance_control_set end end diff --git a/spec/factories/netex_imports.rb b/spec/factories/netex_imports.rb index 9e9d836e4..b59267a0a 100644 --- a/spec/factories/netex_imports.rb +++ b/spec/factories/netex_imports.rb @@ -1,5 +1,7 @@ FactoryGirl.define do factory :netex_import, class: NetexImport, parent: :import do file { File.open(Rails.root.join('spec', 'fixtures', 'OFFRE_TRANSDEV_2017030112251.zip')) } + association :parent, factory: :workbench_import + end end diff --git a/spec/factories/rule_parameter_sets.rb b/spec/factories/rule_parameter_sets.rb deleted file mode 100644 index e20fff8ce..000000000 --- a/spec/factories/rule_parameter_sets.rb +++ /dev/null @@ -1,9 +0,0 @@ -FactoryGirl.define do - factory :rule_parameter_set do - sequence(:name) { |n| "Test #{n}" } - association :organisation - after(:create) do |rsp| - rsp.parameters = RuleParameterSet.default_for_all_modes( rsp.organisation).parameters - end - end -end diff --git a/spec/features/compliance_check_sets_spec.rb b/spec/features/compliance_check_sets_spec.rb new file mode 100644 index 000000000..7ba64b6b8 --- /dev/null +++ b/spec/features/compliance_check_sets_spec.rb @@ -0,0 +1,110 @@ +require 'rails_helper' + +RSpec.describe "ComplianceCheckSets", type: :feature do + + include ComplianceCheckSetsHelper + include TransportModeHelper + + login_user + + # We setup a control_set with two blocks and one direct control (meaning that it is not attached to a block) + # Then we add one control to the first block and two controls to the second block + let( :compliance_check_set ){ create :compliance_check_set, name: random_string } + let(:blox){[ + create( :compliance_check_block, + compliance_check_set: compliance_check_set, transport_mode: 'bus', transport_submode: 'demandAndResponseBus'), + create( :compliance_check_block, + compliance_check_set: compliance_check_set, transport_mode: 'rail', transport_submode: 'suburbanRailway') + ]} + let!(:direct_checks){ make_check(nil, times: 2) + make_check(nil, severity: :error) } + let!(:indirect_checks){ blox.flat_map{ |block| make_check(block) } } + let( :all_checks ){ direct_checks + indirect_checks } + + + context 'executed' do + + before do + visit(executed_compliance_check_set_path(compliance_check_set)) + end + + it 'we can see the expected content' do + # Breadcrumbs + expect_breadcrumb_links "Accueil", "Gestion de l'offre", "Liste des jeux de contrôles" + + # Headline + expect( page ).to have_content("Jeu de contrôles exécutés #{compliance_check_set.name}") + + # Information Definition List + expect( page.first('.dl-term') ).to have_content("Nom") + expect( page.first('.dl-def') ).to have_content(compliance_check_set.name) + + # Filters + within( 'form.form-filter' ) do + expect( page ).to have_content("Groupe de contrôle") + expect( page ).to have_content("Objet") + expect( page ).to have_content("Criticité") + end + + # Checks + # Direct Children + within(:xpath, xpath_for_div_of_block) do + direct_checks.each do | direct_check | + expect( page ).to have_content( direct_check.code ) + expect( page ).to have_content( direct_check.name ) + expect( page ).to have_content( direct_check.criticity ) + expect( page ).to have_content( direct_check.comment ) + end + + end + # Indirect Children + compliance_check_set.compliance_check_blocks.each do | block | + within(:xpath, xpath_for_div_of_block(block)) do + block.compliance_checks.each do | check | + expect( page ).to have_content( check.code ) + expect( page ).to have_content( check.name ) + expect( page ).to have_content( check.criticity ) + expect( page ).to have_content( check.comment ) + end + end + end + end + + it 'can filter the results and remove the filter' do + # Filter + check('error') + click_on('Filtrer') + all_checks.each do | check | + if check.criticity == 'error' + expect( page ).to have_content(check.code) + else + expect( page ).not_to have_content(check.code) + end + end + + # Remove filter + click_on('Effacer') + all_checks.each do | check | + expect( page ).to have_content(check.code) + end + + end + end + + def make_check ccblock=nil, times: 1, severity: :warning + times.times.map do + make_one_check ccblock, severity + end + end + + def make_one_check ccblock, severity + create( :compliance_check, + code: random_string, + compliance_check_block: ccblock, + compliance_check_set: compliance_check_set, + criticity: severity) + end + + def xpath_for_div_of_block(block = nil) + %{.//div[@class="col-lg-12"]/h2[contains(text(),"#{transport_mode_text(block)}")]/../../..} + end +end diff --git a/spec/features/compliance_control_sets_spec.rb b/spec/features/compliance_control_sets_spec.rb index 500d4ce6f..bcb989cdc 100644 --- a/spec/features/compliance_control_sets_spec.rb +++ b/spec/features/compliance_control_sets_spec.rb @@ -25,7 +25,18 @@ RSpec.describe "ComplianceControlSets", type: :feature do visit compliance_control_set_path( control_set ) end - it 'we can see the controls inside their blocks' do + it 'we can see the expected content' do + # Breadcrumb + expect_breadcrumb_links "Accueil", "Liste des jeux de contrôles" + + # Headline + expect( page ).to have_content("Consulter le jeu de contrôles #{control_set.name}") + + # Information Definition List + expect( page.first('.dl-term') ).to have_content("Nom") + expect( page.first('.dl-def') ).to have_content(control_set.name) + + # Children controls.each do | control | expect( page ).to have_content(control.code) end @@ -76,7 +87,8 @@ RSpec.describe "ComplianceControlSets", type: :feature do create( :generic_attribute_control_min_max, code: random_string, compliance_control_block: ccblock, - compliance_control_set: control_set) + compliance_control_set: control_set, + criticity: severity) end end diff --git a/spec/models/compliance_check_block_spec.rb b/spec/models/compliance_check_block_spec.rb index a3d98d459..0629a645d 100644 --- a/spec/models/compliance_check_block_spec.rb +++ b/spec/models/compliance_check_block_spec.rb @@ -1,10 +1,17 @@ -require 'rails_helper' - RSpec.describe ComplianceCheckBlock, type: :model do - it 'should have a valid factory' do - expect(FactoryGirl.build(:compliance_check_block)).to be_valid - end it { should belong_to :compliance_check_set } it { should have_many :compliance_checks } + + it { should allow_values(*%w{bus metro rail tram funicular}).for(:transport_mode) } + it { should_not allow_values(*%w{bs mtro ril tramm Funicular}).for(:transport_mode) } + + + it { should allow_values( *%w{ demandAndResponseBus nightBus airportLinkBus highFrequencyBus expressBus + railShuttle suburbanRailway regionalRail interregionalRail }) + .for(:transport_submode) } + + it { should_not allow_values( *%w{ demandResponseBus nightus irportLinkBus highrequencyBus expressBUs + Shuttle suburban regioalRail interregion4lRail }) + .for(:transport_submode) } end diff --git a/spec/models/compliance_control_block_spec.rb b/spec/models/compliance_control_block_spec.rb index c7440a5eb..4abe0ed9c 100644 --- a/spec/models/compliance_control_block_spec.rb +++ b/spec/models/compliance_control_block_spec.rb @@ -1,13 +1,20 @@ 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) } + + it { should allow_values(*%w{bus metro rail tram funicular}).for(:transport_mode) } + it { should_not allow_values(*%w{bs mtro ril tramm Funicular}).for(:transport_mode) } + + + it { should allow_values( *%w{ demandAndResponseBus nightBus airportLinkBus highFrequencyBus expressBus + railShuttle suburbanRailway regionalRail interregionalRail }) + .for(:transport_submode) } + + it { should_not allow_values( *%w{ demandResponseBus nightus irportLinkBus highrequencyBus expressBUs + Shuttle suburban regioalRail interregion4lRail }) + .for(:transport_submode) } end diff --git a/spec/models/import/netex_import_spec.rb b/spec/models/import/netex_import_spec.rb new file mode 100644 index 000000000..8ffeed1f4 --- /dev/null +++ b/spec/models/import/netex_import_spec.rb @@ -0,0 +1,33 @@ +RSpec.describe NetexImport, type: [:model, :with_commit] do + + let( :boiv_iev_uri ){ URI("#{Rails.configuration.iev_url}/boiv_iev/referentials/importer/new?id=#{subject.id}")} + + + before do + allow(Thread).to receive(:new).and_yield + end + + context 'with referential' do + subject{ build( :netex_import, id: random_int ) } + + it 'will trigger the Java API' do + with_stubbed_request(:get, boiv_iev_uri) do |request| + with_commit{ subject.save! } + expect(request).to have_been_requested + end + end + end + + context 'without referential' do + subject { build :netex_import, referential_id: nil } + + it 'its status is forced to aborted and the Java API is not callled' do + with_stubbed_request(:get, boiv_iev_uri) do |request| + with_commit{ subject.save! } + expect(subject.reload.status).to eq('aborted') + expect(request).not_to have_been_requested + end + end + end + +end diff --git a/spec/models/import_spec.rb b/spec/models/import_spec.rb index 7be05908a..4e8aac3f4 100644 --- a/spec/models/import_spec.rb +++ b/spec/models/import_spec.rb @@ -13,9 +13,9 @@ RSpec.describe Import, type: :model do it { should allow_value('file.zip').for(:file).with_message(I18n.t('activerecord.errors.models.import.attributes.file.wrong_file_extension')) } it { should_not allow_values('file.json', 'file.png', 'file.pdf').for(:file) } - let(:workbench_import) { build_stubbed(:workbench_import) } + let(:workbench_import) {netex_import.parent} let(:workbench_import_with_completed_steps) do - workbench_import = build_stubbed( + build_stubbed( :workbench_import, total_steps: 2, current_step: 2 @@ -23,20 +23,18 @@ RSpec.describe Import, type: :model do end let(:netex_import) do - netex_import = build_stubbed( - :netex_import, - parent: workbench_import + build_stubbed( + :netex_import ) end describe "#destroy" do it "must destroy all child imports" do - workbench_import = create(:workbench_import) - create(:netex_import, parent: workbench_import) + netex_import = create(:netex_import) - workbench_import.destroy + netex_import.parent.destroy - expect(workbench_import).to be_destroyed + expect(netex_import.parent).to be_destroyed expect(NetexImport.count).to eq(0) end diff --git a/spec/models/line_referential_spec.rb b/spec/models/line_referential_spec.rb index ea83c0ebd..46434a7ab 100644 --- a/spec/models/line_referential_spec.rb +++ b/spec/models/line_referential_spec.rb @@ -1,6 +1,4 @@ -require 'spec_helper' - -RSpec.describe LineReferential, :type => :model do +RSpec.describe LineReferential, type: :model do it 'should have a valid factory' do expect(FactoryGirl.build(:line_referential)).to be_valid end @@ -11,9 +9,4 @@ RSpec.describe LineReferential, :type => :model do it { should validate_presence_of(:sync_interval) } it { should validate_presence_of(:objectid_format) } - describe "#transport_modes" do - it 'returns a list of all transport modes' do - expect(FactoryGirl.create(:line_referential).class.transport_modes).to match_array(StifTransportModeEnumerations.transport_modes ) - end - end end diff --git a/spec/models/netex_import_spec.rb b/spec/models/netex_import_spec.rb new file mode 100644 index 000000000..c6051a869 --- /dev/null +++ b/spec/models/netex_import_spec.rb @@ -0,0 +1,39 @@ +RSpec.describe NetexImport, type: :model do + describe "#destroy" do + it "must destroy its associated Referential if ready: false" do + workbench_import = create(:workbench_import) + referential_ready_false = create(:referential, ready: false) + referential_ready_true = create(:referential, ready: true) + create( + :netex_import, + parent: workbench_import, + referential: referential_ready_false + ) + create( + :netex_import, + parent: workbench_import, + referential: referential_ready_true + ) + + workbench_import.destroy + + expect( + Referential.where(id: referential_ready_false.id).exists? + ).to be false + expect( + Referential.where(id: referential_ready_true.id).exists? + ).to be true + end + + it "doesn't try to destroy nil referentials" do + workbench_import = create(:workbench_import) + create( + :netex_import, + parent: workbench_import, + referential: nil + ) + + expect { workbench_import.destroy }.not_to raise_error + end + end +end diff --git a/spec/models/rule_parameter_set_spec.rb b/spec/models/rule_parameter_set_spec.rb deleted file mode 100644 index 71ab0cddd..000000000 --- a/spec/models/rule_parameter_set_spec.rb +++ /dev/null @@ -1,49 +0,0 @@ -# require 'spec_helper' - -# describe RuleParameterSet, :type => :model do - -# describe ".mode_of_mode_attribute" do -# it "should retreive attribute name" do -# expect(subject.class.attribute_of_mode_attribute("dummy1_mode_dummy2")).to eq("dummy1") -# end -# it "should retreive mode" do -# expect(subject.class.mode_of_mode_attribute("dummy1_mode_dummy2")).to eq("dummy2") -# end -# end - -# RuleParameterSet.mode_attribute_prefixes.each do |prefix| -# RuleParameterSet.all_modes.map do |mode| -# "#{prefix}_mode_#{mode}".tap do |attribute| -# describe "##{attribute}=" do -# it "should store value on parameters hash" do -# subject.send( "#{attribute}=".to_sym, 1234) -# expect(subject.send( attribute.to_sym)).to eq(1234) -# expect(subject.parameters["mode_#{mode}"][ prefix]).to eq(1234) -# end -# end -# it { is_expected.to allow_mass_assignment_of attribute.to_sym} -# end -# end -# end - -# RuleParameterSet.general_attributes.each do |attribute| -# describe "##{attribute}=" do -# it "should store value on parameters hash" do -# subject.send( "#{attribute}=".to_sym, 1234) -# expect(subject.send( attribute.to_sym)).to eq(1234) -# expect(subject.parameters[ attribute]).to eq(1234) -# end -# end -# it { is_expected.to allow_mass_assignment_of attribute.to_sym} -# end - -# describe "#referential" do -# it { is_expected.to validate_presence_of(:referential) } -# it { is_expected.to allow_mass_assignment_of :referential_id } -# end - -# describe "#name" do -# it { is_expected.to validate_presence_of(:name) } -# it { is_expected.to allow_mass_assignment_of :name } -# end -# end diff --git a/spec/support/breadcrumb_features.rb b/spec/support/breadcrumb_features.rb new file mode 100644 index 000000000..36bfce19c --- /dev/null +++ b/spec/support/breadcrumb_features.rb @@ -0,0 +1,15 @@ +module BreadcrumbFeatures + def expect_breadcrumb_links *link_names + within('.breadcrumbs') do + all('a').zip( link_names ).each do | link_element, link_content | + within(link_element) do | | + expect(page).to have_content(link_content) + end + end + end + end +end + +RSpec.configure do | conf | + conf.include BreadcrumbFeatures, type: :feature +end diff --git a/spec/support/webmock/helpers.rb b/spec/support/webmock/helpers.rb index fc6c77850..a6506c035 100644 --- a/spec/support/webmock/helpers.rb +++ b/spec/support/webmock/helpers.rb @@ -8,6 +8,11 @@ module Support def make_headers(headers={}, authorization_token:) headers.merge('Authorization' => "Token token=#{authorization_token.inspect}") end + + def with_stubbed_request( method, uri, &blk ) + stub_request(method, uri).tap(&blk) + end + end end end diff --git a/spec/support/with_commit.rb b/spec/support/with_commit.rb new file mode 100644 index 000000000..2b4725f89 --- /dev/null +++ b/spec/support/with_commit.rb @@ -0,0 +1,10 @@ +module WithCommit + def with_commit + yield + subject._run_commit_callbacks + end +end + +RSpec.configure do |conf| + conf.include WithCommit, type: :with_commit +end diff --git a/spec/views/rule_parameter_sets/new.html.erb_spec.rb b/spec/views/rule_parameter_sets/new.html.erb_spec.rb deleted file mode 100644 index 6f44311d5..000000000 --- a/spec/views/rule_parameter_sets/new.html.erb_spec.rb +++ /dev/null @@ -1,27 +0,0 @@ -require 'spec_helper' - -describe "/rule_parameter_sets/new", :type => :view do - - assign_organisation - let!(:organisation) { create(:organisation) } - let!(:rule_parameter_set) { assign :rule_parameter_set, build( :rule_parameter_set, :organisation => organisation) } - - describe "form" do - - xit "should render input for name" do - render - expect(rendered).to have_selector("form") do - with_selector "input[type=text][name=?]", rule_parameter_set.name - end - end - xit "should render input div for added_mode_parameter_set" do - render - expect(rendered).to have_selector("form") do - with_selector "#added_mode_parameter_set" - end - end - - end - -end - |
