Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Fix rendering deprecations in view specs #529

Merged
merged 1 commit into from

4 participants

@jdelStrother

render(:template=>'new.erb') is now deprecated and should be render(:template=>'new', :handlers=>['erb']). This patch takes the default template name supplied in the spec and breaks it up into its separate components before calling render().

See #485 for background.

For some reason I thought just running 'rake' in rspec-dev ran the specs against a variety of rails versions, but scanning through the code I can't see where that's done. So at the moment, this is only tested against 3.2.2 - any tips on testing the others, or do we not care?

@jdelStrother jdelStrother Fix rendering deprecations in view specs
render(:template=>'new.erb') is now deprecated and should be render(:template=>'new', :handlers=>['erb']).  This patch takes the default template name supplied in the spec and breaks it up into its separate components before calling render().
656ff35
@justinko

Thanks for the pull!

This needs to work against all of the Rails versions in our travis config.

Have a look at this page to see how to run against multiple versions.

@jdelStrother

OK, seems fine against all Rails versions except master, which I can't seem to even install at the moment ("Could not find gem 'active_record_deprecated_finders (= 0.0.1) ruby'" when running bundle install)

@dchelimsky dchelimsky merged commit 0336706 into rspec:master
@dchelimsky dchelimsky referenced this pull request from a commit
@dchelimsky dchelimsky Changelog for #529 [ci skip] 040f6a9
@fcy
fcy commented

Hi Guys,

I'm new to Ruby/Rails in general. Sorry If I'm asking this on the wrong place or if there's a place where it's already answered. But in which version will this fix be available?

@dchelimsky
Owner

@fmcypriano sem problemas. Vai estar incluido na versão 2.10, provavilmente na fim de semana que vem.

@fcy
fcy commented

@dchelimsky Valeu! Tomei um "susto" com a resposta em português :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 13, 2012
  1. @jdelStrother

    Fix rendering deprecations in view specs

    jdelStrother authored
    render(:template=>'new.erb') is now deprecated and should be render(:template=>'new', :handlers=>['erb']).  This patch takes the default template name supplied in the spec and breaks it up into its separate components before calling render().
This page is out of date. Refresh to see the latest.
View
15 lib/rspec/rails/example/view_example_group.rb
@@ -42,7 +42,7 @@ module ExampleMethods
# end
# end
def render(options={}, local_assigns={}, &block)
- options = {:template => _default_file_to_render} if Hash === options and options.empty?
+ options = _default_render_options if Hash === options and options.empty?
super(options, local_assigns, &block)
end
@@ -98,6 +98,19 @@ def _default_file_to_render
example.example_group.top_level_description
end
+ def _default_render_options
+ # pluck the handler, format, and locale out of, eg, posts/index.de.html.haml
+ template, *components = _default_file_to_render.split('.')
+ handler, format, locale = *components.reverse
+
+ render_options = {:template => template}
+ render_options[:handlers] = [handler] if handler
+ render_options[:formats] = [format] if format
+ render_options[:locales] = [locale] if locale
+
+ render_options
+ end
+
def _path_parts
_default_file_to_render.split("/")
end
View
11 spec/rspec/rails/example/view_example_group_spec.rb
@@ -108,10 +108,15 @@ def _assigns
end
context "given no input" do
- it "sends render(:file => (described file)) to the view" do
- view_spec.stub(:_default_file_to_render) { "widgets/new.html.erb" }
+ it "sends render(:template => (described file)) to the view" do
+ view_spec.stub(:_default_file_to_render) { "widgets/new" }
view_spec.render
- view_spec.received.first.should == [{:template => "widgets/new.html.erb"},{}, nil]
+ view_spec.received.first.should == [{:template => "widgets/new"},{}, nil]
+ end
+ it "converts the filename components into render options" do
+ view_spec.stub(:_default_file_to_render) { "widgets/new.en.html.erb" }
+ view_spec.render
+ view_spec.received.first.should == [{:template => "widgets/new", :locales=>['en'], :formats=>['html'], :handlers=>['erb']},{}, nil]
end
end
Something went wrong with that request. Please try again.