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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T00:14:48+00:00 2026-06-09T00:14:48+00:00

I’m unable to resolve the following rspec validation error: Failures: 1) User treating associations

  • 0

I’m unable to resolve the following rspec validation error:

Failures:

  1) User treating associations should have the right treatings in the right order
     Failure/Error: FactoryGirl.create(:treating, requestor: @user, created_at: 1.day.ago)
     ActiveRecord::RecordInvalid:
       Validation failed: Requestee can't be blank
     # ./spec/models/user_spec.rb:143:in `block (3 levels) in <top (required)>'

I’m dealing with two models, User and Treating (think of it as a meeting):

user.rb

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

    has_many :sent_treatings, :foreign_key => "requestor_id", :class_name => "Treating", dependent: :destroy
    has_many :received_treatings, :foreign_key => "requestee_id", :class_name => "Treating", dependent: :destroy

end

treating.rb

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

  validates :intro, presence: true, length: { maximum: 190 }
  validates :requestor_id, presence: true
  validates :requestee_id, presence: true

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

    default_scope order: 'treatings.created_at DESC'

end

Finally, the portion from my user_spec that is giving me this error:

describe "treating associations" do
        before { @user.save }
        let!(:older_treating) do
            FactoryGirl.create(:treating, requestor: @user, created_at: 1.day.ago)
            FactoryGirl.create(:treating, requestee: @user, created_at: 1.day.ago)

        9end
        let!(:newer_treating) do
            FactoryGirl.create(:treating, requestor: @user, created_at: 1.hour.ago)
            FactoryGirl.create(:treating, requestee: @user, created_at: 1.hour.ago)
        end

        it "should have the right treatings in the right order" do
            @sent_treating = requestor.sent_treatings.build(intro: "Lorem ipsum")
            @sent_treating.requestee = requestee

            @received_treating = requestee.received_treatings.build(intro: "Lorem ipsum")
        @received_treating.requestor = requestor

            requestor.sent_treatings.should == [newer_treating, older_treating]
            requestee.received_treatings.should == [newer_treating, older_treating]
        end

I’m not sure why ‘requestee’ would be blank here and could use some help. Thank you.

EDIT: factory is below, thanks!

FactoryGirl.define do
    factory :user do
        sequence(:name) { |n| "Person #{n}" }
        sequence(:email) { |n| "person_#{n}@example.com"}
        password "foobar"
        password_confirmation "foobar"

        factory :admin do
            admin true
        end
    end

    factory :treating do
    intro "Lorem ipsum"
  end

end

(I’ve tried to add ‘user’, ‘requestor’, and ‘requestee’ below ‘intro’ in the :treating factory, but still no success). When I add ‘user’ in the factory file (below ‘intro “Lorem ipsum”), I get the following error:

1) User treating associations should have the right treatings in the right order
     Failure/Error: FactoryGirl.create(:treating, requestor: @user, created_at: 1.day.ago)
     NoMethodError:
       undefined method `user=' for #<Treating:0x00000104fa0668>
     # ./spec/models/user_spec.rb:143:in `block (3 levels) in <top (required)>'

When I add ‘requestor’ and ‘requestee’ to the factory instead of user (and in addition to use), I get the following error:

Failures:

  1) User treating associations should have the right treatings in the right order
     Failure/Error: FactoryGirl.create(:treating, requestor: @user, created_at: 1.day.ago)
     ArgumentError:
       Trait not registered: requestee
  • 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-09T00:14:51+00:00Added an answer on June 9, 2026 at 12:14 am

    The problem is that your Treating Factory does not have the requestor and requestee defined, and in addition, you need to tell FactoryGirl that requestor and requestee are aliases for a User

    factory :user, :aliases => [:requestor, :requestee]  do
        sequence(:name) { |n| "Person #{n}" }
        sequence(:email) { |n| "person_#{n}@example.com"}
        password "foobar"
        password_confirmation "foobar"
    
        factory :admin do
            admin true
        end
    end
    
    factory :treating do
        intro "Lorem ipsum"
        requestor
        requestee
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

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.