factory-bot Questions
1
Solved
I have the factory
FactoryBot.define do
factory :activity_fit_file do
association :user, factory: :user
activity_type {:cycling}
after(:build) do |activity|
activity.original_activity_log_fi...
Frescobaldi asked 12/3, 2019 at 12:6
1
Solved
I tried to convert from FactoryGirl to FactoryBot. This should not be a big issue but i do not get it to work. The code:
Added to Gem File
gem 'factory_bot'
Added to spec_helper
FactoryBot.def...
Prentice asked 12/3, 2019 at 10:33
1
Solved
In the 5.0 FactoryBot release, static attributes will be deprecated and dynamic attributes will have to be used instead. So:
factory :product do
name 'Some Product'
end
Will need to become:
fa...
Swinish asked 28/2, 2019 at 2:7
2
Solved
I am using Ruby on Rails 3.0.9, RSpec-rails 2 and FactoryGirl. I am trying to state a Factory association model but I am in trouble.
I have a factories/user.rb file like the following:
FactoryGir...
Depravity asked 20/9, 2011 at 1:3
2
Solved
In a Rails app, I'm using FactoryGirl to define a general factory plus several more specific traits. The general case and all but one of the traits have a particular association, but I'd like to de...
Papal asked 8/11, 2013 at 18:2
3
Is it possible to preserve the build strategy when I have a factory for a model that has an association to a second model, which itself has an association to a third model?
In the example below, a...
Shandra asked 21/11, 2012 at 0:49
9
Solved
Provided that I have a project factory
Factory.define :project do |p|
p.sequence(:title) { |n| "project #{n} title" }
p.sequence(:subtitle) { |n| "project #{n} subtitle" }
p....
Divertimento asked 29/7, 2010 at 2:53
4
Solved
In one of my RSpec test, I am creating multiple objects from the same factory definition
Eg
FactoryBot.create(:model_1)
FactoryBot.create(:model_1)
FactoryBot.create(:model_1)
Is there a method th...
Spondee asked 26/8, 2013 at 13:52
2
Solved
I've been running into quite an annoying issue when dealing with Rails 4 action mailer previews and factory girl. Here's an example of some of my code:
class TransactionMailerPreview < ActionMa...
Whiff asked 20/8, 2015 at 12:45
1
Is there a FactoryBot method or some way to get available traits for a factory?
Ex:
FactoryBot.define do
factory :address, class: Address do
trait :in_california do
state 'CA'
end
trait :in...
Soapbark asked 27/7, 2018 at 18:50
3
Solved
I have a Model that has an enum as attribute.
class ApplicationLetter < ActiveRecord::Base
belongs_to :user
belongs_to :event
validates :user, :event, presence: true
enum status: {accepte...
Sumatra asked 27/11, 2016 at 14:51
2
Solved
I have a model that uses both an association and an enum attribute.
class ProjectItem < ActiveRecord::Base
belongs_to :project
enum status: {open: 0, pending: 1, completed: 2}
When I'm run...
Lipscomb asked 22/12, 2014 at 16:12
3
Solved
I have models for Users and Sites with a has_many through relaitonship between them. There is one extra piece of data on the sites_users join table is_default which is type boolean with the intenti...
Upwind asked 22/9, 2018 at 13:57
1
Solved
Following this blog post, http://blog.arkency.com/2015/09/testing-race-conditions/
I am trying to test concurrency. But in my specs, I am not able to find the record when I spin up a new thread or...
Remediable asked 2/3, 2017 at 0:8
11
Solved
Given the following
class User < ActiveRecord::Base
has_and_belongs_to_many :companies
end
class Company < ActiveRecord::Base
has_and_belongs_to_many :users
end
how do you define factor...
Smatter asked 27/9, 2009 at 20:17
3
Solved
Can't call "dummy = create(:user)" to create a user. Have gone back and forth for hours.
/home/parreirat/backend-clone/Passworks/spec/models/user_spec.rb:15:in `block (2 levels) in <top (requi...
Presnell asked 30/3, 2014 at 23:42
10
Solved
I'm attempting to follow railstutorial.org, and am currently on Chapter 7, where you start using factories: http://railstutorial.org/chapters/modeling-and-viewing-users-two#sec:tests_with_factories...
Amberly asked 21/10, 2010 at 19:14
1
Solved
I'm using FactoryBot and Faker for my tests, and it looks like that Faker is generating the same name:
class Profile < ApplicationRecord
belongs_to :user
validates_presence_of :first_name, :l...
Hophead asked 19/5, 2018 at 17:34
2
Solved
I have a gem that includes some Factories. The gem looks something like:
.
├── Gemfile
├── Gemfile.lock
├── README.md
├── Rakefile
├── db
├── lib
│ ├── models
│ │ ├── users.rb
├── pkg
├── core.ge...
Microphyte asked 29/7, 2015 at 12:25
5
Solved
Say I have models User and Post, a user has_many posts and a post belongs_to a user.
When I write a spec for Post, my first instinct is to write something like this:
before do
@user = FactoryGir...
Keturahkeung asked 18/12, 2013 at 16:28
3
Solved
The Factory Girl introduction delineates the difference between FactoryGirl.build() and FactoryGirl.create():
# Returns a User instance that's not saved
user = FactoryGirl.build(:user)
# Returns a...
Canonry asked 31/12, 2012 at 5:57
2
Solved
Im currently working on a Rails 4.2.6 and with RSpec 3.7 version. When I run my test I get the following error:
undefined method `build' for #<RSpec::ExampleGroups::UserName:0x007ff984a99d38>...
Putrescent asked 20/3, 2018 at 16:18
9
Solved
"Could not find a valid mapping for #<User ...>" only on second and successive tests
I'm trying to write a request test that asserts that the proper links appear on the application layout depending in whether a user is logged in or out. FWIW, I'm using Devise for the authentication...
Reduplicative asked 15/6, 2011 at 19:52
3
Solved
I recently upgraded to Rails 4 and everything works fine except for my Rspec tests.
require 'spec_helper'
describe Invoice do
before :each do
@user = FactoryGirl.create(:activated_user)
perso...
Postglacial asked 5/12, 2013 at 17:25
2
Solved
I have a fairly chunky FactoryBot trait that accepts params and creates a has_many relation. I can call that trait as part of another trait to dry up traits or make it easier to bundles traits toge...
Selfassurance asked 1/12, 2015 at 0:30
© 2022 - 2024 — McMap. All rights reserved.