public
Description: Merb plugin that provides flexible fixtures system. DataMapper, ActiveRecord and Sequel is supported.
Homepage:
Clone URL: git://github.com/botanicus/merb-fixtures.git
name age message
file .gitignore Sat Jun 21 08:25:37 -0700 2008 Improved README and TODO, added .gitignore [Botanicus]
file LICENSE Sat Jun 21 04:54:00 -0700 2008 Initial import. [Botanicus]
file README Sun Aug 24 01:06:35 -0700 2008 Used require_fixtures instead of load_fixtures ... [Botanicus]
file Rakefile Wed Aug 13 04:07:48 -0700 2008 Whops. Fixed Fixtures.save and Fixtures.all bug [Botanicus]
file TODO Tue Aug 12 00:59:15 -0700 2008 Added Kernel#load_fixtures for loading fixture ... [Botanicus]
directory lib/ Wed Aug 20 01:02:53 -0700 2008 Oh dear! Fixed bug with Rake tasks. Thanks high... [Botanicus]
directory spec/ Wed Aug 13 05:21:25 -0700 2008 BIG CHANGES: Fixtures's output is hash, not arr... [Botanicus]
README
=== About ===
Fixtures is Merb plugin which provides fixture system for Merb.
  1) Fixtures are written in Ruby, not in YAML, so it's more powerful than YAML one. For example it's much easier to add 
  HABTM relationships.
  2) Fixtures aren't just for testing, but they are useful for development and even for migrations

=== Setup ===
git clone git://github.com/botanicus/merb-fixtures.git
cd merb-fixtures
rake install

# config/init.rb
dependency 'merb-fixtures'

By default, fixtures folder is app/fixtures. If you like to puts your fixtures on other place, feel free to change it in 
your init.rb:
# config/init.rb
Merb::Plugins.config[:fixtures] = {
  :directory => Merb.root / "app" / "fixtures"
}

=== Writing fixtures ===
First you must write a fixture:
# app/fixtures/author.rb
fixture_for(Author, :botanicus) do
  self.first_name = "Jakub"
  self.last_name  = "Šťastný"
  self.nickname   = "Botanicus"
  self.homepage   = "http://botablog.cz"
  self.posts      = [ ... ]
end

=== Usage from merb console or specs ===
Now you can use it - from your specs or just from merb console:
# Get fixture named :botanicus
Author.fixture(:botanicus)
=> #<Author last_name="Šťastný" homepage="http://botablog.cz" first_name="Jakub" nickname="Botanicus">

# Get all the author's fixtures
Author.fixtures
=> [#<Author last_name="Šťastný" homepage="http://botablog.cz" first_name="Jakub" nickname="Botanicus">]

=== Usage in migrations ===
# Usage in migrations
migration 1, "Add default author" do
  up do
    Author.fixture(:botanicus).save
  end
  down do
    # foo
  end
end

=== FAQ ===

== HABTM ==
# TODO: describe different types of associations
class ModelOne
  has 0..n, :model_two
end

class ModelTwo
  belongs_to :model_one
  # model_one_id
end

fixture_for(ModelOne, :one) do
  # foo bar
end

require_fixtures :model_one
fixture_for(ModelTwo, :two) do
  self.model_one = ModelOne.fixture(:model_one)
end

1) save ModelOne