factory_girl 1.1.4 → 1.1.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,10 @@
1
+ We're using GitHub[http://github.com/thoughtbot/factory_girl/tree/master] and Lighthouse[http://thoughtbot.lighthouseapp.com/projects/14354], and we've been getting any combination of github pull requests, Lighthouse tickets, patches, emails, etc. We need to normalize this workflow to make sure we don't miss any fixes.
2
+
3
+ * Make sure you're accessing the source from the {official repository}[http://github.com/thoughtbot/factory_girl/tree/master].
4
+ * We prefer git branches over patches, but we can take either.
5
+ * If you're using git, please make a branch for each separate contribution. We can cherry pick your commits, but pulling from a branch is easier.
6
+ * If you're submitting patches, please cut each fix or feature into a separate patch.
7
+ * There should be a Lighthouse[http://thoughtbot.lighthouseapp.com/projects/14354] ticket for any submission. If you've found a bug and want to fix it, open a new ticket at the same time.
8
+ * Please <b>don't send pull requests</b> Just update the lighthouse ticket with the url for your fix (or attach the patch) when it's ready. The github pull requests pretty much get dropped on the floor until someone with commit rights notices them in the mailbox.
9
+ * Contributions without tests won't be accepted.
10
+ * Please don't submit patches or branches that update the Gem version.
data/Changelog CHANGED
@@ -1,3 +1,13 @@
1
+ 1.1.4 (November 28, 2008)
2
+ Factory.build now uses Factory.create for associations of the built object
3
+ Factory definitions are now detected in subdirectories, such as
4
+ factories/person_factory.rb (thanks to Josh Nichols)
5
+ Factory definitions are now loaded after the environment in a Rails project
6
+ (fixes some issues with dependencies being loaded too early) (thanks to
7
+ Josh Nichols)
8
+ Factory names ending in 's' no longer cause problems (thanks to Alex Sharp
9
+ and Josh Owens)
10
+
1
11
  1.1.3 (September 12, 2008)
2
12
  Automatically pull in definitions from factories.rb, test/factories.rb, or
3
13
  spec/factories.rb
data/README.textile CHANGED
@@ -19,6 +19,10 @@ config.gem "thoughtbot-factory_girl",
19
19
  :lib => "factory_girl",
20
20
  :source => "http://gems.github.com"
21
21
 
22
+ h2. Contributing
23
+
24
+ Please read the contribution guidelines before submitting patches or pull requests.
25
+
22
26
  h2. Defining factories
23
27
 
24
28
  <pre><code># This will guess the User class
data/Rakefile CHANGED
@@ -39,7 +39,7 @@ end
39
39
 
40
40
  spec = Gem::Specification.new do |s|
41
41
  s.name = %q{factory_girl}
42
- s.version = "1.1.4"
42
+ s.version = "1.1.5"
43
43
  s.summary = %q{factory_girl provides a framework and DSL for defining and
44
44
  using model instance factories.}
45
45
  s.description = %q{factory_girl provides a framework and DSL for defining and
@@ -58,7 +58,6 @@ spec = Gem::Specification.new do |s|
58
58
  s.email = %q{jferris@thoughtbot.com}
59
59
 
60
60
  s.platform = Gem::Platform::RUBY
61
- s.add_dependency(%q<activesupport>, [">= 1.0"])
62
61
  end
63
62
 
64
63
  Rake::GemPackageTask.new spec do |pkg|
@@ -1,6 +1,8 @@
1
1
  class Factory
2
2
 
3
- cattr_accessor :aliases #:nodoc:
3
+ class << self
4
+ attr_accessor :aliases #:nodoc:
5
+ end
4
6
  self.aliases = [
5
7
  [/(.*)_id/, '\1'],
6
8
  [/(.*)/, '\1_id']
@@ -1,13 +1,16 @@
1
1
  class Factory
2
2
 
3
- cattr_accessor :factories #:nodoc:
4
- self.factories = {}
3
+ class << self
4
+ attr_accessor :factories #:nodoc:
5
+
6
+ # An Array of strings specifying locations that should be searched for
7
+ # factory definitions. By default, factory_girl will attempt to require
8
+ # "factories," "test/factories," and "spec/factories." Only the first
9
+ # existing file will be loaded.
10
+ attr_accessor :definition_file_paths
11
+ end
5
12
 
6
- # An Array of strings specifying locations that should be searched for
7
- # factory definitions. By default, factory_girl will attempt to require
8
- # "factories," "test/factories," and "spec/factories." Only the first
9
- # existing file will be loaded.
10
- cattr_accessor :definition_file_paths
13
+ self.factories = {}
11
14
  self.definition_file_paths = %w(factories test/factories spec/factories)
12
15
 
13
16
  attr_reader :factory_name
@@ -36,7 +39,7 @@ class Factory
36
39
  end
37
40
 
38
41
  def initialize (name, options = {}) #:nodoc:
39
- options.assert_valid_keys(:class)
42
+ assert_valid_options(options)
40
43
  @factory_name = factory_name_for(name)
41
44
  @options = options
42
45
  @attributes = []
@@ -111,7 +114,7 @@ class Factory
111
114
  # default use the "user" factory.
112
115
  def association (name, options = {})
113
116
  name = name.to_sym
114
- options = options.symbolize_keys
117
+ options = symbolize_keys(options)
115
118
  association_factory = options[:factory] || name
116
119
 
117
120
  add_attribute(name) {|a| a.association(association_factory) }
@@ -203,7 +206,7 @@ class Factory
203
206
  private
204
207
 
205
208
  def build_attributes_hash (values, strategy)
206
- values = values.symbolize_keys
209
+ values = symbolize_keys(values)
207
210
  passed_keys = values.keys.collect {|key| Factory.aliases_for(key) }.flatten
208
211
  @attributes.each do |attribute|
209
212
  unless passed_keys.include?(attribute.name)
@@ -225,7 +228,7 @@ class Factory
225
228
 
226
229
  def class_for (class_or_to_s)
227
230
  if class_or_to_s.respond_to?(:to_sym)
228
- class_or_to_s.to_s.pluralize.classify.constantize
231
+ Object.const_get(variable_name_to_class_name(class_or_to_s))
229
232
  else
230
233
  class_or_to_s
231
234
  end
@@ -235,7 +238,7 @@ class Factory
235
238
  if class_or_to_s.respond_to?(:to_sym)
236
239
  class_or_to_s.to_sym
237
240
  else
238
- class_or_to_s.to_s.underscore.to_sym
241
+ class_name_to_variable_name(class_or_to_s).to_sym
239
242
  end
240
243
  end
241
244
 
@@ -243,4 +246,35 @@ class Factory
243
246
  !@attributes.detect {|attr| attr.name == name }.nil?
244
247
  end
245
248
 
249
+ def assert_valid_options(options)
250
+ invalid_keys = options.keys - [:class]
251
+ unless invalid_keys == []
252
+ raise ArgumentError, "Unknown arguments: #{invalid_keys.inspect}"
253
+ end
254
+ end
255
+
256
+ # Based on ActiveSupport's underscore inflector
257
+ def class_name_to_variable_name(name)
258
+ name.to_s.gsub(/::/, '/').
259
+ gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
260
+ gsub(/([a-z\d])([A-Z])/,'\1_\2').
261
+ tr("-", "_").
262
+ downcase
263
+ end
264
+
265
+ # Based on ActiveSupport's camelize inflector
266
+ def variable_name_to_class_name(name)
267
+ name.to_s.
268
+ gsub(/\/(.?)/) { "::#{$1.upcase}" }.
269
+ gsub(/(?:^|_)(.)/) { $1.upcase }
270
+ end
271
+
272
+ # From ActiveSupport
273
+ def symbolize_keys(hash)
274
+ hash.inject({}) do |options, (key, value)|
275
+ options[(key.to_sym rescue key) || key] = value
276
+ options
277
+ end
278
+ end
279
+
246
280
  end
@@ -15,7 +15,9 @@ class Factory
15
15
 
16
16
  end
17
17
 
18
- cattr_accessor :sequences #:nodoc:
18
+ class << self
19
+ attr_accessor :sequences #:nodoc:
20
+ end
19
21
  self.sequences = {}
20
22
 
21
23
  # Defines a new sequence that can be used to generate unique values in a specific format.
data/test/factory_test.rb CHANGED
@@ -337,7 +337,7 @@ class FactoryTest < Test::Unit::TestCase
337
337
 
338
338
  end
339
339
 
340
- should "raise an ActiveRecord::RecordInvalid error for invalid instances" do
340
+ should "raise an error for invalid instances" do
341
341
  assert_raise(ActiveRecord::RecordInvalid) do
342
342
  @factory.create(:first_name => nil)
343
343
  end
@@ -28,7 +28,7 @@ class IntegrationTest < Test::Unit::TestCase
28
28
  end
29
29
 
30
30
  def teardown
31
- Factory.send(:class_variable_get, "@@factories").clear
31
+ Factory.factories.clear
32
32
  end
33
33
 
34
34
  context "a generated attributes hash" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: factory_girl
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.4
4
+ version: 1.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joe Ferris
@@ -9,19 +9,10 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-11-28 00:00:00 -05:00
12
+ date: 2008-12-11 00:00:00 -05:00
13
13
  default_executable:
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
16
- name: activesupport
17
- type: :runtime
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
20
- requirements:
21
- - - ">="
22
- - !ruby/object:Gem::Version
23
- version: "1.0"
24
- version:
14
+ dependencies: []
15
+
25
16
  description: factory_girl provides a framework and DSL for defining and using factories - less error-prone, more explicit, and all-around easier to work with than fixtures.
26
17
  email: jferris@thoughtbot.com
27
18
  executables: []
@@ -32,6 +23,7 @@ extra_rdoc_files:
32
23
  - README.textile
33
24
  files:
34
25
  - Changelog
26
+ - CONTRIBUTION_GUIDELINES.rdoc
35
27
  - LICENSE
36
28
  - Rakefile
37
29
  - README.textile