summaryrefslogtreecommitdiffstats
path: root/spec/unit/rails/resource.rb
blob: eaead2e3daba7c706d116b87b8c2e69676a56cb6 (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
#!/usr/bin/env ruby

require File.dirname(__FILE__) + '/../../spec_helper'

describe "Puppet::Rails::Resource" do
    confine "Cannot test without ActiveRecord" => Puppet.features.rails?

    def column(name, type)
        ActiveRecord::ConnectionAdapters::Column.new(name, nil, type, false)
    end

    before do
        require 'puppet/rails/resource'

        # Stub this so we don't need access to the DB.
        Puppet::Rails::Resource.stubs(:columns).returns([column("title", "string"), column("restype", "string"), column("exported", "boolean")])
    end

    describe "when creating initial resource arguments" do
        it "should set the restype to the resource's type" do
            Puppet::Rails::Resource.rails_resource_initial_args(Puppet::Resource.new(:file, "/file"))[:restype].should == "File"
        end

        it "should set the title to the resource's title" do
            Puppet::Rails::Resource.rails_resource_initial_args(Puppet::Resource.new(:file, "/file"))[:title].should == "/file"
        end

        it "should set the line to the resource's line if one is available" do
            resource = Puppet::Resource.new(:file, "/file")
            resource.line = 50

            Puppet::Rails::Resource.rails_resource_initial_args(resource)[:line].should == 50
        end

        it "should set 'exported' to true of the resource is exported" do
            resource = Puppet::Resource.new(:file, "/file")
            resource.exported = true

            Puppet::Rails::Resource.rails_resource_initial_args(resource)[:exported].should be_true
        end
    end
end