<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>TODO</filename>
    </added>
    <added>
      <filename>lib/scenarios/extensions/object.rb</filename>
    </added>
    <added>
      <filename>testing/rspec_on_rails_3014.patch</filename>
    </added>
    <added>
      <filename>testing/rspec_on_rails_3119.patch</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -3,7 +3,7 @@ gem 'rake'; require 'rake'
 require 'rake/rdoctask'
 require File.expand_path(&quot;#{File.dirname(__FILE__)}/testing/environment&quot;)
 
-TESTING_ENVIRONMENTS[&quot;rspec_trunk_rails_trunk&quot;].load
+TESTING_ENVIRONMENTS[&quot;rspec_3119_rails_8375&quot;].load
 require 'rake/testtask'
 require &quot;spec/rake/spectask&quot;
 </diff>
      <filename>Rakefile</filename>
    </modified>
    <modified>
      <diff>@@ -39,12 +39,15 @@ module Scenarios
     include TableMethods
     include Loading
     
+    attr_reader :table_config
+    
     # Initialize a scenario with a Configuration. Used internally by the
     # Scenarios plugin.
     def initialize(config = Configuration.new)
-      self.table_config = config
+      @table_config = config
+      table_config.update_scenario_helpers self.class
       self.extend table_config.table_readers
-      self.extend self.class.helpers
+      self.extend table_config.scenario_helpers
     end
     
     # This method should be implemented in your scenarios. You may also have</diff>
      <filename>lib/scenarios/base.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,12 +1,55 @@
 module Scenarios
   class Configuration # :nodoc:
-    attr_reader :blasted_tables, :record_metas, :table_readers, :symbolic_names_to_id
+    attr_reader :blasted_tables, :loaded_scenarios, :record_metas, :table_readers, :scenario_helpers, :symbolic_names_to_id
     
     def initialize
       @blasted_tables       = Set.new
       @record_metas         = Hash.new
       @table_readers        = Module.new
+      @scenario_helpers     = Module.new
       @symbolic_names_to_id = Hash.new {|h,k| h[k] = Hash.new}
+      @loaded_scenarios     = Array.new
+    end
+    
+    # Given a created record (currently ScenarioModel or ScenarioRecord),
+    # update the table readers module appropriately such that this record and
+    # it's id are findable via methods like 'people(symbolic_name)' and
+    # 'person_id(symbolic_name)'.
+    def update_table_readers(record)
+      ids, record_meta = symbolic_names_to_id, record.record_meta # scoping assignments
+      
+      ids[record_meta.table_name][record.symbolic_name] = record.id
+      table_readers.send :define_method, record_meta.id_reader do |*symbolic_names|
+        record_ids = symbolic_names.flatten.collect do |symbolic_name|
+          if symbolic_name.kind_of?(ActiveRecord::Base)
+            symbolic_name.id
+          else
+            record_id = ids[record_meta.table_name][symbolic_name.to_sym]
+            raise ActiveRecord::RecordNotFound, &quot;No object is associated with #{record_meta.table_name}(:#{symbolic_name})&quot; unless record_id
+            record_id
+          end
+        end
+        record_ids.size &gt; 1 ? record_ids : record_ids.first
+      end
+      
+      table_readers.send :define_method, record_meta.record_reader do |*symbolic_names|
+        results = symbolic_names.flatten.collect do |symbolic_name|
+          symbolic_name.kind_of?(ActiveRecord::Base) ?
+            symbolic_name :
+            record_meta.record_class.find(send(record_meta.id_reader, symbolic_name))
+        end
+        results.size &gt; 1 ? results : results.first
+      end
+    end
+    
+    def update_scenario_helpers(scenario_class)
+      scenario_helpers.module_eval do
+        include scenario_class.helpers
+      end
+    end
+    
+    def scenarios_loaded?
+      !loaded_scenarios.blank?
     end
   end
 end
\ No newline at end of file</diff>
      <filename>lib/scenarios/configuration.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,3 +1,4 @@
+require File.dirname(__FILE__) + &quot;/extensions/object&quot;
 require File.dirname(__FILE__) + &quot;/extensions/string&quot;
 require File.dirname(__FILE__) + &quot;/extensions/symbol&quot;
 require File.dirname(__FILE__) + &quot;/extensions/active_record&quot;</diff>
      <filename>lib/scenarios/extensions.rb</filename>
    </modified>
    <modified>
      <diff>@@ -6,7 +6,7 @@ module ActiveRecord
     # In order to guarantee that tables are tracked when _create_model_ is
     # used, and those models cause other models to be created...
     def create_with_table_blasting
-      blast_table(self.class.table_name) unless blasted_tables.include?(self.class.table_name)
+      prepare_table(self.class.table_name)
       create_without_table_blasting
     end
     alias_method_chain :create, :table_blasting</diff>
      <filename>lib/scenarios/extensions/active_record.rb</filename>
    </modified>
    <modified>
      <diff>@@ -2,6 +2,7 @@ module Test #:nodoc:
   module Unit #:nodoc:
     class TestCase #:nodoc:
       superclass_delegating_accessor :scenario_classes
+      superclass_delegating_accessor :table_config
       
       # Changing either of these is not supported at this time.
       self.use_transactional_fixtures = true
@@ -36,7 +37,7 @@ module Test #:nodoc:
             attr_accessor :test_class
             def run_with_scenarios(*args, &amp;block)
               run_without_scenarios(*args, &amp;block)
-              test_class.loaded_scenarios.each { |s| s.unload } if test_class.loaded_scenarios &amp;&amp; test_class.use_transactional_fixtures
+              test_class.table_config.loaded_scenarios.each { |s| s.unload } if test_class.use_transactional_fixtures
             end
             alias_method_chain :run, :scenarios
           end
@@ -50,7 +51,10 @@ module Test #:nodoc:
       # is expected to be called in a fashion respective of
       # use_transactional_fixtures. I feel like a leech.
       def load_fixtures
-        load_scenarios(scenario_classes)
+        self.class.table_config ||= Scenarios::Configuration.new
+        load_scenarios(scenario_classes) if !scenarios_loaded? || !use_transactional_fixtures?
+        self.extend scenario_helpers
+        self.extend table_readers
       end
       
       # Here we are counting on existing logic to allow teardown method
@@ -60,6 +64,7 @@ module Test #:nodoc:
       # tests, right!). See the TestSuite extension done in _suite_ for
       # behaviour when using transaction fixtures.
       def teardown_with_scenarios
+        teardown_without_scenarios
         loaded_scenarios.each { |s| s.unload } unless use_transactional_fixtures?
       end
       alias_method_chain :teardown, :scenarios</diff>
      <filename>lib/scenarios/extensions/test_case.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,33 +1,52 @@
 module Scenarios
+  # Provides scenario loading and convenience methods around the Configuration
+  # that must be made available through a method _table_config_.
   module Loading # :nodoc:
+    def load_scenarios(scenario_classes)
+      # debugger
+      install_active_record_tracking_hook
+      scenario_classes.each do |scenario_class|
+        scenario = scenario_class.new(table_config)
+        scenario.load
+        table_config.loaded_scenarios &lt;&lt; scenario
+      end if scenario_classes
+    end
     
-    def self.included(base)
-      base.module_eval do
-        superclass_delegating_accessor :loaded_scenarios
-      end
+    def loaded_scenarios
+      table_config.loaded_scenarios
     end
     
-    def load_scenarios(scenario_classes)
-      self.table_config = Configuration.new
-      ActiveRecord::Base.table_config = self.table_config
-      self.class.loaded_scenarios = []
-      previous_scenario = nil
-      if scenario_classes
-        scenario_classes.each do |scenario_class|
-          scenario = scenario_class.new(table_config)
-          if previous_scenario
-            scenario_class.helpers.extend previous_scenario.class.helpers
-            scenario_class.send :include, previous_scenario.class.helpers
-            scenario.table_readers.extend previous_scenario.table_readers
-          end
-          scenario.load
-          self.class.send :include, scenario_class.helpers
-          self.class.send :include, scenario.table_readers
-          previous_scenario = scenario
-          loaded_scenarios &lt;&lt; scenario
-        end
-      end
+    def scenarios_loaded?
+      table_config &amp;&amp; table_config.scenarios_loaded?
     end
     
+    # The sum of all the loaded scenario's helper methods. These can be mixed
+    # into anything you like to gain access to them.
+    def scenario_helpers
+      table_config.scenario_helpers
+    end
+    
+    # The sum of all the available table reading methods. These will only
+    # include readers for which data has been placed into the table. These can
+    # be mixed into anything you like to gain access to them.
+    def table_readers
+      table_config.table_readers
+    end
+    
+    # # This understand nesting descriptions one deep
+    # def table_config
+    #   on_my_class = self.class.instance_variable_get(&quot;@table_config&quot;)
+    #   return on_my_class if on_my_class
+    #   
+    #   if self.class.superclass
+    #     on_super_class = self.class.superclass.instance_variable_get(&quot;@table_config&quot;)
+    #     return on_super_class if on_super_class
+    #   end
+    # end
+    
+    private
+      def install_active_record_tracking_hook
+        ActiveRecord::Base.table_config = table_config
+      end
   end
 end
\ No newline at end of file</diff>
      <filename>lib/scenarios/loading.rb</filename>
    </modified>
    <modified>
      <diff>@@ -12,5 +12,9 @@ module Scenarios
       end
       blasted_tables &lt;&lt; name
     end
+    
+    def prepare_table(name)
+      blast_table(name) unless blasted_tables.include?(name)
+    end
   end
 end
\ No newline at end of file</diff>
      <filename>lib/scenarios/table_blasting.rb</filename>
    </modified>
    <modified>
      <diff>@@ -5,8 +5,7 @@ module Scenarios
   module TableMethods
     include TableBlasting
     
-    attr_accessor :table_config unless respond_to?(:table_config)
-    delegate :table_readers, :record_metas, :symbolic_names_to_id, :to =&gt; :table_config
+    delegate :record_metas, :to =&gt; :table_config
     
     # Insert a record into the database, add the appropriate helper methods
     # into the scenario and spec, and return the ID of the inserted record:
@@ -72,10 +71,10 @@ module Scenarios
         record       = record_or_model.new(record_meta, attributes, symbolic_name)
         return_value = nil
         ActiveRecord::Base.silence do
-          blast_table(record_meta.table_name) unless blasted_tables.include?(record_meta.table_name)
+          prepare_table(record_meta.table_name)
           return_value = insertion.call record
-          symbolic_names_to_id[record_meta.table_name][record.symbolic_name] = record.id
-          update_table_readers(symbolic_names_to_id, record_meta)
+          table_config.update_table_readers(record)
+          self.extend table_config.table_readers
         end
         return_value
       end
@@ -90,35 +89,6 @@ module Scenarios
         end
       end
       
-      def update_table_readers(ids, record_meta)
-        table_readers.send :define_method, record_meta.id_reader do |*symbolic_names|
-          record_ids = symbolic_names.flatten.collect do |symbolic_name|
-            if symbolic_name.kind_of?(ActiveRecord::Base)
-              symbolic_name.id
-            else
-              record_id = ids[record_meta.table_name][symbolic_name.to_sym]
-              raise ActiveRecord::RecordNotFound, &quot;No object is associated with #{record_meta.table_name}(:#{symbolic_name})&quot; unless record_id
-              record_id
-            end
-          end
-          record_ids.size &gt; 1 ? record_ids : record_ids.first
-        end
-        
-        table_readers.send :define_method, record_meta.record_reader do |*symbolic_names|
-          results = symbolic_names.flatten.collect do |symbolic_name|
-            symbolic_name.kind_of?(ActiveRecord::Base) ?
-              symbolic_name :
-              record_meta.record_class.find(send(record_meta.id_reader, symbolic_name))
-          end
-          results.size &gt; 1 ? results : results.first
-        end
-        metaclass.send :include, table_readers
-      end
-      
-      def metaclass
-        (class &lt;&lt; self; self; end)
-      end
-      
       class RecordMeta # :nodoc:
         attr_reader :class_name, :record_class, :table_name
         </diff>
      <filename>lib/scenarios/table_methods.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,37 +1,6 @@
 require File.expand_path(File.dirname(__FILE__) + &quot;/spec_helper&quot;)
 
-describe &quot;test/unit support&quot; do
-  before do
-    @test_result = Test::Unit::TestResult.new
-    @test_case = Class.new(Test::Unit::TestCase)
-    @test_case.module_eval do
-      scenario :things
-      def test_something; end
-    end
-  end
-  
-  it &quot;should extend TestSuite to allow for scenario unloading after suite has run&quot; do
-    suite = @test_case.suite
-    suite.should respond_to(&quot;run_with_scenarios&quot;)
-    lambda { suite.run(@test_result) {} }.should_not raise_error
-  end
-  
-  it &quot;should give the test all the helper methods&quot; do
-    @test_case.instance_methods.should include(&quot;create_record&quot;)
-  end
-  
-  it &quot;should work even when RSpec is installed&quot; do pending(&quot;A ton of refactoring is going on - they've modified TestCase a lot&quot;)
-    test = @test_case.new(&quot;test_something&quot;)
-    lambda { test.run(@test_result) {} }.should_not raise_error
-    test.things(:one).should_not be_nil
-  end
-  
-  it &quot;should load scenarios on setup and install helpers&quot; do
-    test = @test_case.new(Spec::Example::Example.new(&quot;ugh, they've changed the signature!&quot;) {})
-    lambda { test.setup; test.run }.should_not raise_error
-    test.things(:one).should_not be_nil
-  end
-end
+start_debugger
 
 describe &quot;Scenario loading&quot; do
   it &quot;should load from configured directories&quot; do
@@ -52,6 +21,18 @@ describe &quot;Scenario loading&quot; do
     end
     klass.new.methods.should include('hello')
   end
+  
+  it &quot;should load the scenarios only once per test class/example group, then unload at the end&quot; do
+    tracking_scenario = Class.new(Scenario::Base)
+    tracking_scenario_instance = tracking_scenario.new
+    tracking_scenario.should_receive(:new).once.and_return(tracking_scenario_instance)
+    example_test = Class.new(Test::Unit::TestCase) do
+      scenario tracking_scenario
+      def test_one; end
+      def test_two; end
+    end
+    example_test.suite.run
+  end
 end
 
 describe Scenarios::TableMethods do</diff>
      <filename>spec/scenarios_spec.rb</filename>
    </modified>
    <modified>
      <diff>@@ -27,17 +27,18 @@ unless defined?(PLUGIN_ROOT)
   rspec_package = lambda do |pkg|
     pkg.add_library &quot;rspec&quot;
     pkg.add_library(&quot;rspec_on_rails&quot;, :after_update =&gt; lambda do |lib|
-      system &quot;cd #{lib.support_directory} &amp;&amp; patch -p0 &lt; #{File.join(PLUGIN_ROOT, &quot;rspec_on_rails_load.patch&quot;)}&quot;
+      system &quot;cd #{lib.support_directory} &amp;&amp; patch -p0 &lt; #{File.join(TESTING_ROOT, &quot;rspec_on_rails_3119.patch&quot;)}&quot;
     end)
   end
   
-  TESTING_ENVIRONMENTS &lt;&lt; TestingLibrary::Environment.new(&quot;rspec_trunk_rails_trunk&quot;, SUPPORT_TEMP, DB_CONFIG_FILE, DB_SCHEMA_FILE) do |env|
-    env.package &quot;rails&quot;, &quot;http://svn.rubyonrails.org/rails&quot;, &quot;trunk&quot;, &quot;8239&quot;, &amp;rails_package
-    env.package &quot;rspec&quot;, &quot;http://rspec.rubyforge.org/svn&quot;,   &quot;trunk&quot;, &quot;3014&quot;, &amp;rspec_package
+  # If you change this, you will need to change the Rakefile, as we are depending on the definition of Spectask from here
+  TESTING_ENVIRONMENTS &lt;&lt; TestingLibrary::Environment.new(&quot;rspec_3119_rails_8375&quot;, SUPPORT_TEMP, DB_CONFIG_FILE, DB_SCHEMA_FILE) do |env|
+    env.package &quot;rails&quot;, &quot;http://svn.rubyonrails.org/rails&quot;, &quot;trunk&quot;, &quot;8375&quot;, &amp;rails_package
+    env.package &quot;rspec&quot;, &quot;http://rspec.rubyforge.org/svn&quot;,   &quot;trunk&quot;, &quot;3119&quot;, &amp;rspec_package
   end
-  TESTING_ENVIRONMENTS &lt;&lt; TestingLibrary::Environment.new(&quot;rspec_trunk_rails_1_2_6&quot;, SUPPORT_TEMP, DB_CONFIG_FILE, DB_SCHEMA_FILE) do |env|
+  TESTING_ENVIRONMENTS &lt;&lt; TestingLibrary::Environment.new(&quot;rspec_3119_rails_1_2_6&quot;, SUPPORT_TEMP, DB_CONFIG_FILE, DB_SCHEMA_FILE) do |env|
     env.package &quot;rails&quot;, &quot;http://svn.rubyonrails.org/rails&quot;, &quot;tags/rel_1-2-6&quot;, &amp;rails_package
-    env.package &quot;rspec&quot;, &quot;http://rspec.rubyforge.org/svn&quot;, &quot;trunk&quot;, &quot;3014&quot;, &amp;rspec_package
+    env.package &quot;rspec&quot;, &quot;http://rspec.rubyforge.org/svn&quot;, &quot;trunk&quot;, &quot;3119&quot;, &amp;rspec_package
   end
   TESTING_ENVIRONMENTS &lt;&lt; TestingLibrary::Environment.new(&quot;testunit_rails_trunk&quot;, SUPPORT_TEMP, DB_CONFIG_FILE, DB_SCHEMA_FILE) do |env|
     env.package &quot;rails&quot;, &quot;http://svn.rubyonrails.org/rails&quot;, &quot;trunk&quot;, &amp;rails_package
@@ -49,4 +50,18 @@ unless defined?(PLUGIN_ROOT)
   require 'logger'
   RAILS_DEFAULT_LOGGER = Logger.new(&quot;#{SUPPORT_TEMP}/test.log&quot;)
   RAILS_DEFAULT_LOGGER.level = Logger::DEBUG
+end
+
+def start_debugger
+  begin
+    require 'rubygems'
+    require_library_or_gem 'ruby-debug'
+    Debugger.start
+    Debugger.settings[:autoeval] = true
+    Debugger.settings[:autolist] = true
+    puts &quot;=&gt; Debugger enabled&quot;
+  rescue Exception
+    puts &quot;You need to install ruby-debug to run the server in debugging mode. With gems, use 'gem install ruby-debug'&quot;
+    exit
+  end
 end
\ No newline at end of file</diff>
      <filename>testing/environment.rb</filename>
    </modified>
    <modified>
      <diff>@@ -113,7 +113,7 @@ module TestingLibrary
     end
     
     def update
-      system &quot;svn export -r#{scmrev} #{scmuri} #{support_directory}&quot;
+      system &quot;svn co -r#{scmrev} #{scmuri} #{support_directory}&quot;
     end
     
     # http://dev.rubyonrails.org/rails/trunk/activerecord</diff>
      <filename>testing/library.rb</filename>
    </modified>
  </modified>
  <removed type="array">
    <removed>
      <filename>rspec_on_rails_load.patch</filename>
    </removed>
  </removed>
  <parents type="array">
    <parent>
      <id>55541e29f34c705b2435d9bd64ec94b3c11c7661</id>
    </parent>
  </parents>
  <author>
    <name>Adam Williams</name>
    <email>adam@thewilliams.ws</email>
  </author>
  <url>http://github.com/aiwilliams/scenarios/commit/ee63ccc12c71f5a698ed0405261c3c7a74decea1</url>
  <id>ee63ccc12c71f5a698ed0405261c3c7a74decea1</id>
  <committed-date>2007-12-11T09:19:15-08:00</committed-date>
  <authored-date>2007-12-11T09:19:15-08:00</authored-date>
  <message>Turns out the scenarios were being loaded for each test. Blech! That's fixed.
Improvements in loading code overall. Working toward putting more on the thing called 'table_config' - would like to rename that.
Updated to support latest revs of Rails and RSpec. See testing/environment.rb.</message>
  <tree>e2d65a737f576223f6010ca566467f5efda91706</tree>
  <committer>
    <name>Adam Williams</name>
    <email>adam@thewilliams.ws</email>
  </committer>
</commit>
