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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T14:38:51+00:00 2026-06-10T14:38:51+00:00

I have two models Indicator belongs_to Privacy. In indicator I wrote a method to

  • 0

I have two models Indicator belongs_to Privacy.

In indicator I wrote a method to return the proper name of the privacy setting

def privacy
    Privacy.find(privacy_tag_id).content
end

That works in rails console. If I create an Indicator and then run Indicator.privacy I get back “red” or “green” or whatever. But I can’t get my rspec to pass. Here is the test

describe "indicator" do
    it "should return a human named when asked for its privacy level" do
        @privacy = PrivacyTag.create(:content => "Secret")
        @ind = Indicator.new(:content => 'test',
                             :privacy_tag_id => @privacy.id)
        @ind.privacy.should == "Secret"
    end
end

When I run the test I get this message:

Failures:

  1) indicator should return a human named when asked for its privacy level
     Failure/Error: @ind.privacy.should_equal "Secret"
     ActiveRecord::RecordNotFound:
       Couldn't find PrivacyTag without an ID
     # ./app/models/indicator.rb:13:in `privacy'
     # ./spec/models/indicator_model_spec.rb:9:in `block (2 levels) in <top (required)>'

What am I doing wrong in my test? Any ideas?

  • 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-10T14:38:53+00:00Added an answer on June 10, 2026 at 2:38 pm

    I would suspect that the Privacy object isn’t being created. Try calling create! instead of create. If it raises an exception, then that means that your Privacy model has some validations in it.

    It would’ve been super helpful to have seen your models in the first place.

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

Sidebar

Related Questions

I have two models: class Contact(models.Model): name = models.CharField(max_length=255) class Campaign(models.Model): contact = models.ForeignKey(Contact,
I have the following models: class Indicator(models.Model): name = models.CharField(max_length=200) category = models.ForeignKey(IndicatorCategory) weight
I have two models Company and Role related by has_many and belongs_to association respectively.
I have two models: class Category < ActiveRecord::Base has_one :weight after_create :create_category_weight def create_category_weight
I have two models: class Studio(models.Model): name = models.CharField(Studio, max_length=30, unique=True) class Film(models.Model): studio
I have two models named message.php and user.php In message.php, I have following method
I have two models Station and Broadcast . Broadcast belongs_to Station and has a
I have two models and controllers: Snippets, and Tags. There is a belongs_to relationship,
I have two models, Listing and Invitation, associated with has_and_belongs_to_many. I am looking at
I have two Models, Programme and Event, a programme has many events. I need

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.