factory-bot

How to define an array / hash in Factory Girl?

痴心易碎 提交于 2019-12-02 14:06:04
I am trying to write a test that simulates some return values from Dropbox's REST service that gives me back data in an Array, with a nested hash. I am having trouble figuring out how to code my Factory since the return result is an array with a has inside. What would go here? Factory.define :dropbox_hash do ?? end Dropbox data looks like this: ["/home", {"revision"=>48, "rev"=>"30054214dc", "thumb_exists"=>false, "bytes"=>0, "modified"=>"Thu, 29 Dec 2011 01:53:26 +0000", "path"=>"/Home", "is_dir"=>true, "icon"=>"folder_app", "root"=>"app_folder", "size"=>"0 bytes"}] And I'd like a factory

Rspec: Testing nested destroy action

廉价感情. 提交于 2019-12-02 13:34:46
问题 I am trying to test the 'destroy' action for my nested comments controller. Post has_many Comments . I have ran into similar issues before and understand that I need to pass an id, but I'm still running into a very familiar error... Failures: 1) CommentsController#DELETE destroy deletes a comment Failure/Error: delete :destroy, comment: create(:comment), post_id: @post ActionController::UrlGenerationError: No route matches {:action=>"destroy", :comment=>"1", :controller=>"comments", :post_id=

Factory girl saving records in my development database

跟風遠走 提交于 2019-12-02 13:18:28
I have a very strange problem and I don't know where I should look to find it. I am developing a rails 3 app using rspec and factory girl for testing. For some reason, whenever I run any rails commands (eg to rake the db, start the dev server etc) one factory user is created and stored in my development database. The worst part is, it always has the same email, which I am validating the uniqueness of in my app, so the commands won't run until I go in manually delete the record. I have looked all through my factories file and I don't think I am doing anything strange there, and suggestions

RSpec & Database Cleaner - Keep certain objects permanently in the test database

亡梦爱人 提交于 2019-12-02 05:30:07
问题 I have (belatedly) started testing my Rails app (a shopping website) with RSpec/capybara, using database cleaner to clear the database and Factory Girl to generate new objects for every test (like most people do). This works fine, and I do think it is a good idea to clear the data between tests. However, it can get slow and (as far as I can figure out) a bit tedious to generate multiple instances of the same object. There are some objects that are always the same in my database, or that I

rspec - why does this attribute comparison usng assert_equal fail when they are the same, on ubuntu only?

孤街醉人 提交于 2019-12-02 04:28:34
问题 Two tests are failing - but only on Ubuntu(12) but not on my (new) Mac. The failure two are Active Record object attribute comparisons but in all my effort to compare them, e.g. making hash's at the command line and pasting the attributes in, the comparison says they are the same. A real puzzler as we have an extensive test suite with many hundreds of tests. Rails 3.2.8, rspec 2.11 Failure/Error: assert_equal @iep_service.attributes, IepService.first.attributes MiniTest::Assertion: <{"id"=

rspec - why does this attribute comparison usng assert_equal fail when they are the same, on ubuntu only?

為{幸葍}努か 提交于 2019-12-02 02:13:22
Two tests are failing - but only on Ubuntu(12) but not on my (new) Mac. The failure two are Active Record object attribute comparisons but in all my effort to compare them, e.g. making hash's at the command line and pasting the attributes in, the comparison says they are the same. A real puzzler as we have an extensive test suite with many hundreds of tests. Rails 3.2.8, rspec 2.11 Failure/Error: assert_equal @iep_service.attributes, IepService.first.attributes MiniTest::Assertion: <{"id"=>414, "duration"=>30, "frequency"=>3, "period"=>"week", "group_size"=>"group", "location"=>nil, "service"=

RSpec & Database Cleaner - Keep certain objects permanently in the test database

梦想与她 提交于 2019-12-02 01:18:29
I have (belatedly) started testing my Rails app (a shopping website) with RSpec/capybara, using database cleaner to clear the database and Factory Girl to generate new objects for every test (like most people do). This works fine, and I do think it is a good idea to clear the data between tests. However, it can get slow and (as far as I can figure out) a bit tedious to generate multiple instances of the same object. There are some objects that are always the same in my database, or that I will always generate an identical copy of for testing. For example, my Package model, which defines the

rspec test of my controller returns nil (+factory girl)

☆樱花仙子☆ 提交于 2019-12-01 10:29:13
I am learning tests with rspec and factory girl on Rails and I can't manage to make them work. My User controller looks like this : class UsersController < ApplicationController def index @users = User.all.order(:first_name) end end and the tests : require 'spec_helper' describe UsersController do before(:each) do @user1 = FactoryGirl.create(:user, first_name: "B", last_name: "B", uid: "b") @user2 = FactoryGirl.create(:user, first_name: "A", last_name: "A", uid: "a") end describe "GET index" do it "sets a list of users sorted by first name" do get :index assigns(:users).should == [@user2,

rspec test of my controller returns nil (+factory girl)

戏子无情 提交于 2019-12-01 08:57:28
问题 I am learning tests with rspec and factory girl on Rails and I can't manage to make them work. My User controller looks like this : class UsersController < ApplicationController def index @users = User.all.order(:first_name) end end and the tests : require 'spec_helper' describe UsersController do before(:each) do @user1 = FactoryGirl.create(:user, first_name: "B", last_name: "B", uid: "b") @user2 = FactoryGirl.create(:user, first_name: "A", last_name: "A", uid: "a") end describe "GET index"

Rspec/FactoryGirl: clean database state

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-01 02:41:59
I am new to Rspec and Factory girl and would like my test to run on a specific database state. I understand I can get Factory girl to create these records, and the objects will be destroyed after the test run, but what happens if I have data in the database. For example: I want my test to run when there are 3 records in the database that I created through Factory Girl. However, I currently already have 1 model record in the database, and I don't want to delete it just for the test. Having that 1 model in there ruins my test. Database Content [#<Leaderboard id: 1, score: 500, name: "Trudy">]