diff options
author | Jamis Buck <jamis@37signals.com> | 2005-09-02 10:51:23 +0000 |
---|---|---|
committer | Jamis Buck <jamis@37signals.com> | 2005-09-02 10:51:23 +0000 |
commit | e3d34286e338bdd6c7681e08a0d79a955dc24ca1 (patch) | |
tree | b791cf50fd0123c309e812b5206435014a8e4067 | |
parent | bf3f920989f3b1e06109335212c9127396e5cfc2 (diff) | |
download | rails-e3d34286e338bdd6c7681e08a0d79a955dc24ca1.tar.gz rails-e3d34286e338bdd6c7681e08a0d79a955dc24ca1.tar.bz2 rails-e3d34286e338bdd6c7681e08a0d79a955dc24ca1.zip |
Fixtures ignore table name prefix and suffix #1987 [Jakob S]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2101 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
-rw-r--r-- | activerecord/CHANGELOG | 2 | ||||
-rwxr-xr-x | activerecord/lib/active_record/fixtures.rb | 4 | ||||
-rwxr-xr-x | activerecord/test/fixtures_test.rb | 38 |
3 files changed, 43 insertions, 1 deletions
diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG index 67aaed3aea..8405ba92c9 100644 --- a/activerecord/CHANGELOG +++ b/activerecord/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Fixtures ignore table name prefix and suffix #1987 [Jakob S] + * Add documentation for index_type argument to add_index method for migrations #2005 [blaine@odeo.com] * Modify read_attribute to allow a symbol argument #2024 [Ken Kunz] diff --git a/activerecord/lib/active_record/fixtures.rb b/activerecord/lib/active_record/fixtures.rb index dab719946f..fd1de46c1d 100755 --- a/activerecord/lib/active_record/fixtures.rb +++ b/activerecord/lib/active_record/fixtures.rb @@ -232,6 +232,7 @@ class Fixtures < Hash end all_loaded_fixtures.merge! fixtures_map + connection.transaction do fixtures.reverse.each { |fixture| fixture.delete_existing_fixtures } fixtures.each { |fixture| fixture.insert_fixtures } @@ -265,8 +266,9 @@ class Fixtures < Hash def initialize(connection, table_name, fixture_path, file_filter = DEFAULT_FILTER_RE) @connection, @table_name, @fixture_path, @file_filter = connection, table_name, fixture_path, file_filter - @class_name = Inflector.classify(@table_name) + @class_name = Inflector.classify(@table_name) + @table_name = ActiveRecord::Base.table_name_prefix + @table_name + ActiveRecord::Base.table_name_suffix read_fixture_files end diff --git a/activerecord/test/fixtures_test.rb b/activerecord/test/fixtures_test.rb index cc43589e7a..f51de4a6d1 100755 --- a/activerecord/test/fixtures_test.rb +++ b/activerecord/test/fixtures_test.rb @@ -51,6 +51,44 @@ class FixturesTest < Test::Unit::TestCase assert_nil(secondRow["author_email_address"]) end + def test_inserts_with_pre_and_suffix + ActiveRecord::Base.connection.create_table :prefix_topics_suffix do |t| + t.column :title, :string + t.column :author_name, :string + t.column :author_email_address, :string + t.column :written_on, :datetime + t.column :bonus_time, :time + t.column :last_read, :date + t.column :content, :text + t.column :approved, :boolean, :default => true + t.column :replies_count, :integer, :default => 0 + t.column :parent_id, :integer + t.column :type, :string, :limit => 50 + end + + # Store existing prefix/suffix + old_prefix = ActiveRecord::Base.table_name_prefix + old_suffix = ActiveRecord::Base.table_name_suffix + + # Set a prefix/suffix we can test against + ActiveRecord::Base.table_name_prefix = 'prefix_' + ActiveRecord::Base.table_name_suffix = '_suffix' + + topics = create_fixtures("topics") + + # Restore prefix/suffix to its previous values + ActiveRecord::Base.table_name_prefix = old_prefix + ActiveRecord::Base.table_name_suffix = old_suffix + + firstRow = ActiveRecord::Base.connection.select_one("SELECT * FROM prefix_topics_suffix WHERE author_name = 'David'") + assert_equal("The First Topic", firstRow["title"]) + + secondRow = ActiveRecord::Base.connection.select_one("SELECT * FROM prefix_topics_suffix WHERE author_name = 'Mary'") + assert_nil(secondRow["author_email_address"]) + ensure + ActiveRecord::Base.connection.drop_table :prefix_topics_suffix rescue nil + end + def test_insert_with_datetime topics = create_fixtures("tasks") first = Task.find(1) |