Skip to content
Newer
Older
100644 66 lines (55 sloc) 1.68 KB
05dc18b @dchelimsky use the Rails' NullResolver now that it's released
dchelimsky authored
1 require 'action_view/testing/resolvers'
2
a321c9c @dchelimsky change top-level module from Rspec to RSpec
dchelimsky authored
3 module RSpec
4505078 @dchelimsky add render_views declaration to turn off view isolation
dchelimsky authored
4 module Rails
5 module ViewRendering
6 extend ActiveSupport::Concern
7
8 module ClassMethods
11c380b @dchelimsky scope NullResolver in Rspec::Rails instead of ActionView
dchelimsky authored
9 def metadata_for_rspec_rails
10 metadata[:rspec_rails] ||= {}
11 end
12
ae48e7b @dchelimsky words
dchelimsky authored
13 # See RSpec::Rails::ControllerExampleGroup
4505078 @dchelimsky add render_views declaration to turn off view isolation
dchelimsky authored
14 def render_views
11c380b @dchelimsky scope NullResolver in Rspec::Rails instead of ActionView
dchelimsky authored
15 metadata_for_rspec_rails[:render_views] = true
4505078 @dchelimsky add render_views declaration to turn off view isolation
dchelimsky authored
16 end
17
18 def render_views?
4a79ee7 @dchelimsky Create new AV::Template objects for view isolation
dchelimsky authored
19 !!metadata_for_rspec_rails[:render_views]
4505078 @dchelimsky add render_views declaration to turn off view isolation
dchelimsky authored
20 end
21 end
22
67bf65c @dchelimsky Even cleaner.
dchelimsky authored
23 # Delegates find_all to the submitted path set and then returns templates
24 # with modified source
25 class PathSetDelegatorResolver < ::ActionView::Resolver
26 attr_reader :path_set
61f5bcc @dchelimsky Stub template content in controller specs instead of using NullResolver
dchelimsky authored
27
67bf65c @dchelimsky Even cleaner.
dchelimsky authored
28 def initialize(path_set)
29 @path_set = path_set
30 end
61f5bcc @dchelimsky Stub template content in controller specs instead of using NullResolver
dchelimsky authored
31
67bf65c @dchelimsky Even cleaner.
dchelimsky authored
32 def find_all(*args)
4a79ee7 @dchelimsky Create new AV::Template objects for view isolation
dchelimsky authored
33 path_set.find_all(*args).collect do |template|
8955d4e @dchelimsky Make RSpec-generated template blank.
dchelimsky authored
34 puts template.inspect
4a79ee7 @dchelimsky Create new AV::Template objects for view isolation
dchelimsky authored
35 ::ActionView::Template.new(
8955d4e @dchelimsky Make RSpec-generated template blank.
dchelimsky authored
36 "",
4a79ee7 @dchelimsky Create new AV::Template objects for view isolation
dchelimsky authored
37 template.identifier,
38 template.handler,
39 {
40 :virtual_path => template.virtual_path,
41 :format => template.formats
42 }
43 )
61f5bcc @dchelimsky Stub template content in controller specs instead of using NullResolver
dchelimsky authored
44 end
45 end
67bf65c @dchelimsky Even cleaner.
dchelimsky authored
46 end
61f5bcc @dchelimsky Stub template content in controller specs instead of using NullResolver
dchelimsky authored
47
4505078 @dchelimsky add render_views declaration to turn off view isolation
dchelimsky authored
48 included do
49 before do
d36ca6f @dchelimsky Make render_views work again
dchelimsky authored
50 unless self.class.render_views?
51 @_path_set_delegator_resolver = PathSetDelegatorResolver.new(@controller.class.view_paths)
52 @controller.class.view_paths = ::ActionView::PathSet.new.push(@_path_set_delegator_resolver)
53 end
4505078 @dchelimsky add render_views declaration to turn off view isolation
dchelimsky authored
54 end
61f5bcc @dchelimsky Stub template content in controller specs instead of using NullResolver
dchelimsky authored
55
4505078 @dchelimsky add render_views declaration to turn off view isolation
dchelimsky authored
56 after do
d36ca6f @dchelimsky Make render_views work again
dchelimsky authored
57 unless self.class.render_views?
58 @controller.class.view_paths = @_path_set_delegator_resolver.path_set
59 end
4505078 @dchelimsky add render_views declaration to turn off view isolation
dchelimsky authored
60 end
61 end
61f5bcc @dchelimsky Stub template content in controller specs instead of using NullResolver
dchelimsky authored
62
4505078 @dchelimsky add render_views declaration to turn off view isolation
dchelimsky authored
63 end
64 end
65 end
Something went wrong with that request. Please try again.