File: railsresource.rb

package info (click to toggle)
puppet 0.20.1-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 3,072 kB
  • ctags: 3,365
  • sloc: ruby: 47,009; sh: 496; lisp: 143; xml: 122; makefile: 67
file content (62 lines) | stat: -rwxr-xr-x 1,695 bytes parent folder | download
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
61
62
#!/usr/bin/env ruby

$:.unshift("../lib").unshift("../../lib") if __FILE__ =~ /\.rb$/

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

# Don't do any tests w/out this class
if defined? ActiveRecord::Base
class TestRailsResource < Test::Unit::TestCase
    include PuppetTest::RailsTesting
    include PuppetTest::ResourceTesting
    
    # 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
end
else
    $stderr.puts "Install Rails for Rails and Caching tests"
end

# $Id: railsresource.rb 1873 2006-11-13 07:49:48Z luke $