require 'test_helper' class CsvDictionaryTest < Test::Unit::TestCase def setup CsvDictionaryTestHelper.setup_database @dictionary = CsvDictionary.new(:bts_aircraft_type, :url => GDOCS_URL, :sheet => 1) end def teardown Aircraft.clear_csv_dictionaries CsvDictionaryTestHelper.teardown_database end def test_should_set_key_name assert_equal :bts_aircraft_type, @dictionary.key_name end def test_should_set_url dictionary = CsvDictionary.new(:bts_aircraft_type, :url => CSV_URL) assert_equal CSV_URL, dictionary.url end def test_should_interpret_gdocs_urls assert_equal GDOCS_URL + '&output=csv&gid=0', @dictionary.send(:interpret_url, @dictionary.url) end def test_should_raise_if_gdocs_url_includes_gid assert_raise RuntimeError do CsvDictionary.new(:bts_aircraft_type, :url => GDOCS_URL + '&gid=1') end end def test_should_raise_if_sheet_option_set_on_non_gdocs_url assert_raise RuntimeError do CsvDictionary.new(:bts_aircraft_type, :url => CSV_URL, :sheet => 1) end end def test_should_set_default_sheet assert_equal 0, @dictionary.sheet end def test_should_replace_attributes attributes = { :bts_aircraft_type => '103' } @dictionary.expects(:lookup).with('103').returns('SJ') @dictionary.replace_attributes!(attributes) assert_equal({ :brighter_planet_aircraft_class_code => 'SJ' }, attributes) end # real http call def test_should_set_value_name_after_dictionary_loaded @dictionary.send(:load_dictionary) assert_equal :brighter_planet_aircraft_class_code, @dictionary.value_name end # real http call def test_should_lookup assert_equal 'SJ', @dictionary.lookup('103') end end