factory-bot

Single Table Inheritance with Factory Girl in Rails

僤鯓⒐⒋嵵緔 提交于 2019-12-12 11:16:47
问题 I'm making a Rails 4.0.1 app using Capybara and FactoryGirl but I'm having trouble getting my tests to work correctly. I'm using single table inheritance to make a Collection < ActiveRecord::Base and a VideoCollection < Collection model. When using Factory Girl in my tests, the models don't seem to get instantiated as they should. The Details: When I visually inspect a view in my browser that I'm testing, it displays the collection properly. When I run print page.html in the test for the same

Disabling a FactoryGirl association within a trait

倖福魔咒の 提交于 2019-12-12 09:58:30
问题 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 define a trait where that association is not created/built. I can use an after callback to set the association's id to nil , but this doesn't stop the association record from being created in the first place. Is there a way in a trait definition to completely disable the creation/building of an

“undefined method `env' for nil:NilClass” in 'setup_controller_for_warden' error when testing Devise using Rspec

一曲冷凌霜 提交于 2019-12-12 07:06:35
问题 I'm trying to create a spec for a sign out flow by using factorygirl to create a user and then use Devise's sign_in method to authenticate the user, then use capybara to click the "Sign Out" link. I'm getting (what seems to me to be) a strange error when I run the spec: Failures: 1) Sign out flow successfully redirects to the welcome index (root) Failure/Error: Unable to find matching line from backtrace NoMethodError: undefined method `env' for nil:NilClass # /home/vagrant/.rvm/gems/ruby-2.0

How do I select a value from a database populated dropdown with Capybara?

╄→гoц情女王★ 提交于 2019-12-12 03:39:38
问题 I have 2 models: Venue and Event. Venue has_many :events and Event belongs_to :venue. My events/new form has the following fields Date (populated with current date) Time (populated with current time) Title (empty) Venue (populated with venues table from development database) Now I'm trying to test this with RSpec and Capybara. Here's my feature: require 'spec_helper' feature "Events" do let(:venue) { FactoryGirl.create(:venue) } let(:event) { FactoryGirl.create(:event, venue: venue) }

Running two spec folders in Rails with RSpec

自作多情 提交于 2019-12-12 02:32:51
问题 I'm currently trying to rewrite an application's FactoryGirl factories and therefore I am looking to run two spec folders. Maybe a spec folder and an old_spec folder. However there always seems to be conflicts as FactoryGirl doesn't seem to know whether to use the original factories or the new versions... Obviously I would like to have both folders integrated with my CI server as Im re-writing & so therefore I require both folders to be ran. Does anybody have any experience running two spec

How do I able to create a user before initialization of model

有些话、适合烂在心里 提交于 2019-12-12 02:15:21
问题 In my model(Product) i have a validation, that each product should have a valid owner (login_id of user) validates_presence_of :owner validates_inclusion_of :owner, :in => User.first.login_id, :message => "%{value} is not a valid owner name" I am trying to create product mock object using factory girl for creating a new product I need login_id of a user. to do so i have create a user. up to this every thing is ok, but when i am trying to create a Product using that user's login_id product is

Records created with FactoryGirl not available in Controller

北城余情 提交于 2019-12-12 01:57:11
问题 One of my tests has started failing. It previously worked and going through the same actions by hand in the browser show the feature to be working. I create the records to be tested like this: will = FactoryGirl.create(:user, profile: "security of the internet", first_name: "will") To investigate, I added a binding.pry call in my controller. The action searches Users. If i do: User.all at the pry prompt, no users are shown, an empty result. If i break into the actual test with pry, User.all

Associations not loading

纵饮孤独 提交于 2019-12-12 01:31:57
问题 So I seem to be having some difficulties with the has_many associations in Factory_Girl I have four classes with associations: Aaa has_many bbbs & cccs Bbb belongs_to aaa & ddd Ccc belongs_to aaa & ddd Ddd has_many bbbs & cccs Here are the classes spec\factories\aaas.rb FactoryGirl.define do factory :aaa do end end spec\factories\bbbs.rb FactoryGirl.define do factory :bbb do aaa ddd end end spec\factories\cccs.rb FactoryGirl.define do factory :ccc do aaa ddd end end spec\factories\ddds.rb

Using ActiveRecord with column names with spaces in them

亡梦爱人 提交于 2019-12-12 00:56:15
问题 I work on a team that is using ActiveRecord to access the schema on a MSSQL server. Modifying the schema is not an option and the column names have spaces in them, a la SPACEY COLUMN . When writing the ActiveRecord class to access a table with spaces in it, what is good practice? We also need this to work with factory girl... 回答1: AR-JDBC (as well as the AR-SQLServer-Adapter) will/should handle this just fine since it auto-magically quotes column name identifiers using "[ COlumn NAME ]" ... I

how to test a method of models with rspec and factory

拈花ヽ惹草 提交于 2019-12-12 00:33:06
问题 I'm newbie on rails and I have to write tests for existing rails apps with 'Rspec','shoulda' and 'factory girl' gems. I can test non specific tests like validates_presence_of: something with 'sholda' matchers. But I want to test methods which in models. I can visualize what I need to do, but I can't compose. This is an example what I'm talking about: . . . context 'is editable if project is not started' do setup do @brief=Factory(:brief) @started_project=Factory(:project_started, :brief =>