Skip to content

Commit

Permalink
Update assert_select for Nokogiri compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
dnrce committed Aug 10, 2015
1 parent 2908f3b commit 5bfdde2
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 48 deletions.
6 changes: 3 additions & 3 deletions test/controllers/contexts_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def test_show_xml_with_nil_context_returns_404
login_as :admin_user
get :show, { :id => "0", :format => 'xml' }
assert_response 404
assert_xml_select 'error', 'Context not found'
assert_select 'error', 'Context not found'
end

# RSS
Expand All @@ -97,7 +97,7 @@ def test_rss_feed_content
assert_equal 'application/rss+xml', @response.content_type
#puts @response.body

assert_xml_select 'rss[version="2.0"]' do
assert_select 'rss[version="2.0"]' do
assert_select 'channel' do
assert_select '>title', 'Tracks Contexts'
assert_select '>description', "Lists all the contexts for #{users(:admin_user).display_name}"
Expand Down Expand Up @@ -145,7 +145,7 @@ def test_atom_feed_content
assert_equal 'application/atom+xml', @response.content_type
#puts @response.body

assert_xml_select 'feed[xmlns="http://www.w3.org/2005/Atom"]' do
assert_select 'feed[xmlns="http://www.w3.org/2005/Atom"]' do
assert_select '>title', 'Tracks Contexts'
assert_select '>subtitle', "Lists all the contexts for #{users(:admin_user).display_name}"
assert_select 'entry', 10 do
Expand Down
6 changes: 3 additions & 3 deletions test/controllers/projects_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def test_rss_feed_content
assert_equal 'application/rss+xml', @response.content_type
#puts @response.body

assert_xml_select 'rss[version="2.0"]' do
assert_select 'rss[version="2.0"]' do
assert_select 'channel' do
assert_select '>title', 'Tracks Projects'
assert_select '>description', "Lists all the projects for #{users(:admin_user).display_name}"
Expand Down Expand Up @@ -119,7 +119,7 @@ def test_atom_feed_content
assert_equal 'application/atom+xml', @response.content_type
# puts @response.body

assert_xml_select 'feed[xmlns="http://www.w3.org/2005/Atom"]' do
assert_select 'feed[xmlns="http://www.w3.org/2005/Atom"]' do
assert_select '>title', 'Tracks Projects'
assert_select '>subtitle', "Lists all the projects for #{users(:admin_user).display_name}"
assert_select 'entry', 3 do
Expand Down Expand Up @@ -229,7 +229,7 @@ def test_xml_content
get :index, { :format => "xml" }
assert_equal 'application/xml', @response.content_type

assert_xml_select 'projects' do
assert_select 'projects' do
assert_select 'project', 3 do
assert_select 'name', /.+/
assert_select 'state', 'active'
Expand Down
26 changes: 13 additions & 13 deletions test/controllers/todos_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,8 @@ def test_fail_to_create_todo_via_xml
"project_name"=>"Build a working time machine",
"todo"=>{"notes"=>"", "description"=>"Call Warren Buffet to find out how much he makes per day", "due"=>"30/11/2006"}, "tag_list"=>"foo bar" }
assert_response 409
assert_xml_select "errors" do
assert_xml_select "error", "Context can't be blank"
assert_select "errors" do
assert_select "error", "Context can't be blank"
end
end

Expand Down Expand Up @@ -467,7 +467,7 @@ def test_rss_feed
assert_equal 'application/rss+xml', @response.content_type
# puts @response.body

assert_xml_select 'rss[version="2.0"]' do
assert_select 'rss[version="2.0"]' do
assert_select 'channel' do
assert_select '>title', 'Tracks Actions'
assert_select '>description', "Actions for #{users(:admin_user).display_name}"
Expand All @@ -488,7 +488,7 @@ def test_rss_feed_with_limit
login_as(:admin_user)
get :index, { :format => "rss", :limit => '5' }

assert_xml_select 'rss[version="2.0"]' do
assert_select 'rss[version="2.0"]' do
assert_select 'channel' do
assert_select '>title', 'Tracks Actions'
assert_select '>description', "Actions for #{users(:admin_user).display_name}"
Expand Down Expand Up @@ -524,13 +524,13 @@ def test_atom_feed_content
assert_equal 'application/atom+xml', @response.content_type
# #puts @response.body

assert_xml_select 'feed[xmlns="http://www.w3.org/2005/Atom"]' do
assert_xml_select '>title', 'Tracks Actions'
assert_xml_select '>subtitle', "Actions for #{users(:admin_user).display_name}"
assert_xml_select 'entry', 17 do
assert_xml_select 'title', /.+/
assert_xml_select 'content[type="html"]', /.*/
assert_xml_select 'published', /(#{Regexp.escape(todos(:book).updated_at.xmlschema)}|#{Regexp.escape(projects(:moremoney).updated_at.xmlschema)})/
assert_select 'feed[xmlns="http://www.w3.org/2005/Atom"]' do
assert_select '>title', 'Tracks Actions'
assert_select '>subtitle', "Actions for #{users(:admin_user).display_name}"
assert_select 'entry', 17 do
assert_select 'title', /.+/
assert_select 'content[type="html"]', /.*/
assert_select 'published', /(#{Regexp.escape(todos(:book).updated_at.xmlschema)}|#{Regexp.escape(projects(:moremoney).updated_at.xmlschema)})/
end
end
end
Expand Down Expand Up @@ -846,7 +846,7 @@ def test_url_with_slash_in_query_string_are_parsed_correctly
todo.notes = "foo #{url} bar"
todo.save!
get :index
assert_select("a[href=#{url}]")
assert_select("a[href=\"#{url}\"]")
end

def test_format_note_normal
Expand Down Expand Up @@ -875,7 +875,7 @@ def test_format_note_link
todo.save!
get :index
assert_select("div#notes_todo_#{todo.id}", 'A link to http://github.com/.')
assert_select("div#notes_todo_#{todo.id} a[href=http://github.com/]", 'http://github.com/')
assert_select("div#notes_todo_#{todo.id} a[href=\"http://github.com/\"]", 'http://github.com/')
end

def test_format_note_link_message
Expand Down
11 changes: 6 additions & 5 deletions test/integration/project_xml_api_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ class ProjectXmlApiTest < ActionDispatch::IntegrationTest

def test_retrieve_project
authenticated_get_xml "/projects/1.xml", users(:admin_user).login, 'abracadabra', {}
assert_tag :tag => "project"
assert_tag :tag => "project", :child => {:tag => "not_done" }
assert_tag :tag => "project", :child => {:tag => "deferred" }
assert_tag :tag => "project", :child => {:tag => "pending" }
assert_tag :tag => "project", :child => {:tag => "done" }
assert_select 'project' do
assert_select 'not_done'
assert_select 'deferred'
assert_select 'pending'
assert_select 'done'
end
assert_response 200
end

Expand Down
10 changes: 6 additions & 4 deletions test/integration/todo_xml_api_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@ def test_get_tickler_needs_authentication
def test_get_tickler_returns_all_deferred_and_pending_todos
number = @user.todos.deferred.count + @user.todos.pending.count
authenticated_get_xml "/tickler.xml", @user.login, @password, {}
assert_tag :tag => "todos", :children => { :count => number }
assert_select 'todos' do
assert_select 'todo', count: number
end
end

def test_get_tickler_omits_user_id
authenticated_get_xml "/tickler.xml", @user.login, @password, {}
assert_no_tag :tag => "user_id"
assert_select 'user_id', false
end

def test_get_index_with_only_active_todos
Expand Down Expand Up @@ -245,7 +247,7 @@ def test_post_create_todo_with_wrong_project_and_context_id
<project_id type='integer'>-11</project_id>
</todo>"
assert_response 409
assert_xml_select 'errors' do
assert_select 'errors' do
assert_select 'error', 2
end
end
Expand All @@ -261,4 +263,4 @@ def authenticated_post_xml_to_todo_create(postdata = @@valid_postdata, user = @u
authenticated_post_xml "/todos.xml", user, password, postdata
end

end
end
11 changes: 6 additions & 5 deletions test/integration/users_xml_api_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,17 @@ def test_fails_with_get_verb
def test_get_users_as_xml
get '/users.xml', {}, basic_auth_headers()
assert_response :success
assert_tag :tag => "users",
:children => { :count => 4, :only => { :tag => "user" } }
assert_no_tag :tag => "password"
assert_select 'users' do
assert_select 'user', count: 4
end
assert_select 'password', false
end

def test_get_user_as_xml
get "/users/#{users(:other_user).id}.xml", {}, basic_auth_headers()
assert_response :success
assert_tag :tag => "user"
assert_no_tag :tag => "password"
assert_select 'user'
assert_select 'password', false
end

private
Expand Down
16 changes: 1 addition & 15 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,6 @@ def generate_random_string(length)
def assert_equal_dmy(date1, date2)
assert_equal date1.strftime("%d-%m-%y"), date2.strftime("%d-%m-%y")
end

def xml_document
@xml_document ||= HTML::Document.new(@response.body, false, true)
end

def assert_xml_select(*args, &block)
@html_document = xml_document
assert_select(*args, &block)
end
end

class ActionController::TestCase
Expand All @@ -90,11 +81,6 @@ def ajax_create(name)
xhr :post, :create, get_model_class.downcase => {:name => name}
end

def assert_xml_select(*args, &block)
@html_document = xml_document
assert_select(*args, &block)
end

private

def get_model_class
Expand Down Expand Up @@ -145,7 +131,7 @@ def assert_401_unauthorized_admin

def assert_responses_with_error(error_msg)
assert_response 409
assert_xml_select 'errors' do
assert_select 'errors' do
assert_select 'error', 1, error_msg
end
end
Expand Down

0 comments on commit 5bfdde2

Please sign in to comment.