factory-bot Questions

2

Solved

I am writing controller tests for an application that I did not build, so it's definitely been a learning process. This is my first time encountering a controller that inherits directly from Abstra...
Protract asked 29/3, 2016 at 14:59

5

Solved

I am trying to do a simple test for my model Course, I have wrote this factory: FactoryGirl.define do factory :course do name 'How to be happy ?' end end the course_spec.rb: require "rspec" ...
Gyve asked 3/1, 2012 at 5:31

1

Solved

I read this from Thoughtbot but it's still confusing to me. This is their example: factory :user do transient do rockstar true upcased false end name { "John Doe#{" - Rockstar" if rockstar}...
Dearden asked 15/3, 2016 at 20:2

1

I have a typical requirement, I have to address user object as follows user.referrer and user.referrers. Basically, user can refer more than one person and one person should be referred by one p...
Transpadane asked 11/3, 2016 at 12:47

1

Solved

In my Factory I have a boolean field (evaluated), which I am trying to set to false. I want the field to be required, and always set to either true or false Model validates_presence_of :evaluate...
Thrush asked 8/3, 2016 at 9:28

2

Solved

In accordance with rails 4 model association left join validate id I had to update my factories. I am trying to create a condition where a coupon can be created, but has a job id only assigned when...
Thee asked 5/3, 2016 at 0:43

4

Solved

How do I create multiple records or multiple factories of the same class? I tried: Factory.define :user do |user| user.email "[email protected]" user.password "somepassword" user.email "...
Flosser asked 1/4, 2011 at 6:14

2

Solved

I'm trying to figure out how to write a factory that belongs to 2 different models that each should have the same parent model. Here's the contrived sample code: class User < ActiveRecord::Base...
Otto asked 24/10, 2012 at 1:55

2

Solved

I have this code: FactoryGirl.define do factory :gimme_a_hash, class: Hash do one 'the number 1' two 'the number 2' end end It returns a hash that looks like: 1.9.3p448 :003 > FactoryGir...
Jessie asked 16/12, 2013 at 21:44

2

Solved

There is a Company class that has_many QuarterValue, and I have a RSpec test for it. let(:company) { Company.create } describe 'company has many quarter values' do before do 10.times { create...
Elmerelmina asked 27/12, 2015 at 14:11

2

Solved

Using the FactoryGirl gem, inside the factories.rb file, how can I create a factory with an association that defaults to nil? I am thinking something along these lines: Factory.define :user do |f...
Induline asked 8/12, 2011 at 21:28

1

Solved

I have a factory defined in <Rails-root>/spec/factories/models.rb: FactoryGirl.define do factory :model do id 1 association :organization, factory: :aureso name "Default Model" factory...
Exemplification asked 10/1, 2016 at 5:4

4

Solved

I'm trying to populate some fake data into a factory using the Faker gem: Factory.define :user do |user| user.first_name Faker::Name::first_name user.last_name Faker::Name::last_name user.seque...
Bermejo asked 18/3, 2011 at 18:37

3

Solved

I am new to FactoryGirl and I am trying the following simple scenario? factory :female, :class => Gender do code 'Female' end factory :male, :class => Gender do code 'Male' end factory :...
Allonge asked 1/6, 2012 at 8:15

2

Solved

I am using FactoryGirl and Faker to generate user objects in my seeds.rb file but for some reason the exact same user is being created and rake db:seed is failing because of an email uniqueness val...
Sumach asked 31/7, 2014 at 21:0

2

Solved

I need to write a test for associated models. spec/factories/users.rb: FactoryGirl.define do factory :user do sequence(:name){ |i| "us#{i}" } sequence(:email){ |i| "us#{i}@ad.ad" } password '...
Clearly asked 8/9, 2015 at 18:15

1

I have a Listing model which has_many :categories, through: :categories_listings and has_many :categories_listings. I was testing it with a Factory Girl factory which looks like this: factory :lis...
Heredity asked 3/9, 2015 at 19:25

1

I am new to RSpec and TDD and I am having difficulties writing a RSpec test to test if Devise is actually sending the confirmation email after a user signs up. I know that my application is working...
Hindsight asked 16/6, 2015 at 19:10

2

Solved

I'm new to programming and have been learning Ruby on Rails for about 11 weeks. When trying to test my user factory for validation, I get 1) User has a valid factory Failure/Error: expect(@user...
Jujitsu asked 29/11, 2014 at 13:29

2

Solved

Here is my test. The error I am getting is ActiveRecord::RecordNotFound: Couldn't find MedicalStudentProfile with 'id'=1001. Am I using build_stubbed correctly? RSpec Test RSpec.describe MedicalS...
Cityscape asked 24/7, 2015 at 18:45

2

I'm trying to create a has_many:has_many relationship with factory girl. Here are my models: class User < ActiveRecord::Base has_many :user_roles has_many :roles, through: :user_roles end c...
Intercalary asked 5/9, 2014 at 11:24

4

Gemfile gem 'pundit', '~> 0.2.1' app/controllers/application_controller.rb class ApplicationController < ActionController::Base include Pundit ... app/policies/application_policy.rb ...
Sourwood asked 28/11, 2013 at 2:55

4

Solved

I have added the database_cleaner gem to my rails application in order to clean my database between specs. Here's my current configuration for database_cleaner, located in spec/spec_helper.rb: c...
Helvetic asked 30/11, 2013 at 2:47

4

Solved

Ive been following this introductory to Rails testing and Ive run into an issue I cant seem to find the solution to. Im very familiar with Rails but this is my first foray into testing. Anyhow, I ...

4

Solved

Having a lot trouble getting all the ducks in the right order with FactoryGirl. Set up a minimalist rails app (3.0.11), factory_girl_rails (1.4.0), factory_girl (2.3.2) & cucumber-rails (1.2.1...
Quartermaster asked 7/12, 2011 at 2:42

© 2022 - 2024 — McMap. All rights reserved.