Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9236189
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T07:13:49+00:00 2026-06-18T07:13:49+00:00

I have the following models class User < ActiveRecord::Base devise :database_authenticatable, :registerable, :recoverable, :rememberable,

  • 0

I have the following models

class User < ActiveRecord::Base
  devise :database_authenticatable, :registerable,
        :recoverable, :rememberable, :trackable, :validatable
   
     attr_accessible :email, :password, :password_confirmation, :remember_me, :company_id
end


 class Company < ActiveRecord::Base
   attr_accessible :email, :name
 end


#test/factories/companies.rb
FactoryGirl.define do
  factory :company do
    name "sample company"
    email "sample@company.com"
  end
end

#test/factories/users.rb
FactoryGirl.define do
 factory :user do |u|
   u.email 'sameera@sample.com'
   u.password 'welcome'
   u.password_confirmation 'welcome'
   u.association :company, :factory => :company
 end
end


#spec/models/user_spec.rb
require 'spec_helper'
 
describe User do
   describe "Validations" do
     it "should validate the email" do
       user = FactoryGirl.build(:user, :email => nil)
       user.should have(1).error_on(:email)
     end
   end
end

but I’m getting this error, with guard (even after re-starting Guard)

15:47:35 - INFO - Running: spec/models/user_spec.rb
Running tests with args ["--drb", "-f", "progress", "-r", "/home/sameera/.rvm/gems/ruby-1.9.2-p290/gems/guard-rspec-2.4.0/lib/guard/rspec/formatter.rb", "-f", "Guard::RSpec::Formatter", "--failure-exit-code", "2", "spec/models/user_spec.rb"]...
F

Failures:

  1) User Validations should validate the email
     Failure/Error: user = FactoryGirl.build(:user, :email => nil)
     NoMethodError:
       undefined method `company=' for #<User:0x00000004dcee08>
     # ./spec/models/user_spec.rb:6:in `block (3 levels) in <top (required)>'

Finished in 0.16308 seconds
1 example, 1 failure

Failed examples:

rspec ./spec/models/user_spec.rb:5 # User Validations should validate the email


Randomized with seed 26095

Done.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T07:13:51+00:00Added an answer on June 18, 2026 at 7:13 am

    Your User model doesn’t declare a belongs_to association as you factory assume it would:

    you should add it:

    class User < ActiveRecord::Base
      devise :database_authenticatable, :registerable,
            :recoverable, :rememberable, :trackable, :validatable
    
         attr_accessible :email, :password, :password_confirmation, :remember_me, :company_id
      belongs_to :company
    end
    

    of course this assumes that your user table has a company_id column (but I guess you already added it, as you listed it in attr_accessible)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So, i have model User class User < ActiveRecord::Base devise :database_authenticatable, :registerable, :recoverable, :rememberable,
Hello I have the following models. The User Model: class User < ActiveRecord::Base attr_accessible
I have the following models: class EventParticipant < ActiveRecord::Base belongs_to :event has_one :user attr_accessible
I have the following three models: class User < ActiveRecord::Base has_many :associations has_many :pharmacies,
I have the following models: class User < ActiveRecord::Base has_many :subscriptions, as: :subscribable has_many
I currently have the following models: class Player < ActiveRecord::Base belongs_to :team belongs_to :user
I have the following models: class Mark < ActiveRecord::Base validates_presence_of :user validates_presence_of :page belongs_to
I have the following models: class User < ActiveRecord::Base has_many :subscriptions end class Subscription
I have the following models, with their relevant associations: class User < ActiveRecord::Base has_many
I have a very simple issue: User model: class User < ActiveRecord::Base devise :database_authenticatable,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.