File: param_value_spec.rb

package info (click to toggle)
puppet 3.7.2-4
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 18,896 kB
  • sloc: ruby: 210,387; sh: 2,050; xml: 1,554; lisp: 300; makefile: 142; python: 108; sql: 103; yacc: 72
file content (46 lines) | stat: -rwxr-xr-x 1,606 bytes parent folder | download | duplicates (3)
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
#! /usr/bin/env ruby
require 'spec_helper'
require 'puppet/rails'

describe "Puppet::Rails::ParamValue", :if => can_use_scratch_database? do
  before do
    require 'puppet/rails/param_value'
    setup_scratch_database

    # Stub this so we don't need access to the DB.
    name = stub 'param_name', :name => "foo"
    Puppet::Rails::ParamName.stubs(:find_or_create_by_name).returns(name)
  end

  after do
    Puppet::Rails.teardown
  end

  describe "when creating initial parameter values" do
    it "should return an array of hashes" do
      Puppet::Rails::ParamValue.from_parser_param(:myparam, %w{a b})[0].should be_instance_of(Hash)
    end

    it "should return hashes for each value with the parameter name set as the ParamName instance" do
      name = stub 'param_name', :name => "foo"
      Puppet::Rails::ParamName.expects(:find_or_create_by_name).returns(name)

      result = Puppet::Rails::ParamValue.from_parser_param(:myparam, "a")[0]
      result[:value].should == "a"
      result[:param_name].should == name
    end

    it "should return an array of hashes even when only one parameter is provided" do
      Puppet::Rails::ParamValue.from_parser_param(:myparam, "a")[0].should be_instance_of(Hash)
    end

    it "should convert all arguments into strings" do
      Puppet::Rails::ParamValue.from_parser_param(:myparam, 50)[0][:value].should == "50"
    end

    it "should not convert Resource References into strings" do
      ref = Puppet::Resource.new(:file, "/file")
      Puppet::Rails::ParamValue.from_parser_param(:myparam, ref)[0][:value].should == ref
    end
  end
end