diff options
author | Piotr Chmolowski <piotr@chmolowski.pl> | 2014-03-08 23:09:54 +0100 |
---|---|---|
committer | Piotr Chmolowski <piotr@chmolowski.pl> | 2014-03-09 08:47:17 +0100 |
commit | 025c691536b22cc3f0ba802f6c303dd6f955c1c3 (patch) | |
tree | 05f18a57f6c48db8528f08bed3cac3096be91f6b /actionview/test/template | |
parent | 45efd0ebf77811e43cebc68400c24652133a0f99 (diff) | |
download | rails-025c691536b22cc3f0ba802f6c303dd6f955c1c3.tar.gz rails-025c691536b22cc3f0ba802f6c303dd6f955c1c3.tar.bz2 rails-025c691536b22cc3f0ba802f6c303dd6f955c1c3.zip |
Ensure LookupContext in Digestor selects correct variant
Related to: #14242 #14243 14293
Variants passed to LookupContext#find() seem to be ignored, so
I've used the setter instead: `finder.variants = [ variant ]`.
I've also added some more test cases for variants. Hopefully this
time passing tests will mean it actually works.
Diffstat (limited to 'actionview/test/template')
-rw-r--r-- | actionview/test/template/digestor_test.rb | 8 | ||||
-rw-r--r-- | actionview/test/template/lookup_context_test.rb | 14 |
2 files changed, 19 insertions, 3 deletions
diff --git a/actionview/test/template/digestor_test.rb b/actionview/test/template/digestor_test.rb index 2406a64310..0580758dab 100644 --- a/actionview/test/template/digestor_test.rb +++ b/actionview/test/template/digestor_test.rb @@ -15,10 +15,12 @@ end class FixtureFinder FIXTURES_DIR = "#{File.dirname(__FILE__)}/../fixtures/digestor" - attr_reader :details + attr_reader :details + attr_accessor :variants def initialize - @details = {} + @details = {} + @variants = [] end def details_key @@ -28,7 +30,7 @@ class FixtureFinder def find(logical_name, keys, partial, options) partial_name = partial ? logical_name.gsub(%r|/([^/]+)$|, '/_\1') : logical_name format = options[:formats].first.to_s - format += "+#{options[:variants].first}" if options[:variants].any? + format += "+#{@variants.first}" if @variants.any? FixtureTemplate.new("digestor/#{partial_name}.#{format}.erb") end diff --git a/actionview/test/template/lookup_context_test.rb b/actionview/test/template/lookup_context_test.rb index ce9485e146..4f7823045e 100644 --- a/actionview/test/template/lookup_context_test.rb +++ b/actionview/test/template/lookup_context_test.rb @@ -93,6 +93,20 @@ class LookupContextTest < ActiveSupport::TestCase assert_equal "Hey verden", template.source end + test "find templates with given variants" do + @lookup_context.formats = [:html] + @lookup_context.variants = [:phone] + + template = @lookup_context.find("hello_world", %w(test)) + assert_equal "Hello phone!", template.source + + @lookup_context.variants = [:phone] + @lookup_context.formats = [:text] + + template = @lookup_context.find("hello_world", %w(test)) + assert_equal "Hello texty phone!", template.source + end + test "found templates respects given formats if one cannot be found from template or handler" do ActionView::Template::Handlers::Builder.expects(:default_format).returns(nil) @lookup_context.formats = [:text] |