fixtures

Do setup/teardown hurt test maintainability?

This seemed to spark a bit of conversation on another question and I thought it worthy to spin into its own question. The DRY principle seems to be our weapon-of-choice for fighting maintenance problems, but what about the maintenance of test code? Do the same rules of thumb apply? A few strong voices in the developer testing communit...

Do fixtures trigger model callbacks?

Say I have a User model with the following code in User.rb: before_create :create_dependencies after_create :build_inbox And I also have a users.yml file with a bunch of user fixtures defined in it. When I run rake db:fixtures:load, it doesn't appear to trigger the callbacks. Is this how it is expected to work? If so, why did they...

Foreign keys in fixtures in rails 2.0

I'm having problems with my fixtures in Rails. I have two models, a message and a user. The user model is generated from restful authentication. A message has a sender and a recipient, which are both users. When I don't use the fixtures everything works fine. But when I try to use them in fixtures both are nil. This is the messages fi...

Unit testing: Is it a good practice to have assertions in setup methods?

In unit testing, the setup method is used to create the objects needed for testing. In those setup methods, I like using assertions: I know what values I want to see in those objects, and I like to document that knowledge via an assertion. In a recent post on unit tests calling other unit tests here on stackoverflow, the general feelin...

django fixtures: Where to add a fixture file

Hi! I am trying to create a set of test case to cover my django application. I need pre defined database data, to run some of my test. So I decided to use fixtures. What I did was: 1) created fixture file: oleg$ python manage.py dumpdata goserver > fixture1.json 2) Placed the fixture in the directory where application lives oleg...

Rails batch object creation for fixture?

I have a big list of record (something like 20, could be more) with a has_many :through relations, which is a bit complicate and it looks ugly on yml. Factory_girl doesn't seems to give me the simplistic ability to just create the fixture with a AR based script (it's a lot shorter that way) any good recommendation on what I could do? ...

How to make fixtures updateable in Rails' tests?

Below I listed some code from simple Rails application. The test listed below fails in last line, because the updated_at field of the post is not changed within the update action of PostController in this test. Why? This behaviour seems to me a little strange, because standard timestamps are included in Post model, live testing on local...

Ruby on rails: create_fixtures memory problem....

Hello, I have to create around 100k records. Those records are in the csv file and are being loaded using create_fixtures function. It's slow on my development machine but it completes. The problem starts on production where we have memory limits per process which leads to killing the rake process. I think it's because the create_fixtu...

Convert fixtures into Factory Girl in Rails

I'd like to migrate my fixtures to "Factory Girl" in Rails. Is there any easy way to convert all yml files in a factories.rb file? ...

Specifying an empty or nil fixture in Rails

I have the ff. ActiveRecord which I use only for the ID it generates: class SomeTable < ActiveRecord::Base end I thought that one could specify fixtures for it through: one: two: Which I refer to in other fixtures as: other_one: some_field: some value some_table: one But when I run my tests, I get: Fixture::FormatError: Ba...

Django fixture not loading with loaddata.

I've created a json fixture, and put it in my myapp/fixtures/. I've added myapp/fixtures to settings.FIXTURE_DIRS. Here's the output of my attempt to load the fixture: jeff@jeff-linux:~/myapp$ ./manage.py loaddata --verbosity=2 default.json Loading 'default' fixtures... [...truncated checking default paths and installed apps/fixtures......

How can I load HABTM-with-foreign-key relationships in my fixtures ?

I have the following two models: School and User, and a HABTM relationship between them, with a join table. In this join table, the foreign key refering to the User table is not called user_id but student_id. class School < ActiveRecord::Base has_and_belongs_to_many :students, :class_name => "User", :join_table => "schools_students",...

Django: Create fixtures without specifying a primary key?

One of the things that bugs me about Django fixtures is that you've got to specify every model's primary key. Is there any way to create fixtures without having to specify a primary key for each row? ...

Fixture loading works with loaddata but fails silently in unit test in Django

I can load the fixture file in my django application by using loaddata: manage.py loaddata palamut The fixture palamut.yaml is in the directory palamut/fixtures/ I have a unit test module service_tests.py in palamut/tests/. Its content is here: import unittest from palamut.models import * from palamut.service import * from palamut....

Rails fixtures seem to be adding extra unexpected data

Hello, all. I've got a dynamic fixture CSV file that's generating predictable data for a table in order for my unit tests to do their thing. It's working as expected and filling the table with the data, but when I check the table after the tests run, I'm seeing a number of additional rows of "blank" data (all zeros, etc). Those aren't be...

Rails unit testing doesn't load fixtures

Hello together, rake test:units fails in my current application, because the needed data of the fixtures is missing. If I'm loading the fixtures manually via rake db:fixtures:load RAILS_ENV=test the unit tests are working, but rake purges the test database. My test_helper includes fixtures :all and my tests are inheriting from it - bu...

FixtureReplacement with Cucumber

Hi, I am using Cucumber with Selenium, FixtureReplacement and DatabaseCleaner. Funnily enough, my data I created with FixtureReplacement is not accessible from my tests. I have added an own rails environment for selenium and I am using an own profile for my enhanced selenium features. My cucumber setup for the selenium profile is: We...

Django db reset without loading fixtures

Is there an easy way to reset a django database (i.e. drop all data/tables, create new tables and create indexes) without loading fixture data afterwords? What I want to have is just an empty database because all data is loaded from another source (a kind of a post-processed backup). I know that this could be achieved by piping the out...

How can I use more than one set of fixtures per table in Rails?

I want to define alternative sets of fixtures per database table. For example, class BusinessSpec describe "some aspect of businesses" do fixtures :fixture_set_1 ... end describe "some unrelated aspect of businesses" do fixtures :fixture_set_2 ... end end Is this, or something similar, possible? ...

How do I generate Symfony fixtures YML from exising database data?

I was wondering if anyone knew how to generate a fixture.yml from data that is already existing in the database? As you can use the build-schema to generate a schema, is there a way to do that for data? symfony propel:build-schema ...