fixtures

Rails Foxy Fixtures throwing unknown column error

I am using dynamic fixtures and whenever I run my tests I am getting an error that thinks my association is a column, when it should be owner_id: ActiveRecord::StatementInvalid: Mysql::Error: Unknown column 'owner' in 'field list': INSERT INTO `companies` (`custom_host`, `name`, `created_at`, `updated_at`, `api_key`, `id`, `subdomain`, ...

Prevent Rails test from deleting seed data

I am using seeds.rb to populate some State model reference data: State.create :name => 'Alabama', :abbreviation => 'AL' State.create :name => 'Alaska', :abbreviation => 'AK' # ... Although I am not using state fixtures (since it's seed data to begin with, I think it wouldn't be DRY to have to duplicate this purely for tests), the Rail...

django fixtures: load multiple fixtures on syncdb

Hi, I have a lot of things in my initial_data.json right now. I wondered if there is a way to split the data in files (by model) so that all of the files are loaded via same manage syncdb command? Thanks, Nick I recently revisited the problem, and came up with a better way of hooking code to 'real' post_syncdb signal: http://www.dja...

Rails fixtures - defining a table name?

Hi, At the minute all my fixtures have the same name as the table that they are intended for, because of a recent issue with rails it doesn't seem possible to have a fixture beginning with the word 'test' Does anyone know of a way to have a different fixture name and then map it to the correct table? Thanks, Andy ...

Rails Fixtures not loading with rspec

So, I'm trying to learn the rspec BDD testing framework in the context of a rails project. The problem I'm having is that I can't, for the life of me, get my fixtures to load properly in rspec descriptions. Disclaimer: Yes, there are better things than fixtures to use. I'm trying to learn one thing at a time, here (specifically rspec)...

Using factory_girl in Rails with associations that have unique constraints. Getting duplicate errors.

I'm working with a Rails 2.2 project working to update it. I'm replacing existing fixtures with factories (using factory_girl) and have had some issues. The problem is with models that represent tables with lookup data. When I create a Cart with two products that have the same product type, each created product is re-creating the same pr...

Django JSON fixture generation

I'm new to Django coming from Rails, and I am finding the Django fixtures (most commonly JSON from what I gather), to be somewhat awkward and unweildy, at least in comparison to the rails fixtures that I am familiar with. I liked being able to embed some ruby code, e.g <%= Time.now %>, or reference other fixtures by name when relating ...

translation in django fixtures

Here is example initial_data.json. I want let django store value from column 'name' into translation file. So later, when value is printed somewhere, it could use its translated value. Is there any way to do it? Thanks. [ {"pk": 1, "model": "category.category", "fields": {"name": "Report"}}, {"pk": 2, "model": "category.category", "fiel...

Ruby on Rails and db:fixtures:load - can it ignore some models?

I have two databases in use in a Ruby on Rails application; one is the database for the application while the second is an independent database over which Rails is not given control. Problem is when loading fixtures into the dev, it tries to run DELETE statements on the tables in the independent database from the connection to the dev d...

loading fixtures for django tests

Hi, I want to use some fixtures in my tests. I have cms_sample app and a fixtures folder inside with cms_sample_data.xml I use the following in my test.py: class Funtionality(TestCase): fixtures = ['cms_sample_data'] I do use TestCase of django.tests and not unittest. But the fixtures are not loaded. What am I missing? Th...

Test does not load many to many fixture

I am using Test to test my application. I have some fixtures: users.yml, roles.yml, roles_users.yml. The users and roles are loaded but not the many to many table roles_users so the users are not related to any role. With Rails console in development everything is ok, in test any user is not connected to any role. I can see the users and...

Using fixtures without a corresponding model in Rails

I currently have some large strings that I would like use as test data when testing a log scraper. It would work well to have these strings in a YAML file. I would love to refer to them while testing in a short and concise manner such as: log_lines(:incorrect_string) Is there anyway to do this using fixtures, or are they exclusively...

Referencing fixtures from the same type in Rails

In associations between different models, one can avoid setting foreign key IDs directly by using fixture names as in this answer. What about self-referencing associations, such as when using acts_as_tree? Trying this: # categories.yml forsale: name: For Sale parent_id: nil books: name: Books parent: forsale I get this error:...

Rails DB seed with yml files sometimes removes and re-adds existing records, sometimes not. What gives?

I have a rails project with seeds that are executed using rake db:seed. This in turn loads the RB files in the db/seeds directory which in turn executes something like this: Fixtures.create_fixtures("db/seeds","projects") There is a projects.yml in the form project_name1: property: value project_name2: property: value In the ...

How to have nameless YAML fixtures in Rails?

Let's say we have. apple: name: apple orange: name: orange grape: name: grape Can this turn into something below? name: apple name: orange name: grape Because I have like 25 items, manually name them is really a valueless job. ...

Rails Single Table Inheritance with HABTM Fixture in unit testing returning NoMethodError: undefined method `singularize'

Imagine a model structure as follows: models/cross_sell_promotion.rb class CrossSellPromotion < Promotion has_and_belongs_to_many :afflicted_products, :join_table => :promotion_afflicted_products, :foreign_key => 'promotion_id', :association_foreign_key => 'product_id', :class_name => 'Product' has_and_belongs_to_...

Which is the best way to randomly generate a list of fixtures?

I have an even number of teams and I need to create a list of fixtures. The rule is that a team that plays a fixture at home will play the next one away. What do you think is the best aproach for this problem? So the problem is to generate half of the fixtures, the other will be generated reversing home - away. So, if I have 6 teams {A...

Django shift to PostgreSQL fails to import fixtures, stating data too long

I am switching from using SQLite3 to PostgreSQL, and hoped that I could populate the database using the fixtures I had been using to populate SQLite3. However, I am getting these errors: $ python manage.py loaddata fixtures/core.json fixtures/auth.json Installing json fixture 'fixtures/core' from absolute path. Problem installing fixtu...

ruby-on-rails: Seeding-data strategies (or loading test data into developer database)

I want to clear and re-load my developer database (Ruby on rails) frequently. Of course, I can manually add the data via the web page but I was wondering if anyone has any strategies for this type of testing. (I already have unit, functional and integration tests, fyi) Thanks ...

How to load sql fixture in Django for User model?

Hi folks, Does anyone knows how to load initial data for auth.User using sql fixtures? For my models, I just got have a < modelname >.sql file in a folder named sql that syncdb does it's job beautifully. But I have no clue how to do it for the auth.User model. I've googled it, but with no success. Thanks in advance, Aldo ...