jeremyevans-fixture_dependencies 1.1.2 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -12,9 +12,9 @@ the following features:
12
12
  constraints aren't violated
13
13
  - Has a very simple API (FixtureDependencies.load(:model__fixture))
14
14
  - Handles almost all cyclic dependencies
15
- - Includes Rails and Sequel test helpers for Test::Unit that load fixtures for
16
- every test inside a transaction, so fixture data is never left in your
17
- database
15
+ - Includes Rails and Sequel test helpers for Test::Unit (and a Sequel test
16
+ helper for RSpec) that load fixtures for every test inside a transaction,
17
+ so fixture data is never left in your database
18
18
 
19
19
  == Installation
20
20
 
@@ -54,11 +54,18 @@ Make sure the test case classes use FixtureDependencies::SequelTestCase:
54
54
 
55
55
  This runs the test cases inside a Sequel transaction.
56
56
 
57
+ === With Sequel/RSpec:
58
+
59
+ Somewhere before the test code is loaded:
60
+
61
+ require 'fixture_dependencies/rspec/sequel'
62
+
63
+ This runs each spec inside a separate Sequel transaction.
64
+
57
65
  === With other testing libraries:
58
66
 
59
67
  You can just use FixtureDependencies.load to handle the loading of fixtures.
60
- The use of transactions is up to you. It's fairly easy to add support for
61
- running RSpec examples inside transactions. One thing you must do if you are
68
+ The use of transactions is up to you. One thing you must do if you are
62
69
  not using the rails test helper is to set the fixture path for
63
70
  FixtureDependencies:
64
71
 
@@ -128,6 +135,12 @@ the loosest coupling possible. Here's an example:
128
135
  # Test the employee
129
136
  end
130
137
 
138
+ def test_employees
139
+ # Load the fixtures and return two Employee objects
140
+ employee1, employee2 = load(:employees=>[:jeremy, :karl])
141
+ # Test the employees
142
+ end
143
+
131
144
  def test_award_statistics
132
145
  # Load all fixtures in both tables
133
146
  load(:employee_award__jeremy_first, :award__first)
@@ -206,8 +219,7 @@ The plugin is significantly slower than the default testing method, because it
206
219
  loads all fixtures inside of a transaction (one per test method), where Rails
207
220
  defaults to loading the fixtures once per test suite (outside of a
208
221
  transaction), and only deletes fixtures from a table when overwriting it with
209
- new fixtures. Rails actually did something similar starting with r2714, but it
210
- was rolled back in r2730 due to speed issues. See ticket #2404 on Rails' trac.
222
+ new fixtures.
211
223
 
212
224
  Instantiated fixtures are not available with this plugin. Instead, you should
213
225
  use load(:model__fixture_name).
@@ -10,11 +10,32 @@ class FixtureDependencies
10
10
  # to that model. If multiple arguments are given, return a list of
11
11
  # model instances (for single fixture arguments) or list of model instances
12
12
  # (for model fixture arguments). If no arguments, return the empty list.
13
+ # If any of the arguments is a hash, assume the key specifies the model
14
+ # and the values specify the fixture, and treat it as though individual
15
+ # symbols specifying both model and fixture were given.
16
+ #
17
+ # Examples:
18
+ # * load(:posts) # All post fixtures, not recommended
19
+ # * load(:posts, :comments) # All post and comment fixtures, again not recommended
20
+ # * load(:post__post1) # Just the post fixture named post1
21
+ # * load(:post__post1, :post__post2) # Post fixtures named post1 and post2
22
+ # * load(:posts=>[:post1, :post2]) # Post fixtures named post1 and post2
23
+ # * load(:post__post1, :comment__comment2) # Post fixture named post1 and comment fixture named comment2
24
+ # * load({:posts=>[:post1, :post2]}, :comment__comment2) # Post fixtures named post1 and post2 and comment fixture named comment2
13
25
  #
14
26
  # This will load the data from the yaml files for each argument whose model
15
27
  # is not already in the fixture hash.
16
28
  def self.load(*records)
17
- ret = records.collect do |record|
29
+ ret = records.map do |record|
30
+ if record.is_a?(Hash)
31
+ record.map do |k, vals|
32
+ model = k.to_s.singularize
33
+ vals.map{|v| :"#{model}__#{v}"}
34
+ end
35
+ else
36
+ record
37
+ end
38
+ end.flatten.compact.map do |record|
18
39
  model_name, name = split_name(record)
19
40
  if name
20
41
  use(record.to_sym)
@@ -24,10 +45,10 @@ class FixtureDependencies
24
45
  puts "loading #{model_name}.yml" if verbose > 0
25
46
  load_yaml(model_name)
26
47
  end
27
- fixtures[model_name.to_sym].keys.collect{|name| use("#{model_name}__#{name}".to_sym)}
48
+ fixtures[model_name.to_sym].keys.map{|name| use(:"#{model_name}__#{name}")}
28
49
  end
29
50
  end
30
- records.length == 1 ? ret[0] : ret
51
+ ret.length == 1 ? ret[0] : ret
31
52
  end
32
53
  end
33
54
 
@@ -0,0 +1,9 @@
1
+ class Spec::Example::ExampleGroup
2
+ def execute(*args, &block)
3
+ Sequel::Model.db.transaction{super(*args, &block); raise Sequel::Error::Rollback}
4
+ end
5
+
6
+ def load(*args)
7
+ FixtureDependencies.load(*args)
8
+ end
9
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jeremyevans-fixture_dependencies
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Evans
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-10-27 00:00:00 -07:00
12
+ date: 2009-02-05 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -31,6 +31,7 @@ files:
31
31
  - lib/fixture_dependencies/test_unit.rb
32
32
  - lib/fixture_dependencies/test_unit/rails.rb
33
33
  - lib/fixture_dependencies/test_unit/sequel.rb
34
+ - lib/fixture_dependencies/rspec/sequel.rb
34
35
  has_rdoc: true
35
36
  homepage:
36
37
  post_install_message: