summaryrefslogtreecommitdiffstats
path: root/test/rails/railsparameter.rb
blob: 7dc7ef5dd095184ff60424a642dbca62d6efb3f5 (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
#!/usr/bin/ruby

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

class TestRailsParameter < Test::Unit::TestCase
    include PuppetTest::RailsTesting
    
    # Don't do any tests w/out this class
    if defined? ActiveRecord::Base
    # Create a resource param from a rails parameter
    def test_to_resourceparam
        railsinit
        # First create our parameter
        rparam = nil
        hash = { :name => :myparam, :value => "myval",
                :file => __FILE__, :line => __LINE__}
        assert_nothing_raised do
            rparam = Puppet::Rails::RailsParameter.new(hash)
        end

        assert(rparam, "Did not create rails parameter")

        # The id doesn't get assigned until we save
        rparam.save

        # Now create a source
        interp = mkinterp
        source = interp.newclass "myclass"

        # And try to convert our parameter
        pparam = nil
        assert_nothing_raised do
            pparam = rparam.to_resourceparam(source)
        end


        assert_instance_of(Puppet::Parser::Resource::Param, pparam)
        hash.each do |name, value|
            assert_equal(value,  pparam.send(name), "%s was not equal" % name)
        end
    end
    else
        $stderr.puts "Install Rails for Rails and Caching tests"
    end
end

# $Id$