Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'master' of git://github.com/rails/rails

  • Loading branch information...
commit e404490f9bae102f8c7126917d59568e6d1fef79 2 parents 80a044e + 8d576b5
@mikel mikel authored
Showing with 167 additions and 80 deletions.
  1. +10 −0 actionpack/CHANGELOG
  2. +26 −3 actionpack/lib/action_dispatch/routing/mapper.rb
  3. +39 −0 actionpack/test/dispatch/routing_test.rb
  4. +6 −3 activemodel/lib/active_model/serializers/json.rb
  5. +21 −15 activemodel/test/cases/serializeration/json_serialization_test.rb
  6. +2 −1  activerecord/lib/active_record/associations.rb
  7. +5 −2 activerecord/lib/active_record/relation.rb
  8. +4 −13 activerecord/test/cases/adapter_test.rb
  9. +4 −0 activerecord/test/cases/associations/belongs_to_associations_test.rb
  10. +1 −1  activerecord/test/cases/associations/has_many_associations_test.rb
  11. +4 −3 activerecord/test/cases/base_test.rb
  12. +3 −1 activerecord/test/cases/date_time_test.rb
  13. +8 −11 activerecord/test/cases/json_serialization_test.rb
  14. +2 −2 activerecord/test/cases/log_subscriber_test.rb
  15. +16 −17 activerecord/test/cases/migration_test.rb
  16. +1 −1  activerecord/test/cases/relations_test.rb
  17. +1 −1  activerecord/test/connections/native_oracle/connection.rb
  18. +6 −0 activerecord/test/models/topic.rb
  19. +3 −3 activesupport/lib/active_support/core_ext/date_time/conversions.rb
  20. +2 −0  activesupport/lib/active_support/multibyte/chars.rb
  21. +1 −1  activesupport/test/abstract_unit.rb
  22. +2 −2 activesupport/test/core_ext/date_time_ext_test.rb
View
10 actionpack/CHANGELOG
@@ -1,5 +1,15 @@
*Rails 3.0.0 [beta 4/release candidate] (unreleased)*
+* Add shallow routes back to the new router [Diego Carrion]
+
+ resources :posts do
+ shallow do
+ resources :comments
+ end
+ end
+
+ You can now use comment_path for /comments/1 instead of post_comment_path for /posts/1/comments/1.
+
* Remove middleware laziness [José Valim]
* Make session stores rely on request.cookie_jar and change set_session semantics to return the cookie value instead of a boolean. [José Valim]
View
29 actionpack/lib/action_dispatch/routing/mapper.rb
@@ -350,6 +350,10 @@ def constraints(constraints = {})
scope(:constraints => constraints) { yield }
end
+ def shallow
+ scope(:shallow => true) { yield }
+ end
+
def defaults(defaults = {})
scope(:defaults => defaults) { yield }
end
@@ -374,12 +378,21 @@ def scope_options
@scope_options ||= private_methods.grep(/^merge_(.+)_scope$/) { $1.to_sym }
end
+ def merge_shallow_scope(parent, child)
+ parent or child
+ end
+
def merge_path_scope(parent, child)
- Mapper.normalize_path("#{parent}/#{child}")
+ parent_path = (@scope[:shallow] and child.eql?(':id')) ? parent.split('/').last : parent
+ Mapper.normalize_path "#{parent_path}/#{child}"
end
def merge_name_prefix_scope(parent, child)
- parent ? "#{parent}_#{child}" : child
+ if @scope[:shallow]
+ child
+ else
+ parent ? "#{parent}_#{child}" : child
+ end
end
def merge_module_scope(parent, child)
@@ -514,6 +527,10 @@ def nested_options
options["#{singular}_id".to_sym] = id_constraint if id_constraint?
options
end
+
+ def shallow?
+ options[:shallow]
+ end
end
class SingletonResource < Resource #:nodoc:
@@ -581,8 +598,12 @@ def resources(*resources, &block)
resource = Resource.new(resources.pop, options)
- scope(:path => resource.path, :controller => resource.controller) do
+ scope(:path => resource.path, :controller => resource.controller, :shallow => resource.shallow?) do
with_scope_level(:resources, resource) do
+ if @scope[:shallow] && @scope[:name_prefix]
+ @scope[:path] = "/#{@scope[:name_prefix].pluralize}/:#{@scope[:name_prefix]}_id/#{resource.path}"
+ end
+
yield if block_given?
with_scope_level(:collection) do
@@ -596,6 +617,8 @@ def resources(*resources, &block)
with_scope_level(:member) do
scope(':id') do
scope(resource.options) do
+ @scope[:name_prefix] = nil if @scope[:shallow]
+
get :show if resource.actions.include?(:show)
put :update if resource.actions.include?(:update)
delete :destroy if resource.actions.include?(:destroy)
View
39 actionpack/test/dispatch/routing_test.rb
@@ -34,6 +34,33 @@ def self.matches?(request)
end
end
+ resources :users do
+ shallow do
+ resources :photos do
+ resources :types do
+ member do
+ post :preview
+ end
+ collection do
+ delete :erase
+ end
+ end
+ end
+ end
+ end
+
+ shallow do
+ resources :teams do
+ resources :players
+ end
+
+ resources :countries do
+ resources :cities do
+ resources :places
+ end
+ end
+ end
+
match 'account/logout' => redirect("/logout"), :as => :logout_redirect
match 'account/login', :to => redirect("/login")
@@ -728,6 +755,18 @@ def test_update_person_route
end
end
+ def test_shallow_routes
+ with_test_routes do
+ assert_equal '/photos/4', photo_path(4)
+ assert_equal '/types/10/edit', edit_type_path(10)
+ assert_equal '/types/5/preview', preview_type_path(5)
+ assert_equal '/photos/2/types', photo_types_path(2)
+ assert_equal '/cities/1/places', url_for(:controller => :places, :action => :index, :city_id => 1, :only_path => true)
+ assert_equal '/teams/new', url_for(:controller => :teams, :action => :new, :only_path => true)
+ assert_equal '/photos/11/types/erase', url_for(:controller => :types, :action => :erase, :photo_id => 11, :only_path => true)
+ end
+ end
+
def test_update_project_person
with_test_routes do
get '/projects/1/people/2/update'
View
9 activemodel/lib/active_model/serializers/json.rb
@@ -1,5 +1,5 @@
require 'active_support/json'
-require 'active_support/core_ext/class/attribute_accessors'
+require 'active_support/core_ext/class/attribute'
module ActiveModel
module Serializers
@@ -10,7 +10,8 @@ module JSON
included do
extend ActiveModel::Naming
- cattr_accessor :include_root_in_json, :instance_writer => true
+ class_attribute :include_root_in_json
+ self.include_root_in_json = true
end
# Returns a JSON string representing the model. Some configuration is
@@ -92,7 +93,9 @@ def as_json(options = nil)
end
def from_json(json)
- self.attributes = ActiveSupport::JSON.decode(json)
+ hash = ActiveSupport::JSON.decode(json)
+ hash = hash.values.first if include_root_in_json
+ self.attributes = hash
self
end
end
View
36 activemodel/test/cases/serializeration/json_serialization_test.rb
@@ -22,35 +22,41 @@ def setup
end
test "should include root in json" do
+ json = @contact.to_json
+
+ assert_match %r{^\{"contact":\{}, json
+ assert_match %r{"name":"Konata Izumi"}, json
+ assert_match %r{"age":16}, json
+ assert json.include?(%("created_at":#{ActiveSupport::JSON.encode(Time.utc(2006, 8, 1))}))
+ assert_match %r{"awesome":true}, json
+ assert_match %r{"preferences":\{"shows":"anime"\}}, json
+ end
+
+ test "should not include root in json" do
begin
- Contact.include_root_in_json = true
+ Contact.include_root_in_json = false
json = @contact.to_json
- assert_match %r{^\{"contact":\{}, json
+ assert_no_match %r{^\{"contact":\{}, json
assert_match %r{"name":"Konata Izumi"}, json
assert_match %r{"age":16}, json
assert json.include?(%("created_at":#{ActiveSupport::JSON.encode(Time.utc(2006, 8, 1))}))
assert_match %r{"awesome":true}, json
assert_match %r{"preferences":\{"shows":"anime"\}}, json
ensure
- Contact.include_root_in_json = false
+ Contact.include_root_in_json = true
end
end
test "should include custom root in json" do
- begin
- Contact.include_root_in_json = true
- json = @contact.to_json(:root => 'json_contact')
+ json = @contact.to_json(:root => 'json_contact')
- assert_match %r{^\{"json_contact":\{}, json
- assert_match %r{"name":"Konata Izumi"}, json
- assert_match %r{"age":16}, json
- assert json.include?(%("created_at":#{ActiveSupport::JSON.encode(Time.utc(2006, 8, 1))}))
- assert_match %r{"awesome":true}, json
- assert_match %r{"preferences":\{"shows":"anime"\}}, json
- ensure
- Contact.include_root_in_json = false
- end
+ assert_match %r{^\{"json_contact":\{}, json
+ assert_match %r{"name":"Konata Izumi"}, json
+ assert_match %r{"age":16}, json
+ assert json.include?(%("created_at":#{ActiveSupport::JSON.encode(Time.utc(2006, 8, 1))}))
+ assert_match %r{"awesome":true}, json
+ assert_match %r{"preferences":\{"shows":"anime"\}}, json
end
test "should encode all encodable attributes" do
View
3  activerecord/lib/active_record/associations.rb
@@ -1756,7 +1756,8 @@ def join_base
end
def count_aliases_from_table_joins(name)
- quoted_name = join_base.active_record.connection.quote_table_name(name.downcase)
+ # quoted_name should be downcased as some database adapters (Oracle) return quoted name in uppercase
+ quoted_name = join_base.active_record.connection.quote_table_name(name.downcase).downcase
join_sql = join_base.table_joins.to_s.downcase
join_sql.blank? ? 0 :
# Table names
View
7 activerecord/lib/active_record/relation.rb
@@ -356,13 +356,16 @@ def with_create_scope
end
def references_eager_loaded_tables?
- joined_tables = (tables_in_string(arel.joins(arel)) + [table.name, table.table_alias]).compact.uniq
+ # always convert table names to downcase as in Oracle quoted table names are in uppercase
+ joined_tables = (tables_in_string(arel.joins(arel)) + [table.name, table.table_alias]).compact.map(&:downcase).uniq
(tables_in_string(to_sql) - joined_tables).any?
end
def tables_in_string(string)
return [] if string.blank?
- string.scan(/([a-zA-Z_][\.\w]+).?\./).flatten.uniq
+ # always convert table names to downcase as in Oracle quoted table names are in uppercase
+ # ignore raw_sql_ that is used by Oracle adapter as alias for limit/offset subqueries
+ string.scan(/([a-zA-Z_][\.\w]+).?\./).flatten.map(&:downcase).uniq - ['raw_sql_']
end
end
View
17 activerecord/test/cases/adapter_test.rb
@@ -145,22 +145,13 @@ def test_foreign_key_violations_are_translated_to_specific_exception
def test_add_limit_offset_should_sanitize_sql_injection_for_limit_without_comas
sql_inject = "1 select * from schema"
- assert_equal " LIMIT 1", @connection.add_limit_offset!("", :limit => sql_inject)
- if current_adapter?(:MysqlAdapter)
- assert_equal " LIMIT 7, 1", @connection.add_limit_offset!("", :limit => sql_inject, :offset => 7)
- else
- assert_equal " LIMIT 1 OFFSET 7", @connection.add_limit_offset!("", :limit => sql_inject, :offset => 7)
- end
+ assert_no_match /schema/, @connection.add_limit_offset!("", :limit=>sql_inject)
+ assert_no_match /schema/, @connection.add_limit_offset!("", :limit=>sql_inject, :offset=>7)
end
def test_add_limit_offset_should_sanitize_sql_injection_for_limit_with_comas
sql_inject = "1, 7 procedure help()"
- if current_adapter?(:MysqlAdapter)
- assert_equal " LIMIT 1,7", @connection.add_limit_offset!("", :limit => sql_inject)
- assert_equal " LIMIT 7, 1", @connection.add_limit_offset!("", :limit => '1 ; DROP TABLE USERS', :offset => 7)
- else
- assert_equal " LIMIT 1,7", @connection.add_limit_offset!("", :limit => sql_inject)
- assert_equal " LIMIT 1,7 OFFSET 7", @connection.add_limit_offset!("", :limit => sql_inject, :offset => 7)
- end
+ assert_no_match /procedure/, @connection.add_limit_offset!("", :limit=>sql_inject)
+ assert_no_match /procedure/, @connection.add_limit_offset!("", :limit=>sql_inject, :offset=>7)
end
end
View
4 activerecord/test/cases/associations/belongs_to_associations_test.rb
@@ -37,6 +37,10 @@ def test_belongs_to_with_primary_key_joins_on_correct_column
if current_adapter?(:MysqlAdapter)
assert_no_match(/`firm_with_primary_keys_companies`\.`id`/, sql)
assert_match(/`firm_with_primary_keys_companies`\.`name`/, sql)
+ elsif current_adapter?(:OracleAdapter)
+ # on Oracle aliases are truncated to 30 characters and are quoted in uppercase
+ assert_no_match(/"firm_with_primary_keys_compani"\."id"/i, sql)
+ assert_match(/"firm_with_primary_keys_compani"\."name"/i, sql)
else
assert_no_match(/"firm_with_primary_keys_companies"\."id"/, sql)
assert_match(/"firm_with_primary_keys_companies"\."name"/, sql)
View
2  activerecord/test/cases/associations/has_many_associations_test.rb
@@ -511,7 +511,7 @@ def test_deleting_before_save
end
def test_deleting_updates_counter_cache
- topic = Topic.first
+ topic = Topic.first(:order => "id ASC")
assert_equal topic.replies.to_a.size, topic.replies_count
topic.replies.delete(topic.replies.first)
View
7 activerecord/test/cases/base_test.rb
@@ -430,14 +430,14 @@ def test_non_attribute_access_and_assignment
end
def test_preserving_date_objects
- if current_adapter?(:SybaseAdapter, :OracleAdapter)
+ if current_adapter?(:SybaseAdapter)
# Sybase ctlib does not (yet?) support the date type; use datetime instead.
- # Oracle treats all dates/times as Time.
assert_kind_of(
Time, Topic.find(1).last_read,
"The last_read attribute should be of the Time class"
)
else
+ # Oracle enhanced adapter allows to define Date attributes in model class (see topic.rb)
assert_kind_of(
Date, Topic.find(1).last_read,
"The last_read attribute should be of the Date class"
@@ -2125,10 +2125,11 @@ def test_to_xml
assert_equal "integer", xml.elements["//parent-id"].attributes['type']
assert_equal "true", xml.elements["//parent-id"].attributes['nil']
- if current_adapter?(:SybaseAdapter, :OracleAdapter)
+ if current_adapter?(:SybaseAdapter)
assert_equal last_read_in_current_timezone, xml.elements["//last-read"].text
assert_equal "datetime" , xml.elements["//last-read"].attributes['type']
else
+ # Oracle enhanced adapter allows to define Date attributes in model class (see topic.rb)
assert_equal "2004-04-15", xml.elements["//last-read"].text
assert_equal "date" , xml.elements["//last-read"].attributes['type']
end
View
4 activerecord/test/cases/date_time_test.rb
@@ -5,7 +5,9 @@
class DateTimeTest < ActiveRecord::TestCase
def test_saves_both_date_and_time
time_values = [1807, 2, 10, 15, 30, 45]
- now = DateTime.civil(*time_values)
+ # create DateTime value with local time zone offset
+ local_offset = Rational(Time.local_time(*time_values).utc_offset, 86400)
+ now = DateTime.civil(*(time_values + [local_offset]))
task = Task.new
task.starting = now
View
19 activerecord/test/cases/json_serialization_test.rb
@@ -8,7 +8,7 @@
class JsonSerializationTest < ActiveRecord::TestCase
class NamespacedContact < Contact
- column :name, :string
+ column :name, :string
end
def setup
@@ -23,16 +23,12 @@ def setup
end
def test_should_demodulize_root_in_json
- NamespacedContact.include_root_in_json = true
@contact = NamespacedContact.new :name => 'whatever'
json = @contact.to_json
assert_match %r{^\{"namespaced_contact":\{}, json
- ensure
- NamespacedContact.include_root_in_json = false
end
def test_should_include_root_in_json
- Contact.include_root_in_json = true
json = @contact.to_json
assert_match %r{^\{"contact":\{}, json
@@ -41,8 +37,6 @@ def test_should_include_root_in_json
assert json.include?(%("created_at":#{ActiveSupport::JSON.encode(Time.utc(2006, 8, 1))}))
assert_match %r{"awesome":true}, json
assert_match %r{"preferences":\{"shows":"anime"\}}, json
- ensure
- Contact.include_root_in_json = false
end
def test_should_encode_all_encodable_attributes
@@ -170,15 +164,19 @@ def @david.favorite_quote; "Constraints are liberating"; end
end
def test_should_allow_only_option_for_list_of_authors
+ ActiveRecord::Base.include_root_in_json = false
authors = [@david, @mary]
-
assert_equal %([{"name":"David"},{"name":"Mary"}]), ActiveSupport::JSON.encode(authors, :only => :name)
+ ensure
+ ActiveRecord::Base.include_root_in_json = true
end
def test_should_allow_except_option_for_list_of_authors
+ ActiveRecord::Base.include_root_in_json = false
authors = [@david, @mary]
-
assert_equal %([{"id":1},{"id":2}]), ActiveSupport::JSON.encode(authors, :except => [:name, :author_address_id, :author_address_extra_id])
+ ensure
+ ActiveRecord::Base.include_root_in_json = true
end
def test_should_allow_includes_for_list_of_authors
@@ -201,7 +199,6 @@ def test_should_allow_options_for_hash_of_authors
1 => @david,
2 => @mary
}
-
- assert_equal %({"1":{"name":"David"}}), ActiveSupport::JSON.encode(authors_hash, :only => [1, :name])
+ assert_equal %({"1":{"author":{"name":"David"}}}), ActiveSupport::JSON.encode(authors_hash, :only => [1, :name])
end
end
View
4 activerecord/test/cases/log_subscriber_test.rb
@@ -27,7 +27,7 @@ def test_basic_query_logging
wait
assert_equal 1, @logger.logged(:debug).size
assert_match(/Developer Load/, @logger.logged(:debug).last)
- assert_match(/SELECT .*?FROM .?developers.?/, @logger.logged(:debug).last)
+ assert_match(/SELECT .*?FROM .?developers.?/i, @logger.logged(:debug).last)
end
def test_cached_queries
@@ -38,6 +38,6 @@ def test_cached_queries
wait
assert_equal 2, @logger.logged(:debug).size
assert_match(/CACHE/, @logger.logged(:debug).last)
- assert_match(/SELECT .*?FROM .?developers.?/, @logger.logged(:debug).last)
+ assert_match(/SELECT .*?FROM .?developers.?/i, @logger.logged(:debug).last)
end
end
View
33 activerecord/test/cases/migration_test.rb
@@ -30,13 +30,14 @@ def test_add_schema_info_respects_prefix_and_suffix
conn = ActiveRecord::Base.connection
conn.drop_table(ActiveRecord::Migrator.schema_migrations_table_name) if conn.table_exists?(ActiveRecord::Migrator.schema_migrations_table_name)
- ActiveRecord::Base.table_name_prefix = 'foo_'
- ActiveRecord::Base.table_name_suffix = '_bar'
+ # Use shorter prefix and suffix as in Oracle database identifier cannot be larger than 30 characters
+ ActiveRecord::Base.table_name_prefix = 'p_'
+ ActiveRecord::Base.table_name_suffix = '_s'
conn.drop_table(ActiveRecord::Migrator.schema_migrations_table_name) if conn.table_exists?(ActiveRecord::Migrator.schema_migrations_table_name)
conn.initialize_schema_migrations_table
- assert_equal "foo_unique_schema_migrations_bar", conn.indexes(ActiveRecord::Migrator.schema_migrations_table_name)[0][:name]
+ assert_equal "p_unique_schema_migrations_s", conn.indexes(ActiveRecord::Migrator.schema_migrations_table_name)[0][:name]
ensure
ActiveRecord::Base.table_name_prefix = ""
ActiveRecord::Base.table_name_suffix = ""
@@ -83,13 +84,17 @@ def test_add_index
# Orcl nds shrt indx nms. Sybs 2.
# OpenBase does not have named indexes. You must specify a single column name
- unless current_adapter?(:OracleAdapter, :SybaseAdapter, :OpenBaseAdapter)
+ unless current_adapter?(:SybaseAdapter, :OpenBaseAdapter)
assert_nothing_raised { Person.connection.add_index("people", ["last_name", "first_name"]) }
assert_nothing_raised { Person.connection.remove_index("people", :column => ["last_name", "first_name"]) }
- assert_nothing_raised { Person.connection.add_index("people", ["last_name", "first_name"]) }
- assert_nothing_raised { Person.connection.remove_index("people", :name => "index_people_on_last_name_and_first_name") }
- assert_nothing_raised { Person.connection.add_index("people", ["last_name", "first_name"]) }
- assert_nothing_raised { Person.connection.remove_index("people", "last_name_and_first_name") }
+ # Oracle adapter cannot have specified index name larger than 30 characters
+ # Oracle adapter is shortening index name when just column list is given
+ unless current_adapter?(:OracleAdapter)
+ assert_nothing_raised { Person.connection.add_index("people", ["last_name", "first_name"]) }
+ assert_nothing_raised { Person.connection.remove_index("people", :name => "index_people_on_last_name_and_first_name") }
+ assert_nothing_raised { Person.connection.add_index("people", ["last_name", "first_name"]) }
+ assert_nothing_raised { Person.connection.remove_index("people", "last_name_and_first_name") }
+ end
assert_nothing_raised { Person.connection.add_index("people", ["last_name", "first_name"]) }
assert_nothing_raised { Person.connection.remove_index("people", ["last_name", "first_name"]) }
assert_nothing_raised { Person.connection.add_index("people", ["last_name"], :length => 10) }
@@ -736,13 +741,7 @@ def test_remove_column_with_multi_column_index
table.column :hat_size, :integer
table.column :hat_style, :string, :limit => 100
end
- # Oracle index names should be 30 or less characters
- if current_adapter?(:OracleAdapter)
- ActiveRecord::Base.connection.add_index "hats", ["hat_style", "hat_size"], :unique => true,
- :name => 'index_hats_on_hat_style_size'
- else
- ActiveRecord::Base.connection.add_index "hats", ["hat_style", "hat_size"], :unique => true
- end
+ ActiveRecord::Base.connection.add_index "hats", ["hat_style", "hat_size"], :unique => true
assert_nothing_raised { Person.connection.remove_column("hats", "hat_size") }
ensure
@@ -1375,8 +1374,8 @@ def test_create_table_with_custom_sequence_name
return unless current_adapter? :OracleAdapter
# table name is 29 chars, the standard sequence name will
- # be 33 chars and fail
- assert_raise(ActiveRecord::StatementInvalid) do
+ # be 33 chars and should be shortened
+ assert_nothing_raised do
begin
Person.connection.create_table :table_with_name_thats_just_ok do |t|
t.column :foo, :string, :null => false
View
2  activerecord/test/cases/relations_test.rb
@@ -114,7 +114,7 @@ def test_finding_with_group
def test_select_with_block
even_ids = Developer.scoped.select {|d| d.id % 2 == 0 }.map(&:id)
- assert_equal [2, 4, 6, 8, 10], even_ids
+ assert_equal [2, 4, 6, 8, 10], even_ids.sort
end
def test_finding_with_hash_conditions_on_joined_table
View
2  activerecord/test/connections/native_oracle/connection.rb
@@ -53,7 +53,7 @@
# for assert_queries test helper
ActiveRecord::Base.connection.class.class_eval do
- IGNORED_SELECT_SQL = [/^select .*nextval/i, /^SAVEPOINT/, /^ROLLBACK TO SAVEPOINT/, /^RELEASE SAVEPOINT/, /^\s*select .* from all_tab_columns/im]
+ IGNORED_SELECT_SQL = [/^select .*nextval/i, /^SAVEPOINT/, /^ROLLBACK TO/, /^\s*select .* from ((all|user)_tab_columns|(all|user)_triggers|(all|user)_constraints)/im]
def select_with_query_record(sql, name = nil, return_column_names = false)
$queries_executed ||= []
View
6 activerecord/test/models/topic.rb
@@ -43,6 +43,12 @@ def extension_two
before_create :default_written_on
before_destroy :destroy_children
+ # Explicitly define as :date column so that returned Oracle DATE values would be typecasted to Date and not Time.
+ # Some tests depend on assumption that this attribute will have Date values.
+ if current_adapter?(:OracleEnhancedAdapter)
+ set_date_columns :last_read
+ end
+
def parent
Topic.find(parent_id)
end
View
6 activesupport/lib/active_support/core_ext/date_time/conversions.rb
@@ -60,7 +60,7 @@ def readable_inspect
# Converts self to a Ruby Date object; time portion is discarded
def to_date
::Date.new(year, month, day)
- end unless method_defined?(:to_date)
+ end unless instance_methods(false).include?(:to_date)
# Attempts to convert self to a Ruby Time object; returns self if out of range of Ruby Time class
# If self has an offset other than 0, self will just be returned unaltered, since there's no clean way to map it to a Time
@@ -71,7 +71,7 @@ def to_time
# To be able to keep Times, Dates and DateTimes interchangeable on conversions
def to_datetime
self
- end unless method_defined?(:to_datetime)
+ end unless instance_methods(false).include?(:to_datetime)
def self.civil_from_format(utc_or_local, year, month=1, day=1, hour=0, min=0, sec=0)
offset = utc_or_local.to_sym == :local ? local_offset : 0
@@ -81,7 +81,7 @@ def self.civil_from_format(utc_or_local, year, month=1, day=1, hour=0, min=0, se
# Converts datetime to an appropriate format for use in XML
def xmlschema
strftime("%Y-%m-%dT%H:%M:%S%Z")
- end unless method_defined?(:xmlschema)
+ end unless instance_methods(false).include?(:xmlschema)
# Converts self to a floating-point number of seconds since the Unix epoch
def to_f
View
2  activesupport/lib/active_support/multibyte/chars.rb
@@ -45,6 +45,8 @@ def initialize(string)
@wrapped_string = string
@wrapped_string.force_encoding(Encoding::UTF_8) unless @wrapped_string.frozen?
end
+
+ undef <=>
else
def initialize(string) #:nodoc:
@wrapped_string = string
View
2  activesupport/test/abstract_unit.rb
@@ -18,7 +18,7 @@
require 'active_support'
# Include shims until we get off 1.8.6
-require 'active_support/ruby/shim'
+require 'active_support/ruby/shim' if RUBY_VERSION < '1.8.7'
def uses_memcached(test_name)
require 'memcache'
View
4 activesupport/test/core_ext/date_time_ext_test.rb
@@ -26,11 +26,11 @@ def test_custom_date_format
end
def test_to_date
- assert_equal Date.new(2005, 2, 21), DateTime.new(2005, 2, 21).to_date
+ assert_equal Date.new(2005, 2, 21), DateTime.new(2005, 2, 21, 14, 30, 0).to_date
end
def test_to_datetime
- assert_equal DateTime.new(2005, 2, 21), DateTime.new(2005, 2, 21).to_datetime
+ assert_equal DateTime.new(2005, 2, 21, 14, 30, 0), DateTime.new(2005, 2, 21, 14, 30, 0).to_datetime
end
def test_to_time
Please sign in to comment.
Something went wrong with that request. Please try again.