Code Monkey home page Code Monkey logo

machinist's People

Contributors

adzap avatar benhoskings avatar chrislloyd avatar ianwhite avatar knaveofdiamonds avatar lawrencepit avatar niels avatar notahat avatar perryn avatar pk avatar rubysolo avatar sakuro avatar sobrinho avatar tjsheehy avatar yob avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

machinist's Issues

Rails 3 install

new plugin install command at rails3.

new
./script/rails plugin install git://github.com/notahat/machinist.git

old:
./script/plugin install git://github.com/notahat/machinist.git

Add callbacks to blueprints (before_make, after_make, ... ?)

factory_girl has callbacks. Callbacks can be useful.

Callbacks allow a lot of flexibility for those cases where you need to do some additional setup to an object before or after Machinist does its usual thing.

Example:

User.blueprint do
  before { |user|
    user.auto_initialize_associations = false
    [:code1, :code2].each do |attr_name|
      user.send "#{attr_name}=", '1'
    end
  }
  name
  email_address
  address
  after { |user| do_something_to(user) }
  after { |user| user.activate! }
end

Autoloading of blueprints and adapters

I've create a branch at http://github.com/fox/machinist/tree/autoloading that adds two related features:

  • Blueprints gets automatically loaded from the following locations

    test/blueprints.rb
    spec/blueprints.rb
    test/blueprints/.rb
    spec/blueprints/
    .rb

  • ORM adapters get automatically loaded. This works only when the ORM library ('active_record' ) is required before requiring machinist.

Pull if you like!

Problem with nested associations and instance_eval?

I have blueprints.rb set up like this:

Channel.blueprint do
  name
  short_name
  description
end

Post.blueprint do
  channel
  title
  body
end

Attachment.blueprint do
  post
end

This works fine except in calling Attachment.make. I consistently receive the following error:

ArgumentError in 'Attachment should belong to post'
wrong number of arguments (0 for 1)
/Users/jakepaul/Projects/chirp/spec/blueprint.rb:26:in `post'
/Users/jakepaul/Projects/chirp/spec/blueprint.rb:26:
/Users/jakepaul/Projects/chirp/vendor/plugins/machinist/lib/machinist.rb:20:in `instance_eval'
/Users/jakepaul/Projects/chirp/vendor/plugins/machinist/lib/machinist.rb:20:in `run'
/Users/jakepaul/Projects/chirp/vendor/plugins/machinist/lib/machinist/active_record.rb:52:in `make'
./spec/models/attachment_spec.rb:7:

I've been troubleshooting for awhile and I think it must have something to do with the way the instance_eval works. Replacing post in the Attachment.blueprint block with post_id {2} causes it to work, and I can call Attachment.make{:post => post} successfully in the spec.

If I replace the has_many/belongs_to relationship between Post and Attachment with one between Channel and Attachment (so attachments belong to a Channel instead of a Post), the relationship works as expected. This leads me to suspect that there may be a problem with nesting the relationship (Attachment belonging to Post belonging to Channel) and possibly with instance_eval, but I'm not experienced enough with instance_eval to know why or how to fix it.

Thank you in advance!

Method "make" works not properly for objects with overloaded "initialize" method

Let we have a class like:

class User < ActiveRecord::Base
  def initialize(*args)
    super(*args)
    do_something_args_related(*args)  # this code won't run properly if we use User.make in tests, because make instantiates object without args passed and assigns parameters later.
  end
end

This is a design issue and happens rarely. Do you think it's worth/possible to rewrite object instantiation and parameter assignment logic? I could try to do this but would like to get an advise first.

generate_attribute_value cases problems with polymorphic associations

everything was fine with notahat-machinist 1.0.3 from github. When updating to gemcutter 1.0.6, we ran into an issue with our polymorphic associations.

The issue is here:

def generate_attribute_value(attribute, *args)
if block_given?
# If we've got a block, use that to generate the value.
yield
else
# Otherwise, look for an association or a sham.
if @adapter.has_association?(object, attribute)
@adapter.class_for_association(object, attribute).make(args.first || {})
elsif args.empty?
Sham.send(attribute)
else
# If we've got a constant, just use that.
args.first
end
end
end

    if @adapter.has_association?(object, attribute)
      @adapter.class_for_association(object, attribute).make(args.first || {})

An arg exists, but the association is polymorphic, meaning that class_for_association is unreliable. In our case, it returns a Module whish is not an Active Record object, and thus does not have the monkey-patched #make method.

The previous version treated the argument like a constant, which is exactly how we were using it.

Currently, the code seems to want to do to many things at once. I think we need to assume that associations without args should build an association, but associations with args can be treated as they were before.

Parameterized blueprints

I would be nice to define named blueprints with regexp patterns. The actually blueprint name used could affect the behavior of the blueprint. For example,

Post.make(:with_3_comments)

Doing this with a pattern would allow for large classes of similar blueprints to be supported with very succinct definition. The blueprint for the above would look something like

Post.blueprint(/with_(\d+)_comments/) do |num_comments|
  # ...
  comments(num_comments.to_i)
end

Would a patch implementing this be accepted?

Sham generates same value each time for some values.

I got this problem with Sham: I use Forgery for generating gender-abbreviations "M" vs. "F". This works perfectly in IRB like this:

Forgery(:personal).abbreviated_gender

but with the same using sham:

Sham.gender(:unique => false) { Forgery(:personal).abbreviated_gender }

I get "F" all the time for hundres of values.

Any clue?

Sham: Add an option to seed srand with something other than 1

Sometimes I might just want to let srand do its default behavior (If number is omitted or zero, seeds the generator using a combination of the time, the process id, and a sequence number.) and see if the tests still pass.

Or I might just get tired of seeing the same names come up again and again in the tests.

What's the point of having so many possible values that Sham/Faker might yield if I only over see the first several?

How to test controllers using machinist

After reading the doc on github, I was able to do unit testing on my Rails application something like this in blueprints.rb file and then running respective files under test/unit directory:
Sham.define do
url { Faker::Internet.domain_name }
username { Faker::Internet.user_name }
name { Faker::Name.name }
end

Email.blueprint do
name
url
username
end

But when I try for functional testing, it gives errors in the following part of the code which is written in products_controller_test.rb file (I have products section in my application):
test "should create product" do
assert_difference('Product.count') do
post :create, :product => {:name => 'product_name', :description => 'test_description'}
end
assert_redirected_to product_path(assigns(:product))
end

Any ideas would be appreciated...

Need a Sham.reset(:all) and Sham.reset(:before)

Hi Peter,

After railscamp05 I decided to have a go at a gem that allows easy object graph creation. I've named it Machinery. ;-) See: http://github.com/lawrencepit/machinery

One of the (perhaps not so obvious) main feature of that little gem is that you can set up plain ruby objects (and hence also objects created with Machinist, which is what I'm doing) in a before(:all) block in a transactional manner.

However, when I use Sham to generate some random values for blueprints, and these blueprints are used in a before(:all) block, then in an example test I stumble upon duplicate values generated by Sham because in the before(:each) block it will always do a Sham.reset.

I've created a patch for Sham so that you can add the following instead in the Spec::Runner.configure block of your spec_helper.rb :

config.before(:all) { Sham.reset(:all) }
config.before(:before) { Sham.reset(:before) }

This way it will generate the same sequence of values after each reset(:before) without overlapping the values generated in the before(:all).

The patch is at:

http://github.com/lawrencepit/machinist/commit/66283fda6ce6acf2fa7f0f0203eefda69468e5c5

Cheers,
Lawrence

Problems with object caching

It would be nice to have object caching disabled by default, at least as long as it is "experimental". It was giving me a lot of false positives everywhere (for example, the cache doesn't seem to reset between test runs, am I wrong?) until I figured how to disable it.

Except that, Machinist is indeed a lot funnier than fixtures :)

exceptions aren't raised with the proper caller stack via rspec

Not sure exactly if this is machinist's fault, but thought I'd report it.

Via console:
ree-1.8.7-2010.02 > Topic.make!
NameError: uninitialized constant User::Cache
from /Users/inspire/Dropbox/newap/app/models/user.rb:129:in _callback_after_133' from /Users/inspire/.rvm/gems/ree-1.8.7-2010.02/gems/machinist-2.0.0.beta2/lib/machinist/active_record/blueprint.rb:33:invalue'
from /Users/inspire/.rvm/gems/ree-1.8.7-2010.02/gems/machinist-2.0.0.beta2/lib/machinist/active_record/blueprint.rb:33:in outside_transaction' from /Users/inspire/.rvm/gems/ree-1.8.7-2010.02/gems/machinist-2.0.0.beta2/lib/machinist/shop.rb:43:inbuy'
from /Users/inspire/.rvm/gems/ree-1.8.7-2010.02/gems/machinist-2.0.0.beta2/lib/machinist/machinable.rb:55:in make!' from /Users/inspire/.rvm/gems/ree-1.8.7-2010.02/gems/machinist-2.0.0.beta2/lib/machinist/machinable.rb:94:indecode_args_to_make'
from /Users/inspire/.rvm/gems/ree-1.8.7-2010.02/gems/machinist-2.0.0.beta2/lib/machinist/machinable.rb:53:in `make!'
from (irb):21

Via Rspec:

  1. Model tests requires new topics to have a board
    Failure/Error: t = Topic.new :user => User.make!, :title => "hello world"
    uninitialized constant User::Cache

    /Users/inspire/.rvm/gems/ree-1.8.7-2010.02/gems/machinist-2.0.0.beta2/lib/machinist/active_record/blueprint.rb:33:in `value'

    /Users/inspire/.rvm/gems/ree-1.8.7-2010.02/gems/machinist-2.0.0.beta2/lib/machinist/active_record/blueprint.rb:33:in`outside_transaction'

    /Users/inspire/.rvm/gems/ree-1.8.7-2010.02/gems/machinist-2.0.0.beta2/lib/machinist/shop.rb:43:in `buy'

    /Users/inspire/.rvm/gems/ree-1.8.7-2010.02/gems/machinist-2.0.0.beta2/lib/machinist/machinable.rb:55:in`make!'

    /Users/inspire/.rvm/gems/ree-1.8.7-2010.02/gems/machinist-2.0.0.beta2/lib/machinist/machinable.rb:94:in `decode_args_to_make'

    /Users/inspire/.rvm/gems/ree-1.8.7-2010.02/gems/machinist-2.0.0.beta2/lib/machinist/machinable.rb:53:in`make!'

    ./spec/models/model_spec.rb:22

If it seems like its prob not machinist's fault, let me know.

BTW - you're aware of dm-sweatshop, right? They were inspired by you but added Model.pick, which picked from the currently generated models of that type. Sounds like your caching system acts similar now, but that format made a bit more sense to me.

Handling circular references in blueprints

Setting up blueprints for records that reference each other sends machinist into a infinite loop:

Airport.blueprint do
city
end

City.blueprint do
closest_airport
end

It would be great to have a way to sense this and make the relationship 1 to 1.

Lack of Encoding Awareness

I seem to have discovered a lack of encoding awareness.

Given the following environment
• Ruby 1.9.1 p378
• Rails Edge ( 3.0 b3 + @ SHA: 19cecc90 )

I see the following behavior:

Sorry, Github ate my input:

ruby-1.9.1-p378 > Player.make(:name => "Peter Jöback").name.encoding
 => # Encoding:ASCII-8BIT
ruby-1.9.1-p378 > Player.new(:name => "Peter Jöback").name.encoding
 => # Encoding:UTF-8

"Save failed" with DataMapper

I followed all the information I was able to find, but still, with this minimal code:

require "machinist/data_mapper"

Post.blueprint do
    title "machinist"
    body "machinist works!"
end

post = Post.make

I got a frustrating error:

RuntimeError: Save failed

Also, when I try to use 'make!' as indicated in the docs, I get:

NoMethodError: undefined method `make!' for Post:Class

[Machinist 2] Unique attributes with other validations

I don't know if this is the place for asking this, but in Machinist 2 how should I handle the following case:

A model Person has a SSN which is a structured number which can (and will) be validated. Should I generate a number on the fly by creating a method in the spec_helper (or even in the blueprint)?

Rails 3 deprecated warning

DEPRECATION WARNING: RAILS_ENV is deprecated! Use Rails.env instead. (called from block in class:Plugin at /Users/patrick/workspace_rails3/test_app/vendor/plugins/machinist/init.rb:1)

setting a value called "format" doesn't work

Hi

First of all I want to tell you that your plugin is great and simplifies my testing environment heavily, but unfortunately I've got a problem that I cannot set a value with the name "format" in my blueprints.

My Example looks like this:
class Example < ActiveRecord::Base
validates_presence_of :name
validates_presence_of :format
end

My Blueprint:
Example.blueprint do
name Sham.name
format Sham.format # also tried 'test' and different Sham-functions here
end

If I call "Example.make" now, I get an error "Validation failed: Format can't be blank".
But if I call "Example.make :format => 'test' " it works fine without any issues.

I've tried it with several classes now. Everything I tried worked fine, but "format" never did.

Any clues what the problem could be?
I also use the Forgery-Gem. Is it possible that this causes the issues?

Kind regards
Simon

doesn't create associations that use a :class_name (v2)

class Topic < blah
  belongs_to :last_user, :class_name => 'User'
  validates_presence_of :last_user_id
end

Topic.blueprint do
  title {Faker::Lorem.words}
  rendered {Faker::Lorem.paragraphs(3)}

  #just assumes make? i think so, but needs adding to machinist docs!
  board #{Board.make!}
  user
  # gr, not making last_user.  frustrating...
  last_user_id {u=User.make!; puts "last_user is #{u.id}"; u.id}

end

Topic.make! -> last_user_id can't be null. it also puts 'last user is 51', but apparently doesn't set it.

Also doesn't work with last_user {User.make!} or just 'last user' in the blueprint.

belongs_to association through virtual attribute

Basically, Machinist doesn't allow this behavior:

Group.blueprint do
  name
  category_name
end

Category.blueprint do
  name
end

And the model:

class Group < ActiveRecord::Base
  belongs_to :category
  before_save :assign_category
  attr_writer :category_name

  def assign_category
    self.category = Category.find_or_create_by_name(category_name)
  end
end

What I'm trying to do, is to let the user create a group with a given category name. It works, but when I create a group in my tests, it doesn't get a category.

Support for assigning belongs_to associations through a virtual attribute would be nice. :)

blueprint for mongoid embeds_many association

I am using machinist and mongoid. How can I generate blueprint for embeds_many association. Mongoid embeds_many association embeds the hash of array. So I just started like this:

 User.blueprint do
   address { :address1 => "address", :address2 => 'next address'}
 end

Is this right way of defining? I don't feel good in this way.

Does Machinist support has_many through relationships.

I have just switched from factory_girl to machinist and I am having trouble with a hmt relationship.

Employee.blueprint do
username
password {'password'}
password_confirmation {'password'}
tms_code
first_name
last_name
active false
role
timesheet
end

Role.blueprint do
description
employee
end

I get RuntimeError: No sham defined for role

What am I doing wrong here? Or is it just not supported yet?

Setting id inside a blueprint doesn't work for me.

Since my model doesn't have a typical primary_key I have to set id by hand, and it has to take a MD5 string hash. But when I try to set it via blueprint it doesn't work.

Maybe this has to do with this line inside the lib/machinist.rb:
undef_method :id if respond_to?(:id)

Right?

strange issue with validation failures in has_many.make!

Topics have many comments
Topic.first.comments.make! => validation error 'topic can't be blank'
c = Topic.first.comments.make
c.save => true

Callback at validation error:

ActiveRecord::RecordInvalid: Validation failed: Topic can't be blank
from /Users/kevin/.rvm/gems/ree-1.8.7-2010.02/gems/activerecord-3.0.0.beta4/lib/active_record/validations.rb:46:in save!' from /Users/kevin/.rvm/gems/ree-1.8.7-2010.02/gems/machinist-2.0.0.beta2/lib/machinist/active_record/blueprint.rb:35:invalue'
from /Users/kevin/.rvm/gems/ree-1.8.7-2010.02/gems/machinist-2.0.0.beta2/lib/machinist/active_record/blueprint.rb:35:in outside_transaction' from /Users/kevin/.rvm/gems/ree-1.8.7-2010.02/gems/machinist-2.0.0.beta2/lib/machinist/shop.rb:43:inbuy'
from /Users/kevin/.rvm/gems/ree-1.8.7-2010.02/gems/machinist-2.0.0.beta2/lib/machinist/machinable.rb:55:in make!' from /Users/kevin/.rvm/gems/ree-1.8.7-2010.02/gems/machinist-2.0.0.beta2/lib/machinist/machinable.rb:94:indecode_args_to_make'
from /Users/kevin/.rvm/gems/ree-1.8.7-2010.02/gems/machinist-2.0.0.beta2/lib/machinist/machinable.rb:53:in make!' from /Users/kevin/.rvm/gems/ree-1.8.7-2010.02/gems/activerecord-3.0.0.beta4/lib/active_record/associations/association_collection.rb:421:insend'
from /Users/kevin/.rvm/gems/ree-1.8.7-2010.02/gems/activerecord-3.0.0.beta4/lib/active_record/associations/association_collection.rb:421:in method_missing' from /Users/kevin/.rvm/gems/ree-1.8.7-2010.02/gems/activerecord-3.0.0.beta4/lib/active_record/base.rb:1167:inwith_scope'
from /Users/kevin/.rvm/gems/ree-1.8.7-2010.02/gems/activerecord-3.0.0.beta4/lib/active_record/associations/association_proxy.rb:201:in send' from /Users/kevin/.rvm/gems/ree-1.8.7-2010.02/gems/activerecord-3.0.0.beta4/lib/active_record/associations/association_proxy.rb:201:inwith_scope'
from /Users/kevin/.rvm/gems/ree-1.8.7-2010.02/gems/activerecord-3.0.0.beta4/lib/active_record/associations/association_collection.rb:417:in `method_missing'
from (irb):1

Thanks!

The second invokation of blueprint gives an error

I'm using machinist 0.3.1. When I run machinist with Cucumber with (use_transactional_fixtures off) I get the error 'No blueprint for class X' for the second feature that use the blueprint.

I have tried Sham.reset but that does not help me either.

I will try to debug it and post results here.

Create plain ruby objects with machinist

I was wondering, if there are plans to support plain object creation with machinist. So that you can blueprint objects different from activerecord or data-mapper.

Machinist should not change srand value globally

I think it could probably be considered a security flaw since machinist doesn't reset the srand after use.

srand returns the current value when you call it, so you could do something like this:

start_machinist_srand = srand(machinist_srand_value)
...
some_stuff do; end
#machinist ready to return to application
srand(start_machinist_srand)

Thanks for a great blueprinting gem. ;)

Caching fails if transactional fixtures are off

Caching depends on transactional fixtures. If they're off, you may get objects back from make! that have been modified by earlier tests.

Caching should detect transactional fixtures and disable itself (possibly with a warning.)

Transactional fixtures not working with cucumber 8.3 and machinist2.beta2

I'm not completely sure why, but with machinist2 I need to disable transactional fixtures to get cucumber running repeatably. If I don't do this the database isn't properly cleaned and my scenarios fail because of duplicate records.

As understand, it should be possible to use the transaction strategy with machinist2. I'm not sure what's going on behind the covers to prevent the transactions from encapsulating all the work.

Any thoughts as to why? I don't know what information would be helpful so I won't clog this up with stuff you don't ask for.

Sham interferes with Mocha?

Hi,

I've tried to use mocha with machinist in one project and got the following problem:
http://pastie.org/761613

the line that invokes this error is just a:
@user_session = mock

I've required machinist as a gem in my test environment file as well as mocha:
config.gem 'machinist', :lib => "machinist", :version => "> 1.0.6"
config.gem "mocha", :lib => false, :version => '
> 0.9.8'

Bug in README

This example in the README

Sham.name { (1..10).map { ('a'..'z').to_a.rand } }

should read

Sham.name { (1..10).map { ('a'..'z').to_a.rand }.join }

Thanks for a great plugin!

ArgumentError: wrong number of arguments (0 for 1) in 'reload'

I keep getting this error. As far as I can tell its just calling object.reload. I don't define 'reload' anywhere, so I don't know why it could be saying it needs an argument?

ree-1.8.7-2010.02 > t = Topic.make
making user user0003
making user user0004
ArgumentError: wrong number of arguments (0 for 1)
from /Users/inspire/.rvm/gems/ree-1.8.7-2010.02/gems/machinist-2.0.0.beta2/lib/machinist/active_record/blueprint.rb:8:in reload' from /Users/inspire/.rvm/gems/ree-1.8.7-2010.02/gems/machinist-2.0.0.beta2/lib/machinist/active_record/blueprint.rb:33:invalue'
from /Users/inspire/.rvm/gems/ree-1.8.7-2010.02/gems/machinist-2.0.0.beta2/lib/machinist/active_record/blueprint.rb:33:in outside_transaction' from /Users/inspire/.rvm/gems/ree-1.8.7-2010.02/gems/machinist-2.0.0.beta2/lib/machinist/shop.rb:43:inbuy'
from /Users/inspire/.rvm/gems/ree-1.8.7-2010.02/gems/machinist-2.0.0.beta2/lib/machinist/machinable.rb:55:in make!' from /Users/inspire/.rvm/gems/ree-1.8.7-2010.02/gems/machinist-2.0.0.beta2/lib/machinist/machinable.rb:94:indecode_args_to_make'
from /Users/inspire/.rvm/gems/ree-1.8.7-2010.02/gems/machinist-2.0.0.beta2/lib/machinist/machinable.rb:53:in make!' from ./spec/blueprints.rb:43 from /Users/inspire/.rvm/gems/ree-1.8.7-2010.02/gems/machinist-2.0.0.beta2/lib/machinist/active_record/lathe.rb:8:inmake_one_value'
from /Users/inspire/.rvm/gems/ree-1.8.7-2010.02/gems/machinist-2.0.0.beta2/lib/machinist/lathe.rb:46:in make_attribute' from /Users/inspire/.rvm/gems/ree-1.8.7-2010.02/gems/machinist-2.0.0.beta2/lib/machinist/lathe.rb:30:inmethod_missing'
from ./spec/blueprints.rb:43
from /Users/inspire/.rvm/gems/ree-1.8.7-2010.02/gems/machinist-2.0.0.beta2/lib/machinist/blueprint.rb:26:in instance_eval' from /Users/inspire/.rvm/gems/ree-1.8.7-2010.02/gems/machinist-2.0.0.beta2/lib/machinist/blueprint.rb:26:inmake'
from /Users/inspire/.rvm/gems/ree-1.8.7-2010.02/gems/machinist-2.0.0.beta2/lib/machinist/machinable.rb:39:in make' from /Users/inspire/.rvm/gems/ree-1.8.7-2010.02/gems/machinist-2.0.0.beta2/lib/machinist/machinable.rb:94:indecode_args_to_make'
from /Users/inspire/.rvm/gems/ree-1.8.7-2010.02/gems/machinist-2.0.0.beta2/lib/machinist/machinable.rb:38:in `make'
from (irb):17ree-1.8.7-2010.02 >
ree-1.8.7-2010.02 >

Has and belongs to many documentation

Hi:

Supposed I have a model Location which is linked to many categories through a location_categories table:
has_many :location_categories, :dependent => :destroy
has_many :categories, :through => :location_categories
validates_presence_of :categories

How could I possibly create the objects for that via Machinist. What I learned now is I need a helper method to create the plan for the Location first, then create the Categories and assign them to the plan, then create the final object.
And if my next model is validating the presence of a Location I would need another helper method?

It seems it's not supported in Machinist by default or through some other methods due to various reasons (ActiveRecord not suitable etc etc.). So if anyone knows a solution, pls. add it here and get it included in the README.

BR,
Seb

Lack of Encoding Awareness (Reopened)

I seem to have discovered a lack of encoding awareness.

Given the following environment
• Ruby 1.9.1 p378
• Rails Edge ( 3.0 b3 + @ SHA: 19cecc90 )

I see the following behavior:

ruby-1.9.1-p378 > Player.make(:name => "Peter Jöback").name.encoding
 => # Encoding:ASCII-8BIT
ruby-1.9.1-p378 > Player.new(:name => "Peter Jöback").name.encoding
 => # Encoding:UTF-8

(reopened because Github keyboard shortcuts pwned me.)

set_primary_key in ActiveRecord models is not supported?

Almost all of my classes use _id as primary key. So we write:

class Category < ActiveRecord::Base
  set_primary_key '_id'

That will break the Machinist sometimes. It broke the Category model, another model is fine.

class Device < ActiveRecord::Base
  set_primary_key '_id'

So for Category I have to use:
Category.blueprint do
title
parent_category_id { nil }
_id { 2 } # not yet randomized, I know..
end

Is that a known issue?

nested blueprint classes don't inherit boolean values

I have a class structure in my rails app like this:

C > B > A

My blueprints file is like this:

A.blueprint do
a_string { "foo" }
a_boolean { true }
end

B.blueprint do
A
end

C.blueprint do
B
end

...so the values for a_string and a_boolean should show up when I do a C.make. But they don't. a_boolean keeps coming up blank in C. It work properly when I paste "a_boolean { true }" inside the blueprint for C but that's not DRY.

Machinist.with_save_nerfed doesn't restore old value

It resets @@nerfed to false even if it was already true. This causes the following to fail:

    Post.blueprint { }
    Comment.blueprint { }
    Comment.blueprint(:with_unvalidated_post) do
      post { Post.make_unsaved {|p| p.save(false)} }
    end
    Comment.make_unsaved(:with_unvalidated_post).should be_new_record

provide attribute generators with an index parameter

Often I want to define a quick indexed generator that's specific to a particular model and attribute. It would be nice if I could use this syntax:

Post.blueprint do
  title {|index| "Post #{index}"}
end

Sometimes moving an indexed generator like this into a named Sham is a good thing, but in other cases it just impairs readability and pollutes the Sham namespace.

List additional development dependencies

Please consider adding these:
gem.add_development_dependency "activerecord"
gem.add_development_dependency "sequel"
gem.add_development_dependency "dm-core"
gem.add_development_dependency "dm-validations"
gem.add_development_dependency "data_objects"
gem.add_development_dependency "do_sqlite3"

rake spec was giving ugly errors until I installed all of those.

Validation errors should be shown

When #make fails due to validation errors it is not immediately clear which attributes need to be added or changed.

For ActiveRecord I have applied the following hack to get it working:

class ActiveRecord::Base
  class << self
    def make_with_error_presentation(*args, &block)
      make_without_error_presentation(*args, &block)
    rescue ActiveRecord::RecordInvalid => invalid
      raise "#{invalid.message}. The following errors were found: #{invalid.record.errors.full_messages} for #{invalid.record.class.name}"
    end
    alias_method_chain :make, :error_presentation
  end
end

I could supply a patch to get this into machinist if you are interested.

.make! calls in before :all get mysteriously changed

before(:all) do
@U = User.make!
end

describe "blah" do
it "tests" do
puts "old u.id is #{@u.id}"
u2 = User.make!
puts "u.id is now #{@u.id}"
end
end

somehow manages to change my @U's id from 1 to 2 just by calling .make! on another row. I have no idea how this is possible, but it must be related to some weird haxorness.

Moving the .make! call into a before :each fixes the problem, but then the tests take twice as long to run (even though its only making 4 simple rows before each of 30 tests).

Innodb. But when I check the logs there are "commits" all over, so clearly using transactions isn't working as expected?

Should be able to set a known seed value

As per discussion here:

http://github.com/notahat/machinist/issues#issue/7

This is related to the seed value that machinist sets...

Setting the random seed has several effects...

a) you can get issues like above where it seems the other library resets the seed before generating... meaning that machinist sets it back and you always get the same value from rand

b) If you use Faker or other library, you will always get the same values as every other person using Faker... potentially a security flaw since rand is no longer random...

My suggestions would be:

  • have faker increment the seed every time it resets it... so the seed is (1) first time, (2) second time, not just (1) every time. Thereby fixing above behaviour.
  • have machinist use a rails constant (if available), so that the randomness is the same for that project, but not every rails project. (I was thinking ActionController::Base.session[:secret])
  • have an option to turn off resetting the seed, so all data from machinist is truely random.

A couple of examples:

Machinist.sham_seed = "abc"
Machinist.sham_seed = ActionController::Base.session[:secret]
#turn on true randomness
Machinist.sham_seed = false

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.