Skip to content

Commit

Permalink
made to work with Rails 3 + RSpec 2
Browse files Browse the repository at this point in the history
  • Loading branch information
mislav committed Aug 17, 2010
1 parent c4fe809 commit 8a95532
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 33 deletions.
42 changes: 12 additions & 30 deletions lib/dataset.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require 'activesupport'
require 'activerecord'
require 'active_support'
require 'active_record'

require 'dataset/version'
require 'dataset/instance_methods'
Expand Down Expand Up @@ -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).
#
Expand All @@ -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) {
Expand All @@ -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
end
13 changes: 10 additions & 3 deletions lib/dataset/extensions/rspec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
module Dataset
module Extensions # :nodoc:

module RSpecExampleGroup # :nodoc:
module RSpec # :nodoc:
def dataset(*datasets, &block)
add_dataset(*datasets, &block)

Expand All @@ -18,4 +17,12 @@ def dataset(*datasets, &block)

end
end
Spec::Example::ExampleGroup.extend Dataset::Extensions::RSpecExampleGroup

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
1 change: 1 addition & 0 deletions lib/dataset/record/heirarchy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8a95532

Please sign in to comment.