josevalim-nested_scenarios 0.2 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. data/README +1 -1
  2. data/lib/nested_scenarios/fixtures.rb +16 -5
  3. metadata +2 -2
data/README CHANGED
@@ -1,6 +1,6 @@
1
1
  NestedScenarios
2
2
  License: MIT
3
- Version: 0.2
3
+ Version: 0.2.1
4
4
 
5
5
  Description
6
6
  -----------
@@ -1,4 +1,14 @@
1
1
  class Fixtures < (RUBY_VERSION < '1.9' ? YAML::Omap : Hash)
2
+ cattr_accessor :current_fixture_path
3
+ @@all_cached_fixtures = {}
4
+
5
+ # Overwrite cache for connection to take into account the current fixture path.
6
+ def self.cache_for_connection(connection)
7
+ @@all_cached_fixtures[connection.object_id] ||= {}
8
+ @@all_cached_fixtures[connection.object_id][@@current_fixture_path] ||= {}
9
+ @@all_cached_fixtures[connection.object_id][@@current_fixture_path]
10
+ end
11
+
2
12
  def self.destroy_fixtures(table_names)
3
13
  NestedScenarios.delete_tables(table_names)
4
14
  end
@@ -40,10 +50,10 @@ module ActiveRecord #:nodoc:
40
50
  def scenario(scenario_name = nil, options = {})
41
51
  case scenario_name
42
52
  when Hash
43
- self.load_root_fixtures = scenario_name.delete(:root) unless scenario_name[:root].nil?
53
+ self.load_root_fixtures = scenario_name.delete(:root) if scenario_name.key? :root
44
54
  scenario_name = scenario_name.join('/')
45
55
  when Symbol, String
46
- self.load_root_fixtures = options.delete(:root) unless options[:root].nil?
56
+ self.load_root_fixtures = options.delete(:root) if options.key? :root
47
57
  scenario_name = scenario_name.to_s
48
58
  else
49
59
  raise ArgumentError, "Scenario must be a symbol, string or hash. You gave #{scenario_name.class}."
@@ -83,10 +93,12 @@ module ActiveRecord #:nodoc:
83
93
  @loaded_fixtures = {}
84
94
 
85
95
  if self.load_root_fixtures
96
+ Fixtures.current_fixture_path = self.fixture_path
86
97
  root_fixtures = Fixtures.create_fixtures(self.fixture_path, self.root_table_names, fixture_class_names)
87
98
  end
88
99
 
89
100
  if self.scenario_path
101
+ Fixtures.current_fixture_path = self.scenario_path
90
102
  scenario_fixtures = Fixtures.create_fixtures(self.scenario_path, self.scenario_table_names, fixture_class_names)
91
103
  end
92
104
 
@@ -106,16 +118,15 @@ module ActiveRecord #:nodoc:
106
118
 
107
119
  Fixtures.destroy_fixtures(self.fixture_table_names)
108
120
 
109
- unless use_transactional_fixtures?
121
+ unless run_in_transaction?
110
122
  Fixtures.reset_cache
111
123
  end
112
124
 
113
125
  # Rollback changes if a transaction is active.
114
- if use_transactional_fixtures? && ActiveRecord::Base.connection.open_transactions != 0
126
+ if run_in_transaction? && ActiveRecord::Base.connection.open_transactions != 0
115
127
  ActiveRecord::Base.connection.rollback_db_transaction
116
128
  ActiveRecord::Base.connection.decrement_open_transactions
117
129
  end
118
-
119
130
  ActiveRecord::Base.clear_active_connections!
120
131
  end
121
132
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: josevalim-nested_scenarios
3
3
  version: !ruby/object:Gem::Version
4
- version: "0.2"
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - "Jos\xC3\xA9 Valim"
@@ -11,7 +11,7 @@ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
13
 
14
- date: 2008-11-29 00:00:00 -08:00
14
+ date: 2009-02-22 00:00:00 -08:00
15
15
  default_executable:
16
16
  dependencies: []
17
17