factory-bot Questions
2
Solved
I am using the rspec_rails and factory_girl_rails gems within my Rails project. All of the models are already created. Is there a generator that I can run that will create the factory file for an e...
Response asked 27/2, 2016 at 5:19
2
Solved
I've combined my user & shift factories to save space.
FactoryGirl.define do
factory :user do
name 'test'
password 'test'
phone_number '1-444-555-8888'
end
factory :shift do
user
end
...
Hautesavoie asked 22/2, 2015 at 0:17
3
I have the following three models: Product, Warehouse and Inventory
# app/models/product.rb
class Product < ApplicationRecord
has_many :inventories
has_many :warehouses, through: :inventories ...
Leahleahey asked 24/11, 2019 at 21:13
3
I have installed FactoryBot and trying to use it with RSpec.
scenario 'User signs in' do
create :user, email: '[email protected]', password: 'testpassword'
visit '/users/sign_in'
fill_in '...
Decastere asked 20/11, 2015 at 14:44
9
Solved
I have a User model that belongs to a Group. Group must have unique name attribute. User factory and group factory are defined as:
Factory.define :user do |f|
f.association :group, :factory =>...
Carothers asked 22/8, 2011 at 9:10
7
Solved
When I create an object via FactoryGirl and Faker, shell show me an error
[1] pry(main)> FactoryGirl.create(:company)
[DEPRECATION] requiring "RMagick" is deprecated. Use "rmagick" instead
bu...
Garamond asked 25/4, 2015 at 14:33
4
Solved
I am using rails console in the development environment and I want to use factories. How can I get access to them?
I have tried require "FactoryBot" which returns
1.9.3p393 :301 > requ...
Luxembourg asked 12/8, 2013 at 20:12
3
Solved
I have 2 factories. Beta_user and Beta_invite. Basically before a Beta_user can validly save I have to create an entry of Beta_invite. Unfortunately these models don't have clean associations, but ...
Lannielanning asked 17/5, 2011 at 1:6
5
Solved
I have been playing with Rails for a couple of years now and have produced a couple of passable apps that are in production. I've always avoided doing any testing though and I have decided to recti...
Christiansand asked 12/4, 2012 at 10:32
3
Solved
Problem localhost:3000/users/ won't display
I enter humbly as I am trying to make it through the rails tutorial for the first time. I am in chapter 10 and I have been trouble shooting this for 5 ...
Prurigo asked 19/12, 2012 at 15:7
3
I have an existing Factory (order), and I am trying to make a new factory that effectively inherits from it. It looks like this:
factory :order_with_domain, :parent => :order do |o|
o.order_pr...
Transfix asked 15/3, 2018 at 16:43
3
Solved
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 < Veh...
Largescale asked 20/5, 2018 at 18:11
3
Solved
Is it possible to define a default trait in FactoryGirl? If I define a factory like this (where both question_response belongs_to question):
factory :question_response do
question
work_history
...
Dove asked 14/6, 2015 at 13:37
2
Solved
Here's my models :
Class Audition
belongs_to :video
end
Class Video
has_one :audition
end
and my factories :
Factory.define :video do |v|
v.filename {Sham.filename}
v.video_url {Sham.url}
...
Dahl asked 10/2, 2010 at 16:44
6
Solved
I had a method in a model:
class Article < ActiveRecord::Base
def do_something
end
end
I also had a unit test for this method:
# spec/models/article_spec.rb
describe "#do_something" do
@a...
Cervical asked 21/5, 2013 at 19:12
4
Solved
There is help online for using select2 with capybara (see links below), but no help in particular as far as I have seen for select2 drop-down fields. I have tried all kinds of things, including try...
Higgins asked 21/12, 2016 at 7:39
2
Solved
I'm using factory_bot to create objects in my test, here is a example of my factory:
factory :user do
name "John"
surname "Doe"
trait :with_photo do
ignore do
photo_count 1
end
after(:cre...
Overwhelm asked 17/1, 2014 at 14:8
3
Solved
#rspec test code
@room = FactoryGirl.build(:room)
#factory definition
factory :room do
length {10}
width {20}
end
#code implementation
class Room
attr_accessor :length, :width
def initialize...
Risley asked 26/7, 2011 at 23:19
3
Solved
I'm trying to use Factory Girl in a rake task like this:
require 'factory_girl'
require File.expand_path("spec/factories.rb")
namespace :users do
desc "Create sample users for use in developmen...
Egan asked 10/11, 2011 at 17:8
7
Solved
When I am writing unit tests in dynamically-typed Ruby or Python, I use the libraries factory_girl and factory_boy, respectively, in order to conveniently generate objects under test. They provide ...
Descartes asked 18/2, 2015 at 4:59
5
Solved
I want to use FactoryGirl.attributes_for in controller testing, as in:
it "raise error creating a new PremiseGroup for this user" do
expect {
post :create, {:premise_group => FactoryGirl.attr...
Bond asked 24/4, 2012 at 0:42
2
I still can't find a solution to fix an association factory issue when using Sequel.
I have two models relying on one_to_many, which is the same as has_manyin Active Record, and many_to_one, which...
Cetacean asked 24/4, 2017 at 14:4
0
I am trying to put a conditional piece of logic into a factory that will only run if a specific trait has been passed in as an argument. I am inside the to_create block so have access to the instan...
Attainable asked 22/5, 2019 at 13:12
3
Is there some configuration in a factory of factory girl/machinist that forces it to create objects with the same factory name just once during test case and return the same instance all the time? ...
Schoolbook asked 30/11, 2010 at 19:48
2
Solved
What is the purpose of transient do in FactoryBot factories?
I've seen a lot of factories that begin with something like below.
factory :car do
owner nil
other_attribute nil
end
...
I've found s...
Legator asked 25/7, 2016 at 16:34
© 2022 - 2024 — McMap. All rights reserved.