Skip to content

Commit

Permalink
Make assert_tag :children count appropriately. Closes #2181.
Browse files Browse the repository at this point in the history
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2500 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information
Marcel Molina committed Oct 9, 2005
1 parent 64cd4e4 commit a9de9c4
Show file tree
Hide file tree
Showing 3 changed files with 131 additions and 2 deletions.
2 changes: 2 additions & 0 deletions actionpack/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*

* Make assert_tag :children count appropriately. Closes #2181. [jamie@bravenet.com]

* Forced newer versions of RedCloth to use hard breaks [DHH]

* Added new scriptaculous options for auto_complete_field #2343 [m.stienstra@fngtps.com]
Expand Down
Expand Up @@ -435,7 +435,7 @@ def match(conditions)

# count children
if opts = conditions[:children]
matches = children
matches = children.select { |c| c.match(/./) }
matches = matches.select { |c| c.match(opts[:only]) } if opts[:only]
opts.each do |key, value|
next if key == :only
Expand Down
129 changes: 128 additions & 1 deletion actionpack/test/controller/test_test.rb
Expand Up @@ -89,7 +89,134 @@ def test_multiple_calls
assert_equal "OK", @response.body
end

def test_assert_tag
def test_assert_tag_tag
process :test_html_output

# there is a 'form' tag
assert_tag :tag => 'form'
# there is not an 'hr' tag
assert_no_tag :tag => 'hr'
end

def test_assert_tag_attributes
process :test_html_output

# there is a tag with an 'id' of 'bar'
assert_tag :attributes => { :id => "bar" }
# there is no tag with a 'name' of 'baz'
assert_no_tag :attributes => { :name => "baz" }
end

def test_assert_tag_parent
process :test_html_output

# there is a tag with a parent 'form' tag
assert_tag :parent => { :tag => "form" }
# there is no tag with a parent of 'input'
assert_no_tag :parent => { :tag => "input" }
end

def test_assert_tag_child
process :test_html_output

# there is a tag with a child 'input' tag
assert_tag :child => { :tag => "input" }
# there is no tag with a child 'a' tag
assert_no_tag :child => { :tag => "a" }
end

def test_assert_tag_ancestor
process :test_html_output

# there is a 'li' tag with an ancestor having an id of 'foo'
assert_tag :ancestor => { :attributes => { :id => "foo" } }, :tag => "li"
# there is no tag of any kind with an ancestor having an href matching 'foo'
assert_no_tag :ancestor => { :attributes => { :href => /foo/ } }
end

def test_assert_tag_descendant
process :test_html_output

# there is a tag with a decendant 'li' tag
assert_tag :descendant => { :tag => "li" }
# there is no tag with a descendant 'html' tag
assert_no_tag :descendant => { :tag => "html" }
end

def test_assert_tag_sibling
process :test_html_output

# there is a tag with a sibling of class 'item'
assert_tag :sibling => { :attributes => { :class => "item" } }
# there is no tag with a sibling 'ul' tag
assert_no_tag :sibling => { :tag => "ul" }
end

def test_assert_tag_after
process :test_html_output

# there is a tag following a sibling 'div' tag
assert_tag :after => { :tag => "div" }
# there is no tag following a sibling tag with id 'bar'
assert_no_tag :after => { :attributes => { :id => "bar" } }
end

def test_assert_tag_before
process :test_html_output

# there is a tag preceeding a tag with id 'bar'
assert_tag :before => { :attributes => { :id => "bar" } }
# there is no tag preceeding a 'form' tag
assert_no_tag :before => { :tag => "form" }
end

def test_assert_tag_children_count
process :test_html_output

# there is a tag with 2 children
assert_tag :children => { :count => 2 }
# there is no tag with 4 children
assert_no_tag :children => { :count => 4 }
end

def test_assert_tag_children_less_than
process :test_html_output

# there is a tag with less than 5 children
assert_tag :children => { :less_than => 5 }
# there is no 'ul' tag with less than 2 children
assert_no_tag :children => { :less_than => 2 }, :tag => "ul"
end

def test_assert_tag_children_greater_than
process :test_html_output

# there is a 'body' tag with more than 1 children
assert_tag :children => { :greater_than => 1 }, :tag => "body"
# there is no tag with more than 10 children
assert_no_tag :children => { :greater_than => 10 }
end

def test_assert_tag_children_only
process :test_html_output

# there is a tag containing only one child with an id of 'foo'
assert_tag :children => { :count => 1,
:only => { :attributes => { :id => "foo" } } }
# there is no tag containing only one 'li' child
assert_no_tag :children => { :count => 1, :only => { :tag => "li" } }
end

def test_assert_tag_content
process :test_html_output

# the output contains the string "Name"
assert_tag :content => "Name"
# the output does not contain the string "test"
assert_no_tag :content => "test"
end

def test_assert_tag_multiple
process :test_html_output

# there is a 'div', id='bar', with an immediate child whose 'action'
Expand Down

0 comments on commit a9de9c4

Please sign in to comment.