fixture_dependencies 1.3.3 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README +13 -0
  3. data/lib/fixture_dependencies.rb +13 -4
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0f4cee7af840c8a156ac870017fb795b25de4afb
4
- data.tar.gz: 1d055871b5ebb184888890ba40e1eb13fa285b6d
3
+ metadata.gz: 9e1db26a9939a45edd1a1d37d76b3558cf51df5c
4
+ data.tar.gz: 274b53935e81281fef934ee40fac21a992b87fef
5
5
  SHA512:
6
- metadata.gz: b1efe861b5f15165f2b2ec45da32ec4446c6a605a6062688b7ae63e8566d8040d39d8e343f16a13f10ea62277802ebc58c912e947c972db923c357368fe78ee8
7
- data.tar.gz: 3d4af868883a4cf63133b2505b0d4062979f4d443810f4994316f9b958e73c8c12502ea244ce6186765c63228ec5e9ae80e7562366261e81c471ebc25d2cc725
6
+ metadata.gz: 2ef34241a9926ad6412d410fffd065b9111f5c4f35373db225002bdc290048a38e33936340a51e3ac1b2c232e52a1cc95f04d0325b380948ca794107c0efc157
7
+ data.tar.gz: a9bd54222d249d51c34804fe0de3933397eed4df736c33bc6daab0d27b872fe47dfb1d36fffea1cf791711de4b894d23a53f0132d193ba5208898d3894140670
data/README CHANGED
@@ -235,6 +235,19 @@ new fixtures.
235
235
  Instantiated fixtures are not available with this plugin. Instead, you should
236
236
  use load(:model__fixture_name).
237
237
 
238
+ == Namespace Issues
239
+
240
+ By default, fixture dependencies is going to load the model with the camelized
241
+ name in the symbol used. So for :foo_bar__baz, it's going to look for
242
+ the fixture with name baz for the model FooBar. If your model is namespaced,
243
+ such as Foo::Bar, this isn't going to work well. In that case, you can
244
+ override the default mapping:
245
+
246
+ FixtureDependencies.class_map[:bar] = Foo::Bar
247
+
248
+ and then use :bar__baz to load the fixture with name baz for the model
249
+ Foo::Bar.
250
+
238
251
  == Troubleshooting
239
252
 
240
253
  If you run into problems with loading your fixtures, it can be difficult to see
@@ -5,6 +5,7 @@ require 'yaml'
5
5
  class FixtureDependencies
6
6
  @fixtures = {}
7
7
  @loaded = {}
8
+ @class_map = {}
8
9
  @verbose = 0
9
10
 
10
11
  # Load all record arguments into the database. If a single argument is
@@ -62,7 +63,7 @@ require 'fixture_dependencies/sequel' if defined?(Sequel::Model)
62
63
 
63
64
  class << FixtureDependencies
64
65
  attr_reader :fixtures, :loaded
65
- attr_accessor :verbose, :fixture_path
66
+ attr_accessor :verbose, :fixture_path, :class_map
66
67
 
67
68
  private
68
69
 
@@ -76,7 +77,7 @@ class << FixtureDependencies
76
77
  # the fixture name.
77
78
  def get(record)
78
79
  model_name, name = split_name(record)
79
- model = model_name.camelize.constantize
80
+ model = model_class(model_name)
80
81
  model_method(:model_find, model_type(model), model, fixtures[model_name.to_sym][name.to_sym][fixture_pk(model)])
81
82
  end
82
83
 
@@ -85,7 +86,7 @@ class << FixtureDependencies
85
86
  def load_yaml(model_name)
86
87
  raise(ArgumentError, "No fixture_path set. Use FixtureDependencies.fixture_path = ...") unless fixture_path
87
88
 
88
- filename = model_name.camelize.constantize.table_name
89
+ filename = model_class(model_name).table_name
89
90
  yaml_path = File.join(fixture_path, "#{filename}.yml")
90
91
 
91
92
  if File.exist?(yaml_path)
@@ -121,6 +122,14 @@ class << FixtureDependencies
121
122
  end
122
123
  end
123
124
 
125
+ # Return the class associated with the given model_name. By default, the
126
+ # class name is automagically derived from the model name, however this
127
+ # can be overridden by <tt>FixtureDependencies.class_map[:name] =
128
+ # Some::Class</tt>.
129
+ def model_class(model_name)
130
+ class_map[model_name.to_sym] || model_name.camelize.constantize
131
+ end
132
+
124
133
  # Split the fixture name into the name of the model and the name of
125
134
  # the individual fixture.
126
135
  def split_name(name)
@@ -139,7 +148,7 @@ class << FixtureDependencies
139
148
  puts "#{spaces}load stack:#{loading.inspect}" if verbose > 1
140
149
  loading.push(record)
141
150
  model_name, name = split_name(record)
142
- model = model_name.camelize.constantize
151
+ model = model_class(model_name)
143
152
  unless loaded[model_name.to_sym]
144
153
  puts "#{spaces}loading #{model.table_name}.yml" if verbose > 0
145
154
  load_yaml(model_name)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fixture_dependencies
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.3
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Evans
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-27 00:00:00.000000000 Z
11
+ date: 2014-09-03 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: code@jeremyevans.net