summaryrefslogtreecommitdiffstats
path: root/test/rails/railsresource.rb
blob: c9c1788119c829c3d07767179866e16afbe43c8f (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
57
58
59
60
#!/usr/bin/env ruby -I../lib -I../../lib

require 'puppet'
require 'puppet/rails'
require 'puppettest'
require 'puppettest/railstesting'
require 'puppettest/resourcetesting'

class TestRailsResource < Test::Unit::TestCase
    include PuppetTest::RailsTesting
    include PuppetTest::ResourceTesting
    
    # Don't do any tests w/out this class
    if defined? ActiveRecord::Base
    # Create a resource param from a rails parameter
    def test_to_resource
        railsinit
        
        # We need a host for resources
        host = Puppet::Rails::Host.new(:name => "myhost")

        # Now build a resource
        resource = host.rails_resources.build(
            :title => "/tmp/to_resource", :restype => "file",
            :exported => true
        )

        # Now add some params
        {"owner" => "root", "mode" => "644"}.each do |param, value|
            resource.rails_parameters.build(
                :name => param, :value => value
            )
        end

        # Now save the whole thing
        host.save

        # Now, try to convert our resource to a real resource

        # We need a scope
        interp, scope, source = mkclassframing

        res = nil
        assert_nothing_raised do
            res = resource.to_resource(scope)
        end

        assert_instance_of(Puppet::Parser::Resource, res)

        assert_equal("root", res[:owner])
        assert_equal("644", res[:mode])
        assert_equal("/tmp/to_resource", res.title)
        assert_equal(source, res.source)
    end
    else
        $stderr.puts "Install Rails for Rails and Caching tests"
    end
end

# $Id$