From e05e9979075b37342b7c88e557dbffd672b2086a Mon Sep 17 00:00:00 2001 From: Jeff Kreeftmeijer Date: Wed, 9 Mar 2011 10:58:18 +0100 Subject: Add a note to discourage users from using presence validators with allow_(nil|blank) --- railties/guides/source/active_record_validations_callbacks.textile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/railties/guides/source/active_record_validations_callbacks.textile b/railties/guides/source/active_record_validations_callbacks.textile index 58a184a48e..2301d6715d 100644 --- a/railties/guides/source/active_record_validations_callbacks.textile +++ b/railties/guides/source/active_record_validations_callbacks.textile @@ -463,9 +463,11 @@ h3. Common Validation Options There are some common options that all the validation helpers can use. Here they are, except for the +:if+ and +:unless+ options, which are discussed later in "Conditional Validation":#conditional-validation. +TIP: Note that +allow_nil+ and +allow_blank+ will be ignored when using the presence validator. Please use the length validator if you want to validate if something is a specific length but allows for +nil+ values. + h4. +:allow_nil+ -The +:allow_nil+ option skips the validation when the value being validated is +nil+. Using +:allow_nil+ with +validates_presence_of+ allows for +nil+, but any other +blank?+ value will still be rejected. +The +:allow_nil+ option skips the validation when the value being validated is +nil+. class Coffee < ActiveRecord::Base -- cgit v1.2.3 From f65023cbda53c9920d4a0ac3f31bc4de624805cf Mon Sep 17 00:00:00 2001 From: Diego Carrion Date: Wed, 9 Mar 2011 14:56:44 -0300 Subject: expose ActionMailer::MailHelper in the RDoc --- Rakefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Rakefile b/Rakefile index 53acd077d7..607ce01fd0 100755 --- a/Rakefile +++ b/Rakefile @@ -85,6 +85,7 @@ RDoc::Task.new do |rdoc| rdoc.rdoc_files.include('actionmailer/README.rdoc') rdoc.rdoc_files.include('actionmailer/CHANGELOG') rdoc.rdoc_files.include('actionmailer/lib/action_mailer/base.rb') + rdoc.rdoc_files.include('actionmailer/lib/action_mailer/mail_helper.rb') rdoc.rdoc_files.exclude('actionmailer/lib/action_mailer/vendor/*') rdoc.rdoc_files.include('activesupport/README.rdoc') -- cgit v1.2.3 From 6fba542f4487bd825203ea5b14bf038fe722709b Mon Sep 17 00:00:00 2001 From: David Aaron Fendley Date: Wed, 9 Mar 2011 18:06:50 -0600 Subject: Added note re: functional tests and HTTP methods. --- railties/guides/source/testing.textile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/railties/guides/source/testing.textile b/railties/guides/source/testing.textile index a75cedbdc1..f4111269ba 100644 --- a/railties/guides/source/testing.textile +++ b/railties/guides/source/testing.textile @@ -500,6 +500,8 @@ If you're familiar with the HTTP protocol, you'll know that +get+ is a type of r All of request types are methods that you can use, however, you'll probably end up using the first two more often than the others. +NOTE: Functional tests do not verify whether the specified request type should be be accepted by the action. Request types in this context exist to make your tests more descriptive. + h4. The Four Hashes of the Apocalypse After a request has been made by using one of the 5 methods (+get+, +post+, etc.) and processed, you will have 4 Hash objects ready for use: -- cgit v1.2.3 From 439ccdc3cf2aa46e22a8dfb7debcee073127df86 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Thu, 10 Mar 2011 19:58:55 +0530 Subject: update plugin urls to reflect official maintainers --- railties/guides/source/3_0_release_notes.textile | 4 ++-- railties/guides/source/active_record_validations_callbacks.textile | 2 +- railties/guides/source/debugging_rails_applications.textile | 2 +- railties/guides/source/form_helpers.textile | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/railties/guides/source/3_0_release_notes.textile b/railties/guides/source/3_0_release_notes.textile index 001f458fd9..f75b245ed8 100644 --- a/railties/guides/source/3_0_release_notes.textile +++ b/railties/guides/source/3_0_release_notes.textile @@ -59,12 +59,12 @@ The +config.gem+ method is gone and has been replaced by using +bundler+ and a + h4. Upgrade Process -To help with the upgrade process, a plugin named "Rails Upgrade":http://github.com/rails/rails_upgrade has been created to automate part of it. +To help with the upgrade process, a plugin named "Rails Upgrade":http://github.com/jm/rails_upgrade has been created to automate part of it. Simply install the plugin, then run +rake rails:upgrade:check+ to check your app for pieces that need to be updated (with links to information on how to update them). It also offers a task to generate a +Gemfile+ based on your current +config.gem+ calls and a task to generate a new routes file from your current one. To get the plugin, simply run the following: -$ ruby script/plugin install git://github.com/rails/rails_upgrade.git +$ ruby script/plugin install git://github.com/jm/rails_upgrade.git You can see an example of how that works at "Rails Upgrade is now an Official Plugin":http://omgbloglol.com/post/364624593/rails-upgrade-is-now-an-official-plugin diff --git a/railties/guides/source/active_record_validations_callbacks.textile b/railties/guides/source/active_record_validations_callbacks.textile index 2301d6715d..bfb06a9cd5 100644 --- a/railties/guides/source/active_record_validations_callbacks.textile +++ b/railties/guides/source/active_record_validations_callbacks.textile @@ -744,7 +744,7 @@ Rails maintains an official plugin that provides helpers to display the error me h4. Installing as a plugin -$ rails plugin install git://github.com/rails/dynamic_form.git +$ rails plugin install git://github.com/joelmoss/dynamic_form.git h4 Installing as a Gem diff --git a/railties/guides/source/debugging_rails_applications.textile b/railties/guides/source/debugging_rails_applications.textile index 67e17056e5..045b8823ca 100644 --- a/railties/guides/source/debugging_rails_applications.textile +++ b/railties/guides/source/debugging_rails_applications.textile @@ -686,7 +686,7 @@ There are some Rails plugins to help you to find errors and debug your applicati * "Query Trace":https://github.com/ntalbott/query_trace/tree/master: Adds query origin tracing to your logs. * "Query Stats":https://github.com/dan-manges/query_stats/tree/master: A Rails plugin to track database queries. * "Query Reviewer":http://code.google.com/p/query-reviewer/: This rails plugin not only runs "EXPLAIN" before each of your select queries in development, but provides a small DIV in the rendered output of each page with the summary of warnings for each query that it analyzed. -* "Exception Notifier":https://github.com/rails/exception_notification/tree/master: Provides a mailer object and a default set of templates for sending email notifications when errors occur in a Rails application. +* "Exception Notifier":https://github.com/smartinez87/exception_notification/tree/master: Provides a mailer object and a default set of templates for sending email notifications when errors occur in a Rails application. * "Exception Logger":https://github.com/defunkt/exception_logger/tree/master: Logs your Rails exceptions in the database and provides a funky web interface to manage them. h3. References diff --git a/railties/guides/source/form_helpers.textile b/railties/guides/source/form_helpers.textile index 0cfc005f80..1f21c27ae6 100644 --- a/railties/guides/source/form_helpers.textile +++ b/railties/guides/source/form_helpers.textile @@ -475,7 +475,7 @@ To leverage time zone support in Rails, you have to ask your users what time zon There is also +time_zone_options_for_select+ helper for a more manual (therefore more customizable) way of doing this. Read the API documentation to learn about the possible arguments for these two methods. -Rails _used_ to have a +country_select+ helper for choosing countries, but this has been extracted to the "country_select plugin":https://github.com/rails/country_select/tree/master. When using this, be aware that the exclusion or inclusion of certain names from the list can be somewhat controversial (and was the reason this functionality was extracted from Rails). +Rails _used_ to have a +country_select+ helper for choosing countries, but this has been extracted to the "country_select plugin":https://github.com/chrislerum/country_select. When using this, be aware that the exclusion or inclusion of certain names from the list can be somewhat controversial (and was the reason this functionality was extracted from Rails). h3. Using Date and Time Form Helpers -- cgit v1.2.3 From ee7c48678f443ed7fb77fe97042f7a698e359df9 Mon Sep 17 00:00:00 2001 From: Mike Gehard Date: Thu, 10 Mar 2011 10:08:30 -0500 Subject: Minor formatting changes and remove a comment --- railties/guides/source/plugins.textile | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/railties/guides/source/plugins.textile b/railties/guides/source/plugins.textile index daca50ee9e..2d9821e627 100644 --- a/railties/guides/source/plugins.textile +++ b/railties/guides/source/plugins.textile @@ -45,9 +45,9 @@ as a gem. This tutorial will begin to bridge that gap by demonstrating how to c "Enginex gem":http://www.github.com/josevalim/enginex. - gem install enginex - enginex --help - enginex yaffle +$ gem install enginex +$ enginex --help +$ enginex yaffle This command will create a new directory named "yaffle" within the current directory. @@ -401,7 +401,9 @@ h3. Publishing your Gem Gem plugins in progress can be easily be shared from any Git repository. To share the Yaffle gem with others, simply commit the code to a Git repository (like Github) and add a line to the Gemfile of the any application: -gem 'yaffle', :git => 'git://github.com/yaffle_watcher/yaffle.git' + +gem 'yaffle', :git => 'git://github.com/yaffle_watcher/yaffle.git' + After running +bundle install+, your gem functionality will be available to the application. @@ -450,8 +452,6 @@ Once your comments are good to go, navigate to your plugin directory and run: $ rake rdoc -!!!!!!!!!!!!!! Make sure these still make sense. Add any references that you see fit. !!!!!!!!!!!!! - h4. References * "Developing a RubyGem using Bundler":https://github.com/radar/guides/blob/master/gem-development.md @@ -462,6 +462,7 @@ h4. References h3. Changelog +* March 10, 2011: Minor formatting tweaks. * February 13, 2011: Get guide in synch with Rails 3.0.3. Remove information not compatible with Rails 3. Send reader elsewhere for information that is covered elsewhere. * April 4, 2010: Fixed document to validate XHTML 1.0 Strict. "Jaime Iniesta":http://jaimeiniesta.com -- cgit v1.2.3 From 0a51e43866e54c5445a8efce253d60df23e3a7d6 Mon Sep 17 00:00:00 2001 From: Paco Guzman Date: Fri, 11 Mar 2011 23:08:55 +0100 Subject: remove some blanks --- activerecord/lib/active_record/locking/optimistic.rb | 2 +- activerecord/lib/active_record/locking/pessimistic.rb | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/activerecord/lib/active_record/locking/optimistic.rb b/activerecord/lib/active_record/locking/optimistic.rb index 6b2b1ebafe..9a31675782 100644 --- a/activerecord/lib/active_record/locking/optimistic.rb +++ b/activerecord/lib/active_record/locking/optimistic.rb @@ -23,7 +23,7 @@ module ActiveRecord # p2.first_name = "should fail" # p2.save # Raises a ActiveRecord::StaleObjectError # - # Optimistic locking will also check for stale data when objects are destroyed. Example: + # Optimistic locking will also check for stale data when objects are destroyed. Example: # # p1 = Person.find(1) # p2 = Person.find(1) diff --git a/activerecord/lib/active_record/locking/pessimistic.rb b/activerecord/lib/active_record/locking/pessimistic.rb index 557b277d6b..862cf8f72a 100644 --- a/activerecord/lib/active_record/locking/pessimistic.rb +++ b/activerecord/lib/active_record/locking/pessimistic.rb @@ -9,9 +9,8 @@ module ActiveRecord # Account.find(1, :lock => true) # # Pass :lock => 'some locking clause' to give a database-specific locking clause - # of your own such as 'LOCK IN SHARE MODE' or 'FOR UPDATE NOWAIT'. + # of your own such as 'LOCK IN SHARE MODE' or 'FOR UPDATE NOWAIT'. Example: # - # Example: # Account.transaction do # # select * from accounts where name = 'shugo' limit 1 for update # shugo = Account.where("name = 'shugo'").lock(true).first @@ -24,6 +23,7 @@ module ActiveRecord # # You can also use ActiveRecord::Base#lock! method to lock one record by id. # This may be better if you don't need to lock every row. Example: + # # Account.transaction do # # select * from accounts where ... # accounts = Account.where(...).all @@ -44,7 +44,7 @@ module ActiveRecord module Pessimistic # Obtain a row lock on this record. Reloads the record to obtain the requested # lock. Pass an SQL locking clause to append the end of the SELECT statement - # or pass true for "FOR UPDATE" (the default, an exclusive row lock). Returns + # or pass true for "FOR UPDATE" (the default, an exclusive row lock). Returns # the locked record. def lock!(lock = true) reload(:lock => lock) if persisted? -- cgit v1.2.3 From 63c8ea9a6a28ecaabb236dae094d99d9d1ee2ecd Mon Sep 17 00:00:00 2001 From: Rolf Timmermans Date: Sat, 12 Mar 2011 14:24:36 +0100 Subject: adds a couple of missing AS dependencies --- activesupport/lib/active_support/callbacks.rb | 1 + activesupport/lib/active_support/core_ext/module/deprecation.rb | 2 ++ 2 files changed, 3 insertions(+) diff --git a/activesupport/lib/active_support/callbacks.rb b/activesupport/lib/active_support/callbacks.rb index b531a094cf..a7a7836f03 100644 --- a/activesupport/lib/active_support/callbacks.rb +++ b/activesupport/lib/active_support/callbacks.rb @@ -1,3 +1,4 @@ +require 'active_support/concern' require 'active_support/descendants_tracker' require 'active_support/core_ext/array/wrap' require 'active_support/core_ext/class/attribute' diff --git a/activesupport/lib/active_support/core_ext/module/deprecation.rb b/activesupport/lib/active_support/core_ext/module/deprecation.rb index 5a5b4e3f80..9c169a2598 100644 --- a/activesupport/lib/active_support/core_ext/module/deprecation.rb +++ b/activesupport/lib/active_support/core_ext/module/deprecation.rb @@ -1,3 +1,5 @@ +require 'active_support/deprecation' + class Module # Declare that a method has been deprecated. # deprecate :foo -- cgit v1.2.3 From 58de03f077b0da1cb923f28835b00cd092de3c08 Mon Sep 17 00:00:00 2001 From: Mike Gehard Date: Wed, 9 Feb 2011 06:32:40 -0700 Subject: Add additional text to NotImplementedErrors [#6328 state:resolved] Signed-off-by: Santiago Pastorino --- actionpack/lib/action_view/template/resolver.rb | 2 +- activemodel/lib/active_model/validator.rb | 4 ++-- activerecord/lib/active_record/associations/singular_association.rb | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/actionpack/lib/action_view/template/resolver.rb b/actionpack/lib/action_view/template/resolver.rb index 4d999fb3b2..589b2a1a76 100644 --- a/actionpack/lib/action_view/template/resolver.rb +++ b/actionpack/lib/action_view/template/resolver.rb @@ -36,7 +36,7 @@ module ActionView # because Resolver guarantees that the arguments are present and # normalized. def find_templates(name, prefix, partial, details) - raise NotImplementedError + raise NotImplementedError, "Subclasses must implement a find_templates(name, prefix, partial, details) method" end # Helpers that builds a path. Useful for building virtual paths. diff --git a/activemodel/lib/active_model/validator.rb b/activemodel/lib/active_model/validator.rb index 1c6123eb09..c5ed8d22d3 100644 --- a/activemodel/lib/active_model/validator.rb +++ b/activemodel/lib/active_model/validator.rb @@ -120,7 +120,7 @@ module ActiveModel #:nodoc: # Override this method in subclasses with validation logic, adding errors # to the records +errors+ array where necessary. def validate(record) - raise NotImplementedError + raise NotImplementedError, "Subclasses must implement a validate(record) method." end end @@ -156,7 +156,7 @@ module ActiveModel #:nodoc: # Override this method in subclasses with the validation logic, adding # errors to the records +errors+ array where necessary. def validate_each(record, attribute, value) - raise NotImplementedError + raise NotImplementedError, "Subclasses must implement a validate_each(record, attribute, value) method" end # Hook method that gets called by the initializer allowing verification diff --git a/activerecord/lib/active_record/associations/singular_association.rb b/activerecord/lib/active_record/associations/singular_association.rb index 0d8e45adb5..4edbe216be 100644 --- a/activerecord/lib/active_record/associations/singular_association.rb +++ b/activerecord/lib/active_record/associations/singular_association.rb @@ -37,7 +37,7 @@ module ActiveRecord # Implemented by subclasses def replace(record) - raise NotImplementedError + raise NotImplementedError, "Subclasses must implement a replace(record) method" end def set_new_record(record) -- cgit v1.2.3 From 46f6a2e3889bae420589f429b09722a37dbdf18d Mon Sep 17 00:00:00 2001 From: Rolf Timmermans Date: Sat, 12 Mar 2011 23:49:25 +0800 Subject: It should be possible to use ActiveSupport::DescendantTracker without getting ActiveSupport::Dependencies for free. --- activesupport/lib/active_support/descendants_tracker.rb | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/activesupport/lib/active_support/descendants_tracker.rb b/activesupport/lib/active_support/descendants_tracker.rb index 4d1cfacc95..e2a8b4d4e3 100644 --- a/activesupport/lib/active_support/descendants_tracker.rb +++ b/activesupport/lib/active_support/descendants_tracker.rb @@ -1,5 +1,3 @@ -require 'active_support/dependencies' - module ActiveSupport # This module provides an internal implementation to track descendants # which is faster than iterating through ObjectSpace. @@ -18,12 +16,16 @@ module ActiveSupport end def self.clear - @@direct_descendants.each do |klass, descendants| - if ActiveSupport::Dependencies.autoloaded?(klass) - @@direct_descendants.delete(klass) - else - descendants.reject! { |v| ActiveSupport::Dependencies.autoloaded?(v) } + if defined? ActiveSupport::Dependencies + @@direct_descendants.each do |klass, descendants| + if ActiveSupport::Dependencies.autoloaded?(klass) + @@direct_descendants.delete(klass) + else + descendants.reject! { |v| ActiveSupport::Dependencies.autoloaded?(v) } + end end + else + @@direct_descendants.clear end end -- cgit v1.2.3 From 1a3fe8ce42e202630e6b1d8cf7137002e270ebdb Mon Sep 17 00:00:00 2001 From: Rolf Timmermans Date: Sat, 12 Mar 2011 23:05:52 +0800 Subject: Prevent callbacks in child classes from being executed more than once. --- activesupport/lib/active_support/callbacks.rb | 2 +- activesupport/test/callback_inheritance_test.rb | 30 +++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/activesupport/lib/active_support/callbacks.rb b/activesupport/lib/active_support/callbacks.rb index a7a7836f03..418102352f 100644 --- a/activesupport/lib/active_support/callbacks.rb +++ b/activesupport/lib/active_support/callbacks.rb @@ -416,7 +416,7 @@ module ActiveSupport options = filters.last.is_a?(Hash) ? filters.pop : {} filters.unshift(block) if block - ([self] + ActiveSupport::DescendantsTracker.descendants(self)).each do |target| + ([self] + ActiveSupport::DescendantsTracker.descendants(self)).reverse.each do |target| chain = target.send("_#{name}_callbacks") yield target, chain.dup, type, filters, options target.__define_runner(name) diff --git a/activesupport/test/callback_inheritance_test.rb b/activesupport/test/callback_inheritance_test.rb index 71249050fc..d569cbb4fb 100644 --- a/activesupport/test/callback_inheritance_test.rb +++ b/activesupport/test/callback_inheritance_test.rb @@ -82,6 +82,30 @@ class EmptyChild < EmptyParent end end +class CountingParent + include ActiveSupport::Callbacks + + attr_reader :count + + define_callbacks :dispatch + + def initialize + @count = 0 + end + + def count! + @count += 1 + end + + def dispatch + run_callbacks(:dispatch) + self + end +end + +class CountingChild < CountingParent +end + class BasicCallbacksTest < Test::Unit::TestCase def setup @index = GrandParent.new("index").dispatch @@ -147,4 +171,10 @@ class DynamicInheritedCallbacks < Test::Unit::TestCase child = EmptyChild.new.dispatch assert child.performed? end + + def test_callbacks_should_be_performed_once_in_child_class + CountingParent.set_callback(:dispatch, :before) { count! } + child = CountingChild.new.dispatch + assert_equal 1, child.count + end end -- cgit v1.2.3 From 015192560b7e81639430d7e46c410bf6a3cd9223 Mon Sep 17 00:00:00 2001 From: Chris Oliver Date: Fri, 11 Mar 2011 16:13:44 -0600 Subject: Fixed a bug when empty? was called on a grouped Relation that wasn't loaded [#5829 state:resolved] Signed-off-by: Andrew White --- activerecord/lib/active_record/relation.rb | 5 ++++- activerecord/test/cases/relations_test.rb | 30 ++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb index 5af20bf38b..371403f510 100644 --- a/activerecord/lib/active_record/relation.rb +++ b/activerecord/lib/active_record/relation.rb @@ -110,7 +110,10 @@ module ActiveRecord # Returns true if there are no records. def empty? - loaded? ? @records.empty? : count.zero? + return @records.empty? if loaded? + + c = count + c.respond_to?(:zero?) ? c.zero? : c.empty? end def any? diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb index 948fcf7012..ec53218451 100644 --- a/activerecord/test/cases/relations_test.rb +++ b/activerecord/test/cases/relations_test.rb @@ -673,6 +673,36 @@ class RelationTest < ActiveRecord::TestCase assert_equal expected, posts.count end + def test_empty + posts = Post.scoped + + assert_queries(1) { assert_equal false, posts.empty? } + assert ! posts.loaded? + + no_posts = posts.where(:title => "") + assert_queries(1) { assert_equal true, no_posts.empty? } + assert ! no_posts.loaded? + + best_posts = posts.where(:comments_count => 0) + best_posts.to_a # force load + assert_no_queries { assert_equal false, best_posts.empty? } + end + + def test_empty_complex_chained_relations + posts = Post.select("comments_count").where("id is not null").group("author_id").where("comments_count > 0") + assert_queries(1) { assert_equal false, posts.empty? } + assert ! posts.loaded? + + no_posts = posts.where(:title => "") + assert_queries(1) { assert_equal true, no_posts.empty? } + assert ! no_posts.loaded? + + best_posts = posts.where(:comments_count => 0) + best_posts.to_a # force load + assert_no_queries { assert_equal true, best_posts.empty? } + assert best_posts.loaded? + end + def test_any posts = Post.scoped -- cgit v1.2.3 From f48d3d4df6c8ff6ab544f5fe384af2a0552984d7 Mon Sep 17 00:00:00 2001 From: Andriy Tyurnikov Date: Thu, 10 Mar 2011 19:50:55 +0200 Subject: length validation for fixnums Signed-off-by: Santiago Pastorino --- activemodel/lib/active_model/validations/length.rb | 3 ++- activemodel/test/cases/validations/length_validation_test.rb | 11 +++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/activemodel/lib/active_model/validations/length.rb b/activemodel/lib/active_model/validations/length.rb index 7af6c83460..3e6f6e62e6 100644 --- a/activemodel/lib/active_model/validations/length.rb +++ b/activemodel/lib/active_model/validations/length.rb @@ -42,7 +42,8 @@ module ActiveModel next unless check_value = options[key] value ||= [] if key == :maximum - + + next if value.kind_of?(Fixnum) && value.to_s.size.send(validity_check, check_value) next if value && value.size.send(validity_check, check_value) errors_options = options.except(*RESERVED_OPTIONS) diff --git a/activemodel/test/cases/validations/length_validation_test.rb b/activemodel/test/cases/validations/length_validation_test.rb index 1e6180a938..5e4f4f5cae 100644 --- a/activemodel/test/cases/validations/length_validation_test.rb +++ b/activemodel/test/cases/validations/length_validation_test.rb @@ -341,6 +341,17 @@ class LengthValidationTest < ActiveModel::TestCase assert t.errors[:content].any? assert_equal ["Your essay must be at least 5 words."], t.errors[:content] end + + def test_validates_length_of_for_fixnum + Topic.validates_length_of(:approved, :is => 4) + + t = Topic.new("title" => "uhohuhoh", "content" => "whatever", :approved => 1) + assert t.invalid? + assert t.errors[:approved].any? + + t = Topic.new("title" => "uhohuhoh", "content" => "whatever", :approved => 1234) + assert t.valid? + end def test_validates_length_of_for_ruby_class Person.validates_length_of :karma, :minimum => 5 -- cgit v1.2.3 From 157c37f55854a17fcb50e77b7636fab01773df3c Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Sat, 12 Mar 2011 21:10:19 -0200 Subject: Refactor length validation --- activemodel/lib/active_model/validations/length.rb | 6 +++--- activemodel/test/cases/validations/length_validation_test.rb | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/activemodel/lib/active_model/validations/length.rb b/activemodel/lib/active_model/validations/length.rb index 3e6f6e62e6..72735cfb89 100644 --- a/activemodel/lib/active_model/validations/length.rb +++ b/activemodel/lib/active_model/validations/length.rb @@ -42,9 +42,9 @@ module ActiveModel next unless check_value = options[key] value ||= [] if key == :maximum - - next if value.kind_of?(Fixnum) && value.to_s.size.send(validity_check, check_value) - next if value && value.size.send(validity_check, check_value) + + value_length = value.respond_to?(:length) ? value.length : value.to_s.length + next if value_length.send(validity_check, check_value) errors_options = options.except(*RESERVED_OPTIONS) errors_options[:count] = check_value diff --git a/activemodel/test/cases/validations/length_validation_test.rb b/activemodel/test/cases/validations/length_validation_test.rb index 5e4f4f5cae..f02514639b 100644 --- a/activemodel/test/cases/validations/length_validation_test.rb +++ b/activemodel/test/cases/validations/length_validation_test.rb @@ -341,14 +341,14 @@ class LengthValidationTest < ActiveModel::TestCase assert t.errors[:content].any? assert_equal ["Your essay must be at least 5 words."], t.errors[:content] end - + def test_validates_length_of_for_fixnum Topic.validates_length_of(:approved, :is => 4) - + t = Topic.new("title" => "uhohuhoh", "content" => "whatever", :approved => 1) assert t.invalid? assert t.errors[:approved].any? - + t = Topic.new("title" => "uhohuhoh", "content" => "whatever", :approved => 1234) assert t.valid? end -- cgit v1.2.3 From 9f5b1e1ed08df9dbedded0a6b7798d919d43b9a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sun, 13 Mar 2011 08:35:50 +0100 Subject: Revert "It should be possible to use ActiveSupport::DescendantTracker without getting ActiveSupport::Dependencies for free." This reverts commit 46f6a2e3889bae420589f429b09722a37dbdf18d. Caused failures on CI. rake test:isolated on activesupport directory show them. --- activesupport/lib/active_support/descendants_tracker.rb | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/activesupport/lib/active_support/descendants_tracker.rb b/activesupport/lib/active_support/descendants_tracker.rb index e2a8b4d4e3..4d1cfacc95 100644 --- a/activesupport/lib/active_support/descendants_tracker.rb +++ b/activesupport/lib/active_support/descendants_tracker.rb @@ -1,3 +1,5 @@ +require 'active_support/dependencies' + module ActiveSupport # This module provides an internal implementation to track descendants # which is faster than iterating through ObjectSpace. @@ -16,16 +18,12 @@ module ActiveSupport end def self.clear - if defined? ActiveSupport::Dependencies - @@direct_descendants.each do |klass, descendants| - if ActiveSupport::Dependencies.autoloaded?(klass) - @@direct_descendants.delete(klass) - else - descendants.reject! { |v| ActiveSupport::Dependencies.autoloaded?(v) } - end + @@direct_descendants.each do |klass, descendants| + if ActiveSupport::Dependencies.autoloaded?(klass) + @@direct_descendants.delete(klass) + else + descendants.reject! { |v| ActiveSupport::Dependencies.autoloaded?(v) } end - else - @@direct_descendants.clear end end -- cgit v1.2.3 From c540b3544100a29d3d34ada220c175dbd70bab2f Mon Sep 17 00:00:00 2001 From: Lars Smit Date: Sun, 13 Mar 2011 09:07:23 +0100 Subject: Removed double texts --- .../guides/source/contributing_to_ruby_on_rails.textile | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/railties/guides/source/contributing_to_ruby_on_rails.textile b/railties/guides/source/contributing_to_ruby_on_rails.textile index 4ba01a2a8f..846a25d6d2 100644 --- a/railties/guides/source/contributing_to_ruby_on_rails.textile +++ b/railties/guides/source/contributing_to_ruby_on_rails.textile @@ -364,19 +364,6 @@ Please make sure the patch does not introduce whitespace errors: $ git apply --whitespace=error-all mynew_patch.diff -You can check your patches by applying your patch to an different dedicated branch: - - -$ git checkout -b testing_branch -$ git apply --check my_new_patch.diff - - -You can make sure your patches don't add any whitespace by applying it yourself using the --whitespace=error-all option. Make sure you are on your dedicated test branche and: - - -$ git apply --whitespace=error-all mynew_patch.diff - - h4. Create a Lighthouse Ticket -- cgit v1.2.3 From deae670e9a8c042ed24a7262b91283f05bcaa3d6 Mon Sep 17 00:00:00 2001 From: Manuel Meurer Date: Sun, 13 Mar 2011 15:14:51 +0700 Subject: Change ActionView::ViewPathSet to ActionView::PathSet --- actionpack/lib/abstract_controller/view_paths.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/actionpack/lib/abstract_controller/view_paths.rb b/actionpack/lib/abstract_controller/view_paths.rb index 6544c8949a..cea0f5ad1e 100644 --- a/actionpack/lib/abstract_controller/view_paths.rb +++ b/actionpack/lib/abstract_controller/view_paths.rb @@ -36,7 +36,7 @@ module AbstractController # ==== Parameters # * path - If a String is provided, it gets converted into # the default view path. You may also provide a custom view path - # (see ActionView::ViewPathSet for more information) + # (see ActionView::PathSet for more information) def append_view_path(path) self.view_paths = view_paths.dup + Array(path) end @@ -46,7 +46,7 @@ module AbstractController # ==== Parameters # * path - If a String is provided, it gets converted into # the default view path. You may also provide a custom view path - # (see ActionView::ViewPathSet for more information) + # (see ActionView::PathSet for more information) def prepend_view_path(path) self.view_paths = Array(path) + view_paths.dup end @@ -59,8 +59,8 @@ module AbstractController # Set the view paths. # # ==== Parameters - # * paths - If a ViewPathSet is provided, use that; - # otherwise, process the parameter into a ViewPathSet. + # * paths - If a PathSet is provided, use that; + # otherwise, process the parameter into a PathSet. def view_paths=(paths) self._view_paths = ActionView::Base.process_view_paths(paths) self._view_paths.freeze -- cgit v1.2.3 From 47871b025e2205c9686ab1a20464cb4fac98cd74 Mon Sep 17 00:00:00 2001 From: Andrew White Date: Sun, 13 Mar 2011 08:37:16 +0000 Subject: Remove invalid test The test fails on PostgreSQL when trying to load the records as the comments_count field is not included in the GROUP BY clause. --- activerecord/test/cases/relations_test.rb | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb index ec53218451..00b7c26080 100644 --- a/activerecord/test/cases/relations_test.rb +++ b/activerecord/test/cases/relations_test.rb @@ -690,17 +690,13 @@ class RelationTest < ActiveRecord::TestCase def test_empty_complex_chained_relations posts = Post.select("comments_count").where("id is not null").group("author_id").where("comments_count > 0") + assert_queries(1) { assert_equal false, posts.empty? } assert ! posts.loaded? no_posts = posts.where(:title => "") assert_queries(1) { assert_equal true, no_posts.empty? } assert ! no_posts.loaded? - - best_posts = posts.where(:comments_count => 0) - best_posts.to_a # force load - assert_no_queries { assert_equal true, best_posts.empty? } - assert best_posts.loaded? end def test_any -- cgit v1.2.3 From 9b64399684ded345e1006a0b5d54f94f5f44f121 Mon Sep 17 00:00:00 2001 From: Anders Elfving Date: Sun, 13 Mar 2011 11:49:56 +0100 Subject: Adjust unique constraint comment to include info about the RecordNotUnique exception --- activerecord/lib/active_record/validations/uniqueness.rb | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/activerecord/lib/active_record/validations/uniqueness.rb b/activerecord/lib/active_record/validations/uniqueness.rb index a96796f9ff..9cd6c26322 100644 --- a/activerecord/lib/active_record/validations/uniqueness.rb +++ b/activerecord/lib/active_record/validations/uniqueness.rb @@ -173,10 +173,17 @@ module ActiveRecord # This technique is also known as optimistic concurrency control: # http://en.wikipedia.org/wiki/Optimistic_concurrency_control # - # Active Record currently provides no way to distinguish unique - # index constraint errors from other types of database errors, so you - # will have to parse the (database-specific) exception message to detect - # such a case. + # The bundled ActiveRecord::ConnectionAdapters distinguish unique index + # constraint errors from other types of database errors by throwing an + # ActiveRecord::RecordNotUnique exception. + # For other adapters you will have to parse the (database-specific) exception + # message to detect such a case. + # The following bundled adapters throw the ActiveRecord::RecordNotUnique exception: + # * ActiveRecord::ConnectionAdapters::MysqlAdapter + # * ActiveRecord::ConnectionAdapters::Mysql2Adapter + # * ActiveRecord::ConnectionAdapters::SQLiteAdapter + # * ActiveRecord::ConnectionAdapters::SQLite3Adapter + # * ActiveRecord::ConnectionAdapters::PostgreSQLAdapter # def validates_uniqueness_of(*attr_names) validates_with UniquenessValidator, _merge_attributes(attr_names) -- cgit v1.2.3 From 88d8ca2ef976ea802657c92a3d27e2737247ee5c Mon Sep 17 00:00:00 2001 From: Jack Dempsey Date: Sun, 13 Mar 2011 08:01:12 +0800 Subject: use parens and silence ambiguous args warnings --- .../test/generators/plugin_new_generator_test.rb | 12 +++++------ railties/test/generators/shared_generator_tests.rb | 24 +++++++++++----------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/railties/test/generators/plugin_new_generator_test.rb b/railties/test/generators/plugin_new_generator_test.rb index 2a8b337144..3c11c8dbaf 100644 --- a/railties/test/generators/plugin_new_generator_test.rb +++ b/railties/test/generators/plugin_new_generator_test.rb @@ -55,7 +55,7 @@ class PluginNewGeneratorTest < Rails::Generators::TestCase def test_ensure_that_plugin_options_are_not_passed_to_app_generator FileUtils.cd(Rails.root) - assert_no_match /It works from file!.*It works_from_file/, run_generator([destination_root, "-m", "lib/template.rb"]) + assert_no_match(/It works from file!.*It works_from_file/, run_generator([destination_root, "-m", "lib/template.rb"])) end def test_ensure_that_test_dummy_can_be_generated_from_a_template @@ -85,7 +85,7 @@ class PluginNewGeneratorTest < Rails::Generators::TestCase def test_ensure_that_skip_active_record_option_is_passed_to_app_generator run_generator [destination_root, "--skip_active_record"] assert_no_file "test/dummy/config/database.yml" - assert_no_match /ActiveRecord/, File.read(File.join(destination_root, "test/test_helper.rb")) + assert_no_match(/ActiveRecord/, File.read(File.join(destination_root, "test/test_helper.rb"))) end def test_ensure_that_database_option_is_passed_to_app_generator @@ -134,21 +134,21 @@ class PluginNewGeneratorTest < Rails::Generators::TestCase def test_template_from_dir_pwd FileUtils.cd(Rails.root) - assert_match /It works from file!/, run_generator([destination_root, "-m", "lib/template.rb"]) + assert_match(/It works from file!/, run_generator([destination_root, "-m", "lib/template.rb"])) end def test_ensure_that_tests_works run_generator FileUtils.cd destination_root `bundle install` - assert_match /1 tests, 1 assertions, 0 failures, 0 errors/, `bundle exec rake test` + assert_match(/1 tests, 1 assertions, 0 failures, 0 errors/, `bundle exec rake test`) end def test_ensure_that_tests_works_in_full_mode run_generator [destination_root, "--full", "--skip_active_record"] FileUtils.cd destination_root `bundle install` - assert_match /2 tests, 2 assertions, 0 failures, 0 errors/, `bundle exec rake test` + assert_match(/2 tests, 2 assertions, 0 failures, 0 errors/, `bundle exec rake test`) end def test_creating_engine_in_full_mode @@ -159,7 +159,7 @@ class PluginNewGeneratorTest < Rails::Generators::TestCase end def test_being_quiet_while_creating_dummy_application - assert_no_match /create\s+config\/application.rb/, run_generator + assert_no_match(/create\s+config\/application.rb/, run_generator) end def test_create_mountable_application_with_mountable_option diff --git a/railties/test/generators/shared_generator_tests.rb b/railties/test/generators/shared_generator_tests.rb index 9e6169721b..592da39ccd 100644 --- a/railties/test/generators/shared_generator_tests.rb +++ b/railties/test/generators/shared_generator_tests.rb @@ -32,7 +32,7 @@ module SharedGeneratorTests def test_invalid_database_option_raises_an_error content = capture(:stderr){ run_generator([destination_root, "-d", "unknown"]) } - assert_match /Invalid value for \-\-database option/, content + assert_match(/Invalid value for \-\-database option/, content) end def test_test_unit_is_skipped_if_required @@ -42,21 +42,21 @@ module SharedGeneratorTests def test_options_before_application_name_raises_an_error content = capture(:stderr){ run_generator(["--pretend", destination_root]) } - assert_match /Options should be given after the \w+ name. For details run: rails( plugin)? --help\n/, content + assert_match(/Options should be given after the \w+ name. For details run: rails( plugin)? --help\n/, content) end def test_name_collision_raises_an_error reserved_words = %w[application destroy plugin runner test] reserved_words.each do |reserved| content = capture(:stderr){ run_generator [File.join(destination_root, reserved)] } - assert_match /Invalid \w+ name #{reserved}. Please give a name which does not match one of the reserved rails words.\n/, content + assert_match(/Invalid \w+ name #{reserved}. Please give a name which does not match one of the reserved rails words.\n/, content) end end def test_name_raises_an_error_if_name_already_used_constant %w{ String Hash Class Module Set Symbol }.each do |ruby_class| content = capture(:stderr){ run_generator [File.join(destination_root, ruby_class)] } - assert_match /Invalid \w+ name #{ruby_class}, constant #{ruby_class} is already in use. Please choose another \w+ name.\n/, content + assert_match(/Invalid \w+ name #{ruby_class}, constant #{ruby_class} is already in use. Please choose another \w+ name.\n/, content) end end @@ -72,8 +72,8 @@ module SharedGeneratorTests def test_template_raises_an_error_with_invalid_path content = capture(:stderr){ run_generator([destination_root, "-m", "non/existant/path"]) } - assert_match /The template \[.*\] could not be loaded/, content - assert_match /non\/existant\/path/, content + assert_match(/The template \[.*\] could not be loaded/, content) + assert_match(/non\/existant\/path/, content) end def test_template_is_executed_when_supplied @@ -82,7 +82,7 @@ module SharedGeneratorTests 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_all } + assert_match(/It works!/, silence(:stdout){ generator.invoke_all }) end def test_dev_option @@ -100,8 +100,8 @@ module SharedGeneratorTests def test_template_raises_an_error_with_invalid_path content = capture(:stderr){ run_generator([destination_root, "-m", "non/existant/path"]) } - assert_match /The template \[.*\] could not be loaded/, content - assert_match /non\/existant\/path/, content + assert_match(/The template \[.*\] could not be loaded/, content) + assert_match(/non\/existant\/path/, content) end def test_template_is_executed_when_supplied @@ -110,7 +110,7 @@ module SharedGeneratorTests 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_all } + assert_match(/It works!/, silence(:stdout){ generator.invoke_all }) end def test_template_is_executed_when_supplied_an_https_path @@ -119,7 +119,7 @@ module SharedGeneratorTests 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_all } + assert_match(/It works!/, silence(:stdout){ generator.invoke_all }) end def test_dev_option @@ -191,6 +191,6 @@ module SharedCustomGeneratorTests generator([destination_root], :builder => path).expects(:open).with(path, 'Accept' => 'application/x-thor-template').returns(template) capture(:stdout) { generator.invoke_all } - default_files.each{ |path| assert_no_file path } + default_files.each{ |path| assert_no_file(path) } end end -- cgit v1.2.3 From dfa9e2811320d44ff140f115a4f7a3abb41bda16 Mon Sep 17 00:00:00 2001 From: Jack Dempsey Date: Sun, 13 Mar 2011 08:59:20 +0800 Subject: silence @dummy_path not defined warnings --- railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb b/railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb index 5b4687ce64..c373ca5e67 100644 --- a/railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb +++ b/railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb @@ -145,6 +145,7 @@ task :default => :test def initialize(*args) raise Error, "Options should be given after the plugin name. For details run: rails plugin --help" if args[0].blank? + @dummy_path = nil super end -- cgit v1.2.3 From de5e41f855a8d715d99eec6195f9b31cc4048b99 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Mon, 14 Mar 2011 21:59:58 +0100 Subject: move the tips about :allow_(nil|blank) near their explanations, also no need to say these are options for all validators if they are not --- .../guides/source/active_record_validations_callbacks.textile | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/railties/guides/source/active_record_validations_callbacks.textile b/railties/guides/source/active_record_validations_callbacks.textile index bfb06a9cd5..e5349d546c 100644 --- a/railties/guides/source/active_record_validations_callbacks.textile +++ b/railties/guides/source/active_record_validations_callbacks.textile @@ -461,9 +461,7 @@ The block receives the model, the attribute's name and the attribute's value. Yo h3. Common Validation Options -There are some common options that all the validation helpers can use. Here they are, except for the +:if+ and +:unless+ options, which are discussed later in "Conditional Validation":#conditional-validation. - -TIP: Note that +allow_nil+ and +allow_blank+ will be ignored when using the presence validator. Please use the length validator if you want to validate if something is a specific length but allows for +nil+ values. +These are common validation options: h4. +:allow_nil+ @@ -476,6 +474,8 @@ class Coffee < ActiveRecord::Base end +TIP: +:allow_nil+ is ignored by the presence validator. + h4. +:allow_blank+ The +:allow_blank+ option is similar to the +:allow_nil+ option. This option will let validation pass if the attribute's value is +blank?+, like +nil+ or an empty string for example. @@ -489,6 +489,8 @@ Topic.create("title" => "").valid? # => true Topic.create("title" => nil).valid? # => true +TIP: +:allow_blank+ is ignored by the presence validator. + h4. +:message+ As you've already seen, the +:message+ option lets you specify the message that will be added to the +errors+ collection when validation fails. When this option is not used, Active Record will use the respective default error message for each validation helper. -- cgit v1.2.3 From a0826cceea8d181cc28046929c9025147f9325af Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Mon, 14 Mar 2011 22:06:27 +0100 Subject: be be -> be --- railties/guides/source/testing.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/railties/guides/source/testing.textile b/railties/guides/source/testing.textile index f4111269ba..4ebdb3edf6 100644 --- a/railties/guides/source/testing.textile +++ b/railties/guides/source/testing.textile @@ -500,7 +500,7 @@ If you're familiar with the HTTP protocol, you'll know that +get+ is a type of r All of request types are methods that you can use, however, you'll probably end up using the first two more often than the others. -NOTE: Functional tests do not verify whether the specified request type should be be accepted by the action. Request types in this context exist to make your tests more descriptive. +NOTE: Functional tests do not verify whether the specified request type should be accepted by the action. Request types in this context exist to make your tests more descriptive. h4. The Four Hashes of the Apocalypse -- cgit v1.2.3 From 833a90594e9fe25819c5111c853adc91eb6071c2 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Mon, 14 Mar 2011 15:15:40 -0700 Subject: RegexpWithNamedGroups is only used for path_info, so only apply to path info --- actionpack/lib/action_dispatch/routing/route.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/actionpack/lib/action_dispatch/routing/route.rb b/actionpack/lib/action_dispatch/routing/route.rb index eae9d4ea6d..0f90b2169d 100644 --- a/actionpack/lib/action_dispatch/routing/route.rb +++ b/actionpack/lib/action_dispatch/routing/route.rb @@ -23,7 +23,8 @@ module ActionDispatch conditions[:path_info] = ::Rack::Mount::Strexp.compile(path, requirements, SEPARATORS, anchor) end - @conditions = Hash[conditions.map { |k,v| [k, Rack::Mount::RegexpWithNamedGroups.new(v)] }] + @conditions = conditions.dup + @conditions[:path_info] = Rack::Mount::RegexpWithNamedGroups.new(@conditions[:path_info]) if @conditions[:path_info] @conditions.delete_if{ |k,v| k != :path_info && !valid_condition?(k) } @requirements.delete_if{ |k,v| !valid_condition?(k) } end -- cgit v1.2.3 From 9ba2d422f58e17b9e3d2a91d9979017aa36d13bd Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Mon, 14 Mar 2011 16:17:05 -0700 Subject: stop splatting arguments so that we can understand wtf is going on --- actionpack/lib/action_dispatch/routing/mapper.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index f67708722b..e7b267da81 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -365,8 +365,9 @@ module ActionDispatch # # See Scoping#defaults for its scope equivalent. def match(path, options=nil) - mapping = Mapping.new(@set, @scope, path, options || {}).to_route - @set.add_route(*mapping) + mapping = Mapping.new(@set, @scope, path, options || {}) + app, conditions, requirements, defaults, as, anchor = mapping.to_route + @set.add_route(app, conditions, requirements, defaults, as, anchor) self end -- cgit v1.2.3 From 9f2706d770a2a5513d54dac9d0fb536f787a434b Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Mon, 14 Mar 2011 18:26:30 -0700 Subject: use a list to represent the supported verbs for a route object --- actionpack/lib/action_dispatch/routing/mapper.rb | 4 ++-- actionpack/lib/action_dispatch/routing/route.rb | 20 +++++++++++--------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index e7b267da81..cc6b8aa82d 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -195,8 +195,8 @@ module ActionDispatch def request_method_condition if via = @options[:via] - via = Array(via).map { |m| m.to_s.dasherize.upcase } - { :request_method => %r[^#{via.join('|')}$] } + list = Array(via).map { |m| m.to_s.dasherize.upcase } + { :request_method => list } else { } end diff --git a/actionpack/lib/action_dispatch/routing/route.rb b/actionpack/lib/action_dispatch/routing/route.rb index 0f90b2169d..a049510182 100644 --- a/actionpack/lib/action_dispatch/routing/route.rb +++ b/actionpack/lib/action_dispatch/routing/route.rb @@ -12,6 +12,8 @@ module ActionDispatch @defaults = defaults @name = name + # FIXME: we should not be doing this much work in a constructor. + @requirements = requirements.merge(defaults) @requirements.delete(:controller) if @requirements[:controller].is_a?(Regexp) @requirements.delete_if { |k, v| @@ -23,22 +25,22 @@ module ActionDispatch conditions[:path_info] = ::Rack::Mount::Strexp.compile(path, requirements, SEPARATORS, anchor) end + @verbs = conditions[:request_method] || [] + @conditions = conditions.dup + + # Rack-Mount requires that :request_method be a regular expression. + # :request_method represents the HTTP verb that matches this route. + # + # Here we munge values before they get sent on to rack-mount. + @conditions[:request_method] = %r[^#{verb}$] unless @verbs.empty? @conditions[:path_info] = Rack::Mount::RegexpWithNamedGroups.new(@conditions[:path_info]) if @conditions[:path_info] @conditions.delete_if{ |k,v| k != :path_info && !valid_condition?(k) } @requirements.delete_if{ |k,v| !valid_condition?(k) } end def verb - if method = conditions[:request_method] - case method - when Regexp - source = method.source.upcase - source =~ /\A\^[-A-Z|]+\$\Z/ ? source[1..-2] : source - else - method.to_s.upcase - end - end + @verbs.join '|' end def segment_keys -- cgit v1.2.3 From 7bd70dcd6c62fb94e3298e926f69a4e1946739cc Mon Sep 17 00:00:00 2001 From: Norman Clarke Date: Tue, 15 Mar 2011 10:06:53 -0300 Subject: Add messages to plain assertions. Signed-off-by: Santiago Pastorino --- activemodel/lib/active_model/lint.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/activemodel/lib/active_model/lint.rb b/activemodel/lib/active_model/lint.rb index 957d1b9d70..35e216ac6b 100644 --- a/activemodel/lib/active_model/lint.rb +++ b/activemodel/lib/active_model/lint.rb @@ -23,7 +23,7 @@ module ActiveModel def test_to_key assert model.respond_to?(:to_key), "The model should respond to to_key" def model.persisted?() false end - assert model.to_key.nil? + assert model.to_key.nil?, "to_key should return nil when `persisted?` returns false" end # == Responds to to_param @@ -40,7 +40,7 @@ module ActiveModel assert model.respond_to?(:to_param), "The model should respond to to_param" def model.to_key() [1] end def model.persisted?() false end - assert model.to_param.nil? + assert model.to_param.nil?, "to_param should return nil when `persited?` returns false" end # == Responds to valid? -- cgit v1.2.3 From e8458d37c56a94fae5f4c762b1767f67e10ddb43 Mon Sep 17 00:00:00 2001 From: Andrew White Date: Wed, 16 Mar 2011 10:28:40 +0000 Subject: Fix typo in assertion message --- activemodel/lib/active_model/lint.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/activemodel/lib/active_model/lint.rb b/activemodel/lib/active_model/lint.rb index 35e216ac6b..b71ef4b22e 100644 --- a/activemodel/lib/active_model/lint.rb +++ b/activemodel/lib/active_model/lint.rb @@ -40,7 +40,7 @@ module ActiveModel assert model.respond_to?(:to_param), "The model should respond to to_param" def model.to_key() [1] end def model.persisted?() false end - assert model.to_param.nil?, "to_param should return nil when `persited?` returns false" + assert model.to_param.nil?, "to_param should return nil when `persisted?` returns false" end # == Responds to valid? -- cgit v1.2.3 From 0eae62525696b57fe7fc4bbb0bf9c0bc7ee4e480 Mon Sep 17 00:00:00 2001 From: Josh Kalderimis Date: Wed, 16 Mar 2011 19:03:25 +0100 Subject: fixes an issue with number_to_human when converting values which are less than 1 but greater than -1 [#6576 state:resolved] Signed-off-by: Santiago Pastorino --- actionpack/lib/action_view/helpers/number_helper.rb | 2 +- actionpack/test/template/number_helper_test.rb | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/actionpack/lib/action_view/helpers/number_helper.rb b/actionpack/lib/action_view/helpers/number_helper.rb index 4e44843c4b..05a9c5b4f1 100644 --- a/actionpack/lib/action_view/helpers/number_helper.rb +++ b/actionpack/lib/action_view/helpers/number_helper.rb @@ -472,7 +472,7 @@ module ActionView end.keys.map{|e_name| inverted_du[e_name] }.sort_by{|e| -e} number_exponent = number != 0 ? Math.log10(number.abs).floor : 0 - display_exponent = unit_exponents.find{|e| number_exponent >= e } + display_exponent = unit_exponents.find{ |e| number_exponent >= e } || 0 number /= 10 ** display_exponent unit = case units diff --git a/actionpack/test/template/number_helper_test.rb b/actionpack/test/template/number_helper_test.rb index c1b4bab903..c8d50ebf75 100644 --- a/actionpack/test/template/number_helper_test.rb +++ b/actionpack/test/template/number_helper_test.rb @@ -195,7 +195,9 @@ class NumberHelperTest < ActionView::TestCase def test_number_to_human assert_equal '-123', number_to_human(-123) - assert_equal '0', number_to_human(0) + assert_equal '-0.5', number_to_human(-0.5) + assert_equal '0', number_to_human(0) + assert_equal '0.5', number_to_human(0.5) assert_equal '123', number_to_human(123) assert_equal '1.23 Thousand', number_to_human(1234) assert_equal '12.3 Thousand', number_to_human(12345) -- cgit v1.2.3