Supporting Hickey version: 0.0.x
Hickey provides a simple way of preparing test data inside your test for Rails project. For making the process of preparing test data fast, Hickey will bypass all model validations and callbacks. Of course, your can enable them when you need.
Run the following if you haven’t already:
gem sources -a http://gems.github.com
Install the gem:
sudo gem install xli-hickey
After installed hickey gem, require ‘hickey’ in your test environment.
Suppose we have a User model that has attributes login and admin
% class User < ActiveRecord::Base % end
We can create a user model by the following code:
% Hickey.dump(:user => {:login => 'xli', :admin => true})
It’s not the simplest way to create user model, but just let you know how it works.
Suppose we have the following models:
% class Project < ActiveRecord::Base % has_many :tags % has_many :cards % end % % class Tag < ActiveRecord::Base % has_many :taggings, :class_name => '::Tagging' % belongs_to :project % end % % class Tagging < ActiveRecord::Base % belongs_to :tag % belongs_to :taggable, :polymorphic => true % end % % class Card < ActiveRecord::Base % has_many :taggings, :as => :taggable % belongs_to :project % end
We can create a domain in the test by the following code:
% Hickey.dump :project => { % :identifier => 'hickey', :cards => [ % { % :name => 'first card', % :taggings => [{:tag => {:name => 'first_tag'}}], % }, % { % :name => 'dont make me think', % :taggings => [{:tag => {:name => 'ignore me'}}] % } % ] % }
Another example for we want to create tag cards with one same tag named ‘first_tag’:
% Hickey.dump :project => { % :identifier => 'hickey', :cards => [ % { % :name => 'first card', % :taggings => [{:tag => {:find_or_create => {:name => 'first_tag'}}}], % }, % { % :name => 'dont make me think', % :taggings => [{:tag => {:find_or_create => {:name => 'first_tag'}}}] % } % ] % }
Hickey is available under an Apache License Version 2.0.
- Author
-
Li Xiao <iam@li-xiao.com>
- Requires
-
Ruby 1.8.6 or later
- License
-
Copyright 2008 by Li Xiao. Released under an Apache License Version 2.0. See the LICENSE file included in the distribution.
This software is provided “as is” and without any express or implied warranties, including, without limitation, the implied warranties of merchantibility and fitness for a particular purpose.