diff options
Diffstat (limited to 'activerecord/lib')
4 files changed, 33 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index 25074c2d4f..99ed273a8a 100644 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -1738,7 +1738,7 @@ MSG end # Returns an <tt>#inspect</tt>-like string for the value of the - # attribute +attr_name+. String attributes are elided after 50 + # attribute +attr_name+. String attributes are truncated upto 50 # characters, and Date and Time attributes are returned in the # <tt>:db</tt> format. Other attributes return the value of # <tt>#inspect</tt> without modification. diff --git a/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb b/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb index bcd3abc08d..123b3654e6 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb @@ -46,6 +46,12 @@ module ActiveRecord # "database" => "path/to/dbfile" # ) # + # Or a URL: + # + # ActiveRecord::Base.establish_connection( + # "postgres://myuser:mypass@localhost/somedatabase" + # ) + # # The exceptions AdapterNotSpecified, AdapterNotFound and ArgumentError # may be returned on an error. def self.establish_connection(spec = nil) @@ -58,6 +64,8 @@ module ActiveRecord when Symbol, String if configuration = configurations[spec.to_s] establish_connection(configuration) + elsif spec.is_a?(String) && hash = connection_url_to_hash(spec) + establish_connection(hash) else raise AdapterNotSpecified, "#{spec} database is not configured" end @@ -81,6 +89,24 @@ module ActiveRecord end end + def self.connection_url_to_hash(url) # :nodoc: + config = URI.parse url + adapter = config.scheme + adapter = "postgresql" if adapter == "postgres" + spec = { :adapter => adapter, + :username => config.user, + :password => config.password, + :port => config.port, + :database => config.path.sub(%r{^/},""), + :host => config.host } + spec.reject!{ |_,value| !value } + if config.query + options = Hash[config.query.split("&").map{ |pair| pair.split("=") }].symbolize_keys + spec.merge!(options) + end + spec + end + class << self # Returns the connection currently associated with the class. This can # also be used to "borrow" the connection to do database work unrelated diff --git a/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb b/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb index 724b2e6d9c..e2a0f63393 100644 --- a/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb @@ -157,6 +157,11 @@ module ActiveRecord end end + def type_cast(value, column) # :nodoc: + return super unless BigDecimal === value + + value.to_f + end # DATABASE STATEMENTS ====================================== diff --git a/activerecord/lib/active_record/nested_attributes.rb b/activerecord/lib/active_record/nested_attributes.rb index 53617059d0..2dbebfcaf8 100644 --- a/activerecord/lib/active_record/nested_attributes.rb +++ b/activerecord/lib/active_record/nested_attributes.rb @@ -383,7 +383,7 @@ module ActiveRecord attributes_collection = if keys.include?('id') || keys.include?(:id) Array.wrap(attributes_collection) else - attributes_collection.sort_by { |i, _| i.to_i }.map { |_, attributes| attributes } + attributes_collection.values end end |