diff --git a/lib/dataset.rb b/lib/dataset.rb index 00d1e43..9435a36 100644 --- a/lib/dataset.rb +++ b/lib/dataset.rb @@ -1,5 +1,5 @@ -require 'activesupport' -require 'activerecord' +require 'active_support' +require 'active_record' require 'dataset/version' require 'dataset/instance_methods' @@ -65,27 +65,13 @@ # require 'dataset' # class Test::Unit::TestCase # include Dataset -# datasets_directory "#{RAILS_ROOT}/test/datasets" +# datasets_directory "#{Rails.root}/test/datasets" # end # # Note that should you desire your Dataset::Base subclasses be # auto-discovered, you can set the _datasets_directory_. # module Dataset - def self.included(test_context) # :nodoc: - if test_context.name =~ /World\Z/ - require 'dataset/extensions/cucumber' - elsif test_context.name =~ /TestCase\Z/ - require 'dataset/extensions/test_unit' - elsif test_context.name =~ /ExampleGroup\Z/ - require 'dataset/extensions/rspec' - else - raise "I don't understand your test framework" - end - - test_context.extend ContextClassMethods - end - # Methods that are added to the class that Dataset is included in (the test # context class). # @@ -97,19 +83,15 @@ def self.extended(context_class) # :nodoc: end end - mattr_accessor :datasets_database_dump_path - self.datasets_database_dump_path = File.expand_path(RAILS_ROOT + '/tmp/dataset') if defined?(RAILS_ROOT) - - # Replaces the default Dataset::Resolver with one that will look for - # dataset class definitions in the specified directory. Captures of the - # database will be stored in a subdirectory 'tmp' (see - # Dataset::Database::Base). - def datasets_directory(path) - Dataset::Resolver.default = Dataset::DirectoryResolver.new(path) - Dataset::ContextClassMethods.datasets_database_dump_path = File.join(path, '/tmp/dataset') + # Replaces the default Dataset::Resolver with one that will look for dataset + # class definitions in the specified directory. Captures of the database + # will be stored in a subdirectory 'tmp' (see Dataset::Database::Base). + def set_dataset_resolver + Dataset::Resolver.default ||= Dataset::DirectoryResolver.new(RSpec.configuration.datasets_directory) end def add_dataset(*datasets, &block) # :nodoc: + set_dataset_resolver dataset_session = dataset_session_in_hierarchy datasets.each { |dataset| dataset_session.add_dataset(self, dataset) } dataset_session.add_dataset(self, Class.new(Dataset::Block) { @@ -119,11 +101,11 @@ def add_dataset(*datasets, &block) # :nodoc: def dataset_session_in_hierarchy # :nodoc: self.dataset_session ||= begin - database_spec = ActiveRecord::Base.configurations['test'].with_indifferent_access + database_spec = ActiveRecord::Base.configurations[Rails.env].with_indifferent_access database_class = Dataset::Database.const_get(database_spec[:adapter].classify) - database = database_class.new(database_spec, Dataset::ContextClassMethods.datasets_database_dump_path) + database = database_class.new(database_spec, RSpec.configuration.datasets_dump_path) Dataset::Session.new(database) end end end -end \ No newline at end of file +end diff --git a/lib/dataset/extensions/rspec.rb b/lib/dataset/extensions/rspec.rb index a8299d4..8212e55 100644 --- a/lib/dataset/extensions/rspec.rb +++ b/lib/dataset/extensions/rspec.rb @@ -1,7 +1,6 @@ module Dataset module Extensions # :nodoc: - - module RSpecExampleGroup # :nodoc: + module RSpec # :nodoc: def dataset(*datasets, &block) add_dataset(*datasets, &block) @@ -18,4 +17,12 @@ def dataset(*datasets, &block) end end -Spec::Example::ExampleGroup.extend Dataset::Extensions::RSpecExampleGroup \ No newline at end of file + +RSpec.configure do |config| + config.extend Dataset::ContextClassMethods + config.extend Dataset::Extensions::RSpec + config.add_setting :datasets_directory, :default => Rails.root + 'spec/datasets' + config.add_setting :datasets_dump_path, :default => Rails.root + 'tmp/dataset' +end + +Dataset::Resolver.default = nil diff --git a/lib/dataset/record/heirarchy.rb b/lib/dataset/record/heirarchy.rb index c38a3df..45913db 100644 --- a/lib/dataset/record/heirarchy.rb +++ b/lib/dataset/record/heirarchy.rb @@ -31,6 +31,7 @@ def to_s def update(record_class) record_class.ancestors.each do |c| + next unless c.is_a? Class finder_name = model_finder_name(c) unless model_finder_names.include?(finder_name) model_finder_names << finder_name