From d60d7edce462f4602bfc9996689087a235b034c9 Mon Sep 17 00:00:00 2001 From: Sam Goldstein Date: Wed, 8 Jul 2009 11:45:26 -0700 Subject: Make it so AR attributes which conflict with object-private methods (e.g. system) don't 'randomly' cause NoMethodErrors Previously if you called this attribute before others, you'd get exceptions. But if it was the second-or-subsequent attribute you retrieved you'd get the correct behaviour. Signed-off-by: Michael Koziarski [#2808 state:committed] --- activerecord/lib/active_record/attribute_methods.rb | 13 +++++++++---- activerecord/test/cases/attribute_methods_test.rb | 16 ++++++++++++++++ 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/activerecord/lib/active_record/attribute_methods.rb b/activerecord/lib/active_record/attribute_methods.rb index 15358979c2..ecd2d57a5a 100644 --- a/activerecord/lib/active_record/attribute_methods.rb +++ b/activerecord/lib/active_record/attribute_methods.rb @@ -133,6 +133,7 @@ module ActiveRecord end private + # Suffixes a, ?, c become regexp /(a|\?|c)$/ def rebuild_attribute_method_regexp suffixes = attribute_method_suffixes.map { |s| Regexp.escape(s) } @@ -238,19 +239,17 @@ module ActiveRecord def method_missing(method_id, *args, &block) method_name = method_id.to_s - if self.class.private_method_defined?(method_name) - raise NoMethodError.new("Attempt to call private method", method_name, args) - end - # If we haven't generated any methods yet, generate them, then # see if we've created the method we're looking for. if !self.class.generated_methods? self.class.define_attribute_methods + guard_private_attribute_method!(method_name, args) if self.class.generated_methods.include?(method_name) return self.send(method_id, *args, &block) end end + guard_private_attribute_method!(method_name, args) if self.class.primary_key.to_s == method_name id elsif md = self.class.match_attribute_method?(method_name) @@ -371,6 +370,12 @@ module ActiveRecord end private + # prevent method_missing from calling private methods with #send + def guard_private_attribute_method!(method_name, args) + if self.class.private_method_defined?(method_name) + raise NoMethodError.new("Attempt to call private method", method_name, args) + end + end def missing_attribute(attr_name, stack) raise ActiveRecord::MissingAttributeError, "missing attribute: #{attr_name}", stack diff --git a/activerecord/test/cases/attribute_methods_test.rb b/activerecord/test/cases/attribute_methods_test.rb index 17ed302465..183be1e2f9 100644 --- a/activerecord/test/cases/attribute_methods_test.rb +++ b/activerecord/test/cases/attribute_methods_test.rb @@ -277,6 +277,22 @@ class AttributeMethodsTest < ActiveRecord::TestCase assert_raise(ActiveRecord::UnknownAttributeError) { @target.new.attributes = { :title => "Ants in pants" } } end + def test_read_attribute_overwrites_private_method_not_considered_implemented + # simulate a model with a db column that shares its name an inherited + # private method (e.g. Object#system) + # + Object.class_eval do + private + def title; "private!"; end + end + assert !@target.instance_method_already_implemented?(:title) + topic = @target.new + assert_equal nil, topic.title + + Object.send(:undef_method, :title) # remove test method from object + end + + private def time_related_columns_on_topic Topic.columns.select{|c| [:time, :date, :datetime, :timestamp].include?(c.type)}.map(&:name) -- cgit v1.2.3 From 01d92021e69f54def1ec8103b2b99f907dd88ec4 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Fri, 10 Jul 2009 11:34:39 -0500 Subject: Switch scaffolding templates to HTML 5 doctype --- railties/html/404.html | 33 ++++++------ railties/html/422.html | 33 ++++++------ railties/html/500.html | 31 +++++------ railties/html/index.html | 61 +++++++++++----------- .../components/scaffold/templates/layout.html.erb | 8 ++- .../scaffold/templates/view_index.html.erb | 3 ++ 6 files changed, 80 insertions(+), 89 deletions(-) diff --git a/railties/html/404.html b/railties/html/404.html index eff660b90c..88ee108e90 100644 --- a/railties/html/404.html +++ b/railties/html/404.html @@ -1,23 +1,20 @@ - - - - + + The page you were looking for doesn't exist (404) - + @@ -27,4 +24,4 @@

You may have mistyped the address or the page may have moved.

- \ No newline at end of file + diff --git a/railties/html/422.html b/railties/html/422.html index b54e4a3cad..9c3c96670b 100644 --- a/railties/html/422.html +++ b/railties/html/422.html @@ -1,23 +1,20 @@ - - - - + + The change you wanted was rejected (422) - + @@ -27,4 +24,4 @@

Maybe you tried to change something you didn't have access to.

- \ No newline at end of file + diff --git a/railties/html/500.html b/railties/html/500.html index ec3bbf02c4..f71c86e652 100644 --- a/railties/html/500.html +++ b/railties/html/500.html @@ -1,23 +1,20 @@ - - - - + + We're sorry, but something went wrong (500) - + diff --git a/railties/html/index.html b/railties/html/index.html index cd337dc74c..ff2dfd3193 100644 --- a/railties/html/index.html +++ b/railties/html/index.html @@ -1,5 +1,4 @@ - + @@ -14,20 +13,20 @@ font-size: 13px; color: #333; } - + h1 { font-size: 28px; color: #000; } - + a {color: #03c} a:hover { background-color: #03c; color: white; text-decoration: none; } - - + + #page { background-color: #f0f0f0; width: 750px; @@ -35,7 +34,7 @@ margin-left: auto; margin-right: auto; } - + #content { float: left; background-color: white; @@ -44,7 +43,7 @@ padding: 25px; width: 500px; } - + #sidebar { float: right; width: 175px; @@ -53,7 +52,7 @@ #footer { clear: both; } - + #header, #about, #getting-started { padding-left: 75px; @@ -73,14 +72,14 @@ font-weight: normal; font-size: 16px; } - - + + #about h3 { margin: 0; margin-bottom: 10px; font-size: 14px; } - + #about-content { background-color: #ffd; border: 1px solid #fc0; @@ -113,8 +112,8 @@ margin: 0; padding: 10px; } - - + + #getting-started { border-top: 1px solid #ccc; margin-top: 25px; @@ -150,8 +149,8 @@ color: #555; font-size: 13px; } - - + + #search { margin: 0; padding-top: 10px; @@ -163,8 +162,8 @@ margin: 2px; } #search-text {width: 170px} - - + + #sidebar ul { margin-left: 0; padding-left: 0; @@ -181,7 +180,7 @@ #sidebar ul.links li { margin-bottom: 5px; } - + @@ -194,11 +193,11 @@ onComplete: function() {new Effect.BlindDown('about-content', {duration: 0.25})} }); } else { - new Effect[Element.visible('about-content') ? + new Effect[Element.visible('about-content') ? 'BlindUp' : 'BlindDown']('about-content', {duration: 0.25}); } } - + window.onload = function() { $('search-text').value = ''; $('search').onsubmit = function() { @@ -218,7 +217,7 @@ the Rails site - +
  • Join the community

  • - +
  • Browse the documentation