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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T18:18:59+00:00 2026-06-15T18:18:59+00:00

Hi I’m trying to learn testing but my unit test isn’t working. So I

  • 0

Hi I’m trying to learn testing but my unit test isn’t working. So I have a user model (and other models as well, but haven’t started testing them yet):

class Users < ActiveRecord::Base
  attr_accessible :age, :gender, :name

  has_many :sent_messages, :class => "Messages", :foreign_key => 'sender_id'
  has_many :received_messages, :class => "Messages", :foreign_key => 'receiver_id'

  belongs_to :location
  belongs_to :language

  before_save { |user| if user.new_record? then create_remember_token end }


    private

        def create_remember_token
            self.remember_token = SecureRandom.urlsafe_base64
        end

end

and a test/unit/users_test.rb

require 'test_helper'

class UsersTest < ActiveSupport::TestCase
  test "user is created" do
    user = User.create!(:name => "Edmund")
    assert_equal user, User.first
  end
end

but when I run rake test:units I get:

Edmunds-MacBook-Pro:langexchange edmundmai$ rake test:units
NOTICE:  CREATE TABLE will create implicit sequence "languages_id_seq" for serial column "languages.id"
NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index "languages_pkey" for table "languages"
NOTICE:  CREATE TABLE will create implicit sequence "locations_id_seq" for serial column "locations.id"
NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index "locations_pkey" for table "locations"
NOTICE:  CREATE TABLE will create implicit sequence "messages_id_seq" for serial column "messages.id"
NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index "messages_pkey" for table "messages"
NOTICE:  CREATE TABLE will create implicit sequence "users_id_seq" for serial column "users.id"
NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index "users_pkey" for table "users"
/Users/edmundmai/.rvm/gems/ruby-1.9.3-p194@rails3tutorial2ndEd/gems/activesupport-3.2.8/lib/active_support/core_ext/hash/keys.rb:51:in `block in assert_valid_keys': Unknown key: class (ArgumentError)
    from /Users/edmundmai/.rvm/gems/ruby-1.9.3-p194@rails3tutorial2ndEd/gems/activesupport-3.2.8/lib/active_support/core_ext/hash/keys.rb:50:in `each_key'
    from /Users/edmundmai/.rvm/gems/ruby-1.9.3-p194@rails3tutorial2ndEd/gems/activesupport-3.2.8/lib/active_support/core_ext/hash/keys.rb:50:in `assert_valid_keys'
    from /Users/edmundmai/.rvm/gems/ruby-1.9.3-p194@rails3tutorial2ndEd/gems/activerecord-3.2.8/lib/active_record/associations/builder/association.rb:33:in `validate_options'
    from /Users/edmundmai/.rvm/gems/ruby-1.9.3-p194@rails3tutorial2ndEd/gems/activerecord-3.2.8/lib/active_record/associations/builder/association.rb:24:in `build'
    from /Users/edmundmai/.rvm/gems/ruby-1.9.3-p194@rails3tutorial2ndEd/gems/activerecord-3.2.8/lib/active_record/autosave_association.rb:139:in `build'
    from /Users/edmundmai/.rvm/gems/ruby-1.9.3-p194@rails3tutorial2ndEd/gems/activerecord-3.2.8/lib/active_record/associations/builder/belongs_to.rb:14:in `build'
    from /Users/edmundmai/.rvm/gems/ruby-1.9.3-p194@rails3tutorial2ndEd/gems/activerecord-3.2.8/lib/active_record/associations/builder/association.rb:12:in `build'
    from /Users/edmundmai/.rvm/gems/ruby-1.9.3-p194@rails3tutorial2ndEd/gems/activerecord-3.2.8/lib/active_record/associations.rb:1428:in `belongs_to'
    from /Users/edmundmai/Desktop/Class/Ruby/langexchange/app/models/messages.rb:4:in `<class:Messages>'
    from /Users/edmundmai/Desktop/Class/Ruby/langexchange/app/models/messages.rb:1:in `<top (required)>'
    from /Users/edmundmai/.rvm/gems/ruby-1.9.3-p194@rails3tutorial2ndEd/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:251:in `require'
    from /Users/edmundmai/.rvm/gems/ruby-1.9.3-p194@rails3tutorial2ndEd/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:251:in `block in require'
    from /Users/edmundmai/.rvm/gems/ruby-1.9.3-p194@rails3tutorial2ndEd/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:236:in `load_dependency'
    from /Users/edmundmai/.rvm/gems/ruby-1.9.3-p194@rails3tutorial2ndEd/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:251:in `require'
    from /Users/edmundmai/.rvm/gems/ruby-1.9.3-p194@rails3tutorial2ndEd/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:359:in `require_or_load'
    from /Users/edmundmai/.rvm/gems/ruby-1.9.3-p194@rails3tutorial2ndEd/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:313:in `depend_on'
    from /Users/edmundmai/.rvm/gems/ruby-1.9.3-p194@rails3tutorial2ndEd/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:225:in `require_dependency'
    from /Users/edmundmai/.rvm/gems/ruby-1.9.3-p194@rails3tutorial2ndEd/gems/railties-3.2.8/lib/rails/engine.rb:439:in `block (2 levels) in eager_load!'
    from /Users/edmundmai/.rvm/gems/ruby-1.9.3-p194@rails3tutorial2ndEd/gems/railties-3.2.8/lib/rails/engine.rb:438:in `each'
    from /Users/edmundmai/.rvm/gems/ruby-1.9.3-p194@rails3tutorial2ndEd/gems/railties-3.2.8/lib/rails/engine.rb:438:in `block in eager_load!'
    from /Users/edmundmai/.rvm/gems/ruby-1.9.3-p194@rails3tutorial2ndEd/gems/railties-3.2.8/lib/rails/engine.rb:436:in `each'
    from /Users/edmundmai/.rvm/gems/ruby-1.9.3-p194@rails3tutorial2ndEd/gems/railties-3.2.8/lib/rails/engine.rb:436:in `eager_load!'
    from /Users/edmundmai/.rvm/gems/ruby-1.9.3-p194@rails3tutorial2ndEd/gems/railties-3.2.8/lib/rails/application/finisher.rb:53:in `block in <module:Finisher>'
    from /Users/edmundmai/.rvm/gems/ruby-1.9.3-p194@rails3tutorial2ndEd/gems/railties-3.2.8/lib/rails/initializable.rb:30:in `instance_exec'
    from /Users/edmundmai/.rvm/gems/ruby-1.9.3-p194@rails3tutorial2ndEd/gems/railties-3.2.8/lib/rails/initializable.rb:30:in `run'
    from /Users/edmundmai/.rvm/gems/ruby-1.9.3-p194@rails3tutorial2ndEd/gems/railties-3.2.8/lib/rails/initializable.rb:55:in `block in run_initializers'
    from /Users/edmundmai/.rvm/gems/ruby-1.9.3-p194@rails3tutorial2ndEd/gems/railties-3.2.8/lib/rails/initializable.rb:54:in `each'
    from /Users/edmundmai/.rvm/gems/ruby-1.9.3-p194@rails3tutorial2ndEd/gems/railties-3.2.8/lib/rails/initializable.rb:54:in `run_initializers'
    from /Users/edmundmai/.rvm/gems/ruby-1.9.3-p194@rails3tutorial2ndEd/gems/railties-3.2.8/lib/rails/application.rb:136:in `initialize!'
    from /Users/edmundmai/.rvm/gems/ruby-1.9.3-p194@rails3tutorial2ndEd/gems/railties-3.2.8/lib/rails/railtie/configurable.rb:30:in `method_missing'
    from /Users/edmundmai/Desktop/Class/Ruby/langexchange/config/environment.rb:5:in `<top (required)>'
    from /Users/edmundmai/Desktop/Class/Ruby/langexchange/test/test_helper.rb:2:in `require'
    from /Users/edmundmai/Desktop/Class/Ruby/langexchange/test/test_helper.rb:2:in `<top (required)>'
    from /Users/edmundmai/Desktop/Class/Ruby/langexchange/test/unit/helpers/home_helper_test.rb:1:in `require'
    from /Users/edmundmai/Desktop/Class/Ruby/langexchange/test/unit/helpers/home_helper_test.rb:1:in `<top (required)>'
    from /Users/edmundmai/.rvm/gems/ruby-1.9.3-p194@rails3tutorial2ndEd/gems/rake-10.0.2/lib/rake/rake_test_loader.rb:10:in `require'
    from /Users/edmundmai/.rvm/gems/ruby-1.9.3-p194@rails3tutorial2ndEd/gems/rake-10.0.2/lib/rake/rake_test_loader.rb:10:in `block (2 levels) in <main>'
    from /Users/edmundmai/.rvm/gems/ruby-1.9.3-p194@rails3tutorial2ndEd/gems/rake-10.0.2/lib/rake/rake_test_loader.rb:9:in `each'
    from /Users/edmundmai/.rvm/gems/ruby-1.9.3-p194@rails3tutorial2ndEd/gems/rake-10.0.2/lib/rake/rake_test_loader.rb:9:in `block in <main>'
    from /Users/edmundmai/.rvm/gems/ruby-1.9.3-p194@rails3tutorial2ndEd/gems/rake-10.0.2/lib/rake/rake_test_loader.rb:4:in `select'
    from /Users/edmundmai/.rvm/gems/ruby-1.9.3-p194@rails3tutorial2ndEd/gems/rake-10.0.2/lib/rake/rake_test_loader.rb:4:in `<main>'
rake aborted!
Command failed with status (1): [ruby -I"lib:test" -I"/Users/edmundmai/.rvm/gems/ruby-1.9.3-p194@rails3tutorial2ndEd/gems/rake-10.0.2/lib" "/Users/edmundmai/.rvm/gems/ruby-1.9.3-p194@rails3tutorial2ndEd/gems/rake-10.0.2/lib/rake/rake_test_loader.rb" "test/unit/**/*_test.rb" ]
Tasks: TOP => test:units
(See full trace by running task with --trace)

how is this possible?? Can someone help? I haven’t written any other tests so I don’t know how it’s going berserk

UPDATE
Messages model:

class Messages < ActiveRecord::Base
  attr_accessible :content, :read

  belongs_to :sender, :class => "User", :foreign_key => 'sender_id'
  belongs_to :receiver, :class => "User", :foreign_key => 'receiver_id'
end
  • 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-15T18:19:00+00:00Added an answer on June 15, 2026 at 6:19 pm

    in your Users model you use

    has_many :sent_messages, :class => "Messages", :foreign_key => 'sender_id'
    has_many :received_messages, :class => "Messages", :foreign_key => 'receiver_id'
    

    you should be using:

    has_many :sent_messages, :class_name => "Messages", :foreign_key => 'sender_id'
    has_many :received_messages, :class_name => "Messages", :foreign_key => 'receiver_id'
    

    (switched :class to :class_name)


    In associations there is no such thing as the :class option. What you want is the :class_name option. (You will have to change ever model that uses this.)

    http://guides.rubyonrails.org/association_basics.html#has_many-association-reference

    • 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
I have a French site that I want to parse, but am running into
This could be a duplicate question, but I have no idea what search terms
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I am trying to loop through a bunch of documents I have to put
I need to clean up various Word 'smart' characters in user input, including but
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i

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.