Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: rails/rails
...
head fork: rails/rails
  • 13 commits
  • 26 files changed
  • 4 commit comments
  • 7 contributors
Commits on Oct 29, 2012
@graceliu graceliu fixed support for DATABASE_URL for rake db tasks
Backport for #7521

- added tests to confirm establish_connection uses DATABASE_URL and
  Rails.env correctly even when no arguments are passed in.
- updated rake db tasks to support DATABASE_URL, and added tests to
  confirm correct behavior for these rake tasks.  (Removed
  establish_connection call from some tasks since in those cases
  the :environment task already made sure the function would be called)
- updated Resolver so that when it resolves the database url, it
  removes hash values with empty strings from the config spec (e.g.
  to support connection to postgresql when no username is specified).
- updated ResolverTest to use current_adapter? to check the type of
  the current adapter.
e7a6b92
@rafaelfranca rafaelfranca Merge pull request #8009 from graceliu/3-2-fix_database_url_support
fixed support for DATABASE_URL for rake db tasks
e6b4184
Commits on Oct 30, 2012
@rafaelfranca rafaelfranca Fix bug when Column is trying to type cast boolean values to integer.
This can occur if the user is using :integer columns to store boolean
values. Now we are handling the boolean values but it still raises if
the value can't type cast to integer and is not a boolean. See #7509.

Fixes #8067.
96a13fc
@rafaelfranca rafaelfranca Fix typo :bomb: [ci skip] fad74d6
@rafaelfranca rafaelfranca Add CHANGELOG entry to #8032 fix
e6b4184 fixes that issue too.

[ci skip]
37c60c9
Commits on Oct 31, 2012
@rafaelfranca rafaelfranca Revert "Merge pull request #7797 from senny/7459_prefix_tempalte_asse…
…rtion_variables"

This reverts commit 2bad605.

Conflicts:
	actionpack/CHANGELOG.md

Reason: This added a regression related with shoulda-matchers, since it
is expecting the instance variable @layouts

See https://github.com/thoughtbot/shoulda-matchers/blob/9e1188eea68c47d9a56ce6280e45027da6187ab1/lib/shoulda/matchers/action_controller/render_with_layout_matcher.rb#L74

This will introduce back #7459 but this stable release will be backward compatible.
Related with #8068.
6b7cd20
@rafaelfranca rafaelfranca Revert "Merge pull request #7659 from HugoLnx/template_error_no_match…
…es_rebased"

This reverts commit 7d17cd2.

Conflicts:
	actionpack/CHANGELOG.md

Reason: This added a regression since people were relying on this buggy behavior.
This will introduce back #3849 but we will be backward compatible in
stable release.

Fixes #8068.
d5b275d
@saks saks Fix ActiveRecord#update_column return value 68307a1
@josevalim josevalim Merge pull request #8083 from saks/fix_update_column_return_value
Fix ActiveRecord#update_column return value
f5f57e2
@fxn fxn relaxes assertion
This method returns the status of the operation,
but as we generally do in the code base it does
not commit to any particular exact value. Hence,
we do not have to check for a singleton, because
if the implementation changes and returns some
other true value the test should pass.
f32f150
Commits on Nov 01, 2012
@carlosantoniodasilva carlosantoniodasilva Fix issue with collection associations and first(n)/last(n)
When calling first(n) or last(n) in a collection, Active Record was
improperly trying to set the inverse of instance in case that option
existed. This change was introduced by
fdf4eae.

In such cases we don't need to do that "manually", since the way
collection will be loaded will already handle that, so we just skip
setting the inverse association when any argument is given to
first(n)/last(n).

The test included ensures that these scenarios will have the inverse of
instance set properly.

Fixes #8087, Closes #8094.
d37d40b
@carlosantoniodasilva carlosantoniodasilva Ensure calling first/last with options correctly set inverse association
Also related to #8087. Thanks @al2o3cr.
c368b66
@spastorino spastorino Bump to 3.2.9.rc2 de3dff3
Showing with 403 additions and 114 deletions.
  1. +1 −1  RAILS_VERSION
  2. +1 −1  actionmailer/lib/action_mailer/version.rb
  3. +15 −0 actionpack/CHANGELOG.md
  4. +26 −33 actionpack/lib/action_controller/test_case.rb
  5. +1 −1  actionpack/lib/action_pack/version.rb
  6. +3 −3 actionpack/lib/action_view/test_case.rb
  7. +0 −22 actionpack/test/controller/action_pack_assertions_test.rb
  8. +0 −1  actionpack/test/fixtures/test/hello/hello.erb
  9. +1 −1  activemodel/lib/active_model/version.rb
  10. +18 −1 activerecord/CHANGELOG.md
  11. +3 −1 activerecord/lib/active_record/associations/collection_association.rb
  12. +1 −1  activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb
  13. +13 −2 activerecord/lib/active_record/connection_adapters/column.rb
  14. +1 −1  activerecord/lib/active_record/persistence.rb
  15. +54 −34 activerecord/lib/active_record/railties/databases.rake
  16. +1 −1  activerecord/lib/active_record/version.rb
  17. +20 −0 activerecord/test/cases/associations/inverse_associations_test.rb
  18. +4 −4 activerecord/test/cases/column_test.rb
  19. +0 −2  activerecord/test/cases/connection_specification/resolver_test.rb
  20. +6 −0 activerecord/test/cases/persistence_test.rb
  21. +1 −1  activeresource/lib/active_resource/version.rb
  22. +1 −1  activesupport/lib/active_support/version.rb
  23. +1 −1  railties/lib/rails/version.rb
  24. +36 −0 railties/test/application/initializers/frameworks_test.rb
  25. +194 −0 railties/test/application/rake/dbs_test.rb
  26. +1 −1  version.rb
View
2  RAILS_VERSION
@@ -1 +1 @@
-3.2.9.rc1
+3.2.9.rc2
View
2  actionmailer/lib/action_mailer/version.rb
@@ -3,7 +3,7 @@ module VERSION #:nodoc:
MAJOR = 3
MINOR = 2
TINY = 9
- PRE = "rc1"
+ PRE = "rc2"
STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
end
View
15 actionpack/CHANGELOG.md
@@ -1,5 +1,20 @@
## Rails 3.2.9 (unreleased) ##
+* Revert the `assert_template` fix to not pass with ever string that matches the template name.
+ This added a regression since people were relying on this buggy behavior.
+ This will introduce back #3849 but this stable release will be backward compatible.
+ Fixes #8068.
+
+ *Rafael Mendonça França*
+
+* Revert the rename of internal variable on ActionController::TemplateAssertions to prevent
+ naming collisions. This added a regression related with shoulda-matchers, since it is
+ expecting the [instance variable @layouts](https://github.com/thoughtbot/shoulda-matchers/blob/9e1188eea68c47d9a56ce6280e45027da6187ab1/lib/shoulda/matchers/action_controller/render_with_layout_matcher.rb#L74).
+ This will introduce back #7459 but this stable release will be backward compatible.
+ Fixes #8068.
+
+ *Rafael Mendonça França*
+
* Accept :remote as symbolic option for `link_to` helper. *Riley Lynch*
* Warn when the `:locals` option is passed to `assert_template` outside of a view test case
View
59 actionpack/lib/action_controller/test_case.rb
@@ -14,13 +14,13 @@ module TemplateAssertions
end
def setup_subscriptions
- @_partials = Hash.new(0)
- @_templates = Hash.new(0)
- @_layouts = Hash.new(0)
+ @partials = Hash.new(0)
+ @templates = Hash.new(0)
+ @layouts = Hash.new(0)
ActiveSupport::Notifications.subscribe("render_template.action_view") do |name, start, finish, id, payload|
path = payload[:layout]
- @_layouts[path] += 1
+ @layouts[path] += 1
end
ActiveSupport::Notifications.subscribe("!render_template.action_view") do |name, start, finish, id, payload|
@@ -28,11 +28,11 @@ def setup_subscriptions
next unless path
partial = path =~ /^.*\/_[^\/]*$/
if partial
- @_partials[path] += 1
- @_partials[path.split("/").last] += 1
- @_templates[path] += 1
+ @partials[path] += 1
+ @partials[path.split("/").last] += 1
+ @templates[path] += 1
else
- @_templates[path] += 1
+ @templates[path] += 1
end
end
end
@@ -43,9 +43,9 @@ def teardown_subscriptions
end
def process(*args)
- @_partials = Hash.new(0)
- @_templates = Hash.new(0)
- @_layouts = Hash.new(0)
+ @partials = Hash.new(0)
+ @templates = Hash.new(0)
+ @layouts = Hash.new(0)
super
end
@@ -72,39 +72,32 @@ def assert_template(options = {}, message = nil)
validate_request!
case options
- when NilClass, Regexp, String, Symbol
+ when NilClass, String, Symbol
options = options.to_s if Symbol === options
- rendered = @_templates
+ rendered = @templates
msg = build_message(message,
"expecting <?> but rendering with <?>",
options, rendered.keys.join(', '))
- matches_template =
- case options
- when String
- rendered.any? do |t, num|
- options_splited = options.split(File::SEPARATOR)
- t_splited = t.split(File::SEPARATOR)
- t_splited.last(options_splited.size) == options_splited
- end
- when Regexp
+ assert_block(msg) do
+ if options
rendered.any? { |t,num| t.match(options) }
- when NilClass
- rendered.blank?
+ else
+ @templates.blank?
end
- assert matches_template, msg
+ end
when Hash
if expected_layout = options[:layout]
msg = build_message(message,
"expecting layout <?> but action rendered <?>",
- expected_layout, @_layouts.keys)
+ expected_layout, @layouts.keys)
case expected_layout
when String
- assert(@_layouts.keys.include?(expected_layout), msg)
+ assert(@layouts.keys.include?(expected_layout), msg)
when Regexp
- assert(@_layouts.keys.any? {|l| l =~ expected_layout }, msg)
+ assert(@layouts.keys.any? {|l| l =~ expected_layout }, msg)
when nil
- assert(@_layouts.empty?, msg)
+ assert(@layouts.empty?, msg)
end
end
@@ -119,7 +112,7 @@ def assert_template(options = {}, message = nil)
warn "the :locals option to #assert_template is only supported in a ActionView::TestCase"
end
elsif expected_count = options[:count]
- actual_count = @_partials[expected_partial]
+ actual_count = @partials[expected_partial]
msg = build_message(message,
"expecting ? to be rendered ? time(s) but rendered ? time(s)",
expected_partial, expected_count, actual_count)
@@ -127,11 +120,11 @@ def assert_template(options = {}, message = nil)
else
msg = build_message(message,
"expecting partial <?> but action rendered <?>",
- options[:partial], @_partials.keys)
- assert(@_partials.include?(expected_partial), msg)
+ options[:partial], @partials.keys)
+ assert(@partials.include?(expected_partial), msg)
end
else
- assert @_partials.empty?,
+ assert @partials.empty?,
"Expected no partials to be rendered"
end
end
View
2  actionpack/lib/action_pack/version.rb
@@ -3,7 +3,7 @@ module VERSION #:nodoc:
MAJOR = 3
MINOR = 2
TINY = 9
- PRE = "rc1"
+ PRE = "rc2"
STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
end
View
6 actionpack/lib/action_view/test_case.rb
@@ -193,16 +193,16 @@ def view
@_result
@_routes
@controller
- @_layouts
+ @layouts
@locals
@method_name
@output_buffer
- @_partials
+ @partials
@passed
@rendered
@request
@routes
- @_templates
+ @templates
@options
@test_passed
@view
View
22 actionpack/test/controller/action_pack_assertions_test.rb
@@ -7,7 +7,6 @@ class ActionPackAssertionsController < ActionController::Base
def nothing() head :ok end
def hello_world() render :template => "test/hello_world"; end
- def hello_repeating_in_path() render :template => "test/hello/hello"; end
def hello_xml_world() render :template => "test/hello_xml_world"; end
@@ -470,20 +469,6 @@ def test_fails_with_incorrect_string
end
end
- def test_fails_with_incorrect_string_that_matches
- get :hello_world
- assert_raise(ActiveSupport::TestCase::Assertion) do
- assert_template 'est/he'
- end
- end
-
- def test_fails_with_repeated_name_in_path
- get :hello_repeating_in_path
- assert_raise(ActiveSupport::TestCase::Assertion) do
- assert_template 'test/hello'
- end
- end
-
def test_fails_with_incorrect_symbol
get :hello_world
assert_raise(ActiveSupport::TestCase::Assertion) do
@@ -491,13 +476,6 @@ def test_fails_with_incorrect_symbol
end
end
- def test_fails_with_incorrect_symbol_that_matches
- get :hello_world
- assert_raise(ActiveSupport::TestCase::Assertion) do
- assert_template :"est/he"
- end
- end
-
def test_fails_with_wrong_layout
get :render_with_layout
assert_raise(ActiveSupport::TestCase::Assertion) do
View
1  actionpack/test/fixtures/test/hello/hello.erb
@@ -1 +0,0 @@
-Hello world!
View
2  activemodel/lib/active_model/version.rb
@@ -3,7 +3,7 @@ module VERSION #:nodoc:
MAJOR = 3
MINOR = 2
TINY = 9
- PRE = "rc1"
+ PRE = "rc2"
STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
end
View
19 activerecord/CHANGELOG.md
@@ -1,5 +1,22 @@
## Rails 3.2.9 (unreleased)
+* Fix issue with collection associations calling first(n)/last(n) and attempting
+ to set the inverse association when `:inverse_of` was used. Fixes #8087.
+
+ *Carlos Antonio da Silva*
+
+* Fix bug when Column is trying to type cast boolean values to integer.
+ Fixes #8067.
+
+ *Rafael Mendonça França*
+
+* Fix bug where `rake db:test:prepare` tries to load the structure.sql into development database.
+ Fixes #8032.
+
+ *Grace Liu + Rafael Mendonça França*
+
+* Fixed support for `DATABASE_URL` environment variable for rake db tasks. *Grace Liu*
+
* Fix bug where `update_columns` and `update_column` would not let you update the primary key column.
*Henrik Nyh*
@@ -11,7 +28,7 @@
* Fix AR#dup to nullify the validation errors in the dup'ed object. Previously the original
and the dup'ed object shared the same errors.
- * Christian Seiler*
+ *Christian Seiler*
* Synchronize around deleting from the reserved connections hash.
Fixes #7955
View
4 activerecord/lib/active_record/associations/collection_association.rb
@@ -571,7 +571,9 @@ def first_or_last(type, *args)
args.shift if args.first.is_a?(Hash) && args.first.empty?
collection = fetch_first_or_last_using_find?(args) ? scoped : load_target
- collection.send(type, *args).tap {|it| set_inverse_instance it }
+ collection.send(type, *args).tap do |record|
+ set_inverse_instance record if record.is_a? ActiveRecord::Base
+ end
end
end
end
View
2  activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb
@@ -67,7 +67,7 @@ def connection_url_to_hash(url) # :nodoc:
:port => config.port,
:database => config.path.sub(%r{^/},""),
:host => config.host }
- spec.reject!{ |_,value| !value }
+ spec.reject!{ |_,value| value.blank? }
spec.map { |key,value| spec[key] = URI.unescape(value) if value.is_a?(String) }
if config.query
options = Hash[config.query.split("&").map{ |pair| pair.split("=") }].symbolize_keys
View
15 activerecord/lib/active_record/connection_adapters/column.rb
@@ -75,7 +75,7 @@ def type_cast(value)
case type
when :string, :text then value
- when :integer then value.to_i
+ when :integer then klass.value_to_integer(value)
when :float then value.to_f
when :decimal then klass.value_to_decimal(value)
when :datetime, :timestamp then klass.string_to_time(value)
@@ -92,7 +92,7 @@ def type_cast_code(var_name)
case type
when :string, :text then var_name
- when :integer then "(#{var_name}.to_i)"
+ when :integer then "#{klass}.value_to_integer(#{var_name})"
when :float then "#{var_name}.to_f"
when :decimal then "#{klass}.value_to_decimal(#{var_name})"
when :datetime, :timestamp then "#{klass}.string_to_time(#{var_name})"
@@ -168,6 +168,17 @@ def value_to_boolean(value)
end
end
+ # Used to convert values to integer.
+ # handle the case when an integer column is used to store boolean values
+ def value_to_integer(value)
+ case value
+ when TrueClass, FalseClass
+ value ? 1 : 0
+ else
+ value.to_i
+ end
+ end
+
# convert something to a BigDecimal
def value_to_decimal(value)
# Using .class is faster than .is_a? and
View
2  activerecord/lib/active_record/persistence.rb
@@ -194,7 +194,7 @@ def update_column(name, value)
raise ActiveRecordError, "#{name} is marked as readonly" if self.class.readonly_attributes.include?(name)
raise ActiveRecordError, "can not update on a new record object" unless persisted?
- updated_count = self.class.update_all({ name => value }, self.class.primary_key => id) == 1
+ updated_count = self.class.update_all({ name => value }, self.class.primary_key => id)
raw_write_attribute(name, value)
View
88 activerecord/lib/active_record/railties/databases.rake
@@ -2,6 +2,25 @@ require 'active_support/core_ext/object/inclusion'
require 'active_record'
db_namespace = namespace :db do
+ def database_url_config
+ @database_url_config ||=
+ ActiveRecord::Base::ConnectionSpecification::Resolver.new(ENV["DATABASE_URL"], {}).spec.config.stringify_keys
+ end
+
+ def current_config(options = {})
+ options = { :env => Rails.env }.merge! options
+
+ if options[:config]
+ @current_config = options[:config]
+ else
+ @current_config ||= if ENV['DATABASE_URL']
+ database_url_config
+ else
+ ActiveRecord::Base.configurations[options[:env]]
+ end
+ end
+ end
+
task :load_config do
ActiveRecord::Base.configurations = Rails.application.config.database_configuration
ActiveRecord::Migrator.migrations_paths = Rails.application.paths['db/migrate'].to_a
@@ -35,10 +54,14 @@ db_namespace = namespace :db do
end
end
- desc 'Create the database from config/database.yml for the current Rails.env (use db:create:all to create all dbs in the config)'
+ desc 'Create the database from DATABASE_URL or config/database.yml for the current Rails.env (use db:create:all to create all dbs in the config)'
task :create => [:load_config, :rails_env] do
- configs_for_environment.each { |config| create_database(config) }
- ActiveRecord::Base.establish_connection(configs_for_environment.first)
+ if ENV['DATABASE_URL']
+ create_database(database_url_config)
+ else
+ configs_for_environment.each { |config| create_database(config) }
+ ActiveRecord::Base.establish_connection(configs_for_environment.first)
+ end
end
def mysql_creation_options(config)
@@ -133,9 +156,13 @@ db_namespace = namespace :db do
end
end
- desc 'Drops the database for the current Rails.env (use db:drop:all to drop all databases)'
+ desc 'Drops the database using DATABASE_URL or the current Rails.env (use db:drop:all to drop all databases)'
task :drop => [:load_config, :rails_env] do
- configs_for_environment.each { |config| drop_database_and_rescue(config) }
+ if ENV['DATABASE_URL']
+ drop_database_and_rescue(database_url_config)
+ else
+ configs_for_environment.each { |config| drop_database_and_rescue(config) }
+ end
end
def local_database?(config, &block)
@@ -146,7 +173,6 @@ db_namespace = namespace :db do
end
end
-
desc "Migrate the database (options: VERSION=x, VERBOSE=false)."
task :migrate => [:environment, :load_config] do
ActiveRecord::Migration.verbose = ENV["VERBOSE"] ? ENV["VERBOSE"] == "true" : true
@@ -201,8 +227,6 @@ db_namespace = namespace :db do
desc 'Display status of migrations'
task :status => [:environment, :load_config] do
- config = ActiveRecord::Base.configurations[Rails.env]
- ActiveRecord::Base.establish_connection(config)
unless ActiveRecord::Base.connection.table_exists?(ActiveRecord::Migrator.schema_migrations_table_name)
puts 'Schema migrations table does not exist yet.'
next # means "return" for rake task
@@ -222,7 +246,7 @@ db_namespace = namespace :db do
['up', version, '********** NO FILE **********']
end
# output
- puts "\ndatabase: #{config['database']}\n\n"
+ puts "\ndatabase: #{ActiveRecord::Base.connection_config[:database]}\n\n"
puts "#{'Status'.center(8)} #{'Migration ID'.ljust(14)} Migration Name"
puts "-" * 50
(db_list + file_list).sort_by {|migration| migration[1]}.each do |migration|
@@ -314,7 +338,6 @@ db_namespace = namespace :db do
task :load => [:environment, :load_config] do
require 'active_record/fixtures'
- ActiveRecord::Base.establish_connection(Rails.env)
base_dir = File.join [Rails.root, ENV['FIXTURES_PATH'] || %w{test fixtures}].flatten
fixtures_dir = File.join [base_dir, ENV['FIXTURES_DIR']].compact
@@ -353,7 +376,6 @@ db_namespace = namespace :db do
require 'active_record/schema_dumper'
filename = ENV['SCHEMA'] || "#{Rails.root}/db/schema.rb"
File.open(filename, "w:utf-8") do |file|
- ActiveRecord::Base.establish_connection(Rails.env)
ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, file)
end
db_namespace['schema:dump'].reenable
@@ -377,25 +399,25 @@ db_namespace = namespace :db do
namespace :structure do
desc 'Dump the database structure to db/structure.sql. Specify another file with DB_STRUCTURE=db/my_structure.sql'
task :dump => [:environment, :load_config] do
- abcs = ActiveRecord::Base.configurations
+ config = current_config
filename = ENV['DB_STRUCTURE'] || File.join(Rails.root, "db", "structure.sql")
- case abcs[Rails.env]['adapter']
+ case config['adapter']
when /mysql/, 'oci', 'oracle'
- ActiveRecord::Base.establish_connection(abcs[Rails.env])
+ ActiveRecord::Base.establish_connection(config)
File.open(filename, "w:utf-8") { |f| f << ActiveRecord::Base.connection.structure_dump }
when /postgresql/
- set_psql_env(abcs[Rails.env])
- search_path = abcs[Rails.env]['schema_search_path']
+ set_psql_env(config)
+ search_path = config['schema_search_path']
unless search_path.blank?
search_path = search_path.split(",").map{|search_path_part| "--schema=#{Shellwords.escape(search_path_part.strip)}" }.join(" ")
end
- `pg_dump -i -s -x -O -f #{Shellwords.escape(filename)} #{search_path} #{Shellwords.escape(abcs[Rails.env]['database'])}`
+ `pg_dump -i -s -x -O -f #{Shellwords.escape(filename)} #{search_path} #{Shellwords.escape(config['database'])}`
raise 'Error dumping database' if $?.exitstatus == 1
when /sqlite/
- dbfile = abcs[Rails.env]['database']
+ dbfile = config['database']
`sqlite3 #{dbfile} .schema > #{filename}`
when 'sqlserver'
- `smoscript -s #{abcs[Rails.env]['host']} -d #{abcs[Rails.env]['database']} -u #{abcs[Rails.env]['username']} -p #{abcs[Rails.env]['password']} -f #{filename} -A -U`
+ `smoscript -s #{config['host']} -d #{config['database']} -u #{config['username']} -p #{config['password']} -f #{filename} -A -U`
when "firebird"
set_firebird_env(abcs[Rails.env])
db_string = firebird_db_string(abcs[Rails.env])
@@ -412,36 +434,34 @@ db_namespace = namespace :db do
# desc "Recreate the databases from the structure.sql file"
task :load => [:environment, :load_config] do
- env = Rails.env
-
- abcs = ActiveRecord::Base.configurations
+ config = current_config
filename = ENV['DB_STRUCTURE'] || File.join(Rails.root, "db", "structure.sql")
- case abcs[env]['adapter']
+ case config['adapter']
when /mysql/
- ActiveRecord::Base.establish_connection(abcs[env])
+ ActiveRecord::Base.establish_connection(config)
ActiveRecord::Base.connection.execute('SET foreign_key_checks = 0')
IO.read(filename).split("\n\n").each do |table|
ActiveRecord::Base.connection.execute(table)
end
when /postgresql/
- set_psql_env(abcs[env])
- `psql -f "#{filename}" #{abcs[env]['database']}`
+ set_psql_env(config)
+ `psql -f "#{filename}" #{config['database']}`
when /sqlite/
- dbfile = abcs[env]['database']
+ dbfile = config['database']
`sqlite3 #{dbfile} < "#{filename}"`
when 'sqlserver'
- `sqlcmd -S #{abcs[env]['host']} -d #{abcs[env]['database']} -U #{abcs[env]['username']} -P #{abcs[env]['password']} -i #{filename}`
+ `sqlcmd -S #{config['host']} -d #{config['database']} -U #{config['username']} -P #{config['password']} -i #{filename}`
when 'oci', 'oracle'
- ActiveRecord::Base.establish_connection(abcs[env])
+ ActiveRecord::Base.establish_connection(config)
IO.read(filename).split(";\n\n").each do |ddl|
ActiveRecord::Base.connection.execute(ddl)
end
when 'firebird'
- set_firebird_env(abcs[env])
- db_string = firebird_db_string(abcs[env])
+ set_firebird_env(config)
+ db_string = firebird_db_string(config)
sh "isql -i #{filename} #{db_string}"
else
- raise "Task not supported by '#{abcs[env]['adapter']}'"
+ raise "Task not supported by '#{config['adapter']}'"
end
end
@@ -465,10 +485,10 @@ db_namespace = namespace :db do
# desc "Recreate the test database from an existent structure.sql file"
task :load_structure => 'db:test:purge' do
begin
- old_env, ENV['RAILS_ENV'] = ENV['RAILS_ENV'], 'test'
+ current_config(:config => ActiveRecord::Base.configurations['test'])
db_namespace["structure:load"].invoke
ensure
- ENV['RAILS_ENV'] = old_env
+ current_config(:config => nil)
end
end
View
2  activerecord/lib/active_record/version.rb
@@ -3,7 +3,7 @@ module VERSION #:nodoc:
MAJOR = 3
MINOR = 2
TINY = 9
- PRE = "rc1"
+ PRE = "rc2"
STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
end
View
20 activerecord/test/cases/associations/inverse_associations_test.rb
@@ -261,10 +261,30 @@ def test_parent_instance_should_be_shared_with_replaced_via_accessor_children
def test_parent_instance_should_be_shared_with_first_and_last_child
man = Man.first
+
assert man.interests.first.man.equal? man
assert man.interests.last.man.equal? man
end
+ def test_parent_instance_should_be_shared_with_first_and_last_child_when_given_options
+ man = Man.first
+
+ assert man.interests.first(:order => 'topic').man.equal? man
+ assert man.interests.last(:order => 'topic').man.equal? man
+ end
+
+ def test_parent_instance_should_be_shared_with_first_n_and_last_n_children
+ man = Man.first
+
+ interests = man.interests.first(2)
+ assert interests[0].man.equal? man
+ assert interests[1].man.equal? man
+
+ interests = man.interests.last(2)
+ assert interests[0].man.equal? man
+ assert interests[1].man.equal? man
+ end
+
def test_trying_to_use_inverses_that_dont_exist_should_raise_an_error
assert_raise(ActiveRecord::InverseOfAssociationNotFoundError) { Man.find(:first).secret_interests }
end
View
8 activerecord/test/cases/column_test.rb
@@ -33,6 +33,8 @@ def test_type_cast_integer
assert_equal 0, column.type_cast('bad1')
assert_equal 0, column.type_cast('bad')
assert_equal 1, column.type_cast(1.7)
+ assert_equal 0, column.type_cast(false)
+ assert_equal 1, column.type_cast(true)
assert_nil column.type_cast(nil)
end
@@ -41,11 +43,9 @@ def test_type_cast_non_integer_to_integer
assert_raises(NoMethodError) do
column.type_cast([])
end
+
assert_raises(NoMethodError) do
- column.type_cast(true)
- end
- assert_raises(NoMethodError) do
- column.type_cast(false)
+ column.type_cast(Object.new)
end
end
end
View
2  activerecord/test/cases/connection_specification/resolver_test.rb
@@ -13,7 +13,6 @@ def test_url_host_no_db
spec = resolve 'mysql://foo?encoding=utf8'
assert_equal({
:adapter => "mysql",
- :database => "",
:host => "foo",
:encoding => "utf8" }, spec)
end
@@ -33,7 +32,6 @@ def test_url_port
spec = resolve 'mysql://foo:123?encoding=utf8'
assert_equal({
:adapter => "mysql",
- :database => "",
:port => 123,
:host => "foo",
:encoding => "utf8" }, spec)
View
6 activerecord/test/cases/persistence_test.rb
@@ -513,6 +513,12 @@ def test_update_column_changing_id
assert_equal 123, topic.id
end
+ def test_update_column_should_return_correct_value
+ developer = Developer.find(1)
+ return_value = developer.update_column(:salary, 80001)
+ assert return_value
+ end
+
def test_update_attributes
topic = Topic.find(1)
assert !topic.approved?
View
2  activeresource/lib/active_resource/version.rb
@@ -3,7 +3,7 @@ module VERSION #:nodoc:
MAJOR = 3
MINOR = 2
TINY = 9
- PRE = "rc1"
+ PRE = "rc2"
STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
end
View
2  activesupport/lib/active_support/version.rb
@@ -3,7 +3,7 @@ module VERSION #:nodoc:
MAJOR = 3
MINOR = 2
TINY = 9
- PRE = "rc1"
+ PRE = "rc2"
STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
end
View
2  railties/lib/rails/version.rb
@@ -3,7 +3,7 @@ module VERSION #:nodoc:
MAJOR = 3
MINOR = 2
TINY = 9
- PRE = "rc1"
+ PRE = "rc2"
STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
end
View
36 railties/test/application/initializers/frameworks_test.rb
@@ -193,5 +193,41 @@ def from_bar_helper
require "#{app_path}/config/environment"
assert_nil defined?(ActiveRecord::Base)
end
+
+ test "active record establish_connection uses Rails.env if DATABASE_URL is not set" do
+ begin
+ require "#{app_path}/config/environment"
+ orig_database_url = ENV.delete("DATABASE_URL")
+ orig_rails_env, Rails.env = Rails.env, 'development'
+
+ ActiveRecord::Base.establish_connection
+
+ assert ActiveRecord::Base.connection
+ assert_match /#{ActiveRecord::Base.configurations[Rails.env]['database']}/, ActiveRecord::Base.connection_config[:database]
+ ensure
+ ActiveRecord::Base.remove_connection
+ ENV["DATABASE_URL"] = orig_database_url if orig_database_url
+ Rails.env = orig_rails_env if orig_rails_env
+ end
+ end
+
+ test "active record establish_connection uses DATABASE_URL even if Rails.env is set" do
+ begin
+ require "#{app_path}/config/environment"
+ orig_database_url = ENV.delete("DATABASE_URL")
+ orig_rails_env, Rails.env = Rails.env, 'development'
+ database_url_db_name = "db/database_url_db.sqlite3"
+ ENV["DATABASE_URL"] = "sqlite3://:@localhost/#{database_url_db_name}"
+
+ ActiveRecord::Base.establish_connection
+
+ assert ActiveRecord::Base.connection
+ assert_match /#{database_url_db_name}/, ActiveRecord::Base.connection_config[:database]
+ ensure
+ ActiveRecord::Base.remove_connection
+ ENV["DATABASE_URL"] = orig_database_url if orig_database_url
+ Rails.env = orig_rails_env if orig_rails_env
+ end
+ end
end
end
View
194 railties/test/application/rake/dbs_test.rb
@@ -0,0 +1,194 @@
+require "isolation/abstract_unit"
+
+module ApplicationTests
+ module RakeTests
+ class RakeDbsTest < Test::Unit::TestCase
+ include ActiveSupport::Testing::Isolation
+
+ def setup
+ build_app
+ boot_rails
+ FileUtils.rm_rf("#{app_path}/config/environments")
+ end
+
+ def teardown
+ teardown_app
+ end
+
+ def database_url_db_name
+ "db/database_url_db.sqlite3"
+ end
+
+ def set_database_url
+ ENV['DATABASE_URL'] = "sqlite3://:@localhost/#{database_url_db_name}"
+ end
+
+ def expected
+ @expected ||= {}
+ end
+
+ def db_create_and_drop
+ Dir.chdir(app_path) do
+ output = `bundle exec rake db:create`
+ assert_equal output, ""
+ assert File.exists?(expected[:database])
+ assert_equal expected[:database],
+ ActiveRecord::Base.connection_config[:database]
+ output = `bundle exec rake db:drop`
+ assert_equal output, ""
+ assert !File.exists?(expected[:database])
+ end
+ end
+
+ test 'db:create and db:drop without database url' do
+ require "#{app_path}/config/environment"
+ expected[:database] = ActiveRecord::Base.configurations[Rails.env]['database']
+ db_create_and_drop
+ end
+
+ test 'db:create and db:drop with database url' do
+ require "#{app_path}/config/environment"
+ set_database_url
+ expected[:database] = database_url_db_name
+ db_create_and_drop
+ end
+
+ def db_migrate_and_status
+ Dir.chdir(app_path) do
+ `rails generate model book title:string`
+ `bundle exec rake db:migrate`
+ output = `bundle exec rake db:migrate:status`
+ assert_match(/database:\s+\S*#{expected[:database]}/, output)
+ assert_match(/up\s+\d{14}\s+Create books/, output)
+ end
+ end
+
+ test 'db:migrate and db:migrate:status without database_url' do
+ require "#{app_path}/config/environment"
+ expected[:database] = ActiveRecord::Base.configurations[Rails.env]['database']
+ db_migrate_and_status
+ end
+
+ test 'db:migrate and db:migrate:status with database_url' do
+ require "#{app_path}/config/environment"
+ set_database_url
+ expected[:database] = database_url_db_name
+ db_migrate_and_status
+ end
+
+ def db_schema_dump
+ Dir.chdir(app_path) do
+ `rails generate model book title:string`
+ `rake db:migrate`
+ `rake db:schema:dump`
+
+ assert File.exists?("db/schema.rb"), "db/schema.rb doesn't exist"
+
+ schema_dump = File.read("db/schema.rb")
+
+ assert_match(/create_table \"books\"/, schema_dump)
+ end
+ end
+
+ test 'db:schema:dump without database_url' do
+ db_schema_dump
+ end
+
+ test 'db:schema:dump with database_url' do
+ set_database_url
+ db_schema_dump
+ end
+
+ def db_fixtures_load
+ Dir.chdir(app_path) do
+ `rails generate model book title:string`
+ `bundle exec rake db:migrate`
+ `bundle exec rake db:fixtures:load`
+ assert_match /#{expected[:database]}/,
+ ActiveRecord::Base.connection_config[:database]
+ require "#{app_path}/app/models/book"
+ assert_equal 2, Book.count
+ end
+ end
+
+ test 'db:fixtures:load without database_url' do
+ require "#{app_path}/config/environment"
+ expected[:database] = ActiveRecord::Base.configurations[Rails.env]['database']
+ db_fixtures_load
+ end
+
+ test 'db:fixtures:load with database_url' do
+ require "#{app_path}/config/environment"
+ set_database_url
+ expected[:database] = database_url_db_name
+ db_fixtures_load
+ end
+
+ def db_structure_dump_and_load
+ Dir.chdir(app_path) do
+ `rails generate model book title:string`
+ `bundle exec rake db:create`
+ `bundle exec rake db:migrate`
+ `bundle exec rake db:structure:dump`
+
+ assert File.exists?("db/structure.sql"), "db/structure.sql doesn't exist"
+
+ structure_dump = File.read("db/structure.sql")
+
+ assert_match /CREATE TABLE \"books\"/, structure_dump
+
+ `bundle exec rake db:drop`
+ `bundle exec rake db:structure:load`
+
+ assert_match /#{expected[:database]}/,
+ ActiveRecord::Base.connection_config[:database]
+
+ require "#{app_path}/app/models/book"
+ #if structure is not loaded correctly, exception would be raised
+ assert_equal Book.count, 0
+ end
+ end
+
+ test 'db:structure:dump and db:structure:load without database_url' do
+ require "#{app_path}/config/environment"
+ expected[:database] = ActiveRecord::Base.configurations[Rails.env]['database']
+ db_structure_dump_and_load
+ end
+
+ test 'db:structure:dump and db:structure:load with database_url' do
+ require "#{app_path}/config/environment"
+ set_database_url
+ expected[:database] = database_url_db_name
+ db_structure_dump_and_load
+ end
+
+ def db_test_load_structure
+ Dir.chdir(app_path) do
+ `rails generate model book title:string`
+ `bundle exec rake db:migrate`
+ `bundle exec rake db:structure:dump`
+ `bundle exec rake db:test:load_structure`
+ ActiveRecord::Base.configurations = Rails.application.config.database_configuration
+ ActiveRecord::Base.establish_connection 'test'
+ require "#{app_path}/app/models/book"
+
+ #if structure is not loaded correctly, exception would be raised
+ assert_equal Book.count, 0
+ assert_match /#{ActiveRecord::Base.configurations['test']['database']}/,
+ ActiveRecord::Base.connection_config[:database]
+ end
+ end
+
+ test 'db:test:load_structure without database_url' do
+ require "#{app_path}/config/environment"
+ db_test_load_structure
+ end
+
+ test 'db:test:load_structure with database_url' do
+ require "#{app_path}/config/environment"
+ set_database_url
+ db_test_load_structure
+ end
+ end
+ end
+end
View
2  version.rb
@@ -3,7 +3,7 @@ module VERSION #:nodoc:
MAJOR = 3
MINOR = 2
TINY = 9
- PRE = "rc1"
+ PRE = "rc2"
STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
end

Showing you all comments on commits in this comparison.

@frodsan

typo => boolean

@rafaelfranca

:bomb:. I'll fix in a second

@frodsan

:+1: powered by RafaLint™

@rafaelfranca

lol. My lint algorithm is getting slower

Something went wrong with that request. Please try again.