summaryrefslogtreecommitdiffstats
path: root/test/rails/ast.rb
blob: 48ec18c45166c4c270d67c5dd32e8f7f39dfaf9b (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
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env ruby

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

require 'puppettest'
require 'puppet/rails'
require 'puppet/parser/parser'
require 'puppettest/resourcetesting'
require 'puppettest/parsertesting'
require 'puppettest/railstesting'
require 'puppettest/support/collection'

class TestRailsAST < PuppetTest::TestCase
    confine "Missing rails" => Puppet.features.rails?
    include PuppetTest::RailsTesting
    include PuppetTest::ParserTesting
    include PuppetTest::ResourceTesting
    include PuppetTest::Support::Collection

    def test_exported_collexp
        railsinit
        Puppet[:storeconfigs] = true

        @scope = mkscope

        # make a rails resource
        railsresource "file", "/tmp/testing", :owner => "root", :group => "bin",
            :mode => "644" 

        run_collection_queries(:exported) do |string, result, query|
            code = nil
            str = nil

            # We don't support more than one search criteria at the moment.
            retval = nil
            bad = false
            # Figure out if the search is for anything rails will ignore
            if string =~ /\band\b|\bor\b/
                bad = true
            else
                bad = false
            end

            # And if it is, make sure we throw an error.
            if bad
                assert_raise(Puppet::ParseError, "Evaluated '#{string}'") do
                    str, code = query.evaluate :scope => @scope
                end
                next
            else
                assert_nothing_raised("Could not evaluate '#{string}'") do
                    str, code = query.evaluate :scope => @scope
                end
            end
            assert_nothing_raised("Could not find resource") do
                retval = Puppet::Rails::Resource.find(:all,
                    :include => {:param_values => :param_name},
                    :conditions => str) 
            end

            if result
                assert_equal(1, retval.length, "Did not find resource with '#{string}'")
                res = retval.shift

                assert_equal("file", res.restype)
                assert_equal("/tmp/testing", res.title)
            else
                assert_equal(0, retval.length, "found a resource with '#{string}'")
            end
        end
    end
end