diff options
author | Rick Bradley <rick@rickbradley.com> | 2008-04-02 19:29:04 -0500 |
---|---|---|
committer | Luke Kanies <luke@madstop.com> | 2008-04-11 13:11:28 -0500 |
commit | 93bc1a946f2da6e7c78a38ff90dac8a20b1bcbc7 (patch) | |
tree | af2894a72c59138abdf5a53bcf5e9d7b33948b29 /spec/integration/indirector | |
parent | 99b295b8301d7a89c97ecdc1d636c2d2b7f1ae8e (diff) | |
download | puppet-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/integration/indirector')
-rw-r--r-- | spec/integration/indirector/rest.rb | 93 |
1 files changed, 91 insertions, 2 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 |