giraffesoft-resource_controller 0.5.3 → 0.5.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +2 -14
 - data/VERSION.yml +4 -0
 - data/lib/resource_controller.rb +1 -14
 - data/lib/resource_controller/base.rb +2 -2
 - data/lib/resource_controller/class_methods.rb +2 -2
 - data/lib/resource_controller/helpers.rb +0 -6
 - data/lib/resource_controller/helpers/nested.rb +1 -1
 - data/lib/resource_controller/singleton.rb +2 -2
 - data/test/app/controllers/cms/personnel_controller.rb +2 -0
 - data/test/app/controllers/cms/photos_controller.rb +6 -0
 - data/test/app/controllers/photos_controller.rb +1 -0
 - data/test/app/models/personnel.rb +3 -0
 - data/test/app/models/photo.rb +1 -0
 - data/test/app/views/cms/photos/edit.rhtml +17 -0
 - data/test/app/views/cms/photos/index.rhtml +20 -0
 - data/test/app/views/cms/photos/new.rhtml +16 -0
 - data/test/app/views/cms/photos/show.rhtml +8 -0
 - data/test/config/database.yml +6 -10
 - data/test/config/environment.rb +4 -4
 - data/test/config/environments/development.rb +0 -1
 - data/test/config/initializers/inflections.rb +14 -0
 - data/test/config/routes.rb +3 -0
 - data/test/db/migrate/013_create_personnel.rb +11 -0
 - data/test/db/migrate/014_add_personnel_id_to_photos.rb +9 -0
 - data/test/db/schema.rb +9 -3
 - data/test/test/fixtures/personnel.yml +5 -0
 - data/test/test/functional/cms/options_controller_test.rb +1 -1
 - data/test/test/functional/cms/photos_controller_test.rb +43 -0
 - data/test/test/functional/cms/products_controller_test.rb +1 -1
 - data/test/test/functional/comments_controller_test.rb +1 -1
 - data/test/test/functional/images_controller_test.rb +1 -1
 - data/test/test/functional/people_controller_test.rb +1 -1
 - data/test/test/functional/photos_controller_test.rb +1 -1
 - data/test/test/functional/posts_controller_test.rb +1 -1
 - data/test/test/functional/projects_controller_test.rb +1 -1
 - data/test/test/functional/somethings_controller_test.rb +1 -1
 - data/test/test/functional/tags_controller_test.rb +1 -1
 - data/test/test/functional/users_controller_test.rb +1 -1
 - data/test/test/test_helper.rb +1 -1
 - data/test/test/unit/accessors_test.rb +2 -2
 - data/test/test/unit/account_test.rb +1 -1
 - data/test/test/unit/action_options_test.rb +1 -1
 - data/test/test/unit/base_test.rb +1 -1
 - data/test/test/unit/comment_test.rb +1 -1
 - data/test/test/unit/failable_action_options_test.rb +1 -1
 - data/test/test/unit/helpers_test.rb +1 -1
 - data/test/test/unit/image_test.rb +1 -1
 - data/test/test/unit/option_test.rb +1 -1
 - data/test/test/unit/photo_test.rb +1 -1
 - data/test/test/unit/post_test.rb +1 -1
 - data/test/test/unit/project_test.rb +1 -1
 - data/test/test/unit/response_collector_test.rb +1 -1
 - data/test/test/unit/something_test.rb +1 -1
 - data/test/test/unit/tag_test.rb +1 -1
 - data/test/test/unit/urligence_test.rb +1 -1
 - data/test/vendor/gems/{resource_controller-0.5.2 → resource_controller-10.0.0} +0 -0
 - metadata +57 -69
 - data/LICENSE +0 -22
 - data/Rakefile +0 -35
 - data/init.rb +0 -1
 - data/lib/resource_controller/version.rb +0 -9
 - data/test/vendor/plugins/shoulda/Rakefile +0 -32
 - data/test/vendor/plugins/shoulda/bin/convert_to_should_syntax +0 -40
 - data/test/vendor/plugins/shoulda/init.rb +0 -3
 - data/test/vendor/plugins/shoulda/lib/shoulda.rb +0 -43
 - data/test/vendor/plugins/shoulda/lib/shoulda/active_record_helpers.rb +0 -580
 - data/test/vendor/plugins/shoulda/lib/shoulda/color.rb +0 -77
 - data/test/vendor/plugins/shoulda/lib/shoulda/controller_tests/controller_tests.rb +0 -467
 - data/test/vendor/plugins/shoulda/lib/shoulda/controller_tests/formats/html.rb +0 -201
 - data/test/vendor/plugins/shoulda/lib/shoulda/controller_tests/formats/xml.rb +0 -170
 - data/test/vendor/plugins/shoulda/lib/shoulda/gem/proc_extensions.rb +0 -14
 - data/test/vendor/plugins/shoulda/lib/shoulda/gem/shoulda.rb +0 -239
 - data/test/vendor/plugins/shoulda/lib/shoulda/general.rb +0 -118
 - data/test/vendor/plugins/shoulda/lib/shoulda/private_helpers.rb +0 -22
 
| 
         @@ -1,77 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            require 'test/unit/ui/console/testrunner'
         
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
       3 
     | 
    
         
            -
            # Completely stolen from redgreen gem
         
     | 
| 
       4 
     | 
    
         
            -
            #
         
     | 
| 
       5 
     | 
    
         
            -
            # Adds colored output to your tests.  Specify <tt>color: true</tt> in 
         
     | 
| 
       6 
     | 
    
         
            -
            # your <tt>~/.shoulda.conf</tt> file to enable.
         
     | 
| 
       7 
     | 
    
         
            -
            #
         
     | 
| 
       8 
     | 
    
         
            -
            # *Bug*: for some reason, this adds another line of output to the end of 
         
     | 
| 
       9 
     | 
    
         
            -
            # every rake task, as though there was another (empty) set of tests.  
         
     | 
| 
       10 
     | 
    
         
            -
            # A fix would be most welcome.
         
     | 
| 
       11 
     | 
    
         
            -
            #
         
     | 
| 
       12 
     | 
    
         
            -
            module ThoughtBot::Shoulda::Color 
         
     | 
| 
       13 
     | 
    
         
            -
              COLORS = { :clear => 0, :red => 31, :green => 32, :yellow => 33 } # :nodoc:
         
     | 
| 
       14 
     | 
    
         
            -
              def self.method_missing(color_name, *args)  # :nodoc:
         
     | 
| 
       15 
     | 
    
         
            -
                color(color_name) + args.first + color(:clear) 
         
     | 
| 
       16 
     | 
    
         
            -
              end
         
     | 
| 
       17 
     | 
    
         
            -
              def self.color(color) # :nodoc:
         
     | 
| 
       18 
     | 
    
         
            -
                "\e[#{COLORS[color.to_sym]}m"
         
     | 
| 
       19 
     | 
    
         
            -
              end
         
     | 
| 
       20 
     | 
    
         
            -
            end
         
     | 
| 
       21 
     | 
    
         
            -
             
     | 
| 
       22 
     | 
    
         
            -
            module Test # :nodoc:
         
     | 
| 
       23 
     | 
    
         
            -
              module Unit # :nodoc:
         
     | 
| 
       24 
     | 
    
         
            -
                class TestResult # :nodoc:
         
     | 
| 
       25 
     | 
    
         
            -
                  alias :old_to_s :to_s
         
     | 
| 
       26 
     | 
    
         
            -
                  def to_s
         
     | 
| 
       27 
     | 
    
         
            -
                    if old_to_s =~ /\d+ tests, \d+ assertions, (\d+) failures, (\d+) errors/
         
     | 
| 
       28 
     | 
    
         
            -
                      ThoughtBot::Shoulda::Color.send($1.to_i != 0 || $2.to_i != 0 ? :red : :green, $&)
         
     | 
| 
       29 
     | 
    
         
            -
                    end
         
     | 
| 
       30 
     | 
    
         
            -
                  end
         
     | 
| 
       31 
     | 
    
         
            -
                end
         
     | 
| 
       32 
     | 
    
         
            -
             
     | 
| 
       33 
     | 
    
         
            -
                class AutoRunner # :nodoc:
         
     | 
| 
       34 
     | 
    
         
            -
                  alias :old_initialize :initialize
         
     | 
| 
       35 
     | 
    
         
            -
                  def initialize(standalone)
         
     | 
| 
       36 
     | 
    
         
            -
                    old_initialize(standalone)
         
     | 
| 
       37 
     | 
    
         
            -
                    @runner = proc do |r| 
         
     | 
| 
       38 
     | 
    
         
            -
                      Test::Unit::UI::Console::RedGreenTestRunner
         
     | 
| 
       39 
     | 
    
         
            -
                    end
         
     | 
| 
       40 
     | 
    
         
            -
                  end
         
     | 
| 
       41 
     | 
    
         
            -
                end
         
     | 
| 
       42 
     | 
    
         
            -
             
     | 
| 
       43 
     | 
    
         
            -
                class Failure # :nodoc:
         
     | 
| 
       44 
     | 
    
         
            -
                  alias :old_long_display :long_display
         
     | 
| 
       45 
     | 
    
         
            -
                  def long_display
         
     | 
| 
       46 
     | 
    
         
            -
                    # old_long_display.sub('Failure', ThoughtBot::Shoulda::Color.red('Failure'))
         
     | 
| 
       47 
     | 
    
         
            -
                    ThoughtBot::Shoulda::Color.red(old_long_display)
         
     | 
| 
       48 
     | 
    
         
            -
                  end
         
     | 
| 
       49 
     | 
    
         
            -
                end
         
     | 
| 
       50 
     | 
    
         
            -
             
     | 
| 
       51 
     | 
    
         
            -
                class Error # :nodoc:
         
     | 
| 
       52 
     | 
    
         
            -
                  alias :old_long_display :long_display
         
     | 
| 
       53 
     | 
    
         
            -
                  def long_display
         
     | 
| 
       54 
     | 
    
         
            -
                    # old_long_display.sub('Error', ThoughtBot::Shoulda::Color.yellow('Error'))
         
     | 
| 
       55 
     | 
    
         
            -
                    ThoughtBot::Shoulda::Color.yellow(old_long_display)
         
     | 
| 
       56 
     | 
    
         
            -
                  end
         
     | 
| 
       57 
     | 
    
         
            -
                end
         
     | 
| 
       58 
     | 
    
         
            -
             
     | 
| 
       59 
     | 
    
         
            -
                module UI # :nodoc:
         
     | 
| 
       60 
     | 
    
         
            -
                  module Console # :nodoc:
         
     | 
| 
       61 
     | 
    
         
            -
                    class RedGreenTestRunner < Test::Unit::UI::Console::TestRunner  # :nodoc:
         
     | 
| 
       62 
     | 
    
         
            -
                      def output_single(something, level=NORMAL)
         
     | 
| 
       63 
     | 
    
         
            -
                        return unless (output?(level))
         
     | 
| 
       64 
     | 
    
         
            -
                        something = case something
         
     | 
| 
       65 
     | 
    
         
            -
                        when '.' then ThoughtBot::Shoulda::Color.green('.')
         
     | 
| 
       66 
     | 
    
         
            -
                        when 'F' then ThoughtBot::Shoulda::Color.red("F")
         
     | 
| 
       67 
     | 
    
         
            -
                        when 'E' then ThoughtBot::Shoulda::Color.yellow("E")
         
     | 
| 
       68 
     | 
    
         
            -
                        else something
         
     | 
| 
       69 
     | 
    
         
            -
                        end
         
     | 
| 
       70 
     | 
    
         
            -
                        @io.write(something) 
         
     | 
| 
       71 
     | 
    
         
            -
                        @io.flush
         
     | 
| 
       72 
     | 
    
         
            -
                      end
         
     | 
| 
       73 
     | 
    
         
            -
                    end
         
     | 
| 
       74 
     | 
    
         
            -
                  end
         
     | 
| 
       75 
     | 
    
         
            -
                end
         
     | 
| 
       76 
     | 
    
         
            -
              end
         
     | 
| 
       77 
     | 
    
         
            -
            end
         
     | 
| 
         @@ -1,467 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            module ThoughtBot # :nodoc:
         
     | 
| 
       2 
     | 
    
         
            -
              module Shoulda # :nodoc:
         
     | 
| 
       3 
     | 
    
         
            -
                module Controller
         
     | 
| 
       4 
     | 
    
         
            -
                  def self.included(other) # :nodoc:
         
     | 
| 
       5 
     | 
    
         
            -
                    other.class_eval do
         
     | 
| 
       6 
     | 
    
         
            -
                      extend  ThoughtBot::Shoulda::Controller::ClassMethods
         
     | 
| 
       7 
     | 
    
         
            -
                      include ThoughtBot::Shoulda::Controller::InstanceMethods
         
     | 
| 
       8 
     | 
    
         
            -
                      ThoughtBot::Shoulda::Controller::ClassMethods::VALID_FORMATS.each do |format|
         
     | 
| 
       9 
     | 
    
         
            -
                        include "ThoughtBot::Shoulda::Controller::#{format.to_s.upcase}".constantize
         
     | 
| 
       10 
     | 
    
         
            -
                      end
         
     | 
| 
       11 
     | 
    
         
            -
                    end
         
     | 
| 
       12 
     | 
    
         
            -
                  end
         
     | 
| 
       13 
     | 
    
         
            -
                  
         
     | 
| 
       14 
     | 
    
         
            -
                  # = Macro test helpers for your controllers
         
     | 
| 
       15 
     | 
    
         
            -
                  #
         
     | 
| 
       16 
     | 
    
         
            -
                  # By using the macro helpers you can quickly and easily create concise and easy to read test suites.
         
     | 
| 
       17 
     | 
    
         
            -
                  # 
         
     | 
| 
       18 
     | 
    
         
            -
                  # This code segment:
         
     | 
| 
       19 
     | 
    
         
            -
                  #   context "on GET to :show for first record" do
         
     | 
| 
       20 
     | 
    
         
            -
                  #     setup do
         
     | 
| 
       21 
     | 
    
         
            -
                  #       get :show, :id => 1
         
     | 
| 
       22 
     | 
    
         
            -
                  #     end
         
     | 
| 
       23 
     | 
    
         
            -
                  #   
         
     | 
| 
       24 
     | 
    
         
            -
                  #     should_assign_to :user
         
     | 
| 
       25 
     | 
    
         
            -
                  #     should_respond_with :success
         
     | 
| 
       26 
     | 
    
         
            -
                  #     should_render_template :show
         
     | 
| 
       27 
     | 
    
         
            -
                  #     should_not_set_the_flash
         
     | 
| 
       28 
     | 
    
         
            -
                  #
         
     | 
| 
       29 
     | 
    
         
            -
                  #     should "do something else really cool" do
         
     | 
| 
       30 
     | 
    
         
            -
                  #       assert_equal 1, assigns(:user).id
         
     | 
| 
       31 
     | 
    
         
            -
                  #     end
         
     | 
| 
       32 
     | 
    
         
            -
                  #   end
         
     | 
| 
       33 
     | 
    
         
            -
                  #
         
     | 
| 
       34 
     | 
    
         
            -
                  # Would produce 5 tests for the +show+ action
         
     | 
| 
       35 
     | 
    
         
            -
                  #
         
     | 
| 
       36 
     | 
    
         
            -
                  # Furthermore, the should_be_restful helper will create an entire set of tests which will verify that your
         
     | 
| 
       37 
     | 
    
         
            -
                  # controller responds restfully to a variety of requested formats.
         
     | 
| 
       38 
     | 
    
         
            -
                  module ClassMethods
         
     | 
| 
       39 
     | 
    
         
            -
                    # Formats tested by #should_be_restful.  Defaults to [:html, :xml]
         
     | 
| 
       40 
     | 
    
         
            -
                    VALID_FORMATS = Dir.glob(File.join(File.dirname(__FILE__), 'formats', '*.rb')).map { |f| File.basename(f, '.rb') }.map(&:to_sym) # :doc:
         
     | 
| 
       41 
     | 
    
         
            -
                    VALID_FORMATS.each {|f| require "shoulda/controller_tests/formats/#{f}.rb"}
         
     | 
| 
       42 
     | 
    
         
            -
             
     | 
| 
       43 
     | 
    
         
            -
                    # Actions tested by #should_be_restful
         
     | 
| 
       44 
     | 
    
         
            -
                    VALID_ACTIONS = [:index, :show, :new, :edit, :create, :update, :destroy] # :doc:
         
     | 
| 
       45 
     | 
    
         
            -
             
     | 
| 
       46 
     | 
    
         
            -
                    # A ResourceOptions object is passed into should_be_restful in order to configure the tests for your controller.
         
     | 
| 
       47 
     | 
    
         
            -
                    # 
         
     | 
| 
       48 
     | 
    
         
            -
                    # Example:
         
     | 
| 
       49 
     | 
    
         
            -
                    #   class UsersControllerTest < Test::Unit::TestCase
         
     | 
| 
       50 
     | 
    
         
            -
                    #     load_all_fixtures
         
     | 
| 
       51 
     | 
    
         
            -
                    #   
         
     | 
| 
       52 
     | 
    
         
            -
                    #     def setup
         
     | 
| 
       53 
     | 
    
         
            -
                    #       ...normal setup code...
         
     | 
| 
       54 
     | 
    
         
            -
                    #       @user = User.find(:first)
         
     | 
| 
       55 
     | 
    
         
            -
                    #     end
         
     | 
| 
       56 
     | 
    
         
            -
                    #   
         
     | 
| 
       57 
     | 
    
         
            -
                    #     should_be_restful do |resource|
         
     | 
| 
       58 
     | 
    
         
            -
                    #       resource.identifier = :id
         
     | 
| 
       59 
     | 
    
         
            -
                    #       resource.klass      = User
         
     | 
| 
       60 
     | 
    
         
            -
                    #       resource.object     = :user
         
     | 
| 
       61 
     | 
    
         
            -
                    #       resource.parent     = []
         
     | 
| 
       62 
     | 
    
         
            -
                    #       resource.actions    = [:index, :show, :new, :edit, :update, :create, :destroy]
         
     | 
| 
       63 
     | 
    
         
            -
                    #       resource.formats    = [:html, :xml]
         
     | 
| 
       64 
     | 
    
         
            -
                    #   
         
     | 
| 
       65 
     | 
    
         
            -
                    #       resource.create.params = { :name => "bob", :email => 'bob@bob.com', :age => 13}
         
     | 
| 
       66 
     | 
    
         
            -
                    #       resource.update.params = { :name => "sue" }
         
     | 
| 
       67 
     | 
    
         
            -
                    #   
         
     | 
| 
       68 
     | 
    
         
            -
                    #       resource.create.redirect  = "user_url(@user)"
         
     | 
| 
       69 
     | 
    
         
            -
                    #       resource.update.redirect  = "user_url(@user)"
         
     | 
| 
       70 
     | 
    
         
            -
                    #       resource.destroy.redirect = "users_url"
         
     | 
| 
       71 
     | 
    
         
            -
                    #   
         
     | 
| 
       72 
     | 
    
         
            -
                    #       resource.create.flash  = /created/i
         
     | 
| 
       73 
     | 
    
         
            -
                    #       resource.update.flash  = /updated/i
         
     | 
| 
       74 
     | 
    
         
            -
                    #       resource.destroy.flash = /removed/i    
         
     | 
| 
       75 
     | 
    
         
            -
                    #     end
         
     | 
| 
       76 
     | 
    
         
            -
                    #   end
         
     | 
| 
       77 
     | 
    
         
            -
                    #
         
     | 
| 
       78 
     | 
    
         
            -
                    # Whenever possible, the resource attributes will be set to sensible defaults.
         
     | 
| 
       79 
     | 
    
         
            -
                    #
         
     | 
| 
       80 
     | 
    
         
            -
                    class ResourceOptions
         
     | 
| 
       81 
     | 
    
         
            -
                      # Configuration options for the create, update, destroy actions under should_be_restful
         
     | 
| 
       82 
     | 
    
         
            -
                      class ActionOptions
         
     | 
| 
       83 
     | 
    
         
            -
                        # String evaled to get the target of the redirection.
         
     | 
| 
       84 
     | 
    
         
            -
                        # All of the instance variables set by the controller will be available to the 
         
     | 
| 
       85 
     | 
    
         
            -
                        # evaled code.
         
     | 
| 
       86 
     | 
    
         
            -
                        #
         
     | 
| 
       87 
     | 
    
         
            -
                        # Example:
         
     | 
| 
       88 
     | 
    
         
            -
                        #   resource.create.redirect  = "user_url(@user.company, @user)"
         
     | 
| 
       89 
     | 
    
         
            -
                        #
         
     | 
| 
       90 
     | 
    
         
            -
                        # Defaults to a generated url based on the name of the controller, the action, and the resource.parents list.
         
     | 
| 
       91 
     | 
    
         
            -
                        attr_accessor :redirect
         
     | 
| 
       92 
     | 
    
         
            -
             
     | 
| 
       93 
     | 
    
         
            -
                        # String or Regexp describing a value expected in the flash.  Will match against any flash key.
         
     | 
| 
       94 
     | 
    
         
            -
                        #
         
     | 
| 
       95 
     | 
    
         
            -
                        # Defaults:
         
     | 
| 
       96 
     | 
    
         
            -
                        # destroy:: /removed/
         
     | 
| 
       97 
     | 
    
         
            -
                        # create::  /created/
         
     | 
| 
       98 
     | 
    
         
            -
                        # update::  /updated/
         
     | 
| 
       99 
     | 
    
         
            -
                        attr_accessor :flash
         
     | 
| 
       100 
     | 
    
         
            -
                        
         
     | 
| 
       101 
     | 
    
         
            -
                        # Hash describing the params that should be sent in with this action.
         
     | 
| 
       102 
     | 
    
         
            -
                        attr_accessor :params
         
     | 
| 
       103 
     | 
    
         
            -
                      end
         
     | 
| 
       104 
     | 
    
         
            -
             
     | 
| 
       105 
     | 
    
         
            -
                      # Configuration options for the denied actions under should_be_restful
         
     | 
| 
       106 
     | 
    
         
            -
                      #
         
     | 
| 
       107 
     | 
    
         
            -
                      # Example:
         
     | 
| 
       108 
     | 
    
         
            -
                      #   context "The public" do
         
     | 
| 
       109 
     | 
    
         
            -
                      #     setup do
         
     | 
| 
       110 
     | 
    
         
            -
                      #       @request.session[:logged_in] = false
         
     | 
| 
       111 
     | 
    
         
            -
                      #     end
         
     | 
| 
       112 
     | 
    
         
            -
                      #   
         
     | 
| 
       113 
     | 
    
         
            -
                      #     should_be_restful do |resource|
         
     | 
| 
       114 
     | 
    
         
            -
                      #       resource.parent = :user
         
     | 
| 
       115 
     | 
    
         
            -
                      #   
         
     | 
| 
       116 
     | 
    
         
            -
                      #       resource.denied.actions = [:index, :show, :edit, :new, :create, :update, :destroy]
         
     | 
| 
       117 
     | 
    
         
            -
                      #       resource.denied.flash = /get outta here/i
         
     | 
| 
       118 
     | 
    
         
            -
                      #       resource.denied.redirect = 'new_session_url'
         
     | 
| 
       119 
     | 
    
         
            -
                      #     end    
         
     | 
| 
       120 
     | 
    
         
            -
                      #   end
         
     | 
| 
       121 
     | 
    
         
            -
                      #
         
     | 
| 
       122 
     | 
    
         
            -
                      class DeniedOptions
         
     | 
| 
       123 
     | 
    
         
            -
                        # String evaled to get the target of the redirection.
         
     | 
| 
       124 
     | 
    
         
            -
                        # All of the instance variables set by the controller will be available to the 
         
     | 
| 
       125 
     | 
    
         
            -
                        # evaled code.
         
     | 
| 
       126 
     | 
    
         
            -
                        #
         
     | 
| 
       127 
     | 
    
         
            -
                        # Example:
         
     | 
| 
       128 
     | 
    
         
            -
                        #   resource.create.redirect  = "user_url(@user.company, @user)"
         
     | 
| 
       129 
     | 
    
         
            -
                        attr_accessor :redirect
         
     | 
| 
       130 
     | 
    
         
            -
             
     | 
| 
       131 
     | 
    
         
            -
                        # String or Regexp describing a value expected in the flash.  Will match against any flash key.
         
     | 
| 
       132 
     | 
    
         
            -
                        #
         
     | 
| 
       133 
     | 
    
         
            -
                        # Example:
         
     | 
| 
       134 
     | 
    
         
            -
                        #   resource.create.flash = /created/
         
     | 
| 
       135 
     | 
    
         
            -
                        attr_accessor :flash
         
     | 
| 
       136 
     | 
    
         
            -
             
     | 
| 
       137 
     | 
    
         
            -
                        # Actions that should be denied (only used by resource.denied).  <i>Note that these actions will
         
     | 
| 
       138 
     | 
    
         
            -
                        # only be tested if they are also listed in +resource.actions+</i>
         
     | 
| 
       139 
     | 
    
         
            -
                        # The special value of :all will deny all of the REST actions.
         
     | 
| 
       140 
     | 
    
         
            -
                        attr_accessor :actions
         
     | 
| 
       141 
     | 
    
         
            -
                      end
         
     | 
| 
       142 
     | 
    
         
            -
             
     | 
| 
       143 
     | 
    
         
            -
                      # Name of key in params that references the primary key.  
         
     | 
| 
       144 
     | 
    
         
            -
                      # Will almost always be :id (default), unless you are using a plugin or have patched rails.
         
     | 
| 
       145 
     | 
    
         
            -
                      attr_accessor :identifier
         
     | 
| 
       146 
     | 
    
         
            -
                      
         
     | 
| 
       147 
     | 
    
         
            -
                      # Name of the ActiveRecord class this resource is responsible for.  Automatically determined from
         
     | 
| 
       148 
     | 
    
         
            -
                      # test class if not explicitly set.  UserTest => "User"
         
     | 
| 
       149 
     | 
    
         
            -
                      attr_accessor :klass
         
     | 
| 
       150 
     | 
    
         
            -
             
     | 
| 
       151 
     | 
    
         
            -
                      # Name of the instantiated ActiveRecord object that should be used by some of the tests.  
         
     | 
| 
       152 
     | 
    
         
            -
                      # Defaults to the underscored name of the AR class.  CompanyManager => :company_manager
         
     | 
| 
       153 
     | 
    
         
            -
                      attr_accessor :object
         
     | 
| 
       154 
     | 
    
         
            -
             
     | 
| 
       155 
     | 
    
         
            -
                      # Name of the parent AR objects.  Can be set as parent= or parents=, and can take either
         
     | 
| 
       156 
     | 
    
         
            -
                      # the name of the parent resource (if there's only one), or an array of names (if there's
         
     | 
| 
       157 
     | 
    
         
            -
                      # more than one).
         
     | 
| 
       158 
     | 
    
         
            -
                      #
         
     | 
| 
       159 
     | 
    
         
            -
                      # Example:
         
     | 
| 
       160 
     | 
    
         
            -
                      #   # in the routes...
         
     | 
| 
       161 
     | 
    
         
            -
                      #   map.resources :companies do
         
     | 
| 
       162 
     | 
    
         
            -
                      #     map.resources :people do
         
     | 
| 
       163 
     | 
    
         
            -
                      #       map.resources :limbs
         
     | 
| 
       164 
     | 
    
         
            -
                      #     end
         
     | 
| 
       165 
     | 
    
         
            -
                      #   end
         
     | 
| 
       166 
     | 
    
         
            -
                      #
         
     | 
| 
       167 
     | 
    
         
            -
                      #   # in the tests...
         
     | 
| 
       168 
     | 
    
         
            -
                      #   class PeopleControllerTest < Test::Unit::TestCase
         
     | 
| 
       169 
     | 
    
         
            -
                      #     should_be_restful do |resource|
         
     | 
| 
       170 
     | 
    
         
            -
                      #       resource.parent = :companies
         
     | 
| 
       171 
     | 
    
         
            -
                      #     end
         
     | 
| 
       172 
     | 
    
         
            -
                      #   end
         
     | 
| 
       173 
     | 
    
         
            -
                      #
         
     | 
| 
       174 
     | 
    
         
            -
                      #   class LimbsControllerTest < Test::Unit::TestCase
         
     | 
| 
       175 
     | 
    
         
            -
                      #     should_be_restful do |resource|
         
     | 
| 
       176 
     | 
    
         
            -
                      #       resource.parents = [:companies, :people]
         
     | 
| 
       177 
     | 
    
         
            -
                      #     end
         
     | 
| 
       178 
     | 
    
         
            -
                      #   end
         
     | 
| 
       179 
     | 
    
         
            -
                      attr_accessor :parent
         
     | 
| 
       180 
     | 
    
         
            -
                      alias parents parent
         
     | 
| 
       181 
     | 
    
         
            -
                      alias parents= parent=
         
     | 
| 
       182 
     | 
    
         
            -
                      
         
     | 
| 
       183 
     | 
    
         
            -
                      # Actions that should be tested.  Must be a subset of VALID_ACTIONS (default).
         
     | 
| 
       184 
     | 
    
         
            -
                      # Tests for each actionw will only be generated if the action is listed here.
         
     | 
| 
       185 
     | 
    
         
            -
                      # The special value of :all will test all of the REST actions.
         
     | 
| 
       186 
     | 
    
         
            -
                      #
         
     | 
| 
       187 
     | 
    
         
            -
                      # Example (for a read-only controller):
         
     | 
| 
       188 
     | 
    
         
            -
                      #   resource.actions = [:show, :index]
         
     | 
| 
       189 
     | 
    
         
            -
                      attr_accessor :actions
         
     | 
| 
       190 
     | 
    
         
            -
             
     | 
| 
       191 
     | 
    
         
            -
                      # Formats that should be tested.  Must be a subset of VALID_FORMATS (default).
         
     | 
| 
       192 
     | 
    
         
            -
                      # Each action will be tested against the formats listed here.  The special value
         
     | 
| 
       193 
     | 
    
         
            -
                      # of :all will test all of the supported formats.
         
     | 
| 
       194 
     | 
    
         
            -
                      #
         
     | 
| 
       195 
     | 
    
         
            -
                      # Example:
         
     | 
| 
       196 
     | 
    
         
            -
                      #   resource.actions = [:html, :xml]
         
     | 
| 
       197 
     | 
    
         
            -
                      attr_accessor :formats
         
     | 
| 
       198 
     | 
    
         
            -
                      
         
     | 
| 
       199 
     | 
    
         
            -
                      # ActionOptions object specifying options for the create action.
         
     | 
| 
       200 
     | 
    
         
            -
                      attr_accessor :create
         
     | 
| 
       201 
     | 
    
         
            -
             
     | 
| 
       202 
     | 
    
         
            -
                      # ActionOptions object specifying options for the update action.
         
     | 
| 
       203 
     | 
    
         
            -
                      attr_accessor :update
         
     | 
| 
       204 
     | 
    
         
            -
             
     | 
| 
       205 
     | 
    
         
            -
                      # ActionOptions object specifying options for the desrtoy action.
         
     | 
| 
       206 
     | 
    
         
            -
                      attr_accessor :destroy
         
     | 
| 
       207 
     | 
    
         
            -
             
     | 
| 
       208 
     | 
    
         
            -
                      # DeniedOptions object specifying which actions should return deny a request, and what should happen in that case.
         
     | 
| 
       209 
     | 
    
         
            -
                      attr_accessor :denied
         
     | 
| 
       210 
     | 
    
         
            -
             
     | 
| 
       211 
     | 
    
         
            -
                      def initialize # :nodoc:
         
     | 
| 
       212 
     | 
    
         
            -
                        @create  = ActionOptions.new
         
     | 
| 
       213 
     | 
    
         
            -
                        @update  = ActionOptions.new
         
     | 
| 
       214 
     | 
    
         
            -
                        @destroy = ActionOptions.new
         
     | 
| 
       215 
     | 
    
         
            -
                        @denied  = DeniedOptions.new
         
     | 
| 
       216 
     | 
    
         
            -
             
     | 
| 
       217 
     | 
    
         
            -
                        @create.flash  ||= /created/i
         
     | 
| 
       218 
     | 
    
         
            -
                        @update.flash  ||= /updated/i
         
     | 
| 
       219 
     | 
    
         
            -
                        @destroy.flash ||= /removed/i
         
     | 
| 
       220 
     | 
    
         
            -
                        @denied.flash  ||= /denied/i
         
     | 
| 
       221 
     | 
    
         
            -
             
     | 
| 
       222 
     | 
    
         
            -
                        @create.params  ||= {}
         
     | 
| 
       223 
     | 
    
         
            -
                        @update.params  ||= {}
         
     | 
| 
       224 
     | 
    
         
            -
             
     | 
| 
       225 
     | 
    
         
            -
                        @actions = VALID_ACTIONS
         
     | 
| 
       226 
     | 
    
         
            -
                        @formats = VALID_FORMATS
         
     | 
| 
       227 
     | 
    
         
            -
                        @denied.actions = []
         
     | 
| 
       228 
     | 
    
         
            -
                      end
         
     | 
| 
       229 
     | 
    
         
            -
             
     | 
| 
       230 
     | 
    
         
            -
                      def normalize!(target) # :nodoc:
         
     | 
| 
       231 
     | 
    
         
            -
                        @denied.actions  = VALID_ACTIONS if @denied.actions == :all
         
     | 
| 
       232 
     | 
    
         
            -
                        @actions         = VALID_ACTIONS if @actions        == :all
         
     | 
| 
       233 
     | 
    
         
            -
                        @formats         = VALID_FORMATS if @formats        == :all
         
     | 
| 
       234 
     | 
    
         
            -
                        
         
     | 
| 
       235 
     | 
    
         
            -
                        @denied.actions  = @denied.actions.map(&:to_sym)
         
     | 
| 
       236 
     | 
    
         
            -
                        @actions         = @actions.map(&:to_sym)
         
     | 
| 
       237 
     | 
    
         
            -
                        @formats         = @formats.map(&:to_sym)
         
     | 
| 
       238 
     | 
    
         
            -
                        
         
     | 
| 
       239 
     | 
    
         
            -
                        ensure_valid_members(@actions,        VALID_ACTIONS, 'actions')
         
     | 
| 
       240 
     | 
    
         
            -
                        ensure_valid_members(@denied.actions, VALID_ACTIONS, 'denied.actions')
         
     | 
| 
       241 
     | 
    
         
            -
                        ensure_valid_members(@formats,        VALID_FORMATS, 'formats')
         
     | 
| 
       242 
     | 
    
         
            -
                        
         
     | 
| 
       243 
     | 
    
         
            -
                        @identifier    ||= :id
         
     | 
| 
       244 
     | 
    
         
            -
                        @klass         ||= target.name.gsub(/ControllerTest$/, '').singularize.constantize
         
     | 
| 
       245 
     | 
    
         
            -
                        @object        ||= @klass.name.tableize.singularize
         
     | 
| 
       246 
     | 
    
         
            -
                        @parent        ||= []
         
     | 
| 
       247 
     | 
    
         
            -
                        @parent          = [@parent] unless @parent.is_a? Array
         
     | 
| 
       248 
     | 
    
         
            -
             
     | 
| 
       249 
     | 
    
         
            -
                        collection_helper = [@parent, @object.to_s.pluralize, 'url'].flatten.join('_')
         
     | 
| 
       250 
     | 
    
         
            -
                        collection_args   = @parent.map {|n| "@#{object}.#{n}"}.join(', ')
         
     | 
| 
       251 
     | 
    
         
            -
                        @destroy.redirect ||= "#{collection_helper}(#{collection_args})"
         
     | 
| 
       252 
     | 
    
         
            -
             
     | 
| 
       253 
     | 
    
         
            -
                        member_helper = [@parent, @object, 'url'].flatten.join('_')
         
     | 
| 
       254 
     | 
    
         
            -
                        member_args   = [@parent.map {|n| "@#{object}.#{n}"}, "@#{object}"].flatten.join(', ')
         
     | 
| 
       255 
     | 
    
         
            -
                        @create.redirect  ||= "#{member_helper}(#{member_args})"
         
     | 
| 
       256 
     | 
    
         
            -
                        @update.redirect  ||= "#{member_helper}(#{member_args})"
         
     | 
| 
       257 
     | 
    
         
            -
                        @denied.redirect  ||= "new_session_url"
         
     | 
| 
       258 
     | 
    
         
            -
                      end
         
     | 
| 
       259 
     | 
    
         
            -
                      
         
     | 
| 
       260 
     | 
    
         
            -
                      private
         
     | 
| 
       261 
     | 
    
         
            -
                      
         
     | 
| 
       262 
     | 
    
         
            -
                      def ensure_valid_members(ary, valid_members, name)  # :nodoc:
         
     | 
| 
       263 
     | 
    
         
            -
                        invalid = ary - valid_members
         
     | 
| 
       264 
     | 
    
         
            -
                        raise ArgumentError, "Unsupported #{name}: #{invalid.inspect}" unless invalid.empty?
         
     | 
| 
       265 
     | 
    
         
            -
                      end
         
     | 
| 
       266 
     | 
    
         
            -
                    end
         
     | 
| 
       267 
     | 
    
         
            -
             
     | 
| 
       268 
     | 
    
         
            -
                    # :section: should_be_restful
         
     | 
| 
       269 
     | 
    
         
            -
                    # Generates a full suite of tests for a restful controller.
         
     | 
| 
       270 
     | 
    
         
            -
                    #
         
     | 
| 
       271 
     | 
    
         
            -
                    # The following definition will generate tests for the +index+, +show+, +new+, 
         
     | 
| 
       272 
     | 
    
         
            -
                    # +edit+, +create+, +update+ and +destroy+ actions, in both +html+ and +xml+ formats:
         
     | 
| 
       273 
     | 
    
         
            -
                    #
         
     | 
| 
       274 
     | 
    
         
            -
                    #   should_be_restful do |resource|
         
     | 
| 
       275 
     | 
    
         
            -
                    #     resource.parent = :user
         
     | 
| 
       276 
     | 
    
         
            -
                    #   
         
     | 
| 
       277 
     | 
    
         
            -
                    #     resource.create.params = { :title => "first post", :body => 'blah blah blah'}
         
     | 
| 
       278 
     | 
    
         
            -
                    #     resource.update.params = { :title => "changed" }
         
     | 
| 
       279 
     | 
    
         
            -
                    #   end
         
     | 
| 
       280 
     | 
    
         
            -
                    #
         
     | 
| 
       281 
     | 
    
         
            -
                    # This generates about 40 tests, all of the format:
         
     | 
| 
       282 
     | 
    
         
            -
                    #   "on GET to :show should assign @user."
         
     | 
| 
       283 
     | 
    
         
            -
                    #   "on GET to :show should not set the flash."
         
     | 
| 
       284 
     | 
    
         
            -
                    #   "on GET to :show should render 'show' template."
         
     | 
| 
       285 
     | 
    
         
            -
                    #   "on GET to :show should respond with success."
         
     | 
| 
       286 
     | 
    
         
            -
                    #   "on GET to :show as xml should assign @user."
         
     | 
| 
       287 
     | 
    
         
            -
                    #   "on GET to :show as xml should have ContentType set to 'application/xml'."
         
     | 
| 
       288 
     | 
    
         
            -
                    #   "on GET to :show as xml should respond with success."
         
     | 
| 
       289 
     | 
    
         
            -
                    #   "on GET to :show as xml should return <user/> as the root element."
         
     | 
| 
       290 
     | 
    
         
            -
                    # The +resource+ parameter passed into the block is a ResourceOptions object, and 
         
     | 
| 
       291 
     | 
    
         
            -
                    # is used to configure the tests for the details of your resources.
         
     | 
| 
       292 
     | 
    
         
            -
                    #
         
     | 
| 
       293 
     | 
    
         
            -
                    def should_be_restful(&blk) # :yields: resource
         
     | 
| 
       294 
     | 
    
         
            -
                      resource = ResourceOptions.new
         
     | 
| 
       295 
     | 
    
         
            -
                      blk.call(resource)
         
     | 
| 
       296 
     | 
    
         
            -
                      resource.normalize!(self)
         
     | 
| 
       297 
     | 
    
         
            -
             
     | 
| 
       298 
     | 
    
         
            -
                      resource.formats.each do |format|
         
     | 
| 
       299 
     | 
    
         
            -
                        resource.actions.each do |action|
         
     | 
| 
       300 
     | 
    
         
            -
                          if self.respond_to? :"make_#{action}_#{format}_tests"
         
     | 
| 
       301 
     | 
    
         
            -
                            self.send(:"make_#{action}_#{format}_tests", resource) 
         
     | 
| 
       302 
     | 
    
         
            -
                          else
         
     | 
| 
       303 
     | 
    
         
            -
                            should "test #{action} #{format}" do
         
     | 
| 
       304 
     | 
    
         
            -
                              flunk "Test for #{action} as #{format} not implemented"
         
     | 
| 
       305 
     | 
    
         
            -
                            end
         
     | 
| 
       306 
     | 
    
         
            -
                          end
         
     | 
| 
       307 
     | 
    
         
            -
                        end
         
     | 
| 
       308 
     | 
    
         
            -
                      end
         
     | 
| 
       309 
     | 
    
         
            -
                    end
         
     | 
| 
       310 
     | 
    
         
            -
             
     | 
| 
       311 
     | 
    
         
            -
                    # :section: Test macros
         
     | 
| 
       312 
     | 
    
         
            -
                    
         
     | 
| 
       313 
     | 
    
         
            -
                    # Macro that creates a test asserting that the flash contains the given value.
         
     | 
| 
       314 
     | 
    
         
            -
                    # val can be a String, a Regex, or nil (indicating that the flash should not be set)
         
     | 
| 
       315 
     | 
    
         
            -
                    #
         
     | 
| 
       316 
     | 
    
         
            -
                    # Example:
         
     | 
| 
       317 
     | 
    
         
            -
                    #
         
     | 
| 
       318 
     | 
    
         
            -
                    #   should_set_the_flash_to "Thank you for placing this order."
         
     | 
| 
       319 
     | 
    
         
            -
                    #   should_set_the_flash_to /created/i
         
     | 
| 
       320 
     | 
    
         
            -
                    #   should_set_the_flash_to nil
         
     | 
| 
       321 
     | 
    
         
            -
                    def should_set_the_flash_to(val)
         
     | 
| 
       322 
     | 
    
         
            -
                      if val
         
     | 
| 
       323 
     | 
    
         
            -
                        should "have #{val.inspect} in the flash" do
         
     | 
| 
       324 
     | 
    
         
            -
                          assert_contains flash.values, val, ", Flash: #{flash.inspect}"            
         
     | 
| 
       325 
     | 
    
         
            -
                        end
         
     | 
| 
       326 
     | 
    
         
            -
                      else
         
     | 
| 
       327 
     | 
    
         
            -
                        should "not set the flash" do
         
     | 
| 
       328 
     | 
    
         
            -
                          assert_equal({}, flash, "Flash was set to:\n#{flash.inspect}")
         
     | 
| 
       329 
     | 
    
         
            -
                        end
         
     | 
| 
       330 
     | 
    
         
            -
                      end
         
     | 
| 
       331 
     | 
    
         
            -
                    end
         
     | 
| 
       332 
     | 
    
         
            -
                
         
     | 
| 
       333 
     | 
    
         
            -
                    # Macro that creates a test asserting that the flash is empty.  Same as
         
     | 
| 
       334 
     | 
    
         
            -
                    # @should_set_the_flash_to nil@
         
     | 
| 
       335 
     | 
    
         
            -
                    def should_not_set_the_flash
         
     | 
| 
       336 
     | 
    
         
            -
                      should_set_the_flash_to nil
         
     | 
| 
       337 
     | 
    
         
            -
                    end
         
     | 
| 
       338 
     | 
    
         
            -
                    
         
     | 
| 
       339 
     | 
    
         
            -
                    # Macro that creates a test asserting that the controller assigned to @name
         
     | 
| 
       340 
     | 
    
         
            -
                    #
         
     | 
| 
       341 
     | 
    
         
            -
                    # Example:
         
     | 
| 
       342 
     | 
    
         
            -
                    #
         
     | 
| 
       343 
     | 
    
         
            -
                    #   should_assign_to :user
         
     | 
| 
       344 
     | 
    
         
            -
                    def should_assign_to(name)
         
     | 
| 
       345 
     | 
    
         
            -
                      should "assign @#{name}" do
         
     | 
| 
       346 
     | 
    
         
            -
                        assert assigns(name.to_sym), "The action isn't assigning to @#{name}"
         
     | 
| 
       347 
     | 
    
         
            -
                      end
         
     | 
| 
       348 
     | 
    
         
            -
                    end
         
     | 
| 
       349 
     | 
    
         
            -
             
     | 
| 
       350 
     | 
    
         
            -
                    # Macro that creates a test asserting that the controller did not assign to @name
         
     | 
| 
       351 
     | 
    
         
            -
                    #
         
     | 
| 
       352 
     | 
    
         
            -
                    # Example:
         
     | 
| 
       353 
     | 
    
         
            -
                    #
         
     | 
| 
       354 
     | 
    
         
            -
                    #   should_not_assign_to :user
         
     | 
| 
       355 
     | 
    
         
            -
                    def should_not_assign_to(name)
         
     | 
| 
       356 
     | 
    
         
            -
                      should "not assign to @#{name}" do
         
     | 
| 
       357 
     | 
    
         
            -
                        assert !assigns(name.to_sym), "@#{name} was visible"
         
     | 
| 
       358 
     | 
    
         
            -
                      end
         
     | 
| 
       359 
     | 
    
         
            -
                    end
         
     | 
| 
       360 
     | 
    
         
            -
             
     | 
| 
       361 
     | 
    
         
            -
                    # Macro that creates a test asserting that the controller responded with a 'response' status code.
         
     | 
| 
       362 
     | 
    
         
            -
                    # Example:
         
     | 
| 
       363 
     | 
    
         
            -
                    #
         
     | 
| 
       364 
     | 
    
         
            -
                    #   should_respond_with :success
         
     | 
| 
       365 
     | 
    
         
            -
                    def should_respond_with(response)
         
     | 
| 
       366 
     | 
    
         
            -
                      should "respond with #{response}" do
         
     | 
| 
       367 
     | 
    
         
            -
                        assert_response response
         
     | 
| 
       368 
     | 
    
         
            -
                      end
         
     | 
| 
       369 
     | 
    
         
            -
                    end
         
     | 
| 
       370 
     | 
    
         
            -
                
         
     | 
| 
       371 
     | 
    
         
            -
                    # Macro that creates a test asserting that the controller rendered the given template.
         
     | 
| 
       372 
     | 
    
         
            -
                    # Example:
         
     | 
| 
       373 
     | 
    
         
            -
                    #
         
     | 
| 
       374 
     | 
    
         
            -
                    #   should_render_template :new
         
     | 
| 
       375 
     | 
    
         
            -
                    def should_render_template(template)
         
     | 
| 
       376 
     | 
    
         
            -
                      should "render template #{template.inspect}" do            
         
     | 
| 
       377 
     | 
    
         
            -
                        assert_template template.to_s
         
     | 
| 
       378 
     | 
    
         
            -
                      end
         
     | 
| 
       379 
     | 
    
         
            -
                    end
         
     | 
| 
       380 
     | 
    
         
            -
             
     | 
| 
       381 
     | 
    
         
            -
                    # Macro that creates a test asserting that the controller returned a redirect to the given path.
         
     | 
| 
       382 
     | 
    
         
            -
                    # The given string is evaled to produce the resulting redirect path.  All of the instance variables
         
     | 
| 
       383 
     | 
    
         
            -
                    # set by the controller are available to the evaled string.
         
     | 
| 
       384 
     | 
    
         
            -
                    # Example:
         
     | 
| 
       385 
     | 
    
         
            -
                    #
         
     | 
| 
       386 
     | 
    
         
            -
                    #   should_redirect_to '"/"'
         
     | 
| 
       387 
     | 
    
         
            -
                    #   should_redirect_to "users_url(@user)"
         
     | 
| 
       388 
     | 
    
         
            -
                    def should_redirect_to(url)
         
     | 
| 
       389 
     | 
    
         
            -
                      should "redirect to #{url.inspect}" do
         
     | 
| 
       390 
     | 
    
         
            -
                        instantiate_variables_from_assigns do
         
     | 
| 
       391 
     | 
    
         
            -
                          assert_redirected_to eval(url, self.send(:binding), __FILE__, __LINE__)
         
     | 
| 
       392 
     | 
    
         
            -
                        end
         
     | 
| 
       393 
     | 
    
         
            -
                      end
         
     | 
| 
       394 
     | 
    
         
            -
                    end
         
     | 
| 
       395 
     | 
    
         
            -
                    
         
     | 
| 
       396 
     | 
    
         
            -
                    # Macro that creates a test asserting that the rendered view contains a <form> element.
         
     | 
| 
       397 
     | 
    
         
            -
                    def should_render_a_form
         
     | 
| 
       398 
     | 
    
         
            -
                      should "display a form" do
         
     | 
| 
       399 
     | 
    
         
            -
                        assert_select "form", true, "The template doesn't contain a <form> element"            
         
     | 
| 
       400 
     | 
    
         
            -
                      end
         
     | 
| 
       401 
     | 
    
         
            -
                    end
         
     | 
| 
       402 
     | 
    
         
            -
                  end
         
     | 
| 
       403 
     | 
    
         
            -
             
     | 
| 
       404 
     | 
    
         
            -
                  module InstanceMethods # :nodoc:
         
     | 
| 
       405 
     | 
    
         
            -
                    
         
     | 
| 
       406 
     | 
    
         
            -
                    private # :enddoc:
         
     | 
| 
       407 
     | 
    
         
            -
                    
         
     | 
| 
       408 
     | 
    
         
            -
                    SPECIAL_INSTANCE_VARIABLES = %w{
         
     | 
| 
       409 
     | 
    
         
            -
                      _cookies
         
     | 
| 
       410 
     | 
    
         
            -
                      _flash
         
     | 
| 
       411 
     | 
    
         
            -
                      _headers
         
     | 
| 
       412 
     | 
    
         
            -
                      _params
         
     | 
| 
       413 
     | 
    
         
            -
                      _request
         
     | 
| 
       414 
     | 
    
         
            -
                      _response
         
     | 
| 
       415 
     | 
    
         
            -
                      _session
         
     | 
| 
       416 
     | 
    
         
            -
                      action_name
         
     | 
| 
       417 
     | 
    
         
            -
                      before_filter_chain_aborted
         
     | 
| 
       418 
     | 
    
         
            -
                      cookies
         
     | 
| 
       419 
     | 
    
         
            -
                      flash
         
     | 
| 
       420 
     | 
    
         
            -
                      headers
         
     | 
| 
       421 
     | 
    
         
            -
                      ignore_missing_templates
         
     | 
| 
       422 
     | 
    
         
            -
                      logger
         
     | 
| 
       423 
     | 
    
         
            -
                      params
         
     | 
| 
       424 
     | 
    
         
            -
                      request
         
     | 
| 
       425 
     | 
    
         
            -
                      request_origin
         
     | 
| 
       426 
     | 
    
         
            -
                      response
         
     | 
| 
       427 
     | 
    
         
            -
                      session
         
     | 
| 
       428 
     | 
    
         
            -
                      template
         
     | 
| 
       429 
     | 
    
         
            -
                      template_class
         
     | 
| 
       430 
     | 
    
         
            -
                      template_root
         
     | 
| 
       431 
     | 
    
         
            -
                      url
         
     | 
| 
       432 
     | 
    
         
            -
                      variables_added
         
     | 
| 
       433 
     | 
    
         
            -
                    }.map(&:to_s)
         
     | 
| 
       434 
     | 
    
         
            -
                    
         
     | 
| 
       435 
     | 
    
         
            -
                    def instantiate_variables_from_assigns(*names, &blk)
         
     | 
| 
       436 
     | 
    
         
            -
                      old = {}
         
     | 
| 
       437 
     | 
    
         
            -
                      names = (@response.template.assigns.keys - SPECIAL_INSTANCE_VARIABLES) if names.empty?
         
     | 
| 
       438 
     | 
    
         
            -
                      names.each do |name|
         
     | 
| 
       439 
     | 
    
         
            -
                        old[name] = instance_variable_get("@#{name}")
         
     | 
| 
       440 
     | 
    
         
            -
                        instance_variable_set("@#{name}", assigns(name.to_sym))
         
     | 
| 
       441 
     | 
    
         
            -
                      end
         
     | 
| 
       442 
     | 
    
         
            -
                      blk.call
         
     | 
| 
       443 
     | 
    
         
            -
                      names.each do |name|
         
     | 
| 
       444 
     | 
    
         
            -
                        instance_variable_set("@#{name}", old[name])
         
     | 
| 
       445 
     | 
    
         
            -
                      end
         
     | 
| 
       446 
     | 
    
         
            -
                    end
         
     | 
| 
       447 
     | 
    
         
            -
             
     | 
| 
       448 
     | 
    
         
            -
                    def get_existing_record(res) # :nodoc:
         
     | 
| 
       449 
     | 
    
         
            -
                      returning(instance_variable_get("@#{res.object}")) do |record|
         
     | 
| 
       450 
     | 
    
         
            -
                        assert(record, "This test requires you to set @#{res.object} in your setup block")    
         
     | 
| 
       451 
     | 
    
         
            -
                      end
         
     | 
| 
       452 
     | 
    
         
            -
                    end
         
     | 
| 
       453 
     | 
    
         
            -
             
     | 
| 
       454 
     | 
    
         
            -
                    def make_parent_params(resource, record = nil, parent_names = nil) # :nodoc:
         
     | 
| 
       455 
     | 
    
         
            -
                      parent_names ||= resource.parents.reverse
         
     | 
| 
       456 
     | 
    
         
            -
                      return {} if parent_names == [] # Base case
         
     | 
| 
       457 
     | 
    
         
            -
                      parent_name = parent_names.shift
         
     | 
| 
       458 
     | 
    
         
            -
                      parent = record ? record.send(parent_name) : parent_name.to_s.classify.constantize.find(:first)
         
     | 
| 
       459 
     | 
    
         
            -
             
     | 
| 
       460 
     | 
    
         
            -
                      { :"#{parent_name}_id" => parent.to_param }.merge(make_parent_params(resource, parent, parent_names))
         
     | 
| 
       461 
     | 
    
         
            -
                    end
         
     | 
| 
       462 
     | 
    
         
            -
             
     | 
| 
       463 
     | 
    
         
            -
                  end
         
     | 
| 
       464 
     | 
    
         
            -
                end  
         
     | 
| 
       465 
     | 
    
         
            -
              end
         
     | 
| 
       466 
     | 
    
         
            -
            end
         
     | 
| 
       467 
     | 
    
         
            -
             
     |