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
Botanicus (author)
Sun Aug 24 01:06:35 -0700 2008
commit  2bccd4ea710d6c19fbd5a93d722338b33adffe45
tree    4a673a395eb50b02882222615d3dca47dee9faf4
parent  9b125fa723a188385feb11d7c533657dbe3810d3
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 Loading commit data...
file Rakefile
file TODO
directory lib/
directory spec/
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