diff options
| author | cedricnjanga | 2017-11-13 18:17:21 +0100 |
|---|---|---|
| committer | cedricnjanga | 2017-11-13 18:17:21 +0100 |
| commit | c1c2d2b8b8a2bbedcb0af1c8780839690ff8b2ad (patch) | |
| tree | b6dd8483122581e25acc4c6ed340d92bc9ad6a8a /spec | |
| parent | dca27ca43414267d316c40071d542435182ea464 (diff) | |
| parent | 96afaed78fa043449c0264ea09f0106147755c8e (diff) | |
| download | chouette-core-c1c2d2b8b8a2bbedcb0af1c8780839690ff8b2ad.tar.bz2 | |
Merge branch 'master' into staging
Diffstat (limited to 'spec')
| -rw-r--r-- | spec/controllers/api/v1/compliance_check_sets_controller_spec.rb | 37 | ||||
| -rw-r--r-- | spec/factories/chouette_route_sections.rb | 6 | ||||
| -rw-r--r-- | spec/models/chouette/route_section_spec.rb | 93 | ||||
| -rw-r--r-- | spec/models/compliance_check_set_spec.rb | 77 | ||||
| -rw-r--r-- | spec/models/route_sections_selector_spec.rb | 43 | ||||
| -rw-r--r-- | spec/policies/compliance_control_block_policy_spec.rb | 19 | ||||
| -rw-r--r-- | spec/policies/compliance_control_set_policy_spec.rb | 8 | ||||
| -rw-r--r-- | spec/support/permissions.rb | 4 |
8 files changed, 139 insertions, 148 deletions
diff --git a/spec/controllers/api/v1/compliance_check_sets_controller_spec.rb b/spec/controllers/api/v1/compliance_check_sets_controller_spec.rb new file mode 100644 index 000000000..1c3784807 --- /dev/null +++ b/spec/controllers/api/v1/compliance_check_sets_controller_spec.rb @@ -0,0 +1,37 @@ +RSpec.describe Api::V1::ComplianceCheckSetsController, type: :controller do + include_context 'iboo authenticated api user' + + describe "POST #validate" do + let(:check_set) { create(:compliance_check_set) } + + it "calls #update_status on the ComplianceCheckSet" do + expect_any_instance_of(ComplianceCheckSet).to receive(:update_status) + + patch :validated, id: check_set.id + end + + context "responds with" do + render_views + + it "object JSON on #update_status true" do + allow_any_instance_of( + ComplianceCheckSet + ).to receive(:update_status).and_return(true) + + patch :validated, id: check_set.id + + expect(JSON.parse(response.body)['id']).to eq(check_set.id) + end + + it "error JSON on #update_status false" do + allow_any_instance_of( + ComplianceCheckSet + ).to receive(:update_status).and_return(false) + + patch :validated, id: check_set.id + + expect(response.body).to include('error') + end + end + end +end diff --git a/spec/factories/chouette_route_sections.rb b/spec/factories/chouette_route_sections.rb deleted file mode 100644 index d5e2cf69d..000000000 --- a/spec/factories/chouette_route_sections.rb +++ /dev/null @@ -1,6 +0,0 @@ -FactoryGirl.define do - factory :route_section, :class => Chouette::RouteSection do - association :departure, :factory => :stop_area - association :arrival, :factory => :stop_area - end -end diff --git a/spec/models/chouette/route_section_spec.rb b/spec/models/chouette/route_section_spec.rb deleted file mode 100644 index f064d38ea..000000000 --- a/spec/models/chouette/route_section_spec.rb +++ /dev/null @@ -1,93 +0,0 @@ -# require 'spec_helper' -# -# RSpec.describe Chouette::RouteSection, :type => :model do -# -# subject { create :route_section } -# -# it { should validate_presence_of(:departure) } -# it { should validate_presence_of(:arrival) } -# -# describe "#default_geometry" do -# -# it "should return nil when departure isn't defined" do -# subject.departure = nil -# expect(subject.default_geometry).to be_nil -# end -# -# it "should return nil when arrival isn't defined" do -# subject.arrival = nil -# expect(subject.default_geometry).to be_nil -# end -# -# it "should return nil when departure has no geometry" do -# subject.departure.stub :geometry -# expect(subject.default_geometry).to be_nil -# end -# -# it "should return nil when arrival has no geometry" do -# subject.arrival.stub :geometry -# expect(subject.default_geometry).to be_nil -# end -# -# it "should use departure geometry as first point" do -# expect(subject.default_geometry.first).to eq(subject.departure.geometry) -# end -# -# end -# -# describe "#process_geometry" do -# -# let(:sample_geometry) { line_string("0 0,1 1").to_rgeo } -# -# context "without processor" do -# -# it "should use the input geometry" do -# subject.input_geometry = sample_geometry -# subject.process_geometry -# expect(subject.processed_geometry).to eq(subject.input_geometry) -# end -# -# it "should use the default geometry when no input is defined" do -# subject.input_geometry = nil -# subject.process_geometry -# expect(subject.processed_geometry).to eq(subject.default_geometry.to_rgeo) -# end -# -# end -# -# # context "with a processor" do -# # -# # it "should use the processor result" do -# # subject.processor = Proc.new { |s| sample_geometry } -# # subject.process_geometry -# # subject.processor = nil -# # expect(subject.processed_geometry).to eq(sample_geometry) -# # end -# # end -# end -# -# describe "#distance" do -# -# context "with simple line" do -# let(:sample_geometry) { line_string("2.329534 48.842397,2.325725 48.855839").to_rgeo } -# it "should return the right distance" do -# subject.input_geometry = sample_geometry -# subject.process_geometry -# expect(subject.distance).to eq(sample_geometry.to_georuby.spherical_distance) -# end -# end -# -# context "with complex line" do -# let(:sample_geometry) { line_string("2.329561 48.842397, 2.329351 48.843119, 2.329152 48.843801, 2.3289820000000003 48.844426,2.3287960000000005 48.845059,2.3286540000000007 48.845575,2.3283130000000005 48.846748,2.3281220000000005 48.847404999999995,2.3279330000000003 48.848088,2.3278860000000003 48.848245999999996,2.3273240000000004 48.850142999999996,2.3273030000000006 48.850218999999996,2.3271630000000005 48.850745999999994,2.3270140000000006 48.85130999999999,2.3269350000000006 48.85142799999999,2.3268640000000005 48.85153599999999,2.3268290000000005 48.85161099999999,2.3267490000000004 48.85180999999999,2.3267700000000002 48.852053999999995,2.326759 48.852216999999996,2.326687 48.852427999999996,2.3266620000000002 48.852512,2.3264280000000004 48.853286,2.3264050000000003 48.853362,2.3263710000000004 48.853483,2.326125 48.854343,2.3259980000000002 48.854727,2.325737 48.855833999999994").to_rgeo } -# it "should return the right distance" do -# subject.input_geometry = sample_geometry -# subject.process_geometry -# expect(subject.distance).to eq(sample_geometry.to_georuby.spherical_distance) -# end -# end -# -# end -# -# -# -# end diff --git a/spec/models/compliance_check_set_spec.rb b/spec/models/compliance_check_set_spec.rb index 8afea5b3e..0159d1c6b 100644 --- a/spec/models/compliance_check_set_spec.rb +++ b/spec/models/compliance_check_set_spec.rb @@ -12,4 +12,81 @@ RSpec.describe ComplianceCheckSet, type: :model do it { should have_many :compliance_checks } it { should have_many :compliance_check_blocks } + + describe "#update_status" do + it "updates :status to successful when all resources are OK" do + check_set = create(:compliance_check_set) + create_list( + :compliance_check_resource, + 2, + compliance_check_set: check_set, + status: 'OK' + ) + + check_set.update_status + + expect(check_set.status).to eq('successful') + end + + it "updates :status to failed when one resource is ERROR" do + check_set = create(:compliance_check_set) + create( + :compliance_check_resource, + compliance_check_set: check_set, + status: 'ERROR' + ) + create( + :compliance_check_resource, + compliance_check_set: check_set, + status: 'OK' + ) + + updated = check_set.update_status + + expect(updated).to be true + expect(check_set.status).to eq('failed') + end + + it "updates :status to warning when one resource is WARNING" do + check_set = create(:compliance_check_set) + create( + :compliance_check_resource, + compliance_check_set: check_set, + status: 'WARNING' + ) + create( + :compliance_check_resource, + compliance_check_set: check_set, + status: 'OK' + ) + + check_set.update_status + + expect(check_set.status).to eq('warning') + end + + it "updates :status to successful when resources are IGNORED" do + check_set = create(:compliance_check_set) + create( + :compliance_check_resource, + compliance_check_set: check_set, + status: 'IGNORED' + ) + create( + :compliance_check_resource, + compliance_check_set: check_set, + status: 'OK' + ) + + check_set.update_status + + expect(check_set.status).to eq('successful') + end + + it "returns true when the status did not get updated" do + check_set = create(:compliance_check_set) + + expect(check_set.update_status).to be true + end + end end diff --git a/spec/models/route_sections_selector_spec.rb b/spec/models/route_sections_selector_spec.rb deleted file mode 100644 index 19863c315..000000000 --- a/spec/models/route_sections_selector_spec.rb +++ /dev/null @@ -1,43 +0,0 @@ -# require 'spec_helper' -# -# describe RouteSectionsSelector, :type => :model do -# -# let(:stop_points) { create_list :stop_point, 5 } -# let(:itinerary) { double stop_points: stop_points, route_sections: [] } -# -# subject { RouteSectionsSelector.new itinerary } -# -# describe "#sections" do -# -# it "should create a Section between each StopPoint" do -# expect(subject.sections.size).to eq(stop_points.size - 1) -# end -# -# end -# -# end -# -# describe RouteSectionsSelector::Section, :type => :model do -# -# let(:departure) { create :stop_point } -# let(:arrival) { create :stop_point } -# -# subject { RouteSectionsSelector::Section.new departure, arrival } -# -# let(:route_sections) do -# create_list :route_section, 5, -# departure: departure.stop_area, -# arrival: arrival.stop_area -# end -# -# describe "#candidates" do -# it "should return an empty array when no RouteSection exists" do -# expect(subject.candidates).to be_empty -# end -# -# it "should return the RouteSections with the same departure/arrival StopAreas" do -# expect(subject.candidates).to match_array(route_sections) -# end -# end -# -# end diff --git a/spec/policies/compliance_control_block_policy_spec.rb b/spec/policies/compliance_control_block_policy_spec.rb new file mode 100644 index 000000000..02c4ae08d --- /dev/null +++ b/spec/policies/compliance_control_block_policy_spec.rb @@ -0,0 +1,19 @@ +require 'rails_helper' + +RSpec.describe ComplianceControlBlockPolicy do + + let( :record ){ build_stubbed :compliance_control_block } + before { stub_policy_scope(record) } + + permissions :create? do + it_behaves_like 'permitted policy outside referential', 'compliance_control_blocks.create' + end + + permissions :update? do + it_behaves_like 'permitted policy outside referential', 'compliance_control_blocks.update' + end + + permissions :destroy? do + it_behaves_like 'permitted policy outside referential', 'compliance_control_blocks.destroy' + end +end diff --git a/spec/policies/compliance_control_set_policy_spec.rb b/spec/policies/compliance_control_set_policy_spec.rb index 6ab0bd60c..9b89338d6 100644 --- a/spec/policies/compliance_control_set_policy_spec.rb +++ b/spec/policies/compliance_control_set_policy_spec.rb @@ -6,18 +6,18 @@ RSpec.describe ComplianceControlSetPolicy do before { stub_policy_scope(record) } permissions :create? do - it_behaves_like 'permitted policy outside referential', 'compliance_controls_sets.create' + it_behaves_like 'permitted policy outside referential', 'compliance_control_sets.create' end permissions :update? do - it_behaves_like 'permitted policy outside referential', 'compliance_controls_sets.update' + it_behaves_like 'permitted policy outside referential', 'compliance_control_sets.update' end permissions :clone? do - it_behaves_like 'permitted policy outside referential', 'compliance_controls_sets.create' + it_behaves_like 'permitted policy outside referential', 'compliance_control_sets.create' end permissions :destroy? do - it_behaves_like 'permitted policy outside referential', 'compliance_controls_sets.destroy' + it_behaves_like 'permitted policy outside referential', 'compliance_control_sets.destroy' end end diff --git a/spec/support/permissions.rb b/spec/support/permissions.rb index 7d09e16cb..dde530871 100644 --- a/spec/support/permissions.rb +++ b/spec/support/permissions.rb @@ -26,8 +26,8 @@ module Support vehicle_journeys api_keys compliance_controls - compliance_controls_sets - compliance_controls_blocks + compliance_control_sets + compliance_control_blocks compliance_check_sets ] end |
