~ubuntu-branches/ubuntu/lucid/puppet/lucid

« back to all changes in this revision

Viewing changes to spec/unit/rails/param_value.rb

  • Committer: Bazaar Package Importer
  • Author(s): Chuck Short
  • Date: 2009-12-23 00:48:10 UTC
  • mfrom: (1.1.10 upstream) (3.1.7 squeeze)
  • Revision ID: james.westby@ubuntu.com-20091223004810-3i4oryds922g5n59
Tags: 0.25.1-3ubuntu1
* Merge from debian testing.  Remaining changes:
  - debian/rules:
    + Don't start puppet when first installing puppet.
  - debian/puppet.conf, lib/puppet/defaults.rb:
    + Move templates to /etc/puppet
  - lib/puppet/defaults.rb:
    + Fix /var/lib/puppet/state ownership.
  - man/man8/puppet.conf.8: 
    + Fix broken URL in manpage.
  - debian/control:
    + Update maintainer accordint to spec.
    + Puppetmaster Recommends -> Suggests
    + Created puppet-testsuite as a seperate. Allow the users to run puppet's 
      testsuite.
  - tests/Rakefile: Fix rakefile so that the testsuite can acutally be ran.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env ruby
 
2
 
 
3
require File.dirname(__FILE__) + '/../../spec_helper'
 
4
 
 
5
describe "Puppet::Rails::ParamValue" do
 
6
    confine "Cannot test without ActiveRecord" => Puppet.features.rails?
 
7
 
 
8
    def column(name, type)
 
9
        ActiveRecord::ConnectionAdapters::Column.new(name, nil, type, false)
 
10
    end
 
11
 
 
12
    before do
 
13
        require 'puppet/rails/param_value'
 
14
 
 
15
        name = stub 'param_name', :name => "foo"
 
16
 
 
17
        # Stub this so we don't need access to the DB.
 
18
        Puppet::Rails::ParamValue.stubs(:columns).returns([column("value", "string")])
 
19
        Puppet::Rails::ParamName.stubs(:find_or_create_by_name).returns(name)
 
20
    end
 
21
 
 
22
    describe "when creating initial parameter values" do
 
23
        it "should return an array of hashes" do
 
24
            Puppet::Rails::ParamValue.from_parser_param(:myparam, %w{a b})[0].should be_instance_of(Hash)
 
25
        end
 
26
 
 
27
        it "should return hashes for each value with the parameter name set as the ParamName instance" do
 
28
            name = stub 'param_name', :name => "foo"
 
29
            Puppet::Rails::ParamName.expects(:find_or_create_by_name).returns(name)
 
30
 
 
31
            result = Puppet::Rails::ParamValue.from_parser_param(:myparam, "a")[0]
 
32
            result[:value].should == "a"
 
33
            result[:param_name].should == name
 
34
        end
 
35
 
 
36
        it "should return an array of hashes even when only one parameter is provided" do
 
37
            Puppet::Rails::ParamValue.from_parser_param(:myparam, "a")[0].should be_instance_of(Hash)
 
38
        end
 
39
 
 
40
        it "should convert all arguments into strings" do
 
41
            Puppet::Rails::ParamValue.from_parser_param(:myparam, 50)[0][:value].should == "50"
 
42
        end
 
43
 
 
44
        it "should not convert Resource References into strings" do
 
45
            ref = Puppet::Resource::Reference.new(:file, "/file")
 
46
            Puppet::Rails::ParamValue.from_parser_param(:myparam, ref)[0][:value].should == ref
 
47
        end
 
48
    end
 
49
end