daddys_girl 0.3 → 0.4
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.
- data/lib/daddys_girl.rb +44 -36
- metadata +40 -5
data/lib/daddys_girl.rb
CHANGED
|
@@ -1,54 +1,62 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
module DaddysGirl
|
|
2
|
+
module ActiveRecordModel
|
|
3
|
+
class << self
|
|
4
|
+
def symbol
|
|
5
|
+
self.name.underscore.to_sym
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def generate(attributes = {})
|
|
9
|
+
FactoryGirl.create(self.symbol, attributes)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def generate!(attributes = {})
|
|
13
|
+
FactoryGirl.create(self.symbol, attributes).tap do |obj|
|
|
14
|
+
raise obj.errors.inspect unless obj.errors.empty?
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def spawn(attributes = {})
|
|
19
|
+
FactoryGirl.build(self.symbol, attributes)
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
ActiveRecord::Base.send(:include, DaddysGirl::ActiveRecordModel) if defined?(ActiveRecord)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
module DaddysGirl
|
|
29
|
+
module AssociationModel
|
|
30
|
+
def target_class_symbol
|
|
31
|
+
self.symbol
|
|
5
32
|
end
|
|
6
33
|
|
|
7
34
|
def generate(attributes = {})
|
|
8
|
-
|
|
35
|
+
attributes = attributes.merge(association_attribute)
|
|
36
|
+
FactoryGirl.create(target_class_symbol, attributes)
|
|
9
37
|
end
|
|
10
38
|
|
|
11
39
|
def generate!(attributes = {})
|
|
12
|
-
|
|
40
|
+
attributes = attributes.merge(association_attribute)
|
|
41
|
+
FactoryGirl.create(target_class_symbol, attributes).tap do |obj|
|
|
13
42
|
raise obj.errors.inspect unless obj.errors.empty?
|
|
14
43
|
end
|
|
15
44
|
end
|
|
16
45
|
|
|
17
46
|
def spawn(attributes = {})
|
|
18
|
-
|
|
47
|
+
attributes = attributes.merge(association_attribute)
|
|
48
|
+
FactoryGirl.build(target_class_symbol, attributes)
|
|
19
49
|
end
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
ActiveRecord::Associations::AssociationProxy.class_eval do
|
|
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
50
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
raise obj.errors.inspect unless obj.errors.empty?
|
|
51
|
+
private
|
|
52
|
+
def owner_association
|
|
53
|
+
proxy_reflection.primary_key_name.to_sym
|
|
37
54
|
end
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
def spawn(attributes = {})
|
|
41
|
-
attributes = attributes.merge(association_attribute)
|
|
42
|
-
FactoryGirl.build(target_class_symbol, attributes)
|
|
43
|
-
end
|
|
44
55
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
def association_attribute
|
|
51
|
-
{owner_association => proxy_owner.id}
|
|
56
|
+
def association_attribute
|
|
57
|
+
{owner_association => proxy_owner.id}
|
|
58
|
+
end
|
|
52
59
|
end
|
|
53
60
|
end
|
|
54
61
|
|
|
62
|
+
ActiveRecord::Associations::AssociationProxy.send(:include, DaddysGirl::AssocationModel) if defined?(ActiveRecord)
|
metadata
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: daddys_girl
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
hash:
|
|
4
|
+
hash: 3
|
|
5
5
|
prerelease:
|
|
6
6
|
segments:
|
|
7
7
|
- 0
|
|
8
|
-
-
|
|
9
|
-
version: "0.
|
|
8
|
+
- 4
|
|
9
|
+
version: "0.4"
|
|
10
10
|
platform: ruby
|
|
11
11
|
authors:
|
|
12
12
|
- Kurt Preston
|
|
@@ -15,8 +15,43 @@ bindir: bin
|
|
|
15
15
|
cert_chain: []
|
|
16
16
|
|
|
17
17
|
date: 2020-03-13 00:00:00 Z
|
|
18
|
-
dependencies:
|
|
19
|
-
|
|
18
|
+
dependencies:
|
|
19
|
+
- !ruby/object:Gem::Dependency
|
|
20
|
+
name: activerecord
|
|
21
|
+
prerelease: false
|
|
22
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
|
23
|
+
none: false
|
|
24
|
+
requirements:
|
|
25
|
+
- - ">="
|
|
26
|
+
- !ruby/object:Gem::Version
|
|
27
|
+
hash: 7
|
|
28
|
+
segments:
|
|
29
|
+
- 3
|
|
30
|
+
- 0
|
|
31
|
+
version: "3.0"
|
|
32
|
+
- - <=
|
|
33
|
+
- !ruby/object:Gem::Version
|
|
34
|
+
hash: 3
|
|
35
|
+
segments:
|
|
36
|
+
- 3
|
|
37
|
+
- 2
|
|
38
|
+
version: "3.2"
|
|
39
|
+
type: :runtime
|
|
40
|
+
version_requirements: *id001
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: factory_girl
|
|
43
|
+
prerelease: false
|
|
44
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
|
45
|
+
none: false
|
|
46
|
+
requirements:
|
|
47
|
+
- - ">="
|
|
48
|
+
- !ruby/object:Gem::Version
|
|
49
|
+
hash: 3
|
|
50
|
+
segments:
|
|
51
|
+
- 0
|
|
52
|
+
version: "0"
|
|
53
|
+
type: :runtime
|
|
54
|
+
version_requirements: *id002
|
|
20
55
|
description: Rubygem to provide object_daddy-like syntax for factory_girl
|
|
21
56
|
email: development@inventables.com
|
|
22
57
|
executables: []
|