mirror of
https://github.com/thoughtbot/shoulda-matchers.git
synced 2022-11-09 12:01:38 -05:00
Fix render_with_layout_matcher on Rails 4.
Rails 4 moved the layouts ivar from `@layouts` to `@_layouts`. This change introduces what I have (for now) called the 'RailsShim'. The idea is that this single class will house the rail version workarounds, which can then be reused through the code. This paid off here because both the spec and the implementation need access to the layouts ivar.
This commit is contained in:
parent
630dc2212d
commit
c4927b73f2
4 changed files with 29 additions and 3 deletions
|
@ -1,5 +1,6 @@
|
|||
require 'shoulda/matchers/version'
|
||||
require 'shoulda/matchers/assertion_error'
|
||||
require 'shoulda/matchers/rails_shim'
|
||||
|
||||
if defined?(RSpec)
|
||||
require 'shoulda/matchers/integrations/rspec'
|
||||
|
|
|
@ -71,7 +71,7 @@ module Shoulda # :nodoc:
|
|||
|
||||
def recorded_layouts
|
||||
if @context
|
||||
@context.instance_variable_get('@layouts')
|
||||
@context.instance_variable_get(Shoulda::Matchers::RailsShim.layouts_ivar)
|
||||
else
|
||||
{}
|
||||
end
|
||||
|
|
20
lib/shoulda/matchers/rails_shim.rb
Normal file
20
lib/shoulda/matchers/rails_shim.rb
Normal file
|
@ -0,0 +1,20 @@
|
|||
module Shoulda # :nodoc:
|
||||
module Matchers
|
||||
class RailsShim # :nodoc:
|
||||
|
||||
def self.layouts_ivar
|
||||
if rails_major_version >= 4
|
||||
'@_layouts'
|
||||
else
|
||||
'@layouts'
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def self.rails_major_version
|
||||
Rails::VERSION::MAJOR
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -47,8 +47,13 @@ describe Shoulda::Matchers::ActionController::RenderWithLayoutMatcher do
|
|||
end
|
||||
|
||||
def set_in_context_layout(layout)
|
||||
@layouts = Hash.new(0)
|
||||
@layouts[layout] = 1
|
||||
layouts = Hash.new(0)
|
||||
layouts[layout] = 1
|
||||
self.instance_variable_set(layouts_ivar, layouts)
|
||||
end
|
||||
|
||||
def layouts_ivar
|
||||
Shoulda::Matchers::RailsShim.layouts_ivar
|
||||
end
|
||||
|
||||
def controller_without_layout
|
||||
|
|
Loading…
Reference in a new issue