spec/economic/entity_spec.rb in rconomic-0.4 vs spec/economic/entity_spec.rb in rconomic-0.4.1
- old
+ new
@@ -1,9 +1,9 @@
require './spec/spec_helper'
class SpecEntity < Economic::Entity
- has_properties :foo, :baz
+ has_properties :id, :foo, :baz
def existing_method; end
def proxy; Economic::SpecEntityProxy.new(session); end
end
@@ -62,12 +62,12 @@
subject.expects(:define_method).with('number').never
subject.expects(:define_method).with('handle').never
subject.has_properties :id, :number, :handle
end
- it "does not clobber existing methods" do
- subject.expects(:define_method).with('existing_method').never
+ it "does clobber existing methods" do
+ subject.expects(:define_method).with('existing_method')
subject.has_properties :existing_method
end
describe "properties created with has_properties" do
end
@@ -213,35 +213,63 @@
subject.update_properties(:foo => 'bar', 'baz' => 'qux')
end
end
describe "equality" do
+ subject { SpecEntity.new }
+ let(:other) { SpecEntity.new }
+
context "when other is nil do" do
- let(:other) { nil }
+ it { should_not == nil }
+ end
- it "should return true" do
+ context "when both handles are empty" do
+ it "returns false" do
+ subject.handle = Economic::Entity::Handle.new({})
+ other.handle = Economic::Entity::Handle.new({})
+
subject.should_not == other
end
end
+ context "when self handle isn't present" do
+ it "returns false" do
+ subject.handle = nil
+ subject.should_not == other
+ end
+ end
+
+ context "when other handle isn't present" do
+ it "returns false" do
+ other.handle = nil
+ subject.should_not == other
+ end
+ end
+
context "when other handle is equal" do
- context "when other is same class" do
- let(:other) { Economic::Entity.new(:session => session, :handle => subject.handle) }
+ let(:handle) { Economic::Entity::Handle.new(:id => 42) }
+ subject { Economic::Debtor.new(:handle => handle) }
+ context "when other is another class" do
+ it "should return false" do
+ other = Economic::CashBook.new(:handle => handle)
+ subject.should_not == other
+ end
+ end
+
+ context "when other is same class" do
it "should return true" do
+ other = Economic::Debtor.new(:handle => handle)
subject.should == other
end
end
context "when other is child class" do
- let(:other) { Economic::Debtor.new(:session => session, :handle => subject.handle) }
-
it "should return true" do
- subject.should == other
+ one = Economic::Entity.new(:handle => handle)
+ other = SpecEntity.new(:handle => handle)
+ one.should == other
end
end
end
-
-
-
end
end