module BigRecord::TestFixtures::ClassMethods
Public Instance Methods
bigrecord_fixtures(*bigrecord_table_names)
click to toggle source
# 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
bigrecord_set_fixture_class(class_names = {})
click to toggle source
# 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
require_bigrecord_fixture_classes(table_names = nil)
click to toggle source
# 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
setup_bigrecord_fixture_accessors(table_names = nil)
click to toggle source
# 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
uses_transaction(*methods)
click to toggle source
# 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
uses_transaction?(method)
click to toggle source
# 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