Module: BigRecord::TestFixtures::ClassMethods

Defined in:
lib/big_record/fixtures.rb

Instance Method Summary

Instance Method Details

- (Object) bigrecord_fixtures(*bigrecord_table_names)



867
868
869
870
871
872
873
874
875
876
877
878
# File 'lib/big_record/fixtures.rb', line 867

def bigrecord_fixtures(*bigrecord_table_names)
  if bigrecord_table_names.first == :all
    bigrecord_table_names = Dir["#{fixture_path}/*.yml"] + Dir["#{fixture_path}/*.csv"]
    bigrecord_table_names.map! { |f| File.basename(f).split('.')[0..-2].join('.') }
  else
    bigrecord_table_names = bigrecord_table_names.flatten.map { |n| n.to_s }
  end

  self.bigrecord_fixture_table_names |= bigrecord_table_names
  require_bigrecord_fixture_classes(bigrecord_table_names)
  setup_bigrecord_fixture_accessors(bigrecord_table_names)
end

- (Object) bigrecord_set_fixture_class(class_names = {})



863
864
865
# File 'lib/big_record/fixtures.rb', line 863

def bigrecord_set_fixture_class(class_names = {})
  self.bigrecord_fixture_class_names = self.bigrecord_fixture_class_names.merge(class_names)
end

- (Object) require_bigrecord_fixture_classes(table_names = nil)



880
881
882
883
884
885
886
887
888
889
890
# File 'lib/big_record/fixtures.rb', line 880

def require_bigrecord_fixture_classes(table_names = nil)
  (table_names || fixture_table_names).each do |table_name|
    file_name = table_name.to_s
    file_name = file_name.singularize if ActiveRecord::Base.pluralize_table_names
    begin
      require_dependency file_name
    rescue LoadError
      # Let's hope the developer has included it himself
    end
  end
end

- (Object) setup_bigrecord_fixture_accessors(table_names = nil)



892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
# File 'lib/big_record/fixtures.rb', line 892

def setup_bigrecord_fixture_accessors(table_names = nil)
  (table_names || fixture_table_names).each do |table_name|
    table_name = table_name.to_s.tr('.', '_')

    define_method(table_name) do |*fixtures|
      force_reload = fixtures.pop if fixtures.last == true || fixtures.last == :reload
      @bigrecord_fixture_cache[table_name] ||= {}

      instances = fixtures.map do |fixture|
        @bigrecord_fixture_cache[table_name].delete(fixture) if force_reload

        if @loaded_bigrecord_fixtures[table_name][fixture.to_s]
          @bigrecord_fixture_cache[table_name][fixture] ||= @loaded_bigrecord_fixtures[table_name][fixture.to_s].find
        else
          raise StandardError, "No fixture with name '#{fixture}' found for table '#{table_name}'"
        end
      end

      instances.size == 1 ? instances.first : instances
    end
  end
end

- (Object) uses_transaction(*methods)



915
916
917
918
# File 'lib/big_record/fixtures.rb', line 915

def uses_transaction(*methods)
  @bigrecord_uses_transaction = [] unless defined?(@bigrecord_uses_transaction)
  @bigrecord_uses_transaction.concat methods.map(&:to_s)
end

- (Boolean) uses_transaction?(method)

Returns:

  • (Boolean)


920
921
922
923
# File 'lib/big_record/fixtures.rb', line 920

def uses_transaction?(method)
  @uses_transaction = [] unless defined?(@uses_transaction)
  @uses_transaction.include?(method.to_s)
end