factory-bot Questions

2

Solved

I have a user model and a follower model, such that a user can have many followers. So in schema of follower model I have user_id column and a follower_by_user_id column. So in follower model a use...
Huihuie asked 25/7, 2014 at 20:15

3

I'm using the factory_girl plugin in my rails application. For each model, I have a corresponding ruby file containing the factory data e.g. Factory.define :valid_thing, :class => Thing do |t| ...
Pedal asked 10/2, 2010 at 0:51

3

How can I define a normal method for use in one of my FactoryGirl factories? For instance: FactoryGirl.define do def silly_horse_name verbs = %w[brunches dribbles haggles meddles] nouns = %w[la...
Danie asked 1/8, 2012 at 13:47

5

When running my specs, I am stopped by a FactoryGirl error before rspec can even iterate through them. Finished in 0.18709 seconds (files took 1.57 seconds to load) 0 examples, 0 failures /.rben...
Sensitivity asked 18/6, 2015 at 23:21

3

Solved

I am trying to get factory girl to run with rspec in my rails 4.1.1 app. Problem is when I run rspec in my command line, i get Failure/Error: verse = build(:verse) ArgumentError: Factory not regis...

3

Solved

I am trying to test the before_update callback of the model bellow. models/option.rb: class Option < ApplicationRecord belongs_to :activity has_many :suboptions, class_name: "Option", forei...
Gradate asked 11/1, 2017 at 4:42

1

Solved

I am trying to generate a new factory inside a module and I basically required require 'rails/generators' and I am calling the command below. Notice that it creates the file inside the test fol...
Floret asked 2/1, 2017 at 19:8

8

I have model Person that has many Images, where images has a Paperclip attachment field called data, an abbreviated version displayed below: class Person has_many :images ... end class Image ha...
Harhay asked 20/7, 2010 at 22:13

3

Solved

My factories.rb file became too big to maintain over time and I'm now trying to split it across many files in factories directory. The problem is that I don't know how to deal with dependencies. T...
Patriotism asked 26/5, 2014 at 3:16

1

I have the following associations class Training < ApplicationRecord has_many :attendances has_many :attendees, through: :attendances end class Attendance < ApplicationRecord belongs_to ...
Sinistrality asked 14/11, 2016 at 9:25

5

Solved

I have a web service that serves Ads to several different clients. The structure of the Ad varies between clients, and therefore, I am using namespaces for my models and controllers by the client n...
Capitally asked 14/6, 2011 at 20:2

1

Solved

I've been banging my head over this. I want to be able to overwrite attributes on top of traits. I've been reading the documentation and some internet examples but I can't get it to work. This is ...
Recrudescence asked 24/10, 2016 at 0:5

3

This is probably silly simple but I can't find an example anywhere. I have two factories: FactoryGirl.define do factory :profile do user title "director" bio "I am very good at things" link...
Fango asked 30/4, 2013 at 10:11

3

In a Rails application, given three models User, Article and Reviewer with the following relationships and validations: class User < ActiveRecord::Base has_many :articles has_many :reviewers ...
Pow asked 2/5, 2012 at 20:29

6

Solved

Solution Thanks to this gist form Steven Harman, I got it working. devise_mail_helpers.rb module Features module MailHelpers def last_email ActionMailer::Base.deliveries[0] end # Can be us...
Nipissing asked 6/9, 2013 at 15:47

2

Solved

In my model, I have an after_create callback that triggers the method: class Job < ActiveRecord::Base after_create :update_vanity_url private def update_vanity_url self.vanity_url = '/job...
Paquin asked 11/3, 2016 at 21:42

5

Solved

I use: gem 'rails', '3.2.11' gem 'rspec-rails', '2.13.2' gem 'webrat', '0.7.3' gem 'factory_girl_rails', '4.1.0' gem 'spork', '~> 0.9.0.rc' I want to test my HP where I always have a link to ...
Deflower asked 18/7, 2013 at 15:57

4

When I boot up my rails console in development I see FactoryGirl creating objects. Clearly I'm doing it wrong, but what's the right way to do this? This code makes my tests work... # tests/factori...
Statute asked 18/4, 2013 at 20:52

1

Solved

I'm setting up an Artist model that has nameand birth_name attributes. In some cases, an artist's stage name is synonomous with their real name, vice-versa. What I'd like to do in my factory is use...
Glaucous asked 2/7, 2016 at 15:45

10

Solved

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 ta...
Merrel asked 6/1, 2010 at 19:10

4

Solved

I have two models (ModelA and ModelB), and FactoryGirl factories for each. I want the factory for ModelB to be able to (A) create test data, and to (B) build (without saving to database) sample dat...
Silvasilvain asked 4/10, 2011 at 19:19

2

Solved

I'm trying to use FactoryGirl gem inside my App in development mode (it's for mailer tests more) with rails_email_preview gem. It works but only on initial page load, after reloading/refreshing th...
Fatimafatimah asked 1/5, 2016 at 10:3

4

Solved

Suppose I have a model user, which has a uniqueness constraint on the email field If I call Factory(:user) once all is well, but if I call it a second time it'll fail with an "entry already exists...
Lund asked 16/8, 2011 at 0:5

1

Solved

I have the following factory defined for a model: factory :page do association :user, factory: :standard_user association :post, factory: [:short_post] after :create do |model| model.post.user...
Beetroot asked 27/4, 2016 at 0:5

2

I have four models: User, Product, Ownership and Location. Userand Product have one Location, and Location belongs to User and to Product (Polymorphic model). I want to use FactoryGirl to create p...
Sinh asked 26/8, 2013 at 7:9

© 2022 - 2024 — McMap. All rights reserved.