diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2005-04-07 06:54:25 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2005-04-07 06:54:25 +0000 |
commit | 7ad57c4f0295d1420f1853c0b1f1802b629d5375 (patch) | |
tree | f407f6e7c49296127f858cb5e9ca45ca801aff85 | |
parent | 8afc284e2c3e0a34a211fc778b880af20d3d0973 (diff) | |
download | rails-7ad57c4f0295d1420f1853c0b1f1802b629d5375.tar.gz rails-7ad57c4f0295d1420f1853c0b1f1802b629d5375.tar.bz2 rails-7ad57c4f0295d1420f1853c0b1f1802b629d5375.zip |
Added quoting of column names for fixtures #997 [jcfischer@gmail.com]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1110 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
17 files changed, 66 insertions, 5 deletions
diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG index 8206d673da..12f577e91d 100644 --- a/activerecord/CHANGELOG +++ b/activerecord/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Added quoting of column names for fixtures #997 [jcfischer@gmail.com] + * Fixed counter_sql when no records exist in database for PostgreSQL (would give error, not 0) #1039 [Caleb Tennis] * Fixed that benchmarking times for rendering included db runtimes #987 [skaes@web.de] diff --git a/activerecord/lib/active_record/fixtures.rb b/activerecord/lib/active_record/fixtures.rb index 77f701e4ab..100908cafb 100755 --- a/activerecord/lib/active_record/fixtures.rb +++ b/activerecord/lib/active_record/fixtures.rb @@ -347,7 +347,8 @@ class Fixture #:nodoc: end def key_list - @fixture.keys.join(", ") + columns = @fixture.keys.collect{ |column_name| ActiveRecord::Base.connection.quote_column_name(column_name) } + columns.join(", ") end def value_list diff --git a/activerecord/test/fixtures/db_definitions/db2.drop.sql b/activerecord/test/fixtures/db_definitions/db2.drop.sql index 1f611c8d5a..88e6516c81 100644 --- a/activerecord/test/fixtures/db_definitions/db2.drop.sql +++ b/activerecord/test/fixtures/db_definitions/db2.drop.sql @@ -15,4 +15,5 @@ DROP TABLE mixins; DROP TABLE people; DROP TABLE binaries; DROP TABLE computers; +DROP TABLE tasks; diff --git a/activerecord/test/fixtures/db_definitions/db2.sql b/activerecord/test/fixtures/db_definitions/db2.sql index 07569c27ed..856847e500 100644 --- a/activerecord/test/fixtures/db_definitions/db2.sql +++ b/activerecord/test/fixtures/db_definitions/db2.sql @@ -129,3 +129,8 @@ CREATE TABLE computers ( developer int NOT NULL ); +CREATE TABLE tasks ( + id int generated by default as identity (start with +10000), + starting timestamp default NULL, + ending timestamp default NULL +); diff --git a/activerecord/test/fixtures/db_definitions/drop_oracle_tables.sql b/activerecord/test/fixtures/db_definitions/drop_oracle_tables.sql index b300d13485..2eb574df75 100644 --- a/activerecord/test/fixtures/db_definitions/drop_oracle_tables.sql +++ b/activerecord/test/fixtures/db_definitions/drop_oracle_tables.sql @@ -32,4 +32,6 @@ DROP TABLE binaries; DROP SEQUENCE binaries_id; DROP TABLE computers; DROP SEQUENCE computers_id; +DROP TABLE tasks; +DROP SEQUENCE tasks_id; EXIT; diff --git a/activerecord/test/fixtures/db_definitions/mysql.drop.sql b/activerecord/test/fixtures/db_definitions/mysql.drop.sql index 99b391ea16..d8eaf9b29c 100644 --- a/activerecord/test/fixtures/db_definitions/mysql.drop.sql +++ b/activerecord/test/fixtures/db_definitions/mysql.drop.sql @@ -15,7 +15,7 @@ DROP TABLE mixins; DROP TABLE people; DROP TABLE binaries; DROP TABLE computers; +DROP TABLE tasks; DROP TABLE posts; DROP TABLE comments; DROP TABLE authors; - diff --git a/activerecord/test/fixtures/db_definitions/mysql.sql b/activerecord/test/fixtures/db_definitions/mysql.sql index 8c919ff4ca..235a1c84d1 100755 --- a/activerecord/test/fixtures/db_definitions/mysql.sql +++ b/activerecord/test/fixtures/db_definitions/mysql.sql @@ -147,3 +147,9 @@ CREATE TABLE `authors` ( `name` VARCHAR(255) NOT NULL ) TYPE=InnoDB; +CREATE TABLE `tasks` ( + `id` int(11) NOT NULL auto_increment, + `starting` datetime NOT NULL default '0000-00-00 00:00:00', + `ending` datetime NOT NULL default '0000-00-00 00:00:00', + PRIMARY KEY (`id`) +); diff --git a/activerecord/test/fixtures/db_definitions/oci.sql b/activerecord/test/fixtures/db_definitions/oci.sql index 16d6e660a2..b17b1091cb 100644 --- a/activerecord/test/fixtures/db_definitions/oci.sql +++ b/activerecord/test/fixtures/db_definitions/oci.sql @@ -166,3 +166,9 @@ create table computers ( id integer not null primary key, developer integer not null references developers initially deferred disable ); + +create table tasks ( + id integer not null primary key, + starting date default null, + ending date default null +); diff --git a/activerecord/test/fixtures/db_definitions/postgresql.drop.sql b/activerecord/test/fixtures/db_definitions/postgresql.drop.sql index 1f611c8d5a..88e6516c81 100644 --- a/activerecord/test/fixtures/db_definitions/postgresql.drop.sql +++ b/activerecord/test/fixtures/db_definitions/postgresql.drop.sql @@ -15,4 +15,5 @@ DROP TABLE mixins; DROP TABLE people; DROP TABLE binaries; DROP TABLE computers; +DROP TABLE tasks; diff --git a/activerecord/test/fixtures/db_definitions/postgresql.sql b/activerecord/test/fixtures/db_definitions/postgresql.sql index ab392c5688..53618b653d 100644 --- a/activerecord/test/fixtures/db_definitions/postgresql.sql +++ b/activerecord/test/fixtures/db_definitions/postgresql.sql @@ -147,3 +147,9 @@ CREATE TABLE computers ( developer integer NOT NULL ); +CREATE TABLE taske ( + id serial, + starting timestamp, + ending timestamp, + PRIMARY KEY (id) +); diff --git a/activerecord/test/fixtures/db_definitions/sqlite.drop.sql b/activerecord/test/fixtures/db_definitions/sqlite.drop.sql index 3fd60de17b..d8eaf9b29c 100644 --- a/activerecord/test/fixtures/db_definitions/sqlite.drop.sql +++ b/activerecord/test/fixtures/db_definitions/sqlite.drop.sql @@ -15,6 +15,7 @@ DROP TABLE mixins; DROP TABLE people; DROP TABLE binaries; DROP TABLE computers; +DROP TABLE tasks; DROP TABLE posts; DROP TABLE comments; DROP TABLE authors; diff --git a/activerecord/test/fixtures/db_definitions/sqlite.sql b/activerecord/test/fixtures/db_definitions/sqlite.sql index db31835807..8639182266 100644 --- a/activerecord/test/fixtures/db_definitions/sqlite.sql +++ b/activerecord/test/fixtures/db_definitions/sqlite.sql @@ -134,3 +134,9 @@ CREATE TABLE 'authors' ( 'name' VARCHAR(255) NOT NULL ); +CREATE TABLE 'tasks' ( + 'id' INTEGER NOT NULL PRIMARY KEY, + 'starting' DATETIME DEFAULT NULL, + 'ending' DATETIME DEFAULT NULL +); + diff --git a/activerecord/test/fixtures/db_definitions/sqlserver.drop.sql b/activerecord/test/fixtures/db_definitions/sqlserver.drop.sql index 19da3f8e61..480b2703c4 100644 --- a/activerecord/test/fixtures/db_definitions/sqlserver.drop.sql +++ b/activerecord/test/fixtures/db_definitions/sqlserver.drop.sql @@ -14,4 +14,5 @@ DROP TABLE colnametests; DROP TABLE mixins; DROP TABLE people; DROP TABLE binaries; -DROP TABLE computers;
\ No newline at end of file +DROP TABLE computers; +DROP TABLE tasks; diff --git a/activerecord/test/fixtures/db_definitions/sqlserver.sql b/activerecord/test/fixtures/db_definitions/sqlserver.sql index 11d5b30255..de746efb57 100644 --- a/activerecord/test/fixtures/db_definitions/sqlserver.sql +++ b/activerecord/test/fixtures/db_definitions/sqlserver.sql @@ -116,3 +116,8 @@ CREATE TABLE computers ( developer int NOT NULL ); +CREATE TABLE tasks ( + id int NOT NULL IDENTITY(1, 1) PRIMARY KEY, + starting datetime default NULL, + ending datetime default NULL +); diff --git a/activerecord/test/fixtures/task.rb b/activerecord/test/fixtures/task.rb new file mode 100644 index 0000000000..ee0282c79b --- /dev/null +++ b/activerecord/test/fixtures/task.rb @@ -0,0 +1,3 @@ +class Task < ActiveRecord::Base + +end diff --git a/activerecord/test/fixtures/tasks.yml b/activerecord/test/fixtures/tasks.yml new file mode 100644 index 0000000000..c8b158dc17 --- /dev/null +++ b/activerecord/test/fixtures/tasks.yml @@ -0,0 +1,7 @@ +# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html +first_task: + id: 1 + starting: "2005-03-30 06:30:00" + ending: "2005-03-30 08:30:00" +another_task: + id: 2 diff --git a/activerecord/test/fixtures_test.rb b/activerecord/test/fixtures_test.rb index fb70289996..687ce817f6 100755 --- a/activerecord/test/fixtures_test.rb +++ b/activerecord/test/fixtures_test.rb @@ -2,13 +2,14 @@ require 'abstract_unit' require 'fixtures/topic' require 'fixtures/developer' require 'fixtures/company' +require 'fixtures/task' class FixturesTest < Test::Unit::TestCase - fixtures :topics, :developers, :accounts + fixtures :topics, :developers, :accounts, :tasks FIXTURES = %w( accounts companies customers developers developers_projects entrants - movies projects subscribers topics ) + movies projects subscribers topics tasks ) MATCH_ATTRIBUTE_NAME = /[a-zA-Z][-_\w]*/ def test_clean_fixtures @@ -46,6 +47,13 @@ class FixturesTest < Test::Unit::TestCase assert_nil(secondRow["author_email_address"]) end + def test_insert_with_datetime + topics = create_fixtures("tasks") + first = Task.find(1) + assert first + end + + def test_bad_format path = File.join(File.dirname(__FILE__), 'fixtures', 'bad_fixtures') Dir.entries(path).each do |file| |