factory-bot

Using Factory Girl with Rspec Views

牧云@^-^@ 提交于 2019-12-11 04:05:06
问题 So I want to test some views using Rspec and Factory Girl, but I don't know how to assign a factory to a view properly. All of the information I see online uses stubbing, and although stubbing is fine, I want to keep my rspec stuff somewhat consistent. I want to use a factory for an edition model and associate that with the page when I render the page, but everything I've considered seems to be broken. Here's sort of a ridiculous example: require 'spec_helper' describe "catalog/editions

FactoryBot namespaced models without class_name

蓝咒 提交于 2019-12-11 03:09:44
问题 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 < Vehicle; end When creating factories for these models, they were set up in the following way: factory :vehicle_car, class: Vehicle::Car do; end factory :vehicle_train, class: Vehicle::Train do; end factory :vehicle_jet, class: Vehicle::Jet do; end This produces the following deprecation warning: DEPRECATION WARNING:

How to build a parent with child factory in one step in order to pass validation

独自空忆成欢 提交于 2019-12-11 02:37:38
问题 Projects must have at least one task created at the same time to ensure the validation passes. This is the snippet I use to validate this: class Project < ActiveRecord::Base validates :tasks, :length => { :minimum => 1 } ... end The challenge I'm having is create the right factory to build a project with task upfront using FactoryGirl. I'm using: FactoryGirl.define do factory :task do name "Get this test passing" project end factory :project do title "Complete the application" factory

How to make a FactoryGirl.create affect another record's attribute?

大城市里の小女人 提交于 2019-12-11 01:19:50
问题 In a webshop application normally after a booking of a product the bookings_controller create action does an order.save which in turn activates the necessary before_save method order.sum_of_all_bookings . When building a RSpec test for an admin viewing a list of orders, making a booking doesn't change the total of an order. The indexing does work in the browser. require 'rails_helper' RSpec.feature 'Admin can oversee orders' do let(:admin) { FactoryGirl.create(:user, :admin) } let(:customer)

How do you define trait using Fabrication

五迷三道 提交于 2019-12-10 20:27:57
问题 I am learning how to use fabrication in Rails and we have decided to replace all our factory_girl code with fabrication. Suppose we have this code in factory_girl FactoryGirl.define do factory :user do trait(:no_credits) { credits 0 } trait(:with_credits) { credits 300 } How will you define this in Fabrication? I have gone through their website but couldn't find anything regarding this. Will appreciate your help 回答1: Seems that your are looking for Fabricator inheritance, this is what the

rspec test failure when switching from initializing attributes to Factory

穿精又带淫゛_ 提交于 2019-12-10 18:05:52
问题 This makes no sense to me, hope someone can help. I'm getting a single test failure when creating a user using a factory (seemingly similar tests pass). In my user_spec.rb test file, the user was originally created like this. Using this initialization approach, all tests pass. USER CREATION user_spec.rb (without factory) describe User do before do @user = User.new(name: "Example User", email: "user@example.com", password: "foobar", password_confirmation: "foobar", username: "username") end

When to switch from cucumber to rspec in the BDD cycle for a login procedure

丶灬走出姿态 提交于 2019-12-10 17:47:53
问题 I'm still trying to understand the combination of cucumber and rspec in the BDD cycle. I have defined the following scenarios for a very simple login system: Feature: Log in In order to get access to the application As a user I want to log in Scenario: User logs in successfully Given I exist as a user When I go to the login page And I fill in "username" with "gabrielhilal" And I fill in "password" with "secret" And I press "Login" Then I should see "Welcome gabrielhilal" And I should be

ERROR: null value in column “id” violates not-null constraint

。_饼干妹妹 提交于 2019-12-10 16:04:42
问题 I just migrated my app from mysql to postgres but when I try to insert a record in a specific table I get violates not-null constraint error: ERROR: null value in column "id" violates not-null constraint DETAIL: Failing row contains (null, 1, 1, null, null, null, 2016-03-09 09:24:12.841891, 2012-12-31 23:00:00, 2012-12-31 23:00:00, null, null, f, null, f, XYZAssignment, null, null, null, null). ********** Error ********** ERROR: null value in column "id" violates not-null constraint SQL state

Reset 'sequence' for FactoryGirl tests

こ雲淡風輕ζ 提交于 2019-12-10 15:59:17
问题 Does anyone know how to reset the sequence method for FactoryGirl? I have a factory that creates a list of tasks and I want to order to start at 1 every time. I use 'sequence' because the task list is a associated model, so I would need the order to increase every time I use FactoryGirl.create until I call a reset. 回答1: You need to write FactoryGirl.reload in the before/after callback of the test file. Example code snippet before do FactoryGirl.reload . . . end The '.' represents other code.

Rails FactoryGirl inside app in development env

天大地大妈咪最大 提交于 2019-12-10 15:54:00
问题 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 the page I get following error: Factory not registered: order where order is name of factory. Here is my code (it is a dummy app for my Rails Engine): spec/dummy/app/mailer_previews/mymodule/order_mailer_preview.rb Dir[Mymodule::Core::Engine.root.join('spec', 'factories', '*')].each do |f| require

工具导航Map