summaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorRick Bradley <rick@rickbradley.com>2008-04-02 19:29:04 -0500
committerLuke Kanies <luke@madstop.com>2008-04-11 13:11:28 -0500
commit93bc1a946f2da6e7c78a38ff90dac8a20b1bcbc7 (patch)
treeaf2894a72c59138abdf5a53bcf5e9d7b33948b29 /spec
parent99b295b8301d7a89c97ecdc1d636c2d2b7f1ae8e (diff)
downloadpuppet-93bc1a946f2da6e7c78a38ff90dac8a20b1bcbc7.tar.gz
puppet-93bc1a946f2da6e7c78a38ff90dac8a20b1bcbc7.tar.xz
puppet-93bc1a946f2da6e7c78a38ff90dac8a20b1bcbc7.zip
adding REST save support, with integration tests. A handful of unit tests in that area now need to be updated.
Diffstat (limited to 'spec')
-rw-r--r--spec/integration/indirector/rest.rb93
-rw-r--r--spec/unit/network/server.rb2
2 files changed, 91 insertions, 4 deletions
diff --git a/spec/integration/indirector/rest.rb b/spec/integration/indirector/rest.rb
index 46a26ee91..a969a975b 100644
--- a/spec/integration/indirector/rest.rb
+++ b/spec/integration/indirector/rest.rb
@@ -9,6 +9,7 @@ class Puppet::TestIndirectedFoo
indirects :test_indirected_foo, :terminus_setting => :test_indirected_foo_terminus
attr_reader :value
+ attr_accessor :version
def initialize(value = 0)
@value = value
@@ -17,6 +18,10 @@ class Puppet::TestIndirectedFoo
def self.from_yaml(yaml)
YAML.load(yaml)
end
+
+ def name
+ "bob"
+ end
end
# empty Terminus class -- this would normally have to be in a directory findable by the autoloader, but we short-circuit that below
@@ -186,7 +191,49 @@ describe Puppet::Indirector::REST do
end
describe "when saving a model instance over REST" do
- it "needs more specs"
+ before :each do
+ @instance = Puppet::TestIndirectedFoo.new(42)
+ @mock_model = stub('faked model', :from_yaml => @instance)
+ Puppet::Network::HTTP::WEBrickREST.any_instance.stubs(:model).returns(@mock_model)
+ Puppet::Network::HTTP::WEBrickREST.any_instance.stubs(:save_object).returns(@instance)
+ end
+
+ describe "when a successful save can be performed" do
+ before :each do
+ end
+
+ it "should not fail" do
+ lambda { @instance.save }.should_not raise_error
+ end
+
+ it 'should return an instance of the model class' do
+ @instance.save.class.should == Puppet::TestIndirectedFoo
+ end
+
+ it 'should return a matching instance of the model class' do
+ @instance.save.value.should == @instance.value
+ end
+ end
+
+ describe "when a save cannot be completed" do
+ before :each do
+ Puppet::Network::HTTP::WEBrickREST.any_instance.stubs(:save_object).returns(false)
+ end
+
+ it "should return failure" do
+ @instance.save.should == false
+ end
+ end
+
+ describe "when an exception is encountered in performing a save" do
+ before :each do
+ Puppet::Network::HTTP::WEBrickREST.any_instance.stubs(:save_object).raises(RuntimeError)
+ end
+
+ it "should raise an exception" do
+ lambda { @instance.save }.should raise_error(RuntimeError)
+ end
+ end
end
after :each do
@@ -357,7 +404,49 @@ describe Puppet::Indirector::REST do
end
describe "when saving a model instance over REST" do
- it "needs more specs"
+ before :each do
+ @instance = Puppet::TestIndirectedFoo.new(42)
+ @mock_model = stub('faked model', :from_yaml => @instance)
+ Puppet::Network::HTTP::MongrelREST.any_instance.stubs(:model).returns(@mock_model)
+ Puppet::Network::HTTP::MongrelREST.any_instance.stubs(:save_object).returns(@instance)
+ end
+
+ describe "when a successful save can be performed" do
+ before :each do
+ end
+
+ it "should not fail" do
+ lambda { @instance.save }.should_not raise_error
+ end
+
+ it 'should return an instance of the model class' do
+ @instance.save.class.should == Puppet::TestIndirectedFoo
+ end
+
+ it 'should return a matching instance of the model class' do
+ @instance.save.value.should == @instance.value
+ end
+ end
+
+ describe "when a save cannot be completed" do
+ before :each do
+ Puppet::Network::HTTP::MongrelREST.any_instance.stubs(:save_object).returns(false)
+ end
+
+ it "should return failure" do
+ @instance.save.should == false
+ end
+ end
+
+ describe "when an exception is encountered in performing a save" do
+ before :each do
+ Puppet::Network::HTTP::MongrelREST.any_instance.stubs(:save_object).raises(RuntimeError)
+ end
+
+ it "should raise an exception" do
+ lambda { @instance.save }.should raise_error(RuntimeError)
+ end
+ end
end
after :each do
diff --git a/spec/unit/network/server.rb b/spec/unit/network/server.rb
index 2e02ffbc3..4e47c22fd 100644
--- a/spec/unit/network/server.rb
+++ b/spec/unit/network/server.rb
@@ -309,8 +309,6 @@ end
describe Class.new, "put these somewhere" do
- it "should allow indirections to deny access to services based upon which client is connecting, or whether the client is authorized"
- it "should deny access to clients based upon rules"
it "should have the ability to use a class-level from_ hook (from_yaml, from_text, etc.) that can be called, based on content-type header, to allow for different deserializations of an object"
it "should allow from_* on the inbound :data packet (look at its content_type) when doing a PUT/.new.save"
it "should prepend a rest version number on the path (w00t)"