Skip to content

Commit

Permalink
Merge branch 'master' into rm-uuid-fixtures
Browse files Browse the repository at this point in the history
Conflicts:
	activerecord/CHANGELOG.md
	activesupport/CHANGELOG.md
  • Loading branch information
rafaelfranca committed Apr 10, 2014
2 parents 54d8c81 + 53610e5 commit 085ce4f
Show file tree
Hide file tree
Showing 79 changed files with 783 additions and 287 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
services: memcache
script: 'ci/travis.rb'
before_install:
- travis_retry gem install bundler
Expand Down
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ gem 'rack-cache', '~> 1.2'
gem 'jquery-rails', '~> 3.1.0'
gem 'turbolinks'
gem 'coffee-rails', '~> 4.0.0'
gem 'sprockets-rails', github: 'rails/sprockets-rails', branch: '2-1-stable'

# require: false so bcrypt is loaded only when has_secure_password is used.
# This is to avoid ActiveModel (and by extension the entire framework)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ We encourage you to contribute to Ruby on Rails! Please check out the

## Code Status

* [![Build Status](https://travis-ci.org/rails/rails.png?branch=master)](https://travis-ci.org/rails/rails)
* [![Build Status](https://travis-ci.org/rails/rails.svg?branch=master)](https://travis-ci.org/rails/rails)

## License

Expand Down
13 changes: 8 additions & 5 deletions actionpack/lib/action_dispatch/middleware/ssl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,14 @@ def call(env)

private
def redirect_to_https(request)
url = URI(request.url)
url.scheme = "https"
url.host = @host if @host
url.port = @port if @port
headers = { 'Content-Type' => 'text/html', 'Location' => url.to_s }
host = @host || request.host
port = @port || request.port

location = "https://#{host}"
location << ":#{port}" if port != 80
location << request.fullpath

headers = { 'Content-Type' => 'text/html', 'Location' => location }

[301, headers, []]
end
Expand Down
23 changes: 16 additions & 7 deletions actionpack/test/controller/flash_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -210,20 +210,29 @@ def test_redirect_to_with_other_flashes
end

def test_redirect_to_with_adding_flash_types
@controller.class.add_flash_types :foo
original_controller = @controller
test_controller_with_flash_type_foo = Class.new(TestController) do
add_flash_types :foo
end
@controller = test_controller_with_flash_type_foo.new
get :redirect_with_foo_flash
assert_equal "for great justice", @controller.send(:flash)[:foo]
ensure
@controller = original_controller
end

class SubclassesTestController < TestController; end

def test_add_flash_type_to_subclasses
TestController.add_flash_types :foo
assert SubclassesTestController._flash_types.include?(:foo)
test_controller_with_flash_type_foo = Class.new(TestController) do
add_flash_types :foo
end
subclass_controller_with_no_flash_type = Class.new(test_controller_with_flash_type_foo)
assert subclass_controller_with_no_flash_type._flash_types.include?(:foo)
end

def test_do_not_add_flash_type_to_parent_class
SubclassesTestController.add_flash_types :bar
def test_does_not_add_flash_type_to_parent_class
Class.new(TestController) do
add_flash_types :bar
end
assert_not TestController._flash_types.include?(:bar)
end
end
Expand Down
7 changes: 7 additions & 0 deletions actionpack/test/dispatch/ssl_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,13 @@ def test_redirect_to_host_and_port
response.headers['Location']
end

def test_redirect_to_host_with_port
self.app = ActionDispatch::SSL.new(default_app, :host => "ssl.example.org:443")
get "http://example.org/path?key=value"
assert_equal "https://ssl.example.org:443/path?key=value",
response.headers['Location']
end

def test_redirect_to_secure_host_when_on_subdomain
self.app = ActionDispatch::SSL.new(default_app, :host => "ssl.example.org")
get "http://ssl.example.org/path?key=value"
Expand Down
2 changes: 1 addition & 1 deletion activemodel/lib/active_model/validations/with.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ module ClassMethods
#
# Configuration options:
# * <tt>:on</tt> - Specifies when this validation is active
# (<tt>:create</tt> or <tt>:update</tt>.
# (<tt>:create</tt> or <tt>:update</tt>).
# * <tt>:if</tt> - Specifies a method, proc or string to call to determine
# if the validation should occur (e.g. <tt>if: :allow_validation</tt>,
# or <tt>if: Proc.new { |user| user.signup_step > 2 }</tt>).
Expand Down
28 changes: 28 additions & 0 deletions activerecord/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,34 @@

*Roderick van Domburg*

* Fixed a problem where an enum would overwrite values of another enum
with the same name in an unrelated class.

Fixes #14607.

*Evan Whalen*

* PostgreSQL and SQLite string columns no longer have a default limit of 255.

Fixes #13435, #9153.

*Vladimir Sazhin*, *Toms Mikoss*, *Yves Senn*

* Make possible to have an association called `records`.

Fixes #11645.

*prathamesh-sonpatki*

* `to_sql` on an association now matches the query that is actually executed, where it
could previously have incorrectly accrued additional conditions (e.g. as a result of
a previous query). CollectionProxy now always defers to the association scope's
`arel` method so the (incorrect) inherited one should be entirely concealed.

Fixes #14003.

*Jefferson Lai*

* Block a few default Class methods as scope name.

For instance, this will raise:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,11 @@ def build(attributes = {}, &block)
end

def create(attributes = {}, &block)
create_record(attributes, &block)
_create_record(attributes, &block)
end

def create!(attributes = {}, &block)
create_record(attributes, true, &block)
_create_record(attributes, true, &block)
end

# Add +records+ to this association. Returns +self+ so method calls may
Expand Down Expand Up @@ -182,11 +182,11 @@ def transaction(*args)
#
# See delete for more info.
def delete_all(dependent = nil)
if dependent.present? && ![:nullify, :delete_all].include?(dependent)
if dependent && ![:nullify, :delete_all].include?(dependent)
raise ArgumentError, "Valid values are :nullify or :delete_all"
end

dependent = if dependent.present?
dependent = if dependent
dependent
elsif options[:dependent] == :destroy
:delete_all
Expand Down Expand Up @@ -449,13 +449,13 @@ def merge_target_lists(persisted, memory)
persisted + memory
end

def create_record(attributes, raise = false, &block)
def _create_record(attributes, raise = false, &block)
unless owner.persisted?
raise ActiveRecord::RecordNotSaved, "You cannot call create unless the parent is saved"
end

if attributes.is_a?(Array)
attributes.collect { |attr| create_record(attr, raise, &block) }
attributes.collect { |attr| _create_record(attr, raise, &block) }
else
transaction do
add_to_target(build_record(attributes)) do |record|
Expand Down
11 changes: 5 additions & 6 deletions activerecord/lib/active_record/associations/collection_proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ def replace(other_array)

# Deletes all the records from the collection. For +has_many+ associations,
# the deletion is done according to the strategy specified by the <tt>:dependent</tt>
# option. Returns an array with the deleted records.
# option.
#
# If no <tt>:dependent</tt> option is given, then it will follow the
# default strategy. The default strategy is <tt>:nullify</tt>. This
Expand Down Expand Up @@ -435,11 +435,6 @@ def replace(other_array)
# # ]
#
# person.pets.delete_all
# # => [
# # #<Pet id: 1, name: "Fancy-Fancy", person_id: 1>,
# # #<Pet id: 2, name: "Spook", person_id: 1>,
# # #<Pet id: 3, name: "Choo-Choo", person_id: 1>
# # ]
#
# Pet.find(1, 2, 3)
# # => ActiveRecord::RecordNotFound
Expand Down Expand Up @@ -860,6 +855,10 @@ def include?(record)
!!@association.include?(record)
end

def arel
scope.arel
end

def proxy_association
@association
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ def writer(record)
end

def create(attributes = {}, &block)
create_record(attributes, &block)
_create_record(attributes, &block)
end

def create!(attributes = {}, &block)
create_record(attributes, true, &block)
_create_record(attributes, true, &block)
end

def build(attributes = {})
Expand Down Expand Up @@ -52,7 +52,7 @@ def set_new_record(record)
replace(record)
end

def create_record(attributes, raise_error = false)
def _create_record(attributes, raise_error = false)
record = build_record(attributes)
yield(record) if block_given?
saved = record.save
Expand Down
4 changes: 2 additions & 2 deletions activerecord/lib/active_record/attribute_methods/dirty.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,11 @@ def save_changed_attribute(attr, value)
end
end

def update_record(*)
def _update_record(*)
partial_writes? ? super(keys_for_partial_write) : super
end

def create_record(*)
def _create_record(*)
partial_writes? ? super(keys_for_partial_write) : super
end

Expand Down
4 changes: 2 additions & 2 deletions activerecord/lib/active_record/callbacks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -302,11 +302,11 @@ def create_or_update #:nodoc:
run_callbacks(:save) { super }
end

def create_record #:nodoc:
def _create_record #:nodoc:
run_callbacks(:create) { super }
end

def update_record(*) #:nodoc:
def _update_record(*) #:nodoc:
run_callbacks(:update) { super }
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class ConnectionUrlResolver # :nodoc:
def initialize(url)
raise "Database URL cannot be empty" if url.blank?
@uri = URI.parse(url)
@adapter = @uri.scheme
@adapter = @uri.scheme.gsub('-', '_')
@adapter = "postgresql" if @adapter == "postgres"

if @uri.opaque
Expand Down Expand Up @@ -220,10 +220,10 @@ def resolve_string_connection(spec)
# an environment key or a URL spec, so we have deprecated
# this ambiguous behaviour and in the future this function
# can be removed in favor of resolve_url_connection.
if configurations.key?(spec)
if configurations.key?(spec) || spec !~ /:/
ActiveSupport::Deprecation.warn "Passing a string to ActiveRecord::Base.establish_connection " \
"for a configuration lookup is deprecated, please pass a symbol (#{spec.to_sym.inspect}) instead"
resolve_connection(configurations[spec])
resolve_symbol_connection(spec)
else
resolve_url_connection(spec)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ class PostgreSQLAdapter < AbstractAdapter
module Quoting
# Escapes binary strings for bytea input to the database.
def escape_bytea(value)
PGconn.escape_bytea(value) if value
@connection.escape_bytea(value) if value
end

# Unescapes bytea output from a database to the binary string it represents.
# NOTE: This is NOT an inverse of escape_bytea! This is only to be used
# on escaped binary output from database drive.
def unescape_bytea(value)
PGconn.unescape_bytea(value) if value
@connection.unescape_bytea(value) if value
end

# Quotes PostgreSQL-specific data types for SQL input.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ class Table < ActiveRecord::ConnectionAdapters::Table

NATIVE_DATABASE_TYPES = {
primary_key: "serial primary key",
string: { name: "character varying", limit: 255 },
string: { name: "character varying" },
text: { name: "text" },
integer: { name: "integer" },
float: { name: "float" },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class SQLite3Adapter < AbstractAdapter

NATIVE_DATABASE_TYPES = {
primary_key: 'INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL',
string: { name: "varchar", limit: 255 },
string: { name: "varchar" },
text: { name: "text" },
integer: { name: "integer" },
float: { name: "float" },
Expand Down
35 changes: 6 additions & 29 deletions activerecord/lib/active_record/connection_handling.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ def establish_connection(spec = nil)
end

class MergeAndResolveDefaultUrlConfig # :nodoc:
def initialize(raw_configurations, url = ENV['DATABASE_URL'])
def initialize(raw_configurations)
@raw_config = raw_configurations.dup
@url = url
@env = DEFAULT_ENV.call.to_s
end

# Returns fully resolved connection hashes.
Expand All @@ -71,33 +71,10 @@ def resolve

private
def config
if @url
raw_merged_into_default
else
@raw_config
end
end

def raw_merged_into_default
default = default_url_hash

@raw_config.each do |env, values|
default[env] = values || {}
default[env].merge!("url" => @url) { |h, v1, v2| v1 || v2 } if default[env].is_a?(Hash)
end
default
end

# When the raw configuration is not present and ENV['DATABASE_URL']
# is available we return a hash with the connection information in
# the connection URL. This hash responds to any string key with
# resolved connection information.
def default_url_hash
Hash.new do |hash, key|
hash[key] = if key.is_a? String
ActiveRecord::ConnectionAdapters::ConnectionSpecification::ConnectionUrlResolver.new(@url).to_hash
else
nil
@raw_config.dup.tap do |cfg|
if url = ENV['DATABASE_URL']
cfg[@env] ||= {}
cfg[@env]["url"] ||= url
end
end
end
Expand Down
Loading

0 comments on commit 085ce4f

Please sign in to comment.