Questions tagged [fabrication-gem]

Fabrication is a fixture replacement library for Ruby.

Fabrication allows you to define schematics for objects and generate valid instances of them on demand in your tests, seeds, or anywhere else. It works with any Ruby object but actively supports ActiveRecord, Mongoid, Sequel, and DataMapper objects.

It is fast, lightweight, and with no gem dependencies at all so you can use it anywhere you want.

69 questions
1
vote
2 answers

Fabrication gem: how to pass custom values to init_with()?

The Fabrication gem allows us to pass custom arguments to the constructor of the class we are fabricating: on_init { init_with('something', true) } But how can I pass custom values for init_with in object generation time? For the object fields, I…
Vinicius Braz Pinto
  • 8,209
  • 3
  • 42
  • 60
1
vote
1 answer

Nested attributes not saved

I have a User class which can have many Payments. The User will get saved but the payments are not. class User < ActiveRecord::Base attr_accessible :email, :password, :password_confirmation attr_accessor :payments, :payments_attributes …
Jan
  • 12,992
  • 9
  • 53
  • 89
1
vote
1 answer

Fabrication has_many though with validation

I'm just getting into testing and I have many models that utilize a has_many though relationship. In each case, one model requires that the other be present at the time of save. I've run into a wall with every testing system I've tried (FactoryGirl,…
Eric Norcross
  • 4,177
  • 4
  • 28
  • 53
1
vote
1 answer

Fabrication Gem difficult association

I tried to use Fabrication gem in order to populate db in development in rails project. The problem is I do feel that Fabrication is very powerful instrument, however except for the simple association I cannot do anything else. For example, I have…
user10756
  • 643
  • 1
  • 6
  • 12
1
vote
1 answer

Fabrication gem with associations undefined method error

I have started using the Fabrication gem with RSpec and on the whole have had great success. However, I don't seem to be able to get the association fabrication to work. I am using Ruby 1.9.3, Rails 3.2.12, RSPec 2.13.0, and Fabrication…
Michael Moulsdale
  • 1,488
  • 13
  • 34
1
vote
1 answer

how to Fabricate object for mongo model with constructor that requires arguments

I have a class class Transaction include Mongoid::Document belongs_to :objectA belongs_to :objectB def initialize(objectA, objectB) super @objectA = objectA @objectB = objectB end end Now I am trying to…
Dimitris
  • 2,501
  • 3
  • 21
  • 28
1
vote
1 answer

random data production in feature steps

class Spinach::Features::Signup < Spinach::FeatureSteps attr_accessor :valid_attributes before do valid_attributes = Fabricate.attributes_for(:identity) #@valid_attributes = Fabricate :identity end step 'I am a visitor' do …
1
vote
2 answers

Devise Authentication not working in Test Environment with RSpec Request Spec and Capybara

I've been stuck trying to get my requests spec to work. I've tried a number of different approaches I've found thru Google and SO. Below are the following helpers I've tried separately with my request…
Gjaldon
  • 5,534
  • 24
  • 32
1
vote
1 answer

Fabricating cyclic dependencies with Fabrication [fabrication_gem]

Okay, I didn't create this code, but I do need to find a good way to test it. We have been using factory_girl and minitest, but have a number of issues. I'm hoping to be able to move to Rspec and the Fabrication gems to setup some new tests,…
anotherdjohnson
  • 303
  • 1
  • 5
  • 13
1
vote
1 answer

Having trouble testing CanCan views with RSpec

I am testing for the presence of a link that's controlled by CanCan: before do @author = Fabricate(:author) visit new_user_session_path fill_in 'Email', :with => @author.email fill_in 'Password', :with => @author.password click_button…
Terence Ponce
  • 9,123
  • 9
  • 31
  • 37
0
votes
1 answer

Duplicate Records created from Association

I am using Mongoid, Rails and Fabrications and at a total loss with how this is happening. Any thoughts very appreciated, but I know this pretty complicated. I just want to fabricate a user and have only four joined groups, but I keep getting eight…
bonhoffer
  • 1,421
  • 2
  • 23
  • 38
0
votes
2 answers

How do i fabricate a model with validate presence on has_one relation with foreign key constraint

I seem to run into a some kind of circular relationships that the two solutions in the gem's documentation won't solve for me. See the example below. Is this meant to be done differently? One would argue that because one object could not really be…
0
votes
1 answer

How do you fabricate objects with has_many associations that can be queried in rspec?

I have this schema that I want to test in rspec. class Question has_many :choices end class Choice belongs_to :question validates_presence_of :question end This doesn't seem to work: Fabricator(:question) do text { sequence(:text) { |i|…
ben
  • 75
  • 8
0
votes
1 answer

Fabrication gem won't let me run `rails console` with the error: 'model_name' is already defined when implementing for rspec factories

The Fabrication gem is making me unable to run rails console because it complains that the Factory models I'm creating with it are already defined in my app/models. For instance, I have an Issue model in my app/models that looks like: class Issue …
beckah
  • 1,543
  • 6
  • 28
  • 61
0
votes
1 answer

how to assign values to an array in a block with Fabricate gem

I have the following and the hosts (second to last) line isn't working. Is this possible? How would I assign to it for the save? venues = Venue.all users = User.all Fabricate.times(16, :event ) do venue { venues.sample } created_by {…
timpone
  • 19,235
  • 36
  • 121
  • 211