require_relative '../../../spec_helper' describe AIXM::Feature::Unit do subject do AIXM::Factory.unit end describe :organisation= do macro :organisation it "fails on nil value" do [nil].wont_be_written_to subject, :organisation end end describe :name= do it "fails on invalid values" do [nil, :foobar, 123].wont_be_written_to subject, :name end it "upcases and transcodes valid values" do subject.tap { |s| s.name = 'Nîmes-Alès APP' }.name.must_equal 'NIMES-ALES APP' 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 = :flight_information_centre }.type.must_equal :flight_information_centre subject.tap { |s| s.type = :MET }.type.must_equal :meteorological_office end end describe :class= do it "fails on invalid values" do [nil, :foobar, 123].wont_be_written_to subject, :class end it "looks up valid values" do subject.tap { |s| s.class = :icao }.class.must_equal :icao subject.tap { |s| s.class = :OTHER }.class.must_equal :other end end describe :airport= do it "fails on invalid values" do [:foobar, 123].wont_be_written_to subject, :airport end it "accepts valid values" do [nil, AIXM::Factory.airport].must_be_written_to subject, :airport end end describe :remarks= do macro :remarks end describe :to_xml do let :service do AIXM::Factory.service.tap do |service| service.type = :AFIS end end it "builds correct complete OFMX" do 2.times { subject.add_service(service) } AIXM.ofmx! subject.to_xml.must_equal <<~END PUJAUT TWR FRANCE LFNT TWR ICAO A/A FR only PUJAUT TWR AFIS 1 H24 service remarks PUJAUT TWR AFIS 1 123.35 124.1 MHZ H24 frequency remarks PUJAUT CONTROL EN PUJAUT CONTROLE FR PUJAUT TWR AFIS 2 H24 service remarks PUJAUT TWR AFIS 2 123.35 124.1 MHZ H24 frequency remarks PUJAUT CONTROL EN PUJAUT CONTROLE FR PUJAUT TWR APP 1 H24 service remarks PUJAUT TWR APP 1 123.35 124.1 MHZ H24 frequency remarks PUJAUT CONTROL EN PUJAUT CONTROLE FR END end it "builds correct minimal OFMX" do AIXM.ofmx! subject.airport = subject.remarks = nil subject.instance_variable_set(:'@services', []) subject.to_xml.must_equal <<~END PUJAUT TWR FRANCE TWR ICAO END end end end