mirror of
https://github.com/TracksApp/tracks.git
synced 2026-02-02 14:11:46 +01:00
Update assert_select for Nokogiri compatibility
assert_select has been moved into the rails-dom-testing gem and is now based on Nokogiri. * Remove assert_tag and assert_xml_select * Quote CSS attribute selector values * Use decoded versions of HTML in assert_select. Nokogiri decodes elements prior to matching. * Add a test helper for entities such as ` ` for which it's difficult or confusing to include the decoded version directly in the assertion. * Assert directly on Atom feeds' XML namespace because it isn't selectable as an attribute
This commit is contained in:
parent
d7d86446c0
commit
689db4c9c3
9 changed files with 66 additions and 64 deletions
|
|
@ -1,6 +1,9 @@
|
|||
require 'test_helper'
|
||||
require 'support/html_entity_helper'
|
||||
|
||||
class ContextsControllerTest < ActionController::TestCase
|
||||
include HTMLEntityHelper
|
||||
|
||||
fixtures :users, :preferences, :contexts
|
||||
|
||||
def test_contexts_list
|
||||
|
|
@ -96,7 +99,7 @@ class ContextsControllerTest < ActionController::TestCase
|
|||
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
|
||||
|
|
@ -107,7 +110,7 @@ class ContextsControllerTest < ActionController::TestCase
|
|||
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}"
|
||||
|
|
@ -118,7 +121,7 @@ class ContextsControllerTest < ActionController::TestCase
|
|||
assert_select 'title', /.+/
|
||||
assert_select 'description' do
|
||||
assert_select_encoded do
|
||||
assert_select 'p', /\d+ actions. Context is (Active|Hidden)./
|
||||
assert_select 'p', /\d+#{nbsp}actions. Context is (Active|Hidden)./
|
||||
end
|
||||
end
|
||||
%w(guid link).each do |node|
|
||||
|
|
@ -153,16 +156,15 @@ class ContextsControllerTest < ActionController::TestCase
|
|||
login_as :admin_user
|
||||
get :index, { :format => "atom" }
|
||||
assert_equal 'application/atom+xml', @response.content_type
|
||||
#puts @response.body
|
||||
|
||||
assert_xml_select 'feed[xmlns="http://www.w3.org/2005/Atom"]' do
|
||||
assert_equal 'http://www.w3.org/2005/Atom', html_document.children[0].namespace.href
|
||||
assert_select 'feed' do
|
||||
assert_select '>title', 'Tracks Contexts'
|
||||
assert_select '>subtitle', "Lists all the contexts for #{users(:admin_user).display_name}"
|
||||
assert_select 'entry', 10 do
|
||||
assert_select 'title', /.+/
|
||||
assert_select 'content[type="html"]' do
|
||||
assert_select_encoded do
|
||||
assert_select 'p', /\d+ actions. Context is (Active|Hidden)./
|
||||
assert_select 'p', /\d+#{nbsp}actions. Context is (Active|Hidden)./
|
||||
end
|
||||
end
|
||||
assert_select 'published', /(#{Regexp.escape(contexts(:agenda).created_at.xmlschema)}|#{Regexp.escape(contexts(:library).created_at.xmlschema)})/
|
||||
|
|
|
|||
|
|
@ -26,4 +26,4 @@ class FeedlistControllerTest < ActionController::TestCase
|
|||
assert_response 200
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
require 'test_helper'
|
||||
require 'support/html_entity_helper'
|
||||
|
||||
class ProjectsControllerTest < ActionController::TestCase
|
||||
include HTMLEntityHelper
|
||||
|
||||
def setup
|
||||
end
|
||||
|
|
@ -83,7 +85,7 @@ class ProjectsControllerTest < ActionController::TestCase
|
|||
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}"
|
||||
|
|
@ -94,7 +96,7 @@ class ProjectsControllerTest < ActionController::TestCase
|
|||
assert_select 'title', /.+/
|
||||
assert_select 'description' do
|
||||
assert_select_encoded do
|
||||
assert_select 'p', /^\d+ actions\. Project is (active|hidden|completed)\.$/
|
||||
assert_select 'p', /^\d+#{nbsp}actions\. Project is (active|hidden|completed)\.$/
|
||||
end
|
||||
end
|
||||
%w(guid link).each do |node|
|
||||
|
|
@ -127,16 +129,15 @@ class ProjectsControllerTest < ActionController::TestCase
|
|||
login_as :admin_user
|
||||
get :index, { :format => "atom" }
|
||||
assert_equal 'application/atom+xml', @response.content_type
|
||||
# puts @response.body
|
||||
|
||||
assert_xml_select 'feed[xmlns="http://www.w3.org/2005/Atom"]' do
|
||||
assert_equal 'http://www.w3.org/2005/Atom', html_document.children[0].namespace.href
|
||||
assert_select 'feed' do
|
||||
assert_select '>title', 'Tracks Projects'
|
||||
assert_select '>subtitle', "Lists all the projects for #{users(:admin_user).display_name}"
|
||||
assert_select 'entry', 3 do
|
||||
assert_select 'title', /.+/
|
||||
assert_select 'content[type="html"]' do
|
||||
assert_select_encoded do
|
||||
assert_select 'p', /\d+ actions. Project is (active|hidden|completed)./
|
||||
assert_select 'p', /\d+#{nbsp}actions. Project is (active|hidden|completed)./
|
||||
end
|
||||
end
|
||||
assert_select 'published', /(#{Regexp.escape(projects(:timemachine).updated_at.xmlschema)}|#{Regexp.escape(projects(:moremoney).updated_at.xmlschema)})/
|
||||
|
|
@ -239,7 +240,7 @@ class ProjectsControllerTest < ActionController::TestCase
|
|||
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'
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
require 'test_helper'
|
||||
|
||||
class TodosControllerTest < ActionController::TestCase
|
||||
|
||||
def test_get_index_when_not_logged_in
|
||||
get :index
|
||||
assert_redirected_to login_url
|
||||
|
|
@ -235,8 +234,8 @@ class TodosControllerTest < ActionController::TestCase
|
|||
"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
|
||||
|
||||
|
|
@ -467,7 +466,7 @@ class TodosControllerTest < ActionController::TestCase
|
|||
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}"
|
||||
|
|
@ -488,7 +487,7 @@ class TodosControllerTest < ActionController::TestCase
|
|||
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}"
|
||||
|
|
@ -522,15 +521,14 @@ class TodosControllerTest < ActionController::TestCase
|
|||
login_as :admin_user
|
||||
get :index, { :format => "atom" }
|
||||
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_equal 'http://www.w3.org/2005/Atom', html_document.children[0].namespace.href
|
||||
assert_select 'feed' 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
|
||||
|
|
@ -846,7 +844,7 @@ class TodosControllerTest < ActionController::TestCase
|
|||
todo.notes = "foo #{url} bar"
|
||||
todo.save!
|
||||
get :index
|
||||
assert_select "a[href=#{url}]"
|
||||
assert_select "a[href='#{url}']"
|
||||
end
|
||||
|
||||
def test_link_opened_in_new_window
|
||||
|
|
@ -886,7 +884,7 @@ class TodosControllerTest < ActionController::TestCase
|
|||
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
|
||||
|
|
@ -895,9 +893,9 @@ class TodosControllerTest < ActionController::TestCase
|
|||
todo.raw_notes = "A Mail.app message://<ABCDEF-GHADB-123455-FOO-BAR@example.com> link"
|
||||
todo.save!
|
||||
get :index
|
||||
assert_select("div#notes_todo_#{todo.id}", 'A Mail.app message://<ABCDEF-GHADB-123455-FOO-BAR@example.com> link')
|
||||
assert_select("div#notes_todo_#{todo.id} a", 'message://<ABCDEF-GHADB-123455-FOO-BAR@example.com>')
|
||||
assert_select("div#notes_todo_#{todo.id} a[href=message://<ABCDEF-GHADB-123455-FOO-BAR@example.com>]", 'message://<ABCDEF-GHADB-123455-FOO-BAR@example.com>')
|
||||
assert_select("div#notes_todo_#{todo.id}", 'A Mail.app message://<ABCDEF-GHADB-123455-FOO-BAR@example.com> link')
|
||||
assert_select("div#notes_todo_#{todo.id} a", 'message://<ABCDEF-GHADB-123455-FOO-BAR@example.com>')
|
||||
assert_select("div#notes_todo_#{todo.id} a[href='message://<ABCDEF-GHADB-123455-FOO-BAR@example.com>']", "message://<ABCDEF-GHADB-123455-FOO-BAR@example.com>")
|
||||
end
|
||||
|
||||
def test_format_note_link_onenote
|
||||
|
|
@ -908,7 +906,7 @@ class TodosControllerTest < ActionController::TestCase
|
|||
get :index
|
||||
assert_select("div#notes_todo_#{todo.id}", 'link me to onenote')
|
||||
assert_select("div#notes_todo_#{todo.id} a", 'link me to onenote')
|
||||
assert_select("div#notes_todo_#{todo.id} a[href=onenote:///E:%5COneNote%5Cdir%5Cnotes.one#PAGE&section-id=%7BFD597D3A-3793-495F-8345-23D34A00DD3B%7D&page-id=%7B1C95A1C7-6408-4804-B3B5-96C28426022B%7D&end]", 'link me to onenote')
|
||||
assert_select("div#notes_todo_#{todo.id} a[href='onenote:///E:%5COneNote%5Cdir%5Cnotes.one#PAGE§ion-id=%7BFD597D3A-3793-495F-8345-23D34A00DD3B%7D&page-id=%7B1C95A1C7-6408-4804-B3B5-96C28426022B%7D&end']", 'link me to onenote')
|
||||
end
|
||||
|
||||
##############
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue