fixtures

Functional testing with Rails and Devise. What to put in my fixtures?

一笑奈何 提交于 2019-11-27 04:04:13
问题 Hi I'm wanting to do some functional testing of my Rails 3 app that uses Devise and CanCan. In my User model I have the users age, I want to test that a user can only visit a certain page if they are: Logged in Over 35 I have seen in the Devise document that I can use: *sign_in* and I have put it in my tests and it appears to work - the test doesn't error because I have: include Devise::TestHelpers in my *test_helper.rb* When I take it out my test does error because *sign_in* is not defined.

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

£可爱£侵袭症+ 提交于 2019-11-27 03:16:48
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=company, name_first=user.first_name, name_last=user.last_name) profile = UserProfile.objects.create(user

Loading Rails Fixtures in a Specific Order when Testing

早过忘川 提交于 2019-11-27 02:14:43
问题 Is there a way to load Rails fixtures in a specific order while running tests? For example, take the following classes... class User < ActiveRecord::Base has_many :memberships has_many :groups, through: :memberships end class Group < ActiveRecord::Base has_many :memberships has_many :users, through: :memberships end class Membership < ActiveRecord::Base belongs_to :user belongs_to :group end Memberships have a database level foreign key constraint requiring Users and Groups to be present

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

让人想犯罪 __ 提交于 2019-11-27 00:02:00
问题 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 product type. This errors from a unique validation on the ProductType model. Problem Demonstration This is from a unit test where I create a Cart and put it

Prevent Rails test from deleting seed data

时光怂恿深爱的人放手 提交于 2019-11-26 22:58:03
问题 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 Rails testing framework seems to delete all the State seed data during testing. (I am dropping, recreating, migrating and reseeding the test db, and confirmed the

Do fixtures trigger model callbacks?

霸气de小男生 提交于 2019-11-26 20:53:12
问题 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 design it this way? Is there a way to force the triggering of the callbacks when loading fixtures? 回答1: Is this how it is expected to work? If so, why did they

Pass a parameter to a fixture function

拜拜、爱过 提交于 2019-11-26 11:50:41
问题 I am using py.test to test some DLL code wrapped in a python class MyTester. For validating purpose I need to log some test data during the tests and do more processing afterwards. As I have many test_... files I want to reuse the tester object creation (instance of MyTester) for most of my tests. As the tester object is the one which got the references to the DLL\'s variables and functions I need to pass a list of the DLL\'s variables to the tester object for each of the test files

Problems with contenttypes when loading a fixture in Django

女生的网名这么多〃 提交于 2019-11-26 06:04:35
问题 I am having trouble loading Django fixtures into my MySQL database because of contenttypes conflicts. First I tried dumping the data from only my app like this: ./manage.py dumpdata escola > fixture.json but I kept getting missing foreign key problems, because my app \"escola\" uses tables from other applications. I kept adding additional apps until I got to this: ./manage.py dumpdata contenttypes auth escola > fixture.json Now the problem is the following constraint violation when I try to