additionals/test/test_helper.rb

61 lines
1.5 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
2018-05-21 13:43:42 +03:00
2021-05-06 11:50:25 +03:00
if ENV['COVERAGE']
require 'simplecov'
SimpleCov.start :rails do
add_filter 'init.rb'
2020-08-08 19:44:40 +03:00
root File.expand_path "#{File.dirname __FILE__}/.."
end
2017-06-28 16:21:00 +03:00
end
2020-08-08 19:44:40 +03:00
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"
2017-06-28 17:19:58 +03:00
module Additionals
2018-07-15 19:02:52 +03:00
module TestHelper
include Additionals::GlobalTestHelper
2016-10-19 14:30:14 +03:00
2018-07-23 19:17:04 +03:00
def prepare_tests
2016-10-19 14:30:14 +03:00
Role.where(id: [1, 2]).each do |r|
2020-07-27 11:49:23 +03:00
r.permissions << :save_dashboards
r.save
end
Role.where(id: [1]).each do |r|
r.permissions << :share_dashboards
2020-07-27 11:49:23 +03:00
r.permissions << :set_system_dashboards
2016-10-19 14:30:14 +03:00
r.save
end
Project.where(id: [1, 2]).each do |project|
2020-08-06 09:18:30 +03:00
EnabledModule.create project: project, name: 'issue_tracking'
2016-10-19 14:30:14 +03:00
end
end
end
2018-07-15 19:02:52 +03:00
2020-07-27 11:49:23 +03:00
module PluginFixturesLoader
def fixtures(*table_names)
2020-08-08 19:44:40 +03:00
dir = "#{File.dirname __FILE__}/fixtures/"
2020-07-27 11:49:23 +03:00
table_names.each do |x|
ActiveRecord::FixtureSet.create_fixtures dir, x if File.exist? "#{dir}/#{x}.yml"
2020-07-27 11:49:23 +03:00
end
super table_names
2020-07-27 11:49:23 +03:00
end
end
2018-07-23 19:17:04 +03:00
class ControllerTest < Redmine::ControllerTest
include Additionals::TestHelper
2020-07-27 11:49:23 +03:00
extend PluginFixturesLoader
2018-07-23 19:17:04 +03:00
end
class TestCase < ActiveSupport::TestCase
include Additionals::TestHelper
2020-07-27 11:49:23 +03:00
extend PluginFixturesLoader
end
class IntegrationTest < Redmine::IntegrationTest
extend PluginFixturesLoader
2018-07-23 19:17:04 +03:00
end
end