Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #1911: more_flexible_fixture_architecture-3b.patch

File more_flexible_fixture_architecture-3b.patch, 22.5 kB (added by duane.johnson@gmail.com, 4 years ago)

Updated patch, resolves single file fixtures problem, patch no longer stale

  • lib/active_record/fixtures.rb

    old new  
    22require 'yaml' 
    33require 'csv' 
    44 
     5# A FixtureGroup is a set of fixtures identified by a name.  Normally, this is the name of the 
     6# corresponding fixture filename.  For example, when you declare the use of fixtures in a 
     7# TestUnit class, like so: 
     8#   fixtures :users 
     9# you are creating a FixtureGroup whose name is 'users', and whose defaults are set such that the 
     10# +class_name+, +file_name+ and +table_name+ are guessed from the FixtureGroup's name. 
     11class FixtureGroup 
     12  attr_accessor :table_name, :class_name, :connection 
     13  attr_reader :group_name, :file_name 
     14 
     15  def initialize(file_name, optional_names = {}) 
     16    self.file_name = file_name 
     17    self.group_name = optional_names[:group_name] || file_name 
     18    if optional_names[:table_name] 
     19      self.table_name = optional_names[:table_name] 
     20      self.class_name = optional_names[:class_name] || Inflector.classify(@table_name.to_s.gsub('.','_')) 
     21    elsif optional_names[:class_name] 
     22      self.class_name = optional_names[:class_name] 
     23      if Object.const_defined?(@class_name) 
     24        model_class = Object.const_get(@class_name) 
     25        self.table_name = ActiveRecord::Base.table_name_prefix + model_class.table_name + ActiveRecord::Base.table_name_suffix 
     26      end 
     27    end 
     28 
     29    # In case either :table_name or :class_name was not set: 
     30    self.table_name ||= ActiveRecord::Base.table_name_prefix + @group_name.to_s + ActiveRecord::Base.table_name_suffix 
     31    self.class_name ||= Inflector.classify(@table_name.to_s.gsub('.','_')) 
     32  end 
     33 
     34  def file_name=(name) 
     35    @file_name = name.to_s 
     36  end 
     37   
     38  def group_name=(name) 
     39    @group_name = name.to_sym 
     40  end 
     41 
     42  def class_file_name 
     43    Inflector.underscore(@class_name) 
     44  end 
     45   
     46  # Instantiate an array of FixtureGroup objects from an array of strings (table_names) 
     47  def self.array_from_names(names) 
     48    names.collect { |n| FixtureGroup.new(n) } 
     49  end 
     50   
     51  def hash 
     52    @group_name.hash 
     53  end 
     54   
     55  def eql?(other) 
     56    @group_name.eql? other.group_name 
     57  end 
     58end 
     59 
    560# Fixtures are a way of organizing data that you want to test against; in short, sample data. They come in 3 flavours: 
    661# 
    762#   1.  YAML fixtures 
     
    193248#      Use InnoDB, MaxDB, or NDB instead. 
    194249class Fixtures < Hash 
    195250  DEFAULT_FILTER_RE = /\.ya?ml$/ 
     251   
     252  cattr_accessor :all_loaded_fixtures 
     253  self.all_loaded_fixtures = {} 
    196254 
    197   def self.instantiate_fixtures(object, table_name, fixtures, load_instances=true) 
    198     old_logger_level = ActiveRecord::Base.logger.level 
    199     ActiveRecord::Base.logger.level = Logger::ERROR 
     255  class << self 
     256    def instantiate_fixtures(object, fixture_group_name, fixtures, load_instances=true) 
     257      old_logger_level = ActiveRecord::Base.logger.level 
     258      ActiveRecord::Base.logger.level = Logger::ERROR 
    200259 
    201     object.instance_variable_set "@#{table_name.to_s.gsub('.','_')}", fixtures 
    202     if load_instances 
    203       fixtures.each do |name, fixture| 
    204         if model = fixture.find 
    205           object.instance_variable_set "@#{name}", model 
     260      # table_name.to_s.gsub('.','_') replaced by 'fixture_group_name' 
     261      object.instance_variable_set "@#{fixture_group_name}", fixtures 
     262      if load_instances 
     263        fixtures.each do |name, fixture| 
     264          if model = fixture.find 
     265            object.instance_variable_set "@#{name}", model 
     266          end 
    206267        end 
    207268      end 
     269 
     270      ActiveRecord::Base.logger.level = old_logger_level 
    208271    end 
    209272 
    210     ActiveRecord::Base.logger.level = old_logger_level 
    211   end 
    212    
    213   def self.instantiate_all_loaded_fixtures(object, load_instances=true) 
    214     all_loaded_fixtures.each do |table_name, fixtures| 
    215       Fixtures.instantiate_fixtures(object, table_name, fixtures, load_instances) 
     273    def instantiate_all_loaded_fixtures(object, load_instances=true) 
     274      all_loaded_fixtures.each do |fixture_group_name, fixtures| 
     275        Fixtures.instantiate_fixtures(object, fixture_group_name, fixtures, load_instances) 
     276      end 
    216277    end 
    217   end 
    218    
    219   cattr_accessor :all_loaded_fixtures 
    220   self.all_loaded_fixtures = {} 
    221278 
    222   def self.create_fixtures(fixtures_directory, *table_names) 
    223     connection = block_given? ? yield : ActiveRecord::Base.connection 
    224     old_logger_level = ActiveRecord::Base.logger.level 
     279    def create_fixtures(fixtures_directory, *fixture_groups) 
     280      connection = block_given? ? yield : ActiveRecord::Base.connection 
     281      old_logger_level = ActiveRecord::Base.logger.level 
     282      fixture_groups.flatten! 
     283       
     284      # Backwards compatibility: Allow an array of table names to be passed in, but just use them 
     285      # to create an array of FixtureGroup objects 
     286      if not fixture_groups.empty? and fixture_groups.first.is_a?(String) 
     287        fixture_groups = FixtureGroup.array_from_names(fixture_groups) 
     288      end 
    225289 
    226     begin 
    227       ActiveRecord::Base.logger.level = Logger::ERROR 
     290      begin 
     291        ActiveRecord::Base.logger.level = Logger::ERROR 
    228292 
    229       fixtures_map = {} 
    230       fixtures = table_names.flatten.map do |table_name| 
    231         fixtures_map[table_name] = Fixtures.new(connection, File.split(table_name.to_s).last, File.join(fixtures_directory, table_name.to_s)) 
    232       end                
    233       all_loaded_fixtures.merge! fixtures_map   
    234        
    235        
    236       connection.transaction do 
    237         fixtures.reverse.each { |fixture| fixture.delete_existing_fixtures } 
    238         fixtures.each { |fixture| fixture.insert_fixtures } 
     293        fixtures_map = {} 
     294        fixtures = fixture_groups.map do |group| 
     295          fixtures_map[group.group_name] = Fixtures.new(connection, fixtures_directory, group) 
     296        end                
     297        # Make sure all refs to all_loaded_fixtures use group_name as hash index, not table_name 
     298        all_loaded_fixtures.merge! fixtures_map   
     299 
     300        connection.transaction do 
     301          fixtures.reverse.each { |fixture| fixture.delete_existing_fixtures } 
     302          fixtures.each { |fixture| fixture.insert_fixtures } 
     303        end 
     304 
     305        reset_sequences(connection, fixture_groups) if connection.is_a?(ActiveRecord::ConnectionAdapters::PostgreSQLAdapter) 
     306 
     307        return fixtures.size > 1 ? fixtures : fixtures.first 
     308      ensure 
     309        ActiveRecord::Base.logger.level = old_logger_level 
    239310      end 
    240        
    241       reset_sequences(connection, table_names) if connection.is_a?(ActiveRecord::ConnectionAdapters::PostgreSQLAdapter) 
    242  
    243       return fixtures.size > 1 ? fixtures : fixtures.first 
    244     ensure 
    245       ActiveRecord::Base.logger.level = old_logger_level 
    246311    end 
    247   end 
    248312 
    249   # Start PostgreSQL fixtures at id 1.  Skip tables without models 
    250   # and models with nonstandard primary keys. 
    251   def self.reset_sequences(connection, table_names) 
    252     table_names.flatten.each do |table| 
    253       if table_class = table.to_s.classify.constantize rescue nil 
    254         pk = table_class.columns_hash[table_class.primary_key] 
    255         if pk and pk.type == :integer 
    256           connection.execute( 
    257             "SELECT setval('#{table}_#{pk.name}_seq', (SELECT COALESCE(MAX(#{pk.name}), 0)+1 FROM #{table}), false)",  
    258             'Setting Sequence' 
    259           ) 
     313    # Start PostgreSQL fixtures at id 1.  Skip tables without models 
     314    # and models with nonstandard primary keys. 
     315    def reset_sequences(connection, fixture_groups) 
     316      fixture_groups.flatten.each do |group| 
     317        if klass = group.class_name.constantize rescue nil 
     318          pk = klass.columns_hash[klass.primary_key] 
     319          if pk and pk.type == :integer 
     320            connection.execute( 
     321              "SELECT setval('#{group.table_name}_#{pk.name}_seq', (SELECT COALESCE(MAX(#{pk.name}), 0)+1 FROM #{group.table_name}), false)",  
     322              'Setting Sequence' 
     323            ) 
     324          end 
    260325        end 
    261326      end 
    262327    end 
    263328  end 
    264329 
    265   attr_reader :table_name 
     330  attr_accessor :connection, :fixtures_directory, :file_filter 
     331  attr_accessor :fixture_group 
    266332 
    267   def initialize(connection, table_name, fixture_path, file_filter = DEFAULT_FILTER_RE) 
    268     @connection, @table_name, @fixture_path, @file_filter = connection, table_name, fixture_path, file_filter 
    269  
    270     @class_name = Inflector.classify(@table_name) 
    271     @table_name = ActiveRecord::Base.table_name_prefix + @table_name + ActiveRecord::Base.table_name_suffix 
     333  def initialize(connection, fixtures_directory, fixture_group, file_filter = DEFAULT_FILTER_RE) 
     334    @connection, @fixtures_directory = connection, fixtures_directory 
     335    @fixture_group = fixture_group 
     336    @file_filter = file_filter 
    272337    read_fixture_files 
    273338  end 
    274339 
    275340  def delete_existing_fixtures 
    276     @connection.delete "DELETE FROM #{@table_name}", 'Fixture Delete' 
     341    @connection.delete "DELETE FROM #{@fixture_group.table_name}", 'Fixture Delete' 
    277342  end 
    278343 
    279344  def insert_fixtures 
    280345    values.each do |fixture| 
    281       @connection.execute "INSERT INTO #{@table_name} (#{fixture.key_list}) VALUES (#{fixture.value_list})", 'Fixture Insert' 
     346      @connection.execute "INSERT INTO #{@fixture_group.table_name} (#{fixture.key_list}) VALUES (#{fixture.value_list})", 'Fixture Insert' 
    282347    end 
    283348  end 
    284349 
    285350  private 
    286351    def read_fixture_files 
    287352      if File.file?(yaml_file_path) 
    288         # YAML fixtures 
    289         begin 
    290           yaml = YAML::load(erb_render(IO.read(yaml_file_path))) 
    291           yaml.each { |name, data| self[name] = Fixture.new(data, @class_name) } if yaml 
    292         rescue Exception=>boom 
    293           raise Fixture::FormatError, "a YAML error occured parsing #{yaml_file_path}. Please note that YAML must be consistently indented using spaces. Tabs are not allowed. Please have a look at http://www.yaml.org/faq.html\nThe exact error was:\n  #{boom.class}: #{boom}" 
    294         end 
     353        read_yaml_fixture_files 
    295354      elsif File.file?(csv_file_path) 
    296         # CSV fixtures 
    297         reader = CSV::Reader.create(erb_render(IO.read(csv_file_path))) 
    298         header = reader.shift 
    299         i = 0 
    300         reader.each do |row| 
    301           data = {} 
    302           row.each_with_index { |cell, j| data[header[j].to_s.strip] = cell.to_s.strip } 
    303           self["#{Inflector::underscore(@class_name)}_#{i+=1}"]= Fixture.new(data, @class_name) 
    304         end 
     355        read_csv_fixture_files 
    305356      elsif File.file?(deprecated_yaml_file_path) 
    306357        raise Fixture::FormatError, ".yml extension required: rename #{deprecated_yaml_file_path} to #{yaml_file_path}" 
     358      elsif File.directory?(single_file_fixtures_path) 
     359        read_standard_fixture_files 
    307360      else 
    308         # Standard fixtures 
    309         Dir.entries(@fixture_path).each do |file| 
    310           path = File.join(@fixture_path, file) 
    311           if File.file?(path) and file !~ @file_filter 
    312             self[file] = Fixture.new(path, @class_name) 
    313           end 
     361        raise Fixture::FixtureError, "Couldn't find a yaml, csv or standard file to load at #{@fixtures_directory} (#{@fixture_group.file_name})." 
     362      end 
     363    end 
     364 
     365    def read_yaml_fixture_files 
     366      # YAML fixtures 
     367      begin 
     368        yaml = YAML::load(erb_render(IO.read(yaml_file_path))) 
     369        yaml.each { |name, data| self[name] = Fixture.new(data, @fixture_group.class_name) } if yaml 
     370      rescue Exception=>boom 
     371        raise Fixture::FormatError, "a YAML error occured parsing #{yaml_file_path}. Please note that YAML must be consistently indented using spaces. Tabs are not allowed. Please have a look at http://www.yaml.org/faq.html\nThe exact error was:\n  #{boom.class}: #{boom}" 
     372      end 
     373    end 
     374 
     375    def read_csv_fixture_files 
     376      # CSV fixtures 
     377      reader = CSV::Reader.create(erb_render(IO.read(csv_file_path))) 
     378      header = reader.shift 
     379      i = 0 
     380      reader.each do |row| 
     381        data = {} 
     382        row.each_with_index { |cell, j| data[header[j].to_s.strip] = cell.to_s.strip } 
     383        self["#{@fixture_group.class_file_name}_#{i+=1}"]= Fixture.new(data, @fixture_group.class_name) 
     384      end 
     385    end 
     386 
     387    def read_standard_fixture_files 
     388      # Standard fixtures 
     389      path = File.join(@fixtures_directory, @fixture_group.file_name) 
     390      Dir.entries(path).each do |file| 
     391        path = File.join(@fixtures_directory, @fixture_group.file_name, file) 
     392        if File.file?(path) and file !~ @file_filter 
     393          self[file] = Fixture.new(path, @fixture_group.class_name) 
    314394        end 
    315395      end 
    316396    end 
    317397 
    318398    def yaml_file_path 
    319       "#{@fixture_path}.yml" 
     399      fixture_path_with_extension ".yml" 
    320400    end 
    321401 
    322402    def deprecated_yaml_file_path 
    323       "#{@fixture_path}.yaml" 
     403      fixture_path_with_extension ".yaml" 
    324404    end 
    325405 
    326406    def csv_file_path 
    327       @fixture_path + ".csv" 
     407      fixture_path_with_extension ".csv" 
    328408    end 
    329  
    330     def yaml_fixtures_key(path) 
    331       File.basename(@fixture_path).split(".").first 
     409     
     410    def single_file_fixtures_path 
     411      fixture_path_with_extension "" 
    332412    end 
    333413 
     414    def fixture_path_with_extension(ext) 
     415      File.join(@fixtures_directory, @fixture_group.file_name + ext) 
     416    end       
     417 
    334418    def erb_render(fixture_content) 
    335419      ERB.new(fixture_content).result 
    336420    end 
     
    399483module Test #:nodoc: 
    400484  module Unit #:nodoc: 
    401485    class TestCase #:nodoc: 
    402       cattr_accessor :fixture_path 
     486      cattr_accessor :fixtures_directory 
     487      class_inheritable_accessor :fixture_groups 
    403488      class_inheritable_accessor :fixture_table_names 
    404489      class_inheritable_accessor :use_transactional_fixtures 
    405490      class_inheritable_accessor :use_instantiated_fixtures   # true, false, or :no_instances 
    406491      class_inheritable_accessor :pre_loaded_fixtures 
    407492 
    408       self.fixture_table_names = [] 
     493      self.fixture_groups = [] 
    409494      self.use_transactional_fixtures = false 
    410495      self.use_instantiated_fixtures = true 
    411496      self.pre_loaded_fixtures = false 
    412497 
    413498      @@already_loaded_fixtures = {} 
    414499 
    415       def self.fixtures(*table_names) 
    416         table_names = table_names.flatten 
    417         self.fixture_table_names |= table_names 
    418         require_fixture_classes(table_names) 
    419         setup_fixture_accessors(table_names) 
     500      # Backwards compatibility 
     501      def self.fixture_path=(path); self.fixtures_directory = path; end 
     502      def self.fixture_path; self.fixtures_directory; end 
     503      def fixture_group_names; fixture_groups.collect { |g| g.group_name }; end 
     504      def fixture_table_names; fixture_group_names; end 
     505 
     506      def self.fixture(file_name, options = {}) 
     507        self.fixture_groups |= [FixtureGroup.new(file_name, options)] 
     508        require_fixture_classes 
     509        setup_fixture_accessors 
    420510      end 
    421511 
    422       def self.require_fixture_classes(table_names=nil) 
    423         (table_names || fixture_table_names).each do |table_name|  
     512      def self.fixtures(*file_names) 
     513        self.fixture_groups |= FixtureGroup.array_from_names(file_names.flatten) 
     514        require_fixture_classes 
     515        setup_fixture_accessors 
     516      end 
     517 
     518      def self.require_fixture_classes(fixture_groups_override = nil) 
     519        (fixture_groups_override || fixture_groups).each do |group|  
    424520          begin 
    425             require Inflector.singularize(table_name.to_s) 
     521            require group.class_file_name 
    426522          rescue LoadError 
    427523            # Let's hope the developer has included it himself 
    428524          end 
    429525        end 
    430526      end 
    431527 
    432       def self.setup_fixture_accessors(table_names=nil) 
    433         (table_names || fixture_table_names).each do |table_name| 
    434           table_name = table_name.to_s.tr('.','_') 
    435           define_method(table_name) do |fixture, *optionals| 
     528      def self.setup_fixture_accessors(fixture_groups_override=nil) 
     529        (fixture_groups_override || fixture_groups).each do |group| 
     530          define_method(group.group_name) do |fixture, *optionals| 
    436531            force_reload = optionals.shift 
    437             @fixture_cache[table_name] ||= Hash.new 
    438             @fixture_cache[table_name][fixture] = nil if force_reload 
    439             @fixture_cache[table_name][fixture] ||= @loaded_fixtures[table_name][fixture.to_s].find 
     532            @fixture_cache[group.group_name] ||= Hash.new 
     533            @fixture_cache[group.group_name][fixture] = nil if force_reload 
     534            @fixture_cache[group.group_name][fixture] ||= @loaded_fixtures[group.group_name][fixture.to_s].find 
    440535          end 
    441536        end 
    442537      end 
     
    519614      private 
    520615        def load_fixtures 
    521616          @loaded_fixtures = {} 
    522           fixtures = Fixtures.create_fixtures(fixture_path, fixture_table_names) 
     617          fixtures = Fixtures.create_fixtures(fixtures_directory, fixture_groups) 
    523618          unless fixtures.nil? 
    524619            if fixtures.instance_of?(Fixtures) 
    525               @loaded_fixtures[fixtures.table_name] = fixtures 
     620              @loaded_fixtures[fixtures.fixture_group.group_name] = fixtures 
    526621            else 
    527               fixtures.each { |f| @loaded_fixtures[f.table_name] = f } 
     622              fixtures.each { |f| @loaded_fixtures[f.fixture_group.group_name] = f } 
    528623            end 
    529624          end 
    530625        end 
     
    536631          if pre_loaded_fixtures 
    537632            raise RuntimeError, 'Load fixtures before instantiating them.' if Fixtures.all_loaded_fixtures.empty? 
    538633            unless @@required_fixture_classes 
    539               self.class.require_fixture_classes Fixtures.all_loaded_fixtures.keys 
     634              groups = Fixtures.all_loaded_fixtures.values.collect { |f| f.group_name } 
     635              self.class.require_fixture_classes groups 
    540636              @@required_fixture_classes = true 
    541637            end 
    542638            Fixtures.instantiate_all_loaded_fixtures(self, load_instances?) 
    543639          else 
    544640            raise RuntimeError, 'Load fixtures before instantiating them.' if @loaded_fixtures.nil? 
    545             @loaded_fixtures.each do |table_name, fixtures| 
    546               Fixtures.instantiate_fixtures(self, table_name, fixtures, load_instances?) 
     641            @loaded_fixtures.each do |fixture_group_name, fixtures| 
     642              Fixtures.instantiate_fixtures(self, fixture_group_name, fixtures, load_instances?) 
    547643            end 
    548644          end 
    549645        end 
  • test/fixtures/topics2.yml

    old new  
     1third: 
     2  id: 3 
     3  title: The Third Topic 
     4  author_name: Duane 
     5  author_email_address: david@loudthinking.com 
     6  written_on: 2003-07-16t15:28:00.00+01:00 
     7  last_read: 2004-04-15 
     8  bonus_time: 2005-01-30t15:28:00.00+01:00 
     9  content: Have a nice day 
     10  approved: 0 
     11  replies_count: 0 
     12 
     13fourth: 
     14  id: 4 
     15  title: The Fourth topic 
     16  author_name: John 
     17  written_on: 2003-07-15t15:28:00.00+01:00 
     18  content: Have a nice day 
     19  approved: 1 
     20  replies_count: 2 
     21  parent_id: 1 
  • test/fixtures_test.rb

    old new  
    106106    end 
    107107  end 
    108108 
     109  def test_fixtures_not_found 
     110    assert_raise(Fixture::FixtureError) { 
     111      Fixtures.new(nil, File.join(File.dirname(__FILE__), 'fixtures'), FixtureGroup.new("bad_extension")) 
     112    } 
     113  end 
     114 
    109115  def test_deprecated_yaml_extension 
    110116    assert_raise(Fixture::FormatError) { 
    111       Fixtures.new(nil, 'bad_extension', File.join(File.dirname(__FILE__), 'fixtures')) 
     117      Fixtures.new(nil, File.join(File.dirname(__FILE__), 'fixtures', 'bad_fixtures'), FixtureGroup.new("deprecated")) 
    112118    } 
    113119  end 
    114120 
     
    139145  end 
    140146 
    141147  def test_empty_yaml_fixture 
    142     assert_not_nil Fixtures.new( Account.connection, "accounts", File.dirname(__FILE__) + "/fixtures/naked/yml/accounts"
     148    assert_not_nil Fixtures.new( Account.connection, File.dirname(__FILE__) + "/fixtures/naked/yml/", FixtureGroup.new("accounts")
    143149  end 
    144150 
    145151  def test_empty_yaml_fixture_with_a_comment_in_it 
    146     assert_not_nil Fixtures.new( Account.connection, "companies", File.dirname(__FILE__) + "/fixtures/naked/yml/companies"
     152    assert_not_nil Fixtures.new( Account.connection, File.dirname(__FILE__) + "/fixtures/naked/yml/", FixtureGroup.new("companies")
    147153  end 
    148154 
    149155  def test_dirty_dirty_yaml_file 
    150156    assert_raises(Fixture::FormatError) do 
    151       Fixtures.new( Account.connection, "courses", File.dirname(__FILE__) + "/fixtures/naked/yml/courses"
     157      Fixtures.new( Account.connection, File.dirname(__FILE__) + "/fixtures/naked/yml/", FixtureGroup.new("courses")
    152158    end 
    153159  end 
    154160 
    155161  def test_empty_csv_fixtures 
    156     assert_not_nil Fixtures.new( Account.connection, "accounts", File.dirname(__FILE__) + "/fixtures/naked/csv/accounts"
     162    assert_not_nil Fixtures.new( Account.connection, File.dirname(__FILE__) + "/fixtures/naked/csv/", FixtureGroup.new("accounts")
    157163  end 
    158164end 
    159165 
     
    250256 
    251257end 
    252258 
     259class FixturesGroupTest < Test::Unit::TestCase 
     260  def test_get_table_name_from_model_class 
     261    fg = FixtureGroup.new(:filedoesnotexist, :class_name => "DeveloperWithAggregate") 
     262    assert_equal fg.table_name, 'developers' 
     263    assert_equal fg.class_name, 'DeveloperWithAggregate' 
     264  end 
     265   
     266  def test_assume_correct_class_name_from_table_name 
     267    fg = FixtureGroup.new(:developers, :table_name => "tests") 
     268    assert_equal fg.table_name, 'tests' 
     269    assert_equal fg.class_name, 'Test' 
     270  end 
    253271 
     272  def test_file_name_is_a_string 
     273    fg = FixtureGroup.new(:developers) 
     274    assert String === fg.file_name 
     275  end 
     276   
     277  def test_fixture_group_name 
     278    fg = FixtureGroup.new(:developers) 
     279    assert Symbol === fg.group_name 
     280    assert_equal fg.group_name, :developers 
     281     
     282    fg = FixtureGroup.new(:developers, :group_name => "other") 
     283    assert Symbol === fg.group_name 
     284    assert_equal fg.group_name, :other 
     285  end 
     286end 
    254287 
     288class MultipleFixturesForTheSameTableTest < Test::Unit::TestCase 
     289  self.use_instantiated_fixtures = true 
     290  fixture :topics, :class_name => "Topic" 
     291  fixture :topics2, :class_name => "Topic" 
     292   
     293  def test_loaded_fixtures 
     294    assert_equal @topics.size, 2 
     295    assert_equal @topics2.size, 2 
     296    union = Topic.find(:all) 
     297    assert_equal union.size, 4 
     298  end 
     299end 
    255300 
     301class MixSingularAndPluralFixturesTest < Test::Unit::TestCase 
     302  self.use_instantiated_fixtures = true 
     303  fixtures :topics, :developers, :accounts 
     304  fixture :topics2, :table_name => "topics" 
     305   
     306  def test_loaded_fixtures 
     307    assert_equal @topics.size, 2 
     308    assert_equal @topics2.size, 2 
     309    union = Topic.find(:all) 
     310    assert_equal union.size, 4 
     311  end 
     312end 
    256313 
    257  
     314class AlternateFileFixturesTest < Test::Unit::TestCase 
     315  self.use_instantiated_fixtures = true 
     316  fixture :topics2, :class_name => "Topic" 
     317   
     318  def test_alternate_fixture_file_was_loaded 
     319    assert_equal @topics2.size, 2 
     320    assert_nil @first 
     321    assert_nil @second 
     322    assert_equal @third.id, 3 
     323    assert_equal @fourth.id, 4 
     324    topics = Topic.find(:all) 
     325    assert_equal @topics2.size, 2 
     326  end 
     327end