require 'test_helper' class DynamicMenusTest < ActiveSupport::TestCase def setup DynamicMenus.create_tables end test "truth" do assert_kind_of Module, DynamicMenus end test "should validate write access" do DynamicMenus.on_validate_write_access{ true } assert_equal DynamicMenus.write_access?, true DynamicMenus.on_validate_write_access{ false } assert_equal DynamicMenus.write_access?, false end test "should do validate show through validate_show method" do test_menu = DynamicMenu.create( idstr: :validate_show_menu ) found = false DynamicMenus.recursive_walkthrough do |data| if data[:menu].id.to_i == test_menu.id.to_i found = true break end end assert_equal found, true DynamicMenus.connect(mode: :validate_show, idstr: :validate_show_menu) do true end found = false DynamicMenus.recursive_walkthrough do |data| if data[:menu].id.to_i == test_menu.id.to_i found = true break end end assert_equal found, true DynamicMenus.connect(mode: :validate_show, idstr: :validate_show_menu) do false end found = false DynamicMenus.recursive_walkthrough do |data| if data[:menu].id.to_i == test_menu.id.to_i found = false break end end assert_equal found, false end test "should do validate show through check_callback" do test_menu = DynamicMenu.create( idstr: :validate_show_menu_check_callback, check_callbacks: "test, test2" ) test_found = false test2_found = false test_menu.check_callbacks_enum.each do |symb| test_found = true if symb == :test test2_found = true if symb == :test2 end assert_equal true, test_found assert_equal true, test2_found found = false DynamicMenus.recursive_walkthrough do |data| if data[:menu].id.to_i == test_menu.id.to_i found = true break end end assert_equal true, found DynamicMenus.connect(mode: :check_callback, idstr: :test2) do false end found = false DynamicMenus.recursive_walkthrough do |data| if data[:menu].id.to_i == test_menu.id.to_i found = true break end end assert_equal false, found end end