I hope this does not feel like a plug:

https://github.com/metaskills/named_seeds

There is a talk I have around this gem/concept I have been using for several 
years. The general idea is:

* Factories generate Valid Garbage™ which is 100% random.
* Test fixtures take advantage of said factories but are explicit in their IDs 
and properties.

This idea is to have a minimal fixture set (not driven by YAML) allowing ad-hoc 
tests to create valid garbage as needed for testing purposes. NamedSeeds even 
allows these fixture personas to populate your development DB. 

I realize this is slightly tangential to the way you are doing things, but I 
wanted to share. Either way I kind of believe that Rails is doing it right now 
and solutions like these are best done in gems and projects like ours. Hope it 
is helpful.


 - Cheers,
    Ken

On February 18, 2016 at 3:28:19 AM, Ben Colon (ben.co...@gmail.com) wrote:

A consistent database ... but with some random fields ;)

I guess, it's simpler to run a seed with
10000.times { User.create! :first_name => Faker::Name.first_name }

than loading an hardcoded file with 10000 users.

Ben

Le mercredi 17 février 2016 20:21:30 UTC+1, Derek Prior a écrit :
Interesting idea. If what you're after is consistent data, why are you 
randomizing anything?


On Wed, Feb 17, 2016 at 9:48 AM, Ben Colon <ben....@gmail.com> wrote:
Hey there,

In many projects, I guess like everyone, we're using the seed file to generate 
a bunch of models with random data.
Obviously, after running db:seed task, each developer has a "different" 
database. Not cool.
If we need to sync those data, we prefix seed.rb code with something like 

```
generator = Rand.new(1234567890)
```
and replace all "rand" calls by "generator.rand"

As we do that in many projects, I could write a gem which would override the 
Railties `load_seed` method and insert a fixed `srand` call before seed.rb 
load, so all `rand` calls during seed will be "predictable".

But is it make sense to make a Railties pull request with this (with a config 
options to enable/disable "predictable" seed) ?
Something like :

```
def load_seed
  srand(config.predictable_seed) if config.predictable_seed
  seed_file = paths["db/seeds.rb"].existent.first
  load(seed_file) if seed_file
ensure
  srand if config.predictable_seed
end
```

Thoughts ?
Thank you
Ben
--
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-co...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.
Visit this group at https://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-core+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-core@googlegroups.com.
Visit this group at https://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-core+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-core@googlegroups.com.
Visit this group at https://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.

Reply via email to