additionals/test/test_helper.rb

91 lines
2.6 KiB
Ruby
Executable File

# frozen_string_literal: true
if ENV['COVERAGE']
require 'simplecov'
SimpleCov.start :rails do
add_filter 'init.rb'
root File.expand_path "#{File.dirname __FILE__}/.."
end
end
require 'minitest/reporters'
Minitest::Reporters.use! [Minitest::Reporters::DefaultReporter.new, Minitest::Reporters::JUnitReporter.new]
require File.expand_path "#{File.dirname __FILE__}/../../../test/test_helper"
require File.expand_path "#{File.dirname __FILE__}/global_test_helper"
require File.expand_path "#{File.dirname __FILE__}/crud_controller_base"
module Additionals
module TestHelper
include Additionals::GlobalTestHelper
def prepare_tests
Role.where(id: [1, 2]).find_each do |r|
r.permissions << :save_dashboards
r.save
end
Role.where(id: [1]).find_each do |r|
r.permissions << :share_dashboards
r.permissions << :set_system_dashboards
r.permissions << :show_hidden_roles_in_memberbox
r.save
end
Project.where(id: [1, 2]).find_each do |project|
EnabledModule.create project:, name: 'issue_tracking'
end
end
def smiley_test_span(text)
"<span class=\"additionals smiley a-icon smiley-smiley\" title=\":)\">#{text}</span>"
end
def svg_test_icon
'<svg class="a-s18 a-svg-icon smiley" title=":)" aria-hidden="true">' \
'<use href="/plugin_assets/additionals/images/icons.svg#icon--smiley-smiley"></use></svg>'
end
# for tanuki_emoji 0.11.0 or newer
# NOTE: tanuki_emoji 0.11.0 can only be used, if Redmine 5.0 suppord dropped
# (depenceny for i18n version)
def emoji_heart_tag_new
'<additionals-emoji title="red heart" data-name="red_heart" data-unicode-version="6.0">❤️</additionals-emoji>'
end
def emoji_heart_tag
'<additionals-emoji title="heavy black heart" data-name="heart" data-unicode-version="1.1">❤</additionals-emoji>'
end
end
module PluginFixturesLoader
def fixtures(*table_names)
dir = "#{File.dirname __FILE__}/fixtures/"
table_names.each do |x|
ActiveRecord::FixtureSet.create_fixtures dir, x if File.exist? "#{dir}/#{x}.yml"
end
super table_names
end
end
class ControllerTest < Redmine::ControllerTest
include Additionals::TestHelper
extend PluginFixturesLoader
end
class TestCase < ActiveSupport::TestCase
include Additionals::TestHelper
extend PluginFixturesLoader
end
class IntegrationTest < Redmine::IntegrationTest
include Additionals::TestHelper
extend PluginFixturesLoader
end
class ApiTest < Redmine::ApiTest::Base
include Additionals::TestHelper
extend PluginFixturesLoader
end
end