factory-bot

FactoryGirl creates incomplete model

旧街凉风 提交于 2019-12-11 19:42:24
问题 Assume that I have a city model where: class city field :full_name, type: String # San Francisco, CA, United States field :_id, type: String, overwrite: true, default: ->{ full_name } end Assume that I have a factory defined in /spec/factories/cities.rb : FactoryGirl.define do factory :city do full_name 'San Francisco, CA, United States' end end Running the following code in one of the specs: city_attrs = { full_name: 'San Francisco, CA, United States' } City.create! city_attrs => #<City _id:

How do you create parent objects for a factory using before(:create) without sparking the parents' after_create callback?

依然范特西╮ 提交于 2019-12-11 18:43:23
问题 I am trying to get this spec to pass: it "queues up AbsenteeReservationEmailerJob" do ActiveJob::Base.queue_adapter = :test expect { subject }.to enqueue_job(AbsenteeReservationEmailerJob) end My factory looks like so: FactoryBot.define do factory :absentee_reservation do amount_cents { 10_000 + rand(1_000_000) } creator { create(:user) } before(:create) do |absentee_reservation| auction = create(:auction_with_one_item_one_bidder) item = auction.items.first absentee_reservation.auction =

FactoryGirl Not Registered (Only one factory runs into this)

╄→尐↘猪︶ㄣ 提交于 2019-12-11 17:45:12
问题 I have three models: users, sites, and passports. users and sites has and belongs to many each other, while passports is the join model with a couple of extra columns. I've tried both of the following: 1. FactoryGirl.define do factory :passports do association :site, factory: :site association :user, factory: :user access_token 'mock_token' end end 2. FactoryGirl.define do factory :passports do access_token 'mock_token' end end And either way, I'm using it with: let(:site) { FactoryGirl

validation error through FactoryGirl

旧巷老猫 提交于 2019-12-11 17:17:16
问题 I have problems on validating my data through FactoryGirl. For team.rb, the custom validations are has_only_one_leader and belongs_to_same_department class Team < ActiveRecord::Base attr_accessible :name, :department, :active has_many :memberships has_many :users, through: :memberships accepts_nested_attributes_for :memberships, :users validates :department, inclusion: [nil, "Architectural", "Interior Design"] validates_uniqueness_of :name, scope: :department, conditions: -> { where(active:

Factory Girl + Rspec gives following error: ActionView::Template::Error: (object id) is not id value

拜拜、爱过 提交于 2019-12-11 16:24:52
问题 I defined a Course >> Level >> and Step in factory girl. Step belongs to level and level belongs to course (each of them has a has_many relationship the other way). Here is the error (I am not even sure where to start): Failure/Error: before { visit course_level_step_path(course.id, level.id, step.id)} ActionView::Template::Error: 0x003fe5daf528a0 is not id value Here is my required route: course_level_step GET /courses/:course_id/levels/:level_id/steps/:id(.:format) steps#show Here my rspec:

Using FactoryGirl to create a parameter string for controller testing with related models

試著忘記壹切 提交于 2019-12-11 11:47:47
问题 I added a validation rule to a model which makes sure the record has a related record in another model. Pretty simple. Only thing is, this broke my controller test in which I'm checking that posting to the method creates a new record: it "should create a new recipe" do expect{ post :create, recipe: FactoryGirl.build(:recipe).attributes }.to change(Recipe,:count).by(1) end Problem seems to be, that calling attributes on the factory only returns attributes for the base model (recipe) and not

FactoryGirl - Validation failed: Time zone is not included in the list

只愿长相守 提交于 2019-12-11 10:31:34
问题 I'm using Rspec, FactoryGirl and Capybara. When using ActiveSupport::TimeZone.us_zones. I run my test for my requests/users_spec and it doesn't even hit the test as it has an issue at the Factory. Here is the error: Failure/Error: make_user_and_login ActiveRecord::RecordInvalid: Validation failed: Time zone is not included in the list # ./spec/support/user_macros.rb:3:in `make_user_and_login' # ./spec/requests/users_spec.rb:7:in `block (3 levels) in <top (required)>' This is my setup: app

RSpec test with factory_girl and will_paginate for associated objects

做~自己de王妃 提交于 2019-12-11 05:58:25
问题 I am having problems with writing a test in rspec for will_paginate. The problem is that I have a model with an Owner that can have many pets. This leads to a factories.rb file that looks like this: Factory.define :owner do |owner| owner.personid "1111111" owner.firstname "Nisse" owner.lastname "Gunnarsson" owner.street "Street" owner.postaladress "38830" owner.town "Town" owner.phone "555-5555" owner.mobile "555-5556" owner.email "nisse@test.com" owner.reminder true end Factory.define :pet

Using Factory Girl with Rspec Views

牧云@^-^@ 提交于 2019-12-11 04:05:06
问题 So I want to test some views using Rspec and Factory Girl, but I don't know how to assign a factory to a view properly. All of the information I see online uses stubbing, and although stubbing is fine, I want to keep my rspec stuff somewhat consistent. I want to use a factory for an edition model and associate that with the page when I render the page, but everything I've considered seems to be broken. Here's sort of a ridiculous example: require 'spec_helper' describe "catalog/editions

FactoryBot namespaced models without class_name

蓝咒 提交于 2019-12-11 03:09:44
问题 I have models which are namespaced such as this: class Vehicle < ActiveRecord::Base; end class Vehicle::Car < Vehicle; end class Vehicle::Train < Vehicle; end class Vehicle::Jet < Vehicle; end When creating factories for these models, they were set up in the following way: factory :vehicle_car, class: Vehicle::Car do; end factory :vehicle_train, class: Vehicle::Train do; end factory :vehicle_jet, class: Vehicle::Jet do; end This produces the following deprecation warning: DEPRECATION WARNING: