From 963c71edfaed3c9942caa3027b2397dd9c403f26 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Mon, 26 Jul 2010 05:52:27 +0800 Subject: Don't interpolate a blank string, avoid warnings --- activerecord/lib/active_record/base.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index c589b32dd8..5898ec3732 100644 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -1255,6 +1255,8 @@ MSG replace_named_bind_variables(statement, values.first) elsif statement.include?('?') replace_bind_variables(statement, values) + elsif statement.blank? + statement else statement % values.collect { |value| connection.quote_string(value.to_s) } end -- cgit v1.2.3 From 8abcd4999596b0a5db5cb5a61e2233e06d087523 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Mon, 26 Jul 2010 06:32:15 +0800 Subject: Bump up bundler --- rails.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rails.gemspec b/rails.gemspec index e3f811966c..db13653ebc 100644 --- a/rails.gemspec +++ b/rails.gemspec @@ -25,5 +25,5 @@ Gem::Specification.new do |s| s.add_dependency('activeresource', version) s.add_dependency('actionmailer', version) s.add_dependency('railties', version) - s.add_dependency('bundler', '>= 1.0.0.beta.5') + s.add_dependency('bundler', '>= 1.0.0.beta.10') end -- cgit v1.2.3 From 2c4fcec44d20f70d44a0c8a153c7e94d4ca606ca Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Mon, 26 Jul 2010 06:31:45 +0800 Subject: Gemfile now makes use of platforms calls with blocks instead of elsif logic to define dependencies over specific platforms --- Gemfile | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/Gemfile b/Gemfile index d2377c2d08..28b3b450ca 100644 --- a/Gemfile +++ b/Gemfile @@ -8,36 +8,35 @@ gem "mocha", ">= 0.9.8" gem "rdoc", ">= 2.5.9" gem "horo" -mri = !defined?(RUBY_ENGINE) || RUBY_ENGINE == "ruby" -if mri && RUBY_VERSION < '1.9' +# AS +gem "memcache-client", ">= 1.8.5" + +# AM +gem "text-format", "~> 1.0.0" + +platforms :mri_18 do gem "system_timer" gem "ruby-debug", ">= 0.10.3" end -if mri || RUBY_ENGINE == "rbx" +platforms :ruby do gem 'json' gem 'yajl-ruby' gem "nokogiri", ">= 1.4.2" -elsif RUBY_ENGINE == "jruby" - gem "ruby-debug" - gem "jruby-openssl" -end - -# AS -gem "memcache-client", ">= 1.8.5" -# AM -gem "text-format", "~> 1.0.0" - -# AR -if mri || RUBY_ENGINE == "rbx" + # AR gem "sqlite3-ruby", "~> 1.3.1", :require => 'sqlite3' group :db do gem "pg", ">= 0.9.0" gem "mysql", ">= 2.8.1" end -elsif RUBY_ENGINE == "jruby" +end + +platforms :jruby do + gem "system_timer" + gem "ruby-debug", ">= 0.10.3" + gem "activerecord-jdbcsqlite3-adapter" group :db do @@ -46,9 +45,11 @@ elsif RUBY_ENGINE == "jruby" end end -if ENV['CI'] +env 'CI' do gem "nokogiri", ">= 1.4.2" - # fcgi gem doesn't compile on 1.9 - gem "fcgi", ">= 0.8.8" if RUBY_VERSION < '1.9.0' + platforms :ruby_18 do + # fcgi gem doesn't compile on 1.9 + gem "fcgi", ">= 0.8.8" + end end -- cgit v1.2.3 From 53fbbf4b83cb5c2c7fcaa691129fad4df4d266ae Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Sun, 25 Jul 2010 16:01:46 -0700 Subject: fisting warning --- activesupport/lib/active_support/notifications.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/activesupport/lib/active_support/notifications.rb b/activesupport/lib/active_support/notifications.rb index 886d7183eb..ca9f5ae1ac 100644 --- a/activesupport/lib/active_support/notifications.rb +++ b/activesupport/lib/active_support/notifications.rb @@ -45,7 +45,7 @@ module ActiveSupport class << self attr_writer :notifier - delegate :publish, :unsubscribe, :to => :notifier + delegate :publish, :to => :notifier def instrument(name, payload = {}) if @instrumenters[name] -- cgit v1.2.3 From 13df581ec77cc7e5351570c5035a563b946532d5 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Sun, 25 Jul 2010 16:44:14 -0700 Subject: using AREL from the environment if it exists --- Gemfile | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 28b3b450ca..b92a6ab7a0 100644 --- a/Gemfile +++ b/Gemfile @@ -1,6 +1,11 @@ source 'http://rubygems.org' -gem "arel", :git => "git://github.com/rails/arel.git" +if ENV['AREL'] + gem "arel", :path => ENV['AREL'] +else + gem "arel", :git => "git://github.com/rails/arel.git" +end + gem "rails", :path => File.dirname(__FILE__) gem "rake", ">= 0.8.7" -- cgit v1.2.3 From 1b97701e51667e6040b4c576cce9234edef1019e Mon Sep 17 00:00:00 2001 From: wycats Date: Mon, 26 Jul 2010 00:59:54 -0700 Subject: Fix a bug where requires inside of autoloads were being added to the autoloaded_constants list, causing mayhem. [#5165 state:resolved] --- activesupport/lib/active_support/dependencies.rb | 17 +++++--- .../load_path/loaded_constant.rb | 3 ++ .../test/autoloading_fixtures/loads_constant.rb | 4 ++ .../test/autoloading_fixtures/requires_constant.rb | 5 +++ activesupport/test/dependencies_test.rb | 49 ++++++++++++++++++++++ 5 files changed, 73 insertions(+), 5 deletions(-) create mode 100644 activesupport/test/autoloading_fixtures/load_path/loaded_constant.rb create mode 100644 activesupport/test/autoloading_fixtures/loads_constant.rb create mode 100644 activesupport/test/autoloading_fixtures/requires_constant.rb diff --git a/activesupport/lib/active_support/dependencies.rb b/activesupport/lib/active_support/dependencies.rb index 9a6da38b1c..2b80bd214f 100644 --- a/activesupport/lib/active_support/dependencies.rb +++ b/activesupport/lib/active_support/dependencies.rb @@ -72,10 +72,6 @@ module ActiveSupport #:nodoc: methods.each { |m| class_eval "def #{m}(*) lock { super } end", __FILE__, __LINE__ } end - def get(key) - (val = assoc(key)) ? val[1] : [] - end - locked :concat, :each, :delete_if, :<< def new_constants_for(frames) @@ -85,7 +81,18 @@ module ActiveSupport #:nodoc: next unless mod.is_a?(Module) new_constants = mod.local_constant_names - prior_constants - get(mod_name).concat(new_constants) + + # If we are checking for constants under, say, :Object, nested under something + # else that is checking for constants also under :Object, make sure the + # parent knows that we have found, and taken care of, the constant. + # + # In particular, this means that since Kernel.require discards the constants + # it finds, parents will be notified that about those constants, and not + # consider them "new". As a result, they will not be added to the + # autoloaded_constants list. + each do |key, value| + value.concat(new_constants) if key == mod_name + end new_constants.each do |suffix| constants << ([mod_name, suffix] - ["Object"]).join("::") diff --git a/activesupport/test/autoloading_fixtures/load_path/loaded_constant.rb b/activesupport/test/autoloading_fixtures/load_path/loaded_constant.rb new file mode 100644 index 0000000000..e3d1218c96 --- /dev/null +++ b/activesupport/test/autoloading_fixtures/load_path/loaded_constant.rb @@ -0,0 +1,3 @@ +module LoadedConstant +end + diff --git a/activesupport/test/autoloading_fixtures/loads_constant.rb b/activesupport/test/autoloading_fixtures/loads_constant.rb new file mode 100644 index 0000000000..b5b80c46da --- /dev/null +++ b/activesupport/test/autoloading_fixtures/loads_constant.rb @@ -0,0 +1,4 @@ +module LoadsConstant +end + +RequiresConstant diff --git a/activesupport/test/autoloading_fixtures/requires_constant.rb b/activesupport/test/autoloading_fixtures/requires_constant.rb new file mode 100644 index 0000000000..14804a0de0 --- /dev/null +++ b/activesupport/test/autoloading_fixtures/requires_constant.rb @@ -0,0 +1,5 @@ +require "loaded_constant" + +module RequiresConstant +end + diff --git a/activesupport/test/dependencies_test.rb b/activesupport/test/dependencies_test.rb index d7bde185bd..ec5116bff4 100644 --- a/activesupport/test/dependencies_test.rb +++ b/activesupport/test/dependencies_test.rb @@ -213,6 +213,48 @@ class DependenciesTest < Test::Unit::TestCase end end + def test_doesnt_break_normal_require + path = File.expand_path("../autoloading_fixtures/load_path", __FILE__) + original_path = $:.dup + original_features = $".dup + $:.push(path) + + with_autoloading_fixtures do + RequiresConstant + assert defined?(RequiresConstant) + assert defined?(LoadedConstant) + ActiveSupport::Dependencies.clear + RequiresConstant + assert defined?(RequiresConstant) + assert defined?(LoadedConstant) + end + ensure + remove_constants(:RequiresConstant, :LoadedConstant, :LoadsConstant) + $".replace(original_features) + $:.replace(original_path) + end + + def test_doesnt_break_normal_require_nested + path = File.expand_path("../autoloading_fixtures/load_path", __FILE__) + original_path = $:.dup + original_features = $".dup + $:.push(path) + + with_autoloading_fixtures do + LoadsConstant + assert defined?(LoadsConstant) + assert defined?(LoadedConstant) + ActiveSupport::Dependencies.clear + LoadsConstant + assert defined?(LoadsConstant) + assert defined?(LoadedConstant) + end + ensure + remove_constants(:RequiresConstant, :LoadedConstant, :LoadsConstant) + $".replace(original_features) + $:.replace(original_path) + end + def failing_test_access_thru_and_upwards_fails with_autoloading_fixtures do assert ! defined?(ModuleFolder) @@ -797,4 +839,11 @@ class DependenciesTest < Test::Unit::TestCase ensure ActiveSupport::Dependencies.hook! end + +private + def remove_constants(*constants) + constants.each do |constant| + Object.send(:remove_const, constant) if Object.const_defined?(constant) + end + end end -- cgit v1.2.3 From 9789d221373123d5d9c26173985080881fcb536a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Mon, 26 Jul 2010 11:41:52 +0200 Subject: Update to latest thor. --- railties/railties.gemspec | 2 +- railties/test/generators/app_generator_test.rb | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/railties/railties.gemspec b/railties/railties.gemspec index 38dcb17ff1..d76b74190b 100644 --- a/railties/railties.gemspec +++ b/railties/railties.gemspec @@ -20,7 +20,7 @@ Gem::Specification.new do |s| s.has_rdoc = false s.add_dependency('rake', '>= 0.8.3') - s.add_dependency('thor', '~> 0.13.7') + s.add_dependency('thor', '~> 0.14.0') s.add_dependency('activesupport', version) s.add_dependency('actionpack', version) end diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index aca30e92b6..67a878e926 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -172,7 +172,7 @@ class AppGeneratorTest < Rails::Generators::TestCase template.instance_eval "def read; self; end" # Make the string respond to read generator([destination_root], :template => path).expects(:open).with(path, 'Accept' => 'application/x-thor-template').returns(template) - assert_match /It works!/, silence(:stdout){ generator.invoke } + assert_match /It works!/, silence(:stdout){ generator.invoke_all } end def test_usage_read_from_file @@ -196,14 +196,14 @@ class AppGeneratorTest < Rails::Generators::TestCase def test_dev_option generator([destination_root], :dev => true).expects(:run).with("#{@bundle_command} install") - silence(:stdout){ generator.invoke } + silence(:stdout){ generator.invoke_all } rails_path = File.expand_path('../../..', Rails.root) assert_file 'Gemfile', /^gem\s+["']rails["'],\s+:path\s+=>\s+["']#{Regexp.escape(rails_path)}["']$/ end def test_edge_option generator([destination_root], :edge => true).expects(:run).with("#{@bundle_command} install") - silence(:stdout){ generator.invoke } + silence(:stdout){ generator.invoke_all } assert_file 'Gemfile', /^gem\s+["']rails["'],\s+:git\s+=>\s+["']#{Regexp.escape("git://github.com/rails/rails.git")}["']$/ end @@ -267,7 +267,7 @@ class CustomAppGeneratorTest < Rails::Generators::TestCase template.instance_eval "def read; self; end" # Make the string respond to read generator([destination_root], :builder => path).expects(:open).with(path, 'Accept' => 'application/x-thor-template').returns(template) - capture(:stdout) { generator.invoke } + capture(:stdout) { generator.invoke_all } DEFAULT_APP_FILES.each{ |path| assert_no_file path } end -- cgit v1.2.3 From a5bb1f511f6d4ea63360eefe8c3850f9bbb7505a Mon Sep 17 00:00:00 2001 From: Neeraj Singh Date: Fri, 23 Jul 2010 15:51:46 -0400 Subject: strengthening the rescue_from test suites MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: José Valim --- activesupport/test/rescuable_test.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/activesupport/test/rescuable_test.rb b/activesupport/test/rescuable_test.rb index ff77e16edd..8d2577c64a 100644 --- a/activesupport/test/rescuable_test.rb +++ b/activesupport/test/rescuable_test.rb @@ -14,6 +14,8 @@ class Stargate include ActiveSupport::Rescuable + rescue_from WraithAttack, :with => :sos_first + rescue_from WraithAttack, :with => :sos rescue_from NuclearExplosion do @@ -45,6 +47,11 @@ class Stargate def sos @result = 'killed' end + + def sos_first + @result = 'sos_first' + end + end class RescueableTest < Test::Unit::TestCase @@ -66,4 +73,11 @@ class RescueableTest < Test::Unit::TestCase @stargate.dispatch :ronanize assert_equal 'dex', @stargate.result end + + def test_rescues_defined_later_are_added_at_end_of_the_rescue_handlers_array + expected = ["WraithAttack", "WraithAttack", "NuclearExplosion", "MadRonon"] + result = @stargate.send(:rescue_handlers).collect {|e| e.first} + assert_equal expected, result + end + end -- cgit v1.2.3 From 78c8242d2f92bccc4caedc235b8cfbcfcb3650cf Mon Sep 17 00:00:00 2001 From: Neeraj Singh Date: Mon, 26 Jul 2010 09:41:53 -0400 Subject: strengthening the test suite for rescue_from MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: José Valim --- activesupport/test/rescuable_test.rb | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/activesupport/test/rescuable_test.rb b/activesupport/test/rescuable_test.rb index 8d2577c64a..1c74ce8b2a 100644 --- a/activesupport/test/rescuable_test.rb +++ b/activesupport/test/rescuable_test.rb @@ -9,6 +9,9 @@ end class MadRonon < StandardError end +class CoolError < StandardError +end + class Stargate attr_accessor :result @@ -54,9 +57,23 @@ class Stargate end +class CoolStargate < Stargate + attr_accessor :result + + include ActiveSupport::Rescuable + + rescue_from CoolError, :with => :sos_cool_error + + def sos_cool_error + @result = 'sos_cool_error' + end +end + + class RescueableTest < Test::Unit::TestCase def setup @stargate = Stargate.new + @cool_stargate = CoolStargate.new end def test_rescue_from_with_method @@ -80,4 +97,10 @@ class RescueableTest < Test::Unit::TestCase assert_equal expected, result end + def test_children_should_inherit_rescue_defintions_from_parents_and_child_rescue_should_be_appended + expected = ["WraithAttack", "WraithAttack", "NuclearExplosion", "MadRonon", "CoolError"] + result = @cool_stargate.send(:rescue_handlers).collect {|e| e.first} + assert_equal expected, result + end + end -- cgit v1.2.3 From 0e969bdaf8ff2e3384350687aa0b583f94d6dfbc Mon Sep 17 00:00:00 2001 From: Josef Reidinger Date: Thu, 22 Jul 2010 08:42:02 +0200 Subject: fix escaping id and parameters in path [#5137 state:resolved] MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: José Valim --- activeresource/lib/active_resource/base.rb | 4 ++-- activeresource/test/cases/base_test.rb | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/activeresource/lib/active_resource/base.rb b/activeresource/lib/active_resource/base.rb index 1557e090e1..72ad2f5872 100644 --- a/activeresource/lib/active_resource/base.rb +++ b/activeresource/lib/active_resource/base.rb @@ -577,7 +577,7 @@ module ActiveResource # Default value is site.path. def prefix=(value = '/') # Replace :placeholders with '#{embedded options[:lookups]}' - prefix_call = value.gsub(/:\w+/) { |key| "\#{options[#{key}]}" } + prefix_call = value.gsub(/:\w+/) { |key| "\#{URI.escape options[#{key}].to_s}" } # Clear prefix parameters in case they have been cached @prefix_parameters = nil @@ -622,7 +622,7 @@ module ActiveResource # def element_path(id, prefix_options = {}, query_options = nil) prefix_options, query_options = split_options(prefix_options) if query_options.nil? - "#{prefix(prefix_options)}#{collection_name}/#{id}.#{format.extension}#{query_string(query_options)}" + "#{prefix(prefix_options)}#{collection_name}/#{URI.escape id.to_s}.#{format.extension}#{query_string(query_options)}" end # Gets the new element path for REST resources. diff --git a/activeresource/test/cases/base_test.rb b/activeresource/test/cases/base_test.rb index a176c037d5..91b375681b 100644 --- a/activeresource/test/cases/base_test.rb +++ b/activeresource/test/cases/base_test.rb @@ -563,6 +563,7 @@ class BaseTest < Test::Unit::TestCase assert_equal '/people/1/addresses/1.xml', StreetAddress.element_path(1, :person_id => 1) assert_equal '/people/1/addresses/1.xml', StreetAddress.element_path(1, 'person_id' => 1) assert_equal '/people/Greg/addresses/1.xml', StreetAddress.element_path(1, 'person_id' => 'Greg') + assert_equal '/people/ann%20mary/addresses/ann%20mary.xml', StreetAddress.element_path(:'ann mary', 'person_id' => 'ann mary') end def test_module_element_path -- cgit v1.2.3 From f70c0b348d2f703d763a8136df7837567f7cb691 Mon Sep 17 00:00:00 2001 From: Thiago Pradi Date: Sun, 25 Jul 2010 21:38:15 -0300 Subject: Removing unnecessary code [#5192 state:resolved] MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: José Valim --- activerecord/lib/active_record/autosave_association.rb | 4 ---- activerecord/test/cases/autosave_association_test.rb | 8 +++++++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/activerecord/lib/active_record/autosave_association.rb b/activerecord/lib/active_record/autosave_association.rb index 7517896235..062b010436 100644 --- a/activerecord/lib/active_record/autosave_association.rb +++ b/activerecord/lib/active_record/autosave_association.rb @@ -377,10 +377,6 @@ module ActiveRecord if association.updated? association_id = association.send(reflection.options[:primary_key] || :id) self[reflection.primary_key_name] = association_id - # TODO: Removing this code doesn't seem to matter... - if reflection.options[:polymorphic] - self[reflection.options[:foreign_type]] = association.class.base_class.name.to_s - end end saved if autosave diff --git a/activerecord/test/cases/autosave_association_test.rb b/activerecord/test/cases/autosave_association_test.rb index 3b89c12a3f..08694526af 100644 --- a/activerecord/test/cases/autosave_association_test.rb +++ b/activerecord/test/cases/autosave_association_test.rb @@ -171,7 +171,7 @@ class TestDefaultAutosaveAssociationOnAHasOneAssociation < ActiveRecord::TestCas end class TestDefaultAutosaveAssociationOnABelongsToAssociation < ActiveRecord::TestCase - fixtures :companies + fixtures :companies, :posts, :tags, :taggings def test_should_save_parent_but_not_invalid_child client = Client.new(:name => 'Joe (the Plumber)') @@ -312,6 +312,12 @@ class TestDefaultAutosaveAssociationOnABelongsToAssociation < ActiveRecord::Test assert_equal num_orders +1, Order.count assert_equal num_customers +2, Customer.count end + + def test_store_association_with_a_polymorphic_relationship + num_tagging = Tagging.count + tags(:misc).create_tagging(:taggable => posts(:thinking)) + assert_equal num_tagging +1, Tagging.count + end end class TestDefaultAutosaveAssociationOnAHasManyAssociation < ActiveRecord::TestCase -- cgit v1.2.3 From da845275dde0f7c13f4a24c0366f809c5006e70a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Strza=C5=82kowski?= Date: Tue, 20 Jul 2010 11:07:13 +0200 Subject: Removed deprecated APIs in text and number helpers [#5156 state:resolved] MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit They're deprecated since 2008. It's time to get rid of them. Signed-off-by: José Valim --- .../lib/action_view/helpers/number_helper.rb | 48 ++-------------------- actionpack/lib/action_view/helpers/text_helper.rb | 21 +--------- actionpack/test/template/number_helper_test.rb | 27 ------------ 3 files changed, 5 insertions(+), 91 deletions(-) diff --git a/actionpack/lib/action_view/helpers/number_helper.rb b/actionpack/lib/action_view/helpers/number_helper.rb index 37e5d91d8b..f11027bc93 100644 --- a/actionpack/lib/action_view/helpers/number_helper.rb +++ b/actionpack/lib/action_view/helpers/number_helper.rb @@ -186,14 +186,7 @@ module ActionView # number_with_delimiter(12345678.05, :locale => :fr) # => 12 345 678,05 # number_with_delimiter(98765432.98, :delimiter => " ", :separator => ",") # # => 98 765 432,98 - # - # You can still use number_with_delimiter with the old API that accepts the - # +delimiter+ as its optional second and the +separator+ as its - # optional third parameter: - # number_with_delimiter(12345678, " ") # => 12 345 678 - # number_with_delimiter(12345678.05, ".", ",") # => 12.345.678,05 - def number_with_delimiter(number, *args) - options = args.extract_options! + def number_with_delimiter(number, options = {}) options.symbolize_keys! begin @@ -207,14 +200,6 @@ module ActionView end defaults = I18n.translate(:'number.format', :locale => options[:locale], :default => {}) - - unless args.empty? - ActiveSupport::Deprecation.warn('number_with_delimiter takes an option hash ' + - 'instead of separate delimiter and precision arguments.', caller) - options[:delimiter] ||= args[0] if args[0] - options[:separator] ||= args[1] if args[1] - end - options = options.reverse_merge(defaults) parts = number.to_s.split('.') @@ -249,13 +234,7 @@ module ActionView # number_with_precision(389.32314, :precision => 4, :significant => true) # => 389.3 # number_with_precision(1111.2345, :precision => 2, :separator => ',', :delimiter => '.') # # => 1.111,23 - # - # You can still use number_with_precision with the old API that accepts the - # +precision+ as its optional second parameter: - # number_with_precision(111.2345, 2) # => 111.23 - def number_with_precision(number, *args) - - options = args.extract_options! + def number_with_precision(number, options = {}) options.symbolize_keys! number = begin @@ -272,13 +251,6 @@ module ActionView precision_defaults = I18n.translate(:'number.precision.format', :locale => options[:locale], :default => {}) defaults = defaults.merge(precision_defaults) - #Backwards compatibility - unless args.empty? - ActiveSupport::Deprecation.warn('number_with_precision takes an option hash ' + - 'instead of a separate precision argument.', caller) - options[:precision] ||= args[0] if args[0] - end - options = options.reverse_merge(defaults) # Allow the user to unset default values: Eg.: :significant => false precision = options.delete :precision significant = options.delete :significant @@ -337,13 +309,7 @@ module ActionView # :strip_insignificant_zeros to +false+ to change that): # number_to_human_size(1234567890123, :precision => 5) # => "1.1229 TB" # number_to_human_size(524288000, :precision=>5) # => "500 MB" - # - # You can still use number_to_human_size with the old API that accepts the - # +precision+ as its optional second parameter: - # number_to_human_size(1234567, 1) # => 1 MB - # number_to_human_size(483989, 2) # => 470 KB - def number_to_human_size(number, *args) - options = args.extract_options! + def number_to_human_size(number, options = {}) options.symbolize_keys! number = begin @@ -359,13 +325,7 @@ module ActionView defaults = I18n.translate(:'number.format', :locale => options[:locale], :default => {}) human = I18n.translate(:'number.human.format', :locale => options[:locale], :default => {}) defaults = defaults.merge(human) - - unless args.empty? - ActiveSupport::Deprecation.warn('number_to_human_size takes an option hash ' + - 'instead of a separate precision argument.', caller) - options[:precision] ||= args[0] if args[0] - end - + options = options.reverse_merge(defaults) #for backwards compatibility with those that didn't add strip_insignificant_zeros to their locale files options[:strip_insignificant_zeros] = true if not options.key?(:strip_insignificant_zeros) diff --git a/actionpack/lib/action_view/helpers/text_helper.rb b/actionpack/lib/action_view/helpers/text_helper.rb index 0be8a2c36e..52a016c9c1 100644 --- a/actionpack/lib/action_view/helpers/text_helper.rb +++ b/actionpack/lib/action_view/helpers/text_helper.rb @@ -61,27 +61,8 @@ module ActionView # # truncate("

Once upon a time in a world far far away

") # # => "

Once upon a time in a wo..." - # - # You can still use truncate with the old API that accepts the - # +length+ as its optional second and the +ellipsis+ as its - # optional third parameter: - # truncate("Once upon a time in a world far far away", 14) - # # => "Once upon a..." - # - # truncate("And they found that many people were sleeping better.", 25, "... (continued)") - # # => "And they f... (continued)" - def truncate(text, *args) - options = args.extract_options! - unless args.empty? - ActiveSupport::Deprecation.warn('truncate takes an option hash instead of separate ' + - 'length and omission arguments', caller) - - options[:length] = args[0] || 30 - options[:omission] = args[1] || "..." - end - + def truncate(text, options = {}) options.reverse_merge!(:length => 30) - text.truncate(options.delete(:length), options) if text end diff --git a/actionpack/test/template/number_helper_test.rb b/actionpack/test/template/number_helper_test.rb index 14e81fc9dc..7f787b7b00 100644 --- a/actionpack/test/template/number_helper_test.rb +++ b/actionpack/test/template/number_helper_test.rb @@ -82,16 +82,6 @@ class NumberHelperTest < ActionView::TestCase assert_equal '12.345.678,05', number_with_delimiter(12345678.05, :delimiter => '.', :separator => ',') end - def test_number_with_delimiter_old_api - silence_deprecation_warnings - assert_equal '12 345 678', number_with_delimiter(12345678, " ") - assert_equal '12-345-678.05', number_with_delimiter(12345678.05, '-') - assert_equal '12.345.678,05', number_with_delimiter(12345678.05, '.', ',') - assert_equal '12,345,678.05', number_with_delimiter(12345678.05, ',', '.') - assert_equal '12 345 678-05', number_with_delimiter(12345678.05, ',', '.', :delimiter => ' ', :separator => '-') - restore_deprecation_warnings - end - def test_number_with_precision assert_equal("111.235", number_with_precision(111.2346)) assert_equal("31.83", number_with_precision(31.825, :precision => 2)) @@ -146,15 +136,6 @@ class NumberHelperTest < ActionView::TestCase assert_equal "12", number_with_precision("12.3", :precision => 0, :significant => true ) end - def test_number_with_precision_old_api - silence_deprecation_warnings - assert_equal("31.8250", number_with_precision(31.825, 4)) - assert_equal("111.235", number_with_precision(111.2346, 3)) - assert_equal("111.00", number_with_precision(111, 2)) - assert_equal("111.000", number_with_precision(111, 2, :precision =>3)) - restore_deprecation_warnings - end - def test_number_to_human_size assert_equal '0 Bytes', number_to_human_size(0) assert_equal '1 Byte', number_to_human_size(1) @@ -202,14 +183,6 @@ class NumberHelperTest < ActionView::TestCase assert_equal '1.000,1 TB', number_to_human_size(terabytes(1000.1), :precision => 5, :delimiter => '.', :separator => ',') end - def test_number_to_human_size_old_api - silence_deprecation_warnings - assert_equal '1.3143 KB', number_to_human_size(kilobytes(1.3143), 4, :significant => false) - assert_equal '10.45 KB', number_to_human_size(kilobytes(10.453), 4) - assert_equal '10 KB', number_to_human_size(kilobytes(10.453), 4, :precision => 2) - restore_deprecation_warnings - end - def test_number_to_human assert_equal '123', number_to_human(123) assert_equal '1.23 Thousand', number_to_human(1234) -- cgit v1.2.3 From a44652baed1d26a4f63380c406e05f7a2ddd4a12 Mon Sep 17 00:00:00 2001 From: Neeraj Singh Date: Thu, 22 Jul 2010 15:20:53 -0400 Subject: No need to check for :uniq MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [#5170 state:resolved] Signed-off-by: José Valim --- .../lib/active_record/associations/association_collection.rb | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/activerecord/lib/active_record/associations/association_collection.rb b/activerecord/lib/active_record/associations/association_collection.rb index f346a19a3a..4ce3b34819 100644 --- a/activerecord/lib/active_record/associations/association_collection.rb +++ b/activerecord/lib/active_record/associations/association_collection.rb @@ -478,13 +478,10 @@ module ActiveRecord callback(:before_add, record) yield(record) if block_given? @target ||= [] unless loaded? - index = @target.index(record) - unless @reflection.options[:uniq] && index - if index - @target[index] = record - else + if index = @target.index(record) + @target[index] = record + else @target << record - end end callback(:after_add, record) set_inverse_instance(record, @owner) -- cgit v1.2.3 From 514624e53c7b3008e3c492ef01f4d85188cdbbd7 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Mon, 26 Jul 2010 12:16:36 -0300 Subject: Fixes usage message when running rails without --dev on a cloned rails repo --- railties/lib/rails/generators/base.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/railties/lib/rails/generators/base.rb b/railties/lib/rails/generators/base.rb index 67a9a6030d..fdfceb14ce 100644 --- a/railties/lib/rails/generators/base.rb +++ b/railties/lib/rails/generators/base.rb @@ -3,7 +3,7 @@ begin rescue LoadError puts "Thor is not available.\nIf you ran this command from a git checkout " \ "of Rails, please make sure thor is installed,\nand run this command " \ - "as `ruby /path/to/rails new myapp --dev`" + "as `ruby #{$0} #{ARGV.join(" ")} --dev`" exit end -- cgit v1.2.3 From 4ea1753fc2bcbaca0a50073463ef4b020a2e3c5f Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Mon, 26 Jul 2010 12:42:07 -0300 Subject: This is for making sure const_missing is triggered without warnings --- activesupport/test/autoloading_fixtures/loads_constant.rb | 3 ++- activesupport/test/dependencies_test.rb | 10 ++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/activesupport/test/autoloading_fixtures/loads_constant.rb b/activesupport/test/autoloading_fixtures/loads_constant.rb index b5b80c46da..0b30dc8bca 100644 --- a/activesupport/test/autoloading_fixtures/loads_constant.rb +++ b/activesupport/test/autoloading_fixtures/loads_constant.rb @@ -1,4 +1,5 @@ module LoadsConstant end -RequiresConstant +# The _ = assignment is to prevent warnings +_ = RequiresConstant diff --git a/activesupport/test/dependencies_test.rb b/activesupport/test/dependencies_test.rb index ec5116bff4..f98d823f00 100644 --- a/activesupport/test/dependencies_test.rb +++ b/activesupport/test/dependencies_test.rb @@ -220,11 +220,12 @@ class DependenciesTest < Test::Unit::TestCase $:.push(path) with_autoloading_fixtures do - RequiresConstant + # The _ = assignments are to prevent warnings + _ = RequiresConstant assert defined?(RequiresConstant) assert defined?(LoadedConstant) ActiveSupport::Dependencies.clear - RequiresConstant + _ = RequiresConstant assert defined?(RequiresConstant) assert defined?(LoadedConstant) end @@ -241,11 +242,12 @@ class DependenciesTest < Test::Unit::TestCase $:.push(path) with_autoloading_fixtures do - LoadsConstant + # The _ = assignments are to prevent warnings + _ = LoadsConstant assert defined?(LoadsConstant) assert defined?(LoadedConstant) ActiveSupport::Dependencies.clear - LoadsConstant + _ = LoadsConstant assert defined?(LoadsConstant) assert defined?(LoadedConstant) end -- cgit v1.2.3 From e87e3db200e5b711237da8bcdc873044a984ad90 Mon Sep 17 00:00:00 2001 From: Bernerd Schaefer Date: Sat, 17 Jul 2010 16:45:19 -0500 Subject: XmlMini.rename_key emits valid xml with dasherize This resolves issues for libraries which use '_' prefixed keys in their attributes hash, such as Mongoid. A key like "_id" or "_type" will no longer be converted to "<-id>" and "<-type>". Signed-off-by: wycats --- activesupport/lib/active_support/xml_mini.rb | 6 +++- activesupport/test/test_xml_mini.rb | 49 ++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 activesupport/test/test_xml_mini.rb diff --git a/activesupport/lib/active_support/xml_mini.rb b/activesupport/lib/active_support/xml_mini.rb index 38e20d32da..352172027b 100644 --- a/activesupport/lib/active_support/xml_mini.rb +++ b/activesupport/lib/active_support/xml_mini.rb @@ -129,12 +129,16 @@ module ActiveSupport camelize = options.has_key?(:camelize) && options[:camelize] dasherize = !options.has_key?(:dasherize) || options[:dasherize] key = key.camelize if camelize - key = key.dasherize if dasherize + key = _dasherize(key) if dasherize key end protected + def _dasherize(key) + key.gsub(/(?!^[_]*)_(?![_]*$)/, '-') + end + # TODO: Add support for other encodings def _parse_binary(bin, entity) #:nodoc: case entity['encoding'] diff --git a/activesupport/test/test_xml_mini.rb b/activesupport/test/test_xml_mini.rb new file mode 100644 index 0000000000..585eb15c6e --- /dev/null +++ b/activesupport/test/test_xml_mini.rb @@ -0,0 +1,49 @@ +require 'abstract_unit' +require 'active_support/xml_mini' + +class XmlMiniTest < Test::Unit::TestCase + def test_rename_key_dasherizes_by_default + assert_equal "my-key", ActiveSupport::XmlMini.rename_key("my_key") + end + + def test_rename_key_does_nothing_with_dasherize_true + assert_equal "my-key", ActiveSupport::XmlMini.rename_key("my_key", :dasherize => true) + end + + def test_rename_key_does_nothing_with_dasherize_false + assert_equal "my_key", ActiveSupport::XmlMini.rename_key("my_key", :dasherize => false) + end + + def test_rename_key_camelizes_with_camelize_true + assert_equal "MyKey", ActiveSupport::XmlMini.rename_key("my_key", :camelize => true) + end + + def test_rename_key_camelizes_with_camelize_true + assert_equal "MyKey", ActiveSupport::XmlMini.rename_key("my_key", :camelize => true) + end + + def test_rename_key_does_not_dasherize_leading_underscores + assert_equal "_id", ActiveSupport::XmlMini.rename_key("_id") + end + + def test_rename_key_with_leading_underscore_dasherizes_interior_underscores + assert_equal "_my-key", ActiveSupport::XmlMini.rename_key("_my_key") + end + + def test_rename_key_does_not_dasherize_trailing_underscores + assert_equal "id_", ActiveSupport::XmlMini.rename_key("id_") + end + + def test_rename_key_with_trailing_underscore_dasherizes_interior_underscores + assert_equal "my-key_", ActiveSupport::XmlMini.rename_key("my_key_") + end + + def test_rename_key_does_not_dasherize_multiple_leading_underscores + assert_equal "__id", ActiveSupport::XmlMini.rename_key("__id") + end + + def test_rename_key_does_not_dasherize_multiple_leading_underscores + assert_equal "id__", ActiveSupport::XmlMini.rename_key("id__") + end + +end -- cgit v1.2.3 From e56c9ef08db49653f0c63a0305d563b2514b266b Mon Sep 17 00:00:00 2001 From: Leigh Caplan Date: Wed, 21 Jul 2010 16:46:38 -0700 Subject: Override new on proxy objects so that they never wrap nil or false. --- activesupport/lib/active_support/deprecation/proxy_wrappers.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/activesupport/lib/active_support/deprecation/proxy_wrappers.rb b/activesupport/lib/active_support/deprecation/proxy_wrappers.rb index dec56715be..b22d0a6941 100644 --- a/activesupport/lib/active_support/deprecation/proxy_wrappers.rb +++ b/activesupport/lib/active_support/deprecation/proxy_wrappers.rb @@ -3,6 +3,13 @@ require 'active_support/inflector' module ActiveSupport module Deprecation class DeprecationProxy #:nodoc: + def self.new(*args, &block) + object = args.first + + return object unless object + super + end + instance_methods.each { |m| undef_method m unless m =~ /^__|^object_id$/ } # Don't give a deprecation warning on inspect since test/unit and error -- cgit v1.2.3 From 37d82f2ca0f8e81d473969586e70826f27538072 Mon Sep 17 00:00:00 2001 From: Leigh Caplan Date: Wed, 21 Jul 2010 16:51:15 -0700 Subject: Test to ensure that falsy objects aren't wrapped by deprecation proxies --- .../test/deprecation/proxy_wrappers_test.rb | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 activesupport/test/deprecation/proxy_wrappers_test.rb diff --git a/activesupport/test/deprecation/proxy_wrappers_test.rb b/activesupport/test/deprecation/proxy_wrappers_test.rb new file mode 100644 index 0000000000..c507eff38e --- /dev/null +++ b/activesupport/test/deprecation/proxy_wrappers_test.rb @@ -0,0 +1,22 @@ +require 'abstract_unit' +require 'active_support/deprecation' + +class ProxyWrappersTest < Test::Unit::TestCase + Waffles = false + NewWaffles = :hamburgers + + def test_deprecated_object_proxy_doesnt_wrap_falsy_objects + proxy = ActiveSupport::Deprecation::DeprecatedObjectProxy.new(nil, "message") + assert !proxy + end + + def test_deprecated_instance_variable_proxy_doesnt_wrap_falsy_objects + proxy = ActiveSupport::Deprecation::DeprecatedInstanceVariableProxy.new(nil, :waffles) + assert !proxy + end + + def test_deprecated_constant_proxy_doesnt_wrap_falsy_objects + proxy = ActiveSupport::Deprecation::DeprecatedConstantProxy.new(Waffles, NewWaffles) + assert !proxy + end +end \ No newline at end of file -- cgit v1.2.3 From fd589db8633ef3eda398365f2a6d551edfed547e Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Sun, 25 Jul 2010 20:59:18 -0300 Subject: Changed returning with tap on guides --- railties/guides/source/plugins.textile | 2 +- railties/guides/source/security.textile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/railties/guides/source/plugins.textile b/railties/guides/source/plugins.textile index e853ba79e9..82f2276153 100644 --- a/railties/guides/source/plugins.textile +++ b/railties/guides/source/plugins.textile @@ -1274,7 +1274,7 @@ class YaffleMigrationGenerator < Rails::Generator::NamedBase end def yaffle_local_assigns - returning(assigns = {}) do + {}.tap do |assigns| assigns[:migration_action] = "add" assigns[:class_name] = "add_yaffle_fields_to_#{custom_file_name}" assigns[:table_name] = custom_file_name diff --git a/railties/guides/source/security.textile b/railties/guides/source/security.textile index 60108d5ab3..8ce0001080 100644 --- a/railties/guides/source/security.textile +++ b/railties/guides/source/security.textile @@ -286,7 +286,7 @@ When filtering user input file names, _(highlight)don't try to remove malicious def sanitize_filename(filename) - returning filename.strip do |name| + filename.strip.tap do |name| # NOTE: File.basename doesn't work right with Windows paths on Unix # get only the filename, not the whole path name.sub! /\A.*(\\|\/)/, '' -- cgit v1.2.3 From c819c131f2d08a8c9089a6ef0dcadcf912e2538c Mon Sep 17 00:00:00 2001 From: Wincent Colaiuta Date: Mon, 26 Jul 2010 16:59:22 +0200 Subject: doc: cleanup respond_to documentation Signed-off-by: Wincent Colaiuta --- .../lib/action_controller/metal/mime_responds.rb | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/actionpack/lib/action_controller/metal/mime_responds.rb b/actionpack/lib/action_controller/metal/mime_responds.rb index c12e5797ae..c6d4c6d936 100644 --- a/actionpack/lib/action_controller/metal/mime_responds.rb +++ b/actionpack/lib/action_controller/metal/mime_responds.rb @@ -12,27 +12,30 @@ module ActionController #:nodoc: end module ClassMethods - # Defines mimes that are rendered by default when invoking respond_with. + # Defines mime types that are rendered by default when invoking + # respond_with. # # Examples: # # respond_to :html, :xml, :json # - # All actions on your controller will respond to :html, :xml and :json. + # Specifies that all actions in the controller respond to requests + # for :html, :xml and :json. # - # But if you want to specify it based on your actions, you can use only and - # except: + # To specify on per-action basis, use :only and + # :except with an array of actions or a single action: # # respond_to :html # respond_to :xml, :json, :except => [ :edit ] # - # The definition above explicits that all actions respond to :html. And all - # actions except :edit respond to :xml and :json. - # - # You can specify also only parameters: + # This specifies that all actions respond to :html + # and all actions except :edit respond to :xml and + # :json. # # respond_to :rjs, :only => :create # + # This specifies that the :create action and no other responds + # to :rjs. def respond_to(*mimes) options = mimes.extract_options! @@ -49,7 +52,7 @@ module ActionController #:nodoc: self.mimes_for_respond_to = new.freeze end - # Clear all mimes in respond_to. + # Clear all mime types in respond_to. # def clear_respond_to self.mimes_for_respond_to = ActiveSupport::OrderedHash.new.freeze -- cgit v1.2.3