Given the following
class User < ActiveRecord::Base
has_and_belongs_to_many :companies
end
class Company < ActiveRecord::Base
has_and_belongs_to_many :users
end
how do you define factories for companies and users including the bidirectional association? Here's my attempt
Factory.define :company do |f|
f.users{ |users| [users.a...
I'm trying to perform an integration test via Watir and RSpec. So, I created a test file within /integration and wrote a test, which adds a test user into a base via factory_girl.
The problem is — I can't actually perform a login with my test user. The test I wrote looks as following:
...
before(:each)
@user = Factory(:user)
@brow...
I have a constraint and a validation placed on the guid field so that each is unique. The problem is, with the factory definition that I have below, I can create only one user instance, as additional instances fail validation.
How do I do this correctly so that the guid field is always unique?
Factory.define(:user) do |u|
u.guid UU...
Is there a way in factory_girl to specify a random instance that an association should point to? For example, I have a Like object which belongs_to one User and one SocialUnit. I want the factory for Like to pick a random existing User and a random SocialUnit to like, instead of just generating a new one. The below snippet sort of wor...
I have the following models:
class Activity < ActiveRecord::Base
has_many :clientships, :dependent => :destroy
has_many :clients, :through => :clientships
end
class Clientship < ActiveRecord::Base
belongs_to :client
belongs_to :activity
validates_presence_of :client_id
validates_presence_of :activity_id, :unless => :ne...
I'm using factory_girl + rspec on Rails 2-3-stable:
Test:
context "test" do
before(:each) do
@profile.stub!(:lastfm_enabled?).and_return(true)
end
it "should be able to scrobble if true" do
@profile.update_attribute(:lastfm_scrobbling, true)
@profile.lastfm_scrobbling_enabled?.should be_true...
I'm running rails 3.0, rspec 2.0 and factory_girl. Here is the simplified scenario I'm working with: a user can subscribe to only one plan at a time
# user.rb
class User < ActiveRecord::Base
has_one :plan
attr_accessible :login, :plan_id
end
# plan.rb
class Profile < ActiveRecord::Base
attr_accessible :plan
end
# user_factory.rb...