spec/unit/router_spec.rb in restfulness-0.2.4 vs spec/unit/router_spec.rb in restfulness-0.2.5

- old
+ new

@@ -20,11 +20,10 @@ obj = klass.new obj.routes.should eql([]) end it "should prepare routes with instance eval block" do - block = lambda {} obj = klass.new do @foo = 'bar' end obj.instance_variable_get(:@foo).should eql('bar') end @@ -37,9 +36,50 @@ obj.add 'projects', resource obj.routes.length.should eql(1) route = obj.routes.first route.should be_a(Restfulness::Route) route.path.should eql(['projects']) + end + end + + describe "#scope" do + it "should append to the current_scope attribute in block and reset" do + obj = klass.new + subscope = nil # Can't use rspec inside instance eval! + obj.scope 'api' do + subscope = current_scope + end + subscope.should eql(['api']) + obj.current_scope.should eql([]) + end + + it "should add scope properties to add call" do + obj = klass.new + res = resource + obj.scope 'api' do + add 'projects', res + end + route = obj.routes.first + route.path.should eql(['api', 'projects']) + end + + it "should allow for scopes within scopes" do + obj = klass.new + res = resource + subscope = nil + subsubscope = nil + obj.scope 'api' do + scope 'projects' do + add 'active', res + subsubscope = current_scope + end + subscope = current_scope + end + subsubscope.should eql(['api', 'projects']) + subscope.should eql(['api']) + obj.current_scope.should eql([]) + route = obj.routes.first + route.path.should eql(['api', 'projects', 'active']) end end describe "#route_for" do let :obj do