sevenwire / forgery Goto Github PK
View Code? Open in Web Editor NEWEasy and customizable generation of forged data.
License: MIT License
Easy and customizable generation of forged data.
License: MIT License
gemcutter has an old version of forgery "0.2.2".
I realize the generator is very simple and could be done by hand, but it'd be nice if the gem was updated for Rails 3.
I am looking at Forgery for creating fake data. The data I am creating will not be in English (And not using a western alphabet).
In the short term I will just override the dictionaries in my app but in future it would be great if we could namespace the dictionaries by language and build up a multi-lingual + alphabet forgery library.
On a Rails 3.1 environment and rake 0.9.2 if you try to run rspec spec.
> rspec spec ruby-1.9.2-p180@tarifador master [c19c69b] modified untracked
/Users/lunks/.rvm/gems/ruby-1.9.2-p180@global/bin/bundle
/Users/lunks/.rvm/gems/ruby-1.9.2-p180@tarifador/gems/forgery-0.3.11/lib/forgery/forgery_railtie.rb:5:in `<class:ForgeryRailtie>': uninitialized constant ForgeryRailtie::Rake (NameError)
from /Users/lunks/.rvm/gems/ruby-1.9.2-p180@tarifador/gems/forgery-0.3.11/lib/forgery/forgery_railtie.rb:4:in `<top (required)>'
from /Users/lunks/.rvm/gems/ruby-1.9.2-p180@tarifador/gems/forgery-0.3.11/lib/forgery.rb:35:in `<top (required)>'
from /Users/lunks/.rvm/gems/ruby-1.9.2-p180@global/gems/bundler-1.0.12/lib/bundler/runtime.rb:68:in `require'
from /Users/lunks/.rvm/gems/ruby-1.9.2-p180@global/gems/bundler-1.0.12/lib/bundler/runtime.rb:68:in `block (2 levels) in require'
from /Users/lunks/.rvm/gems/ruby-1.9.2-p180@global/gems/bundler-1.0.12/lib/bundler/runtime.rb:66:in `each'
from /Users/lunks/.rvm/gems/ruby-1.9.2-p180@global/gems/bundler-1.0.12/lib/bundler/runtime.rb:66:in `block in require'
from /Users/lunks/.rvm/gems/ruby-1.9.2-p180@global/gems/bundler-1.0.12/lib/bundler/runtime.rb:55:in `each'
from /Users/lunks/.rvm/gems/ruby-1.9.2-p180@global/gems/bundler-1.0.12/lib/bundler/runtime.rb:55:in `require'
from /Users/lunks/.rvm/gems/ruby-1.9.2-p180@global/gems/bundler-1.0.12/lib/bundler.rb:120:in `require'
from /Users/lunks/projects/tarifador/config/application.rb:8:in `<top (required)>'
from /Users/lunks/projects/tarifador/config/environment.rb:2:in `require'
from /Users/lunks/projects/tarifador/config/environment.rb:2:in `<top (required)>'
from /Users/lunks/projects/tarifador/spec/spec_helper.rb:11:in `require'
from /Users/lunks/projects/tarifador/spec/spec_helper.rb:11:in `<top (required)>'
from /Users/lunks/projects/tarifador/spec/controllers/accessories_controller_spec.rb:1:in `require'
from /Users/lunks/projects/tarifador/spec/controllers/accessories_controller_spec.rb:1:in `<top (required)>'
from /Users/lunks/.rvm/gems/ruby-1.9.2-p180@tarifador/gems/rspec-core-2.6.4/lib/rspec/core/configuration.rb:419:in `load'
from /Users/lunks/.rvm/gems/ruby-1.9.2-p180@tarifador/gems/rspec-core-2.6.4/lib/rspec/core/configuration.rb:419:in `block in load_spec_files'
from /Users/lunks/.rvm/gems/ruby-1.9.2-p180@tarifador/gems/rspec-core-2.6.4/lib/rspec/core/configuration.rb:419:in `map'
from /Users/lunks/.rvm/gems/ruby-1.9.2-p180@tarifador/gems/rspec-core-2.6.4/lib/rspec/core/configuration.rb:419:in `load_spec_files'
from /Users/lunks/.rvm/gems/ruby-1.9.2-p180@tarifador/gems/rspec-core-2.6.4/lib/rspec/core/command_line.rb:18:in `run'
from /Users/lunks/.rvm/gems/ruby-1.9.2-p180@tarifador/gems/rspec-core-2.6.4/lib/rspec/core/runner.rb:80:in `run_in_process'
from /Users/lunks/.rvm/gems/ruby-1.9.2-p180@tarifador/gems/rspec-core-2.6.4/lib/rspec/core/runner.rb:69:in `run'
from /Users/lunks/.rvm/gems/ruby-1.9.2-p180@tarifador/gems/rspec-core-2.6.4/lib/rspec/core/runner.rb:11:in `block in autorun'
I know I, for one, would love to use Forgery::Geo without depending on GitHub.
Random number is generated by this code in the 12th line of forgery/extensions/range.rb.
Kernel.rand(last - first + (exclude_end? ? 0 : 1)) + first
Forgery(:basic).number(at_least: 0.3, at_most: 1.2) returns only 0.3, because Kernel.rand only returns integers.
It would be better that returns the float number between 0.3 to 1.2, so I propose to change random number generation under this code and will pull request.
Random.rand self
RAILS_ROOT is deprecated in Rails 3, Forgery is still using it and causes some deprecation warnings.
Forgery 0.5.0
Date.date( future: false ) may return dates from the future. however past:true seems to work ok.
ruby-1.9.2-p180 :064 > c=0; 100.times { c+=1 if Forgery::Date.date(future:false) > Time.now.to_date }; c
=> 48
ruby-1.9.2-p180 :065 > c=0; 100.times { c+=1 if Forgery::Date.date(past:true) > Time.now.to_date }; c
=> 0
They should probably be moved into a module, so that forgery
uses it's own Forgery::Array
classes, etc... This is being blamed for an issue with devise
- heartcombo/devise#1280
I started to try to patch this, but it was like going down the rabbit hole; I've had some limited success, but it's not really something I want to be spending time on; what're your thoughts?
One thing I've noticed about Forgery is how sometimes the categories and methods are unintuitive.
For instance, lets say I want to generate a fake name! My first thought would maybe be in the :basic
category? No. Ok, what about :personal
? Nope. Finally I find it in :name
, an entire class for generated names? Hrm, I think it could do a little better than that! I'm willing to do the work, but I want to discuss the goal.
I have a few suggestions for improving the library:
Forge(:full_name)
or Forge(:monetary, :min => 100, :max => 200)
Forgery(:person).full_name
or Forgery(:numeric).date
Forge.build(:address)[:state]
orForgery.build(:person)
#=>
{
:name => {
:first => "Kurtis",
:middle => "Lowell",
:last => "Rainbolt-Greene"
},
:address => {
:street => "718 Mill Street",
:city => "Springfield",
:state => {
:full => "Oregon",
:short => "OR"
}
}
}
and so on.
Any or even all of these used would improve the library significantly, and greatly improve not only my development experience but those I direct to use Forgery.
/home/efranco/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/forgery-0.6.0/lib/forgery/forgery/lorem_ipsum.rb:51: warning: constant ::Fixnum is deprecated
This generates invalid emails such as:
"cpalmer@group buy united.biz"
"pday@deliver the deals.biz"
"jlawson@steal the deal.name"
"[email protected]"
"aortiz@all buys.gov"
"kflores@smart canucks.com"
"[email protected]"
"bking@dream ninja.info"
"fdean@toronto deals online.edu"
"jclark@red flag deals.mil"
"thudson@miser mcgee.info"
"[email protected]"
"jholmes@buy battle.edu"
"[email protected]"
"wholmes@toronto deals online.net"
"[email protected]"
"dgeorge@steal the deal.edu"
"wford@great deal of the day.name"
"breynolds@one spout.net"
"[email protected]"
"[email protected]"
"mburns@angry buys.name"
"[email protected]"
"jduncan@angry buys.name"
"[email protected]"
"jarnold@miser mcgee.gov"
"jlewis@sweet ontario deals.biz"
"[email protected]"
"dfisher@angry buys.org"
"[email protected]"
Calling .sub
method on an object of class Forgery::Extensions::String
returns String
object instead of Forgery::Extensions::String
object on ruby 3, which causes NoMethodError: undefined method 'unextend' for "":String
when using Forgery::Name.job_title
We're still using the "ancient" Rails 1.2.6 for our app & after upgrading to the newest forgery gem started getting "undefined method `root' for Rails:Module" errors. Turns out this happens when the Rails object is defined, but doesn't respond to the root method.
Gem version 0.7.0
I've got a model with an db index that has db unique constraint
create_table "thing", force: :cascade do |t|
t.string "name"
t.string "unique_ref"
t.index ["unique_ref"], name: "index_thing_on_unique_ref", unique: true
end
I've set up my factory with the following. (made sure I didn't make the mistake mentioned #43)
FactoryBot.define do
factory :thing do
unique_ref { Forgery::Basic.encrypt }
end
end
When I go to run my spec
create(:thing, name: 'one')
create(:thing, name: 'two')
I receive the following error
ActiveRecord::RecordNotUnique:
PG::UniqueViolation: ERROR: duplicate key value violates unique constraint "index_things_on_unique_ref"
DETAIL: Key (unique_ref)=(25357e2fe475921386b7bf09b9804d9e357ad287) already exists.
: INSERT INTO "things" ("unique_ref", "name", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "id"
Switching from encrypt
to password
things seem to work as expected and generate unique values.
FactoryBot.define do
factory :thing do
unique_ref { Forgery::Basic.password }
end
end
While the #-(###)###-####
format is simple enough, it creates phone numbers which are not E164 compliant.
This is an issue if you want to introduce phone number plausibility checking from Phony into your model and suddenly all your tests fail randomly.
Maybe the Phony guys could help with a generator? It seems nontrivial. For now I use a preset country code and just generate the last 7 digits of the phone number randomly.
My setup: ruby 1.9.2, rails 3.0.0rc, datamapper (dm-rails 1.0.3).
When the load path gets built, Rails.root is not yet set by rails. Therefore, it generates a wrong load path for lib/forgery...
I can get around it by calling Forgery.load_from! "#{Rails.root}/lib/forgery" right before I use my custom forgeries.
Hi SevenWire,
Seems like Rake::DSL has to be included explicitly to use rake tasks from now on. These are the warnings that are dumped when using Rails 3.1.rc4
WARNING: Global access to Rake DSL methods is deprecated. Please include
... Rake::DSL into classes and modules which use the Rake DSL methods.
WARNING: DSL method Class#namespace called at /Users/akashmanohar/.rvm/gems/ruby-1.9.2-p180@rails31/gems/forgery-0.3.10/lib/forgery/forgery_railtie.rb:10:in block in <class:ForgeryRailtie>' WARNING: DSL method Class#desc called at /Users/akashmanohar/.rvm/gems/ruby-1.9.2-p180@rails31/gems/forgery-0.3.10/lib/forgery/forgery_railtie.rb:24:in
block (2 levels) in class:ForgeryRailtie'
WARNING: DSL method Class#task called at /Users/akashmanohar/.rvm/gems/ruby-1.9.2-p180@rails31/gems/forgery-0.3.10/lib/forgery/forgery_railtie.rb:25:in `block (2 levels) in class:ForgeryRailtie'
Akash
I want to generate a number of size 8. How do I do it?
Thanks
(1...10).random generates a random number between 1 and 10 including 10
Really great lib, but this error is terribly annoying. It only appears for some values (e.g. Sham.gender defined with returning either "m" or "f").
"Can't generate more unique values for Sham.xxx"
where xxx is a defined sham. I consider this more of a bug than a feature...or the documentation missed to mention something.
The Lorem Ipsum functions dont seem to be using any randomness. I'll take a crack at fixing them, those they don't seem to follow the same general idea the other generators use?
Should allow both upper and lower in the form of:
A โ Upper a โ Lower
So, using it with the number format, you would do:
aaaAAA###
Which might generate:
qweRTY123
Forgery::LoremIpsum.words(1,:random => true) raises that error. The trace:
undefined method `random' for 0..932:Range
/home/atd/.rvm/gems/ruby-1.9.2-p180/gems/forgery-0.4.1/lib/forgery/forgery/lorem_ipsum.rb:102:in `range_from_quantity'
/home/atd/.rvm/gems/ruby-1.9.2-p180/gems/forgery-0.4.1/lib/forgery/forgery/lorem_ipsum.rb:43:in `words'
/home/atd/dev/social_stream-base/lib/tasks/db/populate.rake:36:in `block in set_tags'
...
When used with FactoryGirl, i.e.
factory :user do
email Forgery(:internet).email_address
end
and you attempt to create records:
5.times { FactoryGirl.create(:user) }
will return five records with the same e-mail address. This creates a problem if the model validates the uniqueness of the e-mail address.
Seems like it should generate random Lorem Ipsum strings? Can't use it for anything that requires unique text.
Hi, I am using Forgery with factory_girl.
I have one trouble though - when I create Factory like so
Factory.define :client do |f|
f.first_name Forgery(:name).first_name
end
all objects that are created with this factory have the same first name!
Does anybody have an idea on this?
Thanks.
Looks like the random
method is getting called twice in Forgery::Name.first_name
, causing an undefined method 'random'
exception.
Affects v0.4.0. Was previously working in v0.3.12.
Works in 0.3.12, breaks in 0.4.2.
Forgery(:monetary).money
NoMethodError:
undefined method `random' for 0..1000:Range
https://github.com/sevenwire/forgery/blob/master/lib/forgery/dictionaries/company_names
I am using this gem. With our testdata we also test a third party service and this service sends emails. I got contacted from Brainfire because they get emails from the third party service (because of our test data). You should make sure that all company names (which you also use in the email addresses) dont exists.
Well, not quite nowhere. There are many self-referencing links caused by lonely square brackets (e.g. "many more!")
Hopefully no one's already caught in an infinite loop. ;D
Is there a way to overwrite the core dictionaries included with forgery?
For instance, I don't want to use any of the male_first_names
...I'd like to use only the ones I supply.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.