rails_helper 1.1.0 → 1.2.0
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/lib/rails_helper.rb +61 -73
 - data/rails_helper.gemspec +3 -1
 - metadata +15 -4
 
    
        data/lib/rails_helper.rb
    CHANGED
    
    | 
         @@ -1,101 +1,89 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            class Helper
         
     | 
| 
       2 
     | 
    
         
            -
              def Helper.version 
     | 
| 
      
 1 
     | 
    
         
            +
            class Helper < (defined?(ActionView::Base) ? ActionView::Base : Object)
         
     | 
| 
      
 2 
     | 
    
         
            +
              def Helper.version
         
     | 
| 
      
 3 
     | 
    
         
            +
                '1.2.0'
         
     | 
| 
      
 4 
     | 
    
         
            +
              end
         
     | 
| 
       3 
5 
     | 
    
         | 
| 
       4 
6 
     | 
    
         
             
              def Helper.dependencies
         
     | 
| 
       5 
7 
     | 
    
         
             
                {
         
     | 
| 
       6 
     | 
    
         
            -
                  'rails_current' 
     | 
| 
      
 8 
     | 
    
         
            +
                  'rails_current'             => [ 'rails_current',             ' >= 1.0' ],
         
     | 
| 
      
 9 
     | 
    
         
            +
                  'rails_default_url_options' => [ 'rails_default_url_options', ' >= 1.0' ]
         
     | 
| 
       7 
10 
     | 
    
         
             
                }
         
     | 
| 
       8 
11 
     | 
    
         
             
              end
         
     | 
| 
       9 
12 
     | 
    
         | 
| 
       10 
13 
     | 
    
         | 
| 
       11 
     | 
    
         
            -
               
     | 
| 
      
 14 
     | 
    
         
            +
              attr_accessor 'options'
         
     | 
| 
      
 15 
     | 
    
         
            +
              attr_accessor 'args'
         
     | 
| 
      
 16 
     | 
    
         
            +
              attr_accessor 'block'
         
     | 
| 
      
 17 
     | 
    
         
            +
              attr_accessor 'controller'
         
     | 
| 
      
 18 
     | 
    
         
            +
              attr_accessor 'modules'
         
     | 
| 
       12 
19 
     | 
    
         | 
| 
       13 
     | 
    
         
            -
             
     | 
| 
       14 
     | 
    
         
            -
             
     | 
| 
       15 
     | 
    
         
            -
             
     | 
| 
       16 
     | 
    
         
            -
             
     | 
| 
       17 
     | 
    
         
            -
                    end
         
     | 
| 
      
 20 
     | 
    
         
            +
              def initialize(*args, &block)
         
     | 
| 
      
 21 
     | 
    
         
            +
                @options = args.extract_options!.to_options!
         
     | 
| 
      
 22 
     | 
    
         
            +
                @args = args
         
     | 
| 
      
 23 
     | 
    
         
            +
                @block = block
         
     | 
| 
       18 
24 
     | 
    
         | 
| 
       19 
     | 
    
         
            -
             
     | 
| 
       20 
     | 
    
         
            -
             
     | 
| 
       21 
     | 
    
         
            -
             
     | 
| 
      
 25 
     | 
    
         
            +
                controllers, args = args.partition{|arg| ActionController::Base === arg}
         
     | 
| 
      
 26 
     | 
    
         
            +
             
     | 
| 
      
 27 
     | 
    
         
            +
                @controller = controllers.first || Helper.current_controller || Helper.mock_controller
         
     | 
| 
      
 28 
     | 
    
         
            +
             
     | 
| 
      
 29 
     | 
    
         
            +
                @modules = args
         
     | 
| 
      
 30 
     | 
    
         
            +
             
     | 
| 
      
 31 
     | 
    
         
            +
                @controller = controller
         
     | 
| 
      
 32 
     | 
    
         
            +
                @modules.push(nil) if @modules.empty?
         
     | 
| 
      
 33 
     | 
    
         
            +
                @modules.flatten.uniq.each do |mod|
         
     | 
| 
      
 34 
     | 
    
         
            +
                  case mod
         
     | 
| 
      
 35 
     | 
    
         
            +
                    when NilClass, :all, 'all'
         
     | 
| 
      
 36 
     | 
    
         
            +
                      extend ::ActionView::Helpers
         
     | 
| 
      
 37 
     | 
    
         
            +
                    when Module
         
     | 
| 
      
 38 
     | 
    
         
            +
                      extend mod
         
     | 
| 
      
 39 
     | 
    
         
            +
                    else
         
     | 
| 
      
 40 
     | 
    
         
            +
                      raise ArgumentError, mod.class.name
         
     | 
| 
       22 
41 
     | 
    
         
             
                  end
         
     | 
| 
       23 
42 
     | 
    
         
             
                end
         
     | 
| 
       24 
     | 
    
         
            -
             
     | 
| 
       25 
43 
     | 
    
         
             
              end
         
     | 
| 
       26 
44 
     | 
    
         | 
| 
       27 
     | 
    
         
            -
               
     | 
| 
       28 
     | 
    
         
            -
             
     | 
| 
       29 
     | 
    
         
            -
                 
     | 
| 
      
 45 
     | 
    
         
            +
              ### see ./actionpack/test/controller/caching_test.rb OUCH!
         
     | 
| 
      
 46 
     | 
    
         
            +
              def Helper.mock_controller
         
     | 
| 
      
 47 
     | 
    
         
            +
                require 'action_dispatch/testing/test_request.rb'
         
     | 
| 
      
 48 
     | 
    
         
            +
                require 'action_dispatch/testing/test_response.rb'
         
     | 
| 
      
 49 
     | 
    
         
            +
                store = ActiveSupport::Cache::MemoryStore.new
         
     | 
| 
      
 50 
     | 
    
         
            +
                controller = ApplicationController.new
         
     | 
| 
      
 51 
     | 
    
         
            +
                controller.perform_caching = true
         
     | 
| 
      
 52 
     | 
    
         
            +
                controller.cache_store = store
         
     | 
| 
      
 53 
     | 
    
         
            +
                request = ActionDispatch::TestRequest.new
         
     | 
| 
      
 54 
     | 
    
         
            +
                response = ActionDispatch::TestResponse.new
         
     | 
| 
      
 55 
     | 
    
         
            +
                controller.request = request
         
     | 
| 
      
 56 
     | 
    
         
            +
                controller.response = response
         
     | 
| 
      
 57 
     | 
    
         
            +
                controller.send(:initialize_template_class, response)
         
     | 
| 
      
 58 
     | 
    
         
            +
                controller.send(:assign_shortcuts, request, response)
         
     | 
| 
      
 59 
     | 
    
         
            +
                controller.send(:default_url_options).merge!(DefaultUrlOptions) if defined?(DefaultUrlOptions)
         
     | 
| 
      
 60 
     | 
    
         
            +
                controller
         
     | 
| 
       30 
61 
     | 
    
         
             
              end
         
     | 
| 
       31 
62 
     | 
    
         | 
| 
       32 
     | 
    
         
            -
              def  
     | 
| 
       33 
     | 
    
         
            -
                 
     | 
| 
       34 
     | 
    
         
            -
              ensure
         
     | 
| 
       35 
     | 
    
         
            -
                default_url_options[:protocol] = @controller.request.protocol
         
     | 
| 
       36 
     | 
    
         
            -
                default_url_options[:host] = @controller.request.host
         
     | 
| 
       37 
     | 
    
         
            -
                default_url_options[:port] = @controller.request.port
         
     | 
| 
      
 63 
     | 
    
         
            +
              def Helper.current_controller
         
     | 
| 
      
 64 
     | 
    
         
            +
                Current.controller
         
     | 
| 
       38 
65 
     | 
    
         
             
              end
         
     | 
| 
       39 
66 
     | 
    
         | 
| 
       40 
     | 
    
         
            -
              def  
     | 
| 
       41 
     | 
    
         
            -
                 
     | 
| 
      
 67 
     | 
    
         
            +
              def _routes
         
     | 
| 
      
 68 
     | 
    
         
            +
                Rails.application.routes
         
     | 
| 
       42 
69 
     | 
    
         
             
              end
         
     | 
| 
       43 
70 
     | 
    
         | 
| 
       44 
     | 
    
         
            -
               
     | 
| 
       45 
     | 
    
         
            -
                 
     | 
| 
       46 
     | 
    
         
            -
                render_to_string
         
     | 
| 
       47 
     | 
    
         
            -
              )
         
     | 
| 
       48 
     | 
    
         
            -
             
     | 
| 
       49 
     | 
    
         
            -
              controller_delegates.each do |method|
         
     | 
| 
       50 
     | 
    
         
            -
                module_eval <<-__, __FILE__, __LINE__
         
     | 
| 
       51 
     | 
    
         
            -
                  def #{ method }(*args, &block)
         
     | 
| 
       52 
     | 
    
         
            -
                    controller.#{ method }(*args, &block)
         
     | 
| 
       53 
     | 
    
         
            -
                  end
         
     | 
| 
       54 
     | 
    
         
            -
                __
         
     | 
| 
      
 71 
     | 
    
         
            +
              def default_url_options
         
     | 
| 
      
 72 
     | 
    
         
            +
                defined?(DefaultUrlOptions) ? DefaultUrlOptions : {}
         
     | 
| 
       55 
73 
     | 
    
         
             
              end
         
     | 
| 
       56 
74 
     | 
    
         | 
| 
       57 
     | 
    
         
            -
               
     | 
| 
       58 
     | 
    
         
            -
                 
     | 
| 
       59 
     | 
    
         
            -
             
     | 
| 
       60 
     | 
    
         
            -
                    require 'action_dispatch/testing/test_request.rb'
         
     | 
| 
       61 
     | 
    
         
            -
                    require 'action_dispatch/testing/test_response.rb'
         
     | 
| 
       62 
     | 
    
         
            -
                    store = ActiveSupport::Cache::MemoryStore.new
         
     | 
| 
       63 
     | 
    
         
            -
                    controller = 
         
     | 
| 
       64 
     | 
    
         
            -
                      begin
         
     | 
| 
       65 
     | 
    
         
            -
                        ApplicationController.new
         
     | 
| 
       66 
     | 
    
         
            -
                      rescue NameError
         
     | 
| 
       67 
     | 
    
         
            -
                        ActionController::Base.new
         
     | 
| 
       68 
     | 
    
         
            -
                      end
         
     | 
| 
       69 
     | 
    
         
            -
                    controller.perform_caching = true
         
     | 
| 
       70 
     | 
    
         
            -
                    controller.cache_store = store
         
     | 
| 
       71 
     | 
    
         
            -
                    request = ActionDispatch::TestRequest.new
         
     | 
| 
       72 
     | 
    
         
            -
                    response = ActionDispatch::TestResponse.new
         
     | 
| 
       73 
     | 
    
         
            -
                    controller.request = request
         
     | 
| 
       74 
     | 
    
         
            -
                    controller.response = response
         
     | 
| 
       75 
     | 
    
         
            -
                    controller.send(:initialize_template_class, response)
         
     | 
| 
       76 
     | 
    
         
            -
                    controller.send(:assign_shortcuts, request, response)
         
     | 
| 
       77 
     | 
    
         
            -
                    controller.send(:default_url_options).merge!(DefaultUrlOptions) if defined?(DefaultUrlOptions)
         
     | 
| 
       78 
     | 
    
         
            -
                    controller
         
     | 
| 
       79 
     | 
    
         
            -
                  end
         
     | 
| 
       80 
     | 
    
         
            -
                end
         
     | 
| 
      
 75 
     | 
    
         
            +
              def session
         
     | 
| 
      
 76 
     | 
    
         
            +
                controller.session
         
     | 
| 
      
 77 
     | 
    
         
            +
              end
         
     | 
| 
       81 
78 
     | 
    
         | 
| 
       82 
     | 
    
         
            -
             
     | 
| 
       83 
     | 
    
         
            -
             
     | 
| 
       84 
     | 
    
         
            -
             
     | 
| 
       85 
     | 
    
         
            -
                     
     | 
| 
       86 
     | 
    
         
            -
             
     | 
| 
       87 
     | 
    
         
            -
                      block.call()
         
     | 
| 
       88 
     | 
    
         
            -
                    ensure
         
     | 
| 
       89 
     | 
    
         
            -
                      Rails.application = nil
         
     | 
| 
      
 79 
     | 
    
         
            +
              if defined?(::Rails)
         
     | 
| 
      
 80 
     | 
    
         
            +
                if defined?(Rails::Engine)
         
     | 
| 
      
 81 
     | 
    
         
            +
                  class Engine < Rails::Engine
         
     | 
| 
      
 82 
     | 
    
         
            +
                    config.after_initialize do
         
     | 
| 
      
 83 
     | 
    
         
            +
                      Helper.send(:include, Rails.application.routes.url_helpers)
         
     | 
| 
       90 
84 
     | 
    
         
             
                    end
         
     | 
| 
       91 
     | 
    
         
            -
                  else
         
     | 
| 
       92 
     | 
    
         
            -
                    block.call()
         
     | 
| 
       93 
85 
     | 
    
         
             
                  end
         
     | 
| 
       94 
86 
     | 
    
         
             
                end
         
     | 
| 
       95 
     | 
    
         
            -
             
     | 
| 
       96 
     | 
    
         
            -
                def current_controller
         
     | 
| 
       97 
     | 
    
         
            -
                  Current.controller
         
     | 
| 
       98 
     | 
    
         
            -
                end
         
     | 
| 
       99 
87 
     | 
    
         
             
              end
         
     | 
| 
       100 
88 
     | 
    
         
             
            end
         
     | 
| 
       101 
89 
     | 
    
         | 
    
        data/rails_helper.gemspec
    CHANGED
    
    | 
         @@ -3,7 +3,7 @@ 
     | 
|
| 
       3 
3 
     | 
    
         | 
| 
       4 
4 
     | 
    
         
             
            Gem::Specification::new do |spec|
         
     | 
| 
       5 
5 
     | 
    
         
             
              spec.name = "rails_helper"
         
     | 
| 
       6 
     | 
    
         
            -
              spec.version = "1. 
     | 
| 
      
 6 
     | 
    
         
            +
              spec.version = "1.2.0"
         
     | 
| 
       7 
7 
     | 
    
         
             
              spec.platform = Gem::Platform::RUBY
         
     | 
| 
       8 
8 
     | 
    
         
             
              spec.summary = "rails_helper"
         
     | 
| 
       9 
9 
     | 
    
         
             
              spec.description = "description: rails_helper kicks the ass"
         
     | 
| 
         @@ -20,6 +20,8 @@ Gem::Specification::new do |spec| 
     | 
|
| 
       20 
20 
     | 
    
         | 
| 
       21 
21 
     | 
    
         
             
                spec.add_dependency(*["rails_current", " >= 1.0"])
         
     | 
| 
       22 
22 
     | 
    
         | 
| 
      
 23 
     | 
    
         
            +
                spec.add_dependency(*["rails_default_url_options", " >= 1.0"])
         
     | 
| 
      
 24 
     | 
    
         
            +
              
         
     | 
| 
       23 
25 
     | 
    
         | 
| 
       24 
26 
     | 
    
         
             
              spec.extensions.push(*[])
         
     | 
| 
       25 
27 
     | 
    
         | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: rails_helper
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 1. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 1.2.0
         
     | 
| 
       5 
5 
     | 
    
         
             
              prerelease: 
         
     | 
| 
       6 
6 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       7 
7 
     | 
    
         
             
            authors:
         
     | 
| 
         @@ -9,11 +9,11 @@ authors: 
     | 
|
| 
       9 
9 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       10 
10 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       11 
11 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       12 
     | 
    
         
            -
            date:  
     | 
| 
      
 12 
     | 
    
         
            +
            date: 2012-01-16 00:00:00.000000000 Z
         
     | 
| 
       13 
13 
     | 
    
         
             
            dependencies:
         
     | 
| 
       14 
14 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       15 
15 
     | 
    
         
             
              name: rails_current
         
     | 
| 
       16 
     | 
    
         
            -
              requirement: & 
     | 
| 
      
 16 
     | 
    
         
            +
              requirement: &70290739114920 !ruby/object:Gem::Requirement
         
     | 
| 
       17 
17 
     | 
    
         
             
                none: false
         
     | 
| 
       18 
18 
     | 
    
         
             
                requirements:
         
     | 
| 
       19 
19 
     | 
    
         
             
                - - ! '>='
         
     | 
| 
         @@ -21,7 +21,18 @@ dependencies: 
     | 
|
| 
       21 
21 
     | 
    
         
             
                    version: '1.0'
         
     | 
| 
       22 
22 
     | 
    
         
             
              type: :runtime
         
     | 
| 
       23 
23 
     | 
    
         
             
              prerelease: false
         
     | 
| 
       24 
     | 
    
         
            -
              version_requirements: * 
     | 
| 
      
 24 
     | 
    
         
            +
              version_requirements: *70290739114920
         
     | 
| 
      
 25 
     | 
    
         
            +
            - !ruby/object:Gem::Dependency
         
     | 
| 
      
 26 
     | 
    
         
            +
              name: rails_default_url_options
         
     | 
| 
      
 27 
     | 
    
         
            +
              requirement: &70290739114420 !ruby/object:Gem::Requirement
         
     | 
| 
      
 28 
     | 
    
         
            +
                none: false
         
     | 
| 
      
 29 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 30 
     | 
    
         
            +
                - - ! '>='
         
     | 
| 
      
 31 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 32 
     | 
    
         
            +
                    version: '1.0'
         
     | 
| 
      
 33 
     | 
    
         
            +
              type: :runtime
         
     | 
| 
      
 34 
     | 
    
         
            +
              prerelease: false
         
     | 
| 
      
 35 
     | 
    
         
            +
              version_requirements: *70290739114420
         
     | 
| 
       25 
36 
     | 
    
         
             
            description: ! 'description: rails_helper kicks the ass'
         
     | 
| 
       26 
37 
     | 
    
         
             
            email: ara.t.howard@gmail.com
         
     | 
| 
       27 
38 
     | 
    
         
             
            executables: []
         
     |