fixtures

Is it a bad practice to randomly-generate test data?

纵然是瞬间 提交于 2019-12-21 04:40:50
问题 Since I've started using rspec, I've had a problem with the notion of fixtures. My primary concerns are this: I use testing to reveal surprising behavior. I'm not always clever enough to enumerate every possible edge case for the examples I'm testing. Using hard-coded fixtures seems limiting because it only tests my code with the very specific cases that I've imagined. (Admittedly, my imagination is also limiting with respect to which cases I test.) I use testing to as a form of documentation

factory_girl + rspec doesn't seem to roll back changes after each example

戏子无情 提交于 2019-12-20 17:34:23
问题 Similar to the problem described here: http://rpheath.com/posts/411-how-to-use-factory-girl-with-rspec in Short (shorten'd code): spec_helper: config.use_transactional_fixtures = true config.use_instantiated_fixtures = false factories.rb: Factory.define :state do f.name "NY" end in my spec before(:each) do @static_model = Factory(:state) # with validate uniqueness of state name end error: duplicate entry name "NY" etc. Question: Shouldn't rspec clear database before each spec example and

Is seeding data with fixtures dangerous in Ruby on Rails

隐身守侯 提交于 2019-12-20 12:28:43
问题 I have fixtures with initial data that needs to reside in my database (countries, regions, carriers, etc.). I have a task rake db:seed that will seed a database. namespace :db do desc "Load seed fixtures (from db/fixtures) into the current environment's database." task :seed => :environment do require 'active_record/fixtures' Dir.glob(RAILS_ROOT + '/db/fixtures/yamls/*.yml').each do |file| Fixtures.create_fixtures('db/fixtures/yamls', File.basename(file, '.*')) end end end I am a bit worried

Loading fixtures in django unit tests

99封情书 提交于 2019-12-18 13:54:08
问题 I'm trying to start writing unit tests for django and I'm having some questions about fixtures: I made a fixture of my whole project db (not certain application) and I want to load it for each test, because it looks like loading only the fixture for certain app won't be enough. I'd like to have the fixture stored in /proj_folder/fixtures/proj_fixture.json. I've set the FIXTURE_DIRS = ('/fixtures/',) in my settings.py. Then in my testcase I'm trying fixtures = ['proj_fixture.json'] but my

Rails fixtures — how do you set foreign keys?

安稳与你 提交于 2019-12-18 03:49:09
问题 I'm reading about Rails fixtures in this guide (thanks, trevorturk). It appears you define classes in a Yaml file and they're automatically loaded into the test DB -- cool. But if you want to specify that this recipe belongs to that cookbook (or whatever) how do you do that? Are you supposed to specify the values for cookbook.id and recipe.cookbook_id by hand in the Yaml code? (Just a guess -- the guide doesn't show anything like that.) Or is there a more suitable way? 回答1: You should use

Rails unit testing doesn't load fixtures

ぐ巨炮叔叔 提交于 2019-12-18 03:32:10
问题 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 - but the fixtures are simply not loading. I'm kind of clueless at the moment and could really need some help! I've tried a lot and I think it has to do with some environment

How to load sql fixture in Django for User model?

烈酒焚心 提交于 2019-12-17 22:21:54
问题 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 回答1: For SQL fixtures, you'd have to specifically have insert statements for the auth tables. You can find the schema of the auth tables with the command python manage.py sql auth .

How do I prevent fixtures from conflicting with django post_save signal code?

被刻印的时光 ゝ 提交于 2019-12-17 07:12:29
问题 In my application, I want to create entries in certain tables when a new user signs up. For instance, I want to create a userprofile which will then reference their company and some other records for them. I implemented this with a post_save signal: def callback_create_profile(sender, **kwargs): # check if we are creating a new User if kwargs.get('created', True): user = kwargs.get('instance') company = Company.objects.create(name="My Company") employee = Employee.objects.create(company

Rails won't find CSV fixtures

假如想象 提交于 2019-12-13 19:13:13
问题 I am trying to use CSV fixtures, but when I do rake db:fixtures:load , it complains about the lack of YAML files in test/fixtures . Everything works fine when the fixtures are in YAML and the files end in .yml . Furthermore, when I look at the code in activerecord-3.2.3/lib/active_record/fixtures.rb , I see absolutely no reference to CSV processing. It appears that fixtures.rb only knows how to use YAML fixtures. What is up here? Have CSV fixtures been deprecated? 回答1: CSV Fixtures are

php create fixtures with automatic relations

谁都会走 提交于 2019-12-13 07:15:24
问题 I'm currently looking into fixtures for a website with a lot of relations between data. Let's say there is a league table which is in relation with teams table which is in relation with members table. I briefly checked Alice library to handle data "randomization" and other stuff. But I have a question whether there is a library (or way), that would allow me to create "dependent" fixtures? For example I would set template for league to automatically create 20 teams where each team would