require 'spec_helper' describe Stackster do it "should create a new entry object" do @simple_db_mock = mock 'simple db' config = Stackster::Config.new(:config => { 'access_key' => 'the-key', 'secret_key' => 'secret', 'region' => 'us-west-1' }) Stackster::AWS::SimpleDB.should_receive(:new).and_return @simple_db_mock @simple_db_mock.should_receive(:create_domain). with("stacks"). and_return true @simple_db_mock.should_receive(:select). with("select * from stacks where itemName() = 'test-stack-us-west-1'"). and_return('stack-to-find' => { 'attr1' => 'value1' }) entry = Stackster::Entry.new :config => config, :name => 'test-stack' entry.class.should == Stackster::Entry end it "should find the requested stack in simple db" do @simple_db_mock = mock 'simple db' config = Stackster::Config.new(:config => { 'access_key' => 'the-key', 'secret_key' => 'secret', 'region' => 'us-west-1' }) Stackster::AWS::SimpleDB.should_receive(:new).and_return @simple_db_mock @simple_db_mock.should_receive(:create_domain). with("stacks"). and_return true @simple_db_mock.should_receive(:select). with("select * from stacks where itemName() = 'stack-to-find-us-west-1'"). and_return('stack-to-find' => { 'attr1' => 'value1' }) Stackster::Entry.find :name => 'stack-to-find', :config => config end context "with stack object" do before do @config = Stackster::Config.new(:config => { 'access_key' => 'the-key', 'secret_key' => 'secret', 'region' => 'us-west-1' }) @simple_db_mock = mock 'simple db' Stackster::AWS::SimpleDB.should_receive(:new).and_return @simple_db_mock @simple_db_mock.should_receive(:create_domain). with("stacks"). and_return true @simple_db_mock.should_receive(:select). with("select * from stacks where itemName() = 'test-stack-us-west-1'"). and_return('test-stack' => { 'attr1' => 'value1' }) @entry = Stackster::Entry.new :config => @config, :name => 'test-stack' end it "should set the name to region-name for the stack" do @entry.name.should == 'test-stack-us-west-1' end it "should set the Name attribute to stack name before saving" it "should set the attributes in simple db" do @simple_db_mock.should_receive(:put_attributes). with("stacks", "test-stack-us-west-1", {"key"=>"value", "Name"=>"test-stack-us-west-1"}, {:replace=>["key", "Name"]}) @entry.attributes = {"key"=>"value"} @entry.save end it "should set the attributes" do @entry.attributes = {'key1' => 'value1' } @entry.set_attributes(['key2' => 'value2']) @entry.attributes.should == {'key1' => 'value1', 'key2' => 'value2' } end end end