factorygirl

Factory_girl has_one relation with validates_presence_of

I have 2 Models: # user.rb class User < ActiveRecord::Base has_one :profile, :dependent => :destroy end # profile.rb class Profile < ActiveRecord::Base belongs_to :user validates_presence_of :user end # user_factory.rb Factory.define :user do |u| u.login "test" u.association :profile end I want to do this: @user = Factory...

How to stub an users_controller | authlogic, rspec2, rails3, factory_girl

My users_controller.rb # GET /users/1/edit def edit @user = current_user #@user = User.find(params[:id]) end my sweet looking users_controller_spec.rb ( notice all my commented out attempts ) describe "Authenticated examples" do before(:each) do activate_authlogic UserSession.create Factory.build(:valid_user) end des...

Association not finding created objects in tests

I have following models in my app: class Game < ActiveRecord::Base has_many :players has_many :villages, :through => :players end class Village < ActiveRecord::Base belongs_to :player end class Player < ActiveRecord::Base belongs_to :game has_many :villages before_create :build_starting_village protected def...

A better way to build factory using factory_girl in cucumber

I am using cucumber and factory_girl in a rails 2.3.9 project. Here is one of the givens in one of my features. Given a user with first_name "Mary" and last_name "Jane" I started building the regex where I could capture following items. model = user first_name = "Mary" last_name = "Jane" Factory(:user, :first_name => 'Mary', :last_...

Something wrong in my sequence of factory creation..

I was hoping someone would spot why this wouldn't work. I am getting an error thats being called because the attributes I specify with Factory_Girl are not being applied to the stub before validation. The Error: undefined method `downcase' for #<Category:0x1056f2f60> RSpec2 it "should vote up" do @mock_vote = Factory.create(:vote...

Learning how to spec..seem to be having troubles

Here's my code I'm spec'ing: def vote_up get_vote @vote.value += 1 unless @vote.value == 1 @vote.save respond_to do |format| format.js { render :action => "vote", :layout => false } end end Seems pretty straightforward. This is what I'm trying to spec it with : it "should vote up" do @mock_cat = Factory.create(:ca...

undefined method `each' in a factory_girl / rspec2 scenario

I'm trying to Factory a Post associated with a Vote. So that Post.votes would generate the Vote's that are associated with it. Factory.define :voted_post, :parent => :post, :class => Post do |p| p.association :votes, :factory => :vote end And my rspec2 is relatively straightforward : describe "vote scores" do it "should show me t...

undefined method 'password_confirmation' for User: Testing Authlogic with Cucumber and Factory Girl

My tests work fine when I'm testing them individually, rake cucumber FEATURE = 'path/to/feature' but when I try to run rake cucumber They fail with the following error undefined method `password_confirmation=' for #<User:0x1069545f0> (NoMethodError) This comes up when I try to create a user using Factory.build(:user). I have ...

Why does rspec redirect not get full route during test?

I'm attempting the following functional test on the controller. I'm using the following RSpec2 Rails 3 Shoudla Mocha Here's the test context "POST on create should be successful" do before(:each) do Model.any_instance.expects(:save).returns(true).once Model.any_instance.stubs(:id).returns(1) post :create, :model => {}...

rspec model associations with Factory Girl

I am trying to create a rspec test for a model for States. This state model has an association to a Country model. My factories look like Factory.define :country do |country| country.name "Test Country" end Factory.define :state do |state| state.name "Test State" state.association :country end I have made a functional state...

rspec validates_presence_of polymorphic attributes ruby on rails

I am writing an rspec for an address model that has a polymorphic attribute called :addressable. I am using factory girl for testing. This model has no controller because I do not wish to create a standalone address but that doesnt stop the rspec from creating a standalone address. My model, factory and rspec are class Address < Act...

Rails/Devise - What should I test with devise and rspec ?

Hi, Many programmers use devise as their authentication solution and I would like to get their advice: Devise is already tested, but I want to know if there is something to test by myself (integration/unit/funtionnal tests?) for a standard devise integration with my knowledge (I'm not familiar with shoulda and cucumber, but I know a ...

Factory Girl: How to associate a record to another record without creating a new record?

Hello. I'm using Factory Girl/Rspec2/Rails 3. In factories.rb, I have: Factory.define :user do |user| user.name 'Some guy' user.email '[email protected]' user.password 'password' end Factory.define :org_admin, :parent => :user do |user| user.email '[email protected]' end Factory.define :user_with_memb...

Rspec Test fail when using FactoryGirl

I am working with FactoryGirl for the first time and have set up my tests for the following controller code # PUT method def chosen answer = Answer.find(params[:id]) if answer.update_attributes({:selected => true}) respond_to do |format| format.html { flash[:notice] = "Success" redirec...

FactoryGirl: How do define a factory without passing parameters

Hello. I'm using Rails 3 / factory_girl_rails / Rspec 2 and Ruby 1.8 I've defined my factories this way: Factory.define :user do |u| u.name 'Some guy' u.sequence(:email) {|n| "person#{n}@example.com" } u.password 'password' end Factory.define :password_reset_user, :parent => :user do |user| user.password_reset_key '...

Factory Girl error with has_many relationship

Hi, I have the following factories: Factory.define :email do |email| email.email {"infomcburney.cowan.com"} end Factory.define :lead do |lead| lead.emails {|emails| [emails.association(:email)]} end Which are modeling the following classes class Lead < ActiveRecord::Base has_many :emails end class Email < ActiveRecord::Base...