daddys_girl 0.6.1 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +25 -23
- data/README.md +1 -0
- data/daddys_girl.gemspec +1 -1
- data/lib/daddys_girl.rb +52 -23
- data/lib/daddys_girl/version.rb +1 -1
- metadata +12 -12
data/Gemfile.lock
CHANGED
@@ -1,48 +1,50 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
daddys_girl (0.
|
5
|
-
activerecord (
|
6
|
-
factory_girl (
|
4
|
+
daddys_girl (0.7.0)
|
5
|
+
activerecord (>= 3.0)
|
6
|
+
factory_girl (>= 2.0)
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
|
-
activemodel (3.
|
12
|
-
activesupport (= 3.
|
13
|
-
builder (~>
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
11
|
+
activemodel (3.2.3)
|
12
|
+
activesupport (= 3.2.3)
|
13
|
+
builder (~> 3.0.0)
|
14
|
+
activerecord (3.2.3)
|
15
|
+
activemodel (= 3.2.3)
|
16
|
+
activesupport (= 3.2.3)
|
17
|
+
arel (~> 3.0.2)
|
18
|
+
tzinfo (~> 0.3.29)
|
19
|
+
activesupport (3.2.3)
|
20
|
+
i18n (~> 0.6)
|
21
|
+
multi_json (~> 1.0)
|
22
|
+
arel (3.0.2)
|
23
|
+
builder (3.0.0)
|
23
24
|
diff-lcs (1.1.3)
|
24
|
-
factory_girl (
|
25
|
-
activesupport (>=
|
26
|
-
i18n (0.
|
25
|
+
factory_girl (3.1.1)
|
26
|
+
activesupport (>= 3.0.0)
|
27
|
+
i18n (0.6.0)
|
28
|
+
multi_json (1.3.2)
|
27
29
|
rspec (2.9.0)
|
28
30
|
rspec-core (~> 2.9.0)
|
29
31
|
rspec-expectations (~> 2.9.0)
|
30
32
|
rspec-mocks (~> 2.9.0)
|
31
33
|
rspec-core (2.9.0)
|
32
|
-
rspec-expectations (2.9.
|
34
|
+
rspec-expectations (2.9.1)
|
33
35
|
diff-lcs (~> 1.1.3)
|
34
36
|
rspec-mocks (2.9.0)
|
35
|
-
sqlite3 (1.3.
|
37
|
+
sqlite3 (1.3.6)
|
36
38
|
sqlite3-ruby (1.3.3)
|
37
39
|
sqlite3 (>= 1.3.3)
|
38
|
-
tzinfo (0.3.
|
40
|
+
tzinfo (0.3.33)
|
39
41
|
|
40
42
|
PLATFORMS
|
41
43
|
ruby
|
42
44
|
|
43
45
|
DEPENDENCIES
|
44
|
-
activerecord (
|
46
|
+
activerecord (>= 3.0)
|
45
47
|
daddys_girl!
|
46
|
-
factory_girl (
|
48
|
+
factory_girl (>= 2.0)
|
47
49
|
rspec (~> 2.0)
|
48
50
|
sqlite3-ruby
|
data/README.md
CHANGED
@@ -20,6 +20,7 @@ Or install it yourself as:
|
|
20
20
|
First, you must add a class definition to the Factory Girl factories file (normally spec/factories.rb)
|
21
21
|
|
22
22
|
Methods:
|
23
|
+
|
23
24
|
1. ```ClassName.spawn(params)```: creates an object, but does not save it
|
24
25
|
2. ```ClassName.generate(params)```: creates an object and attempts to save it
|
25
26
|
3. ```ClassName.generate!(params)```: creates an object, and throws an error if it can not save it
|
data/daddys_girl.gemspec
CHANGED
@@ -14,7 +14,7 @@ Gem::Specification.new do |gem|
|
|
14
14
|
gem.name = "daddys_girl"
|
15
15
|
gem.require_paths = ["lib"]
|
16
16
|
gem.version = DaddysGirl::VERSION
|
17
|
-
gem.add_dependency "activerecord", "
|
17
|
+
gem.add_dependency "activerecord", ">= 3.0"
|
18
18
|
gem.add_dependency "factory_girl", ">= 2.0"
|
19
19
|
gem.add_development_dependency "rspec", "~> 2.0"
|
20
20
|
gem.add_development_dependency "sqlite3-ruby"
|
data/lib/daddys_girl.rb
CHANGED
@@ -24,38 +24,67 @@ ActiveRecord::Base.class_eval do
|
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
+
if ActiveRecord::VERSION::MAJOR == 3 && ActiveRecord::VERSION::MINOR == 0
|
28
|
+
ActiveRecord::Associations::AssociationProxy.class_eval do
|
29
|
+
def target_class_symbol
|
30
|
+
self.symbol
|
31
|
+
end
|
27
32
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
33
|
+
def generate(attributes = {})
|
34
|
+
attributes = attributes.merge(association_attribute)
|
35
|
+
begin
|
36
|
+
FactoryGirl.create(target_class_symbol, attributes)
|
37
|
+
rescue ActiveRecord::RecordInvalid
|
38
|
+
FactoryGirl.build(target_class_symbol, attributes)
|
39
|
+
end
|
40
|
+
end
|
32
41
|
|
33
|
-
|
34
|
-
|
35
|
-
begin
|
42
|
+
def generate!(attributes = {})
|
43
|
+
attributes = attributes.merge(association_attribute)
|
36
44
|
FactoryGirl.create(target_class_symbol, attributes)
|
37
|
-
|
45
|
+
end
|
46
|
+
|
47
|
+
def spawn(attributes = {})
|
48
|
+
attributes = attributes.merge(association_attribute)
|
38
49
|
FactoryGirl.build(target_class_symbol, attributes)
|
39
50
|
end
|
40
|
-
end
|
41
51
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
52
|
+
private
|
53
|
+
def owner_association
|
54
|
+
proxy_reflection.primary_key_name.to_sym
|
55
|
+
end
|
46
56
|
|
47
|
-
|
48
|
-
|
49
|
-
|
57
|
+
def association_attribute
|
58
|
+
{owner_association => proxy_owner.id}
|
59
|
+
end
|
50
60
|
end
|
61
|
+
end
|
51
62
|
|
52
|
-
private
|
53
|
-
def owner_association
|
54
|
-
proxy_reflection.primary_key_name.to_sym
|
55
|
-
end
|
56
63
|
|
57
|
-
|
58
|
-
|
64
|
+
if ActiveRecord::VERSION::MAJOR == 3 && ActiveRecord::VERSION::MINOR >= 1
|
65
|
+
ActiveRecord::Relation.class_eval do
|
66
|
+
def target_class_symbol
|
67
|
+
self.symbol
|
68
|
+
end
|
69
|
+
|
70
|
+
def generate(attributes = {})
|
71
|
+
attributes = attributes.merge(where_values_hash)
|
72
|
+
begin
|
73
|
+
FactoryGirl.create(target_class_symbol, attributes)
|
74
|
+
rescue ActiveRecord::RecordInvalid
|
75
|
+
FactoryGirl.build(target_class_symbol, attributes)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def generate!(attributes = {})
|
80
|
+
attributes = attributes.merge(where_values_hash)
|
81
|
+
FactoryGirl.create(target_class_symbol, attributes)
|
82
|
+
end
|
83
|
+
|
84
|
+
def spawn(attributes = {})
|
85
|
+
attributes = attributes.merge(where_values_hash)
|
86
|
+
FactoryGirl.build(target_class_symbol, attributes)
|
87
|
+
end
|
88
|
+
|
59
89
|
end
|
60
90
|
end
|
61
|
-
|
data/lib/daddys_girl/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: daddys_girl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,22 +9,22 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-04-
|
12
|
+
date: 2012-04-20 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|
16
|
-
requirement: &
|
16
|
+
requirement: &70814090 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
|
-
- -
|
19
|
+
- - ! '>='
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: 3.0
|
21
|
+
version: '3.0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70814090
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: factory_girl
|
27
|
-
requirement: &
|
27
|
+
requirement: &70813810 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '2.0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70813810
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rspec
|
38
|
-
requirement: &
|
38
|
+
requirement: &70813510 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '2.0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70813510
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: sqlite3-ruby
|
49
|
-
requirement: &
|
49
|
+
requirement: &70813250 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,7 +54,7 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70813250
|
58
58
|
description: Rubygem to provide object_daddy-like syntax for factory_girl
|
59
59
|
email:
|
60
60
|
- development@inventables.com
|