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

  • SEARCH
  • Home
  • 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 7685013
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T19:09:32+00:00 2026-05-31T19:09:32+00:00

I have two models – Tenant and User, each tenant will have_many users and

  • 0

I have two models – Tenant and User, each tenant will have_many users and I am trying to find a way of testing that the ability to create a user and automatically assign tenant. When I try run the test I am getting the following error:

NoMethodError:
  undefined method 'reflect_on_association' for Proc:Class

Tenant Code:

class Tenant < ActiveRecord::Base
attr_accessible :name, :billing_email, :country

validates :name,       :presence => true,
                       :length => { :maximum => 75 },
                       :uniqueness => true

validates :billing_email, :email => true

has_many :users
end

User Code:

class User < ActiveRecord::Base
attr_accessible :email, :first_name, :last_name, :password, :tenant_id

validates :email,       :presence => true,
                        :uniqueness => true,
                        :email => true

validates :first_name,  :presence => true,
                        :length => { :maximum => 50 }

validates :last_name,   :presence => true,
                        :length => { :maximum => 50 }

validate :password_validation

has_many :sessions, :dependent => :destroy
belongs_to :tenant  

end

Test Attempt:

lambda do
  @attr = FactoryGirl.attributes_for(:user)
  post users_path, :user => @attr
  response.should be_success
end.should belong_to(:tenant)
  • 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-05-31T19:09:33+00:00Added an answer on May 31, 2026 at 7:09 pm

    It’s not particularly clear what you’re trying to achieve here. Asserting that one object “belongs_to” another smells bad. Do you really care that belongs_to was used for the association? Too often it seems that rspec tests end up duplicating the code under test without actually testing anything useful.

    More likely you’re interested to see if the result of POSTing to your controller produces the correct results. Since you haven’t shown us your controller and since I think RSpec is pointless noise, here’s how I’d tackle this..

    assert_difference ->{User.count} do
      post: users_path, user: FactoryGirl.attributes_for(:user)
    end
    # Assuming your users table is cleared before each test..
    assert_kind_of Tenant, User.first.tenant
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two models indexed for searching (User and Item). I'm trying to do
I have two models that are related to each other. For a contrived example,
I have two Models, Events and Users that share a many to many association.
I have two models User and Admin(with RailsAdmin) that use Devise. I sign in
I have two models that are associated with each other. Customer has_one :primary_contact And
I have two models, Article and Post that both inherit from a base model
I have two models, Room and Image . Image is a generic model that
I have two models: Show and Venue . Show has one venue while each
I have two models, user and group. I also have a joining table groups_users.
I have two models, Tweets and TweetsLocations, associated to each other with: class Tweets

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.