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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:47:03+00:00 2026-05-26T07:47:03+00:00

Here is the test that is failing: before(:each) do @attr = { :user_id =>

  • 0

Here is the test that is failing:

before(:each) do
    @attr = { 
      :user_id => "1", 
      :project_id => "1",
      :owner_type => "client"
    }
  end

  it "should create a new instance given valid attributes" do
     Ownership.create!(@attr)
   end

Here is the failure:

Failures:

  1) Ownership should create a new instance given valid attributes
     Failure/Error: Ownership.create!(@attr)
     ActiveRecord::RecordInvalid:
       Validation failed: User can't be blank, Project can't be blank
     # ./spec/models/ownership_spec.rb:14:in `block (2 levels) in <top (required)>'

I don’t have any validation for a User or Project to not be blank. Here is my ownership model:

class Ownership < ActiveRecord::Base
  attr_accessible :owner_type

  belongs_to :project
  belongs_to :user

  validates :user_id, :presence => true

  validates :project_id, :presence => true

  validates :owner_type, :presence => true

end

Am I missing something? What did I do wrong? Also, the ownerships aren’t getting created in the actual app..this is what i’m using but isn’t working:

current_user.ownerships.create(:owner_type => 'designer', :project => @project)

here is my user model:

class User < ActiveRecord::Base
  attr_accessible :name, :email, :admin, :projects

  has_many :ownerships
  has_many :projects, :through => :ownerships

  accepts_nested_attributes_for :projects
  • 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-26T07:47:03+00:00Added an answer on May 26, 2026 at 7:47 am

    Add :user_id and :project_id to attr_accesible. Like you have done it for :owner_type. So it should look like

    attr_accessible :owner_type, :user_id, :project_id
    

    This should solve the problem.

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

Sidebar

Related Questions

Here is a test description, testing the Create New Widget use-case. Confirm that you
Here is a test framework to show what I am doing: create a new
I often hear around here from test driven development people that having a function
For example, my goal is to test the code given here: PHP script that
I have a test that's failing even though the operation actually works when I
I've got a small client/server test application where I have a Flex app that
I have a test that is failing with: ====================================================================== FAIL: test_register_should_create_UserProfile (APP.forum.tests.test_views.UserTestCAse) ---------------------------------------------------------------------- Traceback
here is the test page http://www.studioteknik.com/html/test-portfolio.html I got no error, but no hover-slide effect...
Here is my test page (dont mind the layout right now) https://www.bcidaho.com/test_kalyani/employer-plans-test.asp i found
http://steph.net23.net/work.php here is my test link. This page has a jquery script in it

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.