test_dummy 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +21 -0
- data/VERSION +1 -1
- data/lib/test_dummy/helper.rb +4 -4
- data/lib/test_dummy.rb +5 -3
- data/test_dummy.gemspec +2 -2
- metadata +3 -3
data/README.rdoc
CHANGED
@@ -3,6 +3,27 @@
|
|
3
3
|
Test Dummy is an easy fake data generator library with the ability to create
|
4
4
|
fake models or entirely faked data structures on-demand.
|
5
5
|
|
6
|
+
After installing the gem, methods to declare how to fake data are made
|
7
|
+
available within ActiveRecord-derived models. There are several ways to
|
8
|
+
declare how to dummy something:
|
9
|
+
|
10
|
+
class MyModel < ActiveRecord::Base
|
11
|
+
# Pass a block that defines how to dummy this attribute
|
12
|
+
to_dummy :name do
|
13
|
+
"user%d" % rand(10e6)
|
14
|
+
end
|
15
|
+
|
16
|
+
# Pass a block that defines how to dummy several attributes
|
17
|
+
to_dummy :password, :password_confirmation do
|
18
|
+
'tester'
|
19
|
+
end
|
20
|
+
|
21
|
+
# Use one of the pre-defined helper methods to dummy this attribute
|
22
|
+
to_dummy :nickname, :use => :random_phonetic_string
|
23
|
+
end
|
24
|
+
|
25
|
+
A standard method
|
26
|
+
|
6
27
|
== Copyright
|
7
28
|
|
8
29
|
Copyright (c) 2010 Scott Tadman, The Working Group
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.4
|
data/lib/test_dummy/helper.rb
CHANGED
@@ -12,11 +12,11 @@ module TestDummy::Helper
|
|
12
12
|
def random_string(length = 12)
|
13
13
|
string = nil
|
14
14
|
|
15
|
-
while (!string or
|
15
|
+
while (!string or AVOID_SUBSTRINGS.match(string))
|
16
16
|
string = ''
|
17
17
|
|
18
18
|
length.times do
|
19
|
-
string << CHARACTER_SET.
|
19
|
+
string << CHARACTER_SET[rand(CHARACTER_SET.length)]
|
20
20
|
end
|
21
21
|
|
22
22
|
# As it's not especially hard to find a random word that passes this
|
@@ -33,11 +33,11 @@ module TestDummy::Helper
|
|
33
33
|
def random_phonetic_string(length = 12)
|
34
34
|
string = nil
|
35
35
|
|
36
|
-
while (!string or
|
36
|
+
while (!string or AVOID_SUBSTRINGS.match(string))
|
37
37
|
string = ''
|
38
38
|
|
39
39
|
length.times do |i|
|
40
|
-
|
40
|
+
string << ((i % 2 != 0) ? CONSONANTS[rand(CONSONANTS.size)] : VOWELS[rand(VOWELS.size)])
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
data/lib/test_dummy.rb
CHANGED
@@ -39,7 +39,7 @@ module TestDummy
|
|
39
39
|
|
40
40
|
# Used in an initializer to define things that can be dummied by all
|
41
41
|
# models if these properties are available.
|
42
|
-
def self.
|
42
|
+
def self.dummy(*names, &block)
|
43
43
|
case (names.last)
|
44
44
|
when Hash
|
45
45
|
options = names.pop
|
@@ -76,7 +76,7 @@ module TestDummy
|
|
76
76
|
# that can receive up to two parameters, the first the instance of
|
77
77
|
# the model being created, the second the parameters supplied to create
|
78
78
|
# it. The first and second parameters may be nil.
|
79
|
-
def
|
79
|
+
def dummy(*names, &block)
|
80
80
|
options = nil
|
81
81
|
|
82
82
|
case (names.last)
|
@@ -155,7 +155,7 @@ module TestDummy
|
|
155
155
|
end
|
156
156
|
|
157
157
|
# Produces dummy data for a single attribute.
|
158
|
-
def
|
158
|
+
def dummy_attribute(name, with_attributes = nil)
|
159
159
|
with_attributes = TestDummy.combine_attributes(scoped.scope_for_create, with_attributes)
|
160
160
|
|
161
161
|
dummy_method_call(nil, with_attributes, dummy_method(name))
|
@@ -186,6 +186,8 @@ module TestDummy
|
|
186
186
|
# This performs the dummy operation on a model with an optional set
|
187
187
|
# of parameters.
|
188
188
|
def execute_dummy_operation(model, with_attributes = nil)
|
189
|
+
return model unless (@test_dummy_order)
|
190
|
+
|
189
191
|
@test_dummy_order.each do |name|
|
190
192
|
if (reflection = reflect_on_association(name))
|
191
193
|
unless ((with_attributes and with_attributes.key?(name.to_sym)) or model.send(name))
|
data/test_dummy.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{test_dummy}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.4"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["tadman"]
|
12
|
-
s.date = %q{2010-09-
|
12
|
+
s.date = %q{2010-09-03}
|
13
13
|
s.description = %q{Test Dummy allows you to define how to fake models automatically so that you can use dummy data for testing instead of fixtures. Dummy models are always generated using the current schema and don't need to me migrated like fixtures.}
|
14
14
|
s.email = %q{github@tadman.ca}
|
15
15
|
s.extra_rdoc_files = [
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
8
|
+
- 4
|
9
|
+
version: 0.1.4
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- tadman
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-09-
|
17
|
+
date: 2010-09-03 00:00:00 -04:00
|
18
18
|
default_executable:
|
19
19
|
dependencies: []
|
20
20
|
|