minifacture 1.2.2 → 1.3.0
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.
- checksums.yaml +4 -4
- data/minifacture.rb +3 -4
- data/minifacture_test.rb +31 -32
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 827bc343ae326748c408044a36f99b0f9ac16d4e
|
4
|
+
data.tar.gz: 5bf92242ed3d369d125a36d5f89b53f7c1a03c43
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a065832618175d374c6be09070639c97652afd1a5bc0d92ed6a7c89be670577af097099c047958debdec401f16974fe670598bf85192a71cb409e4b4f3f7556b
|
7
|
+
data.tar.gz: 889afe00efa9725ed6efbf867996ebd83a35e2a5b2c26ebbc32fc21a3c8872a53c93ca248ceeeebe0c41e1af8d7f59d4e54492c4b32552e041166e58c9eb5727
|
data/minifacture.rb
CHANGED
@@ -13,7 +13,7 @@ require 'active_support/core_ext/hash'
|
|
13
13
|
# end
|
14
14
|
class Minifacture < Struct.new(:__klass__)
|
15
15
|
undef_method *instance_methods.grep(/^(?!__|object_id)/)
|
16
|
-
@@attrs = {} and private_class_method :new
|
16
|
+
@@attrs = {} and @@counts = Hash.new(0) and private_class_method :new
|
17
17
|
|
18
18
|
class << self
|
19
19
|
def define name, options = {}
|
@@ -24,11 +24,10 @@ class Minifacture < Struct.new(:__klass__)
|
|
24
24
|
(h, opts, n = @@attrs[name = name.to_s]) and m = opts[:class] || name
|
25
25
|
p = opts[:parent] and (h, m = @@attrs[p = p.to_s][0].merge(h), p)
|
26
26
|
(m = m.is_a?(Class) ? m : m.to_s.camelize.constantize).new.tap do |r|
|
27
|
+
c = @@counts[p || name] += 1
|
27
28
|
attrs.symbolize_keys!.reverse_update(h).each do |k, v|
|
28
29
|
r.send "#{k}=", case v when String # Sequence and interpolate.
|
29
|
-
v.sub(/%\d*d/) {|d| d % n ||=
|
30
|
-
m.respond_to?(:maximum) ? m.maximum(:id) : m.max(:id)
|
31
|
-
).to_i + 1} % attrs % n
|
30
|
+
v.sub(/%\d*d/) { |d| d % n ||= c } % attrs % n
|
32
31
|
when Proc then v.call(r) else v
|
33
32
|
end
|
34
33
|
end
|
data/minifacture_test.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
require './minifacture'
|
2
|
-
require '
|
2
|
+
require 'minitest/autorun'
|
3
3
|
|
4
|
-
class MinifactureTest < Test
|
4
|
+
class MinifactureTest < Minitest::Test
|
5
5
|
def test_should_define_factories
|
6
6
|
factories = Minifacture.class_variable_get :@@attrs
|
7
|
-
|
8
|
-
|
7
|
+
refute_nil factories["user"]
|
8
|
+
refute_nil factories["blog_entry"]
|
9
9
|
end
|
10
10
|
|
11
11
|
def test_should_build_object
|
@@ -27,10 +27,10 @@ class MinifactureTest < Test::Unit::TestCase
|
|
27
27
|
|
28
28
|
def test_should_assign_attributes
|
29
29
|
user = Factory.create :user
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
30
|
+
refute_nil user.login
|
31
|
+
refute_nil user.email
|
32
|
+
refute_nil user.password
|
33
|
+
refute_nil user.password_confirmation
|
34
34
|
end
|
35
35
|
|
36
36
|
def test_should_chain_attributes
|
@@ -51,10 +51,10 @@ class MinifactureTest < Test::Unit::TestCase
|
|
51
51
|
|
52
52
|
user = Factory.create :user
|
53
53
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
54
|
+
refute_equal login, user.login
|
55
|
+
refute_equal email, user.email
|
56
|
+
refute_equal password, user.password
|
57
|
+
refute_equal password_confirmation, user.password_confirmation
|
58
58
|
end
|
59
59
|
|
60
60
|
def test_should_sequence
|
@@ -63,6 +63,13 @@ class MinifactureTest < Test::Unit::TestCase
|
|
63
63
|
assert_equal user1.login.sub(/\d+$/) { |n| n.to_i.succ.to_s }, user2.login
|
64
64
|
end
|
65
65
|
|
66
|
+
def test_should_sequence_with_parent
|
67
|
+
user = Factory.create :user
|
68
|
+
admin = Factory.create :admin
|
69
|
+
assert_equal user.login, 'johndoe1'
|
70
|
+
assert_equal admin.login, 'admin2'
|
71
|
+
end
|
72
|
+
|
66
73
|
def test_should_interpolate
|
67
74
|
user = Factory.create :user
|
68
75
|
assert_equal user.email, "#{user.login}@example.com"
|
@@ -70,36 +77,28 @@ class MinifactureTest < Test::Unit::TestCase
|
|
70
77
|
|
71
78
|
def test_should_inherit
|
72
79
|
admin = Factory.create :admin
|
73
|
-
assert_equal '
|
74
|
-
assert_equal '
|
80
|
+
assert_equal 'admin1', admin.login
|
81
|
+
assert_equal 'admin1@example.com', admin.email
|
75
82
|
end
|
76
83
|
|
77
84
|
def test_should_alias
|
78
85
|
blog_entry = Factory.create :blog_entry
|
79
|
-
assert_equal '
|
86
|
+
assert_equal 'admin1', blog_entry.user.login
|
80
87
|
end
|
81
88
|
|
82
89
|
def test_should_accept_class_as_symbol
|
83
|
-
|
84
|
-
guest = Factory.create :guest
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
class Mock
|
90
|
-
@@maximum = nil
|
91
|
-
def self.maximum(column)
|
92
|
-
@@maximum
|
90
|
+
guest = Factory.create :guest
|
93
91
|
end
|
94
92
|
|
95
|
-
def
|
96
|
-
|
97
|
-
|
93
|
+
def teardown
|
94
|
+
counts = Minifacture.class_variable_get(:@@counts)
|
95
|
+
counts.each { |k,_| counts[k] = 0 }
|
98
96
|
end
|
97
|
+
end
|
99
98
|
|
100
|
-
|
101
|
-
|
102
|
-
end
|
99
|
+
class Mock
|
100
|
+
def save!() @saved = true end
|
101
|
+
def new_record?() !@saved end
|
103
102
|
end
|
104
103
|
|
105
104
|
class User < Mock
|
@@ -111,7 +110,7 @@ class Post < Mock
|
|
111
110
|
end
|
112
111
|
|
113
112
|
Minifacture.define :admin, :parent => :user do |f|
|
114
|
-
f.login "admin"
|
113
|
+
f.login "admin%d"
|
115
114
|
end
|
116
115
|
|
117
116
|
Minifacture.define :user do |f|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: minifacture
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stephen Celis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-07-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -92,9 +92,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
92
92
|
version: '0'
|
93
93
|
requirements: []
|
94
94
|
rubyforge_project:
|
95
|
-
rubygems_version: 2.
|
95
|
+
rubygems_version: 2.4.5
|
96
96
|
signing_key:
|
97
97
|
specification_version: 4
|
98
98
|
summary: factory_girl for minitest.
|
99
99
|
test_files:
|
100
100
|
- minifacture_test.rb
|
101
|
+
has_rdoc: false
|