diff options
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/adapter_test.rb | 16 | ||||
-rwxr-xr-x | activerecord/test/base_test.rb | 12 | ||||
-rw-r--r-- | activerecord/test/connections/native_frontbase/connection.rb | 26 | ||||
-rwxr-xr-x | activerecord/test/deprecated_finder_test.rb | 1 | ||||
-rw-r--r-- | activerecord/test/finder_test.rb | 6 | ||||
-rw-r--r-- | activerecord/test/fixtures/db_definitions/frontbase.drop.sql | 30 | ||||
-rw-r--r-- | activerecord/test/fixtures/db_definitions/frontbase.sql | 251 | ||||
-rw-r--r-- | activerecord/test/fixtures/db_definitions/frontbase2.drop.sql | 1 | ||||
-rw-r--r-- | activerecord/test/fixtures/db_definitions/frontbase2.sql | 4 | ||||
-rw-r--r-- | activerecord/test/migration_test.rb | 36 | ||||
-rw-r--r-- | activerecord/test/pk_test.rb | 1 | ||||
-rw-r--r-- | activerecord/test/reflection_test.rb | 6 | ||||
-rw-r--r-- | activerecord/test/threaded_connections_test.rb | 34 | ||||
-rw-r--r-- | activerecord/test/transactions_test.rb | 1 |
14 files changed, 379 insertions, 46 deletions
diff --git a/activerecord/test/adapter_test.rb b/activerecord/test/adapter_test.rb index c4027b31cb..0c12c4d37e 100644 --- a/activerecord/test/adapter_test.rb +++ b/activerecord/test/adapter_test.rb @@ -66,19 +66,21 @@ class AdapterTest < Test::Unit::TestCase if ActiveRecord::Base.connection.respond_to?(:reset_pk_sequence!) require 'fixtures/movie' require 'fixtures/subscriber' + def test_reset_empty_table_with_custom_pk Movie.delete_all Movie.connection.reset_pk_sequence! 'movies' assert_equal 1, Movie.create(:name => 'fight club').id end - def test_reset_table_with_non_integer_pk - Subscriber.delete_all - Subscriber.connection.reset_pk_sequence! 'subscribers' - - sub = Subscriber.new(:name => 'robert drake') - sub.id = 'bob drake' - assert_nothing_raised { sub.save! } + if ActiveRecord::Base.connection.adapter_name != "FrontBase" + def test_reset_table_with_non_integer_pk + Subscriber.delete_all + Subscriber.connection.reset_pk_sequence! 'subscribers' + sub = Subscriber.new(:name => 'robert drake') + sub.id = 'bob drake' + assert_nothing_raised { sub.save! } + end end end diff --git a/activerecord/test/base_test.rb b/activerecord/test/base_test.rb index c4c0742b7b..2f834772a6 100755 --- a/activerecord/test/base_test.rb +++ b/activerecord/test/base_test.rb @@ -1094,21 +1094,21 @@ class BasicsTest < Test::Unit::TestCase end assert_equal res, res3 - res4 = Post.count_by_sql "SELECT COUNT(p.id) FROM posts p, comments c WHERE p.#{QUOTED_TYPE} = 'Post' AND p.id=c.post_id" + res4 = Post.count_by_sql "SELECT COUNT(p.id) FROM posts p, comments co WHERE p.#{QUOTED_TYPE} = 'Post' AND p.id=co.post_id" res5 = nil assert_nothing_raised do - res5 = Post.count(:conditions => "p.#{QUOTED_TYPE} = 'Post' AND p.id=c.post_id", - :joins => "p, comments c", + res5 = Post.count(:conditions => "p.#{QUOTED_TYPE} = 'Post' AND p.id=co.post_id", + :joins => "p, comments co", :select => "p.id") end assert_equal res4, res5 - res6 = Post.count_by_sql "SELECT COUNT(DISTINCT p.id) FROM posts p, comments c WHERE p.#{QUOTED_TYPE} = 'Post' AND p.id=c.post_id" + res6 = Post.count_by_sql "SELECT COUNT(DISTINCT p.id) FROM posts p, comments co WHERE p.#{QUOTED_TYPE} = 'Post' AND p.id=co.post_id" res7 = nil assert_nothing_raised do - res7 = Post.count(:conditions => "p.#{QUOTED_TYPE} = 'Post' AND p.id=c.post_id", - :joins => "p, comments c", + res7 = Post.count(:conditions => "p.#{QUOTED_TYPE} = 'Post' AND p.id=co.post_id", + :joins => "p, comments co", :select => "p.id", :distinct => true) end diff --git a/activerecord/test/connections/native_frontbase/connection.rb b/activerecord/test/connections/native_frontbase/connection.rb new file mode 100644 index 0000000000..e3d1d5b1e1 --- /dev/null +++ b/activerecord/test/connections/native_frontbase/connection.rb @@ -0,0 +1,26 @@ +puts 'Using native Frontbase' +require_dependency 'fixtures/course' +require 'logger' + +ActiveRecord::Base.logger = Logger.new("debug.log") + +db1 = 'activerecord_unittest' +db2 = 'activerecord_unittest2' + +ActiveRecord::Base.establish_connection( + :adapter => "frontbase", + :host => "localhost", + :username => "rails", + :password => "", + :database => db1, + :session_name => "unittest-#{$$}" +) + +Course.establish_connection( + :adapter => "frontbase", + :host => "localhost", + :username => "rails", + :password => "", + :database => db2, + :session_name => "unittest-#{$$}" +) diff --git a/activerecord/test/deprecated_finder_test.rb b/activerecord/test/deprecated_finder_test.rb index 35c8a2379a..c1065b0026 100755 --- a/activerecord/test/deprecated_finder_test.rb +++ b/activerecord/test/deprecated_finder_test.rb @@ -1,6 +1,7 @@ require 'abstract_unit' require 'fixtures/company' require 'fixtures/topic' +require 'fixtures/reply' require 'fixtures/entrant' require 'fixtures/developer' diff --git a/activerecord/test/finder_test.rb b/activerecord/test/finder_test.rb index 98537ecad7..f23e383115 100644 --- a/activerecord/test/finder_test.rb +++ b/activerecord/test/finder_test.rb @@ -13,6 +13,12 @@ class FinderTest < Test::Unit::TestCase assert_equal(topics(:first).title, Topic.find(1).title) end + # find should handle strings that come from URLs + # (example: Category.find(params[:id])) + def test_find_with_string + assert_equal(Topic.find(1).title,Topic.find("1").title) + end + def test_exists assert (Topic.exists?(1)) assert !(Topic.exists?(45)) diff --git a/activerecord/test/fixtures/db_definitions/frontbase.drop.sql b/activerecord/test/fixtures/db_definitions/frontbase.drop.sql new file mode 100644 index 0000000000..231af7895c --- /dev/null +++ b/activerecord/test/fixtures/db_definitions/frontbase.drop.sql @@ -0,0 +1,30 @@ +DROP TABLE accounts CASCADE; +DROP TABLE funny_jokes CASCADE; +DROP TABLE companies CASCADE; +DROP TABLE topics CASCADE; +DROP TABLE developers CASCADE; +DROP TABLE projects CASCADE; +DROP TABLE developers_projects CASCADE; +DROP TABLE orders CASCADE; +DROP TABLE customers CASCADE; +DROP TABLE movies CASCADE; +DROP TABLE subscribers CASCADE; +DROP TABLE booleantests CASCADE; +DROP TABLE auto_id_tests CASCADE; +DROP TABLE entrants CASCADE; +DROP TABLE colnametests CASCADE; +DROP TABLE mixins CASCADE; +DROP TABLE people CASCADE; +DROP TABLE readers CASCADE; +DROP TABLE binaries CASCADE; +DROP TABLE computers CASCADE; +DROP TABLE posts CASCADE; +DROP TABLE comments CASCADE; +DROP TABLE authors CASCADE; +DROP TABLE tasks CASCADE; +DROP TABLE categories CASCADE; +DROP TABLE categories_posts CASCADE; +DROP TABLE fk_test_has_fk CASCADE; +DROP TABLE fk_test_has_pk CASCADE; +DROP TABLE keyboards CASCADE; +DROP TABLE legacy_things CASCADE; diff --git a/activerecord/test/fixtures/db_definitions/frontbase.sql b/activerecord/test/fixtures/db_definitions/frontbase.sql new file mode 100644 index 0000000000..13ce65297b --- /dev/null +++ b/activerecord/test/fixtures/db_definitions/frontbase.sql @@ -0,0 +1,251 @@ +CREATE TABLE accounts ( + id integer DEFAULT unique, + firm_id integer, + credit_limit integer, + PRIMARY KEY (id) +); +SET UNIQUE FOR accounts(id); + +CREATE TABLE funny_jokes ( + id integer DEFAULT unique, + firm_id integer default NULL, + name character varying(50), + PRIMARY KEY (id) +); +SET UNIQUE FOR funny_jokes(id); + +CREATE TABLE companies ( + id integer DEFAULT unique, + "type" character varying(50), + "ruby_type" character varying(50), + firm_id integer, + name character varying(50), + client_of integer, + rating integer default 1, + PRIMARY KEY (id) +); +SET UNIQUE FOR companies(id); + +CREATE TABLE topics ( + id integer DEFAULT unique, + title character varying(255), + author_name character varying(255), + author_email_address character varying(255), + written_on timestamp, + bonus_time time, + last_read date, + content varchar(65536), + approved boolean default true, + replies_count integer default 0, + parent_id integer, + "type" character varying(50), + PRIMARY KEY (id) +); +SET UNIQUE FOR topics(id); + +CREATE TABLE developers ( + id integer DEFAULT unique, + name character varying(100), + salary integer DEFAULT 70000, + created_at timestamp, + updated_at timestamp, + PRIMARY KEY (id) +); +SET UNIQUE FOR developers(id); + +CREATE TABLE projects ( + id integer DEFAULT unique, + name character varying(100), + type varchar(255), + PRIMARY KEY (id) +); +SET UNIQUE FOR projects(id); + +CREATE TABLE developers_projects ( + developer_id integer NOT NULL, + project_id integer NOT NULL, + joined_on date, + access_level integer default 1 +); + +CREATE TABLE orders ( + id integer DEFAULT unique, + name character varying(100), + billing_customer_id integer, + shipping_customer_id integer, + PRIMARY KEY (id) +); +SET UNIQUE FOR orders(id); + +CREATE TABLE customers ( + id integer DEFAULT unique, + name character varying(100), + balance integer default 0, + address_street character varying(100), + address_city character varying(100), + address_country character varying(100), + gps_location character varying(100), + PRIMARY KEY (id) +); +SET UNIQUE FOR customers(id); + +CREATE TABLE movies ( + movieid integer DEFAULT unique, + name varchar(65536), + PRIMARY KEY (movieid) +); +SET UNIQUE FOR movies(movieid); + +CREATE TABLE subscribers ( + nick varchar(65536) NOT NULL, + name varchar(65536), + PRIMARY KEY (nick) +); + +CREATE TABLE booleantests ( + id integer DEFAULT unique, + value boolean, + PRIMARY KEY (id) +); +SET UNIQUE FOR booleantests(id); + +CREATE TABLE auto_id_tests ( + auto_id integer DEFAULT unique, + value integer, + PRIMARY KEY (auto_id) +); +SET UNIQUE FOR auto_id_tests(auto_id); + +CREATE TABLE entrants ( + id integer DEFAULT unique, + name varchar(65536), + course_id integer, + PRIMARY KEY (id) +); +SET UNIQUE FOR entrants(id); + +CREATE TABLE colnametests ( + id integer DEFAULT unique, + "references" integer NOT NULL, + PRIMARY KEY (id) +); +SET UNIQUE FOR colnametests(id); + +CREATE TABLE mixins ( + id integer DEFAULT unique, + parent_id integer, + type character varying(100), + pos integer, + lft integer, + rgt integer, + root_id integer, + created_at timestamp, + updated_at timestamp, + PRIMARY KEY (id) +); +SET UNIQUE FOR mixins(id); + +CREATE TABLE people ( + id integer DEFAULT unique, + first_name varchar(65536), + lock_version integer default 0, + PRIMARY KEY (id) +); +SET UNIQUE FOR people(id); + +CREATE TABLE readers ( + id integer DEFAULT unique, + post_id INTEGER NOT NULL, + person_id INTEGER NOT NULL, + PRIMARY KEY (id) +); +SET UNIQUE FOR readers(id); + +CREATE TABLE binaries ( + id integer DEFAULT unique, + data BLOB, + PRIMARY KEY (id) +); +SET UNIQUE FOR binaries(id); + +CREATE TABLE computers ( + id integer DEFAULT unique, + developer integer NOT NULL, + "extendedWarranty" integer NOT NULL, + PRIMARY KEY (id) +); +SET UNIQUE FOR computers(id); + +CREATE TABLE posts ( + id integer DEFAULT unique, + author_id integer, + title varchar(255), + type varchar(255), + body varchar(65536), + PRIMARY KEY (id) +); +SET UNIQUE FOR posts(id); + +CREATE TABLE comments ( + id integer DEFAULT unique, + post_id integer, + type varchar(255), + body varchar(65536), + PRIMARY KEY (id) +); +SET UNIQUE FOR comments(id); + +CREATE TABLE authors ( + id integer DEFAULT unique, + name varchar(255) default NULL, + PRIMARY KEY (id) +); +SET UNIQUE FOR authors(id); + +CREATE TABLE tasks ( + id integer DEFAULT unique, + starting timestamp, + ending timestamp, + PRIMARY KEY (id) +); +SET UNIQUE FOR tasks(id); + +CREATE TABLE categories ( + id integer DEFAULT unique, + name varchar(255), + type varchar(255), + PRIMARY KEY (id) +); +SET UNIQUE FOR categories(id); + +CREATE TABLE categories_posts ( + category_id integer NOT NULL, + post_id integer NOT NULL +); + +CREATE TABLE fk_test_has_pk ( + id INTEGER NOT NULL PRIMARY KEY +); +SET UNIQUE FOR fk_test_has_pk(id); + +CREATE TABLE fk_test_has_fk ( + id INTEGER NOT NULL PRIMARY KEY, + fk_id INTEGER NOT NULL REFERENCES fk_test_has_fk(id) +); +SET UNIQUE FOR fk_test_has_fk(id); + +CREATE TABLE keyboards ( + key_number integer DEFAULT unique, + "name" character varying(50), + PRIMARY KEY (key_number) +); +SET UNIQUE FOR keyboards(key_number); + +create table "legacy_things" +( + "id" int, + "tps_report_number" int default NULL, + "version" int default 0 not null, + primary key ("id") +); +SET UNIQUE FOR legacy_things(id); diff --git a/activerecord/test/fixtures/db_definitions/frontbase2.drop.sql b/activerecord/test/fixtures/db_definitions/frontbase2.drop.sql new file mode 100644 index 0000000000..17b9ad46d7 --- /dev/null +++ b/activerecord/test/fixtures/db_definitions/frontbase2.drop.sql @@ -0,0 +1 @@ +DROP TABLE courses CASCADE; diff --git a/activerecord/test/fixtures/db_definitions/frontbase2.sql b/activerecord/test/fixtures/db_definitions/frontbase2.sql new file mode 100644 index 0000000000..42f4bb78c9 --- /dev/null +++ b/activerecord/test/fixtures/db_definitions/frontbase2.sql @@ -0,0 +1,4 @@ +CREATE TABLE courses (
+ id integer DEFAULT unique,
+ name varchar(100)
+);
diff --git a/activerecord/test/migration_test.rb b/activerecord/test/migration_test.rb index c6a1d92481..e238eab1a2 100644 --- a/activerecord/test/migration_test.rb +++ b/activerecord/test/migration_test.rb @@ -58,7 +58,7 @@ if ActiveRecord::Base.connection.supports_migrations? # quoting assert_nothing_raised { Person.connection.add_index("people", ["key"], :name => "key", :unique => true) } - assert_nothing_raised { Person.connection.remove_index("people", :name => "key") } + assert_nothing_raised { Person.connection.remove_index("people", :name => "key", :unique => true) } # Sybase adapter does not support indexes on :boolean columns unless current_adapter?(:SybaseAdapter) @@ -461,27 +461,29 @@ if ActiveRecord::Base.connection.supports_migrations? Reminder.reset_sequence_name end - def test_create_table_with_binary_column - Person.connection.drop_table :binary_testings rescue nil +# FrontBase does not support default values on BLOB/CLOB columns + unless current_adapter?(:FrontBaseAdapter) + def test_create_table_with_binary_column + Person.connection.drop_table :binary_testings rescue nil - assert_nothing_raised { - Person.connection.create_table :binary_testings do |t| - t.column "data", :binary, :default => "", :null => false - end - } + assert_nothing_raised { + Person.connection.create_table :binary_testings do |t| + t.column "data", :binary, :default => "", :null => false + end + } - columns = Person.connection.columns(:binary_testings) - data_column = columns.detect { |c| c.name == "data" } + columns = Person.connection.columns(:binary_testings) + data_column = columns.detect { |c| c.name == "data" } - if current_adapter?(:OracleAdapter) - assert_equal "empty_blob()", data_column.default - else - assert_equal "", data_column.default - end + if current_adapter?(:OracleAdapter) + assert_equal "empty_blob()", data_column.default + else + assert_equal "", data_column.default + end - Person.connection.drop_table :binary_testings rescue nil + Person.connection.drop_table :binary_testings rescue nil + end end - def test_migrator_with_duplicates assert_raises(ActiveRecord::DuplicateMigrationVersionError) do ActiveRecord::Migrator.migrate(File.dirname(__FILE__) + '/fixtures/migrations_with_duplicate/', nil) diff --git a/activerecord/test/pk_test.rb b/activerecord/test/pk_test.rb index 839a784e4a..604b263571 100644 --- a/activerecord/test/pk_test.rb +++ b/activerecord/test/pk_test.rb @@ -1,5 +1,6 @@ require "#{File.dirname(__FILE__)}/abstract_unit" require 'fixtures/topic' +require 'fixtures/reply' require 'fixtures/subscriber' require 'fixtures/movie' require 'fixtures/keyboard' diff --git a/activerecord/test/reflection_test.rb b/activerecord/test/reflection_test.rb index 4882ca246f..907d02193f 100644 --- a/activerecord/test/reflection_test.rb +++ b/activerecord/test/reflection_test.rb @@ -45,6 +45,12 @@ class ReflectionTest < Test::Unit::TestCase assert_equal :string, @first.column_for_attribute("title").type assert_equal 255, @first.column_for_attribute("title").limit end + + def test_column_null_not_null + subscriber = Subscriber.find(:first) + assert subscriber.column_for_attribute("name").null + assert !subscriber.column_for_attribute("nick").null + end def test_human_name_for_column assert_equal "Author name", @first.column_for_attribute("author_name").human_name diff --git a/activerecord/test/threaded_connections_test.rb b/activerecord/test/threaded_connections_test.rb index d9cc47eef3..a812ec642c 100644 --- a/activerecord/test/threaded_connections_test.rb +++ b/activerecord/test/threaded_connections_test.rb @@ -1,10 +1,11 @@ require 'abstract_unit' require 'fixtures/topic' -class ThreadedConnectionsTest < Test::Unit::TestCase - self.use_transactional_fixtures = false +unless %w(FrontBase).include? ActiveRecord::Base.connection.adapter_name + class ThreadedConnectionsTest < Test::Unit::TestCase + self.use_transactional_fixtures = false - fixtures :topics + fixtures :topics def setup @connection = ActiveRecord::Base.remove_connection @@ -25,21 +26,22 @@ class ThreadedConnectionsTest < Test::Unit::TestCase ActiveRecord::Base.allow_concurrency = use_threaded_connections ActiveRecord::Base.establish_connection(@connection) - 5.times do - Thread.new do - Topic.find :first - @connections << ActiveRecord::Base.active_connections.values.first - end.join + 5.times do + Thread.new do + Topic.find :first + @connections << ActiveRecord::Base.active_connections.values.first + end.join + end end - end - def test_threaded_connections - gather_connections(true) - assert_equal @connections.uniq.length, 5 - end + def test_threaded_connections + gather_connections(true) + assert_equal @connections.uniq.length, 5 + end - def test_unthreaded_connections - gather_connections(false) - assert_equal @connections.uniq.length, 1 + def test_unthreaded_connections + gather_connections(false) + assert_equal @connections.uniq.length, 1 + end end end diff --git a/activerecord/test/transactions_test.rb b/activerecord/test/transactions_test.rb index 0048e24bc7..421da4d7a6 100644 --- a/activerecord/test/transactions_test.rb +++ b/activerecord/test/transactions_test.rb @@ -1,5 +1,6 @@ require 'abstract_unit' require 'fixtures/topic' +require 'fixtures/reply' require 'fixtures/developer' class TransactionTest < Test::Unit::TestCase |