aboutsummaryrefslogtreecommitdiffstats
path: root/actionview/test
diff options
context:
space:
mode:
authorPiotr Chmolowski <piotr@chmolowski.pl>2014-03-08 23:09:54 +0100
committerPiotr Chmolowski <piotr@chmolowski.pl>2014-03-09 08:47:17 +0100
commit025c691536b22cc3f0ba802f6c303dd6f955c1c3 (patch)
tree05f18a57f6c48db8528f08bed3cac3096be91f6b /actionview/test
parent45efd0ebf77811e43cebc68400c24652133a0f99 (diff)
downloadrails-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')
-rw-r--r--actionview/test/fixtures/test/hello_world.html+phone.erb1
-rw-r--r--actionview/test/fixtures/test/hello_world.text+phone.erb1
-rw-r--r--actionview/test/template/digestor_test.rb8
-rw-r--r--actionview/test/template/lookup_context_test.rb14
4 files changed, 21 insertions, 3 deletions
diff --git a/actionview/test/fixtures/test/hello_world.html+phone.erb b/actionview/test/fixtures/test/hello_world.html+phone.erb
new file mode 100644
index 0000000000..b4f236f878
--- /dev/null
+++ b/actionview/test/fixtures/test/hello_world.html+phone.erb
@@ -0,0 +1 @@
+Hello phone! \ No newline at end of file
diff --git a/actionview/test/fixtures/test/hello_world.text+phone.erb b/actionview/test/fixtures/test/hello_world.text+phone.erb
new file mode 100644
index 0000000000..611e2ee442
--- /dev/null
+++ b/actionview/test/fixtures/test/hello_world.text+phone.erb
@@ -0,0 +1 @@
+Hello texty phone! \ No newline at end of file
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]