daddys_girl 0.2

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 (2) hide show
  1. data/lib/daddys_girl.rb +54 -0
  2. metadata +64 -0
@@ -0,0 +1,54 @@
1
+ class ActiveRecord::Base
2
+ class << self
3
+ def symbol
4
+ self.name.underscore.to_sym
5
+ end
6
+
7
+ def generate(attributes = {})
8
+ FactoryGirl.create(self.symbol, attributes)
9
+ end
10
+
11
+ def generate!(attributes = {})
12
+ FactoryGirl.create(self.symbol, attributes).tap do |obj|
13
+ raise obj.errors.inspect unless obj.errors.empty?
14
+ end
15
+ end
16
+
17
+ def spawn(attributes = {})
18
+ FactoryGirl.build(self.symbol, attributes)
19
+ end
20
+ end
21
+ end
22
+
23
+ class ActiveRecord::Associations::AssociationProxy
24
+ def target_class_symbol
25
+ self.symbol
26
+ end
27
+
28
+ def generate(attributes = {})
29
+ attributes = attributes.merge(association_attribute)
30
+ FactoryGirl.create(target_class_symbol, attributes)
31
+ end
32
+
33
+ def generate!(attributes = {})
34
+ attributes = attributes.merge(association_attribute)
35
+ FactoryGirl.create(target_class_symbol, attributes).tap do |obj|
36
+ raise obj.errors.inspect unless obj.errors.empty?
37
+ end
38
+ end
39
+
40
+ def spawn(attributes = {})
41
+ attributes = attributes.merge(association_attribute)
42
+ FactoryGirl.build(target_class_symbol, attributes)
43
+ end
44
+
45
+ private
46
+ def owner_association
47
+ proxy_reflection.primary_key_name.to_sym
48
+ end
49
+
50
+ def association_attribute
51
+ {owner_association => proxy_owner.id}
52
+ end
53
+ end
54
+
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: daddys_girl
3
+ version: !ruby/object:Gem::Version
4
+ hash: 15
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 2
9
+ version: "0.2"
10
+ platform: ruby
11
+ authors:
12
+ - Kurt Preston
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2020-03-13 00:00:00 Z
18
+ dependencies: []
19
+
20
+ description: Rubygem to provide object_daddy-like syntax for factory_girl
21
+ email: development@inventables.com
22
+ executables: []
23
+
24
+ extensions: []
25
+
26
+ extra_rdoc_files: []
27
+
28
+ files:
29
+ - lib/daddys_girl.rb
30
+ homepage: https://github.com/inventables/daddys_girl
31
+ licenses: []
32
+
33
+ post_install_message:
34
+ rdoc_options: []
35
+
36
+ require_paths:
37
+ - lib
38
+ required_ruby_version: !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 3
44
+ segments:
45
+ - 0
46
+ version: "0"
47
+ required_rubygems_version: !ruby/object:Gem::Requirement
48
+ none: false
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ hash: 3
53
+ segments:
54
+ - 0
55
+ version: "0"
56
+ requirements: []
57
+
58
+ rubyforge_project:
59
+ rubygems_version: 1.7.2
60
+ signing_key:
61
+ specification_version: 3
62
+ summary: "[Object] Daddy's [Factory] Girl"
63
+ test_files: []
64
+