factory-bot Questions
3
Solved
I have this example
FactoryGirl.define do
@site = FactoryGirl.create(:my_site)
factory :user do
email { Faker::Internet.email }
first_name { Faker::Name.first_name }
last_name { Faker::Name.l...
Dickson asked 6/7, 2012 at 14:56
5
Solved
I'm making a big change in my system, so I changed one of my main tables into a STI, and create subclasses to implement the specific behavior.
class MainProcess < ApplicationRecord
end
class P...
Ruminant asked 15/8, 2019 at 3:8
3
Solved
A user has many comments, so I would like to have a factory user with a comment associated to it (user_with_comment):
factory :user, class: User do |t|
...
factory :user_with_comment do |t|
aft...
Aircraft asked 12/2, 2015 at 16:31
6
Solved
I tried to test my Rails 3 application on Windows with RSpec. I've wrote tests and factories, but can't solve the issues which raise when I run RSpec on command line.
Here is one of the test file...
Evanesce asked 7/1, 2013 at 0:22
9
Solved
When including the factory_bot_rails gem in your dev and test blocks in Gemfile, rails will generate factories automatically when your models are generated.
Is there a way to generate factories aft...
Wooten asked 28/7, 2012 at 15:22
6
Solved
This is my factory girl code, and every time I try to generate a review, it's telling me that "Email has already been taken", i've reset my databases, set the transition in spec_helper to true, but...
Aluminous asked 5/4, 2011 at 5:46
2
Solved
I'm creating some test to test a controller and model. When I use FactoryGirl to create fake data I'm getting errors that the User (which the record belongs to) does not exist.
Here is my model c...
Microsurgery asked 14/2, 2017 at 9:16
8
Solved
Using rails, devise, rspec & factorygirl:
Trying to create some tests for my site. I'm using the confirmable model for devise so when I create a user using FactoryGirl, the user isn't confirme...
Matthew asked 25/8, 2012 at 19:35
1
Is there a way I can access test fixtures from within my factories? I'm trying to do something like:
Factory.define do
factory :foo do
user { users(:active) }
end
end
Ingraham asked 2/10, 2015 at 23:5
3
i'm testing with rspec, factory_girl and capybara. The project uses devise, i have the following method to login inside the specs:
def login_admin
before(:each) do
@request.env["devise.mapping"] ...
Misadvise asked 24/9, 2014 at 17:45
28
Description of problem:
- I've setup factory_girl_rails however whenever I try and load a factory it's trying to load it multiple times.
Environment:
- rails (3.2.1)
- factory_girl (2.5.2)
- facto...
Ineffective asked 15/2, 2012 at 19:47
5
Working on a Ruby gem and trying to use FactoryBot inside with RSpec.
I have this in support/factory_bot.rb:
RSpec.configure do |config|
config.include FactoryBot::Syntax::Methods
config.befor...
Stabler asked 4/1, 2018 at 8:44
4
Solved
There are comments in the rails codebase that indicate that the test database should be reset between runs
rake -T
rake test:all # Run tests quickly by merging all types and not resetting db
rake...
Cannell asked 12/6, 2014 at 23:54
18
Solved
I'm testing a model with an after create callback that I'd like to run only on some occasions while testing. How can I skip/run callbacks from a factory?
class User < ActiveRecord::Base
after_...
Embry asked 5/1, 2012 at 23:2
1
Solved
The factory_bot documentation for build strategies says:
factory_bot supports several different build strategies: build, create, attributes_for and build_stubbed
And continues with some examples ...
Shirtwaist asked 17/6, 2022 at 17:19
6
Solved
I have the following models:
class Ad < ActiveRecord::Base
belongs_to :page
has_one :image
has_one :logo
end
class Page < ActiveRecord::Base
has_many :logos
has_many :images
has_many...
Floorage asked 30/11, 2013 at 2:8
7
Solved
Can someone tell me if I'm just going about the setup the wrong way?
I have the following models that have has_many.through associations:
class Listing < ActiveRecord::Base
attr_accessible .....
Hatband asked 5/8, 2011 at 22:30
4
Solved
Or is an external gem necessary to generate random and unique usernames maybe?
Here's my current factory:
factory :user_4 do
sequence(:id) { |n| n }
sequence(:first_name) { |n| "Gemini" + n.to_...
Pass asked 3/1, 2014 at 13:10
2
Solved
Say I have a model like
class Vehicle < ActiveRecore::Base
after_initialize :set_ivars
def set_ivars
@my_ivar = true
end
end
and somewhere else in my code I do something like
@vehicle...
Plea asked 14/2, 2014 at 9:48
6
Solved
If I add:
config.include FactoryBot::Syntax::Methods
under
RSpec.configure do |config|
and run rspec, I see this error:
/Users/perry_mac/rails_projects/mymri/spec/spec_helper.rb:21:in ...
Affenpinscher asked 3/9, 2014 at 15:39
3
Solved
If I have this factory:
factory :product, class: Product do
name { Faker::Commerce.product_name }
description { Faker::Lorem.paragraph }
price { Faker::Number.number(3) }
end
I can use creat...
Synchroscope asked 14/7, 2015 at 7:24
6
Solved
I've been struggling with setting up a has_many/through relationship using Factory Girl.
I have the following models:
class Job < ActiveRecord::Base
has_many :job_details, :dependent => :d...
Amah asked 21/1, 2013 at 18:23
3
Solved
For example I have two models a user and a post. A post belongs_to a user and a user has many posts
#spec/factories/post.rb
FactoryBot.define do
factory :post do
user
body Faker::Movie.quote
po...
Turnstone asked 27/4, 2018 at 11:11
6
Solved
Is it possible to do this?
If so, how can you do it?
Note: FactoryBot was previously named FactoryGirl
Semibreve asked 21/3, 2011 at 18:59
3
Solved
I'm looking for a way to create factories for models which have active storage attachments
I attempted the method in this post
with my factory
factory :activity_fit_file, class: 'Activity' do
...
Brogan asked 13/3, 2019 at 12:7
1 Next >
© 2022 - 2024 — McMap. All rights reserved.