urlsplease-imposter 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +10 -0
- data/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README.rdoc +24 -0
- data/Rakefile +57 -0
- data/VERSION +1 -0
- data/generators/imposter_generator.rb +100 -0
- data/generators/templates/databases.rake +11 -0
- data/id_rsa.pub +1 -0
- data/lib/generators/imposter.rb +18 -0
- data/lib/generators/imposter/gen_models/gen_models_generator.rb +135 -0
- data/lib/generators/imposter/install/install_generator.rb +25 -0
- data/lib/generators/imposter/install/templates/databases.rake +11 -0
- data/lib/generators/imposter/install/templates/models.yml +34 -0
- data/lib/imposter.rb +110 -0
- data/lib/imposter/animal.rb +15 -0
- data/lib/imposter/csz.db +0 -0
- data/lib/imposter/csz.rb +70 -0
- data/lib/imposter/mineral.rb +14 -0
- data/lib/imposter/noun.rb +15 -0
- data/lib/imposter/phone.rb +36 -0
- data/lib/imposter/vegetable.rb +18 -0
- data/lib/imposter/verb.rb +14 -0
- data/lib/imposter/version.rb +9 -0
- data/test/helper.rb +10 -0
- data/test/test_imposter.rb +69 -0
- data/urlsplease-imposter.gemspec +83 -0
- metadata +159 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Robert Hall
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
= Imposter
|
2
|
+
|
3
|
+
Real fake data. Allows creation of an entire schema of fake data that honors associations.
|
4
|
+
|
5
|
+
Forked for urlsplease.com to adapt to Ruby 1.9.x (CSV library)
|
6
|
+
|
7
|
+
== Usage
|
8
|
+
* script/generate imposter => /test/imposter/[timestamp]_[model].yaml #YAML DSLs for the fake data generation
|
9
|
+
# YAMLs are executed in series order much like migrations
|
10
|
+
* rake::imposter IMPOSTER="products" #generate only the /test/fixtures/products.csv
|
11
|
+
* rake::imposter #generate all /test/imposter/[##############_]*.yaml to /test/fixtures
|
12
|
+
* rake::imposter --force #generate all /test/imposter/[###]-*.yaml to /test/fixtures to
|
13
|
+
* overwrite any existing .csv
|
14
|
+
|
15
|
+
* Imposter::Noun.noun => "apple" #random noun
|
16
|
+
* Imposter::Verb.verbs(3) => "run tag jump" #random verbs string space delimited
|
17
|
+
|
18
|
+
#---For unit/integration/etl testing that require real but random addresses
|
19
|
+
* Imposter::CSZ.zip => "90210" #random real postal code
|
20
|
+
* Imposter::CSZ.city(:zip=>"90210") => "Beverly Hills" #real city name from zip
|
21
|
+
* Imposter::CSZ.state_abbr(:zip=>"90210") => "CA" #real 2 letter state abbreviation upper case
|
22
|
+
* Imposter::CSZ.state_name(:zip=>"90210") => "California" #Real State name Camelized
|
23
|
+
|
24
|
+
* Imposter::CSZ.zip(:state_abbr=>"CA") => "90115" #Random but real postal code from real state.
|
data/Rakefile
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'rake'
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'jeweler'
|
5
|
+
Jeweler::Tasks.new do |gem|
|
6
|
+
gem.name = "urlsplease-imposter"
|
7
|
+
gem.summary = "(Ruby 1.9 and Rails 3 ready) Real fake data"
|
8
|
+
gem.email = "mh@michaelharrison.ws"
|
9
|
+
gem.homepage = "http://github.com/urlsplease/imposter"
|
10
|
+
gem.authors = ["Robert Hall", "Michael Harrison"]
|
11
|
+
gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
|
12
|
+
gem.add_dependency "sqlite3-ruby", ">= 1.2.5"
|
13
|
+
gem.add_dependency "faker", ">= 0"
|
14
|
+
gem.add_dependency "fastercsv", ">= 0"
|
15
|
+
gem.files.include %w(lib/generators/**/*.rb lib/imposter/*.rb lib/imposter/*.db generators/**/*.rb generators/templates/*)
|
16
|
+
gem.description = %Q{Temporary fork of Robert Hall's imposter gem with Ruby 1.9 and Rails 3 support. Provides generators and rake tasks via YAML based imposters for schema level data faking}
|
17
|
+
gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
|
18
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
19
|
+
end
|
20
|
+
Jeweler::GemcutterTasks.new
|
21
|
+
rescue LoadError
|
22
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
23
|
+
end
|
24
|
+
|
25
|
+
require 'rake/testtask'
|
26
|
+
Rake::TestTask.new(:test) do |test|
|
27
|
+
test.libs << 'lib' << 'test'
|
28
|
+
test.pattern = 'test/**/test_*.rb'
|
29
|
+
test.verbose = true
|
30
|
+
end
|
31
|
+
|
32
|
+
begin
|
33
|
+
require 'rcov/rcovtask'
|
34
|
+
Rcov::RcovTask.new do |test|
|
35
|
+
test.libs << 'test'
|
36
|
+
test.pattern = 'test/**/test_*.rb'
|
37
|
+
test.verbose = true
|
38
|
+
end
|
39
|
+
rescue LoadError
|
40
|
+
task :rcov do
|
41
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
task :test => :check_dependencies
|
46
|
+
|
47
|
+
task :default => :test
|
48
|
+
|
49
|
+
require 'rake/rdoctask'
|
50
|
+
Rake::RDocTask.new do |rdoc|
|
51
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
52
|
+
|
53
|
+
rdoc.rdoc_dir = 'rdoc'
|
54
|
+
rdoc.title = "imposter #{version}"
|
55
|
+
rdoc.rdoc_files.include('README*')
|
56
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
57
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.2.0
|
@@ -0,0 +1,100 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'activerecord'
|
3
|
+
require 'pathname'
|
4
|
+
require 'activesupport'
|
5
|
+
require 'ftools'
|
6
|
+
|
7
|
+
class ImposterGenerator < Rails::Generator::Base
|
8
|
+
dbc = YAML.load(File.read('config/database.yml'))
|
9
|
+
conn = ActiveRecord::Base.establish_connection(dbc["development"])
|
10
|
+
|
11
|
+
def manifest
|
12
|
+
record do |m|
|
13
|
+
m.directory("test/imposter")
|
14
|
+
m.file("databases.rake", "lib/tasks/database.rake")
|
15
|
+
puts "Collision Forced " + (options[:collision] == :force).to_s
|
16
|
+
puts "Generating"
|
17
|
+
genmodels
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
def genmodel(model_name)
|
23
|
+
mn = Pathname.new(model_name).basename.to_s.chomp(File.extname(model_name))
|
24
|
+
require model_name
|
25
|
+
|
26
|
+
yaml_file = "test/imposter/" + "%03d" % eval(mn.camelcase).reflections.count + "-" + mn + ".yml"
|
27
|
+
if (not File.exists? yaml_file) || options[:collision] == :force then
|
28
|
+
puts " " + mn
|
29
|
+
mh = Hash.new
|
30
|
+
ma = Hash.new
|
31
|
+
mf = Hash.new
|
32
|
+
eval(mn.camelcase).columns.each do |mod|
|
33
|
+
if mod.name.include? "_id" then
|
34
|
+
vl = "@" + mod.name.sub("_id","").pluralize + "[rand(@" + mod.name.sub('_id','').pluralize + ".length)][1]"
|
35
|
+
mh = {mod.name => vl}
|
36
|
+
ma.merge!(mh)
|
37
|
+
else
|
38
|
+
case mod.type.to_s.downcase
|
39
|
+
when 'string'
|
40
|
+
case (1 + rand(3))
|
41
|
+
when 1
|
42
|
+
vl = 'Imposter::Noun.multiple'
|
43
|
+
when 2
|
44
|
+
vl = 'Imposter::Animal.one'
|
45
|
+
when 3
|
46
|
+
vl = 'Imposter::Vegetable.multiple'
|
47
|
+
when 4
|
48
|
+
vl = 'Imposter::Mineral.one'
|
49
|
+
end
|
50
|
+
when 'text' then
|
51
|
+
vl = 'Faker::Lorem.sentence(3)'
|
52
|
+
when 'integer' then
|
53
|
+
vl = 'i.to_s'
|
54
|
+
when 'datetime'
|
55
|
+
vl = 'Date.today.to_s'
|
56
|
+
when 'date'
|
57
|
+
vl = 'Date.today.to_s'
|
58
|
+
when 'decimal' then
|
59
|
+
vl = 'rand(50).to_s + "." + (1000+rand(2000)).to_s'
|
60
|
+
else
|
61
|
+
puts "=-------=============> " + mod.type.to_s.downcase
|
62
|
+
end
|
63
|
+
if not mod.name.include? "_at" and :include_special
|
64
|
+
mh = {mod.name => vl}
|
65
|
+
ma.merge!(mh)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
mf.merge!(mn => {"fields" => ma})
|
70
|
+
mf[mn].merge!({"quantity" => 10})
|
71
|
+
File.open("test/imposter/" + "%03d" % eval(mn.camelcase).reflections.count + "-" + mn + ".yml","w") do |out|
|
72
|
+
YAML.dump(mf,out)
|
73
|
+
end
|
74
|
+
else
|
75
|
+
puts " " + mn + " --skipped"
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def genmodels
|
80
|
+
#create_rake_file
|
81
|
+
models_dir = Dir.glob("app/models/*.rb")
|
82
|
+
models_dir.each do |model_dir|
|
83
|
+
genmodel(model_dir)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def banner
|
88
|
+
"Usage: #{$0} #{spec.name} [options]"
|
89
|
+
end
|
90
|
+
|
91
|
+
def add_options!(opt)
|
92
|
+
opt.on('-f', '--force') { |value| options[:force] = value }
|
93
|
+
end
|
94
|
+
|
95
|
+
def create_rake_file
|
96
|
+
puts "Creating lib/tasks/databases.rake"
|
97
|
+
File.copy( Pathname.new(__FILE__).dirname + "../lib/tasks/databases.rake", "lib/tasks/")
|
98
|
+
end
|
99
|
+
|
100
|
+
end
|
data/id_rsa.pub
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA07d+kNjinydoDakKuXJDArDGevujnc9/lOmY8Op/poBHJuCfJtxcnfF8T1MlV7CtwLmXxp2AtXiRHakyBB1GfjwUPvzbsfkZkxtg7rPukaYgfBJyaKRR9QDxiUKt7AU7FBcTYapuDnaqVIb3U9jhI7ryCyY1RCsJbR5cSjWsw74a0GnhcuO0Ex20RYkv8sUPvLeNsAJn4H+aY+OCwRW2HFgEv0ewAtmV0MxOAuBduxWgXszX/U6jQAEMjiqZcJoJnb7g6dxA3oV0UghsB1n4wy1UDWAe4IG21iIl7gq6U54xZGad5IgtnHmCMvweJkaM65cO9EeDevGmlKG1G1jTMw== robert.hall@itatc.com
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Imposter
|
2
|
+
module Generators
|
3
|
+
module TemplatePath
|
4
|
+
def source_root
|
5
|
+
@_imposter_source_root ||= File.expand_path(File.join(File.dirname(__FILE__), 'imposter', generator_name, 'templates'))
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
class ModelsConfig
|
10
|
+
|
11
|
+
def quantity_for(model_name)
|
12
|
+
@quantites["model_name"] || @default_quantity
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,135 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
require 'fileutils'
|
3
|
+
|
4
|
+
require 'generators/imposter'
|
5
|
+
|
6
|
+
module Imposter
|
7
|
+
module Generators
|
8
|
+
class GenModelsGenerator < ::Rails::Generators::Base
|
9
|
+
|
10
|
+
extend TemplatePath
|
11
|
+
|
12
|
+
dbc = YAML.load(File.read('config/database.yml'))
|
13
|
+
conn = ActiveRecord::Base.establish_connection(dbc["development"])
|
14
|
+
|
15
|
+
# Public models automatically executed
|
16
|
+
def genmodels
|
17
|
+
models_dir = Dir.glob(Rails.root.join('app', 'models').to_s + "/*.rb")
|
18
|
+
empty_directory 'test/imposter' # in case it doesn't exist yet
|
19
|
+
read_config_file
|
20
|
+
|
21
|
+
models_dir.each do |model_dir|
|
22
|
+
genmodel(model_dir)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
protected
|
27
|
+
|
28
|
+
def read_config_file
|
29
|
+
@models_config = YAML.load(
|
30
|
+
File.open(
|
31
|
+
Rails.root.join('test', 'imposter', 'config', 'models.yml')))
|
32
|
+
@models_config["default_quantity"] ||= 10
|
33
|
+
end
|
34
|
+
|
35
|
+
def quantity_for(model_name)
|
36
|
+
model_name = model_name.camelcase
|
37
|
+
if @models_config["quantities"] && @models_config["quantities"][model_name]
|
38
|
+
@models_config["quantities"][model_name]
|
39
|
+
else
|
40
|
+
@models_config["default_quantity"]
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def foreign_key_id(fkey_id)
|
45
|
+
model_name = fkey_id.sub("_id","")
|
46
|
+
"(rand(#{quantity_for(model_name)}) + 1).to_s"
|
47
|
+
end
|
48
|
+
|
49
|
+
def limited_choices_for(col_name)
|
50
|
+
if @models_config["choices"] && @models_config["choices"][col_name]
|
51
|
+
"#{@models_config["choices"][col_name]}.rand"
|
52
|
+
else
|
53
|
+
nil
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def genmodel(model_name)
|
58
|
+
mn = Pathname.new(model_name).basename.to_s.chomp(File.extname(model_name))
|
59
|
+
require model_name
|
60
|
+
return false unless eval(mn.camelcase).is_a? Class
|
61
|
+
|
62
|
+
yaml_file = Rails.root.join('test', 'imposter').to_s + "/%03d" % eval(mn.camelcase).reflections.count + "-" + mn + ".yml"
|
63
|
+
if (not File.exists? yaml_file) || options[:collision] == :force
|
64
|
+
puts " ** YAML file is #{yaml_file}"
|
65
|
+
mh = Hash.new
|
66
|
+
ma = Hash.new
|
67
|
+
mf = Hash.new
|
68
|
+
eval(mn.camelcase).columns.each do |mod|
|
69
|
+
if mod.name.include? "_id" then
|
70
|
+
mh = { mod.name => foreign_key_id(mod.name) }
|
71
|
+
ma.merge!(mh)
|
72
|
+
else
|
73
|
+
case mod.type.to_s.downcase
|
74
|
+
when 'string'
|
75
|
+
unless vl = limited_choices_for(mod.name)
|
76
|
+
if mod.name =~ /phone/
|
77
|
+
vl = 'Imposter::Phone.number("###-###-####")'
|
78
|
+
elsif mod.name =~ /url/
|
79
|
+
vl = 'Imposter.urlify()'
|
80
|
+
elsif mod.name =~ /email/
|
81
|
+
vl = 'Imposter.email_address()'
|
82
|
+
else
|
83
|
+
case (1 + rand(3))
|
84
|
+
when 1
|
85
|
+
vl = 'Imposter::Noun.multiple'
|
86
|
+
when 2
|
87
|
+
vl = 'Imposter::Animal.one'
|
88
|
+
when 3
|
89
|
+
vl = 'Imposter::Vegetable.multiple'
|
90
|
+
when 4
|
91
|
+
vl = 'Imposter::Mineral.one'
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
when 'text' then
|
96
|
+
vl = 'Faker::Lorem.sentence(3)'
|
97
|
+
when 'integer' then
|
98
|
+
vl = 'i.to_s'
|
99
|
+
when 'datetime'
|
100
|
+
vl = 'Date.today.to_s'
|
101
|
+
when 'date'
|
102
|
+
vl = 'Date.today.to_s'
|
103
|
+
when 'decimal' then
|
104
|
+
vl = 'rand(50).to_s + "." + (1000+rand(2000)).to_s'
|
105
|
+
else
|
106
|
+
puts " ** unable to imposter " + mod.type.to_s.downcase
|
107
|
+
end
|
108
|
+
if not mod.name.include? "_at" and :include_special
|
109
|
+
mh = {mod.name => vl}
|
110
|
+
ma.merge!(mh)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
mf.merge!(mn => {"fields" => ma})
|
115
|
+
puts " !! quantity_for(#{mn}): #{quantity_for(mn)}"
|
116
|
+
mf[mn].merge!({"quantity" => quantity_for(mn)})
|
117
|
+
File.open(yaml_file,"w") do |out|
|
118
|
+
YAML.dump(mf,out)
|
119
|
+
end
|
120
|
+
else
|
121
|
+
puts " ** " + mn + " --skipped"
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
def banner
|
126
|
+
"Usage: #{$0} #{spec.name} [options]"
|
127
|
+
end
|
128
|
+
|
129
|
+
def add_options!(opt)
|
130
|
+
opt.on('-f', '--force') { |value| options[:force] = value }
|
131
|
+
end
|
132
|
+
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'generators/imposter'
|
2
|
+
|
3
|
+
module Imposter
|
4
|
+
module Generators
|
5
|
+
class InstallGenerator < ::Rails::Generators::Base
|
6
|
+
|
7
|
+
extend TemplatePath
|
8
|
+
|
9
|
+
def create_test_imposter_directories
|
10
|
+
empty_directory 'test/imposter'
|
11
|
+
empty_directory 'test/imposter/config'
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
def copy_rake_file
|
16
|
+
copy_file "databases.rake", "lib/tasks/databases.rake"
|
17
|
+
end
|
18
|
+
|
19
|
+
def copy_rake_file
|
20
|
+
copy_file "models.yml", "test/imposter/config/models.yml"
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
---
|
2
|
+
default_quantity: 10
|
3
|
+
choices:
|
4
|
+
distribution: normal
|
5
|
+
skip:
|
6
|
+
quantities:
|
7
|
+
|
8
|
+
# Example for blog with User, Post, Comment, Tag, and Feed, models:
|
9
|
+
# Tag has a taggable_id and taggable_type for polymorphic association with
|
10
|
+
# User and Post. Therefore, taggable_type will be a random choice of
|
11
|
+
# 'User' or 'Post.
|
12
|
+
# Distribution will be logarithmic: lower foreign key ids will be used
|
13
|
+
# more frequently. (TODO)
|
14
|
+
# Feed models will not be impostered. (TODO)
|
15
|
+
# More than 100 Post Comment and Tag models will be impostered, and the
|
16
|
+
# foreign keys that refer to these models will span the range from 1
|
17
|
+
# to the upper limit.
|
18
|
+
# Even though Taggable is not a model class, the generator will look for
|
19
|
+
# a quantity when it encounters the taggable_id column.
|
20
|
+
#
|
21
|
+
# ---
|
22
|
+
# default_quantity: 100
|
23
|
+
# choices:
|
24
|
+
# taggable_type:
|
25
|
+
# - User
|
26
|
+
# - Post
|
27
|
+
# distribution: log
|
28
|
+
# skip:
|
29
|
+
# - Feed
|
30
|
+
# quantities:
|
31
|
+
# Post: 1000
|
32
|
+
# Comment: 2000
|
33
|
+
# Tag: 10000
|
34
|
+
# Taggable:100
|
data/lib/imposter.rb
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
require 'faker'
|
2
|
+
require 'pathname'
|
3
|
+
require 'active_support'
|
4
|
+
|
5
|
+
require 'imposter/noun'
|
6
|
+
require 'imposter/verb'
|
7
|
+
require 'imposter/animal'
|
8
|
+
require 'imposter/vegetable'
|
9
|
+
require 'imposter/mineral'
|
10
|
+
require 'imposter/csz'
|
11
|
+
require 'imposter/phone'
|
12
|
+
|
13
|
+
|
14
|
+
require "csv"
|
15
|
+
if CSV.const_defined? :Reader
|
16
|
+
# Ruby 1.8 compatible
|
17
|
+
require 'fastercsv'
|
18
|
+
Object.send(:remove_const, :CSV)
|
19
|
+
CSV = FasterCSV
|
20
|
+
else
|
21
|
+
# CSV is now FasterCSV in ruby 1.9
|
22
|
+
end
|
23
|
+
|
24
|
+
module Imposter
|
25
|
+
def self.gencsv(filename,cnt,fields,values)
|
26
|
+
vl = values
|
27
|
+
l = Array.new
|
28
|
+
m = Array.new(cnt,0)
|
29
|
+
CSV.open(filename,"w") do |csv|
|
30
|
+
csv << fields
|
31
|
+
begin
|
32
|
+
(1..cnt).each do |i|
|
33
|
+
vl.each do |v|
|
34
|
+
begin
|
35
|
+
l << eval(v)
|
36
|
+
rescue
|
37
|
+
puts "Error evaluating " + v.to_s + " in " + filename
|
38
|
+
end
|
39
|
+
end
|
40
|
+
m[i,0] = l
|
41
|
+
csv << l
|
42
|
+
l.clear
|
43
|
+
end
|
44
|
+
rescue
|
45
|
+
puts "Some format/data error in " + filename
|
46
|
+
end
|
47
|
+
end
|
48
|
+
return m
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.getfixtures
|
52
|
+
fixtures_dir = Dir.glob("test/fixtures/*.csv")
|
53
|
+
#Loading existing CSV structures
|
54
|
+
if not fixtures_dir.empty? then
|
55
|
+
fixtures_dir.each do |fixture_csv|
|
56
|
+
fn = Pathname.new(fixture_csv).basename.to_s.chomp(File.extname(fixture_csv))
|
57
|
+
eval("@" + fn + "= CSV.open(fixture_csv,'r').to_a rescue nil")
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def self.parseyaml(yamlfilename)
|
63
|
+
imp_yaml = YAML.load(File.read(yamlfilename))
|
64
|
+
mn = imp_yaml.first[0]
|
65
|
+
imp_values = imp_yaml[mn]["fields"].values
|
66
|
+
imp_fields = imp_yaml[mn]["fields"].keys
|
67
|
+
imp_qty = imp_yaml[mn]["quantity"]
|
68
|
+
rl = gencsv("test/fixtures/" + mn.pluralize + ".csv",imp_qty,imp_fields, imp_values)
|
69
|
+
eval("@" + mn.pluralize + "= rl")
|
70
|
+
yml_fixture_filename = "test/fixtures/#{mn.pluralize}.yml"
|
71
|
+
if File.exists?(yml_fixture_filename)
|
72
|
+
puts " ** Deleting YAML fixture file #{yml_fixture_filename}"
|
73
|
+
File.delete(yml_fixture_filename)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def self.genimposters
|
78
|
+
models_dir = Dir.glob(Rails.root.join('test', 'imposter').to_s + "/*.yml")
|
79
|
+
models_dir.each do |imposter_yaml|
|
80
|
+
getfixtures #reloading each time to get model level data
|
81
|
+
parseyaml(imposter_yaml)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def announce(message)
|
86
|
+
text = "#{@version} #{name}: #{message}"
|
87
|
+
length = [0, 75 - text.length].max
|
88
|
+
write "== %s %s" % [text, "=" * length]
|
89
|
+
end
|
90
|
+
|
91
|
+
def self.urlify
|
92
|
+
('http://www.' + Faker::Internet.domain_name).to_s.downcase
|
93
|
+
end
|
94
|
+
|
95
|
+
def self.email_address
|
96
|
+
Faker::Internet.email()
|
97
|
+
end
|
98
|
+
|
99
|
+
def self.numerify(number_string)
|
100
|
+
number_string.gsub(/#/) { rand(10).to_s }
|
101
|
+
end
|
102
|
+
|
103
|
+
def self.letterify(letter_string)
|
104
|
+
letter_string.gsub(/\?/) { ('a'..'z').to_a.rand }
|
105
|
+
end
|
106
|
+
|
107
|
+
def self.pattern(string)
|
108
|
+
self.letterify(self.numerify(string))
|
109
|
+
end
|
110
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Imposter
|
2
|
+
# Based on Faker::Lorem
|
3
|
+
class Animal
|
4
|
+
Animals = %w(aardvark anteater argali badger beaver budgerigar burro cat chimpanzee coati cow deer donkey dugong ermine finch gazelle gnu grizzly bear hamster hippopotamus ibex jaguar kinkajou lamb lizard mandrill mink moose musk deer mynah bird opossum ox parrot polar bear prairie dog quagga rat roebuck shrew snake steer turtle waterbuck wolf yak addax antelope armadillo basilisk bighorn buffalo camel chameleon chinchilla colt coyote dingo dormouse eland ewe fish gemsbok goat ground hog hare hog iguana jerboa kitten lemur llama mare mole mountain goat musk-ox newt orangutan panda peccary pony pronghorn rabbit reindeer salamander silver fox springbok tapir vicuna weasel wolverine zebra alligator aoudad ass bat bison bull canary chamois chipmunk cony crocodile doe dromedary elephant fawn fox gila monster gopher guanaco hartebeest horse impala kangaroo koala leopard lovebird marmoset mongoose mouse muskrat ocelot oryx panther pig porcupine puma raccoon reptile seal skunk squirrel tiger walrus whale wombat zebu alpaca ape baboon bear boar bunny capybara cheetah civet cougar crow dog duckbill elk ferret frog giraffe gorilla guinea pig hedgehog hyena jackal kid koodoo lion lynx marten monkey mule mustang okapi otter parakeet platypus porpoise puppy ram rhinoceros sheep sloth stallion toad warthog wildcat woodchuck)
|
5
|
+
|
6
|
+
def self.one
|
7
|
+
Animals.rand
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.multiple(word_count = 2)
|
11
|
+
Animals.shuffle[0, word_count].join(" ").capitalize
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
data/lib/imposter/csz.db
ADDED
Binary file
|
data/lib/imposter/csz.rb
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'sqlite3'
|
3
|
+
require 'active_support'
|
4
|
+
|
5
|
+
$db_file = File.join(File.dirname(__FILE__), "csz.db")
|
6
|
+
$csz_db =SQLite3::Database.new($db_file)
|
7
|
+
$csz_db.results_as_hash = true
|
8
|
+
$total_rows = $csz_db.execute2("select count(*) from us")
|
9
|
+
|
10
|
+
|
11
|
+
module Imposter
|
12
|
+
class CSZ
|
13
|
+
class << self
|
14
|
+
|
15
|
+
def get_rand
|
16
|
+
rand_row = (1+rand($total_rows[1][0].to_i - 1)).to_s
|
17
|
+
@@csz_get = $csz_db.execute2("select city,state,statefull,zip5 from us limit " + rand_row + ",1")[1]
|
18
|
+
end
|
19
|
+
|
20
|
+
def get_rand_state(st=nil)
|
21
|
+
rand_row = (1 + rand($csz_db.execute2("select count(*) from us where upper(state)='"+ st.upcase + "'")[1][0].to_i - 1)).to_s
|
22
|
+
@@csz_get = $csz_db.execute2("select city,state,statefull,zip5 from us where state='" + st.upcase + "' limit " + rand_row + ",1")[1]
|
23
|
+
end
|
24
|
+
|
25
|
+
def get_rand_city(cty = nil)
|
26
|
+
rand_row = (1 + rand($csz_db.execute2("select count(*) from us where upper(city)='"+ cty.upcase + "'")[1][0].to_i - 1)).to_s
|
27
|
+
@@csz_get = $csz_db.execute2("select city,state,statefull,zip5 from us where upper(city)='" + cty.upcase + "' limit " + rand_row + ",1")[1]
|
28
|
+
end
|
29
|
+
|
30
|
+
def zip5
|
31
|
+
@@csz_get['zip5']
|
32
|
+
end
|
33
|
+
def state(zip5=nil)
|
34
|
+
@@csz_get['state']
|
35
|
+
end
|
36
|
+
|
37
|
+
def city(zip5=nil)
|
38
|
+
@@csz_get['city']
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
class Street
|
43
|
+
class << self
|
44
|
+
Names = %w(1st First 2nd 3rd Third 4th Fourth 5th Fifth 6th Sixth 7th Seventh 8th Eighth 9th Nineth 10th Tenth Maple Kennedy Central Elm Washngton State Country Acres Douglas Laurel Jefferson Wall Street Main Roosevelt Walnut Tyler Hickory Market Broadway Forest Park Birch Spruce Taylor Beech Oak Sycamore Wood Grant Lincoln Taft Poplar)
|
45
|
+
Types = %w(Highway Hwy Expressway Expy Freeway Fwy Motorway Mtrwy Avenue Ave Boulevard Blvd Road Rd Street St Alley Aly Bay Drive Dr Fairway Gardens Gdns Gate Grove Grv Heights Hts Highlands Knoll Knl Lane Ln Manor Mnr Mews Passage Psge Pathway Pthwy Place Pl Row Terrace Ter Trail Trl View Vw Way Close Court Ct Cove Cv Croft Garth Green Grn Lawn Nook Place Pl Circle Cir Crescent Cres Loop Oval Quadrant Square Sq Canyon Cyn Causeway Cswy Grade Hill Hl Mount Mt Parkway Pkwy Rise Vale)
|
46
|
+
Directions = %w(N. S. E. W. NE. NW. SE. SW.)
|
47
|
+
def name
|
48
|
+
Names.shuffle[0,1]
|
49
|
+
end
|
50
|
+
|
51
|
+
def type
|
52
|
+
return_type=Types.shuffle[0,1]
|
53
|
+
end
|
54
|
+
|
55
|
+
def direction
|
56
|
+
Directions.shuffle[0,1]
|
57
|
+
end
|
58
|
+
|
59
|
+
def full
|
60
|
+
st_num = (100+rand(99999))
|
61
|
+
rnd_addr = st_num.to_s+(['_']+name + ['_'] + type).to_s
|
62
|
+
if (1+rand(5))<2 then
|
63
|
+
rnd_addr += (['_']+direction).to_s.upcase
|
64
|
+
end
|
65
|
+
return rnd_addr.titleize
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Imposter
|
2
|
+
# Based on Faker::Lorem
|
3
|
+
class Mineral
|
4
|
+
Minerals = %w(Abelsonite Abenakiite Abernathyite Abhurite Abswurmbachite Actinolite Acuminite Adamite Adamsite Adelite Admontite Aegirine Aenigmatite Aerinite Aerugite Aeschynite Aeschynite Aeschynite Aetites Afghanite Afwillite Agardite Agrellite Agrinierite Aguilarite Aheylite Ahlfeldite Aikinite Ajoite Akatoreite Akdalaite Aksaite Alabandite Alamosite Alarsite Albite Alforsite Algodonite Aliettite Allabogdanite Allanite Alloclasite Allophane Almandine Alstonite Altaite Aluminite Aluminium Alunite Alunogen Amblygonite Ameghinite Amphibole Analcite Anapaite Anatase Andalusite Andesine Andradite Anglesite Anhydrite Ankerite Annabergite Anorthite Anorthoclase Anthophyllite Antigorite Antimony Antitaenite Antlerite Apatite Apophyllite Aragonite Archerite Arctite Arcubisite Arfvedsonite Argentite Argutite Armalcolite Arsenic Arsenopyrite Arthurite Artinite Artroeite Asisite Astrophyllite Atacamite Atheneite Aubertite Augelite Augite Aurichalcite Auricupride Aurostibite Autunite Axinite Azurite Babingtonite Baddeleyite Baotite Barstowite Baryte Barytocalcite Bazzite Benitoite Bensonite Bentorite Berryite Berthierite Bertrandite Beryl Beryllonite Biotite Birnessite Bismite Bismuth Bismuthinite Bixbyite Blossite Boehmite Boracite Borax Bornite Botryogen Boulangerite Bournonite Brammallite Brassite Braunite Brazilianite Breithauptite Brewsterite Brianite Briartite Brochantite Brookite Bromargyrite Bromellite Bronzite Brucite Brushite Buddingtonite Buergerite Bukovskyite Bytownite Bauxite Beckerite Bixbite Cabriite Cadmium Cafetite Calaverite Calcite Cancrinite Calderite Caledonite Cancrinite Canfieldite Carnallite Carnotite Carobbiite Carrollite Cassiterite Cavansite Celadonite Celestine Celsian Cementite Cerite Cerussite Cesbronite Ceylonite Chabazite Chalcanthite Chalcocite Chalcopyrite Challacolloite Chaoite Chapmanite Charoite Childrenite Chlorargyrite Chlorastrolite Chlorite Chloritoid Chondrodite Chromite Chromium Chrysoberyl Chrysocolla Cinnabar Clarkeite Clinochrysotile Clinoclase Clinohedrite Clinohumite Clinoptilolite Clinozoisite Clintonite Cobaltite Coesite Coffinite Colemanite Coloradoite Columbite Combeite Connellite Cooperite Copiapite Copper Corderoite Cordierite Corundum Covellite Creedite Cristobalite Crocoite Cronstedtite Crookesite Crossite Cryolite Cumberlandite Cummingtonite Cuprite Cyanotrichite Cylindrite Carnelian Chalcedony Chrysolite Chrysoprase Chrysotile Citrine Cleveite Coltan Crocidolite Cymophane Danburite Datolite Davidite Dawsonite Delvauxite Descloizite Diadochite Diamond Diaspore Dickite Digenite Diopside Dioptase Djurleite Dollaseite Dolomite Domeykite Dumortierite Delessite Diatomite Edingtonite Ekanite Elbaite Elsmoreite Emery Empressite Enargite Enstatite Eosphorite Epidote Epsomite Erythrite Esperite Ettringite Euchroite Euclase Eucryptite Eudialyte Euxenite Emerald Fabianite Fayalite Feldspar Feldspathoid Ferberite Fergusonite Feroxyhyte Ferrierite Ferrihydrite Ferro Ferrocolumbite Ferrohortonolite Ferropericlase Ferrotantalite Fergusonite Fichtelite Fluorapatite Fluorcaphite Fluorichterite Fluorite Fluorspar Fornacite Forsterite Franckeite Frankhawthorneite Franklinite Freibergite Freieslebenite Fukuchilite Fassaite Ferricrete Gadolinite Gahnite Galaxite Galena Garnet Garnierite Gaylussite Gehlenite Geigerite Geocronite Germanite Gersdorffite Gibbsite Gismondine Glauberite Glaucochroite Glaucodot Glauconite Glaucophane Gmelinite Goethite Gold Goslarite Graftonite Graphite Greenockite Greigite Grossular Grunerite Guanine Gummite Gunningite Gypsum Gedanite Glessite Hematite Haggertyite Haidingerite Halite Halloysite Halotrichite Hanksite Hapkeite Hardystonite Harmotome Hauerite Hausmannite Hauyne Hawleyite Haxonite Heazlewoodite Hectorite Hedenbergite Hellyerite Hematite Hemimorphite Herbertsmithite Herderite Hessite Hessonite Heulandite Hibonite Hilgardite Hisingerite Holmquistite Homilite Hopeite Hornblende Howlite Humite Hutchinsonite Hyalophane Hydrogrossular Hydromagnesite Hydroxylapatite Hydrozincite Hypersthene Heliodor Heliotrope Hiddenite Hyalite Idocrase Idrialite Ikaite Illite Ilmenite Ilvaite Iodargyrite Jacobsite Jadarite Jadeite Jamesonite Jarosewichite Jarosite Jeffersonite Jerrygibbsite Juonniite Jurbanite Jade Jasper Jet Kaatialaite Kadyrelite Kainite Kalininite Kalinite Kalsilite Kamacite Kambaldaite Kankite Kaolinite Kassite Keilite Kermesite Kernite Kerolite Kieserite Kinoite Knebelite Knorringite Kobellite Kogarkoite Kolbeckite Kornerupine Kratochvilite Kremersite Krennerite Kukharenkoite Kutnohorite Kyanite Keilhauite Krantzite Kunzite Labradorite Lanarkite Langbeinite Lansfordite Lanthanite Laumontite Laurite Lawsonite Lazulite Lazurite Lead Leadhillite Legrandite Lepidocrocite Lepidolite Leucite Leucophanite Leucoxene Levyne Lewisite Libethenite Linarite Liroconite Litharge Lithiophilite Livingstonite Lizardite Lollingite Lonsdaleite Loparite Lopezite Lorandite Lorenzenite Ludwigite Lyonsite Lapis lazuli Larimar Lechatelierite Lignite Limonite Lodestone Lublinite Muscovite Mackinawite Maghemite Magnesite Magnesioferrite Magnetite Majorite Malachite Malacolite Magnesioferrite Manganite Manganocolumbite Manganotantalite Marcasite Margaritasite Margarite Mascagnite Massicot McKelveyite Meionite Melaconite Melanite Melilite Melonite Mendozite Meneghinite Mercury Mesolite Metacinnabarite Metatorbernite Miargyrite Mica Microcline Microlite Millerite Mimetite Minium Mirabilite Mixite Moganite Mohite Moissanite Molybdenite Monazite Monohydrocalcite Monticellite Montmorillonite Moolooite Mordenite Mottramite Mullite Murdochite Muscovite Magnesia Mariposite Menilite Meerschaum Milky quartz Morganite Nabesite Nacrite Nagyagite Nahcolite Native Natrolite Natron Natrophilite Nekrasovite Nelenite Nenadkevichite Nepheline Nephrite Neptunite Nickel Nickeline Niedermayrite Niningerite Niobite Niobite Nissonite Nitratine Nitre Nontronite Nosean Nsutite Nyerereite Oligoclase Olivine Olivenite Omphacite Ordonezite Oregonite Orpiment Orthochrysotile Orthoclase Osarizawaite Osmium Osumilite Otavite Ottrelite Overite Polished Onyx Opal Painite Palladium Palygorskite Papagoite Parachrysotile Paragonite Pararealgar Parisite Partheite Pectolite Pelagosite Pentlandite Periclase Perovskite Petalite Petzite Pezzottaite Pharmacosiderite Phenakite Phillipsite Phlogopite Phoenicochroite Phosgenite Phosphophyllite Pigeonite Plagioclase Na Platinum Polarite Pollucite Polybasite Potassium Polycrase Polydymite Polyhalite Powellite Prehnite Proustite Psilomelane Purpurite Pumpellyite Pyrargyrite Pyrite Pyrochlore Pyrolusite Pyromorphite Pyrope Pyrophyllite Pyroxene Pyroxferroite Pyrrhotite Palagonite Perlite Phosphorite Plessite Pitchblende Pumicite Quartz Quenstedtite Rambergite Rammelsbergite Realgar Renierite Rheniite Rhodium Rhodochrosite Rhodonite Rhomboclase Rickardite Riebeckite Robertsite Rosasite Roscoelite Rosenbergite Routhierite Ruthenium Rutherfordine Rutile Rynersonite Rock crystal Rose Roumanite Ruby Sabatierite Sabieite Sabinaite Safflorite Sal Saliotite Samarskite Samsonite Sanbornite Saneroite Sanidine Santite Saponite Sapphirine Sassolite Sauconite Scapolite Scheelite Schoepite Schorl Schreibersite Schwertmannite Scolecite Scorodite Scorzalite Seamanite Seeligerite Segelerite Sekaninaite Selenite Selenium Seligmannite Sellaite Senarmontite Sepiolite Serpentine Shattuckite Siderite Siderotil Siegenite Sillimanite Silver Simetite Simonellite Skutterudite Smaltite Smectite Smithsonite Soda Sodalite Sperrylite Spessartite Sphalerite Sphene Spinel Spodumene Spurrite Stannite Staurolite Steacyite Steatite Stephanite Stibnite Stichtite Stilbite Stilleite Stolzite Stromeyerite Strontianite Struvite Studtite Sugilite Sulfur Sussexite Sylvanite Sylvite Sapphire Sard Satinspar Smoky quartz Soapstone Spectrolite Stantienite Massive Turquoise Tachyhydrite Taenite Talc Tantalite Tantite Tanzanite Tarapacaite Tausonite Teallite Tellurite Tellurium Tellurobismuthite Temagamite Tennantite Tenorite Tephroite Terlinguaite Teruggite Tetradymite Tetrahedrite Thaumasite Thenardite Thomasclarkite Thomsenolite Thorianite Thorite Thortveitite Thuringite Tiemannite Tin Tincalconite Titanite Titanowodginite Todorokite Tokyoite Topaz Torbernite Tourmaline Tremolite Trevorite Tridymite Triphylite Triplite Triploidite Trona Tsavorite Tschermigite Tugtupite Tungstite Tyrolite Turquoise Tusionite Tyuyamunite Tanzanite Thulite Travertine Tsavorite Uchucchacuaite Uklonskovite Ulexite Ullmannite Ulvospinel Umangite Umber Umbite Upalite Uraninite Uranophane Uranopilite Uvarovite Ultramarine Unakite Uralite Vaesite Valentinite Vanadinite Variscite Vaterite Vauquelinite Vauxite Vermiculite Vesuvianite Villiaumite Violarite Vivianite Volborthite Wagnerite Wardite Warwickite Wavellite Weddellite Weilite Weissite Weloganite Whewellite Whitlockite Willemite Wiluite Witherite Wolframite Wollastonite Wulfenite Wurtzite Wyartite Wad Xenotime Xifengite Xonotlite Ye'elimite Yttrialite Yttrocerite Yttrocolumbite Zabuyelite Zaccagnaite Zaherite Zajacite Zakharovite Zanazziite Zaratite Zeolite Zhanghengite Zharchikhite Zektzerite Zhemchuzhnikovite Zhonghuacerite Ziesite Zimbabweite Zinalsite Zinc Zincite Zincobotryogen Zincochromite Zinkenite Zinnwaldite Zippeite Zircon Zirconolite Zircophyllite Zirkelite Zoisite Zunyite)
|
5
|
+
|
6
|
+
def self.one(num = 1)
|
7
|
+
Minerals.rand
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.multiple(word_count = 2)
|
11
|
+
Minerals.shuffle[0, word_count].join(" ").capitalize
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Imposter
|
2
|
+
# Based on Faker::Lorem
|
3
|
+
|
4
|
+
class Noun
|
5
|
+
Nouns = %w(alarm animal aunt bait balloon bath bead beam bean bedroom boot bread brick brother camp chicken children crook deer dock doctor downtown drum dust eye family father fight flesh food frog goose grade grandfather grandmother grape grass hook horse jail jam kiss kitten light loaf lock lunch lunchroom meal mother notebook owl pail parent park plot rabbit rake robin sack sail scale sea sister soap song spark space spoon spot spy summer tiger toad town trail tramp tray trick trip uncle vase winter water week wheel wish wool yard zebra)
|
6
|
+
|
7
|
+
def self.one
|
8
|
+
Nouns.rand
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.multiple(word_count = 2)
|
12
|
+
Nouns.shuffle[0, word_count].join(" ").capitalize
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'imposter'
|
3
|
+
|
4
|
+
module Imposter
|
5
|
+
|
6
|
+
class Phone
|
7
|
+
def self.number(format=false)
|
8
|
+
format ||= Formats.rand
|
9
|
+
Imposter.numerify(format)
|
10
|
+
end
|
11
|
+
|
12
|
+
Formats = [
|
13
|
+
'###-###-####',
|
14
|
+
'(###)###-####',
|
15
|
+
'1-###-###-####',
|
16
|
+
'###.###.####',
|
17
|
+
'###-###-####',
|
18
|
+
'(###)###-####',
|
19
|
+
'1-###-###-####',
|
20
|
+
'###.###.####',
|
21
|
+
'###-###-#### x###',
|
22
|
+
'(###)###-#### x###',
|
23
|
+
'1-###-###-#### x###',
|
24
|
+
'###.###.#### x###',
|
25
|
+
'###-###-#### x####',
|
26
|
+
'(###)###-#### x####',
|
27
|
+
'1-###-###-#### x####',
|
28
|
+
'###.###.#### x####',
|
29
|
+
'###-###-#### x#####',
|
30
|
+
'(###)###-#### x#####',
|
31
|
+
'1-###-###-#### x#####',
|
32
|
+
'###.###.#### x#####'
|
33
|
+
]
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Imposter
|
2
|
+
# Based on Faker::Lorem
|
3
|
+
class Vegetable
|
4
|
+
Vegetables = %w(Achoccha Amaranth Angelica Anise Arrowroot Arrugula Artichoke Asparagus Apple Balsam\sPear Bambara Bamboo Beans Beet Bok Choy Boniato Broccoli Brussels sprouts Burdock Cabbage Chinese Cabbage Kale Swamp Cabbage Calabaza Cantaloupes Capers Cardoon Carrot Cassava Celeriac Celery Celtuce Chard Chaya Chayote Chicory Chives Chrysanthemum Chufa Cilantro Citron Collards Comfrey Corn salad Corn Cuban Sweet Potato Cucmber Cushcush Daikon Dandelion Dasheen Dill Eggplant Endive Fennel Galia Muskmelon Garbanzo Garlic Gherkin Ginger Ginseng Gourds Guar Hanover Salad Horseradish Horseradish tree Huckleberry Ice Plant Jicama Jojoba Kale Kangkong Kohlrabi Leek Lentils Lettuce Lovage Luffa Gourd Malanga Martynia Casaba Melon Honeydew Melon Momordica Mushroom Cantaloupe Mustard collard Mustard potherb Naranjillo Nasturtium Okra Onion Orach Paprika Parsley Parsley root Parsnip Peas Peanut Pepper Pimiento Pokeweed Potato Sweet potato Pumpkin Purslane Radicchio Radish Radish Chinese Rakkyo Rampion Rape and Canola Rhubarb Romaine Lettuce Roselle Rutabaga Saffron Salsify Sarsaparilla Sassafrass Scorzonera Sea kale Shallot Skirret Smallage Sorrel garden Southern pea Soybeans Spinach Spinach Squash Strawberries Swamp Cabbage Sweet Basil Sweet Corn Sweet potato Swiss Chard Tomatillo Tomato Tomato husk Tomato tree Truffles Upland cress Water celery Waterchestnut Watercress Watermelon Yams)
|
5
|
+
|
6
|
+
def self.one(num = 1)
|
7
|
+
Vegetables.rand
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.multiple(word_count = 2)
|
11
|
+
Vegetables.shuffle[0, word_count].join(" ").capitalize
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.at(num=0)
|
15
|
+
Vegetables[num]
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Imposter
|
2
|
+
# Based on Faker::Lorem
|
3
|
+
class Verb
|
4
|
+
Verbs = %w(add address administer admire admit adopt advise afford agree alert alight allow altered amuse analyze announce annoy answer anticipate apologize appear applaud applied appoint appraise appreciate approve arbitrate argue arise arrange arrest arrive ascertain ask assemble assess assist assure attach attack attain attempt attend attract audited avoid awake back bake balance ban bang bare bat bathe battle be beam bear beat become beg begin behave behold belong bend beset bet bid bind bite bleach bleed bless blind blink blot blow blush boast boil bolt bomb book bore borrow bounce bow box brake branch break breathe breed brief bring broadcast bruise brush bubble budget build bump burn burst bury bust buy buzz calculate call camp care carry carve cast catalog catch cause challenge change charge chart chase cheat check cheer chew choke choose chop claim clap clarify classify clean clear cling clip close clothe coach coil collect color comb come command communicate compare compete compile complain complete compose compute conceive concentrate conceptualize concern conclude conduct confess confront confuse connect conserve consider consist consolidate construct consult contain continue contract control convert coordinate copy correct correlate cost cough counsel count cover crack crash crawl create creep critique cross crush cry cure curl curve cut cycle dam damage dance dare deal decay deceive decide decorate define delay delegate delight deliver demonstrate depend describe desert deserve design destroy detail detect determine develop devise diagnose dig direct disagree disappear disapprove disarm discover dislike dispense display disprove dissect distribute dive divert divide do double doubt draft drag drain dramatize draw dream dress drink drip drive drop drown drum dry dust dwell earn eat edited educate eliminate embarrass employ empty enacted encourage end endure enforce engineer enhance enjoy enlist ensure enter entertain escape establish estimate evaluate examine exceed excite excuse execute exercise exhibit exist expand expect expedite experiment explain explode express extend extract face facilitate fade fail fancy fasten fax fear feed feel fence fetch fight file fill film finalize finance find fire fit fix flap flash flee fling float flood flow flower fly fold follow fool forbid force forecast forego foresee foretell forget forgive form formulate forsake frame freeze frighten fry gather gaze generate get give glow glue go govern grab graduate grate grease greet grin grind grip groan grow guarantee guard guess guide hammer hand handle handwrite hang happen harass harm hate haunt head heal heap hear heat help hide hit hold hook hop hope hover hug hum hunt hurry hurt hypothesize)
|
5
|
+
|
6
|
+
def self.one(num = 1)
|
7
|
+
Verbs.rand
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.multiple(word_count = 2)
|
11
|
+
Verbs.shuffle[0, word_count].join(" ").capitalize
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestImposter < Test::Unit::TestCase
|
4
|
+
|
5
|
+
context "gen_models generator" do
|
6
|
+
|
7
|
+
context "setup"
|
8
|
+
|
9
|
+
# setup do
|
10
|
+
# @user = User.find(:first)
|
11
|
+
# end
|
12
|
+
|
13
|
+
should "read a YAML config file and set instance variables accordingly"
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
should "produce a legal URL on request" do
|
20
|
+
assert_match(%r{http://.+\.\w+}, Imposter.urlify())
|
21
|
+
end
|
22
|
+
|
23
|
+
should "allow user to specify URL's protocol, subdomain, TLD, port number, path, params, etc"
|
24
|
+
|
25
|
+
should "provide a single, scalar word from nouns collection" do
|
26
|
+
assert_equal "String", Imposter::Noun.one.class.name
|
27
|
+
end
|
28
|
+
|
29
|
+
should "provide a single, scalar word from animals collection" do
|
30
|
+
assert_equal "String", Imposter::Animal.one.class.name
|
31
|
+
end
|
32
|
+
|
33
|
+
should "provide a single, scalar word from minerals collection" do
|
34
|
+
assert_equal "String", Imposter::Mineral.one.class.name
|
35
|
+
end
|
36
|
+
|
37
|
+
should "provide a single, scalar word from vegetables collection" do
|
38
|
+
assert_equal "String", Imposter::Vegetable.one.class.name
|
39
|
+
end
|
40
|
+
|
41
|
+
should "provide a single, scalar word from verbs collection" do
|
42
|
+
assert_equal "String", Imposter::Verb.one.class.name
|
43
|
+
end
|
44
|
+
|
45
|
+
should "provide multiple words from nouns collection" do
|
46
|
+
assert_equal "String", Imposter::Noun.multiple(4).class.name
|
47
|
+
end
|
48
|
+
|
49
|
+
should "provide multiple words from animals collection" do
|
50
|
+
assert_equal "String", Imposter::Animal.multiple(4).class.name
|
51
|
+
end
|
52
|
+
|
53
|
+
should "provide multiple words from minerals collection" do
|
54
|
+
assert_equal "String", Imposter::Mineral.multiple(4).class.name
|
55
|
+
end
|
56
|
+
|
57
|
+
should "provide multiple words from vegetables collection" do
|
58
|
+
assert_equal "String", Imposter::Vegetable.multiple(4).class.name
|
59
|
+
end
|
60
|
+
|
61
|
+
should "provide multiple words from verbs collection" do
|
62
|
+
assert_equal "String", Imposter::Verb.multiple(4).class.name
|
63
|
+
end
|
64
|
+
|
65
|
+
should "create simulated email addresses" do
|
66
|
+
assert_match(%r{\S+@\S+\.\S+}, Imposter.email_address())
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{urlsplease-imposter}
|
8
|
+
s.version = "0.2.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Robert Hall", "Michael Harrison"]
|
12
|
+
s.date = %q{2010-08-06}
|
13
|
+
s.description = %q{Temporary fork of Robert Hall's imposter gem with Ruby 1.9 and Rails 3 support. Provides generators and rake tasks via YAML based imposters for schema level data faking}
|
14
|
+
s.email = %q{mh@michaelharrison.ws}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".gitignore",
|
22
|
+
"LICENSE",
|
23
|
+
"README.rdoc",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"generators/imposter_generator.rb",
|
27
|
+
"generators/templates/databases.rake",
|
28
|
+
"id_rsa.pub",
|
29
|
+
"lib/generators/imposter.rb",
|
30
|
+
"lib/generators/imposter/gen_models/gen_models_generator.rb",
|
31
|
+
"lib/generators/imposter/install/install_generator.rb",
|
32
|
+
"lib/generators/imposter/install/templates/databases.rake",
|
33
|
+
"lib/generators/imposter/install/templates/models.yml",
|
34
|
+
"lib/imposter.rb",
|
35
|
+
"lib/imposter/animal.rb",
|
36
|
+
"lib/imposter/csz.db",
|
37
|
+
"lib/imposter/csz.rb",
|
38
|
+
"lib/imposter/mineral.rb",
|
39
|
+
"lib/imposter/noun.rb",
|
40
|
+
"lib/imposter/phone.rb",
|
41
|
+
"lib/imposter/vegetable.rb",
|
42
|
+
"lib/imposter/verb.rb",
|
43
|
+
"lib/imposter/version.rb",
|
44
|
+
"test/helper.rb",
|
45
|
+
"test/test_imposter.rb",
|
46
|
+
"urlsplease-imposter.gemspec"
|
47
|
+
]
|
48
|
+
s.homepage = %q{http://github.com/urlsplease/imposter}
|
49
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
50
|
+
s.require_paths = ["lib"]
|
51
|
+
s.rubygems_version = %q{1.3.7}
|
52
|
+
s.summary = %q{(Ruby 1.9 and Rails 3 ready) Real fake data}
|
53
|
+
s.test_files = [
|
54
|
+
"test/helper.rb",
|
55
|
+
"test/test_imposter.rb"
|
56
|
+
]
|
57
|
+
|
58
|
+
if s.respond_to? :specification_version then
|
59
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
60
|
+
s.specification_version = 3
|
61
|
+
|
62
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
63
|
+
s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
64
|
+
s.add_runtime_dependency(%q<sqlite3-ruby>, [">= 1.2.5"])
|
65
|
+
s.add_runtime_dependency(%q<faker>, [">= 0"])
|
66
|
+
s.add_runtime_dependency(%q<fastercsv>, [">= 0"])
|
67
|
+
s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
68
|
+
else
|
69
|
+
s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
70
|
+
s.add_dependency(%q<sqlite3-ruby>, [">= 1.2.5"])
|
71
|
+
s.add_dependency(%q<faker>, [">= 0"])
|
72
|
+
s.add_dependency(%q<fastercsv>, [">= 0"])
|
73
|
+
s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
74
|
+
end
|
75
|
+
else
|
76
|
+
s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
77
|
+
s.add_dependency(%q<sqlite3-ruby>, [">= 1.2.5"])
|
78
|
+
s.add_dependency(%q<faker>, [">= 0"])
|
79
|
+
s.add_dependency(%q<fastercsv>, [">= 0"])
|
80
|
+
s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
metadata
ADDED
@@ -0,0 +1,159 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: urlsplease-imposter
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 2
|
8
|
+
- 0
|
9
|
+
version: 0.2.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Robert Hall
|
13
|
+
- Michael Harrison
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-08-06 00:00:00 -04:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: thoughtbot-shoulda
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
segments:
|
30
|
+
- 0
|
31
|
+
version: "0"
|
32
|
+
type: :development
|
33
|
+
version_requirements: *id001
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: sqlite3-ruby
|
36
|
+
prerelease: false
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
+
none: false
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
segments:
|
43
|
+
- 1
|
44
|
+
- 2
|
45
|
+
- 5
|
46
|
+
version: 1.2.5
|
47
|
+
type: :runtime
|
48
|
+
version_requirements: *id002
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: faker
|
51
|
+
prerelease: false
|
52
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
segments:
|
58
|
+
- 0
|
59
|
+
version: "0"
|
60
|
+
type: :runtime
|
61
|
+
version_requirements: *id003
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: fastercsv
|
64
|
+
prerelease: false
|
65
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
segments:
|
71
|
+
- 0
|
72
|
+
version: "0"
|
73
|
+
type: :runtime
|
74
|
+
version_requirements: *id004
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: thoughtbot-shoulda
|
77
|
+
prerelease: false
|
78
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
79
|
+
none: false
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
segments:
|
84
|
+
- 0
|
85
|
+
version: "0"
|
86
|
+
type: :development
|
87
|
+
version_requirements: *id005
|
88
|
+
description: Temporary fork of Robert Hall's imposter gem with Ruby 1.9 and Rails 3 support. Provides generators and rake tasks via YAML based imposters for schema level data faking
|
89
|
+
email: mh@michaelharrison.ws
|
90
|
+
executables: []
|
91
|
+
|
92
|
+
extensions: []
|
93
|
+
|
94
|
+
extra_rdoc_files:
|
95
|
+
- LICENSE
|
96
|
+
- README.rdoc
|
97
|
+
files:
|
98
|
+
- .document
|
99
|
+
- .gitignore
|
100
|
+
- LICENSE
|
101
|
+
- README.rdoc
|
102
|
+
- Rakefile
|
103
|
+
- VERSION
|
104
|
+
- generators/imposter_generator.rb
|
105
|
+
- generators/templates/databases.rake
|
106
|
+
- id_rsa.pub
|
107
|
+
- lib/generators/imposter.rb
|
108
|
+
- lib/generators/imposter/gen_models/gen_models_generator.rb
|
109
|
+
- lib/generators/imposter/install/install_generator.rb
|
110
|
+
- lib/generators/imposter/install/templates/databases.rake
|
111
|
+
- lib/generators/imposter/install/templates/models.yml
|
112
|
+
- lib/imposter.rb
|
113
|
+
- lib/imposter/animal.rb
|
114
|
+
- lib/imposter/csz.db
|
115
|
+
- lib/imposter/csz.rb
|
116
|
+
- lib/imposter/mineral.rb
|
117
|
+
- lib/imposter/noun.rb
|
118
|
+
- lib/imposter/phone.rb
|
119
|
+
- lib/imposter/vegetable.rb
|
120
|
+
- lib/imposter/verb.rb
|
121
|
+
- lib/imposter/version.rb
|
122
|
+
- test/helper.rb
|
123
|
+
- test/test_imposter.rb
|
124
|
+
- urlsplease-imposter.gemspec
|
125
|
+
has_rdoc: true
|
126
|
+
homepage: http://github.com/urlsplease/imposter
|
127
|
+
licenses: []
|
128
|
+
|
129
|
+
post_install_message:
|
130
|
+
rdoc_options:
|
131
|
+
- --charset=UTF-8
|
132
|
+
require_paths:
|
133
|
+
- lib
|
134
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
135
|
+
none: false
|
136
|
+
requirements:
|
137
|
+
- - ">="
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
segments:
|
140
|
+
- 0
|
141
|
+
version: "0"
|
142
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
143
|
+
none: false
|
144
|
+
requirements:
|
145
|
+
- - ">="
|
146
|
+
- !ruby/object:Gem::Version
|
147
|
+
segments:
|
148
|
+
- 0
|
149
|
+
version: "0"
|
150
|
+
requirements: []
|
151
|
+
|
152
|
+
rubyforge_project:
|
153
|
+
rubygems_version: 1.3.7
|
154
|
+
signing_key:
|
155
|
+
specification_version: 3
|
156
|
+
summary: (Ruby 1.9 and Rails 3 ready) Real fake data
|
157
|
+
test_files:
|
158
|
+
- test/helper.rb
|
159
|
+
- test/test_imposter.rb
|