From c471e68307f2366751fc02ea02fe4e290873ed83 Mon Sep 17 00:00:00 2001 From: Nathan Weizenbaum Date: Sat, 17 Apr 2010 16:33:57 -0700 Subject: [PATCH] [Haml] Get rid of some Rails 3 beta 3 deprecation warnings in the tests. --- lib/haml/util.rb | 22 ++++++++++++++++++++++ test/haml/template_test.rb | 4 ++-- test/haml/templates/helpers.haml | 13 +++++++++++++ test/test_helper.rb | 5 +++++ 4 files changed, 42 insertions(+), 2 deletions(-) diff --git a/lib/haml/util.rb b/lib/haml/util.rb index dec7b3d9..75f9bc3f 100644 --- a/lib/haml/util.rb +++ b/lib/haml/util.rb @@ -182,6 +182,28 @@ module Haml ActionPack::VERSION::TINY == "0.beta") end + # Returns whether this environment is using ActionPack + # version 3.0.0.beta.3 or greater. + # + # @return [Boolean] + def ap_geq_3_beta_3? + # The ActionPack module is always loaded automatically in Rails >= 3 + return false unless defined?(ActionPack) && defined?(ActionPack::VERSION) + + version = + if defined?(ActionPack::VERSION::MAJOR) + ActionPack::VERSION::MAJOR + else + # Rails 1.2 + ActionPack::VERSION::Major + end + version >= 3 && + ((defined?(ActionPack::VERSION::TINY) && ActionPack::VERSION::TINY >= 1) || + (defined?(ActionPack::VERSION::BUILD) && + ActionPack::VERSION::BUILD =~ /beta(\d+)/ && + $1.to_i >= 3)) + end + # Returns an ActionView::Template* class. # In pre-3.0 versions of Rails, most of these classes # were of the form `ActionView::TemplateFoo`, diff --git a/test/haml/template_test.rb b/test/haml/template_test.rb index cfd99a85..226e4f64 100755 --- a/test/haml/template_test.rb +++ b/test/haml/template_test.rb @@ -268,7 +268,7 @@ END HTML -- form_for :article, @article, :url => '' do |f| +- form_for #{form_for_calling_convention(:article)}, :url => '' do |f| Title: = f.text_field :title Body: @@ -367,7 +367,7 @@ HAML HTML -#{rails_block_helper_char} form_for :article, @article, :url => '' do |f| +#{rails_block_helper_char} form_for #{form_for_calling_convention(:article)}, :url => '' do |f| Title: = f.text_field :title Body: diff --git a/test/haml/templates/helpers.haml b/test/haml/templates/helpers.haml index 59707c83..4d163bb1 100644 --- a/test/haml/templates/helpers.haml +++ b/test/haml/templates/helpers.haml @@ -62,6 +62,19 @@ click +- elsif Haml::Util.ap_geq_3_beta_3? + %p + = form_tag '' + %div + = form_tag '' do + %div= submit_tag 'save' + - @foo = 'value one' + = test_partial 'partial' + = form_for @article, :as => :article, :url => '', :html => {:class => nil, :id => nil} do |f| + Title: + = f.text_field :title + Body: + = f.text_field :body - elsif Haml::Util.ap_geq_3? %p = form_tag '' diff --git a/test/test_helper.rb b/test/test_helper.rb index bf835f8e..6f9ab85e 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -42,4 +42,9 @@ class Test::Unit::TestCase return '=' if Haml::Util.ap_geq_3? return '-' end + + def form_for_calling_convention(name) + return "@#{name}, :as => :#{name}, :html => {:class => nil, :id => nil}" if Haml::Util.ap_geq_3_beta_3? + return ":#{name}, @#{name}" + end end