Skip to content

Commit a7b6256

Browse files
committed
Merge pull request #1572 from bquorning/spec-append-and-prepend-view-path
Spec append and prepend view path
2 parents c1b1979 + d6fd648 commit a7b6256

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

lib/rspec/rails/view_rendering.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,17 +71,17 @@ def self.call(_template)
7171
# @private
7272
module EmptyTemplates
7373
def prepend_view_path(new_path)
74-
lookup_context.view_paths.unshift(*_path_decorator(new_path))
74+
lookup_context.view_paths.unshift(*_path_decorator(*new_path))
7575
end
7676

7777
def append_view_path(new_path)
78-
lookup_context.view_paths.push(*_path_decorator(new_path))
78+
lookup_context.view_paths.push(*_path_decorator(*new_path))
7979
end
8080

8181
private
8282

83-
def _path_decorator(path)
84-
EmptyTemplateResolver.new(path)
83+
def _path_decorator(*paths)
84+
paths.map { |path| EmptyTemplateResolver.new(path) }
8585
end
8686
end
8787

spec/rspec/rails/view_rendering_spec.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,5 +121,27 @@ def example.controller
121121
end
122122
end
123123
end
124+
125+
context 'when render_views? is false' do
126+
let(:controller) { ActionController::Base.new }
127+
128+
before { controller.extend(ViewRendering::EmptyTemplates) }
129+
130+
it 'supports manipulating view paths' do
131+
controller.prepend_view_path 'app/views'
132+
controller.append_view_path 'app/others'
133+
expect(controller.view_paths.map(&:to_s)).to match_paths 'app/views', 'app/others'
134+
end
135+
136+
it 'supports manipulating view paths with arrays' do
137+
controller.prepend_view_path ['app/views', 'app/legacy_views']
138+
controller.append_view_path ['app/others', 'app/more_views']
139+
expect(controller.view_paths.map(&:to_s)).to match_paths 'app/views', 'app/legacy_views', 'app/others', 'app/more_views'
140+
end
141+
142+
def match_paths(*paths)
143+
eq paths.map { |path| File.expand_path path }
144+
end
145+
end
124146
end
125147
end

0 commit comments

Comments
 (0)