Sha256: 8d4a426412401e9e8cef885677d7ceaa9a904ec76034b81bf75d131cf9a0f82a

Contents?: true

Size: 1.35 KB

Versions: 3

Compression:

Stored size: 1.35 KB

Contents

module RSpec
  module Rails
    # Helpers for making instance variables available to views.
    module ViewAssigns
      # Assigns a value to an instance variable in the scope of the
      # view being rendered.
      #
      # @example
      #
      #     assign(:widget, stub_model(Widget))
      def assign(key, value)
        _encapsulated_assigns[key] = value
      end

      # Compat-shim for AbstractController::Rendering#view_assigns
      #
      # _assigns was deprecated in favor of view_assigns after
      # Rails-3.0.0 was released. Since we are not able to predict when
      # the _assigns/view_assigns patch will be released (I thought it
      # would have been in 3.0.1, but 3.0.1 bypassed this change for a
      # security fix), this bit ensures that we do the right thing without
      # knowing anything about the Rails version we are dealing with.
      #
      # Once that change _is_ released, this can be changed to something
      # that checks for the Rails version when the module is being
      # interpreted, as it was before commit dd0095.
      def view_assigns
        super.merge(_encapsulated_assigns)
      rescue
        _assigns
      end

      # @private
      def _assigns
        super.merge(_encapsulated_assigns)
      end

      private

      def _encapsulated_assigns
        @_encapsulated_assigns ||= {}
      end

    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rspec-rails-3.0.2 lib/rspec/rails/view_assigns.rb
rspec-rails-3.0.1 lib/rspec/rails/view_assigns.rb
rspec-rails-3.0.0 lib/rspec/rails/view_assigns.rb