From 4e7d344193e32de0c117e5c1eaa28e7c70d14fec Mon Sep 17 00:00:00 2001 From: Tim Linquist Date: Wed, 1 Sep 2010 00:28:11 -0700 Subject: [PATCH 1/7] Initial conversion to rails 3. specs failing --- dataset.gemspec | 8 ++++---- lib/dataset.rb | 4 ++-- plugit/descriptor.rb | 8 ++++---- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/dataset.gemspec b/dataset.gemspec index 138288a..7037681 100644 --- a/dataset.gemspec +++ b/dataset.gemspec @@ -81,12 +81,12 @@ Gem::Specification.new do |s| s.add_runtime_dependency(%q, [">= 2.3.0"]) s.add_runtime_dependency(%q, [">= 2.3.0"]) else - s.add_dependency(%q, [">= 2.3.0"]) - s.add_dependency(%q, [">= 2.3.0"]) + s.add_dependency(%q, [">= 3.0.0"]) + s.add_dependency(%q, [">= 3.0.0"]) end else - s.add_dependency(%q, [">= 2.3.0"]) - s.add_dependency(%q, [">= 2.3.0"]) + s.add_dependency(%q, [">= 3.0.0"]) + s.add_dependency(%q, [">= 3.0.0"]) end end diff --git a/lib/dataset.rb b/lib/dataset.rb index 00d1e43..437b67c 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' diff --git a/plugit/descriptor.rb b/plugit/descriptor.rb index 882092f..daac240 100644 --- a/plugit/descriptor.rb +++ b/plugit/descriptor.rb @@ -9,12 +9,12 @@ dataset.environment :default, 'Released versions of Rails and RSpec' do |env| env.library :rails, :export => "git clone git://github.com/rails/rails.git" do |rails| - rails.after_update { `git fetch origin 2-3-stable:2-3-stable; git checkout 2-3-stable` } - rails.load_paths = %w{/activesupport/lib /activerecord/lib /actionpack/lib} + rails.after_update { `git fetch origin 3-0-stable:3-0-stable; git checkout 3-0-stable` } + rails.load_paths = %w{/active_support/lib /active_record/lib /actionpack/lib} rails.requires = %w{active_support active_record active_record/fixtures action_controller action_view} end - env.library :rspec, :export => "git clone git://github.com/dchelimsky/rspec.git" do |rspec| - rspec.after_update { `git checkout -b rspecrelease 1.1.12 && mkdir -p #{vendor_directory} && ln -nsf #{File.expand_path('.')} #{vendor_directory + '/rspec'}` } + env.library :rspec, :export => "git clone http://github.com/dchelimsky/rspec-rails.git" do |rspec| + rspec.after_update { `git checkout -b rails3 && mkdir -p #{vendor_directory} && ln -nsf #{File.expand_path('.')} #{vendor_directory + '/rspec'}` } rspec.requires = %w{spec} end env.library :cucumber, :export => "git clone git://github.com/aslakhellesoy/cucumber.git" do |cukes| From 7beb14cf58c325a8fd8e84c9a4e9b8b4879cee95 Mon Sep 17 00:00:00 2001 From: Mark Turner Date: Tue, 5 Apr 2011 10:15:59 -0700 Subject: [PATCH 2/7] Trying to make this work with RSpec 2 --- lib/dataset/extensions/rspec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/dataset/extensions/rspec.rb b/lib/dataset/extensions/rspec.rb index a8299d4..0f50c63 100644 --- a/lib/dataset/extensions/rspec.rb +++ b/lib/dataset/extensions/rspec.rb @@ -18,4 +18,4 @@ def dataset(*datasets, &block) end end -Spec::Example::ExampleGroup.extend Dataset::Extensions::RSpecExampleGroup \ No newline at end of file +RSpec::Core::ExampleGroup.extend Dataset::Extensions::RSpecExampleGroup From d2911d6ba48ae590654ab88e0a478886422d974a Mon Sep 17 00:00:00 2001 From: Mark Turner Date: Tue, 5 Apr 2011 10:26:11 -0700 Subject: [PATCH 3/7] Trying to make this work with RSpec 2 - again --- lib/dataset/extensions/rspec.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/dataset/extensions/rspec.rb b/lib/dataset/extensions/rspec.rb index 0f50c63..198d5c7 100644 --- a/lib/dataset/extensions/rspec.rb +++ b/lib/dataset/extensions/rspec.rb @@ -2,6 +2,7 @@ module Dataset module Extensions # :nodoc: module RSpecExampleGroup # :nodoc: + puts "EXTENDED" def dataset(*datasets, &block) add_dataset(*datasets, &block) From d769ddf1d840e38f1bc4d7fc603a58e4b4f626a7 Mon Sep 17 00:00:00 2001 From: Mark Turner Date: Tue, 5 Apr 2011 10:41:26 -0700 Subject: [PATCH 4/7] Removed bullshit --- lib/dataset/extensions/rspec.rb | 3 --- 1 file changed, 3 deletions(-) diff --git a/lib/dataset/extensions/rspec.rb b/lib/dataset/extensions/rspec.rb index 198d5c7..e937c2b 100644 --- a/lib/dataset/extensions/rspec.rb +++ b/lib/dataset/extensions/rspec.rb @@ -1,8 +1,6 @@ module Dataset module Extensions # :nodoc: - module RSpecExampleGroup # :nodoc: - puts "EXTENDED" def dataset(*datasets, &block) add_dataset(*datasets, &block) @@ -16,7 +14,6 @@ def dataset(*datasets, &block) end end end - end end RSpec::Core::ExampleGroup.extend Dataset::Extensions::RSpecExampleGroup From b0ef5916e3dce92ccac7eb7539925e4209a20b04 Mon Sep 17 00:00:00 2001 From: Mark Turner Date: Wed, 6 Apr 2011 00:54:21 -0700 Subject: [PATCH 5/7] Annyone deprecation removed --- lib/dataset.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/dataset.rb b/lib/dataset.rb index 437b67c..05b6d21 100644 --- a/lib/dataset.rb +++ b/lib/dataset.rb @@ -98,7 +98,7 @@ def self.extended(context_class) # :nodoc: end mattr_accessor :datasets_database_dump_path - self.datasets_database_dump_path = File.expand_path(RAILS_ROOT + '/tmp/dataset') if defined?(RAILS_ROOT) + self.datasets_database_dump_path = File.expand_path(::Rails.root.to_s + '/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 @@ -126,4 +126,4 @@ def dataset_session_in_hierarchy # :nodoc: end end end -end \ No newline at end of file +end From 11810adde3df3c3c9903aa4270b8adb06d310571 Mon Sep 17 00:00:00 2001 From: Mark Turner Date: Thu, 7 Apr 2011 17:28:24 -0700 Subject: [PATCH 6/7] Whitespace fixed --- CHANGELOG | 4 +-- README | 40 ++++++++++----------- TODO | 4 +-- lib/dataset.rb | 22 ++++++------ lib/dataset/base.rb | 30 ++++++++-------- lib/dataset/collection.rb | 6 ++-- lib/dataset/load.rb | 12 +++---- lib/dataset/resolver.rb | 28 +++++++-------- lib/dataset/session.rb | 10 +++--- lib/dataset/session_binding.rb | 66 +++++++++++++++++----------------- lib/dataset/version.rb | 2 +- 11 files changed, 112 insertions(+), 112 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 712fa79..e6c6385 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -30,7 +30,7 @@ class Note < ActiveRecord::Base belongs_to :person end - + person_id = create_record Person, :myguy create_record Note, :person => :myguy Note.last.person_id == person_id @@ -60,4 +60,4 @@ *1.0.0 [Scenarios Replacement] (December 15, 2008) -* Drop-in replacement for Scenarios plugin of old [aiwilliams] \ No newline at end of file +* Drop-in replacement for Scenarios plugin of old [aiwilliams] diff --git a/README b/README index 61928b1..f31773e 100644 --- a/README +++ b/README @@ -6,52 +6,52 @@ Dataset loads data intelligently if you use 'nested contexts' in your tests (RSp describe Something do dataset :a => Dataset :a is loaded (at the right time) - - it 'should whatever' - end - - describe More do + + it 'should whatever' + end + + describe More do dataset :b => Dataset :b is loaded. :a data is still there - - it 'should' - end - end - + + it 'should' + end + end + describe Another do => Database is restored to :a, without re-running :a logic it 'should' end end end - + The goal is to see a marked improvement in overall test run speed, basing this on the assumption that it is faster to have the OS copy a file or mySQL dump and load. Of course, we may find this to be a false assumption, but there were plenty of bugs in the former 'Scenarios' - addressing that afforded the opportunity to test the assumption. Dataset does not prevent you from using other libraries like Machinist or factory_girl. If you were to used either of those, you could have a dataset like this: - + require 'faker' - + class OrganizationsDataset < Dataset::Base Sham.name { Faker::Name.name } - + Organization.blueprint do name { Sham.name } end - + def load name_model Organization.make, :org_one end end - + The benefit is that you can reuse interesting sets of data, without sacrificing the utility of those other libraries. describe Organization, 'stuff' do dataset :organizations end - + describe Organization, 'other stuff' do dataset :organizations end - + Get things installed, then read more in the Dataset documentation at http://aiwilliams.github.com/dataset @@ -99,7 +99,7 @@ If you were a user of the Scenarios plugin, and want to do as little as possible == Credits Written by [Adam Williams](http://github.com/aiwilliams). - + Contributors: - [Saturn Flyer](http://www.saturnflyer.com) [github](http://github.com/saturnflyer) @@ -108,4 +108,4 @@ Contributors: --- -Dataset is released under the MIT-License and is Copyright (c)2008 Adam Williams. \ No newline at end of file +Dataset is released under the MIT-License and is Copyright (c)2008 Adam Williams. diff --git a/TODO b/TODO index 4b29dc3..eabbb33 100644 --- a/TODO +++ b/TODO @@ -1,6 +1,6 @@ take any instance variables already in context and make them available to dataset blocks - this is for nested describes I'm not sure about this one. It can be very frustrating to lose context of when the state of an iv is modified. - + add ability to clear the database (some tests wanted to guarantee a clear db) This is acheived with "dataset {}" @@ -12,4 +12,4 @@ describe what happens when someone has a fixtures file - they get loaded after o look into truncating database instead individual table deletes allow configuration of dataset * permatable / global scope -re-evaluation location of some tests that depend on TestCase in non-test/unit tests \ No newline at end of file +re-evaluation location of some tests that depend on TestCase in non-test/unit tests diff --git a/lib/dataset.rb b/lib/dataset.rb index 05b6d21..01d8c60 100644 --- a/lib/dataset.rb +++ b/lib/dataset.rb @@ -19,26 +19,26 @@ require 'dataset/record/model' # == Quick Start -# +# # Write a test. If you want some data in your database, create a dataset. # Start simple. -# +# # describe States do # dataset do # [%w(Colorado CO), %w(North\ Carolina NC), %w(South\ Carolina SC)].each do |name,abbrev| # create_record :state, abbrev.downcase, :name => name, :abbrev => abbrev # end # end -# +# # it 'should have an abbreviated name' # states(:nc).abbrev.should be('NC') # end -# +# # it 'should have a name' # states(:nc).name.should be('North Carolin') # end # end -# +# # Notice that you won't be using _find_id_ or _find_model_ in your tests. You # use methods like _states_ and _state_id_, as in the example above. # @@ -82,10 +82,10 @@ def self.included(test_context) # :nodoc: 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). # @@ -96,10 +96,10 @@ def self.extended(context_class) # :nodoc: superclass_delegating_accessor :dataset_session end end - + mattr_accessor :datasets_database_dump_path self.datasets_database_dump_path = File.expand_path(::Rails.root.to_s + '/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 @@ -108,7 +108,7 @@ def datasets_directory(path) Dataset::Resolver.default = Dataset::DirectoryResolver.new(path) Dataset::ContextClassMethods.datasets_database_dump_path = File.join(path, '/tmp/dataset') end - + def add_dataset(*datasets, &block) # :nodoc: dataset_session = dataset_session_in_hierarchy datasets.each { |dataset| dataset_session.add_dataset(self, dataset) } @@ -116,7 +116,7 @@ def add_dataset(*datasets, &block) # :nodoc: define_method :doload, block }) unless block.nil? end - + def dataset_session_in_hierarchy # :nodoc: self.dataset_session ||= begin database_spec = ActiveRecord::Base.configurations['test'].with_indifferent_access diff --git a/lib/dataset/base.rb b/lib/dataset/base.rb index 20a60b6..85dada4 100644 --- a/lib/dataset/base.rb +++ b/lib/dataset/base.rb @@ -1,5 +1,5 @@ module Dataset - + # The superclass of your Dataset classes. # # It is recommended that you create a dataset using the Dataset::Block @@ -25,11 +25,11 @@ def helpers(&method_definitions) end @helper_methods.module_eval &method_definitions end - + def helper_methods # :nodoc: @helper_methods end - + # Allows a subsclass to declare which datasets it uses. # # Dataset is designed to promote 'design by composition', rather than @@ -54,16 +54,16 @@ def helper_methods # :nodoc: # C uses B # A uses C # B, C, A is the load order - # + # def uses(*datasets) @used_datasets = datasets end - + def used_datasets # :nodoc: @used_datasets end end - + # Invoked once before a collection of tests is run. If you use a dataset # in multiple test classes, it will be called once for each of them - # remember that the database will be cleared at the beginning of running a @@ -74,7 +74,7 @@ def used_datasets # :nodoc: # def load; end end - + # The easiest way to create some data before a suite of tests is run is by # using a Dataset::Block. An example works wonders: # @@ -82,7 +82,7 @@ def load; end # dataset do # create_record :person, :billy, :name => 'Billy' # end - # + # # def test_name # assert_equal 'Billy', people(:billy).name # end @@ -98,17 +98,17 @@ def load; end # # describe Something do # dataset :a => Dataset :a is loaded (at the right time) - # + # # it 'should whatever' # end - # + # # describe More do # dataset :b => Dataset :b is loaded. :a data is still there - # + # # it 'should' # end # end - # + # # describe Another do => Database is restored to :a, without re-running :a logic # it 'should' # end @@ -136,7 +136,7 @@ def load; end # id = create_record :person, :second_admin, :name => 'Admin Three' # create_record :organization_administratorship, :organization_id => organization_id(:first_bank), :person_id => id # end - # + # # def test_admins # assert organizations(:first_bank).admins.include?(people(:second_admin)) # end @@ -147,11 +147,11 @@ def load; end # When you need to go beyond the block, create a Dataset::Base subclass! class Block < Base include Dataset::InstanceMethods - + def load # :nodoc: dataset_session_binding.install_block_variables(self) doload dataset_session_binding.copy_block_variables(self) end end -end \ No newline at end of file +end diff --git a/lib/dataset/collection.rb b/lib/dataset/collection.rb index f5d6a8d..8bf550f 100644 --- a/lib/dataset/collection.rb +++ b/lib/dataset/collection.rb @@ -5,15 +5,15 @@ class Collection < Array # :nodoc: def initialize(parent) concat parent end - + def <<(dataset) super uniq! self end - + def subset?(other) Set.new(self).subset?(Set.new(other)) end end -end \ No newline at end of file +end diff --git a/lib/dataset/load.rb b/lib/dataset/load.rb index 4b4dd70..44d9c72 100644 --- a/lib/dataset/load.rb +++ b/lib/dataset/load.rb @@ -1,13 +1,13 @@ module Dataset class Load # :nodoc: attr_reader :datasets, :dataset_binding, :helper_methods - + def initialize(datasets, parent_binding) @datasets = datasets @dataset_binding = SessionBinding.new(parent_binding) @helper_methods = Module.new end - + def execute(loaded_datasets, dataset_resolver) (datasets - loaded_datasets).each do |dataset| instance = dataset.new @@ -23,7 +23,7 @@ def execute(loaded_datasets, dataset_resolver) instance.load end end - + def used_datasets(dataset, dataset_resolver, collector = []) dataset.used_datasets.each do |used| ds = dataset_resolver.resolve(used) @@ -34,14 +34,14 @@ def used_datasets(dataset, dataset_resolver, collector = []) collector.uniq end end - + class Reload # :nodoc: attr_reader :dataset_binding, :load delegate :datasets, :helper_methods, :to => :load - + def initialize(load) @load = load @dataset_binding = SessionBinding.new(@load.dataset_binding) end end -end \ No newline at end of file +end diff --git a/lib/dataset/resolver.rb b/lib/dataset/resolver.rb index 4647dfd..8eb899e 100644 --- a/lib/dataset/resolver.rb +++ b/lib/dataset/resolver.rb @@ -3,17 +3,17 @@ module Dataset # class DatasetNotFound < StandardError end - + # A dataset may be referenced as a class or as a name. A Dataset::Resolver # will take an identifier, whether a class or a name, and return the class. # class Resolver cattr_accessor :default - + def identifiers @identifiers ||= {} end - + # Attempt to convert a name to a constant. With the identifier :people, it # will search for 'PeopleDataset', then 'People'. # @@ -29,7 +29,7 @@ def resolve(identifier) end identifiers[identifier] = constant end - + protected def resolve_identifier(identifier) # :nodoc: constant = resolve_class(identifier) @@ -38,7 +38,7 @@ def resolve_identifier(identifier) # :nodoc: end constant end - + def resolve_class(identifier) names = [identifier.to_s.camelize, identifier.to_s.camelize + suffix] constant = resolve_these(names.reverse) @@ -47,7 +47,7 @@ def resolve_class(identifier) end constant end - + def resolve_these(names) # :nodoc: names.each do |name| constant = name.constantize rescue nil @@ -55,12 +55,12 @@ def resolve_these(names) # :nodoc: end nil end - + def suffix # :nodoc: @suffix ||= 'Dataset' end end - + # Resolves a dataset by looking for a file in the provided directory path # that has a name matching the identifier. Of course, should the identifier # be a class already, it is simply returned. @@ -69,11 +69,11 @@ class DirectoryResolver < Resolver def initialize(*paths) @paths = paths end - + def <<(path) @paths << path end - + protected def resolve_identifier(identifier) # :nodoc: @paths.each do |path| @@ -95,16 +95,16 @@ def resolve_identifier(identifier) # :nodoc: end raise DatasetNotFound, "Could not find a dataset file in #{@paths.inspect} having the name '#{identifier}.rb' or '#{identifier}_#{file_suffix}.rb'." end - + def file_suffix # :nodoc: @file_suffix ||= suffix.downcase end end - + # The default resolver, used by the Dataset::Sessions that aren't given a # different instance. You can set this to something else in your # test/spec_helper. # Resolver.default = Resolver.new - -end \ No newline at end of file + +end diff --git a/lib/dataset/session.rb b/lib/dataset/session.rb index 82678a6..237cc3c 100644 --- a/lib/dataset/session.rb +++ b/lib/dataset/session.rb @@ -1,14 +1,14 @@ module Dataset class Session # :nodoc: attr_accessor :dataset_resolver - + def initialize(database, dataset_resolver = Resolver.default) @database = database @dataset_resolver = dataset_resolver @datasets = Hash.new @load_stack = [] end - + def add_dataset(test_class, dataset_identifier) dataset = dataset_resolver.resolve(dataset_identifier) if dataset.used_datasets @@ -16,13 +16,13 @@ def add_dataset(test_class, dataset_identifier) end datasets_for(test_class) << dataset end - + def datasets_for(test_class) if test_class.superclass @datasets[test_class] ||= Collection.new(datasets_for(test_class.superclass) || []) end end - + def load_datasets_for(test_class) datasets = datasets_for(test_class) if last_load = @load_stack.last @@ -48,4 +48,4 @@ def load_datasets_for(test_class) current_load end end -end \ No newline at end of file +end diff --git a/lib/dataset/session_binding.rb b/lib/dataset/session_binding.rb index 3126256..dd5bc09 100644 --- a/lib/dataset/session_binding.rb +++ b/lib/dataset/session_binding.rb @@ -9,7 +9,7 @@ def initialize(record_heirarchy, symbolic_name) super "There is no '#{record_heirarchy.base_class.name}' found for the symbolic name ':#{symbolic_name}'." end end - + # Whenever you use Dataset::RecordMethods, you will get finder methods in # your tests that help you load instances of the records you have created # (or named models). @@ -45,7 +45,7 @@ def create_finders(record_meta) # :nodoc: @finders_generated ||= [] heirarchy_finders_hash = record_meta.heirarchy.model_finder_names.join('').hash return if @finders_generated.include?(heirarchy_finders_hash) - + record_meta.heirarchy.model_finder_names.each do |finder_name| unless instance_methods.include?(finder_name) define_method finder_name do |*symbolic_names| @@ -57,7 +57,7 @@ def create_finders(record_meta) # :nodoc: end end end - + record_meta.heirarchy.id_finder_names.each do |finder_name| unless instance_methods.include?(finder_name) define_method finder_name do |*symbolic_names| @@ -69,18 +69,18 @@ def create_finders(record_meta) # :nodoc: end end end - + @finders_generated << heirarchy_finders_hash end end - + # Any Dataset::Base subclass, dataset block, or test method in a # dataset-using test context (including setup/teardown/before/after) may # create and access models through these methods. Note that you should use # Dataset::ModelFinders if you can for finding your created data. # module RecordMethods - + # Similar to old fashioned fixtures, this will do a direct database # insert, without running any validations or preventing you from writing # attr_protected attributes. Very nice for speed, but kind of a pain if @@ -98,7 +98,7 @@ module RecordMethods def create_record(*args) dataset_session_binding.create_record(*args) end - + # This will instantiate your model class and assign each attribute WITHOUT # using mass assignment. Validations will be run. Very nice for complex # structures or hard to keep right validations, but potentially a bit @@ -116,7 +116,7 @@ def create_record(*args) def create_model(*args) dataset_session_binding.create_model(*args) end - + # Dataset will track each of the records it creates by symbolic name to # id. When you need the id of a record, there is no need to go to the # database. @@ -128,7 +128,7 @@ def create_model(*args) def find_id(*args) dataset_session_binding.find_id(*args) end - + # Dataset will track each of the records it creates by symbolic name to # id. When you need an instance of a record, the stored id will be used to # do the fastest lookup possible: Person.find(23425234). @@ -141,7 +141,7 @@ def find_id(*args) def find_model(*args) dataset_session_binding.find_model(*args) end - + # This is a great help when you want to create records in a custom helper # method, then make it and maybe things associated to it available to # tests through the Dataset::ModelFinders. @@ -158,53 +158,53 @@ def find_model(*args) def name_model(*args) dataset_session_binding.name_model(*args) end - + # Converts string names into symbols for use in naming models - # + # # name_to_sym 'my name' => :my_name # name_to_sym 'RPaul' => :r_paul - # + # def name_to_sym(name) dataset_session_binding.name_to_sym(name) end end - + class SessionBinding # :nodoc: attr_reader :database, :parent_binding attr_reader :model_finders, :record_methods attr_reader :block_variables - + def initialize(database_or_parent_binding) @id_cache = Hash.new {|h,k| h[k] = {}} @record_methods = new_record_methods_module @model_finders = new_model_finders_module @block_variables = Hash.new - + case database_or_parent_binding when Dataset::SessionBinding @parent_binding = database_or_parent_binding @database = parent_binding.database @model_finders.module_eval { include database_or_parent_binding.model_finders } @block_variables.update(database_or_parent_binding.block_variables) - else + else @database = database_or_parent_binding end end - + def copy_block_variables(dataset_block) dataset_block.instance_variables.each do |name| self.block_variables[name] = dataset_block.instance_variable_get(name) end end - + def create_model(record_type, *args) insert(Dataset::Record::Model, record_type, *args) end - + def create_record(record_type, *args) insert(Dataset::Record::Fixture, record_type, *args) end - + def find_id(record_type_or_meta, symbolic_name) record_meta = record_meta_for_type(record_type_or_meta) heirarchy = record_meta.heirarchy @@ -216,7 +216,7 @@ def find_id(record_type_or_meta, symbolic_name) raise RecordNotFound.new(heirarchy, symbolic_name) end end - + def find_model(record_type_or_meta, symbolic_name) record_meta = record_meta_for_type(record_type_or_meta) heirarchy = record_meta.heirarchy @@ -228,38 +228,38 @@ def find_model(record_type_or_meta, symbolic_name) raise RecordNotFound.new(heirarchy, symbolic_name) end end - + def install_block_variables(target) block_variables.each do |k,v| target.instance_variable_set(k,v) end end - + def name_model(record, symbolic_name) record_meta = database.record_meta(record.class) @model_finders.create_finders(record_meta) @id_cache[record_meta.heirarchy.id_cache_key][symbolic_name] = record.id record end - + def record_meta_for_type(record_type) record_type.is_a?(Record::Meta) ? record_type : begin record_class = resolve_record_class(record_type) database.record_meta(record_class) end end - + def name_to_sym(name) name.to_s.underscore.gsub("'", "").gsub("\"", "").gsub(" ", "_").to_sym if name end - + protected def insert(dataset_record_class, record_type, *args) symbolic_name, attributes = extract_creation_arguments args record_meta = record_meta_for_type(record_type) record = dataset_record_class.new(record_meta, attributes, symbolic_name, self) return_value = nil - + @model_finders.create_finders(record_meta) ActiveRecord::Base.silence do return_value = record.create @@ -267,7 +267,7 @@ def insert(dataset_record_class, record_type, *args) end return_value end - + def extract_creation_arguments(arguments) if arguments.size == 2 && arguments.last.kind_of?(Hash) arguments @@ -279,7 +279,7 @@ def extract_creation_arguments(arguments) [nil, Hash.new] end end - + def new_model_finders_module mod = Module.new dataset_binding = self @@ -291,7 +291,7 @@ def new_model_finders_module mod.extend ModelFinders mod end - + def new_record_methods_module mod = Module.new do include RecordMethods @@ -304,7 +304,7 @@ def new_record_methods_module end mod end - + def resolve_record_class(record_type) case record_type when Symbol @@ -316,4 +316,4 @@ def resolve_record_class(record_type) end end end -end \ No newline at end of file +end diff --git a/lib/dataset/version.rb b/lib/dataset/version.rb index 2476280..7d186d4 100644 --- a/lib/dataset/version.rb +++ b/lib/dataset/version.rb @@ -3,7 +3,7 @@ module VERSION #:nodoc: MAJOR = 1 MINOR = 0 TINY = 0 - + STRING = [MAJOR, MINOR, TINY].join('.') end end From 4d6c035354851f2570c14fbb20872e0488111c4d Mon Sep 17 00:00:00 2001 From: Mark Turner Date: Fri, 8 Apr 2011 14:52:05 -0700 Subject: [PATCH 7/7] Rails 3 appears to work --- lib/dataset/record/heirarchy.rb | 1 + 1 file changed, 1 insertion(+) 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