# How to test partial

**URL:** <https://www.ruby-forum.com/t/how-to-test-partial/119464>\
**Category:** Rails\
**Created:** [November 7, 2007, 6:27am UTC](https://www.ruby-forum.com/t/how-to-test-partial/119464 "2007-11-07T06:27:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/5f9b8f/32.png) [@sam](https://www.ruby-forum.com/u/sam)\
**Post date:** [November 7, 2007, 6:27am UTC](https://www.ruby-forum.com/t/how-to-test-partial/119464/1 "2007-11-07T06:27:15Z")

</div>

Hello,

This is the test code. Over here i am trying to test the partial, is  
it render or not?

I tried to test it with assert\_tag, but its giving me an error and  
the whole dump of th partial.  
I have never tested partial. So if any body has test partial, please  
help me with this

def test\_update\_cloud  
get :update\_cloud  
assert\_response(:success)  
assert\_tag :tag =\> ‘span’,attributes =\> { :id =\> “notification” }  
end

* * *

This is the controller code I went to test.

def update\_cloud  
cloud  
render :partial =\> “/shared/cloud”  
end

* * *

This is the small piece of parial code called ‘cloud’ it’s in shared  
directory

100 Highlight level? \<%= select\_tag ‘num\_gray[]’,  
101 options\_for\_select({ ‘least (’+@num\_size\_one.to\_s+’)’ =\> 1,  
‘less (’+@num\_size\_two.to\_s+’)’ =\> 2, ‘average (’+@num\_size\_three.to\_s  
+’)’ =\> 3, ‘more (’+@num\_size\_four.to\_s+’)’ =\> 4, ‘most  
(’+@num\_size\_five.to\_s+’)’=\> 5}.sort{|a,b| a[1]\<=\>b[1]},  
@num\_gray), :onchange =\>  
‘changeColor(this.options[this.selectedIndex].value)’ %\>  
102   
  
103  
104 \<%= @link2 %\>

* * *

This is the cloud method, not really relevent here.

def cloud  
# tag\_id is in both triples and events tables. which one?  
# ajax feature to choose how many tags are going to be gray  
@num\_gray = params[:num\_gray] ? params[:num\_gray].to\_i : 1  
logger.debug ’ num\_gray = %s ’ % @num\_gray

```
   @total = 0 #number of all tag_id
   @size_tag = Hash.new
   @distinct_triples = Triple.find_by_sql("select distinct tag_id

```

from triples")  
logger.debug ’ distinct\_triples = %s ’ % @distinct\_triples

```
   @distinct_triples.each do |t|
     if(!t.tag.nil? && !t.tag.name.empty?) then
     @size_tag[t.tag_id] = Triple.find(:all, :condition

```

[“tag\_i= ?”,t.tag\_id]).size  
@total += @size\_tag[t.tag\_id]  
end

Thanks

---

<div class="post-metadata">

**Author:** ![sam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/5f9b8f/32.png) [@sam](https://www.ruby-forum.com/u/sam)\
**Post date:** [November 7, 2007, 12:30pm UTC](https://www.ruby-forum.com/t/how-to-test-partial/119464/2 "2007-11-07T12:30:01Z")

</div>

One of these must work,

def test\_update\_cloud  
get :update\_cloud  
assert\_response(:success)  
assert\_tag :tag =\> ‘span’, :attributes =\> { :id =\> “notification” }  
end

OR

def test\_update\_cloud  
get :update\_cloud  
assert\_response(:success)  
assert\_tag :tag =\> ‘span’, :attributes =\> { :id =\> /notification/ }  
end

---

<div class="post-metadata">

**Author:** ![sam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/5f9b8f/32.png) [@sam](https://www.ruby-forum.com/u/sam)\
**Post date:** [November 7, 2007, 3:45pm UTC](https://www.ruby-forum.com/t/how-to-test-partial/119464/3 "2007-11-07T15:45:07Z")

</div>

On Nov 7, 2007 12:26 AM, sam [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> def test\_update\_cloud  
> get :update\_cloud  
> assert\_response(:success)  
> assert\_tag :tag =\> ‘span’,attributes =\> { :id =\> “notification” }  
> end

The colon is missing on :attributes, but I see you have it correct in  
your followup message. Don’t retype code; cut and paste.

The assert\_tag call is fine, but assert\_select is the new sexy way to do  
this.

In any event, we can’t help unless you post the specific error message  
and identify the specific line that is raising the message. Your test  
looks OK as written.
