spec/amfetamine/conditions_spec.rb in amfetamine-0.2.9 vs spec/amfetamine/conditions_spec.rb in amfetamine-0.2.11

- old
+ new

@@ -1,31 +1,37 @@ require 'spec_helper' describe "Amfetamine REST Helpers with conditions" do it "should work regular #all" do + # TODO: Throw away and rewrite. Pfft. Dummy.cache.flush # Just to be uber sure query = {:title => 'Dummy'} dummy = build(:dummy) dummy.instance_variable_set('@notsaved',false) result = nil - stub_conditional_all_response(query, dummy) do + + Dummy.prevent_external_connections! do |rc| + rc.get { [dummy]} result = Dummy.all(:conditions => query) end + result2 = Dummy.all(:conditions => query) # No errors raised means it got it from the cache result.should == result2 result.should include(dummy) + Dummy.prevent_external_connections! do |resource| resource.delete {} dummy.destroy end - lambda {Dummy.all(:conditions => query) }.should raise_exception(FakeWeb::NetConnectNotAllowedError) + lambda {Dummy.all(:conditions => query) }.should raise_exception end it "should work with nested resource #all" do + # TODO: Throw away and rewrite Dummy.cache.flush # Just to be uber sure Child.cache.flush query = {:title => 'Child'} dummy = build(:dummy) @@ -34,25 +40,27 @@ dummy.instance_variable_set('@notsaved',false) child.instance_variable_set('@notsaved',false) result = nil - stub_conditional_nested_all_response(dummy, query, child) do + Child.prevent_external_connections! do |r| + r.get(path: "/dummies/#{dummy.id}/children") {[child]} result = dummy.children.all(:conditions => query) end result2 = dummy.children.all(:conditions => query) # No errors raised means it got it from the cache result.should == result2 result.should include(child) - stub_delete_response(child) do + Child.prevent_external_connections! do |r| + r.delete {} child.destroy end child.should_not be_cached - lambda {dummy.children.all(:conditions => query, :force => true) }.should raise_exception(FakeWeb::NetConnectNotAllowedError) + lambda {dummy.children.all(:conditions => query, :force => true) }.should raise_exception end it "should work with normal resource #find" do dummy = build(:dummy) query = { :title => 'Dummy' } @@ -90,19 +98,21 @@ dummy.instance_variable_set('@notsaved',false) child.instance_variable_set('@notsaved',false) result = nil - stub_conditional_nested_single_response(dummy,child, query) do + Child.prevent_external_connections! do |r| + r.get { child } result = dummy.children.find(dummy.id, :conditions => query) end result.should == child result2 = dummy.children.find(dummy.id, :conditions => query) result2.should == result - stub_delete_response(child) do + Child.prevent_external_connections! do |r| + r.delete {} child.destroy end child.should_not be_cached end