mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Fixes #18492
- Add check for not deleting previously created fixtures, to overcome sti fixtures from multiple files - Added fixtures and fixtures test to verify the same - Fixed wrong fixtures duplicating data insertion in same table
This commit is contained in:
parent
850159bd2c
commit
4ae59ebee8
7 changed files with 46 additions and 12 deletions
|
@ -521,12 +521,16 @@ module ActiveRecord
|
||||||
update_all_loaded_fixtures fixtures_map
|
update_all_loaded_fixtures fixtures_map
|
||||||
|
|
||||||
connection.transaction(:requires_new => true) do
|
connection.transaction(:requires_new => true) do
|
||||||
|
deleted_tables = []
|
||||||
fixture_sets.each do |fs|
|
fixture_sets.each do |fs|
|
||||||
conn = fs.model_class.respond_to?(:connection) ? fs.model_class.connection : connection
|
conn = fs.model_class.respond_to?(:connection) ? fs.model_class.connection : connection
|
||||||
table_rows = fs.table_rows
|
table_rows = fs.table_rows
|
||||||
|
|
||||||
table_rows.each_key do |table|
|
table_rows.each_key do |table|
|
||||||
conn.delete "DELETE FROM #{conn.quote_table_name(table)}", 'Fixture Delete'
|
unless deleted_tables.include? table
|
||||||
|
conn.delete "DELETE FROM #{conn.quote_table_name(table)}", 'Fixture Delete'
|
||||||
|
end
|
||||||
|
deleted_tables << table
|
||||||
end
|
end
|
||||||
|
|
||||||
table_rows.each do |fixture_set_name, rows|
|
table_rows.each do |fixture_set_name, rows|
|
||||||
|
|
|
@ -672,7 +672,8 @@ class FasterFixturesTest < ActiveRecord::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
class FoxyFixturesTest < ActiveRecord::TestCase
|
class FoxyFixturesTest < ActiveRecord::TestCase
|
||||||
fixtures :parrots, :parrots_pirates, :pirates, :treasures, :mateys, :ships, :computers, :developers, :"admin/accounts", :"admin/users"
|
fixtures :parrots, :parrots_pirates, :pirates, :treasures, :mateys, :ships, :computers,
|
||||||
|
:developers, :"admin/accounts", :"admin/users", :live_parrots, :dead_parrots
|
||||||
|
|
||||||
if ActiveRecord::Base.connection.adapter_name == 'PostgreSQL'
|
if ActiveRecord::Base.connection.adapter_name == 'PostgreSQL'
|
||||||
require 'models/uuid_parent'
|
require 'models/uuid_parent'
|
||||||
|
@ -812,6 +813,12 @@ class FoxyFixturesTest < ActiveRecord::TestCase
|
||||||
assert_equal pirates(:blackbeard), parrots(:polly).killer
|
assert_equal pirates(:blackbeard), parrots(:polly).killer
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_supports_sti_with_respective_files
|
||||||
|
assert_kind_of LiveParrot, live_parrots(:dusty)
|
||||||
|
assert_kind_of DeadParrot, dead_parrots(:deadbird)
|
||||||
|
assert_equal pirates(:blackbeard), dead_parrots(:deadbird).killer
|
||||||
|
end
|
||||||
|
|
||||||
def test_namespaced_models
|
def test_namespaced_models
|
||||||
assert admin_accounts(:signals37).users.include?(admin_users(:david))
|
assert admin_accounts(:signals37).users.include?(admin_users(:david))
|
||||||
assert_equal 2, admin_accounts(:signals37).users.size
|
assert_equal 2, admin_accounts(:signals37).users.size
|
||||||
|
@ -834,9 +841,9 @@ class CustomNameForFixtureOrModelTest < ActiveRecord::TestCase
|
||||||
set_fixture_class :randomly_named_a9 =>
|
set_fixture_class :randomly_named_a9 =>
|
||||||
ClassNameThatDoesNotFollowCONVENTIONS,
|
ClassNameThatDoesNotFollowCONVENTIONS,
|
||||||
:'admin/randomly_named_a9' =>
|
:'admin/randomly_named_a9' =>
|
||||||
Admin::ClassNameThatDoesNotFollowCONVENTIONS,
|
Admin::ClassNameThatDoesNotFollowCONVENTIONS1,
|
||||||
'admin/randomly_named_b0' =>
|
'admin/randomly_named_b0' =>
|
||||||
Admin::ClassNameThatDoesNotFollowCONVENTIONS
|
Admin::ClassNameThatDoesNotFollowCONVENTIONS2
|
||||||
|
|
||||||
fixtures :randomly_named_a9, 'admin/randomly_named_a9',
|
fixtures :randomly_named_a9, 'admin/randomly_named_a9',
|
||||||
:'admin/randomly_named_b0'
|
:'admin/randomly_named_b0'
|
||||||
|
@ -847,15 +854,15 @@ class CustomNameForFixtureOrModelTest < ActiveRecord::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_named_accessor_for_randomly_named_namespaced_fixture_and_class
|
def test_named_accessor_for_randomly_named_namespaced_fixture_and_class
|
||||||
assert_kind_of Admin::ClassNameThatDoesNotFollowCONVENTIONS,
|
assert_kind_of Admin::ClassNameThatDoesNotFollowCONVENTIONS1,
|
||||||
admin_randomly_named_a9(:first_instance)
|
admin_randomly_named_a9(:first_instance)
|
||||||
assert_kind_of Admin::ClassNameThatDoesNotFollowCONVENTIONS,
|
assert_kind_of Admin::ClassNameThatDoesNotFollowCONVENTIONS2,
|
||||||
admin_randomly_named_b0(:second_instance)
|
admin_randomly_named_b0(:second_instance)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_table_name_is_defined_in_the_model
|
def test_table_name_is_defined_in_the_model
|
||||||
assert_equal 'randomly_named_table', ActiveRecord::FixtureSet::all_loaded_fixtures["admin/randomly_named_a9"].table_name
|
assert_equal 'randomly_named_table2', ActiveRecord::FixtureSet::all_loaded_fixtures["admin/randomly_named_a9"].table_name
|
||||||
assert_equal 'randomly_named_table', Admin::ClassNameThatDoesNotFollowCONVENTIONS.table_name
|
assert_equal 'randomly_named_table2', Admin::ClassNameThatDoesNotFollowCONVENTIONS1.table_name
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
5
activerecord/test/fixtures/dead_parrots.yml
vendored
Normal file
5
activerecord/test/fixtures/dead_parrots.yml
vendored
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
deadbird:
|
||||||
|
name: "Dusty DeadBird"
|
||||||
|
treasures: [ruby, sapphire]
|
||||||
|
parrot_sti_class: DeadParrot
|
||||||
|
killer: blackbeard
|
4
activerecord/test/fixtures/live_parrots.yml
vendored
Normal file
4
activerecord/test/fixtures/live_parrots.yml
vendored
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
dusty:
|
||||||
|
name: "Dusty Bluebird"
|
||||||
|
treasures: [ruby, sapphire]
|
||||||
|
parrot_sti_class: LiveParrot
|
|
@ -1,3 +1,7 @@
|
||||||
class Admin::ClassNameThatDoesNotFollowCONVENTIONS < ActiveRecord::Base
|
class Admin::ClassNameThatDoesNotFollowCONVENTIONS1 < ActiveRecord::Base
|
||||||
self.table_name = :randomly_named_table
|
self.table_name = :randomly_named_table2
|
||||||
|
end
|
||||||
|
|
||||||
|
class Admin::ClassNameThatDoesNotFollowCONVENTIONS2 < ActiveRecord::Base
|
||||||
|
self.table_name = :randomly_named_table3
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
class ClassNameThatDoesNotFollowCONVENTIONS < ActiveRecord::Base
|
class ClassNameThatDoesNotFollowCONVENTIONS < ActiveRecord::Base
|
||||||
self.table_name = :randomly_named_table
|
self.table_name = :randomly_named_table1
|
||||||
end
|
end
|
||||||
|
|
|
@ -623,7 +623,17 @@ ActiveRecord::Schema.define do
|
||||||
t.string :type
|
t.string :type
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table :randomly_named_table, force: true do |t|
|
create_table :randomly_named_table1, force: true do |t|
|
||||||
|
t.string :some_attribute
|
||||||
|
t.integer :another_attribute
|
||||||
|
end
|
||||||
|
|
||||||
|
create_table :randomly_named_table2, force: true do |t|
|
||||||
|
t.string :some_attribute
|
||||||
|
t.integer :another_attribute
|
||||||
|
end
|
||||||
|
|
||||||
|
create_table :randomly_named_table3, force: true do |t|
|
||||||
t.string :some_attribute
|
t.string :some_attribute
|
||||||
t.integer :another_attribute
|
t.integer :another_attribute
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue