Project

General

Profile

Download (1.9 KB) Statistics
| Branch: | Tag: | Revision:

foreman_pipeline / test / foreman_pipeline_test_helper.rb @ master

1
require "test_helper"
2

    
3
FactoryGirl.definition_file_paths << File.join(Katello::Engine.root, 'test', 'factories')
4
FactoryGirl.definition_file_paths << File.join(File.dirname(__FILE__), 'factories')
5
FactoryGirl.reload
6

    
7
require "#{Katello::Engine.root}/test/support/fixtures_support"
8
require "fixtures_support"
9

    
10
require 'dynflow/testing'
11
Mocha::Mock.send :include, Dynflow::Testing::Mimic
12
require "#{Katello::Engine.root}/test/support/foreman_tasks/task"
13

    
14
module FixtureTestCase
15
  extend ActiveSupport::Concern
16

    
17
  included do
18
    extend ActiveRecord::TestFixtures
19

    
20
    self.use_transactional_fixtures = true
21
    self.use_instantiated_fixtures = false
22
    self.pre_loaded_fixtures = true
23

    
24
    Katello::FixturesSupport.set_fixture_classes(self)
25
    ForemanPipeline::FixturesSupport.set_fixture_classes(self)
26

    
27
    self.fixture_path = Dir.mktmpdir("pipeline_and_katello_fixtures")
28
    FileUtils.cp(Dir.glob("#{Katello::Engine.root}/test/fixtures/models/*"), self.fixture_path)
29
    FileUtils.cp(Dir.glob("#{ForemanPipeline::Engine.root}/test/fixtures/*"), self.fixture_path)
30
    FileUtils.cp(Dir.glob("#{Rails.root}/test/fixtures/*"), self.fixture_path)
31
    fixtures(:all)
32
    FIXTURES = load_fixtures(ActiveRecord::Base)
33
  end
34

    
35
  module ClassMethods
36
    def before_suite
37
      @@admin = ::User.find(FIXTURES['users']['admin']['id'])
38
      User.current = @@admin
39
    end
40
  end
41
end
42

    
43
class ActiveSupport::TestCase
44
  include FixtureTestCase
45

    
46
  def get_organization(org = nil)
47
    saved_user = User.current
48
    User.current = User.find(users(:admin).id)
49
    org = org.nil? ? :empty_organization : org
50
    organization = Organization.find(taxonomies(org.to_sym).id)
51
    organization.stubs(:label_not_changed).returns(true)
52
    organization.setup_label_from_name
53
    organization.save!
54
    User.current = saved_user
55
    organization
56
  end
57
end
58

    
59
class ActionController::TestCase
60
  def setup_engine_routes
61
    @routes = ForemanPipeline::Engine.routes
62
  end
63
end