spec/support/shared_examples/ridley_resource.rb in ridley-0.6.3 vs spec/support/shared_examples/ridley_resource.rb in ridley-0.7.0.beta

- old
+ new

@@ -1,7 +1,7 @@ shared_examples_for "a Ridley Resource" do |resource_klass| - let(:connection) { double('connection') } + let(:connection) { double('connection', hosted?: true) } let(:active_connection) { double('active-connection') } let(:response) { double('response') } describe "ClassMethods" do subject { resource_klass } @@ -97,44 +97,10 @@ end end subject { resource_klass.new(connection) } - describe "#attribute" do - it "returns the value of the attribute of the corresponding identifier" do - subject.attributes.each do |attr, value| - subject.attribute(attr).should eql(value) - end - end - end - - describe "#attribute=" do - it "assigns the desired to the attribute of the corresponding identifier" do - subject.attributes.each do |attr, value| - subject.send(:attribute=, attr, "testval") - end - - subject.attributes.each do |attr, value| - subject.attribute(attr).should eql("testval") - end - end - end - - describe "#attributes" do - it "returns a hash of attributes" do - subject.attributes.should be_a(Hash) - end - - it "includes attribute_defaults in the attributes" do - subject.class.stub(:attributes).and_return(Set.new([:val_one])) - subject.class.stub(:attribute_defaults).and_return(val_one: "value") - - subject.attributes.should have_key(:val_one) - subject.attributes[:val_one].should eql("value") - end - end - describe "#save" do context "when the object is valid" do before(:each) { subject.stub(:valid?).and_return(true) } it "sends a create message to the implementing class" do @@ -207,65 +173,9 @@ subject.class.attribute(:name) subject.class.stub(:chef_id) { :name } subject.attributes = { name: "reset" } subject.chef_id.should eql("reset") - end - end - - describe "#from_hash" do - before(:each) do - subject.class.attribute(:name) - @object = subject.from_hash(name: "reset") - end - - it "returns an instance of the implementing class" do - @object.should be_a(subject.class) - end - - it "assigns the attributes to the values of the corresponding keys in the given Hash" do - @object.name.should eql("reset") - end - end - - describe "#to_hash" do - it "returns a hash" do - subject.to_hash.should be_a(Hash) - end - - it "delegates to .attributes" do - subject.should_receive(:attributes) - - subject.to_hash - end - end - - describe "#to_json" do - it "serializes the objects attributes using MultiJson" do - MultiJson.should_receive(:encode).with(subject.attributes, kind_of(Hash)) - - subject.to_json - end - - it "returns the seralized value" do - MultiJson.stub(:encode).and_return("{}") - - subject.to_json.should eql("{}") - end - end - - describe "#from_json" do - before(:each) do - subject.class.attribute(:name) - @object = subject.from_json(%({"name": "reset"})) - end - - it "returns an instance of the implementing class" do - @object.should be_a(subject.class) - end - - it "assigns the attributes to the values of the corresponding keys in the given JSON" do - @object.name.should eql("reset") end end describe "#reload" do let(:updated_subject) { double('updated_subject', attributes: { fake_attribute: "some_value" }) }