dummy_urls 0.9
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/CHANGELOG.md +4 -0
- data/LICENSE +20 -0
- data/README.md +52 -0
- data/lib/dummy_urls.rb +10 -0
- data/lib/generators/urls/templates/model.yml +25 -0
- data/lib/generators/urls/urls_generator.rb +130 -0
- metadata +114 -0
data/CHANGELOG.md
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2010 Gonçalo Silva
|
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.md
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
# Dummy routes
|
2
|
+
|
3
|
+
"Dummy urls" uses [dummy](http://github.com/goncalossilva/dummy) to generate test urls for your Rails 3 application.
|
4
|
+
|
5
|
+
## Description
|
6
|
+
|
7
|
+
"Dummy urls" generates GET, POST, PUT and DELETE test urls for your Rails 3 application. It depends on [dummy\_data](http://github.com/goncalossilva/dummy_data) since it expects you to generate your test data with it (you can change it later). It also uses [dummy](http://github.com/goncalossilva/dummy) to generate the needed data for POST and PUT requests. Check dummy's description for a better understanding of what it does.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
$ gem install dummy_urls
|
12
|
+
|
13
|
+
## Usage
|
14
|
+
|
15
|
+
Add the following to the Gemfile of your Rails 3 application:
|
16
|
+
gem "dummy_urls"
|
17
|
+
|
18
|
+
Now you have access to the generator:
|
19
|
+
rails generate dummy:urls
|
20
|
+
|
21
|
+
You can change the divisor in use (what these mean exactly is explained latter on):
|
22
|
+
rails generate dummy:urls --divisor=3
|
23
|
+
|
24
|
+
Also, you can manually define the amount of urls to generate for each model (or just accept the defaults):
|
25
|
+
rails generate dummy:urls --manual-amounts
|
26
|
+
|
27
|
+
And you can manually set the output folder of the dummy data (which defaults to test/dummy):
|
28
|
+
rails generate dummy:urls --output-folder test/awesome_fixtures
|
29
|
+
|
30
|
+
The files will be placed under _output-folder_/urls.
|
31
|
+
|
32
|
+
Feel free to mix all of these options.
|
33
|
+
|
34
|
+
## More information
|
35
|
+
|
36
|
+
### URLs with smart data
|
37
|
+
|
38
|
+
"Dummy urls" tells dummy to try to understand your database columns and generate data accordingly, instead of dumping "Lorem ipsum" all over the place.
|
39
|
+
|
40
|
+
For instance, if you have a field called _company\_name_, it will generate a company name. If you have a field called _awesome\_postal\_code_, it will generate a valid ZIP Code. If you have a field called _longitude_, it will generate a valid longitude, and so on. You get the picture.
|
41
|
+
|
42
|
+
Dummy cares about associations. It will create random associations between the automatically generated records, so you don't have to worry about that.
|
43
|
+
|
44
|
+
This way, the generated POST and PUT requests will look very realistic.
|
45
|
+
|
46
|
+
### Smart amounts of urls
|
47
|
+
|
48
|
+
"Dummy urls" analyzes the amount of records that dummy\_data generated and uses this amount to estimate the amount of url groups to generate (each group composed by a GET, a POST, a PUT and a DELETE request).
|
49
|
+
|
50
|
+
It uses the divisor for this estimation. If dummy\_data generated 15 records for a given model and dummy\_urls is using the default divisor (5), it will generate 3 groups of urls for this model (12 requests in total).
|
51
|
+
|
52
|
+
Copyright (c) 2010 Gonçalo Silva
|
data/lib/dummy_urls.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
<%= "# '#{@model_name}' urls generated automatically by dummy at #{Time.now.strftime("%H:%M %m/%d/%Y")} (#{@url_amount} groups of urls)." %>
|
2
|
+
<% for i in 1..@url_amount do %>
|
3
|
+
<% id = generate_id(@model_name) -%>
|
4
|
+
get_<%= i %>:
|
5
|
+
type: get
|
6
|
+
url: /<%= @model_name %>/<%= id %>
|
7
|
+
|
8
|
+
post_<%= i %>:
|
9
|
+
type: post
|
10
|
+
url: /<%= @model_name %>/new
|
11
|
+
params:
|
12
|
+
:<%= @model_name.singularize %>:
|
13
|
+
<%= generate_data(@model_name).map { |field, value| "#{field}: #{value}" }.join("\n ") %>
|
14
|
+
|
15
|
+
put_<%= i %>:
|
16
|
+
type: put
|
17
|
+
url: /<%= @model_name %>/<%= id %>
|
18
|
+
params:
|
19
|
+
:<%= @model_name.singularize %>:
|
20
|
+
<%= generate_data(@model_name).map { |field, value| "#{field}: #{value}" }.join("\n ") %>
|
21
|
+
|
22
|
+
delete_<%= i %>:
|
23
|
+
type: delete
|
24
|
+
url: /<%= @model_name %>/<%= id %>
|
25
|
+
<% end %>
|
@@ -0,0 +1,130 @@
|
|
1
|
+
module Dummy
|
2
|
+
module Generators
|
3
|
+
class UrlsGenerator < Rails::Generators::Base
|
4
|
+
include Dummy::Generators::Common
|
5
|
+
|
6
|
+
def self.source_root
|
7
|
+
@source_root ||= File.expand_path("../templates", __FILE__)
|
8
|
+
end
|
9
|
+
|
10
|
+
class_option :divisor, :type => :numeric, :default => 10,
|
11
|
+
:desc => "The divisor to use when determining the amount of urls to generate."
|
12
|
+
class_option :manual_amounts, :type => :boolean, :default => false,
|
13
|
+
:desc => "Manually set the amount of urls to generate for each model."
|
14
|
+
class_option :output_folder, :type => :string, :default => "test/dummy",
|
15
|
+
:desc => "Dummy output folder, urls/ will be used when storing the resulting YAML files."
|
16
|
+
|
17
|
+
def install_dummy_urls
|
18
|
+
initialize_application
|
19
|
+
generate_dummy_urls
|
20
|
+
copy_rake_files
|
21
|
+
update_dummyfile
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def initialize_application
|
27
|
+
require File.expand_path("#{Rails.root}/config/environment.rb")
|
28
|
+
say_status :successful, "initialize Rails application"
|
29
|
+
end
|
30
|
+
|
31
|
+
def generate_dummy_urls
|
32
|
+
get_table_names
|
33
|
+
load_dummyfile
|
34
|
+
predict_url_amounts
|
35
|
+
gather_associations
|
36
|
+
end
|
37
|
+
|
38
|
+
def get_table_names
|
39
|
+
@models = Hash.new
|
40
|
+
Dir["app/models/*.rb"].each do |full_path|
|
41
|
+
model = File.basename(full_path).chomp(File.extname(full_path)).camelcase.constantize
|
42
|
+
@models.merge!({model => {
|
43
|
+
:record_amount => 0, :url_amount => 0, :associations => []
|
44
|
+
}}) if model.respond_to?(:columns)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def load_dummyfile
|
49
|
+
begin
|
50
|
+
records = YAML.load_file "#{options.output_folder}/Dummyfile"
|
51
|
+
rescue
|
52
|
+
raise MissingDummyfile, "Could not find the Dummyfile. Did you forget to generate dummy data or specified a different directory?"
|
53
|
+
end
|
54
|
+
|
55
|
+
records.each do |record, amount|
|
56
|
+
model = record.singularize.camelcase.constantize
|
57
|
+
@models[model][:record_amount] = amount[:records]
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def predict_url_amounts
|
62
|
+
@models.each do |model, data|
|
63
|
+
amount = data[:record_amount] / options.divisor
|
64
|
+
|
65
|
+
if options.manual_amounts
|
66
|
+
user_defined = ask("Number of urls for #{model} (default: #{amount}): ")
|
67
|
+
amount = user_defined unless user_defined.empty?
|
68
|
+
end
|
69
|
+
|
70
|
+
@models[model][:url_amount] = amount.to_i
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def copy_rake_files
|
75
|
+
empty_directory "test/dummy/urls"
|
76
|
+
@models.each do |model, info|
|
77
|
+
@generated_ids = Array.new
|
78
|
+
|
79
|
+
@model_name = model.to_s.underscore.pluralize
|
80
|
+
@url_amount = info[:url_amount]
|
81
|
+
template "model.yml", "#{options.output_folder}/urls/#{@model_name}.yml"
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def generate_id(model_name)
|
86
|
+
model = model_name.singularize.camelcase.constantize
|
87
|
+
|
88
|
+
begin
|
89
|
+
yaml_id = rand(@models[model][:record_amount])
|
90
|
+
end while @generated_ids.include?(yaml_id)
|
91
|
+
@generated_ids.push(yaml_id)
|
92
|
+
|
93
|
+
Fixtures.identify("#{model_name.singularize}_#{yaml_id}")
|
94
|
+
end
|
95
|
+
|
96
|
+
def generate_data(model_name)
|
97
|
+
data = Hash.new
|
98
|
+
key_value = Hash.new
|
99
|
+
model = model_name.singularize.camelcase.constantize
|
100
|
+
|
101
|
+
model.columns.each do |column|
|
102
|
+
name = model.to_s.underscore
|
103
|
+
info = @models[model]
|
104
|
+
|
105
|
+
key_value = generate_record_data(name, info, column, false)
|
106
|
+
data.merge!(key_value) unless key_value.nil?
|
107
|
+
end
|
108
|
+
|
109
|
+
data
|
110
|
+
end
|
111
|
+
|
112
|
+
def update_dummyfile
|
113
|
+
data = Hash.new
|
114
|
+
dummyfile_path = "#{options.output_folder}/Dummyfile"
|
115
|
+
|
116
|
+
@models.each do |model, info|
|
117
|
+
data[model.to_s.underscore.pluralize] = {:records => info[:record_amount],
|
118
|
+
:urls => info[:url_amount]}
|
119
|
+
end
|
120
|
+
|
121
|
+
content = "# This file was automatically generated by Dummy. Do NOT change it.\n"
|
122
|
+
content << YAML.dump(data)
|
123
|
+
|
124
|
+
remove_file dummyfile_path, :verbose => false if File.exists?(dummyfile_path)
|
125
|
+
create_file dummyfile_path, content
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
metadata
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dummy_urls
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 9
|
8
|
+
version: "0.9"
|
9
|
+
platform: ruby
|
10
|
+
authors:
|
11
|
+
- "Gon\xC3\xA7alo Silva"
|
12
|
+
autorequire:
|
13
|
+
bindir: bin
|
14
|
+
cert_chain: []
|
15
|
+
|
16
|
+
date: 2010-09-17 00:00:00 +01:00
|
17
|
+
default_executable:
|
18
|
+
dependencies:
|
19
|
+
- !ruby/object:Gem::Dependency
|
20
|
+
name: dummy
|
21
|
+
prerelease: false
|
22
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
23
|
+
none: false
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 0
|
29
|
+
- 9
|
30
|
+
version: "0.9"
|
31
|
+
type: :runtime
|
32
|
+
version_requirements: *id001
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: dummy_data
|
35
|
+
prerelease: false
|
36
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
37
|
+
none: false
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
segments:
|
42
|
+
- 0
|
43
|
+
- 9
|
44
|
+
version: "0.9"
|
45
|
+
type: :runtime
|
46
|
+
version_requirements: *id002
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rails
|
49
|
+
prerelease: false
|
50
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
segments:
|
56
|
+
- 3
|
57
|
+
- 0
|
58
|
+
- 0
|
59
|
+
- beta
|
60
|
+
version: 3.0.0.beta
|
61
|
+
type: :runtime
|
62
|
+
version_requirements: *id003
|
63
|
+
description: Generates dummy URLs to hit Rails 3 applications' routes. Since POST and PUT requests require more information than an URL, it uses dummy to generate appropriate data for these requests
|
64
|
+
email:
|
65
|
+
- goncalossilva@gmail.com
|
66
|
+
executables: []
|
67
|
+
|
68
|
+
extensions: []
|
69
|
+
|
70
|
+
extra_rdoc_files: []
|
71
|
+
|
72
|
+
files:
|
73
|
+
- lib/dummy_urls.rb
|
74
|
+
- lib/generators/urls/urls_generator.rb
|
75
|
+
- lib/generators/urls/templates/model.yml
|
76
|
+
- LICENSE
|
77
|
+
- CHANGELOG.md
|
78
|
+
- README.md
|
79
|
+
has_rdoc: true
|
80
|
+
homepage: http://github.com/goncalossilva/dummy_urls
|
81
|
+
licenses: []
|
82
|
+
|
83
|
+
post_install_message:
|
84
|
+
rdoc_options: []
|
85
|
+
|
86
|
+
require_paths:
|
87
|
+
- lib
|
88
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
segments:
|
94
|
+
- 0
|
95
|
+
version: "0"
|
96
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
segments:
|
102
|
+
- 1
|
103
|
+
- 3
|
104
|
+
- 7
|
105
|
+
version: 1.3.7
|
106
|
+
requirements: []
|
107
|
+
|
108
|
+
rubyforge_project: dummy_urls
|
109
|
+
rubygems_version: 1.3.7
|
110
|
+
signing_key:
|
111
|
+
specification_version: 3
|
112
|
+
summary: Generates dummy URLs for Rails 3 applications
|
113
|
+
test_files: []
|
114
|
+
|