This repository is private.
All pages are served over SSL and all pushing and pulling is done over SSH.
No one may fork, clone, or view it unless they are added as a member.
Every repository with this icon (
) is private.
Every repository with this icon (
This repository is public.
Anyone may fork, clone, or view it.
Every repository with this icon (
) is public.
Every repository with this icon (
Botanicus (author)
Wed Aug 20 01:02:53 -0700 2008
commit 9b125fa723a188385feb11d7c533657dbe3810d3
tree 057cb96a2fcb1a797adaa2e93a7a8d899cd70bd9
parent ad6854731cf58cb5dd673fac3a5368c94561cf3c
tree 057cb96a2fcb1a797adaa2e93a7a8d899cd70bd9
parent ad6854731cf58cb5dd673fac3a5368c94561cf3c
| name | age | message | |
|---|---|---|---|
| |
.gitignore | Sat Jun 21 08:25:37 -0700 2008 | |
| |
LICENSE | Sat Jun 21 04:54:00 -0700 2008 | |
| |
README | ||
| |
Rakefile | Wed Aug 13 04:07:48 -0700 2008 | |
| |
TODO | Tue Aug 12 00:59:15 -0700 2008 | |
| |
lib/ | Wed Aug 20 01:02:53 -0700 2008 | |
| |
spec/ | Wed Aug 13 05:21:25 -0700 2008 |
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
load_fixtures :model_one
fixture_for(ModelTwo, :two) do
self.model_one = ModelOne.fixture(:model_one)
end
1) save ModelOne







