require_relative '../../../spec_helper' describe AIXM::Feature::Airspace do context "only required attributes set" do subject do AIXM.airspace(type: "TMA", name: "Test TMA") end describe :initialize do it "sets defaults" do subject.id.must_equal 'C55466EC' subject.layers.must_equal [] subject.geometry.must_be_instance_of AIXM::Component::Geometry end end describe :id= do it "fails on invalid values" do [:foobar, 123].wont_be_written_to subject, :id end it "falls back to id derived from digest of type, local_type and name" do subject.tap { |s| s.id = nil }.id.must_equal 'C55466EC' end it "upcases value" do subject.tap { |s| s.id = 'löl' }.id.must_equal 'LOEL' end end describe :type= do it "fails on invalid values" do [nil, :foobar, 123].wont_be_written_to subject, :type end it "looks up valid values" do subject.tap { |s| s.type = :danger_area }.type.must_equal :danger_area subject.tap { |s| s.type = :P }.type.must_equal :prohibited_area end end describe :local_type= do it "fails on invalid values" do [:foobar, 123].wont_be_written_to subject, :local_type end it "accepts nil value" do [nil].must_be_written_to subject, :local_type end it "upcases value" do subject.tap { |s| s.local_type = 'löl' }.local_type.must_equal 'LOEL' end end describe :name= do it "fails on invalid values" do [:foobar, 123].wont_be_written_to subject, :name end it "accepts nil value" do [nil].must_be_written_to subject, :name end it "upcases value" do subject.tap { |s| s.name = 'löl' }.name.must_equal 'LOEL' end end describe :to_uid do it "builds with arbitrary tag" do subject.to_uid.must_match(//) subject.to_uid(as: :FooBar).must_match(//) end end describe :to_xml do it "fails to build AIXM since geometry is not closed" do subject.layers << AIXM::Factory.layer -> { subject.to_xml }.must_raise AIXM::GeometryError end it "fails to build AIXM since layers are not defined" do subject.geometry = AIXM::Factory.circle_geometry -> { subject.to_xml }.must_raise AIXM::LayerError end end end context "only required attributes, geometry and layers set" do subject do AIXM.airspace(type: "TMA", name: "Test TMA").tap do |airspace| airspace.geometry = AIXM::Factory.circle_geometry airspace.layers << AIXM::Factory.layer end end describe :to_xml do it "builds correct AIXM without id" do AIXM.aixm! subject.to_xml.must_match(%r{C55466EC}) end it "builds correct AIXM without short name" do AIXM.aixm! subject.to_xml.wont_match(//) end it "builds correct AIXM with identical name and short name" do AIXM.aixm! subject.to_xml.wont_match(//) end end end context "with one layer" do subject do AIXM::Factory.polygon_airspace end describe :to_xml do it "builds correct complete OFMX" do AIXM.ofmx! subject.to_xml.must_equal <<~"END" D PA POLYGON POLYGON AIRSPACE C XXXX TFC-AD STD 65 FL STD 45 FL ALT 6000 FT HEI 3000 FT H24 Y airspace layer D PA CWA 47.85916667N 007.56000000E WGE 47.90416667N 007.56333333E FRANCE_GERMANY FNT 47.94361111N 007.59583333E WGE GRC 47.85916667N 007.56000000E WGE END end it "builds correct minimal OFMX" do AIXM.ofmx! subject.local_type = subject.name = nil subject.to_xml.must_equal <<~"END" D PA C XXXX TFC-AD STD 65 FL STD 45 FL ALT 6000 FT HEI 3000 FT H24 Y airspace layer D PA CWA 47.85916667N 007.56000000E WGE 47.90416667N 007.56333333E FRANCE_GERMANY FNT 47.94361111N 007.59583333E WGE GRC 47.85916667N 007.56000000E WGE END end end end context "with two layers" do subject do AIXM::Factory.polygon_airspace.tap do |airspace| airspace.layers << AIXM::Factory.layer end end describe :to_xml do it "builds correct OFMX" do AIXM.ofmx! subject.to_xml.must_equal <<~"END" D PA POLYGON POLYGON AIRSPACE D PA CWA 47.85916667N 007.56000000E WGE 47.90416667N 007.56333333E FRANCE_GERMANY FNT 47.94361111N 007.59583333E WGE GRC 47.85916667N 007.56000000E WGE CLASS B794588D POLYGON AIRSPACE LAYER 1 C XXXX TFC-AD STD 65 FL STD 45 FL ALT 6000 FT HEI 3000 FT H24 Y airspace layer CLASS B794588D D PA CLASS 64589EAF POLYGON AIRSPACE LAYER 2 C XXXX TFC-AD STD 65 FL STD 45 FL ALT 6000 FT HEI 3000 FT H24 Y airspace layer CLASS 64589EAF D PA END end end end end