spec/unit/document_spec.rb in friendly-0.3.5 vs spec/unit/document_spec.rb in friendly-0.4.0
- old
+ new
@@ -305,7 +305,54 @@
it "fills the collection with objects from the datastore" do
@collection.should have_received(:replace).with(@docs)
end
end
+
+ describe "creating a named_scope" do
+ before do
+ @scope_proxy = stub(:add_named => nil)
+ @klass.scope_proxy = @scope_proxy
+ @klass.named_scope(:by_name, :order => :name)
+ end
+
+ it "asks the named_scope_set to add it" do
+ @klass.scope_proxy.should have_received(:add_named).
+ with(:by_name, :order => :name)
+ end
+ end
+
+ describe "Document.has_named_scope?" do
+ it "delegates to the scope_proxy" do
+ @scope_proxy = stub
+ @scope_proxy.stubs(:has_named_scope?).with(:whatever).returns(true)
+ @klass.scope_proxy = @scope_proxy
+ @klass.has_named_scope?(:whatever).should be_true
+ end
+ end
+
+ describe "accessing an ad-hoc scope" do
+ before do
+ @scope = stub
+ @scope_proxy = stub
+ @scope_proxy.stubs(:ad_hoc).with(:order! => :name).returns(@scope)
+ @klass.scope_proxy = @scope_proxy
+ end
+
+ it "asks the named_scope_set to add it" do
+ @klass.scope(:order! => :name).should == @scope
+ end
+ end
+
+ describe "adding an association" do
+ before do
+ @assoc_set = stub(:add => nil)
+ @klass.association_set = @assoc_set
+ @klass.has_many :addresses
+ end
+
+ it "asks the association set to add it" do
+ @assoc_set.should have_received(:add).with(:addresses, {})
+ end
+ end
end