spec/harpy/resource_spec.rb in harpy-0.1.12 vs spec/harpy/resource_spec.rb in harpy-0.1.13
- old
+ new
@@ -481,15 +481,11 @@
end
end
describe "#inspect" do
subject { Harpy::Spec::Company.new "firstname" => "Anthony" }
it "shows class name, attributes, errors and persisted state" do
- if RUBY_VERSION.to_f < 1.9
- subject.inspect.should == '<Harpy::Spec::Company @attrs:{"firstname"=>"Anthony"} @errors:#<OrderedHash {}> persisted:false>'
- else
- subject.inspect.should == '<Harpy::Spec::Company @attrs:{"firstname"=>"Anthony"} @errors:{} persisted:false>'
- end
+ subject.inspect.should == '<Harpy::Spec::Company @attrs:{"firstname"=>"Anthony"} @errors:[] persisted:false>'
end
end
describe "#has_key?(key)" do
it "is true when attribute is present" do
subject.has_key?("link").should be_true
@@ -600,11 +596,11 @@
}
eos
Harpy.client.should_receive(:post).with(url, :body => body).and_return response
subject.save.should be_false
subject.callbacks.should =~ [:save, :create]
- subject.should have(1).error
+ subject.should have(2).errors
subject.errors[:lastname].should =~ ["can't be blank", "must be unique"]
subject.firstname.should be_nil
subject.company_name.should == "Stark Enterprises"
end
it "delegates other response codes to client" do
@@ -677,11 +673,11 @@
}
eos
Harpy.client.should_receive(:put).with(url, :body => body).and_return response
subject.save.should be_false
subject.callbacks.should =~ [:save, :update]
- subject.should have(1).error
+ subject.should have(2).errors
subject.errors[:lastname].should =~ ["can't be blank", "must be unique"]
lambda { subject.firstname }.should raise_error NoMethodError
subject.company_name.should == "Stark Enterprises"
end
it "delegates other response codes to client" do
@@ -751,11 +747,11 @@
}
eos
Harpy.client.should_receive(:delete).with(url).and_return response
subject.destroy.should be_false
subject.callbacks.should =~ [:destroy]
- subject.should have(1).error
+ subject.should have(2).errors
subject.errors[:lastname].should =~ ["can't be blank", "must be unique"]
lambda { subject.firstname }.should raise_error NoMethodError
subject.company_name.should == "Stark Enterprises"
end
it "delegates other response codes to client" do
@@ -763,8 +759,30 @@
Harpy.client.should_receive(:delete).with(url).and_return response
Harpy.client.should_receive(:invalid_code).with(response)
subject.destroy
subject.callbacks.should =~ [:destroy]
end
+ end
+ end
+ describe "equality" do
+ it "is equal to itself even without urn" do
+ company1 = Harpy::Spec::Company.new
+ company2 = company1
+ company1.should == company2
+ end
+ it "two instances without urn are not equal" do
+ company1 = Harpy::Spec::Company.new
+ company2 = Harpy::Spec::Company.new
+ company1.should_not == company2
+ end
+ it "two instances of the same class with the same urn are equal" do
+ company1 = Harpy::Spec::Company.new "urn" => "urn:harpy:company:1"
+ company2 = Harpy::Spec::Company.new "urn" => "urn:harpy:company:1"
+ company1.should == company2
+ end
+ it "two instances of the same class with different urns are not equal" do
+ company1 = Harpy::Spec::Company.new "urn" => "urn:harpy:company:1"
+ company2 = Harpy::Spec::Company.new "urn" => "urn:harpy:company:2"
+ company1.should_not == company2
end
end
end
\ No newline at end of file