summaryrefslogtreecommitdiffstats
path: root/spec/unit/rails
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/rails
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/rails')
-rwxr-xr-xspec/unit/rails/host.rb91
1 files changed, 91 insertions, 0 deletions
diff --git a/spec/unit/rails/host.rb b/spec/unit/rails/host.rb
new file mode 100755
index 000000000..882abbd5a
--- /dev/null
+++ b/spec/unit/rails/host.rb
@@ -0,0 +1,91 @@
+#!/usr/bin/env ruby
+
+require File.dirname(__FILE__) + '/../../spec_helper'
+
+describe "Puppet::Rails::Host" 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/host'
+
+ # Stub this so we don't need access to the DB.
+ Puppet::Rails::Host.stubs(:columns).returns([column("name", "string"), column("environment", "string"), column("ip", "string")])
+
+ @node = Puppet::Node.new("foo")
+ @node.environment = "production"
+ @node.ipaddress = "127.0.0.1"
+
+ @host = stub 'host', :environment= => nil, :ip= => nil
+ end
+
+ describe "when converting a Puppet::Node instance into a Rails instance" do
+ it "should modify any existing instance in the database" do
+ Puppet::Rails::Host.expects(:find_by_name).with("foo").returns @host
+
+ Puppet::Rails::Host.from_puppet(@node)
+ end
+
+ it "should create a new instance in the database if none can be found" do
+ Puppet::Rails::Host.expects(:find_by_name).with("foo").returns nil
+ Puppet::Rails::Host.expects(:new).with(:name => "foo").returns @host
+
+ Puppet::Rails::Host.from_puppet(@node)
+ end
+
+ it "should copy the environment from the Puppet instance" do
+ Puppet::Rails::Host.expects(:find_by_name).with("foo").returns @host
+
+ @node.environment = "production"
+ @host.expects(:environment=).with "production"
+
+ Puppet::Rails::Host.from_puppet(@node)
+ end
+
+ it "should copy the ipaddress from the Puppet instance" do
+ Puppet::Rails::Host.expects(:find_by_name).with("foo").returns @host
+
+ @node.ipaddress = "192.168.0.1"
+ @host.expects(:ip=).with "192.168.0.1"
+
+ Puppet::Rails::Host.from_puppet(@node)
+ end
+
+ it "should not save the Rails instance" do
+ Puppet::Rails::Host.expects(:find_by_name).with("foo").returns @host
+
+ @host.expects(:save).never
+
+ Puppet::Rails::Host.from_puppet(@node)
+ end
+ end
+
+ describe "when converting a Puppet::Rails::Host instance into a Puppet::Node instance" do
+ before do
+ @host = Puppet::Rails::Host.new(:name => "foo", :environment => "production", :ip => "127.0.0.1")
+ @node = Puppet::Node.new("foo")
+ Puppet::Node.stubs(:new).with("foo").returns @node
+ end
+
+ it "should create a new instance with the correct name" do
+ Puppet::Node.expects(:new).with("foo").returns @node
+
+ @host.to_puppet
+ end
+
+ it "should copy the environment from the Rails instance" do
+ @host.environment = "prod"
+ @node.expects(:environment=).with "prod"
+ @host.to_puppet
+ end
+
+ it "should copy the ipaddress from the Rails instance" do
+ @host.ip = "192.168.0.1"
+ @node.expects(:ipaddress=).with "192.168.0.1"
+ @host.to_puppet
+ end
+ end
+end