How to test partial

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 (’[email protected]_size_one.to_s+’)’ => 1,
‘less (’[email protected]_size_two.to_s+’)’ => 2, ‘average (’[email protected]_size_three.to_s
+’)’ => 3, ‘more (’[email protected]_size_four.to_s+’)’ => 4, ‘most
(’[email protected]_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

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

On Nov 7, 2007 12:26 AM, sam [email protected] 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.