Changeset 242
- Timestamp:
- 05/27/07 14:49:11 (2 years ago)
- Files:
-
- trunk/TODO (modified) (1 diff)
- trunk/lib/merb.rb (modified) (1 diff)
- trunk/lib/merb/merb_controller.rb (modified) (1 diff)
- trunk/lib/merb/mixins/render_mixin.rb (modified) (1 diff)
- trunk/specs/fixtures/controllers (added)
- trunk/specs/fixtures/controllers/dispatch_spec_controllers.rb (added)
- trunk/specs/merb/merb_controller_filters_spec.rb (modified) (3 diffs)
- trunk/specs/merb/merb_controller_spec.rb (modified) (6 diffs)
- trunk/specs/merb/merb_dispatch_spec.rb (modified) (55 diffs)
- trunk/specs/merb/merb_rendering_spec.rb (added)
- trunk/specs/merb/merb_responder_spec.rb (modified) (28 diffs)
- trunk/specs/merb/merb_view_context_spec.rb (modified) (3 diffs)
- trunk/specs/spec_helper.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/TODO
r135 r242 1 1 [TODO] 2 * Irb Console **DONE** 3 * Migrations **DONE** 4 * Helpers 5 * config file **DONE** 6 * session 7 ** AR ** DONE ** 8 ** DRb 9 * Rails integration 10 * Text backend? 11 * plugins support(rails plugins too?) 12 * Layouts **DONE** 13 * auto template_dir **DONE** 14 * before/after filters **DONE** 15 * merbjs **DONE** 16 * testing 2 * more specs for Template engines and Rendering 3 * trunk/lib/merb.rb
r241 r242 52 52 DIST_ROOT = Merb::Server.dist_root || Dir.pwd+'/dist' 53 53 MERB_ENV = Merb::Server.config[:environment] 54 MERB_VIEW_ROOT = MERB_ROOT / "dist/app/views" 54 55 55 56 logpath = $TESTING ? "/tmp/merb_test.log" : "#{MERB_ROOT}/log/merb.#{Merb::Server.port}.log" trunk/lib/merb/merb_controller.rb
r238 r242 22 22 self._session_id_key = :_session_id 23 23 self._template_extensions = { } 24 self._template_root = File.expand_path(MERB_ ROOT / "dist/app/views")25 self._layout_root = File.expand_path(MERB_ ROOT / "dist/app/views/layout")24 self._template_root = File.expand_path(MERB_VIEW_ROOT) 25 self._layout_root = File.expand_path(MERB_VIEW_ROOT / "layout") 26 26 27 27 include Merb::ControllerMixin trunk/lib/merb/mixins/render_mixin.rb
r240 r242 165 165 def find_template(opts={}) 166 166 if template = opts[:template] 167 path = MERB_ ROOT / "dist/app/views"/ template167 path = MERB_VIEW_ROOT / template 168 168 elsif action = opts[:action] 169 169 path = 170 File.expand_path(MERB_ ROOT / "dist/app/views"/ self.class.name.snake_case / action)170 File.expand_path(MERB_VIEW_ROOT / self.class.name.snake_case / action) 171 171 elsif _layout = opts[:layout] 172 172 path = _layout_root / _layout trunk/specs/merb/merb_controller_filters_spec.rb
r173 r242 38 38 end 39 39 40 context"Dispatch and before/after filters" do40 describe "Dispatch and before/after filters" do 41 41 42 setupdo42 before :each do 43 43 @in = Merb::MockRequest.new 44 44 @res = StringIO.new 45 45 end 46 46 47 specify ":symbol before filter is called" do47 it "should call a :symbol before filter" do 48 48 c = TestFiltersController.new(@in.req, @in.env,{:controller => 'TestFiltersController', :action => 'one'}, @res) 49 49 c.dispatch(:one) … … 54 54 end 55 55 56 specify "Proc before filter is called" do56 it "should call a Proc before filter" do 57 57 c = TestFiltersController.new(@in.req, @in.env,{:controller => 'TestFiltersController', :action => 'two'}, @res) 58 58 c.dispatch(:two) … … 63 63 end 64 64 65 specify "filters_halted is called when throw :halt" do65 it "should call filters_halted when throw :halt" do 66 66 c = TestFiltersController.new(@in.req, @in.env,{:controller => 'TestFiltersController', :action => 'four'}, @res) 67 67 c.dispatch(:four) trunk/specs/merb/merb_controller_spec.rb
r232 r242 8 8 context "Merb::Controller" do 9 9 10 setupdo10 before :each do 11 11 @in = Merb::MockRequest.new 12 12 @res = StringIO.new 13 13 end 14 14 15 teardowndo15 after :each do 16 16 @in = nil 17 17 @res=nil 18 18 end 19 19 20 specify"should instantiate" do20 it "should instantiate" do 21 21 c = Merb::Controller.new @in.req, @in.env,{:controller => 'Test', :action => 'foo'}, @res 22 22 @in.env.should == c.instance_variable_get( "@env") 23 23 end 24 24 25 specify"Default layout should be application.rhtml" do25 it "Default layout should be application.rhtml" do 26 26 c = Merb::Controller.new @in.req, @in.env,{}, @res 27 27 c._layout.should == :application 28 28 end 29 29 30 specify"Post body is parsed into params" do30 it "Post body is parsed into params" do 31 31 @in.post_body = "title=hello%20there&body=some%20text&commit=Submit" 32 32 @in['REQUEST_METHOD'] = 'POST' … … 37 37 end 38 38 39 specify"Query String is parsed into params" do39 it "Query String is parsed into params" do 40 40 @in['QUERY_STRING'] = "title=hello%20there&body=some%20text&commit=Submit" 41 41 c = Merb::Controller.new @in.req, @in.env,{:controller => 'Test', :action => 'foo'}, @res … … 45 45 end 46 46 47 specify"multipart/form-data handles file upload" do47 it "multipart/form-data handles file upload" do 48 48 m = Multipart::Post.new 49 49 p = { :file => File.open(FIXTURES / 'sample.txt') } … … 59 59 end 60 60 61 specify"multipart/form-data handles multiple form fields" do61 it "multipart/form-data handles multiple form fields" do 62 62 m = Multipart::Post.new 63 63 p = {:foo => 'bario', 'files[]' => File.open(FIXTURES / 'sample.txt'), … … 75 75 end 76 76 77 specify"multipart/form-data handles hash-style form fields" do77 it "multipart/form-data handles hash-style form fields" do 78 78 m = Multipart::Post.new 79 79 p = {:foo => 'bario', 'files[foo]' => File.open(FIXTURES / 'sample.txt'), … … 90 90 end 91 91 92 specify"Json Post Body is parsed into params" do92 it "Json Post Body is parsed into params" do 93 93 @in.post_body = "{\"title\":\"hello there\",\"body\":\"some text\"}" 94 94 @in['REQUEST_METHOD'] = 'POST' trunk/specs/merb/merb_dispatch_spec.rb
r241 r242 1 1 require File.dirname(__FILE__) + '/../spec_helper' 2 2 require File.dirname(__FILE__) + '/../mock_request' 3 3 require File.dirname(__FILE__) + '/../fixtures/controllers/dispatch_spec_controllers' 4 4 $TESTING = true 5 5 6 class Foo < Merb::Controller 6 describe Merb::Dispatcher do 7 7 8 def index 9 "index" 10 end 11 12 def bar 13 "bar" 14 end 15 16 end 17 18 class Posts < Merb::Controller 19 # GET /posts 20 # GET /posts.xml 21 def index() :index end 22 # GET /posts/1 23 # GET /posts/1.xml 24 def show() :show end 25 # GET /posts/new 26 def new() :new end 27 # GET /posts/1;edit 28 def edit() :edit end 29 # POST /posts 30 # POST /posts.xml 31 def create() :create end 32 # PUT /posts/1 33 # PUT /posts/1.xml 34 def update() :update end 35 # DELETE /posts/1 36 # DELETE /posts/1.xml 37 def destroy() :destroy end 38 # GET /posts/1;stats 39 # PUT /posts/1;stats 40 def stats() :stats end 41 # GET /posts;filter 42 def filter() :filter end 43 end 44 45 class As < Merb::Controller 46 # GET /as 47 # GET /as.xml 48 def index() :index end 49 # GET /as/1 50 # GET /as/1.xml 51 def show() :show end 52 # GET /as/new 53 def new() :new end 54 # GET /as/1;edit 55 def edit() :edit end 56 # POST /as 57 # POST /as.xml 58 def create() :create end 59 # PUT /as/1 60 # PUT /as/1.xml 61 def update() :update end 62 # DELETE /as/1 63 # DELETE /as/1.xml 64 def destroy() :destroy end 65 end 66 67 class Bs < Merb::Controller 68 # GET /as/1/bs 69 # GET /as/1/bs.xml 70 def index() :index end 71 # GET /as/1/bs/1 72 # GET /as/1/bs/1.xml 73 def show() :show end 74 # GET /as/1/bs/new 75 def new() :new end 76 # GET /as/1/bs/1;edit 77 def edit() :edit end 78 # POST /as/1/bs 79 # POST /as/1/bs.xml 80 def create() :create end 81 # PUT /as/1/bs/1 82 # PUT /as/1/bs/1.xml 83 def update() :update end 84 # DELETE /as/1/bs/1 85 # DELETE /as/1/bs/1.xml 86 def destroy() :destroy end 87 end 88 89 class Cs < Merb::Controller 90 # GET /as/1/bs/1/cs 91 # GET /as/1/bs/1/cs.xml 92 def index() :index end 93 # GET /as/1/bs/1/cs/1 94 # GET /as/1/bs/1/cs/1.xml 95 def show() :show end 96 # GET /as/1/bs/1/cs/new 97 def new() :new end 98 # GET /as/1/bs/1/cs/1;edit 99 def edit() :edit end 100 # POST /as/1/bs/1/cs 101 # POST /as/1/bs/1/cs.xml 102 def create() :create end 103 # PUT /as/1/bs/1/cs/1 104 # PUT /as/1/bs/1/cs/1.xml 105 def update() :update end 106 # DELETE /as/1/bs/1/cs/1 107 # DELETE /as/1/bs/1/cs/1.xml 108 def destroy() :destroy end 109 end 110 111 class Tags < Merb::Controller 112 # GET /tags 113 # GET /tags.xml 114 def index() :index end 115 # GET /tags/1 116 # GET /tags/1.xml 117 def show() :show end 118 # GET /tags/new 119 def new() :new end 120 # GET /tags/1;edit 121 def edit() :edit end 122 # POST /tags 123 # POST /tags.xml 124 def create() :create end 125 # PUT /tags/1 126 # PUT /tags/1.xml 127 def update() :update end 128 # DELETE /tags/1 129 # DELETE /tags/1.xml 130 def destroy() :destroy end 131 # GET /tags/1;stats 132 # PUT /tags/1;stats 133 def stats() :stats end 134 # GET /tags;filter 135 def filter() :filter end 136 end 137 138 class Comments < Merb::Controller 139 # GET /comments 140 # GET /comments.xml 141 def index() :index end 142 # GET /comments/1 143 # GET /comments/1.xml 144 def show() :show end 145 # GET /comments/new 146 def new() :new end 147 # GET /comments/1;edit 148 def edit() :edit end 149 # POST /comments 150 # POST /comments.xml 151 def create() :create end 152 # PUT /comments/1 153 # PUT /comments/1.xml 154 def update() :update end 155 # DELETE /comments/1 156 # DELETE /comments/1.xml 157 def destroy() :destroy end 158 # GET /comments/1;stats 159 # PUT /comments/1;stats 160 def stats() :stats end 161 end 162 163 class Icon < Merb::Controller 164 # GET /icon 165 # GET /icon.xml 166 def show() :show end 167 # GET /icon/new 168 def new() :new end 169 # GET /icon;edit 170 def edit() :edit end 171 # POST /icon 172 # POST /icon.xml 173 def create() :create end 174 # PUT /icon 175 # PUT /icon.xml 176 def update() :update end 177 # DELETE /icon 178 # DELETE /icon.xml 179 def destroy() :destroy end 180 # GET /icon;stats 181 # PUT /icon;stats 182 def stats() :stats end 183 end 184 185 class Profile < Merb::Controller 186 def show() :show end 187 end 188 189 context "Merb::Dispatcher" do 190 191 setup do 8 before(:each) do 192 9 Merb::Server.allow_reloading=false 193 10 Merb::Router.prepare do |r| … … 210 27 #puts Merb::Router.generator.inspect 211 28 end 212 213 def request(verb, path) 214 res = StringIO.new 215 request = Merb::MockRequest.with( path, :request_method => (verb.to_s.upcase rescue 'GET')) 216 route = Merb::Dispatcher.route_path path 217 Merb::Dispatcher.stub!(:instantiate_controller).and_return { 218 Object.const_get( route[:controller].camel_case ).new(request.body, request.params, route, res) 219 } 220 Merb::Dispatcher.handle request, res 221 end 222 223 specify "compile_statement should contain router lambda" do 224 Merb::Router.compiled_statement.should be_kind_of(String) 225 Merb::Router.compiled_statement.should =~ /lambda\{\|path/ 226 Merb::Router.compiled_statement.should =~ /@compiled_regexen/ 227 Merb::Router.compiled_statement.should =~ /update\(sections\)/ 228 end 229 230 specify "should handle request: GET /foo/bar and return Foo#bar" do 29 30 it "should handle request: GET /foo/bar and return Foo#bar" do 231 31 controller, action = request(:get, '/foo/bar') 232 32 controller.class.should == Foo … … 235 35 end 236 36 237 specify"should handle request: GET /foo/bar/1.xml and return Foo#bar format xml" do37 it "should handle request: GET /foo/bar/1.xml and return Foo#bar format xml" do 238 38 controller, action = request(:get, '/foo/bar/1.xml') 239 39 controller.class.should == Foo … … 243 43 end 244 44 245 specify"should handle request: GET /foo/bar.xml and return Foo#bar format xml" do45 it "should handle request: GET /foo/bar.xml and return Foo#bar format xml" do 246 46 controller, action = request(:get, '/foo/bar.xml') 247 47 controller.class.should == Foo … … 251 51 end 252 52 253 specify"should handle request: GET /foo.xml and return Foo#index format xml" do53 it "should handle request: GET /foo.xml and return Foo#index format xml" do 254 54 controller, action = request(:get, '/foo.xml') 255 55 controller.class.should == Foo … … 259 59 end 260 60 261 specify"should handle request: GET /foo. and return Foo#index" do61 it "should handle request: GET /foo. and return Foo#index" do 262 62 controller, action = request(:get, '/foo') 263 63 controller.class.should == Foo … … 266 66 end 267 67 268 specify"should handle request: GET /icon and return Icon#show" do68 it "should handle request: GET /icon and return Icon#show" do 269 69 controller, action = request(:get, '/icon') 270 70 controller.class.should == Icon … … 273 73 end 274 74 275 specify"should handle request: GET /icon.xml and return Icon#show format xml" do75 it "should handle request: GET /icon.xml and return Icon#show format xml" do 276 76 controller, action = request(:get, '/icon.xml') 277 77 controller.class.should == Icon … … 281 81 end 282 82 283 specify"should handle request: GET /icon/new and return Icon#new" do83 it "should handle request: GET /icon/new and return Icon#new" do 284 84 controller, action = request(:get, '/icon/new') 285 85 controller.class.should == Icon … … 288 88 end 289 89 290 specify"should handle request: GET /icon;edit and return Icon#edit" do90 it "should handle request: GET /icon;edit and return Icon#edit" do 291 91 controller, action = request(:get, '/icon;edit') 292 92 controller.class.should == Icon … … 295 95 end 296 96 297 specify"should handle request: GET /icon/edit and return Icon#edit" do97 it "should handle request: GET /icon/edit and return Icon#edit" do 298 98 controller, action = request(:get, '/icon/edit') 299 99 controller.class.should == Icon … … 302 102 end 303 103 304 specify"should handle request: POST /icon and return Icon#create" do104 it "should handle request: POST /icon and return Icon#create" do 305 105 controller, action = request(:post, '/icon') 306 106 controller.class.should == Icon … … 309 109 end 310 110 311 specify"should handle request: PUT /icon and return Icon#update" do111 it "should handle request: PUT /icon and return Icon#update" do 312 112 controller, action = request(:put, '/icon') 313 113 controller.class.should == Icon … … 316 116 end 317 117 318 specify"should handle request: DELETE /icon and return Icon#destroy" do118 it "should handle request: DELETE /icon and return Icon#destroy" do 319 119 controller, action = request(:delete, '/icon') 320 120 controller.class.should == Icon … … 323 123 end 324 124 325 specify"should handle request: GET /admin/tags and return Tags#index" do125 it "should handle request: GET /admin/tags and return Tags#index" do 326 126 controller, action = request(:get, '/admin/tags') 327 127 controller.class.should == Tags … … 330 130 end 331 131 332 specify"should handle request: GET /admin/tags.xml and return Tags#index format xml" do132 it "should handle request: GET /admin/tags.xml and return Tags#index format xml" do 333 133 controller, action = request(:get, '/admin/tags.xml') 334 134 controller.class.should == Tags … … 338 138 end 339 139 340 specify"should handle request: GET /posts and return Posts#index" do140 it "should handle request: GET /posts and return Posts#index" do 341 141 controller, action = request(:get, '/posts') 342 142 controller.class.should == Posts … … 345 145 end 346 146 347 specify"should handle request: GET /posts;filter and return Posts#filter" do147 it "should handle request: GET /posts;filter and return Posts#filter" do 348 148 controller, action = request(:get, '/posts;filter') 349 149 controller.class.should == Posts … … 352 152 end 353 153 354 specify"should handle request: GET /posts/filter and return Posts#filter" do154 it "should handle request: GET /posts/filter and return Posts#filter" do 355 155 controller, action = request(:get, '/posts/filter') 356 156 controller.class.should == Posts … … 359 159 end 360 160 361 specify"should handle request: GET /posts/1/comments and return Comments#index with post_id == 1" do161 it "should handle request: GET /posts/1/comments and return Comments#index with post_id == 1" do 362 162 controller, action = request(:get, '/posts/1/comments') 363 163 controller.class.should == Comments … … 366 166 end 367 167 368 specify"should handle request: GET /posts/1/profile and return Profile#show with post_id == 1" do168 it "should handle request: GET /posts/1/profile and return Profile#show with post_id == 1" do 369 169 controller, action = request(:get, '/posts/1/profile') 370 170 controller.class.should == Profile … … 373 173 end 374 174 375 specify"should handle request: GET /posts/1/profile.xml and return Profile#show with post_id == 1" do175 it "should handle request: GET /posts/1/profile.xml and return Profile#show with post_id == 1" do 376 176 controller, action = request(:get, '/posts/1/profile.xml') 377 177 controller.class.should == Profile … … 381 181 end 382 182 383 specify"should handle request: GET /posts.xml and return Posts#index format xml" do183 it "should handle request: GET /posts.xml and return Posts#index format xml" do 384 184 controller, action = request(:get, '/posts.xml') 385 185 controller.class.should == Posts … … 389 189 end 390 190 391 specify"should handle request: GET /posts/1 and return Posts#show" do191 it "should handle request: GET /posts/1 and return Posts#show" do 392 192 controller, action = request(:get, '/posts/1') 393 193 controller.class.should == Posts … … 397 197 end 398 198 399 specify"should handle request: GET /posts/1/comments/1 and return Comments#show with post_id == 1" do199 it "should handle request: GET /posts/1/comments/1 and return Comments#show with post_id == 1" do 400 200 controller, action = request(:get, '/posts/1/comments/1') 401 201 controller.class.should == Comments … … 406 206 end 407 207 408 specify"should handle request: GET /as/1/bs/1 and return Bs#show with as_id == 1 & id == 1" do208 it "should handle request: GET /as/1/bs/1 and return Bs#show with as_id == 1 & id == 1" do 409 209 controller, action = request(:get, '/as/1/bs/1') 410 210 controller.class.should == Bs … … 415 215 end 416 216 417 specify"should handle request: GET /as/1/bs/1/cs and return Cs#show with a_id == 1 & b_id == 1" do217 it "should handle request: GET /as/1/bs/1/cs and return Cs#show with a_id == 1 & b_id == 1" do 418 218 controller, action = request(:get, '/as/1/bs/1/cs') 419 219 controller.class.should == Cs … … 424 224 end 425 225 426 specify"should handle request: GET /as/1/bs/1/cs/1 and return Bs#show with as_id == 1 & b_id == 1 & id == 1" do226 it "should handle request: GET /as/1/bs/1/cs/1 and return Bs#show with as_id == 1 & b_id == 1 & id == 1" do 427 227 controller, action = request(:get, '/as/1/bs/1/cs/1') 428 228 controller.class.should == Cs … … 434 234 end 435 235 436 specify"should handle request: GET /posts/1.xml and return Posts#show format xml" do236 it "should handle request: GET /posts/1.xml and return Posts#show format xml" do 437 237 controller, action = request(:get, '/posts/1.xml') 438 238 controller.class.should == Posts … … 443 243 end 444 244 445 specify"should handle request: GET /posts/1/comments/1.xml and return Comments#show with post_id == 1 and format xml" do245 it "should handle request: GET /posts/1/comments/1.xml and return Comments#show with post_id == 1 and format xml" do 446 246 controller, action = request(:get, '/posts/1/comments/1.xml') 447 247 controller.class.should == Comments … … 453 253 end 454 254 455 specify"should handle request: GET /posts/new and return Posts#new" do255 it "should handle request: GET /posts/new and return Posts#new" do 456 256 controller, action = request(:get, '/posts/new') 457 257 controller.class.should == Posts … … 460 260 end 461 261 462 specify"should handle request: GET /posts/1/comments/new and return Comments#new with post_id == 1" do262 it "should handle request: GET /posts/1/comments/new and return Comments#new with post_id == 1" do 463 263 controller, action = request(:get, '/posts/1/comments/new') 464 264 controller.class.should == Comments … … 467 267 end 468 268 469 specify"should handle request: GET /posts/1;edit and return Posts#edit" do269 it "should handle request: GET /posts/1;edit and return Posts#edit" do 470 270 controller, action = request(:get, '/posts/1;edit') 471 271 controller.class.should == Posts … … 474 274 controller.body.should == :edit 475 275 end 476 specify"should handle request: GET /posts/1/edit and return Posts#edit" do276 it "should handle request: GET /posts/1/edit and return Posts#edit" do 477 277 controller, action = request(:get, '/posts/1/edit') 478 278 controller.class.should == Posts … … 482 282 end 483 283 484 specify"should handle request: GET /posts/1/comments/1;edit and return Comments#edit with post_id == 1" do284 it "should handle request: GET /posts/1/comments/1;edit and return Comments#edit with post_id == 1" do 485 285 controller, action = request(:get, '/posts/1/comments/1;edit') 486 286 controller.class.should == Comments … … 491 291 end 492 292 493 specify"should handle request: GET /posts/1/comments/1/edit and return Comments#edit with post_id == 1" do293 it "should handle request: GET /posts/1/comments/1/edit and return Comments#edit with post_id == 1" do 494 294 controller, action = request(:get, '/posts/1/comments/1/edit') 495 295 controller.class.should == Comments … … 500 300 end 501 301 502 specify"should handle request: POST /posts and return Posts#create" do302 it "should handle request: POST /posts and return Posts#create" do 503 303 controller, action = request(:post, '/posts') 504 304 controller.class.should == Posts … … 507 307 end 508 308 509 specify"should handle request: POST /posts/1/comments and return Comments#create with post_id == 1" do309 it "should handle request: POST /posts/1/comments and return Comments#create with post_id == 1" do 510 310 controller, action = request(:post, '/posts/1/comments') 511 311 controller.class.should == Comments … … 514 314 end 515 315 516 specify"should handle request: POST /posts/1/comments.xml and return Comments#create with post_id == 1 and format xml" do316 it "should handle request: POST /posts/1/comments.xml and return Comments#create with post_id == 1 and format xml" do 517 317 controller, action = request(:post, '/posts/1/comments.xml') 518 318 controller.class.should == Comments … … 523 323 524 324 525 specify"should handle request: POST /posts.xml and return Posts#create format xml" do325 it "should handle request: POST /posts.xml and return Posts#create format xml" do 526 326 controller, action = request(:post, '/posts.xml') 527 327 controller.class.should == Posts … … 531 331 end 532 332 533 specify"should handle request: PUT /posts/1 and return Posts#update" do333 it "should handle request: PUT /posts/1 and return Posts#update" do 534 334 controller, action = request(:put, '/posts/1') 535 335 controller.class.should == Posts … … 539 339 end 540 340 541 specify"should handle request: PUT /posts/1/comments/1 and return Comments#update with post_id == 1" do341 it "should handle request: PUT /posts/1/comments/1 and return Comments#update with post_id == 1" do 542 342 controller, action = request(:put, '/posts/1/comments/1') 543 343 controller.class.should == Comments … … 548 348 end 549 349 550 specify"should handle request: PUT /posts/1.xml and return Posts#update format xml" do350 it "should handle request: PUT /posts/1.xml and return Posts#update format xml" do 551 351 controller, action = request(:put, '/posts/1.xml') 552 352 controller.class.should == Posts … … 557 357 end 558 358 559 specify"should handle request: PUT /posts/1/comments/1.xml and return Comments#update with post_id == 1 and format xml" do359 it "should handle request: PUT /posts/1/comments/1.xml and return Comments#update with post_id == 1 and format xml" do 560 360 controller, action = request(:put, '/posts/1/comments/1.xml') 561 361 controller.class.should == Comments … … 567 367 end 568 368 569 specify"should handle request: DELETE /posts/1 and return Posts#destroy" do369 it "should handle request: DELETE /posts/1 and return Posts#destroy" do 570 370 controller, action = request(:delete, '/posts/1') 571 371 controller.class.should == Posts … … 575 375 end 576 376 577 specify"should handle request: DELETE /posts/1/comments/1 and return Comments#destroy with post_id == 1" do377 it "should handle request: DELETE /posts/1/comments/1 and return Comments#destroy with post_id == 1" do 578 378 controller, action = request(:delete, '/posts/1/comments/1') 579 379 controller.class.should == Comments … … 584 384 end 585 385 586 specify"should handle request: DELETE /posts/1.xml and return Posts#destroy format xml" do386 it "should handle request: DELETE /posts/1.xml and return Posts#destroy format xml" do 587 387 controller, action = request(:delete, '/posts/1.xml') 588 388 controller.class.should == Posts … … 593 393 end 594 394 595 specify"should handle request: DELETE /posts/1/comments/1.xml and return Comments#destroy with post_id == 1" do395 it "should handle request: DELETE /posts/1/comments/1.xml and return Comments#destroy with post_id == 1" do 596 396 controller, action = request(:delete, '/posts/1/comments/1.xml') 597 397 controller.class.should == Comments … … 603 403 end 604 404 605 specify"should handle request: GET /posts/1;stats and return Posts#stats" do405 it "should handle request: GET /posts/1;stats and return Posts#stats" do 606 406 controller, action = request(:get, '/posts/1;stats') 607 407 controller.class.should == Posts … … 611 411 end 612 412 613 specify"should handle request: GET /posts/1/stats and return Posts#stats" do413 it "should handle request: GET /posts/1/stats and return Posts#stats" do 614 414 controller, action = request(:get, '/posts/1/stats') 615 415 controller.class.should == Posts … … 619 419 end 620 420 621 specify"should handle request: GET /posts/1/comments/1;stats and return Comments#stats with post_id == 1" do421 it "should handle request: GET /posts/1/comments/1;stats and return Comments#stats with post_id == 1" do 622 422 controller, action = request(:get, '/posts/1/comments/1;stats') 623 423 controller.class.should == Comments … … 628 428 end 629 429 630 specify"should handle request: GET /posts/1/comments/1/stats and return Comments#stats with post_id == 1" do430 it "should handle request: GET /posts/1/comments/1/stats and return Comments#stats with post_id == 1" do 631 431 controller, action = request(:get, '/posts/1/comments/1/stats') 632 432 controller.class.should == Comments … … 637 437 end 638 438 639 specify"should handle request: PUT /posts/1;stats and return Posts#stats" do439 it "should handle request: PUT /posts/1;stats and return Posts#stats" do 640 440 controller, action = request(:put, '/posts/1;stats') 641 441 controller.class.should == Posts … … 645 445 end 646 446 647 specify"should handle request: PUT /posts/1/comments/1;stats and return Comments#stats with post_id == 1" do447 it "should handle request: PUT /posts/1/comments/1;stats and return Comments#stats with post_id == 1" do 648 448 controller, action = request(:get, '/posts/1/comments/1;stats') 649 449 controller.class.should == Comments … … 654 454 end 655 455 656 specify"should handle request: PUT /posts/1/comments/1/stats and return Comments#stats with post_id == 1" do456 it "should handle request: PUT /posts/1/comments/1/stats and return Comments#stats with post_id == 1" do 657 457 controller, action = request(:get, '/posts/1/comments/1/stats') 658 458 controller.class.should == Comments trunk/specs/merb/merb_responder_spec.rb
r232 r242 4 4 include Merb::ResponderMixin 5 5 6 context "A Merb Responder's AcceptType" do 7 8 def new_mime(entry,index) 9 Rest::AcceptType.new(entry,index) 10 end 11 12 setupdo6 def new_mime(entry,index) 7 Rest::AcceptType.new(entry,index) 8 end 9 10 describe "A Merb Responder's AcceptType" do 11 12 before :each do 13 13 @app_xhtml = new_mime('application/xhtml+xml',1) 14 14 @text_html = new_mime('text/html',5) … … 16 16 end 17 17 18 specify"should initialize properly from mime description and index" do18 it "should initialize properly from mime description and index" do 19 19 acc_entry = new_mime(' application/html ; q=0.9 ',1) 20 20 acc_entry.media_range.should == 'application/html' … … 27 27 end 28 28 29 specify"should assign lowest quality to */* unless otherwise specified" do29 it "should assign lowest quality to */* unless otherwise specified" do 30 30 new_mime('*/*',1).quality.should == 0 31 31 new_mime('*/*;q=1.0',1).quality.should == 100 … … 33 33 end 34 34 35 specify"should be equal to another AcceptType in the same synonym group" do35 it "should be equal to another AcceptType in the same synonym group" do 36 36 @text_html.should == @app_html 37 37 @text_html.should eql(@app_html) … … 39 39 end 40 40 41 specify"should share a super range with an AcceptType in the same synonym group" do41 it "should share a super range with an AcceptType in the same synonym group" do 42 42 @text_html.synonyms.should == @app_html.synonyms 43 43 @text_html.super_range.should == @app_html.super_range 44 44 end 45 45 46 specify"should parse type and subtype" do46 it "should parse type and subtype" do 47 47 @app_xhtml.type.should == 'application' 48 48 @app_xhtml.sub_type.should == 'xhtml+xml' … … 62 62 end 63 63 64 specify"should parse accept header string to Array of AcceptType instances" do64 it "should parse accept header string to Array of AcceptType instances" do 65 65 acc_hdr = Rest::Responder.parse(@acc_hdr) 66 66 acc_hdr.should be_kind_of(Array) … … 68 68 end 69 69 70 specify"should parse single entry accept headers" do70 it "should parse single entry accept headers" do 71 71 acc_hdr = Rest::Responder.parse('application/xml') 72 72 acc_hdr.should be_kind_of(Array) … … 74 74 end 75 75 76 specify"should parse accept header into proper number of AcceptType instances" do76 it "should parse accept header into proper number of AcceptType instances" do 77 77 acc_hdr = 'foo/bar,baz/quuz,chimi/changa,cobra/khai' 78 78 acc_hdr = Rest::Responder.parse(acc_hdr) … … 80 80 end 81 81 82 specify"should only return unique AcceptType instances" do82 it "should only return unique AcceptType instances" do 83 83 acc_hdr = 'text/html,application/xhtml+xml,application/html,text/xml,' \ 84 84 'application/xml,application/x-xml' … … 87 87 end 88 88 89 specify"should sort AcceptType instances by quality" do89 it "should sort AcceptType instances by quality" do 90 90 acc_hdr = 'foo/bar;q=0.1,donny/darko;q=0.9,tango/cash,water/melon;q=0.5' 91 91 acc_hdr = Rest::Responder.parse(acc_hdr) … … 94 94 end 95 95 96 specify"should sort AcceptType instances by order" do96 it "should sort AcceptType instances by order" do 97 97 acc_hdr = 'foo/bar,baz/quuz,chimi/changa,cobra/khai' 98 98 acc_hdr = Rest::Responder.parse(acc_hdr) … … 101 101 end 102 102 103 specify"should prefer alternate xml forms (foo+xml) over application/xml" do103 it "should prefer alternate xml forms (foo+xml) over application/xml" do 104 104 acc_hdr = Rest::Responder.parse(@acc_hdr) 105 105 acc_hdr.first.super_range.should == 'text/html' 106 106 end 107 107 108 specify"should sort AcceptType instances by quality and order" do108 it "should sort AcceptType instances by quality and order" do 109 109 acc_hdr = Rest::Responder.parse(@acc_hdr) 110 110 acc_hdr.map!{|hdr| hdr.super_range }.should == … … 145 145 context "A Merb Responder's Content Negotiation" do 146 146 147 specify"should set Content-Type by :format for supported type: xml" do147 it "should set Content-Type by :format for supported type: xml" do 148 148 c = new_controller(:format => 'xml') 149 149 c.dispatch(:index) … … 152 152 end 153 153 154 specify"should set Content-Type by :format for supported type: yaml" do154 it "should set Content-Type by :format for supported type: yaml" do 155 155 c = new_controller(:format => 'yaml') 156 156 c.dispatch(:index) … … 159 159 end 160 160 161 specify"should set Content-Type by :format for supported type: html" do161 it "should set Content-Type by :format for supported type: html" do 162 162 c = new_controller(:format => 'html') 163 163 c.dispatch(:index) … … 166 166 end 167 167 168 specify"should set Content-Type by accept header for supported type: xml" do168 it "should set Content-Type by accept header for supported type: xml" do 169 169 c = new_controller(:http_accept => 'text/xml') 170 170 c.dispatch(:index) … … 173 173 end 174 174 175 specify"should set Content-Type by accept header for supported type: yaml" do175 it "should set Content-Type by accept header for supported type: yaml" do 176 176 c = new_controller(:http_accept => 'text/yaml') 177 177 c.dispatch(:index) … … 180 180 end 181 181 182 specify"should set Content-Type by accept header for supported type: html" do182 it "should set Content-Type by accept header for supported type: html" do 183 183 c = new_controller(:http_accept => 'text/html') 184 184 c.dispatch(:index) … … 187 187 end 188 188 189 specify"should set Content-Type by :format in preference to accept headers when both are of a supported response type" do189 it "should set Content-Type by :format in preference to accept headers when both are of a supported response type" do 190 190 c = new_controller(:http_accept => 'text/plain', :format => 'yaml') 191 191 c.dispatch(:index) … … 194 194 end 195 195 196 specify"should set status 406 when format is of an unsupported response type" do196 it "should set status 406 when format is of an unsupported response type" do 197 197 c = new_controller(:format => 'fromage') 198 198 c.dispatch(:index) … … 200 200 end 201 201 202 specify"should set status 406 when no accept header is of a unsupported response type" do202 it "should set status 406 when no accept header is of a unsupported response type" do 203 203 c = new_controller(:http_accept => 'stale/crackers;q=0.7,camel/milk;q=1.0') 204 204 c.dispatch(:index) … … 206 206 end 207 207 208 specify"should raise runtime error when respond_to type is not in TYPES" do208 it "should raise runtime error when respond_to type is not in TYPES" do 209 209 r = Merb::MockRequest.new 210 210 c = CrazyResponderSpecController.new(r.req, r.env, {}, StringIO.new) … … 212 212 end 213 213 214 specify"should call the block for the supported response type yaml" do214 it "should call the block for the supported response type yaml" do 215 215 c = new_controller(:http_accept => 'text/yaml') 216 216 c.dispatch(:index) … … 218 218 end 219 219 220 specify"should call the block for the supported response type xml" do220 it "should call the block for the supported response type xml" do 221 221 c = new_controller(:http_accept => 'text/xml') 222 222 c.dispatch(:index) … … 224 224 end 225 225 226 specify"should call the block for the supported response type html" do226 it "should call the block for the supported response type html" do 227 227 c = new_controller(:http_accept => 'text/html') 228 228 c.dispatch(:index) … … 230 230 end 231 231 232 specify"should utilise format in preference to accept header" do232 it "should utilise format in preference to accept header" do 233 233 c = new_controller(:http_accept => 'text/html', :format => 'xml') 234 234 c.dispatch(:index) … … 237 237 end 238 238 239 specify"should respond to the */* catchall accept header" do239 it "should respond to the */* catchall accept header" do 240 240 c = new_controller(:http_accept => '*/*') 241 241 c.dispatch(:index) … … 244 244 end 245 245 246 specify"should honor a return :nothing => status specified in the respond_to block" do246 it "should honor a return :nothing => status specified in the respond_to block" do 247 247 c = new_controller(:http_accept => 'application/xml') 248 248 c.dispatch(:create) trunk/specs/merb/merb_view_context_spec.rb
r240 r242 9 9 end 10 10 11 context"A View Context" do12 specify"should render an image tag with the image_tag method" do11 describe "A View Context" do 12 it "should render an image tag with the image_tag method" do 13 13 image_tag('foo.gif').clean.should == 14 14 %[<img src="/images/foo.gif"/>].clean … … 19 19 end 20 20 21 specify"should render a link tag with the css_include_tag method" do21 it "should render a link tag with the css_include_tag method" do 22 22 css_include_tag('foo.css').clean.should == 23 23 %[<link href="/stylesheets/foo.css" media="all" rel="Stylesheet" type="text/css"/>].clean … … 30 30 end 31 31 32 specify"should render a script tag with the js_include_tag method" do
