diff options
author | Nat Welch <nat@natwelch.com> | 2011-09-21 23:53:18 -0700 |
---|---|---|
committer | Nat Welch <nat@natwelch.com> | 2011-09-21 23:53:18 -0700 |
commit | 667d21814b67c615d3317488d0678cb992d3bdb1 (patch) | |
tree | d10e68a7d904641f88e6e835074273ab0bcafbc4 /activerecord/test/cases/base_test.rb | |
parent | f69036781c0ee7a22a456fe3a6689277d44ed9a6 (diff) | |
parent | 2bf33bd4bcd488a35e641b32dd667f3092ea9197 (diff) | |
download | rails-667d21814b67c615d3317488d0678cb992d3bdb1.tar.gz rails-667d21814b67c615d3317488d0678cb992d3bdb1.tar.bz2 rails-667d21814b67c615d3317488d0678cb992d3bdb1.zip |
Merge branch 'master' of git://github.com/rails/rails
Diffstat (limited to 'activerecord/test/cases/base_test.rb')
-rw-r--r-- | activerecord/test/cases/base_test.rb | 52 |
1 files changed, 51 insertions, 1 deletions
diff --git a/activerecord/test/cases/base_test.rb b/activerecord/test/cases/base_test.rb index fe46c00b47..12c1cfb30e 100644 --- a/activerecord/test/cases/base_test.rb +++ b/activerecord/test/cases/base_test.rb @@ -22,8 +22,10 @@ require 'models/person' require 'models/edge' require 'models/joke' require 'models/bulb' +require 'models/bird' require 'rexml/document' require 'active_support/core_ext/exception' +require 'bcrypt' class Category < ActiveRecord::Base; end class Categorization < ActiveRecord::Base; end @@ -81,7 +83,13 @@ class BasicsTest < ActiveRecord::TestCase } quoted = conn.quote_column_name "foo#{badchar}bar" - assert_equal("#{badchar}foo#{badchar * 2}bar#{badchar}", quoted) + if current_adapter?(:OracleAdapter) + # Oracle does not allow double quotes in table and column names at all + # therefore quoting removes them + assert_equal("#{badchar}foobar#{badchar}", quoted) + else + assert_equal("#{badchar}foo#{badchar * 2}bar#{badchar}", quoted) + end end def test_columns_should_obey_set_primary_key @@ -271,6 +279,29 @@ class BasicsTest < ActiveRecord::TestCase assert_equal(true, cb.frickinawesome) end + def test_first_or_create + parrot = Bird.first_or_create(:color => 'green', :name => 'parrot') + assert parrot.persisted? + the_same_parrot = Bird.first_or_create(:color => 'yellow', :name => 'macaw') + assert_equal parrot, the_same_parrot + end + + def test_first_or_create_bang + assert_raises(ActiveRecord::RecordInvalid) { Bird.first_or_create! } + parrot = Bird.first_or_create!(:color => 'green', :name => 'parrot') + assert parrot.persisted? + the_same_parrot = Bird.first_or_create!(:color => 'yellow', :name => 'macaw') + assert_equal parrot, the_same_parrot + end + + def test_first_or_initialize + parrot = Bird.first_or_initialize(:color => 'green', :name => 'parrot') + assert_kind_of Bird, parrot + assert !parrot.persisted? + assert parrot.new_record? + assert parrot.valid? + end + def test_load topics = Topic.find(:all, :order => 'id') assert_equal(4, topics.size) @@ -1625,6 +1656,10 @@ class BasicsTest < ActiveRecord::TestCase assert !LooseDescendant.abstract_class? end + def test_abstract_class_table_name + assert_nil AbstractCompany.table_name + end + def test_base_class assert_equal LoosePerson, LoosePerson.base_class assert_equal LooseDescendant, LooseDescendant.base_class @@ -1824,6 +1859,11 @@ class BasicsTest < ActiveRecord::TestCase end def test_marshal_round_trip + if ENV['TRAVIS'] && RUBY_VERSION == "1.8.7" + return skip("Marshalling tests disabled for Ruby 1.8.7 on Travis CI due to what appears " \ + "to be a Ruby bug.") + end + expected = posts(:welcome) marshalled = Marshal.dump(expected) actual = Marshal.load(marshalled) @@ -1832,6 +1872,11 @@ class BasicsTest < ActiveRecord::TestCase end def test_marshal_new_record_round_trip + if ENV['TRAVIS'] && RUBY_VERSION == "1.8.7" + return skip("Marshalling tests disabled for Ruby 1.8.7 on Travis CI due to what appears " \ + "to be a Ruby bug.") + end + marshalled = Marshal.dump(Post.new) post = Marshal.load(marshalled) @@ -1839,6 +1884,11 @@ class BasicsTest < ActiveRecord::TestCase end def test_marshalling_with_associations + if ENV['TRAVIS'] && RUBY_VERSION == "1.8.7" + return skip("Marshalling tests disabled for Ruby 1.8.7 on Travis CI due to what appears " \ + "to be a Ruby bug.") + end + post = Post.new post.comments.build |