I need to test this complicated model that acts as a tree. I have a
fairly complex fixture for it with many tests happily running on it.
Now I need a second, completely different fixtures to test the same
model.
I tried to name it: items2.yml
And then I create items2_test.rb and call:
fixtures :items2
But it fails saying: table "items2" does not exist. It seems that the
"fixtures" call is trying to delete all elements from a table with the
same name.
Is there a way to have 2 different fixtures for the same database
table (and model)?
Cheers
Cyrille
first_one:
id: 1
some_field: "Some data"
another_field: 69
second_one:
id: 2
some_field: "Some different data"
Thanks for your response.
I need to give you a bit more details:
I am testing a model that acts as a tree and I need different
combinations.
For instance, in my first set of data, I have a root, then 3 children.
I would like to test with a root and only 2 children.
I just found a patch that would solve my problem: http://
dev.rubyonrails.org/ticket/1911
It adds a keyword fixture that can be used as:
fixture :items2, :table_name => "items", :file_name => "items2"
Unfortunately, it was apparently not included in Rails 1.2.1. Hmmm...
Cyrille
I did this once ... I wanted another specific fixture for a test. I
did something like this:
def setup
User.delete_all
filename = './test/fixtures/users_fixture_for_test.yml'
YAML.load_file(filename).each {|key, value|
User.create(value)
}
end
HTH
Shane
--
Shane Mingins
good idea! A hack, but less scary than patching Rails...
Thanks for that.
Cyrille
On Feb 16, 6:00 am, "Shane Mingins" <shane.ming...@gmail.com> wrote:
> Hi Cyrille
>
> I did this once ... I wanted another specific fixture for a test. I
> did something like this:
>
> def setup
> User.delete_all
> filename = './test/fixtures/users_fixture_for_test.yml'
> YAML.load_file(filename).each {|key, value|
> User.create(value)
> }
> end
>
> HTH
> Shane
>