summaryrefslogtreecommitdiffstats
path: root/spec/unit/indirector/facts
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2009-04-06 16:38:14 -0500
committerJames Turnbull <james@lovedthanlost.net>2009-04-22 14:39:35 +1000
commitb9c95ebf81eeb78297003de2d0ed4ca048412393 (patch)
tree184d2f5c693c6183ac59414ff339553744d110cd /spec/unit/indirector/facts
parent8d0e9976b199a637d82d70701db6c682a89b9d6a (diff)
downloadpuppet-b9c95ebf81eeb78297003de2d0ed4ca048412393.tar.gz
puppet-b9c95ebf81eeb78297003de2d0ed4ca048412393.tar.xz
puppet-b9c95ebf81eeb78297003de2d0ed4ca048412393.zip
Adding ActiveRecord terminus classes for Node and Facts.
This is most of the way to replacing standard StoreConfigs integration with the Indirector. We still need to convert the Catalog and then change all of the integraiton points (which is mostly the 'store' call in the Compiler). Signed-off-by: Luke Kanies <luke@madstop.com>
Diffstat (limited to 'spec/unit/indirector/facts')
-rwxr-xr-xspec/unit/indirector/facts/active_record.rb103
1 files changed, 103 insertions, 0 deletions
diff --git a/spec/unit/indirector/facts/active_record.rb b/spec/unit/indirector/facts/active_record.rb
new file mode 100755
index 000000000..340f2cf4c
--- /dev/null
+++ b/spec/unit/indirector/facts/active_record.rb
@@ -0,0 +1,103 @@
+#!/usr/bin/env ruby
+
+require File.dirname(__FILE__) + '/../../../spec_helper'
+
+require 'puppet/node/facts'
+require 'puppet/indirector/facts/active_record'
+
+describe Puppet::Node::Facts::ActiveRecord do
+ confine "Missing Rails" => Puppet.features.rails?
+
+ before do
+ Puppet.features.stubs(:rails?).returns true
+ @terminus = Puppet::Node::Facts::ActiveRecord.new
+ end
+
+ it "should be a subclass of the ActiveRecord terminus class" do
+ Puppet::Node::Facts::ActiveRecord.ancestors.should be_include(Puppet::Indirector::ActiveRecord)
+ end
+
+ it "should use Puppet::Rails::Host as its ActiveRecord model" do
+ Puppet::Node::Facts::ActiveRecord.ar_model.should equal(Puppet::Rails::Host)
+ end
+
+ describe "when finding an instance" do
+ before do
+ @request = stub 'request', :key => "foo"
+ end
+
+ it "should use the Hosts ActiveRecord class to find the host" do
+ Puppet::Rails::Host.expects(:find_by_name).with { |key, args| key == "foo" }
+ @terminus.find(@request)
+ end
+
+ it "should include the fact names and values when finding the host" do
+ Puppet::Rails::Host.expects(:find_by_name).with { |key, args| args[:include] == {:fact_values => :fact_name} }
+ @terminus.find(@request)
+ end
+
+ it "should return nil if no host instance can be found" do
+ Puppet::Rails::Host.expects(:find_by_name).returns nil
+
+ @terminus.find(@request).should be_nil
+ end
+
+ it "should convert the node's parameters into a Facts instance if a host instance is found" do
+ host = stub 'host', :name => "foo"
+ host.expects(:get_facts_hash).returns("one" => [mock("two_value", :value => "two")], "three" => [mock("three_value", :value => "four")])
+
+ Puppet::Rails::Host.expects(:find_by_name).returns host
+
+ result = @terminus.find(@request)
+
+ result.should be_instance_of(Puppet::Node::Facts)
+ result.name.should == "foo"
+ result.values.should == {"one" => "two", "three" => "four"}
+ end
+
+ it "should convert all single-member arrays into non-arrays" do
+ host = stub 'host', :name => "foo"
+ host.expects(:get_facts_hash).returns("one" => [mock("two_value", :value => "two")])
+
+ Puppet::Rails::Host.expects(:find_by_name).returns host
+
+ @terminus.find(@request).values["one"].should == "two"
+ end
+ end
+
+ describe "when saving an instance" do
+ before do
+ @host = stub 'host', :name => "foo", :save => nil, :setfacts => nil
+ Puppet::Rails::Host.stubs(:find_by_name).returns @host
+ @facts = Puppet::Node::Facts.new("foo", "one" => "two", "three" => "four")
+ @request = stub 'request', :key => "foo", :instance => @facts
+ end
+
+ it "should find the Rails host with the same name" do
+ Puppet::Rails::Host.expects(:find_by_name).with("foo").returns @host
+
+ @terminus.save(@request)
+ end
+
+ it "should create a new Rails host if none can be found" do
+ Puppet::Rails::Host.expects(:find_by_name).with("foo").returns nil
+
+ Puppet::Rails::Host.expects(:create).with(:name => "foo").returns @host
+
+ @terminus.save(@request)
+ end
+
+ it "should set the facts as facts on the Rails host instance" do
+ # There is other stuff added to the hash.
+ @host.expects(:setfacts).with { |args| args["one"] == "two" and args["three"] == "four" }
+
+ @terminus.save(@request)
+ end
+
+ it "should save the Rails host instance" do
+ @host.expects(:save)
+
+ @terminus.save(@request)
+ end
+ end
+end