spec/ripple/document_spec.rb in ripple-0.9.5 vs spec/ripple/document_spec.rb in ripple-1.0.0.beta
- old
+ new
@@ -1,22 +1,9 @@
-# Copyright 2010 Sean Cribbs, Sonian Inc., and Basho Technologies, Inc.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-require File.expand_path("../spec_helper", File.dirname(__FILE__))
+require 'spec_helper'
describe Ripple::Document do
- require 'support/models/page'
+ # require 'support/models/page'
it "should add bucket access methods to classes when included" do
(class << Page; self; end).included_modules.should include(Ripple::Document::BucketAccess)
Page.should respond_to(:bucket_name)
Page.should respond_to(:bucket)
@@ -36,25 +23,53 @@
@sub = Homepage.new
@error = ErrorPage.new
[@doc,@doc2,@sub,@error].each {|d| d.key = "root"; d.stub!(:new?).and_return(false) }
end
- it "should be equal if the same object" do
+ it "should be == and eql? if the same object, and have the same hash key" do
@doc.should == @doc
+ @doc.should eql(@doc)
+ @doc.hash.should == @doc.hash
end
- it "should be equal if instance of same class and key" do
+ it "should be == and eql? and have the same hash key if instance of same class and key" do
@doc.should == @doc2
+ @doc2.should == @doc
+ @doc.should eql(@doc2)
+ @doc2.should eql(@doc)
+ @doc.hash.should == @doc2.hash
+ end
+
+ it "should be == but not eql? and have different hash keys if they have the same key but one is a subclass of the other" do
@doc.should == @sub
+ @sub.should == @doc
+
+ @doc.should_not eql(@sub)
+ @sub.should_not eql(@doc)
+
+ @doc.hash.should_not == @sub.hash
end
- it "should be equal if of the same bucket and key" do
+ it "should be == but not eql? and have different hash keys if of the same bucket and key" do
@doc.should == @error
+ @error.should == @doc
+
+ @doc.should_not eql(@error)
+ @error.should_not eql(@doc)
+
+ @doc.hash.should_not == @error.hash
+ @error.hash.should_not == @doc.hash
end
- it "should not be equal if new record" do
+ it "should not be == or eql? or have the same hash key if new record" do
@doc2.stub!(:new?).and_return(true)
@doc.should_not == @doc2
+ @doc2.should_not == @doc
+
+ @doc.should_not eql(@doc2)
+ @doc2.should_not eql(@doc)
+
+ @doc.hash.should_not == @doc2.hash
end
end
describe "ActiveModel compatibility" do
include ActiveModel::Lint::Tests