# Testing a model method - private method?

**URL:** <https://www.ruby-forum.com/t/testing-a-model-method-private-method/97410>\
**Category:** Rails\
**Created:** [January 25, 2006, 9:59pm UTC](https://www.ruby-forum.com/t/testing-a-model-method-private-method/97410 "2006-01-25T21:59:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![seanhussey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a88e57/32.png) [@seanhussey](https://www.ruby-forum.com/u/seanhussey)\
**Post date:** [January 25, 2006, 9:59pm UTC](https://www.ruby-forum.com/t/testing-a-model-method-private-method/97410/1 "2006-01-25T21:59:41Z")

</div>

Hi everyone,

I’m trying to test a method in my model:

def html\_email  
return “” + self.email + “”  
end

The method works ok. But when I try to test it:

```
assert_equal ("<a href='mailto:" + people(:staff1_person).email +

```

“’\>” + people(:staff1\_person).email + “”), @person.html\_email

I get a failure:

1. Error:  
test\_html\_email(PersonTest):  
NoMethodError: private method `html_email' called for #<Person:0x256b460> /Applications/Locomotive/Bundles/rails-1.0.0-max.bundle/Contents/Resources/ports/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/base.rb:1501:in`method\_missing’  
test/unit/person\_test.rb:32:in `test\_html\_email’

The method works without errors (that I can see) when using it in a  
view. Why not in a test?

Thanks,

Sean

---

<div class="post-metadata">

**Author:** ![seanhussey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a88e57/32.png) [@seanhussey](https://www.ruby-forum.com/u/seanhussey)\
**Post date:** [January 25, 2006, 10:02pm UTC](https://www.ruby-forum.com/t/testing-a-model-method-private-method/97410/2 "2006-01-25T22:02:42Z")

</div>

Somewhere above the html\_email method you have the keyword  
‘private’. You need to move the html\_email method above the private  
keyword or it will only be accessible by member functions of your model.

-Derrick S.

---

<div class="post-metadata">

**Author:** ![seanhussey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a88e57/32.png) [@seanhussey](https://www.ruby-forum.com/u/seanhussey)\
**Post date:** [January 25, 2006, 10:08pm UTC](https://www.ruby-forum.com/t/testing-a-model-method-private-method/97410/3 "2006-01-25T22:08:45Z")

</div>

That wasn’t it, but it clued me into what it was. The method was  
defined AFTER the Person class definition ended.

What’s the statute of limitations on calling oneself a newbie? I’m  
going to have to finish off these posts with “Sorry, I’m a doofus”  
instead.

Thanks, Derrick! 🙂

Sean
