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 8313977
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T20:40:18+00:00 2026-06-08T20:40:18+00:00

I’m having trouble getting my test to pass. In my application, a User can

  • 0

I’m having trouble getting my test to pass. In my application, a User can have many Meetings that they request (sent_meetings) and those that are requested of them (received_meetings).

First, my (simplified) user.rb model:

user.rb

class User < ActiveRecord::Base
  attr_accessible :name, :email, :password, :password_confirmation
  has_secure_password

  has_many :sent_meetings, :foreign_key => "requestor_id", :class_name => "Meeting"
  has_many :received_meetings, :foreign_key => "requestee_id", :class_name => "Meeting"
end

And my meeting.rb model:

meeting.rb

class Meeting < ActiveRecord::Base
  attr_accessible :intro, :proposed_date, :proposed_location

  belongs_to :requestor, class_name: "User"
  belongs_to :requestee, class_name: "User"
end

And my test:

meeting_spec.rb

require 'spec_helper'

describe Meeting do

  let(:requestee) { FactoryGirl.create(:user) }
  let(:requestor) { FactoryGirl.create(:user) }

  before { @received_meeting = requestee.received_meetings.build(intro: "Lorem ipsum") }
  before { @sent_meeting = requestor.sent_meetings.build(intro: "Lorem ipsum") }

  subject { @sent_meeting }
      it { should respond_to(:intro) }
      it { should respond_to(:requestor_id) }
      it { should respond_to(:requestor) }
      its(:requestor) { should == requestor }
      # it { should be_valid }

  subject { @received_meeting }
    it { should respond_to(:intro) }
    it { should respond_to(:requestee_id) }
    it { should respond_to(:requestee) }
    its(:requestee) { should == requestee }
    # it { should be_valid }

end

There seems to be a conflict between the two “subject” lines in my spec file (@sent_meeting and @received_meeting), and that one is overriding the other. Here is my failed test message:

Failures:

1) Meeting requestor
Failure/Error: its(:requestor) { should == requestor }
expected: #
got: nil (using ==)
# ./spec/models/meeting_spec.rb:15:in `block (2 levels) in ‘

Finished in 0.67458 seconds
36 examples, 1 failure

Failed examples:

rspec ./spec/models/meeting_spec.rb:15 # Meeting requestor

I found it interesting that I was getting this error only for either requestor OR requestee (obviously there is a conflict). The ordering of the two subject code chunks matters, and when I do switch them, I get the same error as above but in regard to ‘requestee’ instead of ‘requestor’.

How can I get the test to pass? Thank you!

  • 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-08T20:40:20+00:00Added an answer on June 8, 2026 at 8:40 pm

    You cant do this. You must do this :

    require 'spec_helper'
    
    describe Meeting do
    
      let(:requestee) { FactoryGirl.create(:user) }
      let(:requestor) { FactoryGirl.create(:user) }
    
      before { @received_meeting = requestee.received_meetings.build(intro: "Lorem ipsum") }
      before { @sent_meeting = requestor.sent_meetings.build(intro: "Lorem ipsum") }
    
      describe "sent meetings" do
        subject { @sent_meeting }
        it { should respond_to(:intro) }
        it { should respond_to(:requestor_id) }
        it { should respond_to(:requestor) }
        its(:requestor) { should == requestor }
        it { should be_valid }
      end
    
      describe "received meetings" do
    
        subject { @received_meeting }
        it { should respond_to(:intro) }
        it { should respond_to(:requestee_id) }
        it { should respond_to(:requestee) }
        its(:requestee) { should == requestee }
        # it { should be_valid }
      end
    
    end
    

    You can also use let instead before like this :

    require 'spec_helper'
    
    describe Meeting do
    
      let(:requestee) { FactoryGirl.create(:user) }
      let(:requestor) { FactoryGirl.create(:user) }
      let(:received_meeting) { requestee.received_meetings.build(intro: "Lorem ipsum") }
      let(:sent_meeting) { requestor.sent_meetings.build(intro: "Lorem ipsum") }
    
      describe "sent meetings" do
        subject { sent_meeting }
        it { should respond_to(:intro) }
        it { should respond_to(:requestor_id) }
        it { should respond_to(:requestor) }
        its(:requestor) { should == requestor }
        it { should be_valid }
      end
    
      describe "received meetings" do
        subject { received_meeting }
        it { should respond_to(:intro) }
        it { should respond_to(:requestee_id) }
        it { should respond_to(:requestee) }
        its(:requestee) { should == requestee }
        it { should be_valid }
      end
    
    end
    

    It will be faster.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I have a view passing on information from a database: def serve_article(request, id): served_article
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and

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.