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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T23:12:06+00:00 2026-06-08T23:12:06+00:00

The following tests are all passing except the it { should be_valid } lines

  • 0

The following tests are all passing except the “it { should be_valid }” lines in ‘describe “sent treatings” do’ and ‘describe “received treatings” do’

require 'spec_helper'

describe Treating do

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

  before { @received_treating = requestee.received_treatings.build(intro: "Lorem ipsum") }
  before { @sent_treating = requestor.sent_treatings.build(intro: "Lorem ipsum") }

  describe "sent treatings" do
    subject { @sent_treating }
      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 treatings" do
    subject { @received_treating }
      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

  describe "accessible attributes" do
    it "should not allow access to requestor_id" do
      expect do
        Treating.new(requestor_id: requestor.id)
      end.should raise_error(ActiveModel::MassAssignmentSecurity::Error)
    end

    it "should not allow access to requestee_id" do
      expect do
        Treating.new(requestee_id: requestee.id)
      end.should raise_error(ActiveModel::MassAssignmentSecurity::Error)
    end
  end

  describe "when requestor_id is not present" do
    before { @sent_treating.requestor_id = nil }
    it { should_not be_valid }
  end

  describe "when requestee_id is not present" do
    before { @received_treating.requestee_id = nil }
    it { should_not be_valid }
  end
end

here is the error:

Failures:

  1) Treating sent treatings 
     Failure/Error: it { should be_valid }
       expected valid? to return true, got false
     # ./spec/models/treating_spec.rb:19:in `block (3 levels) in <top (required)>'

  2) Treating received treatings 
     Failure/Error: it { should be_valid }
       expected valid? to return true, got false
     # ./spec/models/treating_spec.rb:30:in `block (3 levels) in <top (required)>'

lastly, my user.rb model:

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

  validates :requestor_id, presence: true
  validates :requestee_id, presence: true

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

end

any help is appreciated!

  • 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-08T23:12:08+00:00Added an answer on June 8, 2026 at 11:12 pm

    In this test you have two meetings and set only one of the two ids of each of them in the fixture:

    before { @received_treating = requestee.received_treatings.build(intro: "Lorem ipsum") }
    before { @sent_treating = requestor.sent_treatings.build(intro: "Lorem ipsum") }
    

    assuming user is the same as in your last question,

    class User < ActiveRecord::Base
      ...
      has_many :sent_meetings, :foreign_key => "requestor_id", :class_name => "Meeting"
      has_many :received_meetings, :foreign_key => "requestee_id", :class_name => "Meeting"
    

    @received_treating should have an requestee_id but not an requester_id (has never been assigned anywhere!) and @sent_treating has a requestor_id.

    so again, for the same reasons as in your last question, the validation fails, as both have only one of the two ids requested in the validation set.

    What is the behaviour that you expect? If you want to build up the n:m relationship to the users, you will have to specify the second user at some point. Maybe you mean a fixture like that:

    before do 
      @treating = requestor.sent_treatings.build(intro: "Lorem ipsum")
      @treating.requestee = requestee
    end
    

    maybe you even want to create a custom setter in Treating

    def send_to(user)
      requestee = user
    end
    

    then you could write something like

    before { @sent_treating = requestor.sent_treatings.build(intro: "Lorem ipsum").send_to(requestee) }
    

    That gives you a Treating with both ids set.

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

Sidebar

Related Questions

Almost all of my JUnit tests are written with the following signature: public void
I have a bootstrap formtastic form which was passing all of my rspec tests.
I'm passing all my calls to a main mapping function and then it should
I've been using ShowDialog() in following way for all my new Windows. SomeGui test
I have the following controller: class Tests extends CI_Controller { public function update_record_test() {
It seems like EasyMock tests tend to follow the following pattern: @Test public void
When running some tests I came across the following issue. When using: private String
While doing some JavaScript performance tests I came up with the following piece of
I have the following code (correct for my simple tests) for a linked list
How to write tests where conditions like the following arise: Test user Input. Test

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.