11require 'abstract_unit'
2+ require 'controller/fake_models'
23
34class RespondToController < ActionController ::Base
45 layout :set_layout
@@ -471,44 +472,6 @@ def test_format_with_custom_response_type_and_request_headers
471472 end
472473end
473474
474- class RespondResource
475- undef_method :to_json
476-
477- def self . model_name
478- @_model_name ||= ActiveModel ::Name . new ( "resource" )
479- end
480-
481- def to_param
482- 13
483- end
484-
485- def to_xml
486- "XML"
487- end
488-
489- def to_js
490- "JS"
491- end
492-
493- def errors
494- [ ]
495- end
496-
497- def destroyed?
498- false
499- end
500- end
501-
502- class ParentResource
503- def self . model_name
504- @_model_name ||= ActiveModel ::Name . new ( "parent" )
505- end
506-
507- def to_param
508- 11
509- end
510- end
511-
512475class RespondWithController < ActionController ::Base
513476 respond_to :html , :json
514477 respond_to :xml , :except => :using_defaults
@@ -531,17 +494,17 @@ def default_overwritten
531494 end
532495
533496 def using_resource
534- respond_with ( RespondResource . new )
497+ respond_with ( Customer . new ( "david" , 13 ) )
535498 end
536499
537500 def using_resource_with_options
538- respond_with ( RespondResource . new , :status => :unprocessable_entity ) do |format |
501+ respond_with ( Customer . new ( "david" , 13 ) , :status => :unprocessable_entity ) do |format |
539502 format . js
540503 end
541504 end
542505
543506 def using_resource_with_parent
544- respond_with ( [ ParentResource . new , RespondResource . new ] )
507+ respond_with ( [ Quiz :: Store . new ( "developer?" , 11 ) , Customer . new ( "david" , 13 ) ] )
545508 end
546509
547510protected
@@ -550,26 +513,14 @@ def _render_js(js, options)
550513 self . content_type ||= Mime ::JS
551514 self . response_body = js . respond_to? ( :to_js ) ? js . to_js : js
552515 end
553-
554- def resources_url
555- request . host + "/resources"
556- end
557-
558- def resource_url ( resource )
559- request . host + "/resources/#{ resource . to_param } "
560- end
561-
562- def parent_resource_url ( parent , resource )
563- request . host + "/parents/#{ parent . to_param } /resources/#{ resource . to_param } "
564- end
565516end
566517
567518class InheritedRespondWithController < RespondWithController
568519 clear_respond_to
569520 respond_to :xml , :json
570521
571522 def index
572- respond_with ( RespondResource . new ) do |format |
523+ respond_with ( Customer . new ( "david" , 13 ) ) do |format |
573524 format . json { render :text => "JSON" }
574525 end
575526 end
@@ -582,6 +533,11 @@ def setup
582533 super
583534 ActionController ::Base . use_accept_header = true
584535 @request . host = "www.example.com"
536+
537+ ActionController ::Routing ::Routes . draw do |map |
538+ map . resources :customers
539+ map . resources :quiz_stores , :has_many => :customers
540+ end
585541 end
586542
587543 def teardown
@@ -645,11 +601,11 @@ def test_using_resource_for_post_with_html
645601 post :using_resource
646602 assert_equal "text/html" , @response . content_type
647603 assert_equal 302 , @response . status
648- assert_equal "www.example.com/resources /13" , @response . location
604+ assert_equal "http:// www.example.com/customers /13" , @response . location
649605 assert @response . redirect?
650606
651607 errors = { :name => :invalid }
652- RespondResource . any_instance . stubs ( :errors ) . returns ( errors )
608+ Customer . any_instance . stubs ( :errors ) . returns ( errors )
653609 post :using_resource
654610 assert_equal "text/html" , @response . content_type
655611 assert_equal 200 , @response . status
@@ -664,10 +620,10 @@ def test_using_resource_for_post_with_xml
664620 assert_equal "application/xml" , @response . content_type
665621 assert_equal 201 , @response . status
666622 assert_equal "XML" , @response . body
667- assert_equal "www.example.com/resources /13" , @response . location
623+ assert_equal "http:// www.example.com/customers /13" , @response . location
668624
669625 errors = { :name => :invalid }
670- RespondResource . any_instance . stubs ( :errors ) . returns ( errors )
626+ Customer . any_instance . stubs ( :errors ) . returns ( errors )
671627 post :using_resource
672628 assert_equal "application/xml" , @response . content_type
673629 assert_equal 422 , @response . status
@@ -679,11 +635,11 @@ def test_using_resource_for_put_with_html
679635 put :using_resource
680636 assert_equal "text/html" , @response . content_type
681637 assert_equal 302 , @response . status
682- assert_equal "www.example.com/resources /13" , @response . location
638+ assert_equal "http:// www.example.com/customers /13" , @response . location
683639 assert @response . redirect?
684640
685641 errors = { :name => :invalid }
686- RespondResource . any_instance . stubs ( :errors ) . returns ( errors )
642+ Customer . any_instance . stubs ( :errors ) . returns ( errors )
687643 put :using_resource
688644 assert_equal "text/html" , @response . content_type
689645 assert_equal 200 , @response . status
@@ -698,10 +654,10 @@ def test_using_resource_for_put_with_xml
698654 assert_equal "application/xml" , @response . content_type
699655 assert_equal 200 , @response . status
700656 assert_equal " " , @response . body
701- assert_equal "www.example.com/resources /13" , @response . location
657+ assert_equal "http:// www.example.com/customers /13" , @response . location
702658
703659 errors = { :name => :invalid }
704- RespondResource . any_instance . stubs ( :errors ) . returns ( errors )
660+ Customer . any_instance . stubs ( :errors ) . returns ( errors )
705661 put :using_resource
706662 assert_equal "application/xml" , @response . content_type
707663 assert_equal 422 , @response . status
@@ -710,21 +666,21 @@ def test_using_resource_for_put_with_xml
710666 end
711667
712668 def test_using_resource_for_delete_with_html
713- RespondResource . any_instance . stubs ( :destroyed? ) . returns ( true )
669+ Customer . any_instance . stubs ( :destroyed? ) . returns ( true )
714670 delete :using_resource
715671 assert_equal "text/html" , @response . content_type
716672 assert_equal 302 , @response . status
717- assert_equal "www.example.com/resources " , @response . location
673+ assert_equal "http:// www.example.com/customers " , @response . location
718674 end
719675
720676 def test_using_resource_for_delete_with_xml
721- RespondResource . any_instance . stubs ( :destroyed? ) . returns ( true )
677+ Customer . any_instance . stubs ( :destroyed? ) . returns ( true )
722678 @request . accept = "application/xml"
723679 delete :using_resource
724680 assert_equal "application/xml" , @response . content_type
725681 assert_equal 200 , @response . status
726682 assert_equal " " , @response . body
727- assert_equal "www.example.com/resources " , @response . location
683+ assert_equal "http:// www.example.com/customers " , @response . location
728684 end
729685
730686 def test_using_resource_with_options
@@ -756,10 +712,10 @@ def test_using_resource_with_parent_for_post
756712 assert_equal "application/xml" , @response . content_type
757713 assert_equal 201 , @response . status
758714 assert_equal "XML" , @response . body
759- assert_equal "www.example.com/parents /11/resources /13" , @response . location
715+ assert_equal "http:// www.example.com/quiz_stores /11/customers /13" , @response . location
760716
761717 errors = { :name => :invalid }
762- RespondResource . any_instance . stubs ( :errors ) . returns ( errors )
718+ Customer . any_instance . stubs ( :errors ) . returns ( errors )
763719 post :using_resource
764720 assert_equal "application/xml" , @response . content_type
765721 assert_equal 422 , @response . status
0 commit comments