fixtures

Ruby on Rails deleting fixtures with foreign keys

喜你入骨 提交于 2019-12-03 14:58:52
I'm having trouble setting up the tests with fixtures that use foreign keys! And I would be much appreciated if someone could help me understand this. Let's say for example the :user_type model has a reference to the :role model, when tests get executed, and all the data in the test db is deleted to be again re-inserted, Rails deletes the data from the role model first, instead of deleting the data first from the :user_type and only then from :role . The fixtures: #roles.yml technical: name: 'Technical' obs: 'User Role for technical / maintenance users!' #user_types.yml technic: role:

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

耗尽温柔 提交于 2019-12-03 14:52:28
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 for the code. If I have hard-coded fixture values, it's hard to reveal what a particular test is

Fixtures in Play! 2 for Scala

人走茶凉 提交于 2019-12-03 14:02:08
问题 I am trying to do some integration testing in a Play! 2 for Scala application. For this, I need to load some fixtures to have the DB in a known state before each test. At the moment, I am just invoking a method that executes a bunch of Squeryl statements to load data. But declaring the fixtures declaratively, either with a Scala DSL or in a language like JSON or YAML is more readable and easy to mantain. In this example of a Java application I see that fixtures are loaded from a YAML file,

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

我们两清 提交于 2019-12-03 13:18:21
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", :foreign_key => "student_id" end class User < ActiveRecord::Base has_and_belongs_to_many :studying_schools, :class_name => "School", :join_table => "schools_students", :foreign_key => "school_id" end I would like to create in my Users and Schools fixtures a

Error while integrating html with testacularjs

馋奶兔 提交于 2019-12-03 13:07:37
How do I integrate (html) fixtures with testacular? Is there any recommendation for performing DOM based tests or is it an anti-pattern? Objective : I am trying to test a custom module which parses the DOM tree and creates a new data structure. The DOM tree can be dynamic (like contents of a html/markdown editor) and hence is not a good candidate for end to end testing Problem : I am trying to use jasmine-jquery for this DOM testing and in my testacular.conf.js, I have the section to allow loading of html files into the browser. // list of files / patterns to load in the browser files = [

Doctrine 2. orm:schema-tool:update . Set start id

心已入冬 提交于 2019-12-03 12:32:32
问题 When I use ./bin/doctrine orm:fixtures:load to populate tables with sample data first migration sets auto incremental table id like 1,2,3,4,5 etc... After second orm:fixtures:load migration command it purges all data and sets ids like 5,6,7,8,9 and so on... How can I reset AI id counter to 1 when I load fixtures many times? 回答1: $ app/console help doctrine:fixtures:load By default Doctrine Data Fixtures uses DELETE statements to drop the existing rows from the database. If you want to use a

Rails 3 test fixtures with carrierwave?

放肆的年华 提交于 2019-12-03 11:17:00
问题 I'm working on upgrading from attachment_fu to carrierwave, since attachment_fu is broken in rails 3. None of the tests are able to run, because we have invalid fixtures that were using the syntax from attachment_fu for attachment files. For example, we have a Post model that has one PostAttachment. Here's what the data in the PostAttachment fixture looks like: a_image: post_id: 1 attachment_file: <%= Rails.root>/test/files/test.png And this is the error I'm getting: ActiveRecord:

What is the difference between “rake db:seed” and rake db:fixtures:load\"

核能气质少年 提交于 2019-12-03 09:06:43
I am new to Ruby and Rails and am curious about something. In two different tutorials I am looking at they use different methods for populating a database with basic test information. One uses "rake db:seed" to pull from a text file with sample data. The other uses "rake db:fixtures:load". To me they appear to do the exact same thing. Do they, or am I missing something here? (Highly likely) rake db:seeds loads the data from db/seeds.rb into the database. This is generally used for development and production databases. It's permanent data that you use to start an empty application. More

Can I pass arguments to pytest fixtures?

妖精的绣舞 提交于 2019-12-03 08:15:44
The baseline of all my tests is that there will always be a taxi with at least one passenger in it. I can easily achieve this setup with some basic fixtures: from blah import Passenger, Taxi @pytest.fixture def passenger(): return Passenger() @pytest.fixture def taxi(passenger): return Taxi(rear_seat=passenger) Testing the baseline is straightforward: def test_taxi_contains_passenger(taxi) assert taxi.has_passenger() My issue crops up when I start needing more complicated test setup. There will be scenarios where I'll need the taxi to have more than one passenger and scenarios where I'll need

Python factory_boy library m2m in Django model?

让人想犯罪 __ 提交于 2019-12-03 07:34:40
问题 I'm currently using factory_boy for creating fixtures in my tests. Factory_boy docs only mentioned about SubFactory which could act like a ForeignKey field in a model. However, there was nothing on ManyToMany association. If I had a following Post model, how would I go about creating a factory for it? class Post(models.Model): title = models.CharField(max_length=100) tags = models.ManyToManyField('tags.Tag') class PostFactory(factory.Factory): FACTORY_FOR = Post title = 'My title' tags = ???