diff options
210 files changed, 736 insertions, 776 deletions
diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG index 48b3e5bfff..6172fa4e07 100644 --- a/actionpack/CHANGELOG +++ b/actionpack/CHANGELOG @@ -1,5 +1,23 @@ *Rails 3.1.0 (unreleased)* +* Refactor ActionController::TestCase cookies [Andrew White] + + Assigning cookies for test cases should now use cookies[], e.g: + + cookies[:email] = 'user@example.com' + get :index + assert_equal 'user@example.com', cookies[:email] + + To clear the cookies, use clear, e.g: + + cookies.clear + get :index + assert_nil cookies[:email] + + We now no longer write out HTTP_COOKIE and the cookie jar is + persistent between requests so if you need to manipulate the environment + for your test you need to do it before the cookie jar is created. + * Added 'ActionView::Helpers::FormHelper.fields_for_with_index', similar to fields_for but allows to have access to the current iteration index [Jorge Bejar] * Warn if we cannot verify CSRF token authenticity [José Valim] diff --git a/actionpack/lib/action_controller/test_case.rb b/actionpack/lib/action_controller/test_case.rb index bfb820fcdf..6d85846eb3 100644 --- a/actionpack/lib/action_controller/test_case.rb +++ b/actionpack/lib/action_controller/test_case.rb @@ -175,10 +175,6 @@ module ActionController end def recycle! - write_cookies! - @env.delete('HTTP_COOKIE') if @cookies.blank? - @env.delete('action_dispatch.cookies') - @cookies = nil @formats = nil @env.delete_if { |k, v| k =~ /^(action_dispatch|rack)\.request/ } @env.delete_if { |k, v| k =~ /^action_dispatch\.rescue/ } @@ -186,6 +182,7 @@ module ActionController @method = @request_method = nil @fullpath = @ip = @remote_ip = nil @env['action_dispatch.request.query_parameters'] = {} + cookie_jar.reset! end end @@ -301,18 +298,17 @@ module ActionController # For redirects within the same controller, you can even call follow_redirect and the redirect will be followed, triggering another # action call which can then be asserted against. # - # == Manipulating the request collections + # == Manipulating session and cookie variables # - # The collections described above link to the response, so you can test if what the actions were expected to do happened. But - # sometimes you also want to manipulate these collections in the incoming request. This is really only relevant for sessions - # and cookies, though. For sessions, you just do: + # Sometimes you need to set up the session and cookie variables for a test. + # To do this just assign a value to the session or cookie collection: # - # @request.session[:key] = "value" - # @request.cookies[:key] = "value" + # session[:key] = "value" + # cookies[:key] = "value" # - # To clear the cookies for a test just clear the request's cookies hash: + # To clear the cookies for a test just clear the cookie collection: # - # @request.cookies.clear + # cookies.clear # # == \Testing named routes # @@ -450,7 +446,6 @@ module ActionController @controller.process_with_new_base_test(@request, @response) @assigns = @controller.respond_to?(:view_assigns) ? @controller.view_assigns : {} @request.session.delete('flash') if @request.session['flash'].blank? - @request.cookies.merge!(@response.cookies) @response end diff --git a/actionpack/lib/action_dispatch/middleware/cookies.rb b/actionpack/lib/action_dispatch/middleware/cookies.rb index 47c4bad489..c4a83fc8cb 100644 --- a/actionpack/lib/action_dispatch/middleware/cookies.rb +++ b/actionpack/lib/action_dispatch/middleware/cookies.rb @@ -185,6 +185,11 @@ module ActionDispatch value end + # Removes all cookies on the client machine by calling <tt>delete</tt> for each cookie + def clear(options = {}) + @cookies.each_key{ |k| delete(k, options) } + end + # Returns a jar that'll automatically set the assigned cookies to have an expiration date 20 years from now. Example: # # cookies.permanent[:prefers_open_id] = true @@ -222,6 +227,11 @@ module ActionDispatch @delete_cookies.each { |k, v| ::Rack::Utils.delete_cookie_header!(headers, k, v) } end + def reset! #:nodoc: + @set_cookies.clear + @delete_cookies.clear + end + private def write_cookie?(cookie) diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index 3999bd0a5e..ec76d1da1e 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -1423,7 +1423,9 @@ module ActionDispatch end def action_path(name, path = nil) #:nodoc: - path || @scope[:path_names][name.to_sym] || name.to_s + # Ruby 1.8 can't transform empty strings to symbols + name = name.to_sym if name.is_a?(String) && !name.empty? + path || @scope[:path_names][name] || name.to_s end def prefix_name_for_action(as, action) #:nodoc: diff --git a/actionpack/lib/action_dispatch/testing/test_process.rb b/actionpack/lib/action_dispatch/testing/test_process.rb index 397bda41d5..367c295cf5 100644 --- a/actionpack/lib/action_dispatch/testing/test_process.rb +++ b/actionpack/lib/action_dispatch/testing/test_process.rb @@ -1,3 +1,4 @@ +require 'action_dispatch/middleware/cookies' require 'action_dispatch/middleware/flash' require 'active_support/core_ext/hash/indifferent_access' @@ -22,7 +23,7 @@ module ActionDispatch end def cookies - @request.cookies.merge(@response.cookies).with_indifferent_access + @request.cookie_jar end def redirect_to_url diff --git a/actionpack/lib/action_dispatch/testing/test_request.rb b/actionpack/lib/action_dispatch/testing/test_request.rb index 822adb6a47..5c16023137 100644 --- a/actionpack/lib/action_dispatch/testing/test_request.rb +++ b/actionpack/lib/action_dispatch/testing/test_request.rb @@ -20,12 +20,6 @@ module ActionDispatch self.user_agent = 'Rails Testing' end - def env - write_cookies! - delete_nil_values! - super - end - def request_method=(method) @env['REQUEST_METHOD'] = method.to_s.upcase end @@ -70,24 +64,5 @@ module ActionDispatch @env.delete('action_dispatch.request.accepts') @env['HTTP_ACCEPT'] = Array(mime_types).collect { |mime_type| mime_type.to_s }.join(",") end - - def cookies - @cookies ||= super - end - - private - def write_cookies! - unless @cookies.blank? - @env['HTTP_COOKIE'] = @cookies.map { |name, value| escape_cookie(name, value) }.join('; ') - end - end - - def escape_cookie(name, value) - "#{Rack::Utils.escape(name)}=#{Rack::Utils.escape(value)}" - end - - def delete_nil_values! - @env.delete_if { |k, v| v.nil? } - end end end diff --git a/actionpack/lib/action_view/helpers/controller_helper.rb b/actionpack/lib/action_view/helpers/controller_helper.rb index e22331cb3c..db59bca159 100644 --- a/actionpack/lib/action_view/helpers/controller_helper.rb +++ b/actionpack/lib/action_view/helpers/controller_helper.rb @@ -1,3 +1,5 @@ +require 'active_support/core_ext/module/attr_internal' + module ActionView module Helpers # This module keeps all methods and behavior in ActionView diff --git a/actionpack/lib/sprockets/helpers/rails_helper.rb b/actionpack/lib/sprockets/helpers/rails_helper.rb index a99dcad81d..dcf4b9279e 100644 --- a/actionpack/lib/sprockets/helpers/rails_helper.rb +++ b/actionpack/lib/sprockets/helpers/rails_helper.rb @@ -15,42 +15,48 @@ module Sprockets end end - def javascript_include_tag(source, options = {}) + def javascript_include_tag(*sources) + options = sources.extract_options! debug = options.key?(:debug) ? options.delete(:debug) : debug_assets? body = options.key?(:body) ? options.delete(:body) : false - if debug && asset = asset_paths.asset_for(source, 'js') - asset.to_a.map { |dep| - javascript_include_tag(dep, :debug => false, :body => true) - }.join("\n").html_safe - else - options = { - 'type' => "text/javascript", - 'src' => asset_path(source, 'js', body) - }.merge(options.stringify_keys) - - content_tag 'script', "", options - end + sources.collect do |source| + if debug && asset = asset_paths.asset_for(source, 'js') + asset.to_a.map { |dep| + javascript_include_tag(dep, :debug => false, :body => true) + }.join("\n").html_safe + else + tag_options = { + 'type' => "text/javascript", + 'src' => asset_path(source, 'js', body) + }.merge(options.stringify_keys) + + content_tag 'script', "", tag_options + end + end.join("\n").html_safe end - def stylesheet_link_tag(source, options = {}) + def stylesheet_link_tag(*sources) + options = sources.extract_options! debug = options.key?(:debug) ? options.delete(:debug) : debug_assets? body = options.key?(:body) ? options.delete(:body) : false - if debug && asset = asset_paths.asset_for(source, 'css') - asset.to_a.map { |dep| - stylesheet_link_tag(dep, :debug => false, :body => true) - }.join("\n").html_safe - else - options = { - 'rel' => "stylesheet", - 'type' => "text/css", - 'media' => "screen", - 'href' => asset_path(source, 'css', body) - }.merge(options.stringify_keys) - - tag 'link', options - end + sources.collect do |source| + if debug && asset = asset_paths.asset_for(source, 'css') + asset.to_a.map { |dep| + stylesheet_link_tag(dep, :debug => false, :body => true) + }.join("\n").html_safe + else + tag_options = { + 'rel' => "stylesheet", + 'type' => "text/css", + 'media' => "screen", + 'href' => asset_path(source, 'css', body) + }.merge(options.stringify_keys) + + tag 'link', tag_options + end + end.join("\n").html_safe end private diff --git a/actionpack/test/controller/integration_test.rb b/actionpack/test/controller/integration_test.rb index 01dc2f2091..23709e44e2 100644 --- a/actionpack/test/controller/integration_test.rb +++ b/actionpack/test/controller/integration_test.rb @@ -492,6 +492,8 @@ class ApplicationIntegrationTest < ActionDispatch::IntegrationTest end routes.draw do + match '', :to => 'application_integration_test/test#index', :as => :empty_string + match 'foo', :to => 'application_integration_test/test#index', :as => :foo match 'bar', :to => 'application_integration_test/test#index', :as => :bar end @@ -501,11 +503,15 @@ class ApplicationIntegrationTest < ActionDispatch::IntegrationTest end test "includes route helpers" do + assert_equal '/', empty_string_path assert_equal '/foo', foo_path assert_equal '/bar', bar_path end test "route helpers after controller access" do + get '/' + assert_equal '/', empty_string_path + get '/foo' assert_equal '/foo', foo_path diff --git a/actionpack/test/controller/test_test.rb b/actionpack/test/controller/test_test.rb index 899435ff38..f48b73b63a 100644 --- a/actionpack/test/controller/test_test.rb +++ b/actionpack/test/controller/test_test.rb @@ -593,13 +593,13 @@ XML end def test_should_have_knowledge_of_client_side_cookie_state_even_if_they_are_not_set - @request.cookies['foo'] = 'bar' + cookies['foo'] = 'bar' get :no_op assert_equal 'bar', cookies['foo'] end def test_should_detect_if_cookie_is_deleted - @request.cookies['foo'] = 'bar' + cookies['foo'] = 'bar' get :delete_cookie assert_nil cookies['foo'] end diff --git a/actionpack/test/dispatch/cookies_test.rb b/actionpack/test/dispatch/cookies_test.rb index e42c39f527..c975c4f7ba 100644 --- a/actionpack/test/dispatch/cookies_test.rb +++ b/actionpack/test/dispatch/cookies_test.rb @@ -430,54 +430,48 @@ class CookiesTest < ActionController::TestCase def test_setting_request_cookies_is_indifferent_access - @request.cookies.clear - @request.cookies[:user_name] = "andrew" + cookies.clear + cookies[:user_name] = "andrew" get :string_key_mock - assert_equal "david", cookies[:user_name] + assert_equal "david", cookies['user_name'] - @request.cookies.clear - @request.cookies['user_name'] = "andrew" + cookies.clear + cookies['user_name'] = "andrew" get :symbol_key_mock - assert_equal "david", cookies['user_name'] + assert_equal "david", cookies[:user_name] end def test_cookies_retained_across_requests get :symbol_key - assert_equal "user_name=david; path=/", @response.headers["Set-Cookie"] + assert_cookie_header "user_name=david; path=/" assert_equal "david", cookies[:user_name] get :noop assert_nil @response.headers["Set-Cookie"] - assert_equal "user_name=david", @request.env['HTTP_COOKIE'] assert_equal "david", cookies[:user_name] get :noop assert_nil @response.headers["Set-Cookie"] - assert_equal "user_name=david", @request.env['HTTP_COOKIE'] assert_equal "david", cookies[:user_name] end def test_cookies_can_be_cleared get :symbol_key - assert_equal "user_name=david; path=/", @response.headers["Set-Cookie"] assert_equal "david", cookies[:user_name] - @request.cookies.clear + cookies.clear get :noop - assert_nil @response.headers["Set-Cookie"] - assert_nil @request.env['HTTP_COOKIE'] assert_nil cookies[:user_name] get :symbol_key - assert_equal "user_name=david; path=/", @response.headers["Set-Cookie"] assert_equal "david", cookies[:user_name] end - def test_cookies_are_escaped - @request.cookies[:user_ids] = '1;2' + def test_can_set_http_cookie_header + @request.env['HTTP_COOKIE'] = "user_name=david" get :noop - assert_equal "user_ids=1%3B2", @request.env['HTTP_COOKIE'] - assert_equal "1;2", cookies[:user_ids] + assert_equal 'david', cookies['user_name'] + assert_equal 'david', cookies[:user_name] end private diff --git a/actionpack/test/dispatch/test_request_test.rb b/actionpack/test/dispatch/test_request_test.rb index 81a8c24525..c520fb59ec 100644 --- a/actionpack/test/dispatch/test_request_test.rb +++ b/actionpack/test/dispatch/test_request_test.rb @@ -34,12 +34,15 @@ class TestRequestTest < ActiveSupport::TestCase assert_equal({}, req.cookies) assert_equal nil, req.env["HTTP_COOKIE"] - req.cookies["user_name"] = "david" - assert_equal({"user_name" => "david"}, req.cookies) - assert_equal "user_name=david", req.env["HTTP_COOKIE"] + req.cookie_jar["user_name"] = "david" + assert_cookies({"user_name" => "david"}, req.cookie_jar) - req.cookies["login"] = "XJ-122" - assert_equal({"user_name" => "david", "login" => "XJ-122"}, req.cookies) - assert_equal %w(login=XJ-122 user_name=david), req.env["HTTP_COOKIE"].split(/; /).sort + req.cookie_jar["login"] = "XJ-122" + assert_cookies({"user_name" => "david", "login" => "XJ-122"}, req.cookie_jar) end + + private + def assert_cookies(expected, cookie_jar) + assert_equal(expected, cookie_jar.instance_variable_get("@cookies")) + end end diff --git a/actionpack/test/fixtures/sprockets/app/javascripts/extra.js b/actionpack/test/fixtures/sprockets/app/javascripts/extra.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/actionpack/test/fixtures/sprockets/app/javascripts/extra.js diff --git a/actionpack/test/fixtures/sprockets/app/stylesheets/extra.css b/actionpack/test/fixtures/sprockets/app/stylesheets/extra.css new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/actionpack/test/fixtures/sprockets/app/stylesheets/extra.css diff --git a/actionpack/test/template/sprockets_helper_test.rb b/actionpack/test/template/sprockets_helper_test.rb index ebb7e48d70..b1317d0a35 100644 --- a/actionpack/test/template/sprockets_helper_test.rb +++ b/actionpack/test/template/sprockets_helper_test.rb @@ -94,6 +94,9 @@ class SprocketsHelperTest < ActionView::TestCase assert_equal "<script src=\"/assets/xmlhr-d41d8cd98f00b204e9800998ecf8427e.js?body=1\" type=\"text/javascript\"></script>\n<script src=\"/assets/application-d41d8cd98f00b204e9800998ecf8427e.js?body=1\" type=\"text/javascript\"></script>", javascript_include_tag(:application, :debug => true) + + assert_equal "<script src=\"/assets/xmlhr-d41d8cd98f00b204e9800998ecf8427e.js\" type=\"text/javascript\"></script>\n<script src=\"/assets/extra-d41d8cd98f00b204e9800998ecf8427e.js\" type=\"text/javascript\"></script>", + javascript_include_tag("xmlhr", "extra") end test "stylesheet path" do @@ -127,5 +130,8 @@ class SprocketsHelperTest < ActionView::TestCase assert_equal "<link href=\"/assets/style-d41d8cd98f00b204e9800998ecf8427e.css?body=1\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />\n<link href=\"/assets/application-68b329da9893e34099c7d8ad5cb9c940.css?body=1\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />", stylesheet_link_tag(:application, :debug => true) + + assert_equal "<link href=\"/assets/style-d41d8cd98f00b204e9800998ecf8427e.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />\n<link href=\"/assets/extra-d41d8cd98f00b204e9800998ecf8427e.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />", + stylesheet_link_tag("style", "extra") end end diff --git a/activemodel/lib/active_model/mass_assignment_security.rb b/activemodel/lib/active_model/mass_assignment_security.rb index c97420bc03..a7b4706906 100644 --- a/activemodel/lib/active_model/mass_assignment_security.rb +++ b/activemodel/lib/active_model/mass_assignment_security.rb @@ -1,4 +1,5 @@ -require 'active_support/core_ext/class/attribute.rb' +require 'active_support/core_ext/class/attribute' +require 'active_support/core_ext/string/inflections' require 'active_model/mass_assignment_security/permission_set' require 'active_model/mass_assignment_security/sanitizer' diff --git a/activemodel/lib/active_model/validations/exclusion.rb b/activemodel/lib/active_model/validations/exclusion.rb index ab4de3c459..d3b8d31502 100644 --- a/activemodel/lib/active_model/validations/exclusion.rb +++ b/activemodel/lib/active_model/validations/exclusion.rb @@ -1,4 +1,4 @@ -require 'active_support/core_ext/range.rb' +require 'active_support/core_ext/range' module ActiveModel diff --git a/activemodel/lib/active_model/validations/inclusion.rb b/activemodel/lib/active_model/validations/inclusion.rb index bfb65d2f3f..9a9270d615 100644 --- a/activemodel/lib/active_model/validations/inclusion.rb +++ b/activemodel/lib/active_model/validations/inclusion.rb @@ -1,4 +1,4 @@ -require 'active_support/core_ext/range.rb' +require 'active_support/core_ext/range' module ActiveModel diff --git a/activerecord/RUNNING_UNIT_TESTS b/activerecord/RUNNING_UNIT_TESTS index b3d376772e..bc4faa488c 100644 --- a/activerecord/RUNNING_UNIT_TESTS +++ b/activerecord/RUNNING_UNIT_TESTS @@ -1,43 +1,25 @@ -== Creating the test database +== Configure databases -The default names for the test databases are "activerecord_unittest" and -"activerecord_unittest2". If you want to use another database name, then be sure -to update the connection adapter setups you want to test within -test/connections/<your database>/connection.rb. -When you have the database online, you can import the fixture tables with -the test/schema/*.sql files. +Copy test/config.example.yml to test/config.yml and edit as needed. Or just run the tests for +the first time, which will do the copy automatically and use the default (sqlite3). -Make sure that you create database objects with the same user that you specified in -connection.rb otherwise (on Postgres, at least) tests for default values will fail. +You can build postgres and mysql databases using the build_postgresql and build_mysql rake tasks. -== Running with Rake +== Running the tests -The easiest way to run the unit tests is through Rake. The default task runs -the entire test suite for all the adapters. You can also run the suite on just -one adapter by using the tasks test_mysql, test_sqlite3, test_postgresql or any -of the other test_ tasks. For more information, checkout the full array of rake -tasks with "rake -T" +You can run a particular test file from the command line, e.g. -Rake can be found at http://rake.rubyforge.org + $ ruby test/cases/base_test.rb -== Running by hand +To run a specific test: -Unit tests are located in test/cases directory. If you only want to run a single test suite, -you can do so with: + $ ruby test/cases/base_test.rb -n test_something_works - rake test_mysql TEST=test/cases/base_test.rb +You can run with a database other than the default you set in test/config.yml, using the ARCONN +environment variable: -That'll run the base suite using the MySQL-Ruby adapter. Some tests rely on the schema -being initialized - you can initialize the schema with: + $ ARCONN=postgresql ruby test/cases/base_test.rb - rake test_mysql TEST=test/cases/aaa_create_tables_test.rb - rake mysql:build_databases - -To setup the testing environment for PostgreSQL use this command: - - rake postgresql:build_databases - -The incantation for running a particular test looks like this - - rake test TEST=test/cases/datatype_test_postgresql.rb TESTOPTS="-n test_timestamp_with_zone_values_without_rails_time_zone_support" +You can run all the tests for a given database via rake: + $ rake test_postgresql diff --git a/activerecord/Rakefile b/activerecord/Rakefile index 346c7e8142..d5863ab14d 100755 --- a/activerecord/Rakefile +++ b/activerecord/Rakefile @@ -43,26 +43,24 @@ end %w( mysql mysql2 postgresql sqlite3 sqlite3_mem firebird db2 oracle sybase openbase frontbase jdbcmysql jdbcpostgresql jdbcsqlite3 jdbcderby jdbch2 jdbchsqldb ).each do |adapter| Rake::TestTask.new("test_#{adapter}") { |t| - connection_path = "test/connections/#{adapter =~ /jdbc/ ? 'jdbc' : 'native'}_#{adapter}" adapter_short = adapter == 'db2' ? adapter : adapter[/^[a-z0-9]+/] - t.libs << "test" << connection_path t.test_files = (Dir.glob( "test/cases/**/*_test.rb" ).reject { |x| x =~ /\/adapters\// } + Dir.glob("test/cases/adapters/#{adapter_short}/**/*_test.rb")).sort t.verbose = true t.warning = true + t.ruby_opts = ["-r#{File.expand_path('../', __FILE__)}/test/connections/#{adapter}"] } task "isolated_test_#{adapter}" do - connection_path = "test/connections/#{adapter =~ /jdbc/ ? 'jdbc' : 'native'}_#{adapter}" adapter_short = adapter == 'db2' ? adapter : adapter[/^[a-z0-9]+/] - puts [adapter, adapter_short, connection_path].inspect + puts [adapter, adapter_short].inspect ruby = File.join(*RbConfig::CONFIG.values_at('bindir', 'RUBY_INSTALL_NAME')) (Dir["test/cases/**/*_test.rb"].reject { |x| x =~ /\/adapters\// } + Dir["test/cases/adapters/#{adapter_short}/**/*_test.rb"]).all? do |file| - sh(ruby, "-Ilib:test:#{connection_path}", file) + sh(ruby, "-Itest", "-r#{File.expand_path('../', __FILE__)}/test/connections/#{adapter}", file) end or raise "Failures" end diff --git a/activerecord/lib/active_record/associations/collection_association.rb b/activerecord/lib/active_record/associations/collection_association.rb index c32dd77420..7e1a41e84d 100644 --- a/activerecord/lib/active_record/associations/collection_association.rb +++ b/activerecord/lib/active_record/associations/collection_association.rb @@ -104,26 +104,11 @@ module ActiveRecord end def create(attributes = {}, options = {}, &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(attr, options, &block) } - else - transaction do - add_to_target(build_record(attributes, options)) do |record| - yield(record) if block_given? - insert_record(record) - end - end - end + create_record(attributes, options, &block) end - def create!(attrs = {}, options = {}, &block) - record = create(attrs, options, &block) - Array.wrap(record).each(&:save!) - record + def create!(attributes = {}, options = {}, &block) + create_record(attributes, options, true, &block) end # Add +records+ to this association. Returns +self+ so method calls may be chained. @@ -402,16 +387,13 @@ module ActiveRecord return memory if persisted.empty? persisted.map! do |record| + # Unfortunately we cannot simply do memory.delete(record) since on 1.8 this returns + # record rather than memory.at(memory.index(record)). The behaviour is fixed in 1.9. + mem_index = memory.index(record) - # To work with ruby 1.8.7 - # > 1.9 #=> mem_record = memory.delete(record) - mem_record_index = memory.index(record) - if mem_record_index - mem_record = memory.at(mem_record_index) - memory.delete_at(mem_record_index) - end + if mem_index + mem_record = memory.delete_at(mem_index) - if mem_record (record.attribute_names - mem_record.changes.keys).each do |name| mem_record[name] = record[name] end @@ -425,8 +407,25 @@ module ActiveRecord persisted + memory end + def create_record(attributes, options, 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, options, raise, &block) } + else + transaction do + add_to_target(build_record(attributes, options)) do |record| + yield(record) if block_given? + insert_record(record, true, raise) + end + end + end + end + # Do the relevant stuff to insert the given record into the association collection. - def insert_record(record, validate = true) + def insert_record(record, validate = true, raise = false) raise NotImplementedError end @@ -437,7 +436,6 @@ module ActiveRecord def build_record(attributes, options) record = reflection.build_association(attributes, options) record.assign_attributes(create_scope.except(*record.changed), :without_protection => true) - record.assign_attributes(attributes, options) record end diff --git a/activerecord/lib/active_record/associations/collection_proxy.rb b/activerecord/lib/active_record/associations/collection_proxy.rb index adfc71d435..81b4a26b04 100644 --- a/activerecord/lib/active_record/associations/collection_proxy.rb +++ b/activerecord/lib/active_record/associations/collection_proxy.rb @@ -56,6 +56,8 @@ module ActiveRecord Array.wrap(association.options[:extend]).each { |ext| proxy_extend(ext) } end + alias_method :new, :build + def respond_to?(*args) super || (load_target && target.respond_to?(*args)) || @@ -115,14 +117,6 @@ module ActiveRecord @association.reload self end - - def new(*args, &block) - if @association.is_a?(HasManyThroughAssociation) - @association.build(*args, &block) - else - method_missing(:new, *args, &block) - end - end end end end diff --git a/activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb b/activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb index 217213808b..f7ce70db1a 100644 --- a/activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb +++ b/activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb @@ -9,8 +9,14 @@ module ActiveRecord super end - def insert_record(record, validate = true) - return if record.new_record? && !record.save(:validate => validate) + def insert_record(record, validate = true, raise = false) + if record.new_record? + if raise + record.save!(:validate => validate) + else + return unless record.save(:validate => validate) + end + end if options[:insert_sql] owner.connection.insert(interpolate(options[:insert_sql], record)) diff --git a/activerecord/lib/active_record/associations/has_many_association.rb b/activerecord/lib/active_record/associations/has_many_association.rb index 7172e89a05..50ee60284c 100644 --- a/activerecord/lib/active_record/associations/has_many_association.rb +++ b/activerecord/lib/active_record/associations/has_many_association.rb @@ -7,9 +7,14 @@ module ActiveRecord # is provided by its child HasManyThroughAssociation. class HasManyAssociation < CollectionAssociation #:nodoc: - def insert_record(record, validate = true) + def insert_record(record, validate = true, raise = false) set_owner_attributes(record) - record.save(:validate => validate) + + if raise + record.save!(:validate => validate) + else + record.save(:validate => validate) + end end private diff --git a/activerecord/lib/active_record/associations/has_many_through_association.rb b/activerecord/lib/active_record/associations/has_many_through_association.rb index 7708228d23..2e818dca5d 100644 --- a/activerecord/lib/active_record/associations/has_many_through_association.rb +++ b/activerecord/lib/active_record/associations/has_many_through_association.rb @@ -6,8 +6,6 @@ module ActiveRecord class HasManyThroughAssociation < HasManyAssociation #:nodoc: include ThroughAssociation - alias_method :new, :build - # Returns the size of the collection by executing a SELECT COUNT(*) query if the collection hasn't been # loaded and calling collection.size if it has. If it's more likely than not that the collection does # have a size larger than zero, and you need to fetch that collection afterwards, it'll take one fewer @@ -33,9 +31,16 @@ module ActiveRecord super end - def insert_record(record, validate = true) + def insert_record(record, validate = true, raise = false) ensure_not_nested - return if record.new_record? && !record.save(:validate => validate) + + if record.new_record? + if raise + record.save!(:validate => validate) + else + return unless record.save(:validate => validate) + end + end through_record(record).save! update_counter(1) diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index f74810720d..08cc282d09 100644 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -1308,7 +1308,6 @@ MSG rescue NameError => e # We don't want to swallow NoMethodError < NameError errors raise e unless e.instance_of?(NameError) - rescue ArgumentError end end diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb index b681871673..3e390ba994 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb @@ -659,10 +659,7 @@ module ActiveRecord # Returns the list of all tables in the schema search path or a specified schema. def tables(name = nil) query(<<-SQL, 'SCHEMA').map { |row| row[0] } - SELECT case schemaname - when 'public' then tablename - else schemaname||'.'||tablename - end as tablename + SELECT tablename FROM pg_tables WHERE schemaname = ANY (current_schemas(false)) SQL @@ -833,7 +830,11 @@ module ActiveRecord end_sql # [primary_key, sequence] - sequence = result.second == 'public' ? result.last : "#{result.second}.#{result.last}" + if result.second == 'public' then + sequence = result.last + else + sequence = result.second+'.'+result.last + end [result.first, sequence] rescue diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb index e852f50d86..317af8a15d 100644 --- a/activerecord/lib/active_record/relation.rb +++ b/activerecord/lib/active_record/relation.rb @@ -6,7 +6,7 @@ module ActiveRecord JoinOperation = Struct.new(:relation, :join_class, :on) ASSOCIATION_METHODS = [:includes, :eager_load, :preload] MULTI_VALUE_METHODS = [:select, :group, :order, :joins, :where, :having, :bind] - SINGLE_VALUE_METHODS = [:limit, :offset, :lock, :readonly, :create_with, :from, :reorder] + SINGLE_VALUE_METHODS = [:limit, :offset, :lock, :readonly, :create_with, :from, :reorder, :reverse_order] include FinderMethods, Calculations, SpawnMethods, QueryMethods, Batches diff --git a/activerecord/lib/active_record/relation/calculations.rb b/activerecord/lib/active_record/relation/calculations.rb index a785f38e89..aabe5c269b 100644 --- a/activerecord/lib/active_record/relation/calculations.rb +++ b/activerecord/lib/active_record/relation/calculations.rb @@ -196,7 +196,7 @@ module ActiveRecord def execute_simple_calculation(operation, column_name, distinct) #:nodoc: # Postgresql doesn't like ORDER BY when there are no GROUP BY - relation = reorder(nil) + relation = with_default_scope.reorder(nil) if operation == "count" && (relation.limit_value || relation.offset_value) # Shortcut when limit is zero. @@ -245,7 +245,7 @@ module ActiveRecord "#{field} AS #{aliaz}" } - relation = except(:group).group(group.join(',')) + relation = with_default_scope.except(:group).group(group.join(',')) relation.select_values = select_values calculated_data = @klass.connection.select_all(relation.to_sql) diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb index 94aa999715..739363415c 100644 --- a/activerecord/lib/active_record/relation/query_methods.rb +++ b/activerecord/lib/active_record/relation/query_methods.rb @@ -9,7 +9,7 @@ module ActiveRecord :select_values, :group_values, :order_values, :joins_values, :where_values, :having_values, :bind_values, :limit_value, :offset_value, :lock_value, :readonly_value, :create_with_value, - :from_value, :reorder_value + :from_value, :reorder_value, :reverse_order_value def includes(*args) args.reject! {|a| a.blank? } @@ -158,13 +158,9 @@ module ActiveRecord end def reverse_order - order_clause = arel.order_clauses - - order = order_clause.empty? ? - "#{table_name}.#{primary_key} DESC" : - reverse_sql_order(order_clause).join(', ') - - except(:order).order(Arel.sql(order)) + relation = clone + relation.reverse_order_value = !relation.reverse_order_value + relation end def arel @@ -186,6 +182,7 @@ module ActiveRecord arel.group(*@group_values.uniq.reject{|g| g.blank?}) unless @group_values.empty? order = @reorder_value ? @reorder_value : @order_values + order = reverse_sql_order(order) if @reverse_order_value arel.order(*order.uniq.reject{|o| o.blank?}) unless order.empty? build_select(arel, @select_values.uniq) @@ -306,6 +303,8 @@ module ActiveRecord end def reverse_sql_order(order_query) + order_query = ["#{quoted_table_name}.#{quoted_primary_key} ASC"] if order_query.empty? + order_query.join(', ').split(',').collect do |s| s.gsub!(/\sasc\Z/i, ' DESC') || s.gsub!(/\sdesc\Z/i, ' ASC') || s.concat(' DESC') end diff --git a/activerecord/test/.gitignore b/activerecord/test/.gitignore new file mode 100644 index 0000000000..a0ec5967dd --- /dev/null +++ b/activerecord/test/.gitignore @@ -0,0 +1 @@ +/config.yml diff --git a/activerecord/test/cases/adapter_test.rb b/activerecord/test/cases/adapter_test.rb index 49b2e945c3..295d78284e 100644 --- a/activerecord/test/cases/adapter_test.rb +++ b/activerecord/test/cases/adapter_test.rb @@ -1,4 +1,4 @@ -require "cases/helper" +require File.expand_path('../helper', __FILE__) class AdapterTest < ActiveRecord::TestCase def setup diff --git a/activerecord/test/cases/adapters/firebird/connection_test.rb b/activerecord/test/cases/adapters/firebird/connection_test.rb index f57ea686a5..47e8859ac6 100644 --- a/activerecord/test/cases/adapters/firebird/connection_test.rb +++ b/activerecord/test/cases/adapters/firebird/connection_test.rb @@ -1,4 +1,4 @@ -require "cases/helper" +require File.expand_path('../../../helper', __FILE__) class FirebirdConnectionTest < ActiveRecord::TestCase def test_charset_properly_set diff --git a/activerecord/test/cases/adapters/firebird/default_test.rb b/activerecord/test/cases/adapters/firebird/default_test.rb index 713c7e11bf..2d5e45dd74 100644 --- a/activerecord/test/cases/adapters/firebird/default_test.rb +++ b/activerecord/test/cases/adapters/firebird/default_test.rb @@ -1,4 +1,4 @@ -require "cases/helper" +require File.expand_path('../../../helper', __FILE__) require 'models/default' class DefaultTest < ActiveRecord::TestCase diff --git a/activerecord/test/cases/adapters/firebird/migration_test.rb b/activerecord/test/cases/adapters/firebird/migration_test.rb index 710661b9bd..0fe3d4a858 100644 --- a/activerecord/test/cases/adapters/firebird/migration_test.rb +++ b/activerecord/test/cases/adapters/firebird/migration_test.rb @@ -1,4 +1,4 @@ -require "cases/helper" +require File.expand_path('../../../helper', __FILE__) require 'models/course' class FirebirdMigrationTest < ActiveRecord::TestCase @@ -24,7 +24,7 @@ class FirebirdMigrationTest < ActiveRecord::TestCase assert !sequence_exists?('foo_seq') assert sequence_exists?('foo_custom_seq') - assert_nothing_raised { @connection.drop_table(:foo, :sequence => 'foo_custom_seq') } + assert_nothing_raised { @connection.drop_table(:foo) } assert !sequence_exists?('foo_custom_seq') ensure FireRuby::Generator.new('foo_custom_seq', @fireruby_connection).drop rescue nil diff --git a/activerecord/test/cases/adapters/mysql/active_schema_test.rb b/activerecord/test/cases/adapters/mysql/active_schema_test.rb index 509baacaef..c817b259b4 100644 --- a/activerecord/test/cases/adapters/mysql/active_schema_test.rb +++ b/activerecord/test/cases/adapters/mysql/active_schema_test.rb @@ -1,4 +1,4 @@ -require "cases/helper" +require File.expand_path('../../../helper', __FILE__) class ActiveSchemaTest < ActiveRecord::TestCase def setup diff --git a/activerecord/test/cases/adapters/mysql/connection_test.rb b/activerecord/test/cases/adapters/mysql/connection_test.rb index eee771ecff..703eb5a8bd 100644 --- a/activerecord/test/cases/adapters/mysql/connection_test.rb +++ b/activerecord/test/cases/adapters/mysql/connection_test.rb @@ -1,4 +1,4 @@ -require "cases/helper" +require File.expand_path('../../../helper', __FILE__) class MysqlConnectionTest < ActiveRecord::TestCase def setup diff --git a/activerecord/test/cases/adapters/mysql/mysql_adapter_test.rb b/activerecord/test/cases/adapters/mysql/mysql_adapter_test.rb index 146b77a95c..756115e5c9 100644 --- a/activerecord/test/cases/adapters/mysql/mysql_adapter_test.rb +++ b/activerecord/test/cases/adapters/mysql/mysql_adapter_test.rb @@ -1,6 +1,6 @@ # encoding: utf-8 -require "cases/helper" +require File.expand_path('../../../helper', __FILE__) module ActiveRecord module ConnectionAdapters diff --git a/activerecord/test/cases/adapters/mysql/quoting_test.rb b/activerecord/test/cases/adapters/mysql/quoting_test.rb index 9673e2bb46..7933800440 100644 --- a/activerecord/test/cases/adapters/mysql/quoting_test.rb +++ b/activerecord/test/cases/adapters/mysql/quoting_test.rb @@ -1,4 +1,4 @@ -require "cases/helper" +require File.expand_path('../../../helper', __FILE__) module ActiveRecord module ConnectionAdapters @@ -23,4 +23,3 @@ module ActiveRecord end end end - diff --git a/activerecord/test/cases/adapters/mysql/reserved_word_test.rb b/activerecord/test/cases/adapters/mysql/reserved_word_test.rb index 292c7efebb..2750831b93 100644 --- a/activerecord/test/cases/adapters/mysql/reserved_word_test.rb +++ b/activerecord/test/cases/adapters/mysql/reserved_word_test.rb @@ -1,4 +1,4 @@ -require "cases/helper" +require File.expand_path('../../../helper', __FILE__) class Group < ActiveRecord::Base Group.table_name = 'group' diff --git a/activerecord/test/cases/adapters/mysql/schema_test.rb b/activerecord/test/cases/adapters/mysql/schema_test.rb index a2155d1dd1..8b26d303bf 100644 --- a/activerecord/test/cases/adapters/mysql/schema_test.rb +++ b/activerecord/test/cases/adapters/mysql/schema_test.rb @@ -1,4 +1,4 @@ -require "cases/helper" +require File.expand_path('../../../helper', __FILE__) require 'models/post' require 'models/comment' diff --git a/activerecord/test/cases/adapters/mysql/sp_test.rb b/activerecord/test/cases/adapters/mysql/sp_test.rb index 3ca2917ca4..baa44fab70 100644 --- a/activerecord/test/cases/adapters/mysql/sp_test.rb +++ b/activerecord/test/cases/adapters/mysql/sp_test.rb @@ -1,4 +1,4 @@ -require "cases/helper" +require File.expand_path('../../../helper', __FILE__) require 'models/topic' class StoredProcedureTest < ActiveRecord::TestCase diff --git a/activerecord/test/cases/adapters/mysql2/active_schema_test.rb b/activerecord/test/cases/adapters/mysql2/active_schema_test.rb index a83399d0cd..ca716f7016 100644 --- a/activerecord/test/cases/adapters/mysql2/active_schema_test.rb +++ b/activerecord/test/cases/adapters/mysql2/active_schema_test.rb @@ -1,4 +1,4 @@ -require "cases/helper" +require File.expand_path('../../../helper', __FILE__) class ActiveSchemaTest < ActiveRecord::TestCase def setup diff --git a/activerecord/test/cases/adapters/mysql2/bind_parameter_test.rb b/activerecord/test/cases/adapters/mysql2/bind_parameter_test.rb index cd9c1041dc..7bb35d755a 100644 --- a/activerecord/test/cases/adapters/mysql2/bind_parameter_test.rb +++ b/activerecord/test/cases/adapters/mysql2/bind_parameter_test.rb @@ -1,4 +1,4 @@ -require "cases/helper" +require File.expand_path('../../../helper', __FILE__) require 'models/topic' module ActiveRecord diff --git a/activerecord/test/cases/adapters/mysql2/connection_test.rb b/activerecord/test/cases/adapters/mysql2/connection_test.rb index 26091c713b..1c523dad69 100644 --- a/activerecord/test/cases/adapters/mysql2/connection_test.rb +++ b/activerecord/test/cases/adapters/mysql2/connection_test.rb @@ -1,4 +1,4 @@ -require "cases/helper" +require File.expand_path('../../../helper', __FILE__) class MysqlConnectionTest < ActiveRecord::TestCase def setup diff --git a/activerecord/test/cases/adapters/mysql2/reserved_word_test.rb b/activerecord/test/cases/adapters/mysql2/reserved_word_test.rb index 752b864818..9cb30b0fd1 100644 --- a/activerecord/test/cases/adapters/mysql2/reserved_word_test.rb +++ b/activerecord/test/cases/adapters/mysql2/reserved_word_test.rb @@ -1,4 +1,4 @@ -require "cases/helper" +require File.expand_path('../../../helper', __FILE__) class Group < ActiveRecord::Base Group.table_name = 'group' diff --git a/activerecord/test/cases/adapters/mysql2/schema_test.rb b/activerecord/test/cases/adapters/mysql2/schema_test.rb index 858d1da2dd..ec89972360 100644 --- a/activerecord/test/cases/adapters/mysql2/schema_test.rb +++ b/activerecord/test/cases/adapters/mysql2/schema_test.rb @@ -1,4 +1,4 @@ -require "cases/helper" +require File.expand_path('../../../helper', __FILE__) require 'models/post' require 'models/comment' diff --git a/activerecord/test/cases/adapters/oracle/synonym_test.rb b/activerecord/test/cases/adapters/oracle/synonym_test.rb index b9a422a6ca..4cbca6dcb2 100644 --- a/activerecord/test/cases/adapters/oracle/synonym_test.rb +++ b/activerecord/test/cases/adapters/oracle/synonym_test.rb @@ -1,4 +1,4 @@ -require "cases/helper" +require File.expand_path('../../../helper', __FILE__) require 'models/topic' require 'models/subject' diff --git a/activerecord/test/cases/adapters/postgresql/active_schema_test.rb b/activerecord/test/cases/adapters/postgresql/active_schema_test.rb index e4746d4aa3..1802e2be24 100644 --- a/activerecord/test/cases/adapters/postgresql/active_schema_test.rb +++ b/activerecord/test/cases/adapters/postgresql/active_schema_test.rb @@ -1,4 +1,4 @@ -require 'cases/helper' +require File.expand_path('../../../helper', __FILE__) class PostgresqlActiveSchemaTest < ActiveRecord::TestCase def setup diff --git a/activerecord/test/cases/adapters/postgresql/datatype_test.rb b/activerecord/test/cases/adapters/postgresql/datatype_test.rb index ce08e4c6a7..c383e8b6fb 100644 --- a/activerecord/test/cases/adapters/postgresql/datatype_test.rb +++ b/activerecord/test/cases/adapters/postgresql/datatype_test.rb @@ -1,4 +1,4 @@ -require "cases/helper" +require File.expand_path('../../../helper', __FILE__) class PostgresqlArray < ActiveRecord::Base end diff --git a/activerecord/test/cases/adapters/postgresql/postgresql_adapter_test.rb b/activerecord/test/cases/adapters/postgresql/postgresql_adapter_test.rb index 7c49236854..14e78ed982 100644 --- a/activerecord/test/cases/adapters/postgresql/postgresql_adapter_test.rb +++ b/activerecord/test/cases/adapters/postgresql/postgresql_adapter_test.rb @@ -1,5 +1,5 @@ # encoding: utf-8 -require "cases/helper" +require File.expand_path('../../../helper', __FILE__) module ActiveRecord module ConnectionAdapters diff --git a/activerecord/test/cases/adapters/postgresql/quoting_test.rb b/activerecord/test/cases/adapters/postgresql/quoting_test.rb index 172055f15c..e95d10c594 100644 --- a/activerecord/test/cases/adapters/postgresql/quoting_test.rb +++ b/activerecord/test/cases/adapters/postgresql/quoting_test.rb @@ -1,4 +1,4 @@ -require "cases/helper" +require File.expand_path('../../../helper', __FILE__) module ActiveRecord module ConnectionAdapters diff --git a/activerecord/test/cases/adapters/postgresql/schema_authorization_test.rb b/activerecord/test/cases/adapters/postgresql/schema_authorization_test.rb index d5e1838543..8b9c4d337a 100644 --- a/activerecord/test/cases/adapters/postgresql/schema_authorization_test.rb +++ b/activerecord/test/cases/adapters/postgresql/schema_authorization_test.rb @@ -1,4 +1,4 @@ -require "cases/helper" +require File.expand_path('../../../helper', __FILE__) class SchemaThing < ActiveRecord::Base end diff --git a/activerecord/test/cases/adapters/postgresql/schema_test.rb b/activerecord/test/cases/adapters/postgresql/schema_test.rb index a5c3e69af9..6f3dba4168 100644 --- a/activerecord/test/cases/adapters/postgresql/schema_test.rb +++ b/activerecord/test/cases/adapters/postgresql/schema_test.rb @@ -1,4 +1,4 @@ -require "cases/helper" +require File.expand_path('../../../helper', __FILE__) class SchemaTest < ActiveRecord::TestCase self.use_transactional_fixtures = false diff --git a/activerecord/test/cases/adapters/postgresql/timestamp_test.rb b/activerecord/test/cases/adapters/postgresql/timestamp_test.rb new file mode 100644 index 0000000000..fb4616dc76 --- /dev/null +++ b/activerecord/test/cases/adapters/postgresql/timestamp_test.rb @@ -0,0 +1,30 @@ +require File.expand_path('../../../helper', __FILE__) +require 'models/developer' + +class TimestampTest < ActiveRecord::TestCase + def test_load_infinity_and_beyond + unless current_adapter?(:PostgreSQLAdapter) + return skip("only tested on postgresql") + end + + d = Developer.find_by_sql("select 'infinity'::timestamp as updated_at") + assert d.first.updated_at.infinite?, 'timestamp should be infinite' + + d = Developer.find_by_sql("select '-infinity'::timestamp as updated_at") + time = d.first.updated_at + assert time.infinite?, 'timestamp should be infinite' + assert_operator time, :<, 0 + end + + def test_save_infinity_and_beyond + unless current_adapter?(:PostgreSQLAdapter) + return skip("only tested on postgresql") + end + + d = Developer.create!(:name => 'aaron', :updated_at => 1.0 / 0.0) + assert_equal(1.0 / 0.0, d.updated_at) + + d = Developer.create!(:name => 'aaron', :updated_at => -1.0 / 0.0) + assert_equal(-1.0 / 0.0, d.updated_at) + end +end diff --git a/activerecord/test/cases/adapters/sqlite3/copy_table_test.rb b/activerecord/test/cases/adapters/sqlite3/copy_table_test.rb index 575b4806c1..899df1d59a 100644 --- a/activerecord/test/cases/adapters/sqlite3/copy_table_test.rb +++ b/activerecord/test/cases/adapters/sqlite3/copy_table_test.rb @@ -1,4 +1,4 @@ -require "cases/helper" +require File.expand_path('../../../helper', __FILE__) class CopyTableTest < ActiveRecord::TestCase fixtures :customers, :companies, :comments diff --git a/activerecord/test/cases/adapters/sqlite3/quoting_test.rb b/activerecord/test/cases/adapters/sqlite3/quoting_test.rb index 0d9db92447..51f01c262d 100644 --- a/activerecord/test/cases/adapters/sqlite3/quoting_test.rb +++ b/activerecord/test/cases/adapters/sqlite3/quoting_test.rb @@ -1,4 +1,4 @@ -require "cases/helper" +require File.expand_path('../../../helper', __FILE__) require 'bigdecimal' require 'yaml' diff --git a/activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb b/activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb index 6ff04e3eb3..d58a804815 100644 --- a/activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb +++ b/activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb @@ -1,5 +1,5 @@ # encoding: utf-8 -require "cases/helper" +require File.expand_path('../../../helper', __FILE__) module ActiveRecord module ConnectionAdapters diff --git a/activerecord/test/cases/aggregations_test.rb b/activerecord/test/cases/aggregations_test.rb index 3e0e6dce2c..d296364d7f 100644 --- a/activerecord/test/cases/aggregations_test.rb +++ b/activerecord/test/cases/aggregations_test.rb @@ -1,4 +1,4 @@ -require "cases/helper" +require File.expand_path('../helper', __FILE__) require 'models/customer' require 'active_support/core_ext/exception' diff --git a/activerecord/test/cases/ar_schema_test.rb b/activerecord/test/cases/ar_schema_test.rb index 588adc38e3..eb4488899f 100644 --- a/activerecord/test/cases/ar_schema_test.rb +++ b/activerecord/test/cases/ar_schema_test.rb @@ -1,4 +1,4 @@ -require "cases/helper" +require File.expand_path('../helper', __FILE__) if ActiveRecord::Base.connection.supports_migrations? diff --git a/activerecord/test/cases/associations/belongs_to_associations_test.rb b/activerecord/test/cases/associations/belongs_to_associations_test.rb index 5a900e0605..d7293aa1e3 100644 --- a/activerecord/test/cases/associations/belongs_to_associations_test.rb +++ b/activerecord/test/cases/associations/belongs_to_associations_test.rb @@ -1,4 +1,4 @@ -require "cases/helper" +require File.expand_path('../../helper', __FILE__) require 'models/developer' require 'models/project' require 'models/company' diff --git a/activerecord/test/cases/associations/callbacks_test.rb b/activerecord/test/cases/associations/callbacks_test.rb index 2d0d4541b4..387a25b7b1 100644 --- a/activerecord/test/cases/associations/callbacks_test.rb +++ b/activerecord/test/cases/associations/callbacks_test.rb @@ -1,4 +1,4 @@ -require "cases/helper" +require File.expand_path('../../helper', __FILE__) require 'models/post' require 'models/author' require 'models/project' diff --git a/activerecord/test/cases/associations/cascaded_eager_loading_test.rb b/activerecord/test/cases/associations/cascaded_eager_loading_test.rb index ff376a68d8..d21afff978 100644 --- a/activerecord/test/cases/associations/cascaded_eager_loading_test.rb +++ b/activerecord/test/cases/associations/cascaded_eager_loading_test.rb @@ -1,4 +1,4 @@ -require "cases/helper" +require File.expand_path('../../helper', __FILE__) require 'models/post' require 'models/comment' require 'models/author' diff --git a/activerecord/test/cases/associations/eager_load_includes_full_sti_class_test.rb b/activerecord/test/cases/associations/eager_load_includes_full_sti_class_test.rb index d75791cab9..41cf745f91 100644 --- a/activerecord/test/cases/associations/eager_load_includes_full_sti_class_test.rb +++ b/activerecord/test/cases/associations/eager_load_includes_full_sti_class_test.rb @@ -1,4 +1,4 @@ -require 'cases/helper' +require File.expand_path('../../helper', __FILE__) require 'models/post' require 'models/tagging' diff --git a/activerecord/test/cases/associations/eager_load_nested_include_test.rb b/activerecord/test/cases/associations/eager_load_nested_include_test.rb index 2cf9f89c3c..de1f47873f 100644 --- a/activerecord/test/cases/associations/eager_load_nested_include_test.rb +++ b/activerecord/test/cases/associations/eager_load_nested_include_test.rb @@ -1,4 +1,4 @@ -require 'cases/helper' +require File.expand_path('../../helper', __FILE__) require 'models/post' require 'models/tag' require 'models/author' diff --git a/activerecord/test/cases/associations/eager_singularization_test.rb b/activerecord/test/cases/associations/eager_singularization_test.rb index 07d0b24613..ffb5411a5b 100644 --- a/activerecord/test/cases/associations/eager_singularization_test.rb +++ b/activerecord/test/cases/associations/eager_singularization_test.rb @@ -1,4 +1,4 @@ -require "cases/helper" +require File.expand_path('../../helper', __FILE__) class Virus < ActiveRecord::Base belongs_to :octopus diff --git a/activerecord/test/cases/associations/eager_test.rb b/activerecord/test/cases/associations/eager_test.rb index 325fc58958..945edad48a 100644 --- a/activerecord/test/cases/associations/eager_test.rb +++ b/activerecord/test/cases/associations/eager_test.rb @@ -1,4 +1,4 @@ -require "cases/helper" +require File.expand_path('../../helper', __FILE__) require 'models/post' require 'models/tagging' require 'models/tag' diff --git a/activerecord/test/cases/associations/extension_test.rb b/activerecord/test/cases/associations/extension_test.rb index 24830a661a..c0a8f74834 100644 --- a/activerecord/test/cases/associations/extension_test.rb +++ b/activerecord/test/cases/associations/extension_test.rb @@ -1,4 +1,4 @@ -require "cases/helper" +require File.expand_path('../../helper', __FILE__) require 'models/post' require 'models/comment' require 'models/project' diff --git a/activerecord/test/cases/associations/habtm_join_table_test.rb b/activerecord/test/cases/associations/habtm_join_table_test.rb index fe2b82f2c1..cc0a6cd6c2 100644 --- a/activerecord/test/cases/associations/habtm_join_table_test.rb +++ b/activerecord/test/cases/associations/habtm_join_table_test.rb @@ -1,4 +1,4 @@ -require 'cases/helper' +require File.expand_path('../../helper', __FILE__) class MyReader < ActiveRecord::Base has_and_belongs_to_many :my_books diff --git a/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb b/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb index 839a7852fc..171177ad1d 100644 --- a/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb +++ b/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb @@ -1,4 +1,4 @@ -require "cases/helper" +require File.expand_path('../../helper', __FILE__) require 'models/developer' require 'models/project' require 'models/company' @@ -100,7 +100,7 @@ class HasAndBelongsToManyAssociationsTest < ActiveRecord::TestCase assert_equal 'c1', record[0] assert_equal 't1', record[1] end - + def test_proper_usage_of_primary_keys_and_join_table setup_data_for_habtm_case @@ -245,6 +245,21 @@ class HasAndBelongsToManyAssociationsTest < ActiveRecord::TestCase assert_equal Developer.find(1).projects.sort_by(&:id).last, proj # prove join table is updated end + def test_new_aliased_to_build + devel = Developer.find(1) + proj = assert_no_queries { devel.projects.new("name" => "Projekt") } + assert !devel.projects.loaded? + + assert_equal devel.projects.last, proj + assert devel.projects.loaded? + + assert !proj.persisted? + devel.save + assert proj.persisted? + assert_equal devel.projects.last, proj + assert_equal Developer.find(1).projects.sort_by(&:id).last, proj # prove join table is updated + end + def test_build_by_new_record devel = Developer.new(:name => "Marcel", :salary => 75000) devel.projects.build(:name => "Make bed") diff --git a/activerecord/test/cases/associations/has_many_associations_test.rb b/activerecord/test/cases/associations/has_many_associations_test.rb index 43974fd895..b87a1744c1 100644 --- a/activerecord/test/cases/associations/has_many_associations_test.rb +++ b/activerecord/test/cases/associations/has_many_associations_test.rb @@ -1,7 +1,8 @@ -require "cases/helper" +require File.expand_path('../../helper', __FILE__) require 'models/developer' require 'models/project' require 'models/company' +require 'models/contract' require 'models/topic' require 'models/reply' require 'models/category' @@ -536,6 +537,16 @@ class HasManyAssociationsTest < ActiveRecord::TestCase assert_equal 3, companies(:first_firm).clients_of_firm(true).size end + def test_new_aliased_to_build + company = companies(:first_firm) + new_client = assert_no_queries { company.clients_of_firm.new("name" => "Another Client") } + assert !company.clients_of_firm.loaded? + + assert_equal "Another Client", new_client.name + assert !new_client.persisted? + assert_equal new_client, company.clients_of_firm.last + end + def test_build company = companies(:first_firm) new_client = assert_no_queries { company.clients_of_firm.build("name" => "Another Client") } @@ -1475,4 +1486,12 @@ class HasManyAssociationsTest < ActiveRecord::TestCase tagging = Tagging.create! :taggable => post assert_equal [tagging], post.taggings end + + def test_dont_call_save_callbacks_twice_on_has_many + firm = companies(:first_firm) + contract = firm.contracts.create! + + assert_equal 1, contract.hi_count + assert_equal 1, contract.bye_count + end end diff --git a/activerecord/test/cases/associations/has_many_through_associations_test.rb b/activerecord/test/cases/associations/has_many_through_associations_test.rb index 877148bd5e..476bc637f6 100644 --- a/activerecord/test/cases/associations/has_many_through_associations_test.rb +++ b/activerecord/test/cases/associations/has_many_through_associations_test.rb @@ -1,4 +1,4 @@ -require "cases/helper" +require File.expand_path('../../helper', __FILE__) require 'models/post' require 'models/person' require 'models/reference' diff --git a/activerecord/test/cases/associations/has_one_associations_test.rb b/activerecord/test/cases/associations/has_one_associations_test.rb index 299688d840..9bafe0f57d 100644 --- a/activerecord/test/cases/associations/has_one_associations_test.rb +++ b/activerecord/test/cases/associations/has_one_associations_test.rb @@ -1,4 +1,4 @@ -require "cases/helper" +require File.expand_path('../../helper', __FILE__) require 'models/developer' require 'models/project' require 'models/company' diff --git a/activerecord/test/cases/associations/has_one_through_associations_test.rb b/activerecord/test/cases/associations/has_one_through_associations_test.rb index 2503349c08..24576fb580 100644 --- a/activerecord/test/cases/associations/has_one_through_associations_test.rb +++ b/activerecord/test/cases/associations/has_one_through_associations_test.rb @@ -1,4 +1,4 @@ -require "cases/helper" +require File.expand_path('../../helper', __FILE__) require 'models/club' require 'models/member_type' require 'models/member' diff --git a/activerecord/test/cases/associations/identity_map_test.rb b/activerecord/test/cases/associations/identity_map_test.rb index 9b8635774c..0dd6c76efd 100644 --- a/activerecord/test/cases/associations/identity_map_test.rb +++ b/activerecord/test/cases/associations/identity_map_test.rb @@ -1,4 +1,4 @@ -require "cases/helper" +require File.expand_path('../../helper', __FILE__) require 'models/author' require 'models/post' diff --git a/activerecord/test/cases/associations/inner_join_association_test.rb b/activerecord/test/cases/associations/inner_join_association_test.rb index e5e9ca6131..1c0fe8368f 100644 --- a/activerecord/test/cases/associations/inner_join_association_test.rb +++ b/activerecord/test/cases/associations/inner_join_association_test.rb @@ -1,4 +1,4 @@ -require "cases/helper" +require File.expand_path('../../helper', __FILE__) require 'models/post' require 'models/comment' require 'models/author' diff --git a/activerecord/test/cases/associations/inverse_associations_test.rb b/activerecord/test/cases/associations/inverse_associations_test.rb index 76282213d8..9e4975566b 100644 --- a/activerecord/test/cases/associations/inverse_associations_test.rb +++ b/activerecord/test/cases/associations/inverse_associations_test.rb @@ -1,4 +1,4 @@ -require "cases/helper" +require File.expand_path('../../helper', __FILE__) require 'models/man' require 'models/face' require 'models/interest' diff --git a/activerecord/test/cases/associations/join_model_test.rb b/activerecord/test/cases/associations/join_model_test.rb index b59ce4efeb..c869e6fbc5 100644 --- a/activerecord/test/cases/associations/join_model_test.rb +++ b/activerecord/test/cases/associations/join_model_test.rb @@ -1,4 +1,4 @@ -require "cases/helper" +require File.expand_path('../../helper', __FILE__) require 'active_support/core_ext/object/inclusion' require 'models/tag' require 'models/tagging' diff --git a/activerecord/test/cases/associations/nested_through_associations_test.rb b/activerecord/test/cases/associations/nested_through_associations_test.rb index dd450a2a8e..b13b8d5e36 100644 --- a/activerecord/test/cases/associations/nested_through_associations_test.rb +++ b/activerecord/test/cases/associations/nested_through_associations_test.rb @@ -1,4 +1,4 @@ -require "cases/helper" +require File.expand_path('../../helper', __FILE__) require 'models/author' require 'models/post' require 'models/person' diff --git a/activerecord/test/cases/associations_test.rb b/activerecord/test/cases/associations_test.rb index 49d82ba2df..8bff37907d 100644 --- a/activerecord/test/cases/associations_test.rb +++ b/activerecord/test/cases/associations_test.rb @@ -1,4 +1,4 @@ -require "cases/helper" +require File.expand_path('../helper', __FILE__) require 'models/developer' require 'models/project' require 'models/company' diff --git a/activerecord/test/cases/attribute_methods/read_test.rb b/activerecord/test/cases/attribute_methods/read_test.rb index 3641031d12..bb0dcb2a77 100644 --- a/activerecord/test/cases/attribute_methods/read_test.rb +++ b/activerecord/test/cases/attribute_methods/read_test.rb @@ -1,4 +1,4 @@ -require "cases/helper" +require File.expand_path('../../helper', __FILE__) require 'active_support/core_ext/object/inclusion' module ActiveRecord diff --git a/activerecord/test/cases/attribute_methods_test.rb b/activerecord/test/cases/attribute_methods_test.rb index 54c4d4ae90..bf6408be0f 100644 --- a/activerecord/test/cases/attribute_methods_test.rb +++ b/activerecord/test/cases/attribute_methods_test.rb @@ -1,4 +1,4 @@ -require "cases/helper" +require File.expand_path('../helper', __FILE__) require 'active_support/core_ext/object/inclusion' require 'models/minimalistic' require 'models/developer' @@ -134,7 +134,12 @@ class AttributeMethodsTest < ActiveRecord::TestCase if current_adapter?(:MysqlAdapter) def test_read_attributes_before_type_cast_on_boolean bool = Boolean.create({ "value" => false }) - assert_equal 0, bool.reload.attributes_before_type_cast["value"] + if RUBY_PLATFORM =~ /java/ + # JRuby will return the value before typecast as string + assert_equal "0", bool.reload.attributes_before_type_cast["value"] + else + assert_equal 0, bool.reload.attributes_before_type_cast["value"] + end end end diff --git a/activerecord/test/cases/autosave_association_test.rb b/activerecord/test/cases/autosave_association_test.rb index 8f55b7ebe6..b14c458435 100644 --- a/activerecord/test/cases/autosave_association_test.rb +++ b/activerecord/test/cases/autosave_association_test.rb @@ -1,4 +1,4 @@ -require 'cases/helper' +require File.expand_path('../helper', __FILE__) require 'models/bird' require 'models/company' require 'models/customer' diff --git a/activerecord/test/cases/base_test.rb b/activerecord/test/cases/base_test.rb index 39043447fc..5eb9a825b7 100644 --- a/activerecord/test/cases/base_test.rb +++ b/activerecord/test/cases/base_test.rb @@ -1,4 +1,4 @@ -require "cases/helper" +require File.expand_path('../helper', __FILE__) require 'models/post' require 'models/author' require 'models/topic' @@ -1766,6 +1766,13 @@ class BasicsTest < ActiveRecord::TestCase end end + def test_compute_type_argument_error + ActiveSupport::Dependencies.stubs(:constantize).raises(ArgumentError) + assert_raises ArgumentError do + ActiveRecord::Base.send :compute_type, 'InvalidModel' + end + end + def test_clear_cache! # preheat cache c1 = Post.columns diff --git a/activerecord/test/cases/batches_test.rb b/activerecord/test/cases/batches_test.rb index 6620464d6a..31e00c998c 100644 --- a/activerecord/test/cases/batches_test.rb +++ b/activerecord/test/cases/batches_test.rb @@ -1,4 +1,4 @@ -require 'cases/helper' +require File.expand_path('../helper', __FILE__) require 'models/post' class EachTest < ActiveRecord::TestCase diff --git a/activerecord/test/cases/binary_test.rb b/activerecord/test/cases/binary_test.rb index 06c14cb108..365c16679e 100644 --- a/activerecord/test/cases/binary_test.rb +++ b/activerecord/test/cases/binary_test.rb @@ -1,5 +1,5 @@ # encoding: utf-8 -require "cases/helper" +require File.expand_path('../helper', __FILE__) # Without using prepared statements, it makes no sense to test # BLOB data with DB2 or Firebird, because the length of a statement diff --git a/activerecord/test/cases/bind_parameter_test.rb b/activerecord/test/cases/bind_parameter_test.rb index 3652255c38..bfd4c2afdf 100644 --- a/activerecord/test/cases/bind_parameter_test.rb +++ b/activerecord/test/cases/bind_parameter_test.rb @@ -1,4 +1,4 @@ -require 'cases/helper' +require File.expand_path('../helper', __FILE__) require 'models/topic' module ActiveRecord diff --git a/activerecord/test/cases/calculations_test.rb b/activerecord/test/cases/calculations_test.rb index 56f6d795b6..cedd5c3d41 100644 --- a/activerecord/test/cases/calculations_test.rb +++ b/activerecord/test/cases/calculations_test.rb @@ -1,4 +1,4 @@ -require "cases/helper" +require File.expand_path('../helper', __FILE__) require 'models/company' require 'models/topic' require 'models/edge' diff --git a/activerecord/test/cases/callbacks_test.rb b/activerecord/test/cases/callbacks_test.rb index 7f4d25790b..c2b43438fc 100644 --- a/activerecord/test/cases/callbacks_test.rb +++ b/activerecord/test/cases/callbacks_test.rb @@ -1,4 +1,4 @@ -require "cases/helper" +require File.expand_path('../helper', __FILE__) class CallbackDeveloper < ActiveRecord::Base set_table_name 'developers' diff --git a/activerecord/test/cases/clone_test.rb b/activerecord/test/cases/clone_test.rb index d91646efca..b25340c205 100644 --- a/activerecord/test/cases/clone_test.rb +++ b/activerecord/test/cases/clone_test.rb @@ -1,4 +1,4 @@ -require "cases/helper" +require File.expand_path('../helper', __FILE__) require 'models/topic' module ActiveRecord diff --git a/activerecord/test/cases/coders/yaml_column_test.rb b/activerecord/test/cases/coders/yaml_column_test.rb index c7dcc21809..55aba713e8 100644 --- a/activerecord/test/cases/coders/yaml_column_test.rb +++ b/activerecord/test/cases/coders/yaml_column_test.rb @@ -1,5 +1,4 @@ - -require "cases/helper" +require File.expand_path('../../helper', __FILE__) module ActiveRecord module Coders diff --git a/activerecord/test/cases/column_alias_test.rb b/activerecord/test/cases/column_alias_test.rb index 40707d9cb2..1b6ac870e4 100644 --- a/activerecord/test/cases/column_alias_test.rb +++ b/activerecord/test/cases/column_alias_test.rb @@ -1,4 +1,4 @@ -require "cases/helper" +require File.expand_path('../helper', __FILE__) require 'models/topic' class TestColumnAlias < ActiveRecord::TestCase diff --git a/activerecord/test/cases/column_definition_test.rb b/activerecord/test/cases/column_definition_test.rb index d1dddd4c2c..4d046eb9ba 100644 --- a/activerecord/test/cases/column_definition_test.rb +++ b/activerecord/test/cases/column_definition_test.rb @@ -1,4 +1,4 @@ -require "cases/helper" +require File.expand_path('../helper', __FILE__) module ActiveRecord module ConnectionAdapters diff --git a/activerecord/test/cases/connection_adapters/connection_handler_test.rb b/activerecord/test/cases/connection_adapters/connection_handler_test.rb index abf317768f..0bf33f86cf 100644 --- a/activerecord/test/cases/connection_adapters/connection_handler_test.rb +++ b/activerecord/test/cases/connection_adapters/connection_handler_test.rb @@ -1,4 +1,4 @@ -require "cases/helper" +require File.expand_path('../../helper', __FILE__) module ActiveRecord module ConnectionAdapters diff --git a/activerecord/test/cases/connection_management_test.rb b/activerecord/test/cases/connection_management_test.rb index 85871aebdf..2b2deb6732 100644 --- a/activerecord/test/cases/connection_management_test.rb +++ b/activerecord/test/cases/connection_management_test.rb @@ -1,4 +1,4 @@ -require "cases/helper" +require File.expand_path('../helper', __FILE__) module ActiveRecord module ConnectionAdapters diff --git a/activerecord/test/cases/connection_pool_test.rb b/activerecord/test/cases/connection_pool_test.rb index f92f4e62c5..7aa765dc4f 100644 --- a/activerecord/test/cases/connection_pool_test.rb +++ b/activerecord/test/cases/connection_pool_test.rb @@ -1,4 +1,4 @@ -require "cases/helper" +require File.expand_path('../helper', __FILE__) module ActiveRecord module ConnectionAdapters diff --git a/activerecord/test/cases/counter_cache_test.rb b/activerecord/test/cases/counter_cache_test.rb index 3ed96a3ec8..31faef5f0f 100644 --- a/activerecord/test/cases/counter_cache_test.rb +++ b/activerecord/test/cases/counter_cache_test.rb @@ -1,4 +1,4 @@ -require 'cases/helper' +require File.expand_path('../helper', __FILE__) require 'models/topic' require 'models/car' require 'models/wheel' diff --git a/activerecord/test/cases/custom_locking_test.rb b/activerecord/test/cases/custom_locking_test.rb index d63ecdbcc5..1d4385eac0 100644 --- a/activerecord/test/cases/custom_locking_test.rb +++ b/activerecord/test/cases/custom_locking_test.rb @@ -1,4 +1,4 @@ -require "cases/helper" +require File.expand_path('../helper', __FILE__) require 'models/person' module ActiveRecord diff --git a/activerecord/test/cases/database_statements_test.rb b/activerecord/test/cases/database_statements_test.rb index c689e97d83..8fa2c9ca44 100644 --- a/activerecord/test/cases/database_statements_test.rb +++ b/activerecord/test/cases/database_statements_test.rb @@ -1,4 +1,4 @@ -require "cases/helper" +require File.expand_path('../helper', __FILE__) class DatabaseStatementsTest < ActiveRecord::TestCase def setup diff --git a/activerecord/test/cases/date_time_test.rb b/activerecord/test/cases/date_time_test.rb index 3deb0dac99..a9e477bd76 100644 --- a/activerecord/test/cases/date_time_test.rb +++ b/activerecord/test/cases/date_time_test.rb @@ -1,4 +1,4 @@ -require "cases/helper" +require File.expand_path('../helper', __FILE__) require 'models/topic' require 'models/task' diff --git a/activerecord/test/cases/defaults_test.rb b/activerecord/test/cases/defaults_test.rb index b3a281d960..8cf008871b 100644 --- a/activerecord/test/cases/defaults_test.rb +++ b/activerecord/test/cases/defaults_test.rb @@ -1,4 +1,4 @@ -require "cases/helper" +require File.expand_path('../helper', __FILE__) require 'active_support/core_ext/object/inclusion' require 'models/default' require 'models/entrant' diff --git a/activerecord/test/cases/deprecated_finder_test.rb b/activerecord/test/cases/deprecated_finder_test.rb index 2afc91b769..1819bfc5ca 100644 --- a/activerecord/test/cases/deprecated_finder_test.rb +++ b/activerecord/test/cases/deprecated_finder_test.rb @@ -1,4 +1,4 @@ -require "cases/helper" +require File.expand_path('../helper', __FILE__) require 'models/entrant' class DeprecatedFinderTest < ActiveRecord::TestCase diff --git a/activerecord/test/cases/dirty_test.rb b/activerecord/test/cases/dirty_test.rb index b1ce846218..7d58781eca 100644 --- a/activerecord/test/cases/dirty_test.rb +++ b/activerecord/test/cases/dirty_test.rb @@ -1,4 +1,4 @@ -require 'cases/helper' +require File.expand_path('../helper', __FILE__) require 'models/topic' # For booleans require 'models/pirate' # For timestamps require 'models/parrot' diff --git a/activerecord/test/cases/dup_test.rb b/activerecord/test/cases/dup_test.rb index 0236f9b0a1..9acf5fdd32 100644 --- a/activerecord/test/cases/dup_test.rb +++ b/activerecord/test/cases/dup_test.rb @@ -1,4 +1,4 @@ -require "cases/helper" +require File.expand_path('../helper', __FILE__) require 'models/topic' module ActiveRecord diff --git a/activerecord/test/cases/dynamic_finder_match_test.rb b/activerecord/test/cases/dynamic_finder_match_test.rb index e576870317..693a8e2180 100644 --- a/activerecord/test/cases/dynamic_finder_match_test.rb +++ b/activerecord/test/cases/dynamic_finder_match_test.rb @@ -1,4 +1,4 @@ -require "cases/helper" +require File.expand_path('../helper', __FILE__) module ActiveRecord class DynamicFinderMatchTest < ActiveRecord::TestCase diff --git a/activerecord/test/cases/finder_respond_to_test.rb b/activerecord/test/cases/finder_respond_to_test.rb index 235805a67c..7952e9a46a 100644 --- a/activerecord/test/cases/finder_respond_to_test.rb +++ b/activerecord/test/cases/finder_respond_to_test.rb @@ -1,4 +1,4 @@ -require "cases/helper" +require File.expand_path('../helper', __FILE__) require 'models/topic' class FinderRespondToTest < ActiveRecord::TestCase diff --git a/activerecord/test/cases/finder_test.rb b/activerecord/test/cases/finder_test.rb index 4e75eafe3d..3920f306f9 100644 --- a/activerecord/test/cases/finder_test.rb +++ b/activerecord/test/cases/finder_test.rb @@ -1,4 +1,4 @@ -require "cases/helper" +require File.expand_path('../helper', __FILE__) require 'models/post' require 'models/author' require 'models/categorization' diff --git a/activerecord/test/cases/fixtures/file_test.rb b/activerecord/test/cases/fixtures/file_test.rb index 8dbf92ae9a..9ff4455394 100644 --- a/activerecord/test/cases/fixtures/file_test.rb +++ b/activerecord/test/cases/fixtures/file_test.rb @@ -1,4 +1,4 @@ -require "cases/helper" +require File.expand_path('../../helper', __FILE__) require 'tempfile' module ActiveRecord diff --git a/activerecord/test/cases/fixtures_test.rb b/activerecord/test/cases/fixtures_test.rb index 306b437fb3..e645a9a47c 100644 --- a/activerecord/test/cases/fixtures_test.rb +++ b/activerecord/test/cases/fixtures_test.rb @@ -1,4 +1,4 @@ -require "cases/helper" +require File.expand_path('../helper', __FILE__) require 'models/post' require 'models/binary' require 'models/topic' diff --git a/activerecord/test/cases/habtm_destroy_order_test.rb b/activerecord/test/cases/habtm_destroy_order_test.rb index f2b91d977e..776ed3f517 100644 --- a/activerecord/test/cases/habtm_destroy_order_test.rb +++ b/activerecord/test/cases/habtm_destroy_order_test.rb @@ -1,4 +1,4 @@ -require "cases/helper" +require File.expand_path('../helper', __FILE__) require "models/lesson" require "models/student" diff --git a/activerecord/test/cases/helper.rb b/activerecord/test/cases/helper.rb index 9644ac1b02..7a214fa75a 100644 --- a/activerecord/test/cases/helper.rb +++ b/activerecord/test/cases/helper.rb @@ -1,5 +1,8 @@ require File.expand_path('../../../../load_paths', __FILE__) +test = File.expand_path('../..', __FILE__) +$:.unshift(test) unless $:.include?('test') || $:.include?(test) + lib = File.expand_path("#{File.dirname(__FILE__)}/../../lib") $:.unshift(lib) unless $:.include?('lib') || $:.include?(lib) @@ -11,14 +14,13 @@ require 'mocha' require 'active_record' require 'active_support/dependencies' -begin - require 'connection' -rescue LoadError - # If we cannot load connection we assume that driver was not loaded for this test case, so we load sqlite3 as default one. - # This allows for running separate test cases by simply running test file. - connection_type = defined?(JRUBY_VERSION) ? 'jdbc' : 'native' - require "test/connections/#{connection_type}_sqlite3/connection" -end + +require 'support/config' +require 'support/connection' + +ARTest.connect + +# TODO: Move all these random hacks into the ARTest namespace and into the support/ dir # Show backtraces for deprecated behavior for quicker cleanup. ActiveSupport::Deprecation.debug = true diff --git a/activerecord/test/cases/i18n_test.rb b/activerecord/test/cases/i18n_test.rb index 469f513e68..d96dc5fba9 100644 --- a/activerecord/test/cases/i18n_test.rb +++ b/activerecord/test/cases/i18n_test.rb @@ -1,4 +1,4 @@ -require "cases/helper" +require File.expand_path('../helper', __FILE__) require 'models/topic' require 'models/reply' @@ -43,4 +43,3 @@ class ActiveRecordI18nTests < ActiveRecord::TestCase assert_equal 'topic model', Reply.model_name.human end end - diff --git a/activerecord/test/cases/identity_map/middleware_test.rb b/activerecord/test/cases/identity_map/middleware_test.rb index 60dcad4586..047192c244 100644 --- a/activerecord/test/cases/identity_map/middleware_test.rb +++ b/activerecord/test/cases/identity_map/middleware_test.rb @@ -1,4 +1,4 @@ -require "cases/helper" +require File.expand_path('../../helper', __FILE__) module ActiveRecord module IdentityMap diff --git a/activerecord/test/cases/identity_map_test.rb b/activerecord/test/cases/identity_map_test.rb index a0e16400d2..d814f1cc92 100644 --- a/activerecord/test/cases/identity_map_test.rb +++ b/activerecord/test/cases/identity_map_test.rb @@ -1,5 +1,4 @@ -require "cases/helper" - +require File.expand_path('../helper', __FILE__) require 'models/developer' require 'models/project' require 'models/company' @@ -140,7 +139,7 @@ class IdentityMapTest < ActiveRecord::TestCase assert_not_same(p1, p2) end end - + def test_inherited_with_type_attribute_without_identity_map ActiveRecord::IdentityMap.without do c = comments(:sub_special_comment) diff --git a/activerecord/test/cases/inheritance_test.rb b/activerecord/test/cases/inheritance_test.rb index b5d8314541..5bfc572ea8 100644 --- a/activerecord/test/cases/inheritance_test.rb +++ b/activerecord/test/cases/inheritance_test.rb @@ -1,4 +1,4 @@ -require "cases/helper" +require File.expand_path('../helper', __FILE__) require 'models/company' require 'models/project' require 'models/subscriber' diff --git a/activerecord/test/cases/invalid_date_test.rb b/activerecord/test/cases/invalid_date_test.rb index 2de50b224c..65d326bc12 100644 --- a/activerecord/test/cases/invalid_date_test.rb +++ b/activerecord/test/cases/invalid_date_test.rb @@ -1,4 +1,4 @@ -require 'cases/helper' +require File.expand_path('../helper', __FILE__) require 'models/topic' class InvalidDateTest < ActiveRecord::TestCase diff --git a/activerecord/test/cases/invertible_migration_test.rb b/activerecord/test/cases/invertible_migration_test.rb index afec64750e..d145ff7427 100644 --- a/activerecord/test/cases/invertible_migration_test.rb +++ b/activerecord/test/cases/invertible_migration_test.rb @@ -1,4 +1,4 @@ -require "cases/helper" +require File.expand_path('../helper', __FILE__) module ActiveRecord class InvertibleMigrationTest < ActiveRecord::TestCase diff --git a/activerecord/test/cases/json_serialization_test.rb b/activerecord/test/cases/json_serialization_test.rb index d9e350abc0..aef7403a09 100644 --- a/activerecord/test/cases/json_serialization_test.rb +++ b/activerecord/test/cases/json_serialization_test.rb @@ -1,4 +1,4 @@ -require "cases/helper" +require File.expand_path('../helper', __FILE__) require 'models/contact' require 'models/post' require 'models/author' diff --git a/activerecord/test/cases/lifecycle_test.rb b/activerecord/test/cases/lifecycle_test.rb index 643e949087..7d47f7e21b 100644 --- a/activerecord/test/cases/lifecycle_test.rb +++ b/activerecord/test/cases/lifecycle_test.rb @@ -1,4 +1,4 @@ -require 'cases/helper' +require File.expand_path('../helper', __FILE__) require 'models/topic' require 'models/developer' require 'models/reply' diff --git a/activerecord/test/cases/locking_test.rb b/activerecord/test/cases/locking_test.rb index 61baa55027..88861df86a 100644 --- a/activerecord/test/cases/locking_test.rb +++ b/activerecord/test/cases/locking_test.rb @@ -1,5 +1,5 @@ require 'thread' -require "cases/helper" +require File.expand_path('../helper', __FILE__) require 'models/person' require 'models/job' require 'models/reader' diff --git a/activerecord/test/cases/log_subscriber_test.rb b/activerecord/test/cases/log_subscriber_test.rb index c6c6079490..f29ced4526 100644 --- a/activerecord/test/cases/log_subscriber_test.rb +++ b/activerecord/test/cases/log_subscriber_test.rb @@ -1,4 +1,4 @@ -require "cases/helper" +require File.expand_path('../helper', __FILE__) require "models/developer" require "models/post" require "active_support/log_subscriber/test_helper" diff --git a/activerecord/test/cases/mass_assignment_security_test.rb b/activerecord/test/cases/mass_assignment_security_test.rb index 33737e12a8..a41ce539c7 100644 --- a/activerecord/test/cases/mass_assignment_security_test.rb +++ b/activerecord/test/cases/mass_assignment_security_test.rb @@ -1,4 +1,4 @@ -require "cases/helper" +require File.expand_path('../helper', __FILE__) require 'models/company' require 'models/subscriber' require 'models/keyboard' diff --git a/activerecord/test/cases/method_scoping_test.rb b/activerecord/test/cases/method_scoping_test.rb index a0cb5dbdc5..52e76cb91a 100644 --- a/activerecord/test/cases/method_scoping_test.rb +++ b/activerecord/test/cases/method_scoping_test.rb @@ -2,7 +2,7 @@ # All the tests were already ported to relation_scoping_test.rb when the new # relation scoping API was added. -require "cases/helper" +require File.expand_path('../helper', __FILE__) require 'models/post' require 'models/author' require 'models/developer' diff --git a/activerecord/test/cases/migration/command_recorder_test.rb b/activerecord/test/cases/migration/command_recorder_test.rb index 0f79c99e1a..986dc7173d 100644 --- a/activerecord/test/cases/migration/command_recorder_test.rb +++ b/activerecord/test/cases/migration/command_recorder_test.rb @@ -1,4 +1,4 @@ -require "cases/helper" +require File.expand_path('../../helper', __FILE__) module ActiveRecord class Migration diff --git a/activerecord/test/cases/migration_test.rb b/activerecord/test/cases/migration_test.rb index bf7565a0d0..01f7575653 100644 --- a/activerecord/test/cases/migration_test.rb +++ b/activerecord/test/cases/migration_test.rb @@ -1,4 +1,4 @@ -require "cases/helper" +require File.expand_path('../helper', __FILE__) require 'bigdecimal/util' require 'models/person' diff --git a/activerecord/test/cases/mixin_test.rb b/activerecord/test/cases/mixin_test.rb index f927c13979..65101199b8 100644 --- a/activerecord/test/cases/mixin_test.rb +++ b/activerecord/test/cases/mixin_test.rb @@ -1,4 +1,4 @@ -require "cases/helper" +require File.expand_path('../helper', __FILE__) class Mixin < ActiveRecord::Base end diff --git a/activerecord/test/cases/modules_test.rb b/activerecord/test/cases/modules_test.rb index a2041af16a..df5e66ea3c 100644 --- a/activerecord/test/cases/modules_test.rb +++ b/activerecord/test/cases/modules_test.rb @@ -1,4 +1,4 @@ -require "cases/helper" +require File.expand_path('../helper', __FILE__) require 'models/company_in_module' require 'models/shop' diff --git a/activerecord/test/cases/multiple_db_test.rb b/activerecord/test/cases/multiple_db_test.rb index bd51388e05..fca832e50b 100644 --- a/activerecord/test/cases/multiple_db_test.rb +++ b/activerecord/test/cases/multiple_db_test.rb @@ -1,4 +1,4 @@ -require "cases/helper" +require File.expand_path('../helper', __FILE__) require 'models/entrant' require 'models/bird' diff --git a/activerecord/test/cases/named_scope_test.rb b/activerecord/test/cases/named_scope_test.rb index 34188e4915..2403645940 100644 --- a/activerecord/test/cases/named_scope_test.rb +++ b/activerecord/test/cases/named_scope_test.rb @@ -1,4 +1,4 @@ -require "cases/helper" +require File.expand_path('../helper', __FILE__) require 'active_support/core_ext/array/random_access' require 'models/post' require 'models/topic' @@ -456,6 +456,14 @@ class NamedScopeTest < ActiveRecord::TestCase end end + def test_scopes_to_get_newest + post = posts(:welcome) + old_last_comment = post.comments.newest + new_comment = post.comments.create(:body => "My new comment") + assert_equal new_comment, post.comments.newest + assert_not_equal old_last_comment, post.comments.newest + end + def test_scopes_are_reset_on_association_reload post = posts(:welcome) diff --git a/activerecord/test/cases/nested_attributes_test.rb b/activerecord/test/cases/nested_attributes_test.rb index 6568eb1d18..d94d4768a9 100644 --- a/activerecord/test/cases/nested_attributes_test.rb +++ b/activerecord/test/cases/nested_attributes_test.rb @@ -1,4 +1,4 @@ -require "cases/helper" +require File.expand_path('../helper', __FILE__) require "models/pirate" require "models/ship" require "models/ship_part" diff --git a/activerecord/test/cases/persistence_test.rb b/activerecord/test/cases/persistence_test.rb index 57d1441128..00543f7350 100644 --- a/activerecord/test/cases/persistence_test.rb +++ b/activerecord/test/cases/persistence_test.rb @@ -1,4 +1,4 @@ -require "cases/helper" +require File.expand_path('../helper', __FILE__) require 'models/post' require 'models/comment' require 'models/author' diff --git a/activerecord/test/cases/pooled_connections_test.rb b/activerecord/test/cases/pooled_connections_test.rb index 379cf5b44e..0321c5208f 100644 --- a/activerecord/test/cases/pooled_connections_test.rb +++ b/activerecord/test/cases/pooled_connections_test.rb @@ -1,4 +1,4 @@ -require "cases/helper" +require File.expand_path('../helper', __FILE__) require "models/project" require "timeout" diff --git a/activerecord/test/cases/primary_keys_test.rb b/activerecord/test/cases/primary_keys_test.rb index 05a41d8a0a..e810a155a0 100644 --- a/activerecord/test/cases/primary_keys_test.rb +++ b/activerecord/test/cases/primary_keys_test.rb @@ -1,4 +1,4 @@ -require "cases/helper" +require File.expand_path('../helper', __FILE__) require 'models/topic' require 'models/reply' require 'models/subscriber' diff --git a/activerecord/test/cases/query_cache_test.rb b/activerecord/test/cases/query_cache_test.rb index a61180cfaf..b08443b455 100644 --- a/activerecord/test/cases/query_cache_test.rb +++ b/activerecord/test/cases/query_cache_test.rb @@ -1,4 +1,4 @@ -require "cases/helper" +require File.expand_path('../helper', __FILE__) require 'models/topic' require 'models/task' require 'models/category' diff --git a/activerecord/test/cases/quoting_test.rb b/activerecord/test/cases/quoting_test.rb index 80ee74e41e..4cb38118c9 100644 --- a/activerecord/test/cases/quoting_test.rb +++ b/activerecord/test/cases/quoting_test.rb @@ -1,4 +1,4 @@ -require "cases/helper" +require File.expand_path('../helper', __FILE__) module ActiveRecord module ConnectionAdapters diff --git a/activerecord/test/cases/readonly_test.rb b/activerecord/test/cases/readonly_test.rb index e21109baae..88168776b1 100644 --- a/activerecord/test/cases/readonly_test.rb +++ b/activerecord/test/cases/readonly_test.rb @@ -1,4 +1,4 @@ -require "cases/helper" +require File.expand_path('../helper', __FILE__) require 'models/post' require 'models/comment' require 'models/developer' diff --git a/activerecord/test/cases/reflection_test.rb b/activerecord/test/cases/reflection_test.rb index 58c78ab058..c7288baaba 100644 --- a/activerecord/test/cases/reflection_test.rb +++ b/activerecord/test/cases/reflection_test.rb @@ -1,4 +1,4 @@ -require "cases/helper" +require File.expand_path('../helper', __FILE__) require 'models/topic' require 'models/customer' require 'models/company' diff --git a/activerecord/test/cases/relation_scoping_test.rb b/activerecord/test/cases/relation_scoping_test.rb index 8f8e72f052..5067384fb6 100644 --- a/activerecord/test/cases/relation_scoping_test.rb +++ b/activerecord/test/cases/relation_scoping_test.rb @@ -1,4 +1,4 @@ -require "cases/helper" +require File.expand_path('../helper', __FILE__) require 'models/post' require 'models/author' require 'models/developer' @@ -11,6 +11,14 @@ require 'models/reference' class RelationScopingTest < ActiveRecord::TestCase fixtures :authors, :developers, :projects, :comments, :posts, :developers_projects + def test_reverse_order + assert_equal Developer.order("id DESC").to_a.reverse, Developer.order("id DESC").reverse_order + end + + def test_double_reverse_order_produces_original_order + assert_equal Developer.order("name DESC"), Developer.order("name DESC").reverse_order.reverse_order + end + def test_scoped_find Developer.where("name = 'David'").scoping do assert_nothing_raised { Developer.find(1) } @@ -471,7 +479,23 @@ class DefaultScopingTest < ActiveRecord::TestCase assert_equal 10, DeveloperCalledJamis.unscoped.poor.length end + def test_default_scope_select_ignored_by_aggregations + assert_equal DeveloperWithSelect.all.count, DeveloperWithSelect.count + end + + def test_default_scope_select_ignored_by_grouped_aggregations + assert_equal Hash[Developer.all.group_by(&:salary).map { |s, d| [s, d.count] }], + DeveloperWithSelect.group(:salary).count + end + def test_default_scope_order_ignored_by_aggregations assert_equal DeveloperOrderedBySalary.all.count, DeveloperOrderedBySalary.count end + + def test_default_scope_find_last + assert DeveloperOrderedBySalary.count > 1, "need more than one row for test" + + lowest_salary_dev = DeveloperOrderedBySalary.find(developers(:poor_jamis).id) + assert_equal lowest_salary_dev, DeveloperOrderedBySalary.last + end end diff --git a/activerecord/test/cases/relation_test.rb b/activerecord/test/cases/relation_test.rb index 6874bd18f8..5ad089c875 100644 --- a/activerecord/test/cases/relation_test.rb +++ b/activerecord/test/cases/relation_test.rb @@ -1,4 +1,4 @@ -require "cases/helper" +require File.expand_path('../helper', __FILE__) require 'models/post' require 'models/comment' @@ -20,7 +20,7 @@ module ActiveRecord end def test_single_values - assert_equal [:limit, :offset, :lock, :readonly, :create_with, :from, :reorder].map(&:to_s).sort, + assert_equal [:limit, :offset, :lock, :readonly, :create_with, :from, :reorder, :reverse_order].map(&:to_s).sort, Relation::SINGLE_VALUE_METHODS.map(&:to_s).sort end diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb index fc9df8c7a3..ecc68b19d4 100644 --- a/activerecord/test/cases/relations_test.rb +++ b/activerecord/test/cases/relations_test.rb @@ -1,4 +1,4 @@ -require "cases/helper" +require File.expand_path('../helper', __FILE__) require 'models/tag' require 'models/tagging' require 'models/post' diff --git a/activerecord/test/cases/reload_models_test.rb b/activerecord/test/cases/reload_models_test.rb index 0d16a3526f..0ac46a2768 100644 --- a/activerecord/test/cases/reload_models_test.rb +++ b/activerecord/test/cases/reload_models_test.rb @@ -1,4 +1,4 @@ -require "cases/helper" +require File.expand_path('../helper', __FILE__) require 'models/owner' require 'models/pet' diff --git a/activerecord/test/cases/sanitize_test.rb b/activerecord/test/cases/sanitize_test.rb index 817897ceac..7c30bcf4c8 100644 --- a/activerecord/test/cases/sanitize_test.rb +++ b/activerecord/test/cases/sanitize_test.rb @@ -1,4 +1,4 @@ -require "cases/helper" +require File.expand_path('../helper', __FILE__) require 'models/binary' class SanitizeTest < ActiveRecord::TestCase diff --git a/activerecord/test/cases/schema_dumper_test.rb b/activerecord/test/cases/schema_dumper_test.rb index e8f2f44189..e765fdfe70 100644 --- a/activerecord/test/cases/schema_dumper_test.rb +++ b/activerecord/test/cases/schema_dumper_test.rb @@ -1,4 +1,4 @@ -require "cases/helper" +require File.expand_path('../helper', __FILE__) require 'stringio' @@ -230,4 +230,3 @@ class SchemaDumperTest < ActiveRecord::TestCase assert_match %r{t.string[[:space:]]+"id",[[:space:]]+:null => false$}, match[2], "non-primary key id column not preserved" end end - diff --git a/activerecord/test/cases/serialization_test.rb b/activerecord/test/cases/serialization_test.rb index 677d659f39..9c976f4999 100644 --- a/activerecord/test/cases/serialization_test.rb +++ b/activerecord/test/cases/serialization_test.rb @@ -1,4 +1,4 @@ -require "cases/helper" +require File.expand_path('../helper', __FILE__) require 'models/contact' require 'models/topic' require 'models/reply' diff --git a/activerecord/test/cases/session_store/session_test.rb b/activerecord/test/cases/session_store/session_test.rb index 669c0b7b4d..fb6f4cfd44 100644 --- a/activerecord/test/cases/session_store/session_test.rb +++ b/activerecord/test/cases/session_store/session_test.rb @@ -1,4 +1,4 @@ -require 'cases/helper' +require File.expand_path('../../helper', __FILE__) require 'action_dispatch' require 'active_record/session_store' diff --git a/activerecord/test/cases/session_store/sql_bypass.rb b/activerecord/test/cases/session_store/sql_bypass.rb index 7402b2afd6..97ccb1f5c9 100644 --- a/activerecord/test/cases/session_store/sql_bypass.rb +++ b/activerecord/test/cases/session_store/sql_bypass.rb @@ -1,4 +1,4 @@ -require 'cases/helper' +require File.expand_path('../../helper', __FILE__) require 'action_dispatch' require 'active_record/session_store' diff --git a/activerecord/test/cases/timestamp_test.rb b/activerecord/test/cases/timestamp_test.rb index 22d4cac422..ce6419c0da 100644 --- a/activerecord/test/cases/timestamp_test.rb +++ b/activerecord/test/cases/timestamp_test.rb @@ -1,4 +1,4 @@ -require 'cases/helper' +require File.expand_path('../helper', __FILE__) require 'models/developer' require 'models/owner' require 'models/pet' @@ -14,32 +14,6 @@ class TimestampTest < ActiveRecord::TestCase @previously_updated_at = @developer.updated_at end - def test_load_infinity_and_beyond - unless current_adapter?(:PostgreSQLAdapter) - return skip("only tested on postgresql") - end - - d = Developer.find_by_sql("select 'infinity'::timestamp as updated_at") - assert d.first.updated_at.infinite?, 'timestamp should be infinite' - - d = Developer.find_by_sql("select '-infinity'::timestamp as updated_at") - time = d.first.updated_at - assert time.infinite?, 'timestamp should be infinite' - assert_operator time, :<, 0 - end - - def test_save_infinity_and_beyond - unless current_adapter?(:PostgreSQLAdapter) - return skip("only tested on postgresql") - end - - d = Developer.create!(:name => 'aaron', :updated_at => 1.0 / 0.0) - assert_equal(1.0 / 0.0, d.updated_at) - - d = Developer.create!(:name => 'aaron', :updated_at => -1.0 / 0.0) - assert_equal(-1.0 / 0.0, d.updated_at) - end - def test_saving_a_changed_record_updates_its_timestamp @developer.name = "Jack Bauer" @developer.save! diff --git a/activerecord/test/cases/transaction_callbacks_test.rb b/activerecord/test/cases/transaction_callbacks_test.rb index 85f222bca2..2d88e660b3 100644 --- a/activerecord/test/cases/transaction_callbacks_test.rb +++ b/activerecord/test/cases/transaction_callbacks_test.rb @@ -1,4 +1,4 @@ -require "cases/helper" +require File.expand_path('../helper', __FILE__) require 'models/topic' class TransactionCallbacksTest < ActiveRecord::TestCase diff --git a/activerecord/test/cases/transactions_test.rb b/activerecord/test/cases/transactions_test.rb index 110a18772f..fa33ffaed3 100644 --- a/activerecord/test/cases/transactions_test.rb +++ b/activerecord/test/cases/transactions_test.rb @@ -1,4 +1,4 @@ -require "cases/helper" +require File.expand_path('../helper', __FILE__) require 'models/topic' require 'models/reply' require 'models/developer' diff --git a/activerecord/test/cases/unconnected_test.rb b/activerecord/test/cases/unconnected_test.rb index f85fb4e5da..a6aaf1eb3d 100644 --- a/activerecord/test/cases/unconnected_test.rb +++ b/activerecord/test/cases/unconnected_test.rb @@ -1,4 +1,4 @@ -require "cases/helper" +require File.expand_path('../helper', __FILE__) class TestRecord < ActiveRecord::Base end diff --git a/activerecord/test/cases/validations/association_validation_test.rb b/activerecord/test/cases/validations/association_validation_test.rb index 56e345990f..45290680f9 100644 --- a/activerecord/test/cases/validations/association_validation_test.rb +++ b/activerecord/test/cases/validations/association_validation_test.rb @@ -1,5 +1,5 @@ # encoding: utf-8 -require "cases/helper" +require File.expand_path('../../helper', __FILE__) require 'models/topic' require 'models/reply' require 'models/owner' diff --git a/activerecord/test/cases/validations/i18n_generate_message_validation_test.rb b/activerecord/test/cases/validations/i18n_generate_message_validation_test.rb index 628029f8df..922fb5dce7 100644 --- a/activerecord/test/cases/validations/i18n_generate_message_validation_test.rb +++ b/activerecord/test/cases/validations/i18n_generate_message_validation_test.rb @@ -1,4 +1,4 @@ -require "cases/helper" +require File.expand_path('../../helper', __FILE__) require 'models/topic' class I18nGenerateMessageValidationTest < ActiveRecord::TestCase diff --git a/activerecord/test/cases/validations/i18n_validation_test.rb b/activerecord/test/cases/validations/i18n_validation_test.rb index 15b97c02c8..46f0c3c49d 100644 --- a/activerecord/test/cases/validations/i18n_validation_test.rb +++ b/activerecord/test/cases/validations/i18n_validation_test.rb @@ -1,4 +1,4 @@ -require "cases/helper" +require File.expand_path('../../helper', __FILE__) require 'models/topic' require 'models/reply' diff --git a/activerecord/test/cases/validations/uniqueness_validation_test.rb b/activerecord/test/cases/validations/uniqueness_validation_test.rb index 0f1b3667cc..218f673451 100644 --- a/activerecord/test/cases/validations/uniqueness_validation_test.rb +++ b/activerecord/test/cases/validations/uniqueness_validation_test.rb @@ -1,5 +1,5 @@ # encoding: utf-8 -require "cases/helper" +require File.expand_path('../../helper', __FILE__) require 'models/topic' require 'models/reply' require 'models/warehouse_thing' diff --git a/activerecord/test/cases/validations_test.rb b/activerecord/test/cases/validations_test.rb index c3e494866b..8764a22d40 100644 --- a/activerecord/test/cases/validations_test.rb +++ b/activerecord/test/cases/validations_test.rb @@ -1,5 +1,5 @@ # encoding: utf-8 -require "cases/helper" +require File.expand_path('../helper', __FILE__) require 'models/topic' require 'models/reply' require 'models/person' diff --git a/activerecord/test/cases/xml_serialization_test.rb b/activerecord/test/cases/xml_serialization_test.rb index 756c8a32eb..c48957e7a7 100644 --- a/activerecord/test/cases/xml_serialization_test.rb +++ b/activerecord/test/cases/xml_serialization_test.rb @@ -1,4 +1,4 @@ -require "cases/helper" +require File.expand_path('../helper', __FILE__) require 'models/contact' require 'models/post' require 'models/author' diff --git a/activerecord/test/cases/yaml_serialization_test.rb b/activerecord/test/cases/yaml_serialization_test.rb index 0b54c309d1..6caa782a97 100644 --- a/activerecord/test/cases/yaml_serialization_test.rb +++ b/activerecord/test/cases/yaml_serialization_test.rb @@ -1,4 +1,4 @@ -require "cases/helper" +require File.expand_path('../helper', __FILE__) require 'models/topic' class YamlSerializationTest < ActiveRecord::TestCase diff --git a/activerecord/test/config.example.yml b/activerecord/test/config.example.yml new file mode 100644 index 0000000000..6ed38db66d --- /dev/null +++ b/activerecord/test/config.example.yml @@ -0,0 +1,136 @@ +default_connection: <%= defined?(JRUBY_VERSION) ? 'jdbcsqlite3' : 'sqlite3' %> + +connections: + jdbcderby: + arunit: activerecord_unittest + arunit2: activerecord_unittest2 + + jdbch2: + arunit: activerecord_unittest + arunit2: activerecord_unittest2 + + jdbchsqldb: + arunit: activerecord_unittest + arunit2: activerecord_unittest2 + + jdbcmysql: + arunit: + username: rails + encoding: utf8 + arunit2: + username: rails + encoding: utf8 + + jdbcpostgresql: + arunit: + username: <%= ENV['user'] || 'rails' %> + arunit2: + username: <%= ENV['user'] || 'rails' %> + + jdbcsqlite3: + arunit: + database: <%= FIXTURES_ROOT %>/fixture_database.sqlite3 + timeout: 5000 + arunit2: + database: <%= FIXTURES_ROOT %>/fixture_database_2.sqlite3 + timeout: 5000 + + db2: + arunit: + host: localhost + username: arunit + password: arunit + database: arunit + arunit2: + host: localhost + username: arunit + password: arunit + database: arunit2 + + firebird: + arunit: + host: localhost + username: rails + password: rails + charset: UTF8 + arunit2: + host: localhost + username: rails + password: rails + charset: UTF8 + + frontbase: + arunit: + host: localhost + username: rails + session_name: unittest-<%= $$ %> + arunit2: + host: localhost + username: rails + session_name: unittest-<%= $$ %> + + mysql: + arunit: + username: rails + encoding: utf8 + arunit2: + username: rails + encoding: utf8 + + mysql2: + arunit: + username: rails + encoding: utf8 + arunit2: + username: rails + encoding: utf8 + + openbase: + arunit: + username: admin + arunit2: + username: admin + + oracle: + arunit: + adapter: oracle_enhanced + database: <%= ENV['ARUNIT_DB_NAME'] || 'orcl' %> + username: arunit + password: arunit + emulate_oracle_adapter: true + arunit: + adapter: oracle_enhanced + database: <%= ENV['ARUNIT_DB_NAME'] || 'orcl' %> + username: arunit2 + password: arunit2 + emulate_oracle_adapter: true + + postgresql: + arunit: + min_messages: warning + arunit2: + min_messages: warning + + sqlite3: + arunit: + database: <%= FIXTURES_ROOT %>/fixture_database.sqlite3 + timeout: 5000 + arunit2: + database: <%= FIXTURES_ROOT %>/fixture_database_2.sqlite3 + timeout: 5000 + + sqlite3_mem: + arunit: + adapter: sqlite3 + database: ':memory:' + arunit2: + adapter: sqlite3 + database: ':memory:' + + sybase: + arunit: + host: database_ASE + username: sa + arunit2: + host: database_ASE + username: sa diff --git a/activerecord/test/connections/db2.rb b/activerecord/test/connections/db2.rb new file mode 100644 index 0000000000..f43b3fda57 --- /dev/null +++ b/activerecord/test/connections/db2.rb @@ -0,0 +1 @@ +ENV['ARCONN'] = 'db2' diff --git a/activerecord/test/connections/firebird.rb b/activerecord/test/connections/firebird.rb new file mode 100644 index 0000000000..fa874c0bb3 --- /dev/null +++ b/activerecord/test/connections/firebird.rb @@ -0,0 +1 @@ +ENV['ARCONN'] = 'firebird' diff --git a/activerecord/test/connections/frontbase.rb b/activerecord/test/connections/frontbase.rb new file mode 100644 index 0000000000..9d1d5597d4 --- /dev/null +++ b/activerecord/test/connections/frontbase.rb @@ -0,0 +1 @@ +ENV['ARCONN'] = 'frontbase' diff --git a/activerecord/test/connections/jdbc_jdbcderby/connection.rb b/activerecord/test/connections/jdbc_jdbcderby/connection.rb deleted file mode 100644 index 222ef5db38..0000000000 --- a/activerecord/test/connections/jdbc_jdbcderby/connection.rb +++ /dev/null @@ -1,18 +0,0 @@ -print "Using Derby via JRuby, activerecord-jdbc-adapter and activerecord-jdbcderby-adapter\n" -require_dependency 'models/course' -require 'logger' -ActiveRecord::Base.logger = Logger.new("debug.log") - -ActiveRecord::Base.configurations = { - 'arunit' => { - :adapter => 'jdbcderby', - :database => 'activerecord_unittest' - }, - 'arunit2' => { - :adapter => 'jdbcderby', - :database => 'activerecord_unittest2' - } -} - -ActiveRecord::Base.establish_connection 'arunit' -Course.establish_connection 'arunit2' diff --git a/activerecord/test/connections/jdbc_jdbch2/connection.rb b/activerecord/test/connections/jdbc_jdbch2/connection.rb deleted file mode 100644 index 9d2875e8e7..0000000000 --- a/activerecord/test/connections/jdbc_jdbch2/connection.rb +++ /dev/null @@ -1,18 +0,0 @@ -print "Using H2 via JRuby, activerecord-jdbc-adapter and activerecord-jdbch2-adapter\n" -require_dependency 'models/course' -require 'logger' -ActiveRecord::Base.logger = Logger.new("debug.log") - -ActiveRecord::Base.configurations = { - 'arunit' => { - :adapter => 'jdbch2', - :database => 'activerecord_unittest' - }, - 'arunit2' => { - :adapter => 'jdbch2', - :database => 'activerecord_unittest2' - } -} - -ActiveRecord::Base.establish_connection 'arunit' -Course.establish_connection 'arunit2' diff --git a/activerecord/test/connections/jdbc_jdbchsqldb/connection.rb b/activerecord/test/connections/jdbc_jdbchsqldb/connection.rb deleted file mode 100644 index fa943c2c76..0000000000 --- a/activerecord/test/connections/jdbc_jdbchsqldb/connection.rb +++ /dev/null @@ -1,18 +0,0 @@ -print "Using HSQLDB via JRuby, activerecord-jdbc-adapter and activerecord-jdbchsqldb-adapter\n" -require_dependency 'models/course' -require 'logger' -ActiveRecord::Base.logger = Logger.new("debug.log") - -ActiveRecord::Base.configurations = { - 'arunit' => { - :adapter => 'jdbchsqldb', - :database => 'activerecord_unittest' - }, - 'arunit2' => { - :adapter => 'jdbchsqldb', - :database => 'activerecord_unittest2' - } -} - -ActiveRecord::Base.establish_connection 'arunit' -Course.establish_connection 'arunit2' diff --git a/activerecord/test/connections/jdbc_jdbcmysql/connection.rb b/activerecord/test/connections/jdbc_jdbcmysql/connection.rb deleted file mode 100644 index e2517a50eb..0000000000 --- a/activerecord/test/connections/jdbc_jdbcmysql/connection.rb +++ /dev/null @@ -1,26 +0,0 @@ -print "Using MySQL via JRuby, activerecord-jdbc-adapter and activerecord-jdbcmysql-adapter\n" -require_dependency 'models/course' -require 'logger' - -ActiveRecord::Base.logger = Logger.new("debug.log") - -# GRANT ALL PRIVILEGES ON activerecord_unittest.* to 'rails'@'localhost'; -# GRANT ALL PRIVILEGES ON activerecord_unittest2.* to 'rails'@'localhost'; - -ActiveRecord::Base.configurations = { - 'arunit' => { - :adapter => 'jdbcmysql', - :username => 'rails', - :encoding => 'utf8', - :database => 'activerecord_unittest', - }, - 'arunit2' => { - :adapter => 'jdbcmysql', - :username => 'rails', - :database => 'activerecord_unittest2' - } -} - -ActiveRecord::Base.establish_connection 'arunit' -Course.establish_connection 'arunit2' - diff --git a/activerecord/test/connections/jdbc_jdbcpostgresql/connection.rb b/activerecord/test/connections/jdbc_jdbcpostgresql/connection.rb deleted file mode 100644 index 0685da4433..0000000000 --- a/activerecord/test/connections/jdbc_jdbcpostgresql/connection.rb +++ /dev/null @@ -1,26 +0,0 @@ -print "Using Postgrsql via JRuby, activerecord-jdbc-adapter and activerecord-postgresql-adapter\n" -require_dependency 'models/course' -require 'logger' - -ActiveRecord::Base.logger = Logger.new("debug.log") - -# createuser rails --createdb --no-superuser --no-createrole -# createdb -O rails activerecord_unittest -# createdb -O rails activerecord_unittest2 - -ActiveRecord::Base.configurations = { - 'arunit' => { - :adapter => 'jdbcpostgresql', - :username => ENV['USER'] || 'rails', - :database => 'activerecord_unittest' - }, - 'arunit2' => { - :adapter => 'jdbcpostgresql', - :username => ENV['USER'] || 'rails', - :database => 'activerecord_unittest2' - } -} - -ActiveRecord::Base.establish_connection 'arunit' -Course.establish_connection 'arunit2' - diff --git a/activerecord/test/connections/jdbc_jdbcsqlite3/connection.rb b/activerecord/test/connections/jdbc_jdbcsqlite3/connection.rb deleted file mode 100644 index 26d4676ff3..0000000000 --- a/activerecord/test/connections/jdbc_jdbcsqlite3/connection.rb +++ /dev/null @@ -1,25 +0,0 @@ -print "Using SQLite3 via JRuby, activerecord-jdbc-adapter and activerecord-jdbcsqlite3-adapter\n" -require_dependency 'models/course' -require 'logger' -ActiveRecord::Base.logger = Logger.new("debug.log") - -class SqliteError < StandardError -end - -BASE_DIR = FIXTURES_ROOT -sqlite_test_db = "#{BASE_DIR}/fixture_database.sqlite3" -sqlite_test_db2 = "#{BASE_DIR}/fixture_database_2.sqlite3" - -def make_connection(clazz, db_file) - ActiveRecord::Base.configurations = { clazz.name => { :adapter => 'jdbcsqlite3', :database => db_file, :timeout => 5000 } } - unless File.exist?(db_file) - puts "SQLite3 database not found at #{db_file}. Rebuilding it." - sqlite_command = %Q{sqlite3 "#{db_file}" "create table a (a integer); drop table a;"} - puts "Executing '#{sqlite_command}'" - raise SqliteError.new("Seems that there is no sqlite3 executable available") unless system(sqlite_command) - end - clazz.establish_connection(clazz.name) -end - -make_connection(ActiveRecord::Base, sqlite_test_db) -make_connection(Course, sqlite_test_db2) diff --git a/activerecord/test/connections/jdbcderby.rb b/activerecord/test/connections/jdbcderby.rb new file mode 100644 index 0000000000..1c7b63ccdc --- /dev/null +++ b/activerecord/test/connections/jdbcderby.rb @@ -0,0 +1 @@ +ENV['ARCONN'] = 'jdbcderby' diff --git a/activerecord/test/connections/jdbch2.rb b/activerecord/test/connections/jdbch2.rb new file mode 100644 index 0000000000..d2fb177ae3 --- /dev/null +++ b/activerecord/test/connections/jdbch2.rb @@ -0,0 +1 @@ +ENV['ARCONN'] = 'jdbch2' diff --git a/activerecord/test/connections/jdbchsqldb.rb b/activerecord/test/connections/jdbchsqldb.rb new file mode 100644 index 0000000000..22e6d8729e --- /dev/null +++ b/activerecord/test/connections/jdbchsqldb.rb @@ -0,0 +1 @@ +ENV['ARCONN'] = 'jdbchsqldb' diff --git a/activerecord/test/connections/jdbcmysql.rb b/activerecord/test/connections/jdbcmysql.rb new file mode 100644 index 0000000000..f1aaad93a3 --- /dev/null +++ b/activerecord/test/connections/jdbcmysql.rb @@ -0,0 +1 @@ +ENV['ARCONN'] = 'jdbcmysql' diff --git a/activerecord/test/connections/jdbcpostgresql.rb b/activerecord/test/connections/jdbcpostgresql.rb new file mode 100644 index 0000000000..6809115f36 --- /dev/null +++ b/activerecord/test/connections/jdbcpostgresql.rb @@ -0,0 +1 @@ +ENV['ARCONN'] = 'jdbcpostgresql' diff --git a/activerecord/test/connections/jdbcsqlite3.rb b/activerecord/test/connections/jdbcsqlite3.rb new file mode 100644 index 0000000000..9cc872905a --- /dev/null +++ b/activerecord/test/connections/jdbcsqlite3.rb @@ -0,0 +1 @@ +ENV['ARCONN'] = 'jdbcsqlite3' diff --git a/activerecord/test/connections/mysql.rb b/activerecord/test/connections/mysql.rb new file mode 100644 index 0000000000..2f30603098 --- /dev/null +++ b/activerecord/test/connections/mysql.rb @@ -0,0 +1 @@ +ENV['ARCONN'] = 'mysql' diff --git a/activerecord/test/connections/mysql2.rb b/activerecord/test/connections/mysql2.rb new file mode 100644 index 0000000000..10aa9171bd --- /dev/null +++ b/activerecord/test/connections/mysql2.rb @@ -0,0 +1 @@ +ENV['ARCONN'] = 'mysql2' diff --git a/activerecord/test/connections/native_db2/connection.rb b/activerecord/test/connections/native_db2/connection.rb deleted file mode 100644 index 324315d2c8..0000000000 --- a/activerecord/test/connections/native_db2/connection.rb +++ /dev/null @@ -1,25 +0,0 @@ -print "Using native DB2\n" -require_dependency 'models/course' -require 'logger' - -ActiveRecord::Base.logger = Logger.new("debug.log") - -ActiveRecord::Base.configurations = { - 'arunit' => { - :adapter => 'db2', - :host => 'localhost', - :username => 'arunit', - :password => 'arunit', - :database => 'arunit' - }, - 'arunit2' => { - :adapter => 'db2', - :host => 'localhost', - :username => 'arunit', - :password => 'arunit', - :database => 'arunit2' - } -} - -ActiveRecord::Base.establish_connection 'arunit' -Course.establish_connection 'arunit2' diff --git a/activerecord/test/connections/native_firebird/connection.rb b/activerecord/test/connections/native_firebird/connection.rb deleted file mode 100644 index 67a936ca97..0000000000 --- a/activerecord/test/connections/native_firebird/connection.rb +++ /dev/null @@ -1,26 +0,0 @@ -print "Using native Firebird\n" -require_dependency 'models/course' -require 'logger' - -ActiveRecord::Base.logger = Logger.new("debug.log") - -ActiveRecord::Base.configurations = { - 'arunit' => { - :adapter => 'firebird', - :host => 'localhost', - :username => 'rails', - :password => 'rails', - :database => 'activerecord_unittest', - :charset => 'UTF8' - }, - 'arunit2' => { - :adapter => 'firebird', - :host => 'localhost', - :username => 'rails', - :password => 'rails', - :database => 'activerecord_unittest2' - } -} - -ActiveRecord::Base.establish_connection 'arunit' -Course.establish_connection 'arunit2' diff --git a/activerecord/test/connections/native_frontbase/connection.rb b/activerecord/test/connections/native_frontbase/connection.rb deleted file mode 100644 index c01d864a8b..0000000000 --- a/activerecord/test/connections/native_frontbase/connection.rb +++ /dev/null @@ -1,27 +0,0 @@ -puts 'Using native Frontbase' -require_dependency 'models/course' -require 'logger' - -ActiveRecord::Base.logger = Logger.new("debug.log") - -ActiveRecord::Base.configurations = { - 'arunit' => { - :adapter => 'frontbase', - :host => 'localhost', - :username => 'rails', - :password => '', - :database => 'activerecord_unittest', - :session_name => "unittest-#{$$}" - }, - 'arunit2' => { - :adapter => 'frontbase', - :host => 'localhost', - :username => 'rails', - :password => '', - :database => 'activerecord_unittest2', - :session_name => "unittest-#{$$}" - } -} - -ActiveRecord::Base.establish_connection 'arunit' -Course.establish_connection 'arunit2' diff --git a/activerecord/test/connections/native_mysql/connection.rb b/activerecord/test/connections/native_mysql/connection.rb deleted file mode 100644 index 140e06d631..0000000000 --- a/activerecord/test/connections/native_mysql/connection.rb +++ /dev/null @@ -1,25 +0,0 @@ -print "Using native MySQL\n" -require_dependency 'models/course' -require 'logger' - -ActiveRecord::Base.logger = Logger.new("debug.log") - -# GRANT ALL PRIVILEGES ON activerecord_unittest.* to 'rails'@'localhost'; -# GRANT ALL PRIVILEGES ON activerecord_unittest2.* to 'rails'@'localhost'; - -ActiveRecord::Base.configurations = { - 'arunit' => { - :adapter => 'mysql', - :username => 'rails', - :encoding => 'utf8', - :database => 'activerecord_unittest', - }, - 'arunit2' => { - :adapter => 'mysql', - :username => 'rails', - :database => 'activerecord_unittest2' - } -} - -ActiveRecord::Base.establish_connection 'arunit' -Course.establish_connection 'arunit2' diff --git a/activerecord/test/connections/native_mysql2/connection.rb b/activerecord/test/connections/native_mysql2/connection.rb deleted file mode 100644 index c6f198b1ac..0000000000 --- a/activerecord/test/connections/native_mysql2/connection.rb +++ /dev/null @@ -1,25 +0,0 @@ -print "Using native Mysql2\n" -require_dependency 'models/course' -require 'logger' - -ActiveRecord::Base.logger = Logger.new("debug.log") - -# GRANT ALL PRIVILEGES ON activerecord_unittest.* to 'rails'@'localhost'; -# GRANT ALL PRIVILEGES ON activerecord_unittest2.* to 'rails'@'localhost'; - -ActiveRecord::Base.configurations = { - 'arunit' => { - :adapter => 'mysql2', - :username => 'rails', - :encoding => 'utf8', - :database => 'activerecord_unittest', - }, - 'arunit2' => { - :adapter => 'mysql2', - :username => 'rails', - :database => 'activerecord_unittest2' - } -} - -ActiveRecord::Base.establish_connection 'arunit' -Course.establish_connection 'arunit2' diff --git a/activerecord/test/connections/native_openbase/connection.rb b/activerecord/test/connections/native_openbase/connection.rb deleted file mode 100644 index 655cb9ca26..0000000000 --- a/activerecord/test/connections/native_openbase/connection.rb +++ /dev/null @@ -1,21 +0,0 @@ -print "Using native OpenBase\n" -require_dependency 'models/course' -require 'logger' - -ActiveRecord::Base.logger = Logger.new("debug.log") - -ActiveRecord::Base.configurations = { - 'arunit' => { - :adapter => 'openbase', - :username => 'admin', - :database => 'activerecord_unittest', - }, - 'arunit2' => { - :adapter => 'openbase', - :username => 'admin', - :database => 'activerecord_unittest2' - } -} - -ActiveRecord::Base.establish_connection 'arunit' -Course.establish_connection 'arunit2' diff --git a/activerecord/test/connections/native_oracle/connection.rb b/activerecord/test/connections/native_oracle/connection.rb deleted file mode 100644 index 99f921879c..0000000000 --- a/activerecord/test/connections/native_oracle/connection.rb +++ /dev/null @@ -1,35 +0,0 @@ -# uses oracle_enhanced adapter in ENV['ORACLE_ENHANCED_PATH'] or from github.com/rsim/oracle-enhanced.git -require 'active_record/connection_adapters/oracle_enhanced_adapter' - -# otherwise failed with silence_warnings method missing exception -require 'active_support/core_ext/kernel/reporting' - -print "Using Oracle\n" -require_dependency 'models/course' -require 'logger' - -ActiveRecord::Base.logger = Logger.new("debug.log") - -# Set these to your database connection strings -ENV['ARUNIT_DB_NAME'] ||= 'orcl' - -ActiveRecord::Base.configurations = { - 'arunit' => { - :adapter => 'oracle_enhanced', - :database => ENV['ARUNIT_DB_NAME'], - :username => 'arunit', - :password => 'arunit', - :emulate_oracle_adapter => true - }, - 'arunit2' => { - :adapter => 'oracle_enhanced', - :database => ENV['ARUNIT_DB_NAME'], - :username => 'arunit2', - :password => 'arunit2', - :emulate_oracle_adapter => true - } -} - -ActiveRecord::Base.establish_connection 'arunit' -Course.establish_connection 'arunit2' - diff --git a/activerecord/test/connections/native_postgresql/connection.rb b/activerecord/test/connections/native_postgresql/connection.rb deleted file mode 100644 index 3b5ff90003..0000000000 --- a/activerecord/test/connections/native_postgresql/connection.rb +++ /dev/null @@ -1,21 +0,0 @@ -print "Using native PostgreSQL\n" -require_dependency 'models/course' -require 'logger' - -ActiveRecord::Base.logger = Logger.new("debug.log") - -ActiveRecord::Base.configurations = { - 'arunit' => { - :adapter => 'postgresql', - :database => 'activerecord_unittest', - :min_messages => 'warning' - }, - 'arunit2' => { - :adapter => 'postgresql', - :database => 'activerecord_unittest2', - :min_messages => 'warning' - } -} - -ActiveRecord::Base.establish_connection 'arunit' -Course.establish_connection 'arunit2' diff --git a/activerecord/test/connections/native_sqlite3/connection.rb b/activerecord/test/connections/native_sqlite3/connection.rb deleted file mode 100644 index c2aff5551f..0000000000 --- a/activerecord/test/connections/native_sqlite3/connection.rb +++ /dev/null @@ -1,16 +0,0 @@ -print "Using native SQLite3\n" -require_dependency 'models/course' -require 'logger' -ActiveRecord::Base.logger = Logger.new("debug.log") - -BASE_DIR = FIXTURES_ROOT -sqlite_test_db = "#{BASE_DIR}/fixture_database.sqlite3" -sqlite_test_db2 = "#{BASE_DIR}/fixture_database_2.sqlite3" - -def make_connection(clazz, db_file) - ActiveRecord::Base.configurations = { clazz.name => { :adapter => 'sqlite3', :database => db_file, :timeout => 5000 } } - clazz.establish_connection(clazz.name) -end - -make_connection(ActiveRecord::Base, sqlite_test_db) -make_connection(Course, sqlite_test_db2) diff --git a/activerecord/test/connections/native_sqlite3_mem/connection.rb b/activerecord/test/connections/native_sqlite3_mem/connection.rb deleted file mode 100644 index 14e10900d1..0000000000 --- a/activerecord/test/connections/native_sqlite3_mem/connection.rb +++ /dev/null @@ -1,19 +0,0 @@ -# This file connects to an in-memory SQLite3 database, which is a very fast way to run the tests. -# The downside is that disconnect from the database results in the database effectively being -# wiped. For this reason, pooled_connections_test.rb is disabled when using an in-memory database. - -print "Using native SQLite3 (in memory)\n" -require_dependency 'models/course' -require 'logger' -ActiveRecord::Base.logger = Logger.new("debug.log") - -class SqliteError < StandardError -end - -def make_connection(clazz) - ActiveRecord::Base.configurations = { clazz.name => { :adapter => 'sqlite3', :database => ':memory:' } } - clazz.establish_connection(clazz.name) -end - -make_connection(ActiveRecord::Base) -make_connection(Course) diff --git a/activerecord/test/connections/native_sybase/connection.rb b/activerecord/test/connections/native_sybase/connection.rb deleted file mode 100644 index 3282d26922..0000000000 --- a/activerecord/test/connections/native_sybase/connection.rb +++ /dev/null @@ -1,23 +0,0 @@ -print "Using native Sybase Open Client\n" -require_dependency 'models/course' -require 'logger' - -ActiveRecord::Base.logger = Logger.new("debug.log") - -ActiveRecord::Base.configurations = { - 'arunit' => { - :adapter => 'sybase', - :host => 'database_ASE', - :username => 'sa', - :database => 'activerecord_unittest' - }, - 'arunit2' => { - :adapter => 'sybase', - :host => 'database_ASE', - :username => 'sa', - :database => 'activerecord_unittest2' - } -} - -ActiveRecord::Base.establish_connection 'arunit' -Course.establish_connection 'arunit2' diff --git a/activerecord/test/connections/openbase.rb b/activerecord/test/connections/openbase.rb new file mode 100644 index 0000000000..bf072579f4 --- /dev/null +++ b/activerecord/test/connections/openbase.rb @@ -0,0 +1 @@ +ENV['ARCONN'] = 'openbase' diff --git a/activerecord/test/connections/oracle.rb b/activerecord/test/connections/oracle.rb new file mode 100644 index 0000000000..dc64f7c5fc --- /dev/null +++ b/activerecord/test/connections/oracle.rb @@ -0,0 +1,7 @@ +ENV['ARCONN'] = 'oracle' + +# uses oracle_enhanced adapter in ENV['ORACLE_ENHANCED_PATH'] or from github.com/rsim/oracle-enhanced.git +require 'active_record/connection_adapters/oracle_enhanced_adapter' + +# otherwise failed with silence_warnings method missing exception +require 'active_support/core_ext/kernel/reporting' diff --git a/activerecord/test/connections/postgresql.rb b/activerecord/test/connections/postgresql.rb new file mode 100644 index 0000000000..b8bfb6e846 --- /dev/null +++ b/activerecord/test/connections/postgresql.rb @@ -0,0 +1 @@ +ENV['ARCONN'] = 'postgresql' diff --git a/activerecord/test/connections/sqlite3.rb b/activerecord/test/connections/sqlite3.rb new file mode 100644 index 0000000000..e5c75657a5 --- /dev/null +++ b/activerecord/test/connections/sqlite3.rb @@ -0,0 +1 @@ +ENV['ARCONN'] = 'sqlite3' diff --git a/activerecord/test/connections/sqlite3_mem.rb b/activerecord/test/connections/sqlite3_mem.rb new file mode 100644 index 0000000000..900a5c7947 --- /dev/null +++ b/activerecord/test/connections/sqlite3_mem.rb @@ -0,0 +1 @@ +ENV['ARCONN'] = 'sqlite3_mem' diff --git a/activerecord/test/connections/sybase.rb b/activerecord/test/connections/sybase.rb new file mode 100644 index 0000000000..7decdf7f39 --- /dev/null +++ b/activerecord/test/connections/sybase.rb @@ -0,0 +1 @@ +ENV['ARCONN'] = 'sybase' diff --git a/activerecord/test/models/comment.rb b/activerecord/test/models/comment.rb index 2a4c37089a..43650c0427 100644 --- a/activerecord/test/models/comment.rb +++ b/activerecord/test/models/comment.rb @@ -6,7 +6,8 @@ class Comment < ActiveRecord::Base scope :for_first_author, :joins => :post, :conditions => { "posts.author_id" => 1 } - + scope :created + belongs_to :post, :counter_cache => true has_many :ratings diff --git a/activerecord/test/models/contract.rb b/activerecord/test/models/contract.rb index 94fd48e12a..2cf5aa7a85 100644 --- a/activerecord/test/models/contract.rb +++ b/activerecord/test/models/contract.rb @@ -1,4 +1,19 @@ class Contract < ActiveRecord::Base belongs_to :company belongs_to :developer + + before_save :hi + after_save :bye + + attr_accessor :hi_count, :bye_count + + def hi + @hi_count ||= 0 + @hi_count += 1 + end + + def bye + @bye_count ||= 0 + @bye_count += 1 + end end diff --git a/activerecord/test/models/developer.rb b/activerecord/test/models/developer.rb index 41c52f7df0..98d6aa22f7 100644 --- a/activerecord/test/models/developer.rb +++ b/activerecord/test/models/developer.rb @@ -86,6 +86,11 @@ class DeveloperWithBeforeDestroyRaise < ActiveRecord::Base end end +class DeveloperWithSelect < ActiveRecord::Base + self.table_name = 'developers' + default_scope select('name') +end + class DeveloperOrderedBySalary < ActiveRecord::Base self.table_name = 'developers' default_scope :order => 'salary DESC' diff --git a/activerecord/test/models/post.rb b/activerecord/test/models/post.rb index f2ab7b053e..affa37b02d 100644 --- a/activerecord/test/models/post.rb +++ b/activerecord/test/models/post.rb @@ -36,6 +36,10 @@ class Post < ActiveRecord::Base def find_most_recent find(:first, :order => "id DESC") end + + def newest + created.last + end end has_many :author_favorites, :through => :author diff --git a/activerecord/test/support/config.rb b/activerecord/test/support/config.rb new file mode 100644 index 0000000000..2760d88d20 --- /dev/null +++ b/activerecord/test/support/config.rb @@ -0,0 +1,39 @@ +require 'yaml' +require 'erubis' +require 'fileutils' + +module ARTest + class << self + def config + @config ||= read_config + end + + private + + def read_config + unless File.exist?(TEST_ROOT + '/config.yml') + FileUtils.cp TEST_ROOT + '/config.example.yml', TEST_ROOT + '/config.yml' + end + + raw = File.read(TEST_ROOT + '/config.yml') + erb = Erubis::Eruby.new(raw) + expand_config(YAML.parse(erb.result(binding)).transform) + end + + def expand_config(config) + config['connections'].each do |adapter, connection| + dbs = [['arunit', 'activerecord_unittest'], ['arunit2', 'activerecord_unittest']] + dbs.each do |name, dbname| + unless connection[name].is_a?(Hash) + connection[name] = { 'database' => connection[name] } + end + + connection[name]['database'] ||= dbname + connection[name]['adapter'] ||= adapter + end + end + + config + end + end +end diff --git a/activerecord/test/support/connection.rb b/activerecord/test/support/connection.rb new file mode 100644 index 0000000000..f4123c694d --- /dev/null +++ b/activerecord/test/support/connection.rb @@ -0,0 +1,13 @@ +require 'logger' +require_dependency 'models/course' + +module ARTest + def self.connect + connection_name = ENV['ARCONN'] || config['default_connection'] + puts "Using #{connection_name}" + ActiveRecord::Base.logger = Logger.new("debug.log") + ActiveRecord::Base.configurations = config['connections'][connection_name] + ActiveRecord::Base.establish_connection 'arunit' + Course.establish_connection 'arunit2' + end +end diff --git a/activesupport/CHANGELOG b/activesupport/CHANGELOG index bf48306684..6b7044aeae 100644 --- a/activesupport/CHANGELOG +++ b/activesupport/CHANGELOG @@ -7,6 +7,8 @@ *Rails 3.1.0 (unreleased)* +* ActiveSupport::Dependencies now raises NameError if it finds an existing constant in load_missing_constant. This better reflects the nature of the error which is usually caused by calling constantize on a nested constant. [Andrew White] + * Deprecated ActiveSupport::SecureRandom in favour of SecureRandom from the standard library [Jon Leighton] * New reporting method Kernel#quietly. [fxn] diff --git a/activesupport/lib/active_support/cache/mem_cache_store.rb b/activesupport/lib/active_support/cache/mem_cache_store.rb index 7ef1497ac2..64d2c3bff6 100644 --- a/activesupport/lib/active_support/cache/mem_cache_store.rb +++ b/activesupport/lib/active_support/cache/mem_cache_store.rb @@ -31,7 +31,7 @@ module ActiveSupport DELETED = "DELETED\r\n" end - ESCAPE_KEY_CHARS = /[\x00-\x20%\x7F-\xFF]/ + ESCAPE_KEY_CHARS = /[\x00-\x20%\x7F-\xFF]/n def self.build_mem_cache(*addresses) addresses = addresses.flatten diff --git a/activesupport/lib/active_support/dependencies.rb b/activesupport/lib/active_support/dependencies.rb index cae68c3c95..26c5c157cb 100644 --- a/activesupport/lib/active_support/dependencies.rb +++ b/activesupport/lib/active_support/dependencies.rb @@ -473,7 +473,7 @@ module ActiveSupport #:nodoc: raise ArgumentError, "A copy of #{from_mod} has been removed from the module tree but is still active!" end - raise ArgumentError, "#{from_mod} is not missing constant #{const_name}!" if local_const_defined?(from_mod, const_name) + raise NameError, "#{from_mod} is not missing constant #{const_name}!" if local_const_defined?(from_mod, const_name) qualified_name = qualified_name_for from_mod, const_name path_suffix = qualified_name.underscore diff --git a/activesupport/test/dependencies_test.rb b/activesupport/test/dependencies_test.rb index 2ddbce5150..b4edf0f51d 100644 --- a/activesupport/test/dependencies_test.rb +++ b/activesupport/test/dependencies_test.rb @@ -441,7 +441,7 @@ class DependenciesTest < Test::Unit::TestCase with_autoloading_fixtures do require_dependency '././counting_loader' assert_equal 1, $counting_loaded_times - assert_raise(ArgumentError) { ActiveSupport::Dependencies.load_missing_constant Object, :CountingLoader } + assert_raise(NameError) { ActiveSupport::Dependencies.load_missing_constant Object, :CountingLoader } assert_equal 1, $counting_loaded_times end end diff --git a/railties/guides/assets/images/radar.png b/railties/guides/assets/images/radar.png Binary files differnew file mode 100644 index 0000000000..f61e08763f --- /dev/null +++ b/railties/guides/assets/images/radar.png diff --git a/railties/guides/assets/images/vijaydev.jpg b/railties/guides/assets/images/vijaydev.jpg Binary files differnew file mode 100644 index 0000000000..e21d3cabfc --- /dev/null +++ b/railties/guides/assets/images/vijaydev.jpg diff --git a/railties/guides/rails_guides/helpers.rb b/railties/guides/rails_guides/helpers.rb index d466c76c7c..463df8a7a8 100644 --- a/railties/guides/rails_guides/helpers.rb +++ b/railties/guides/rails_guides/helpers.rb @@ -15,7 +15,7 @@ module RailsGuides def author(name, nick, image = 'credits_pic_blank.gif', &block) image = "images/#{image}" - result = content_tag(:img, nil, :src => image, :class => 'left pic', :alt => name) + result = content_tag(:img, nil, :src => image, :class => 'left pic', :alt => name, :width => 91, :height => 91) result << content_tag(:h3, name) result << content_tag(:p, capture(&block)) content_tag(:div, result, :class => 'clearfix', :id => nick) diff --git a/railties/guides/source/api_documentation_guidelines.textile b/railties/guides/source/api_documentation_guidelines.textile index e22ffa4c04..e046bc5cbb 100644 --- a/railties/guides/source/api_documentation_guidelines.textile +++ b/railties/guides/source/api_documentation_guidelines.textile @@ -33,6 +33,10 @@ Spell names correctly: Arel, Test::Unit, RSpec, HTML, MySQL, JavaScript, ERB. Wh Use the article "an" for "SQL", as in "an SQL statement". Also "an SQLite database". +h3. English + +Please use American English (_color_, _center_, _modularize_, etc.). See "a list of American and British English spelling differences here":http://en.wikipedia.org/wiki/American_and_British_English_spelling_differences. + h3. Example Code Choose meaningful examples that depict and cover the basics as well as interesting points or gotchas. diff --git a/railties/guides/source/credits.html.erb b/railties/guides/source/credits.html.erb index 65e396be95..da6bd6acdf 100644 --- a/railties/guides/source/credits.html.erb +++ b/railties/guides/source/credits.html.erb @@ -9,18 +9,14 @@ Ruby on Rails Guides: Credits <% end %> -<h3 class="section">Rails Documentation Team</h3> +<h3 class="section">Rails Guides Reviewers</h3> -<%= author('Mike Gunderloy', 'mgunderloy') do %> - Mike Gunderloy is a consultant with <a href="http://www.actionrails.com">ActionRails</a>. He brings 25 years of experience in a variety of languages to bear on his current work with Rails. His near-daily links and other blogging can be found at <a href="http://afreshcup.com">A Fresh Cup</a> and he <a href="http://twitter.com/MikeG1">twitters</a> too much. -<% end %> - -<%= author('Pratik Naik', 'lifo') do %> - Pratik Naik is a Ruby on Rails consultant with <a href="http://www.actionrails.com">ActionRails</a> and also a member of the <a href="http://rubyonrails.org/core">Rails core team</a>. He maintains a blog at <a href="http://m.onkey.org">has_many :bugs, :through => :rails</a> and has an active <a href="http://twitter.com/lifo">twitter account</a>. +<%= author('Vijay Dev', 'vijaydev', 'vijaydev.jpg') do %> + Vijayakumar, found as Vijay Dev on the web, is a web applications developer and an open source enthusiast who lives in Chennai, India. He started using Rails in 2009 and began actively contributing to Rails documentation in late 2010. He <a href="https://twitter.com/vijay_dev">tweets</a> a lot and also <a href="http://vijaydev.wordpress.com">blogs</a>. <% end %> <%= author('Xavier Noria', 'fxn', 'fxn.png') do %> - Xavier Noria has been into Ruby on Rails since 2005. He is a Rails committer and enjoys combining his passion for Rails and his past life as a proofreader of math textbooks. Xavier is currently a Ruby on Rails consultant. Oh, he also <a href="http://twitter.com/fxn">tweets</a> and can be found everywhere as "fxn". + Xavier Noria has been into Ruby on Rails since 2005. He is a Rails core team member and enjoys combining his passion for Rails and his past life as a proofreader of math textbooks. Xavier is currently an independent Ruby on Rails consultant. Oh, he also <a href="http://twitter.com/fxn">tweets</a> and can be found everywhere as "fxn". <% end %> <h3 class="section">Rails Guides Designers</h3> @@ -31,6 +27,10 @@ Ruby on Rails Guides: Credits <h3 class="section">Rails Guides Authors</h3> +<%= author('Ryan Bigg', 'radar', 'radar.png') do %> +Ryan Bigg works as a consultant at <a href="http://rubyx.com">RubyX</a> and has been working with Rails since 2006. He's co-authoring a book called <a href="http://manning.com/katz">Rails 3 in Action</a> and he's written many gems which can be seen on <a href="http://github.com/radar">his GitHub page</a> and he also tweets prolifically as <a href="http://twitter.com/ryanbigg">@ryanbigg</a>. +<% end %> + <%= author('Frederick Cheung', 'fcheung') do %> Frederick Cheung is Chief Wizard at Texperts where he has been using Rails since 2006. He is based in Cambridge (UK) and when not consuming fine ales he blogs at <a href="http://www.spacevatican.org">spacevatican.org</a>. <% end %> @@ -43,6 +43,10 @@ Ruby on Rails Guides: Credits Jeff Dean is a software engineer with <a href="http://pivotallabs.com">Pivotal Labs</a>. <% end %> +<%= author('Mike Gunderloy', 'mgunderloy') do %> + Mike Gunderloy is a consultant with <a href="http://www.actionrails.com">ActionRails</a>. He brings 25 years of experience in a variety of languages to bear on his current work with Rails. His near-daily links and other blogging can be found at <a href="http://afreshcup.com">A Fresh Cup</a> and he <a href="http://twitter.com/MikeG1">twitters</a> too much. +<% end %> + <%= author('Mikel Lindsaar', 'raasdnil') do %> Mikel Lindsaar has been working with Rails since 2006 and is the author of the Ruby <a href="https://github.com/mikel/mail">Mail gem</a> and core contributor (he helped re-write Action Mailer's API). Mikel is the founder of <a href="http://rubyx.com/">RubyX</a>, has a <a href="http://lindsaar.net/">blog</a> and <a href="http://twitter.com/raasdnil">tweets</a>. <% end %> @@ -55,6 +59,10 @@ Ruby on Rails Guides: Credits James Miller is a software developer for <a href="http://www.jk-tech.com">JK Tech</a> in San Diego, CA. You can find James on GitHub, Gmail, Twitter, and Freenode as "bensie". <% end %> +<%= author('Pratik Naik', 'lifo') do %> + Pratik Naik is a Ruby on Rails consultant with <a href="http://www.actionrails.com">ActionRails</a> and also a member of the <a href="http://rubyonrails.org/core">Rails core team</a>. He maintains a blog at <a href="http://m.onkey.org">has_many :bugs, :through => :rails</a> and has an active <a href="http://twitter.com/lifo">twitter account</a>. +<% end %> + <%= author('Emilio Tagua', 'miloops') do %> Emilio Tagua —a.k.a. miloops— is an Argentinian entrepreneur, developer, open source contributor and Rails evangelist. Cofounder of <a href="http://eventioz.com">Eventioz</a>. He has been using Rails since 2006 and contributing since early 2008. Can be found at gmail, twitter, freenode, everywhere as "miloops". <% end %> diff --git a/railties/lib/rails/generators/rails/app/templates/app/assets/javascripts/application.js.tt b/railties/lib/rails/generators/rails/app/templates/app/assets/javascripts/application.js.tt index 19294b3478..f33a7f4ac2 100644 --- a/railties/lib/rails/generators/rails/app/templates/app/assets/javascripts/application.js.tt +++ b/railties/lib/rails/generators/rails/app/templates/app/assets/javascripts/application.js.tt @@ -1,9 +1,15 @@ -// This is a manifest file that'll be compiled into including all the files listed below. -// Add new JavaScript/Coffee code in separate files in this directory and they'll automatically -// be included in the compiled file accessible from http://example.com/assets/application.js +// This is a manifest file that'll be compiled into application.js, which will include all the files +// listed below. +// +// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts, +// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path. +// // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the // the compiled file. // +// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD +// GO AFTER THE REQUIRES BELOW. +// <% unless options[:skip_javascript] -%> //= require <%= options[:javascript] %> //= require <%= options[:javascript] %>_ujs diff --git a/railties/lib/rails/generators/rails/app/templates/app/assets/stylesheets/application.css b/railties/lib/rails/generators/rails/app/templates/app/assets/stylesheets/application.css index fc25b5723f..9e07c7d9a9 100644 --- a/railties/lib/rails/generators/rails/app/templates/app/assets/stylesheets/application.css +++ b/railties/lib/rails/generators/rails/app/templates/app/assets/stylesheets/application.css @@ -1,7 +1,13 @@ /* - * This is a manifest file that'll automatically include all the stylesheets available in this directory - * and any sub-directories. You're free to add application-wide styles to this file and they'll appear at - * the top of the compiled file, but it's generally better to create a new file per style scope. + * This is a manifest file that'll be compiled into application.css, which will include all the files + * listed below. + * + * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets, + * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path. + * + * You're free to add application-wide styles to this file and they'll appear at the top of the + * compiled file, but it's generally better to create a new file per style scope. + * *= require_self *= require_tree . */
\ No newline at end of file diff --git a/railties/test/application/rackup_test.rb b/railties/test/application/rackup_test.rb index b0a9925890..885355fd46 100644 --- a/railties/test/application/rackup_test.rb +++ b/railties/test/application/rackup_test.rb @@ -11,10 +11,16 @@ module ApplicationTests end def setup + @prev_rails_env = ENV['RAILS_ENV'] + ENV['RAILS_ENV'] = 'development' build_app boot_rails end + def teardown + ENV['RAILS_ENV'] = @prev_rails_env + end + test "rails app is present" do assert File.exist?(app_path("config")) end |