test/unit/tab_helper_test.rb in exlibris-aleph-0.0.2 vs test/unit/tab_helper_test.rb in exlibris-aleph-0.1.0

- old
+ new

@@ -1,17 +1,10 @@ require 'test_helper' class ConfigHelperTest < ActiveSupport::TestCase def setup Exlibris::Aleph::TabHelper.class_variable_set(:@@adms, []) - [ :@@patrons_path, - :@@items_path, - :@@item_permissions_by_item_status_path, - :@@item_permissions_by_item_process_status_path, - :@@collections_path, - :@@pickup_locations_path ].each do |class_variable| - Exlibris::Aleph::TabHelper.class_variable_set(class_variable, {}) - end + Exlibris::Aleph::TabHelper.class_variable_set(:@@refresh_time, ->{1.day.ago}) @adms = ["NYU50", "NYU51"] @tab_path = "/mnt/aleph_tab" dummy_path = "#{File.dirname(__FILE__)}/../dummy" @yml_path = File.join(dummy_path, "config/aleph") @log_path = File.join(dummy_path, "log/aleph") @@ -19,39 +12,102 @@ test "instance_with_no_init" do assert_raise(ArgumentError) { Exlibris::Aleph::TabHelper.send(:new) } end + test "instance_with_wrong_init" do + Exlibris::Aleph::TabHelper.init(nil, nil) + assert_raise(ArgumentError) { Exlibris::Aleph::TabHelper.send(:new) } + Exlibris::Aleph::TabHelper.init(@tab_path, nil) + assert_raise(ArgumentError) { Exlibris::Aleph::TabHelper.send(:new) } + Exlibris::Aleph::TabHelper.init(@tab_path, []) + assert_raise(ArgumentError) { Exlibris::Aleph::TabHelper.send(:new) } + Exlibris::Aleph::TabHelper.init(@tab_path, @adms, nil) + assert_raise(ArgumentError) { Exlibris::Aleph::TabHelper.send(:new) } + end + test "init" do - Exlibris::Aleph::TabHelper.init(@tab_path, @yml_path, @log_path, @adms) + Exlibris::Aleph::TabHelper.init(@tab_path, @adms) helper = Exlibris::Aleph::TabHelper.instance assert_equal(@adms, helper.adms) end test "instance" do - Exlibris::Aleph::TabHelper.init(@tab_path, @yml_path, @log_path, @adms) + Exlibris::Aleph::TabHelper.init(@tab_path, @adms) assert_nothing_raised() { Exlibris::Aleph::TabHelper.send(:new) } assert_same(Exlibris::Aleph::TabHelper.instance, Exlibris::Aleph::TabHelper.instance) end + test "refresh" do + Exlibris::Aleph::TabHelper.init(@tab_path, @adms, ->{1.second.ago}) + helper = Exlibris::Aleph::TabHelper.instance + helper.sub_libraries + updated_at_1 = helper.updated_at + helper.sub_libraries + updated_at_2 = helper.updated_at + assert_equal(updated_at_1, updated_at_2) + sleep 1 + helper.sub_libraries + assert_not_equal(updated_at_1, helper.updated_at) + end + + test "sub_library_text" do + Exlibris::Aleph::TabHelper.init(@tab_path, @adms) + helper = Exlibris::Aleph::TabHelper.instance + assert_equal("NYU Bobst", helper.sub_library_text("BOBST")) + end + + test "sub_library_adm" do + Exlibris::Aleph::TabHelper.init(@tab_path, @adms) + helper = Exlibris::Aleph::TabHelper.instance + assert_equal("NYU50", helper.sub_library_adm("BOBST")) + end + + test "item_pickup_locations" do + Exlibris::Aleph::TabHelper.init(@tab_path, @adms) + helper = Exlibris::Aleph::TabHelper.instance + assert_equal( + ["BOBST", "NCOUR", "NIFA", "NISAW", "NREI", "NPOLY", "NYUAB", "NYUSE", "NYUSS"], + helper.item_pickup_locations({:adm_library_code => "nyu50", :sub_library_code => "BOBST", :bor_status => "51"})) + end + + test "collection_text" do + Exlibris::Aleph::TabHelper.init(@tab_path, @adms) + helper = Exlibris::Aleph::TabHelper.instance + assert_equal( + "Main Collection", + helper.collection_text({:adm_library_code => "nyu50", :sub_library_code => "BOBST", :collection_code => "MAIN"})) + end + + test "item_web_text" do + Exlibris::Aleph::TabHelper.init(@tab_path, @adms) + helper = Exlibris::Aleph::TabHelper.instance + assert_equal( + "Offsite Available", + helper.item_web_text({:adm_library_code => "nyu50", :item_process_status => "Depository"})) + assert_equal( + "Offsite Available", + helper.item_web_text({:adm_library_code => "nyu50", :sub_library_code => "BOBST", :item_process_status_code => "DP"})) + end + test "sub_libraries" do - Exlibris::Aleph::TabHelper.init(@tab_path, @yml_path, @log_path, @adms) + Exlibris::Aleph::TabHelper.init(@tab_path, @adms) helper = Exlibris::Aleph::TabHelper.instance assert_equal("BOBST", helper.sub_libraries["BOBST"][:code]) assert_equal("NYU Bobst", helper.sub_libraries["BOBST"][:text]) assert_equal("NYU50", helper.sub_libraries["BOBST"][:library]) end test "patrons" do - Exlibris::Aleph::TabHelper.init(@tab_path, @yml_path, @log_path, @adms) + Exlibris::Aleph::TabHelper.init(@tab_path, @adms) helper = Exlibris::Aleph::TabHelper.instance assert_equal("51", helper.patrons["nyu50"]["51"][:code]) assert_equal("NYU Administrator", helper.patrons["nyu50"]["51"][:text]) end test "patron_permissions" do - Exlibris::Aleph::TabHelper.init(@tab_path, @yml_path, @log_path, @adms) + Exlibris::Aleph::TabHelper.init(@tab_path, @adms) helper = Exlibris::Aleph::TabHelper.instance assert_equal("BOBST", helper.patron_permissions["nyu50"]["BOBST"]["51"][:sub_library]) assert_equal("51", helper.patron_permissions["nyu50"]["BOBST"]["51"][:patron_status]) assert_equal("Y", helper.patron_permissions["nyu50"]["BOBST"]["51"][:loan_permission]) assert_equal("Y", helper.patron_permissions["nyu50"]["BOBST"]["51"][:photo_permission]) @@ -67,19 +123,19 @@ assert_equal("N", helper.patron_permissions["nyu50"]["BOBST"]["51"][:booking_ignore_closing_hours]) assert_equal("N", helper.patron_permissions["nyu50"]["BOBST"]["51"][:automatically_create_aleph_record]) end test "items" do - Exlibris::Aleph::TabHelper.init(@tab_path, @yml_path, @log_path, @adms) + Exlibris::Aleph::TabHelper.init(@tab_path, @adms) helper = Exlibris::Aleph::TabHelper.instance assert_equal("ITEM-STATUS", helper.items["nyu50"]["Billed as lost"][:code]) assert_equal("Billed as lost", helper.items["nyu50"]["Billed as lost"][:original_text]) assert_equal("Request ILL", helper.items["nyu50"]["Billed as lost"][:web_text]) end test "item_permissions_by_item_status" do - Exlibris::Aleph::TabHelper.init(@tab_path, @yml_path, @log_path, @adms) + Exlibris::Aleph::TabHelper.init(@tab_path, @adms) helper = Exlibris::Aleph::TabHelper.instance assert_equal("BOBST", helper.item_permissions_by_item_status["nyu50"]["BOBST"]["01"][:sub_library]) assert_equal("01", helper.item_permissions_by_item_status["nyu50"]["BOBST"]["01"][:item_status]) assert_equal("Regular loan", helper.item_permissions_by_item_status["nyu50"]["BOBST"]["01"][:text]) assert_equal("Y", helper.item_permissions_by_item_status["nyu50"]["BOBST"]["01"][:loan]) @@ -95,11 +151,11 @@ assert_equal("00", helper.item_permissions_by_item_status["nyu50"]["BOBST"]["01"][:reloaning_limit]) assert_equal("A", helper.item_permissions_by_item_status["nyu50"]["BOBST"]["01"][:booking_hours]) end test "item_permissions_by_item_process_status" do - Exlibris::Aleph::TabHelper.init(@tab_path, @yml_path, @log_path, @adms) + Exlibris::Aleph::TabHelper.init(@tab_path, @adms) helper = Exlibris::Aleph::TabHelper.instance assert_equal("BOBST", helper.item_permissions_by_item_process_status["nyu50"]["BOBST"]["AC"][:sub_library]) assert_equal("AC", helper.item_permissions_by_item_process_status["nyu50"]["BOBST"]["AC"][:item_process_status]) assert_equal("AFC-Post cataloging", helper.item_permissions_by_item_process_status["nyu50"]["BOBST"]["AC"][:text]) assert_equal("Y", helper.item_permissions_by_item_process_status["nyu50"]["BOBST"]["AC"][:loan]) @@ -115,66 +171,45 @@ assert_equal("00", helper.item_permissions_by_item_process_status["nyu50"]["BOBST"]["AC"][:reloaning_limit]) assert_equal("A", helper.item_permissions_by_item_process_status["nyu50"]["BOBST"]["AC"][:booking_hours]) end test "collections" do - Exlibris::Aleph::TabHelper.init(@tab_path, @yml_path, @log_path, @adms) + Exlibris::Aleph::TabHelper.init(@tab_path, @adms) helper = Exlibris::Aleph::TabHelper.instance assert_equal("BOBST", helper.collections["nyu50"]["BOBST"]["MAIN"][:sub_library]) assert_equal("MAIN", helper.collections["nyu50"]["BOBST"]["MAIN"][:collection_code]) assert_equal("Main Collection", helper.collections["nyu50"]["BOBST"]["MAIN"][:text]) end test "pickup_locations" do - Exlibris::Aleph::TabHelper.init(@tab_path, @yml_path, @log_path, @adms) + Exlibris::Aleph::TabHelper.init(@tab_path, @adms) helper = Exlibris::Aleph::TabHelper.instance assert_equal("BOBST", helper.pickup_locations["nyu50"]["BOBST"]["##"]["DP"]["51"]["Y"][:sub_library]) assert_equal("##", helper.pickup_locations["nyu50"]["BOBST"]["##"]["DP"]["51"]["Y"][:item_status]) assert_equal("DP", helper.pickup_locations["nyu50"]["BOBST"]["##"]["DP"]["51"]["Y"][:item_process_status]) assert_equal("51", helper.pickup_locations["nyu50"]["BOBST"]["##"]["DP"]["51"]["Y"][:patron_status]) assert_equal("Y", helper.pickup_locations["nyu50"]["BOBST"]["##"]["DP"]["51"]["Y"][:availability_status]) assert_equal(["BOBST", "NCOUR", "NIFA", "NISAW", "NREI", "NPOLY", "NYUAB", "NYUSE", "NYUSS"], helper.pickup_locations["nyu50"]["BOBST"]["##"]["DP"]["51"]["Y"][:pickup_locations]) end test "refresh_yml" do - Exlibris::Aleph::TabHelper.init(@tab_path, @yml_path, @log_path, @adms) + Exlibris::Aleph::TabHelper.init(@tab_path, @adms) helper = Exlibris::Aleph::TabHelper.instance assert_nil(helper.sub_libraries["NEW__"]) sub_library_file = "/mnt/aleph_tab/alephe/tab/tab_sub_library.eng" file = File.open(sub_library_file, 'r') old_size = file.size file.close # Update the file. File.open(sub_library_file, 'a') {|f| f.puts "NEW__ 1 NYU50 L NYU TEST BOBST BOBST BOBST BOBST NYU50 ALEPH" } Exlibris::Aleph::TabHelper.refresh_yml - helper.refresh + helper.send(:refresh) assert_not_nil(helper.sub_libraries["NEW__"]) assert_equal("NEW__", helper.sub_libraries["NEW__"][:code]) assert_equal("NYU TEST", helper.sub_libraries["NEW__"][:text]) assert_equal("NYU50", helper.sub_libraries["NEW__"][:library]) # Revert the file to what it was file = File.open(sub_library_file, 'r+') file.truncate(old_size) file.close end - - # test "refresh" do - # Exlibris::Aleph::TabHelper.init(@tab_path, @yml_path, @log_path, @adms) - # helper = Exlibris::Aleph::TabHelper.instance - # assert_nil(helper.sub_libraries["NEW__"]) - # sub_library_file = "/mnt/aleph_tab/alephe/tab/tab_sub_library.eng" - # file = File.open(sub_library_file, 'r') - # old_size = file.size - # file.close - # # Update the file. - # File.open(sub_library_file, 'a') {|f| f.puts "NEW__ 1 NYU50 L NYU TEST BOBST BOBST BOBST BOBST NYU50 ALEPH" } - # helper.refresh - # assert_not_nil(helper.sub_libraries["NEW__"]) - # assert_equal("NEW__", helper.sub_libraries["NEW__"][:code]) - # assert_equal("NYU TEST", helper.sub_libraries["NEW__"][:text]) - # assert_equal("NYU50", helper.sub_libraries["NEW__"][:library]) - # # Revert the file to what it was - # file = File.open(sub_library_file, 'r+') - # file.truncate(old_size) - # file.close - # end end \ No newline at end of file