Improve test coverage

This commit is contained in:
Tom Hughes 2015-02-27 00:40:37 +00:00
parent f8f921e09d
commit f04211b172
16 changed files with 174 additions and 44 deletions

View file

@ -18,6 +18,7 @@ module GeocoderHelper
html << result[:prefix] if result[:prefix]
html << " " if result[:prefix] && result[:name]
html << link_to(result[:name], url, html_options) if result[:name]
html << " " if result[:suffix] && result[:name]
html << result[:suffix] if result[:suffix]
html.html_safe
end

View file

@ -120,10 +120,6 @@ class Changeset < ActiveRecord::Base
self.num_changes += elements
end
def tags_as_hash
tags
end
def tags
unless @tags
@tags = {}

View file

@ -93,11 +93,6 @@ class OldRelation < ActiveRecord::Base
el
end
# Temporary method to match interface to nodes
def tags_as_hash
tags
end
# Temporary method to match interface to relations
def relation_members
old_members

View file

@ -116,11 +116,6 @@ class OldWay < ActiveRecord::Base
points
end
# Temporary method to match interface to nodes
def tags_as_hash
tags
end
# Temporary method to match interface to ways
def way_nodes
old_nodes

View file

@ -262,11 +262,6 @@ class Relation < ActiveRecord::Base
true
end
# Temporary method to match interface to nodes
def tags_as_hash
tags
end
##
# if any members are referenced by placeholder IDs (i.e: negative) then
# this calling this method will fix them using the map from placeholders

View file

@ -83,16 +83,6 @@ class Way < ActiveRecord::Base
way
end
# Find a way given it's ID, and in a single SQL call also grab its nodes
#
# You can't pull in all the tags too unless we put a sequence_id on the way_tags table and have a multipart key
def self.find_eager(id)
Way.find(id, :include => { :way_nodes => :node })
# If waytag had a multipart key that was real, you could do this:
# Way.find(id, :include => [:way_tags, {:way_nodes => :node}])
end
# Find a way given it's ID, and in a single SQL call also grab its nodes and tags
def to_xml
doc = OSM::API.new.get_xml_doc
@ -242,11 +232,6 @@ class Way < ActiveRecord::Base
end
end
# Temporary method to match interface to nodes
def tags_as_hash
tags
end
##
# if any referenced nodes are placeholder IDs (i.e: are negative) then
# this calling this method will fix them using the map from placeholders

View file

@ -38,10 +38,4 @@ module GeoRecord
def lon
longitude.to_f / SCALE
end
private
def lat2y(a)
180 / Math::PI * Math.log(Math.tan(Math::PI / 4 + a * (Math::PI / 180) / 2))
end
end

View file

@ -180,6 +180,7 @@ class ChangesetControllerTest < ActionController::TestCase
# document structure.
def test_read
changeset_id = changesets(:normal_user_first_change).id
get :read, :id => changeset_id
assert_response :success, "cannot get first changeset"
@ -193,6 +194,17 @@ class ChangesetControllerTest < ActionController::TestCase
assert_select "osm[version='#{API_VERSION}'][generator='OpenStreetMap server']", 1
assert_select "osm>changeset[id='#{changeset_id}']", 1
assert_select "osm>changeset>discussion", 1
assert_select "osm>changeset>discussion>comment", 0
changeset_id = changesets(:normal_user_closed_change).id
get :read, :id => changeset_id, :include_discussion => true
assert_response :success, "cannot get closed changeset with comments"
assert_select "osm[version='#{API_VERSION}'][generator='OpenStreetMap server']", 1
assert_select "osm>changeset[id='#{changeset_id}']", 1
assert_select "osm>changeset>discussion", 1
assert_select "osm>changeset>discussion>comment", 3
end
##

View file

@ -366,8 +366,8 @@ class MessageControllerTest < ActionController::TestCase
assert_equal false, m.to_user_visible
# Check that the deleting a sent message works
post :delete, :message_id => messages(:unread_message).id
assert_redirected_to inbox_path(:display_name => users(:normal_user).display_name)
post :delete, :message_id => messages(:unread_message).id, :referer => outbox_path(:display_name => users(:normal_user).display_name)
assert_redirected_to outbox_path(:display_name => users(:normal_user).display_name)
assert_equal "Message deleted", flash[:notice]
m = Message.find(messages(:unread_message).id)
assert_equal false, m.from_user_visible

View file

@ -90,6 +90,12 @@ class BrowseHelperTest < ActionView::TestCase
html = format_value("phone", "+1234567890")
assert_dom_equal "<a href=\"tel:+1234567890\" title=\"Call +1234567890\">+1234567890</a>", html
html = format_value("wikipedia", "Test")
assert_dom_equal "<a title=\"The Test article on Wikipedia\" href=\"http://en.wikipedia.org/wiki/Test?uselang=en\">Test</a>", html
html = format_value("wikidata", "Q42")
assert_dom_equal "<a title=\"The Q42 item on Wikidata\" href=\"//www.wikidata.org/wiki/Q42?uselang=en\">Q42</a>", html
end
def test_icon_tags

View file

@ -0,0 +1,23 @@
require "test_helper"
class GeocoderHelperTest < ActionView::TestCase
def test_result_to_html
html = result_to_html(:lat => 1.23, :lon => 4.56, :zoom => 16, :name => "Name")
assert_dom_equal %q(<a class="set_position" data-lat="1.23" data-lon="4.56" data-zoom="16" data-name="Name" href="/#map=16/1.23/4.56">Name</a>), html
html = result_to_html(:lat => 1.23, :lon => 4.56, :zoom => 16, :prefix => "Prefix", :name => "Name")
assert_dom_equal %q(Prefix <a class="set_position" data-lat="1.23" data-lon="4.56" data-zoom="16" data-prefix="Prefix" data-name="Name" href="/#map=16/1.23/4.56">Name</a>), html
html = result_to_html(:lat => 1.23, :lon => 4.56, :zoom => 16, :name => "Name", :suffix => "Suffix")
assert_dom_equal %q(<a class="set_position" data-lat="1.23" data-lon="4.56" data-zoom="16" data-name="Name" data-suffix="Suffix" href="/#map=16/1.23/4.56">Name</a> Suffix), html
html = result_to_html(:lat => 1.23, :lon => 4.56, :zoom => 16, :prefix => "Prefix", :name => "Name", :suffix => "Suffix")
assert_dom_equal %q(Prefix <a class="set_position" data-lat="1.23" data-lon="4.56" data-zoom="16" data-prefix="Prefix" data-name="Name" data-suffix="Suffix" href="/#map=16/1.23/4.56">Name</a> Suffix), html
html = result_to_html(:type => "node", :id => 123456, :name => "Name")
assert_dom_equal %q(<a class="set_position" data-type="node" data-id="123456" data-name="Name" href="/node/123456">Name</a>), html
html = result_to_html(:min_lat => 1.23, :max_lat => 4.56, :min_lon => -1.23, :max_lon => 2.34, :name => "Name")
assert_dom_equal %q(<a class="set_position" data-min-lat="1.23" data-max-lat="4.56" data-min-lon="-1.23" data-max-lon="2.34" data-name="Name" href="/?bbox=-1.23,1.23,2.34,4.56">Name</a), html
end
end

View file

@ -0,0 +1,51 @@
require "test_helper"
class UserRolesHelperTest < ActionView::TestCase
fixtures :users, :user_roles
def test_role_icon_normal
@user = users(:normal_user)
icon = role_icon(users(:normal_user), "moderator")
assert_dom_equal "", icon
icon = role_icon(users(:moderator_user), "moderator")
assert_dom_equal %q(<img border="0" alt="This user is a moderator" title="This user is a moderator" src="/images/roles/moderator.png" width="20" height="20" />), icon
end
def test_role_icon_administrator
@user = users(:administrator_user)
icon = role_icon(users(:normal_user), "moderator")
assert_dom_equal %q(<a confirm="Are you sure you want to grant the role `moderator&#39; to the user `test&#39;?" rel="nofollow" data-method="post" href="/user/test/role/moderator/grant"><img border="0" alt="Grant moderator access" title="Grant moderator access" src="/images/roles/blank_moderator.png" width="20" height="20" /></a>), icon
icon = role_icon(users(:moderator_user), "moderator")
assert_dom_equal %q(<a confirm="Are you sure you want to revoke the role `moderator&#39; from the user `moderator&#39;?" rel="nofollow" data-method="post" href="/user/moderator/role/moderator/revoke"><img border="0" alt="Revoke moderator access" title="Revoke moderator access" src="/images/roles/moderator.png" width="20" height="20" /></a>), icon
end
def test_role_icons_normal
@user = users(:normal_user)
icons = role_icons(users(:normal_user))
assert_dom_equal " ", icons
icons = role_icons(users(:moderator_user))
assert_dom_equal %q( <img border="0" alt="This user is a moderator" title="This user is a moderator" src="/images/roles/moderator.png" width="20" height="20" />), icons
icons = role_icons(users(:super_user))
assert_dom_equal %q( <img border="0" alt="This user is an administrator" title="This user is an administrator" src="/images/roles/administrator.png" width="20" height="20" /> <img border="0" alt="This user is a moderator" title="This user is a moderator" src="/images/roles/moderator.png" width="20" height="20" />), icons
end
def test_role_icons_administrator
@user = users(:administrator_user)
icons = role_icons(users(:normal_user))
assert_dom_equal %q( <a confirm="Are you sure you want to grant the role `administrator&#39; to the user `test&#39;?" rel="nofollow" data-method="post" href="/user/test/role/administrator/grant"><img border="0" alt="Grant administrator access" title="Grant administrator access" src="/images/roles/blank_administrator.png" width="20" height="20" /></a> <a confirm="Are you sure you want to grant the role `moderator&#39; to the user `test&#39;?" rel="nofollow" data-method="post" href="/user/test/role/moderator/grant"><img border="0" alt="Grant moderator access" title="Grant moderator access" src="/images/roles/blank_moderator.png" width="20" height="20" /></a>), icons
icons = role_icons(users(:moderator_user))
assert_dom_equal %q( <a confirm="Are you sure you want to grant the role `administrator&#39; to the user `moderator&#39;?" rel="nofollow" data-method="post" href="/user/moderator/role/administrator/grant"><img border="0" alt="Grant administrator access" title="Grant administrator access" src="/images/roles/blank_administrator.png" width="20" height="20" /></a> <a confirm="Are you sure you want to revoke the role `moderator&#39; from the user `moderator&#39;?" rel="nofollow" data-method="post" href="/user/moderator/role/moderator/revoke"><img border="0" alt="Revoke moderator access" title="Revoke moderator access" src="/images/roles/moderator.png" width="20" height="20" /></a>), icons
icons = role_icons(users(:super_user))
assert_dom_equal %q( <a confirm="Are you sure you want to revoke the role `administrator&#39; from the user `super&#39;?" rel="nofollow" data-method="post" href="/user/super/role/administrator/revoke"><img border="0" alt="Revoke administrator access" title="Revoke administrator access" src="/images/roles/administrator.png" width="20" height="20" /></a> <a confirm="Are you sure you want to revoke the role `moderator&#39; from the user `super&#39;?" rel="nofollow" data-method="post" href="/user/super/role/moderator/revoke"><img border="0" alt="Revoke moderator access" title="Revoke moderator access" src="/images/roles/moderator.png" width="20" height="20" /></a>), icons
end
end

View file

@ -209,7 +209,7 @@ class BoundingBoxTest < ActiveSupport::TestCase
end
end
def test_bbox_area
def test_good_bbox_area
@good_bbox.each do |string|
bbox = BoundingBox.from_s(string)
array = string.split(",")
@ -217,6 +217,10 @@ class BoundingBoxTest < ActiveSupport::TestCase
end
end
def test_nil_bbox_area
assert_equal 0, @bbox_from_nils.area
end
def test_complete
assert !@bbox_from_nils.complete?, "should contain a nil"
assert @bbox_from_string.complete?, "should not contain a nil"

View file

@ -49,6 +49,16 @@ class RichTextTest < ActiveSupport::TestCase
end
end
def test_html_to_text
r = RichText.new("html", "foo <a href='http://example.com/'>bar</a> baz")
assert_equal "foo <a href='http://example.com/'>bar</a> baz", r.to_text
end
def test_html_spam_score
r = RichText.new("html", "foo <a href='http://example.com/'>bar</a> baz")
assert_equal 55, r.spam_score.round
end
def test_markdown_to_html
r = RichText.new("markdown", "foo http://example.com/ bar")
assert_html r do
@ -137,6 +147,16 @@ class RichTextTest < ActiveSupport::TestCase
end
end
def test_markdown_to_text
r = RichText.new("markdown", "foo [bar](http://example.com/) baz")
assert_equal "foo [bar](http://example.com/) baz", r.to_text
end
def test_markdown_spam_score
r = RichText.new("markdown", "foo [bar](http://example.com/) baz")
assert_equal 50, r.spam_score.round
end
def test_text_to_html
r = RichText.new("text", "foo http://example.com/ bar")
assert_html r do
@ -156,6 +176,16 @@ class RichTextTest < ActiveSupport::TestCase
end
end
def test_text_to_text
r = RichText.new("text", "foo http://example.com/ bar")
assert_equal "foo http://example.com/ bar", r.to_text
end
def test_text_spam_score
r = RichText.new("text", "foo http://example.com/ bar")
assert_equal 141, r.spam_score.round
end
private
def assert_html(richtext, &block)

View file

@ -1,9 +1,28 @@
# coding: utf-8
require "test_helper"
class LanguageTest < ActiveSupport::TestCase
fixtures :languages
test "language count" do
def test_language_count
assert_equal 3, Language.count
end
def test_name
assert_equal "English (English)", languages(:en).name
assert_equal "German (Deutsch)", languages(:de).name
assert_equal "Slovenian (slovenščina)", languages(:sl).name
end
def test_load
assert_equal 3, Language.count
assert_raise ActiveRecord::RecordNotFound do
Language.find("zh")
end
Language.load("config/languages.yml")
assert_equal 197, Language.count
assert_not_nil Language.find("zh")
end
end

View file

@ -2,6 +2,8 @@
require "test_helper"
class UserTest < ActiveSupport::TestCase
include Rails::Dom::Testing::Assertions::SelectorAssertions
api_fixtures
fixtures :friends, :languages, :user_roles
@ -121,6 +123,8 @@ class UserTest < ActiveSupport::TestCase
assert_equal [], users(:inactive_user).nearby
# north_pole_user has no user nearby, and doesn't throw exception
assert_equal [], users(:north_pole_user).nearby
# confirmed_user has no home location
assert_equal [], users(:confirmed_user).nearby
end
def test_friends_with
@ -243,4 +247,24 @@ class UserTest < ActiveSupport::TestCase
assert_equal false, user.visible?
assert_equal false, user.active?
end
def test_to_xml
user = users(:normal_user)
xml = user.to_xml
assert_select Nokogiri::XML::Document.parse(xml.to_s), "user" do
assert_select "[display_name=?]", user.display_name
assert_select "[account_created=?]", user.creation_time.xmlschema
assert_select "home[lat=?][lon=?][zoom=?]", user.home_lat.to_s, user.home_lon.to_s, user.home_zoom.to_s
end
end
def test_to_xml_node
user = users(:normal_user)
xml = user.to_xml_node
assert_select Nokogiri::XML::DocumentFragment.parse(xml.to_s), "user" do
assert_select "[display_name=?]", user.display_name
assert_select "[account_created=?]", user.creation_time.xmlschema
assert_select "home[lat=?][lon=?][zoom=?]", user.home_lat.to_s, user.home_lon.to_s, user.home_zoom.to_s
end
end
end