summaryrefslogtreecommitdiffstats
path: root/test/lib/puppettest/railstesting.rb
blob: 3af593762737a6600595dd629d1912b01a1183bf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
module PuppetTest::RailsTesting
    Parser = Puppet::Parser
    AST = Puppet::Parser::AST
    include PuppetTest::ParserTesting

    def teardown
        super

        # If we don't clean up the connection list, then the rails
        # lib will still think it's connected.
        if Puppet.features.rails?
            ActiveRecord::Base.clear_active_connections!
        end
    end

    def railsinit
        Puppet::Rails.init
    end

    def railsteardown
        if Puppet[:dbadapter] != "sqlite3"
            Puppet::Rails.teardown
        end
    end

    def railsresource(type = "file", title = "/tmp/testing", params = {})
        railsteardown
        railsinit

        # We need a host for resources
        #host = Puppet::Rails::Host.new(:name => Facter.value("hostname"))

        # Now build a resource
        resources = []

            resources << mkresource(
                :type => type, :title => title, :exported => true,

                    :parameters => params)

        # Now collect our facts
        facts = Facter.to_hash

        # Now try storing our crap
        host = nil
        node = mknode(facts["hostname"])
        node.parameters = facts
        assert_nothing_raised {
            host = Puppet::Rails::Host.store(node, resources)
        }

        # Now save the whole thing
        host.save
    end
end