Skip to content
This repository
  • 13 commits
  • 26 files changed
  • 4 comments
  • 7 contributors
Oct 29, 2012
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
Rafael Mendonça França Merge pull request #8009 from graceliu/3-2-fix_database_url_support
fixed support for DATABASE_URL for rake db tasks
e6b4184
Rafael Mendonça França 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
Rafael Mendonça França Fix typo :bomb: [ci skip] fad74d6
Rafael Mendonça França Add CHANGELOG entry to #8032 fix
e6b4184 fixes that issue too.

[ci skip]
37c60c9
Oct 30, 2012
Rafael Mendonça França 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
Oct 31, 2012
Rafael Mendonça França 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
Aliaxandr Rahalevich Fix ActiveRecord#update_column return value 68307a1
José Valim Merge pull request #8083 from saks/fix_update_column_return_value
Fix ActiveRecord#update_column return value
f5f57e2
Xavier Noria 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
Nov 01, 2012
Carlos Antonio da Silva 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
Carlos Antonio da Silva Ensure calling first/last with options correctly set inverse association
Also related to #8087. Thanks @al2o3cr.
c368b66
Santiago Pastorino Bump to 3.2.9.rc2 de3dff3

Showing 26 changed files with 403 additions and 114 deletions. Show diff stats Hide diff stats

  1. 2  RAILS_VERSION
  2. 2  actionmailer/lib/action_mailer/version.rb
  3. 15  actionpack/CHANGELOG.md
  4. 59  actionpack/lib/action_controller/test_case.rb
  5. 2  actionpack/lib/action_pack/version.rb
  6. 6  actionpack/lib/action_view/test_case.rb
  7. 22  actionpack/test/controller/action_pack_assertions_test.rb
  8. 1  actionpack/test/fixtures/test/hello/hello.erb
  9. 2  activemodel/lib/active_model/version.rb
  10. 19  activerecord/CHANGELOG.md
  11. 4  activerecord/lib/active_record/associations/collection_association.rb
  12. 2  activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb
  13. 15  activerecord/lib/active_record/connection_adapters/column.rb
  14. 2  activerecord/lib/active_record/persistence.rb
  15. 88  activerecord/lib/active_record/railties/databases.rake
  16. 2  activerecord/lib/active_record/version.rb
  17. 20  activerecord/test/cases/associations/inverse_associations_test.rb
  18. 8  activerecord/test/cases/column_test.rb
  19. 2  activerecord/test/cases/connection_specification/resolver_test.rb
  20. 6  activerecord/test/cases/persistence_test.rb
  21. 2  activeresource/lib/active_resource/version.rb
  22. 2  activesupport/lib/active_support/version.rb
  23. 2  railties/lib/rails/version.rb
  24. 36  railties/test/application/initializers/frameworks_test.rb
  25. 194  railties/test/application/rake/dbs_test.rb
  26. 2  version.rb
2  RAILS_VERSION
... ...
@@ -1 +1 @@
1  
-3.2.9.rc1
  1
+3.2.9.rc2
2  actionmailer/lib/action_mailer/version.rb
@@ -3,7 +3,7 @@ module VERSION #:nodoc:
3 3
     MAJOR = 3
4 4
     MINOR = 2
5 5
     TINY  = 9
6  
-    PRE   = "rc1"
  6
+    PRE   = "rc2"
7 7
 
8 8
     STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
9 9
   end
15  actionpack/CHANGELOG.md
Source Rendered
... ...
@@ -1,5 +1,20 @@
1 1
 ## Rails 3.2.9 (unreleased) ##
2 2
 
  3
+*   Revert the `assert_template` fix to not pass with ever string that matches the template name.
  4
+    This added a regression since people were relying on this buggy behavior.
  5
+    This will introduce back #3849 but this stable release will be backward compatible.
  6
+    Fixes #8068.
  7
+
  8
+    *Rafael Mendonça França*
  9
+
  10
+*   Revert the rename of internal variable on ActionController::TemplateAssertions to prevent
  11
+    naming collisions. This added a regression related with shoulda-matchers, since it is
  12
+    expecting the [instance variable @layouts](https://github.com/thoughtbot/shoulda-matchers/blob/9e1188eea68c47d9a56ce6280e45027da6187ab1/lib/shoulda/matchers/action_controller/render_with_layout_matcher.rb#L74).
  13
+    This will introduce back #7459 but this stable release will be backward compatible.
  14
+    Fixes #8068.
  15
+
  16
+    *Rafael Mendonça França*
  17
+
3 18
 *   Accept :remote as symbolic option for `link_to` helper. *Riley Lynch*
4 19
 
5 20
 *   Warn when the `:locals` option is passed to `assert_template` outside of a view test case
59  actionpack/lib/action_controller/test_case.rb
@@ -14,13 +14,13 @@ module TemplateAssertions
14 14
     end
15 15
 
16 16
     def setup_subscriptions
17  
-      @_partials = Hash.new(0)
18  
-      @_templates = Hash.new(0)
19  
-      @_layouts = Hash.new(0)
  17
+      @partials = Hash.new(0)
  18
+      @templates = Hash.new(0)
  19
+      @layouts = Hash.new(0)
20 20
 
21 21
       ActiveSupport::Notifications.subscribe("render_template.action_view") do |name, start, finish, id, payload|
22 22
         path = payload[:layout]
23  
-        @_layouts[path] += 1
  23
+        @layouts[path] += 1
24 24
       end
25 25
 
26 26
       ActiveSupport::Notifications.subscribe("!render_template.action_view") do |name, start, finish, id, payload|
@@ -28,11 +28,11 @@ def setup_subscriptions
28 28
         next unless path
29 29
         partial = path =~ /^.*\/_[^\/]*$/
30 30
         if partial
31  
-          @_partials[path] += 1
32  
-          @_partials[path.split("/").last] += 1
33  
-          @_templates[path] += 1
  31
+          @partials[path] += 1
  32
+          @partials[path.split("/").last] += 1
  33
+          @templates[path] += 1
34 34
         else
35  
-          @_templates[path] += 1
  35
+          @templates[path] += 1
36 36
         end
37 37
       end
38 38
     end
@@ -43,9 +43,9 @@ def teardown_subscriptions
43 43
     end
44 44
 
45 45
     def process(*args)
46  
-      @_partials = Hash.new(0)
47  
-      @_templates = Hash.new(0)
48  
-      @_layouts = Hash.new(0)
  46
+      @partials = Hash.new(0)
  47
+      @templates = Hash.new(0)
  48
+      @layouts = Hash.new(0)
49 49
       super
50 50
     end
51 51
 
@@ -72,39 +72,32 @@ def assert_template(options = {}, message = nil)
72 72
       validate_request!
73 73
 
74 74
       case options
75  
-      when NilClass, Regexp, String, Symbol
  75
+      when NilClass, String, Symbol
76 76
         options = options.to_s if Symbol === options
77  
-        rendered = @_templates
  77
+        rendered = @templates
78 78
         msg = build_message(message,
79 79
                 "expecting <?> but rendering with <?>",
80 80
                 options, rendered.keys.join(', '))
81  
-        matches_template =
82  
-          case options
83  
-          when String
84  
-            rendered.any? do |t, num|
85  
-              options_splited = options.split(File::SEPARATOR)
86  
-              t_splited = t.split(File::SEPARATOR)
87  
-              t_splited.last(options_splited.size) == options_splited
88  
-            end
89  
-          when Regexp
  81
+        assert_block(msg) do
  82
+          if options
90 83
             rendered.any? { |t,num| t.match(options) }
91  
-          when NilClass
92  
-            rendered.blank?
  84
+          else
  85
+            @templates.blank?
93 86
           end
94  
-        assert matches_template, msg
  87
+        end
95 88
       when Hash
96 89
         if expected_layout = options[:layout]
97 90
           msg = build_message(message,
98 91
                   "expecting layout <?> but action rendered <?>",
99  
-                  expected_layout, @_layouts.keys)
  92
+                  expected_layout, @layouts.keys)
100 93
 
101 94
           case expected_layout
102 95
           when String
103  
-            assert(@_layouts.keys.include?(expected_layout), msg)
  96
+            assert(@layouts.keys.include?(expected_layout), msg)
104 97
           when Regexp
105  
-            assert(@_layouts.keys.any? {|l| l =~ expected_layout }, msg)
  98
+            assert(@layouts.keys.any? {|l| l =~ expected_layout }, msg)
106 99
           when nil
107  
-            assert(@_layouts.empty?, msg)
  100
+            assert(@layouts.empty?, msg)
108 101
           end
109 102
         end
110 103
 
@@ -119,7 +112,7 @@ def assert_template(options = {}, message = nil)
119 112
               warn "the :locals option to #assert_template is only supported in a ActionView::TestCase"
120 113
             end
121 114
           elsif expected_count = options[:count]
122  
-            actual_count = @_partials[expected_partial]
  115
+            actual_count = @partials[expected_partial]
123 116
             msg = build_message(message,
124 117
                     "expecting ? to be rendered ? time(s) but rendered ? time(s)",
125 118
                      expected_partial, expected_count, actual_count)
@@ -127,11 +120,11 @@ def assert_template(options = {}, message = nil)
127 120
           else
128 121
             msg = build_message(message,
129 122
                     "expecting partial <?> but action rendered <?>",
130  
-                    options[:partial], @_partials.keys)
131  
-            assert(@_partials.include?(expected_partial), msg)
  123
+                    options[:partial], @partials.keys)
  124
+            assert(@partials.include?(expected_partial), msg)
132 125
           end
133 126
         else
134  
-          assert @_partials.empty?,
  127
+          assert @partials.empty?,
135 128
             "Expected no partials to be rendered"
136 129
         end
137 130
       end
2  actionpack/lib/action_pack/version.rb
@@ -3,7 +3,7 @@ module VERSION #:nodoc:
3 3
     MAJOR = 3
4 4
     MINOR = 2
5 5
     TINY  = 9
6  
-    PRE   = "rc1"
  6
+    PRE   = "rc2"
7 7
 
8 8
     STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
9 9
   end
6  actionpack/lib/action_view/test_case.rb
@@ -193,16 +193,16 @@ def view
193 193
         @_result
194 194
         @_routes
195 195
         @controller
196  
-        @_layouts
  196
+        @layouts
197 197
         @locals
198 198
         @method_name
199 199
         @output_buffer
200  
-        @_partials
  200
+        @partials
201 201
         @passed
202 202
         @rendered
203 203
         @request
204 204
         @routes
205  
-        @_templates
  205
+        @templates
206 206
         @options
207 207
         @test_passed
208 208
         @view
22  actionpack/test/controller/action_pack_assertions_test.rb
@@ -7,7 +7,6 @@ class ActionPackAssertionsController < ActionController::Base
7 7
   def nothing() head :ok end
8 8
 
9 9
   def hello_world() render :template => "test/hello_world"; end
10  
-  def hello_repeating_in_path() render :template => "test/hello/hello"; end
11 10
 
12 11
   def hello_xml_world() render :template => "test/hello_xml_world"; end
13 12
 
@@ -470,20 +469,6 @@ def test_fails_with_incorrect_string
470 469
     end
471 470
   end
472 471
 
473  
-  def test_fails_with_incorrect_string_that_matches
474  
-    get :hello_world
475  
-    assert_raise(ActiveSupport::TestCase::Assertion) do
476  
-      assert_template 'est/he'
477  
-    end
478  
-  end
479  
-
480  
-  def test_fails_with_repeated_name_in_path
481  
-    get :hello_repeating_in_path
482  
-    assert_raise(ActiveSupport::TestCase::Assertion) do
483  
-      assert_template 'test/hello'
484  
-    end
485  
-  end
486  
-
487 472
   def test_fails_with_incorrect_symbol
488 473
     get :hello_world
489 474
     assert_raise(ActiveSupport::TestCase::Assertion) do
@@ -491,13 +476,6 @@ def test_fails_with_incorrect_symbol
491 476
     end
492 477
   end
493 478
 
494  
-  def test_fails_with_incorrect_symbol_that_matches
495  
-    get :hello_world
496  
-    assert_raise(ActiveSupport::TestCase::Assertion) do
497  
-      assert_template :"est/he"
498  
-    end
499  
-  end
500  
-
501 479
   def test_fails_with_wrong_layout
502 480
     get :render_with_layout
503 481
     assert_raise(ActiveSupport::TestCase::Assertion) do
1  actionpack/test/fixtures/test/hello/hello.erb
... ...
@@ -1 +0,0 @@
1  
-Hello world!
2  activemodel/lib/active_model/version.rb
@@ -3,7 +3,7 @@ module VERSION #:nodoc:
3 3
     MAJOR = 3
4 4
     MINOR = 2
5 5
     TINY  = 9
6  
-    PRE   = "rc1"
  6
+    PRE   = "rc2"
7 7
 
8 8
     STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
9 9
   end
19  activerecord/CHANGELOG.md
Source Rendered
... ...
@@ -1,5 +1,22 @@
1 1
 ## Rails 3.2.9 (unreleased)
2 2
 
  3
+*   Fix issue with collection associations calling first(n)/last(n) and attempting
  4
+    to set the inverse association when `:inverse_of` was used. Fixes #8087.
  5
+
  6
+    *Carlos Antonio da Silva*
  7
+
  8
+*   Fix bug when Column is trying to type cast boolean values to integer.
  9
+    Fixes #8067.
  10
+
  11
+    *Rafael Mendonça França*
  12
+
  13
+*   Fix bug where `rake db:test:prepare` tries to load the structure.sql into development database.
  14
+    Fixes #8032.
  15
+
  16
+    *Grace Liu + Rafael Mendonça França*
  17
+
  18
+*   Fixed support for `DATABASE_URL` environment variable for rake db tasks. *Grace Liu*
  19
+
3 20
 *   Fix bug where `update_columns` and `update_column` would not let you update the primary key column.
4 21
 
5 22
     *Henrik Nyh*
@@ -11,7 +28,7 @@
11 28
 *   Fix AR#dup to nullify the validation errors in the dup'ed object. Previously the original
12 29
     and the dup'ed object shared the same errors.
13 30
 
14  
-    * Christian Seiler*
  31
+    *Christian Seiler*
15 32
 
16 33
 *   Synchronize around deleting from the reserved connections hash.
17 34
     Fixes #7955
4  activerecord/lib/active_record/associations/collection_association.rb
@@ -571,7 +571,9 @@ def first_or_last(type, *args)
571 571
           args.shift if args.first.is_a?(Hash) && args.first.empty?
572 572
 
573 573
           collection = fetch_first_or_last_using_find?(args) ? scoped : load_target
574  
-          collection.send(type, *args).tap {|it| set_inverse_instance it }
  574
+          collection.send(type, *args).tap do |record|
  575
+            set_inverse_instance record if record.is_a? ActiveRecord::Base
  576
+          end
575 577
         end
576 578
     end
577 579
   end
2  activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb
@@ -67,7 +67,7 @@ def connection_url_to_hash(url) # :nodoc:
67 67
                    :port     => config.port,
68 68
                    :database => config.path.sub(%r{^/},""),
69 69
                    :host     => config.host }
70  
-          spec.reject!{ |_,value| !value }
  70
+          spec.reject!{ |_,value| value.blank? }
71 71
           spec.map { |key,value| spec[key] = URI.unescape(value) if value.is_a?(String) }
72 72
           if config.query
73 73
             options = Hash[config.query.split("&").map{ |pair| pair.split("=") }].symbolize_keys
15  activerecord/lib/active_record/connection_adapters/column.rb
@@ -75,7 +75,7 @@ def type_cast(value)
75 75
 
76 76
         case type
77 77
         when :string, :text        then value
78  
-        when :integer              then value.to_i
  78
+        when :integer              then klass.value_to_integer(value)
79 79
         when :float                then value.to_f
80 80
         when :decimal              then klass.value_to_decimal(value)
81 81
         when :datetime, :timestamp then klass.string_to_time(value)
@@ -92,7 +92,7 @@ def type_cast_code(var_name)
92 92
 
93 93
         case type
94 94
         when :string, :text        then var_name
95  
-        when :integer              then "(#{var_name}.to_i)"
  95
+        when :integer              then "#{klass}.value_to_integer(#{var_name})"
96 96
         when :float                then "#{var_name}.to_f"
97 97
         when :decimal              then "#{klass}.value_to_decimal(#{var_name})"
98 98
         when :datetime, :timestamp then "#{klass}.string_to_time(#{var_name})"
@@ -168,6 +168,17 @@ def value_to_boolean(value)
168 168
           end
169 169
         end
170 170
 
  171
+        # Used to convert values to integer.
  172
+        # handle the case when an integer column is used to store boolean values
  173
+        def value_to_integer(value)
  174
+          case value
  175
+          when TrueClass, FalseClass
  176
+            value ? 1 : 0
  177
+          else
  178
+            value.to_i
  179
+          end
  180
+        end
  181
+
171 182
         # convert something to a BigDecimal
172 183
         def value_to_decimal(value)
173 184
           # Using .class is faster than .is_a? and
2  activerecord/lib/active_record/persistence.rb
@@ -194,7 +194,7 @@ def update_column(name, value)
194 194
       raise ActiveRecordError, "#{name} is marked as readonly" if self.class.readonly_attributes.include?(name)
195 195
       raise ActiveRecordError, "can not update on a new record object" unless persisted?
196 196
 
197  
-      updated_count = self.class.update_all({ name => value }, self.class.primary_key => id) == 1
  197
+      updated_count = self.class.update_all({ name => value }, self.class.primary_key => id)
198 198
 
199 199
       raw_write_attribute(name, value)
200 200
 
88  activerecord/lib/active_record/railties/databases.rake
@@ -2,6 +2,25 @@ require 'active_support/core_ext/object/inclusion'
2 2
 require 'active_record'
3 3
 
4 4
 db_namespace = namespace :db do
  5
+  def database_url_config
  6
+    @database_url_config ||=
  7
+        ActiveRecord::Base::ConnectionSpecification::Resolver.new(ENV["DATABASE_URL"], {}).spec.config.stringify_keys
  8
+  end
  9
+
  10
+  def current_config(options = {})
  11
+    options = { :env => Rails.env }.merge! options
  12
+
  13
+    if options[:config]
  14
+      @current_config = options[:config]
  15
+    else
  16
+      @current_config ||= if ENV['DATABASE_URL']
  17
+                            database_url_config
  18
+                          else
  19
+                            ActiveRecord::Base.configurations[options[:env]]
  20
+                          end
  21
+    end
  22
+  end
  23
+
5 24
   task :load_config do
6 25
     ActiveRecord::Base.configurations = Rails.application.config.database_configuration
7 26
     ActiveRecord::Migrator.migrations_paths = Rails.application.paths['db/migrate'].to_a
@@ -35,10 +54,14 @@ db_namespace = namespace :db do
35 54
     end
36 55
   end
37 56
 
38  
-  desc 'Create the database from config/database.yml for the current Rails.env (use db:create:all to create all dbs in the config)'
  57
+  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)'
39 58
   task :create => [:load_config, :rails_env] do
40  
-    configs_for_environment.each { |config| create_database(config) }
41  
-    ActiveRecord::Base.establish_connection(configs_for_environment.first)
  59
+    if ENV['DATABASE_URL']
  60
+      create_database(database_url_config)
  61
+    else
  62
+      configs_for_environment.each { |config| create_database(config) }
  63
+      ActiveRecord::Base.establish_connection(configs_for_environment.first)
  64
+    end
42 65
   end
43 66
 
44 67
   def mysql_creation_options(config)
@@ -133,9 +156,13 @@ db_namespace = namespace :db do
133 156
     end
134 157
   end
135 158
 
136  
-  desc 'Drops the database for the current Rails.env (use db:drop:all to drop all databases)'
  159
+  desc 'Drops the database using DATABASE_URL or the current Rails.env (use db:drop:all to drop all databases)'
137 160
   task :drop => [:load_config, :rails_env] do
138  
-    configs_for_environment.each { |config| drop_database_and_rescue(config) }
  161
+    if ENV['DATABASE_URL']
  162
+      drop_database_and_rescue(database_url_config)
  163
+    else
  164
+      configs_for_environment.each { |config| drop_database_and_rescue(config) }
  165
+    end
139 166
   end
140 167
 
141 168
   def local_database?(config, &block)
@@ -146,7 +173,6 @@ db_namespace = namespace :db do
146 173
     end
147 174
   end
148 175
 
149  
-
150 176
   desc "Migrate the database (options: VERSION=x, VERBOSE=false)."
151 177
   task :migrate => [:environment, :load_config] do
152 178
     ActiveRecord::Migration.verbose = ENV["VERBOSE"] ? ENV["VERBOSE"] == "true" : true
@@ -201,8 +227,6 @@ db_namespace = namespace :db do
201 227
 
202 228
     desc 'Display status of migrations'
203 229
     task :status => [:environment, :load_config] do
204  
-      config = ActiveRecord::Base.configurations[Rails.env]
205  
-      ActiveRecord::Base.establish_connection(config)
206 230
       unless ActiveRecord::Base.connection.table_exists?(ActiveRecord::Migrator.schema_migrations_table_name)
207 231
         puts 'Schema migrations table does not exist yet.'
208 232
         next  # means "return" for rake task
@@ -222,7 +246,7 @@ db_namespace = namespace :db do
222 246
         ['up', version, '********** NO FILE **********']
223 247
       end
224 248
       # output
225  
-      puts "\ndatabase: #{config['database']}\n\n"
  249
+      puts "\ndatabase: #{ActiveRecord::Base.connection_config[:database]}\n\n"
226 250
       puts "#{'Status'.center(8)}  #{'Migration ID'.ljust(14)}  Migration Name"
227 251
       puts "-" * 50
228 252
       (db_list + file_list).sort_by {|migration| migration[1]}.each do |migration|
@@ -314,7 +338,6 @@ db_namespace = namespace :db do
314 338
     task :load => [:environment, :load_config] do
315 339
       require 'active_record/fixtures'
316 340
 
317  
-      ActiveRecord::Base.establish_connection(Rails.env)
318 341
       base_dir     = File.join [Rails.root, ENV['FIXTURES_PATH'] || %w{test fixtures}].flatten
319 342
       fixtures_dir = File.join [base_dir, ENV['FIXTURES_DIR']].compact
320 343
 
@@ -353,7 +376,6 @@ db_namespace = namespace :db do
353 376
       require 'active_record/schema_dumper'
354 377
       filename = ENV['SCHEMA'] || "#{Rails.root}/db/schema.rb"
355 378
       File.open(filename, "w:utf-8") do |file|
356  
-        ActiveRecord::Base.establish_connection(Rails.env)
357 379
         ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, file)
358 380
       end
359 381
       db_namespace['schema:dump'].reenable
@@ -377,25 +399,25 @@ db_namespace = namespace :db do
377 399
   namespace :structure do
378 400
     desc 'Dump the database structure to db/structure.sql. Specify another file with DB_STRUCTURE=db/my_structure.sql'
379 401
     task :dump => [:environment, :load_config] do
380  
-      abcs = ActiveRecord::Base.configurations
  402
+      config = current_config
381 403
       filename = ENV['DB_STRUCTURE'] || File.join(Rails.root, "db", "structure.sql")
382  
-      case abcs[Rails.env]['adapter']
  404
+      case config['adapter']
383 405
       when /mysql/, 'oci', 'oracle'
384  
-        ActiveRecord::Base.establish_connection(abcs[Rails.env])
  406
+        ActiveRecord::Base.establish_connection(config)
385 407
         File.open(filename, "w:utf-8") { |f| f << ActiveRecord::Base.connection.structure_dump }
386 408
       when /postgresql/
387  
-        set_psql_env(abcs[Rails.env])
388  
-        search_path = abcs[Rails.env]['schema_search_path']
  409
+        set_psql_env(config)
  410
+        search_path = config['schema_search_path']
389 411
         unless search_path.blank?
390 412
           search_path = search_path.split(",").map{|search_path_part| "--schema=#{Shellwords.escape(search_path_part.strip)}" }.join(" ")
391 413
         end
392  
-        `pg_dump -i -s -x -O -f #{Shellwords.escape(filename)} #{search_path} #{Shellwords.escape(abcs[Rails.env]['database'])}`
  414
+        `pg_dump -i -s -x -O -f #{Shellwords.escape(filename)} #{search_path} #{Shellwords.escape(config['database'])}`
393 415
         raise 'Error dumping database' if $?.exitstatus == 1
394 416
       when /sqlite/
395  
-        dbfile = abcs[Rails.env]['database']
  417
+        dbfile = config['database']
396 418
         `sqlite3 #{dbfile} .schema > #{filename}`
397 419
       when 'sqlserver'
398  
-        `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`
  420
+        `smoscript -s #{config['host']} -d #{config['database']} -u #{config['username']} -p #{config['password']} -f #{filename} -A -U`
399 421
       when "firebird"
400 422
         set_firebird_env(abcs[Rails.env])
401 423
         db_string = firebird_db_string(abcs[Rails.env])
@@ -412,36 +434,34 @@ db_namespace = namespace :db do
412 434
 
413 435
     # desc "Recreate the databases from the structure.sql file"
414 436
     task :load => [:environment, :load_config] do
415  
-      env = Rails.env
416  
-
417  
-      abcs = ActiveRecord::Base.configurations
  437
+      config = current_config
418 438
       filename = ENV['DB_STRUCTURE'] || File.join(Rails.root, "db", "structure.sql")
419  
-      case abcs[env]['adapter']
  439
+      case config['adapter']
420 440
       when /mysql/
421  
-        ActiveRecord::Base.establish_connection(abcs[env])
  441
+        ActiveRecord::Base.establish_connection(config)
422 442
         ActiveRecord::Base.connection.execute('SET foreign_key_checks = 0')
423 443
         IO.read(filename).split("\n\n").each do |table|
424 444
           ActiveRecord::Base.connection.execute(table)
425 445
         end
426 446
       when /postgresql/
427  
-        set_psql_env(abcs[env])
428  
-        `psql -f "#{filename}" #{abcs[env]['database']}`
  447
+        set_psql_env(config)
  448
+        `psql -f "#{filename}" #{config['database']}`
429 449
       when /sqlite/
430  
-        dbfile = abcs[env]['database']
  450
+        dbfile = config['database']
431 451
         `sqlite3 #{dbfile} < "#{filename}"`
432 452
       when 'sqlserver'
433  
-        `sqlcmd -S #{abcs[env]['host']} -d #{abcs[env]['database']} -U #{abcs[env]['username']} -P #{abcs[env]['password']} -i #{filename}`
  453
+        `sqlcmd -S #{config['host']} -d #{config['database']} -U #{config['username']} -P #{config['password']} -i #{filename}`
434 454
       when 'oci', 'oracle'
435  
-        ActiveRecord::Base.establish_connection(abcs[env])
  455
+        ActiveRecord::Base.establish_connection(config)
436 456
         IO.read(filename).split(";\n\n").each do |ddl|
437 457
           ActiveRecord::Base.connection.execute(ddl)
438 458
         end
439 459
       when 'firebird'
440  
-        set_firebird_env(abcs[env])
441  
-        db_string = firebird_db_string(abcs[env])
  460
+        set_firebird_env(config)
  461
+        db_string = firebird_db_string(config)
442 462
         sh "isql -i #{filename} #{db_string}"
443 463
       else
444  
-        raise "Task not supported by '#{abcs[env]['adapter']}'"
  464
+        raise "Task not supported by '#{config['adapter']}'"
445 465
       end
446 466
     end
447 467
 
@@ -465,10 +485,10 @@ db_namespace = namespace :db do
465 485
     # desc "Recreate the test database from an existent structure.sql file"
466 486
     task :load_structure => 'db:test:purge' do
467 487
       begin
468  
-        old_env, ENV['RAILS_ENV'] = ENV['RAILS_ENV'], 'test'
  488
+        current_config(:config => ActiveRecord::Base.configurations['test'])
469 489
         db_namespace["structure:load"].invoke
470 490
       ensure
471  
-        ENV['RAILS_ENV'] = old_env
  491
+        current_config(:config => nil)
472 492
       end
473 493
     end
474 494
 
2  activerecord/lib/active_record/version.rb
@@ -3,7 +3,7 @@ module VERSION #:nodoc:
3 3
     MAJOR = 3
4 4
     MINOR = 2
5 5
     TINY  = 9
6  
-    PRE   = "rc1"
  6
+    PRE   = "rc2"
7 7
 
8 8
     STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
9 9
   end
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
261 261
 
262 262
   def test_parent_instance_should_be_shared_with_first_and_last_child
263 263
     man = Man.first
  264
+
264 265
     assert man.interests.first.man.equal? man
265 266
     assert man.interests.last.man.equal? man
266 267
   end
267 268
 
  269
+  def test_parent_instance_should_be_shared_with_first_and_last_child_when_given_options
  270
+    man = Man.first
  271
+
  272
+    assert man.interests.first(:order => 'topic').man.equal? man
  273
+    assert man.interests.last(:order => 'topic').man.equal? man
  274
+  end
  275
+
  276
+  def test_parent_instance_should_be_shared_with_first_n_and_last_n_children
  277
+    man = Man.first
  278
+
  279
+    interests = man.interests.first(2)
  280
+    assert interests[0].man.equal? man
  281
+    assert interests[1].man.equal? man
  282
+
  283
+    interests = man.interests.last(2)
  284
+    assert interests[0].man.equal? man
  285
+    assert interests[1].man.equal? man
  286
+  end
  287
+
268 288
   def test_trying_to_use_inverses_that_dont_exist_should_raise_an_error
269 289
     assert_raise(ActiveRecord::InverseOfAssociationNotFoundError) { Man.find(:first).secret_interests }
270 290
   end
8  activerecord/test/cases/column_test.rb
@@ -33,6 +33,8 @@ def test_type_cast_integer
33 33
         assert_equal 0, column.type_cast('bad1')
34 34
         assert_equal 0, column.type_cast('bad')
35 35
         assert_equal 1, column.type_cast(1.7)
  36
+        assert_equal 0, column.type_cast(false)
  37
+        assert_equal 1, column.type_cast(true)
36 38
         assert_nil column.type_cast(nil)
37 39
       end
38 40
 
@@ -41,11 +43,9 @@ def test_type_cast_non_integer_to_integer
41 43
         assert_raises(NoMethodError) do
42 44
           column.type_cast([])
43 45
         end
  46
+
44 47
         assert_raises(NoMethodError) do
45  
-          column.type_cast(true)
46  
-        end
47  
-        assert_raises(NoMethodError) do
48  
-          column.type_cast(false)
  48
+          column.type_cast(Object.new)
49 49
         end
50 50
       end
51 51
     end
2  activerecord/test/cases/connection_specification/resolver_test.rb
@@ -13,7 +13,6 @@ def test_url_host_no_db
13 13
           spec = resolve 'mysql://foo?encoding=utf8'
14 14
           assert_equal({
15 15
             :adapter  => "mysql",
16  
-            :database => "",
17 16
             :host     => "foo",
18 17
             :encoding => "utf8" }, spec)
19 18
         end
@@ -33,7 +32,6 @@ def test_url_port
33 32
           spec = resolve 'mysql://foo:123?encoding=utf8'
34 33
           assert_equal({
35 34
             :adapter  => "mysql",
36  
-            :database => "",
37 35
             :port     => 123,
38 36
             :host     => "foo",
39 37
             :encoding => "utf8" }, spec)
6  activerecord/test/cases/persistence_test.rb
@@ -513,6 +513,12 @@ def test_update_column_changing_id
513 513
     assert_equal 123, topic.id
514 514
   end
515 515
 
  516
+  def test_update_column_should_return_correct_value
  517
+    developer = Developer.find(1)
  518
+    return_value = developer.update_column(:salary, 80001)
  519
+    assert return_value
  520
+  end
  521
+
516 522
   def test_update_attributes
517 523
     topic = Topic.find(1)
518 524
     assert !topic.approved?
2  activeresource/lib/active_resource/version.rb
@@ -3,7 +3,7 @@ module VERSION #:nodoc:
3 3
     MAJOR = 3
4 4
     MINOR = 2
5 5
     TINY  = 9
6  
-    PRE   = "rc1"
  6
+    PRE   = "rc2"
7 7
 
8 8
     STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
9 9
   end
2  activesupport/lib/active_support/version.rb
@@ -3,7 +3,7 @@ module VERSION #:nodoc:
3 3
     MAJOR = 3
4 4
     MINOR = 2
5 5
     TINY  = 9
6  
-    PRE   = "rc1"
  6
+    PRE   = "rc2"
7 7
 
8 8
     STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
9 9
   end
2  railties/lib/rails/version.rb
@@ -3,7 +3,7 @@ module VERSION #:nodoc:
3 3
     MAJOR = 3
4 4
     MINOR = 2
5 5
     TINY  = 9
6  
-    PRE   = "rc1"
  6
+    PRE   = "rc2"
7 7
 
8 8
     STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
9 9
   end
36  railties/test/application/initializers/frameworks_test.rb
@@ -193,5 +193,41 @@ def from_bar_helper
193 193
       require "#{app_path}/config/environment"
194 194
       assert_nil defined?(ActiveRecord::Base)
195 195
     end
  196
+
  197
+    test "active record establish_connection uses Rails.env if DATABASE_URL is not set" do
  198
+      begin
  199
+        require "#{app_path}/config/environment"
  200
+        orig_database_url = ENV.delete("DATABASE_URL")
  201
+        orig_rails_env, Rails.env = Rails.env, 'development'
  202
+
  203
+        ActiveRecord::Base.establish_connection
  204
+
  205
+        assert ActiveRecord::Base.connection
  206
+        assert_match /#{ActiveRecord::Base.configurations[Rails.env]['database']}/, ActiveRecord::Base.connection_config[:database]
  207
+      ensure
  208
+        ActiveRecord::Base.remove_connection
  209
+        ENV["DATABASE_URL"] = orig_database_url if orig_database_url
  210
+        Rails.env = orig_rails_env if orig_rails_env
  211
+      end
  212
+    end
  213
+
  214
+    test "active record establish_connection uses DATABASE_URL even if Rails.env is set" do
  215
+      begin
  216
+        require "#{app_path}/config/environment"
  217
+        orig_database_url = ENV.delete("DATABASE_URL")
  218
+        orig_rails_env, Rails.env = Rails.env, 'development'
  219
+        database_url_db_name = "db/database_url_db.sqlite3"
  220
+        ENV["DATABASE_URL"] = "sqlite3://:@localhost/#{database_url_db_name}"
  221
+
  222
+        ActiveRecord::Base.establish_connection
  223
+
  224
+        assert ActiveRecord::Base.connection
  225
+        assert_match /#{database_url_db_name}/, ActiveRecord::Base.connection_config[:database]
  226
+      ensure
  227
+        ActiveRecord::Base.remove_connection
  228
+        ENV["DATABASE_URL"] = orig_database_url if orig_database_url
  229
+        Rails.env = orig_rails_env if orig_rails_env
  230
+      end
  231
+    end
196 232
   end
197 233
 end
194  railties/test/application/rake/dbs_test.rb
... ...
@@ -0,0 +1,194 @@
  1
+require "isolation/abstract_unit"
  2
+
  3
+module ApplicationTests
  4
+  module RakeTests
  5
+    class RakeDbsTest < Test::Unit::TestCase
  6
+      include ActiveSupport::Testing::Isolation
  7
+
  8
+      def setup
  9
+        build_app
  10
+        boot_rails
  11
+        FileUtils.rm_rf("#{app_path}/config/environments")
  12
+      end
  13
+
  14
+      def teardown
  15
+        teardown_app
  16
+      end
  17
+
  18
+      def database_url_db_name
  19
+        "db/database_url_db.sqlite3"
  20
+      end
  21
+
  22
+      def set_database_url
  23
+        ENV['DATABASE_URL'] = "sqlite3://:@localhost/#{database_url_db_name}"
  24
+      end
  25
+
  26
+      def expected
  27
+        @expected ||= {}
  28
+      end
  29
+
  30
+      def db_create_and_drop
  31
+        Dir.chdir(app_path) do
  32
+          output = `bundle exec rake db:create`
  33
+          assert_equal output, ""
  34
+          assert File.exists?(expected[:database])
  35
+          assert_equal expected[:database],
  36
+                        ActiveRecord::Base.connection_config[:database]
  37
+          output = `bundle exec rake db:drop`
  38
+          assert_equal output, ""
  39
+          assert !File.exists?(expected[:database])
  40
+        end
  41
+      end
  42
+
  43
+      test 'db:create and db:drop without database url' do
  44
+        require "#{app_path}/config/environment"
  45
+        expected[:database] = ActiveRecord::Base.configurations[Rails.env]['database']
  46
+        db_create_and_drop
  47
+      end
  48
+
  49
+      test 'db:create and db:drop with database url' do
  50
+        require "#{app_path}/config/environment"
  51
+        set_database_url
  52
+        expected[:database] = database_url_db_name
  53
+        db_create_and_drop
  54
+      end
  55
+
  56
+      def db_migrate_and_status
  57
+        Dir.chdir(app_path) do
  58
+          `rails generate model book title:string`
  59
+          `bundle exec rake db:migrate`
  60
+          output = `bundle exec rake db:migrate:status`
  61
+          assert_match(/database:\s+\S*#{expected[:database]}/, output)
  62
+          assert_match(/up\s+\d{14}\s+Create books/, output)
  63
+        end
  64
+      end
  65
+
  66
+      test 'db:migrate and db:migrate:status without database_url' do
  67
+        require "#{app_path}/config/environment"
  68
+        expected[:database] = ActiveRecord::Base.configurations[Rails.env]['database']
  69
+        db_migrate_and_status
  70
+      end
  71
+
  72
+      test 'db:migrate and db:migrate:status with database_url' do
  73
+        require "#{app_path}/config/environment"
  74
+        set_database_url
  75
+        expected[:database] = database_url_db_name
  76
+        db_migrate_and_status
  77
+      end
  78
+
  79
+      def db_schema_dump
  80
+        Dir.chdir(app_path) do
  81
+          `rails generate model book title:string`
  82
+          `rake db:migrate`
  83
+          `rake db:schema:dump`
  84
+
  85
+          assert File.exists?("db/schema.rb"), "db/schema.rb doesn't exist"
  86
+
  87
+          schema_dump = File.read("db/schema.rb")
  88
+
  89
+          assert_match(/create_table \"books\"/, schema_dump)
  90
+        end
  91
+      end
  92
+
  93
+      test 'db:schema:dump without database_url' do
  94
+        db_schema_dump
  95
+      end
  96
+
  97
+      test 'db:schema:dump with database_url' do
  98
+        set_database_url
  99
+        db_schema_dump
  100
+      end
  101
+
  102
+      def db_fixtures_load
  103
+        Dir.chdir(app_path) do
  104
+          `rails generate model book title:string`
  105
+          `bundle exec rake db:migrate`
  106
+          `bundle exec rake db:fixtures:load`
  107
+          assert_match /#{expected[:database]}/,
  108
+                    ActiveRecord::Base.connection_config[:database]
  109
+          require "#{app_path}/app/models/book"
  110
+          assert_equal 2, Book.count
  111
+        end
  112
+      end
  113
+
  114
+      test 'db:fixtures:load without database_url' do
  115
+        require "#{app_path}/config/environment"
  116
+        expected[:database] =  ActiveRecord::Base.configurations[Rails.env]['database']
  117
+        db_fixtures_load
  118
+      end
  119
+
  120
+      test 'db:fixtures:load with database_url' do
  121
+        require "#{app_path}/config/environment"
  122
+        set_database_url
  123
+        expected[:database] = database_url_db_name
  124
+        db_fixtures_load
  125
+      end
  126
+
  127
+      def db_structure_dump_and_load
  128
+        Dir.chdir(app_path) do
  129
+          `rails generate model book title:string`
  130
+          `bundle exec rake db:create`
  131
+          `bundle exec rake db:migrate`
  132
+          `bundle exec rake db:structure:dump`
  133
+
  134
+          assert File.exists?("db/structure.sql"), "db/structure.sql doesn't exist"
  135
+
  136
+          structure_dump = File.read("db/structure.sql")
  137
+
  138
+          assert_match /CREATE TABLE \"books\"/, structure_dump
  139
+
  140
+          `bundle exec rake db:drop`
  141
+          `bundle exec rake db:structure:load`
  142
+
  143
+          assert_match /#{expected[:database]}/,
  144
+                       ActiveRecord::Base.connection_config[:database]
  145
+
  146
+          require "#{app_path}/app/models/book"
  147
+          #if structure is not loaded correctly, exception would be raised
  148
+          assert_equal Book.count, 0
  149
+        end
  150
+      end
  151
+
  152
+      test 'db:structure:dump and db:structure:load without database_url' do
  153
+        require "#{app_path}/config/environment"
  154
+        expected[:database] = ActiveRecord::Base.configurations[Rails.env]['database']
  155
+        db_structure_dump_and_load
  156
+      end
  157
+
  158
+      test 'db:structure:dump and db:structure:load with database_url' do
  159
+        require "#{app_path}/config/environment"
  160
+        set_database_url
  161
+        expected[:database] = database_url_db_name
  162
+        db_structure_dump_and_load
  163
+      end
  164
+
  165
+      def db_test_load_structure
  166
+        Dir.chdir(app_path) do
  167
+          `rails generate model book title:string`
  168
+          `bundle exec rake db:migrate`
  169
+          `bundle exec rake db:structure:dump`
  170
+          `bundle exec rake db:test:load_structure`
  171
+          ActiveRecord::Base.configurations = Rails.application.config.database_configuration
  172
+          ActiveRecord::Base.establish_connection 'test'
  173
+          require "#{app_path}/app/models/book"
  174
+
  175
+          #if structure is not loaded correctly, exception would be raised
  176
+          assert_equal Book.count, 0
  177
+          assert_match /#{ActiveRecord::Base.configurations['test']['database']}/,
  178
+                       ActiveRecord::Base.connection_config[:database]
  179
+        end
  180
+      end
  181
+
  182
+      test 'db:test:load_structure without database_url' do
  183
+        require "#{app_path}/config/environment"
  184
+        db_test_load_structure
  185
+      end
  186
+
  187
+      test 'db:test:load_structure with database_url' do
  188
+        require "#{app_path}/config/environment"
  189
+        set_database_url
  190
+        db_test_load_structure
  191
+      end
  192
+    end
  193
+  end
  194
+end
2  version.rb
@@ -3,7 +3,7 @@ module VERSION #:nodoc:
3 3
     MAJOR = 3
4 4
     MINOR = 2
5 5
     TINY  = 9
6  
-    PRE   = "rc1"
  6
+    PRE   = "rc2"
7 7
 
8 8
     STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
9 9
   end

Showing you all comments on commits in this comparison.

Francesco Rodríguez
Collaborator

typo => boolean

Rafael Mendonça França

:bomb:. I'll fix in a second

Francesco Rodríguez
Collaborator

:+1: powered by RafaLint™

Rafael Mendonça França

lol. My lint algorithm is getting slower

Something went wrong with that request. Please try again.