3
require File.dirname(__FILE__) + '/../../spec_helper'
5
describe "Puppet::Rails::ParamValue" do
6
confine "Cannot test without ActiveRecord" => Puppet.features.rails?
9
ActiveRecord::ConnectionAdapters::Column.new(name, nil, type, false)
13
require 'puppet/rails/param_value'
15
name = stub 'param_name', :name => "foo"
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)
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)
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)
31
result = Puppet::Rails::ParamValue.from_parser_param(:myparam, "a")[0]
32
result[:value].should == "a"
33
result[:param_name].should == name
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)
40
it "should convert all arguments into strings" do
41
Puppet::Rails::ParamValue.from_parser_param(:myparam, 50)[0][:value].should == "50"
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