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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T21:37:19+00:00 2026-05-16T21:37:19+00:00

I was hoping someone would spot why this wouldn’t work. I am getting an

  • 0

I was hoping someone would spot why this wouldn’t work.

I am getting an error thats being called because the attributes I specify with Factory_Girl are not being applied to the stub before validation.

The Error:

undefined method `downcase' for #<Category:0x1056f2f60>

RSpec2

it "should vote up" do
  @mock_vote = Factory.create(:vote)
  Vote.stub(:get_vote).and_return(@mock_vote)
  get :vote_up, :id => "1"        
end

Factories

Factory.define :vote, :class => Vote do |v|
  v.user_id "1"
  v.association :post
end

Factory.define :post, :class => Post do |p|
  p.category "spirituality"
  p.name "sleezy snail potluck"
  p.association :category
end

Factory.define :category, :class => Category do |c|
  c.name "spirituality"
  c.id "37"
end

Post.rb – Model

before_save           :prepare_posts
validate              :category?

def prepare_posts
  self.update_attribute("category", self.category.downcase)
  if self.url?
    self.url = "http://" + self.url unless self.url.match /^(https?|ftp):\/\//
  end
end

def category?
  unless Category.exists?(:name => self.category.downcase)
    errors.add(:category, "There's no categories with that name.")
  end
  return true
end

Also, feel free to nitpick any blatantly gross looking code. 😀

Thanks!!

  • 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-16T21:37:20+00:00Added an answer on May 16, 2026 at 9:37 pm

    You have a category attribute, which appears to be a string, but you also seem to have a category association which automatically creates, among other things, an attribute on Post called category, probably overwriting your category attribute. Hence, the Category class has no downcase method, because it’s not a String.

    Rename your category attribute to something like category_name, but really you shouldn’t have that attribute at all.

    Maybe where you’re calling self.category.downcase you meant self.category.name.downcase?

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

Sidebar

Related Questions

I joined this site today hoping someone would be kind enough to explain to
This would be a real pain to try to duplicate, so I'm hoping someone
Hi was I hoping someone would help understand this behaviour of the below code.
I'm hoping someone could shed some light on how I would do this in
Hoping someone can shed some light on this: Do lookup tables need their own
Hoping someone can clear this up for me. Let's say I have 2 globals:
I am hoping someone could enlighten me as to why I am getting the
I was hoping someone with better math capabilities would assist me in figuring out
I was hoping someone would be able to help me with a problem I've
I'm hoping someone can enlighten me as to what could possibly be causing 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.