Add a few more tests

This commit is contained in:
Tom Hughes 2015-03-07 00:50:35 +00:00
parent 11af851248
commit 93fb360a08
5 changed files with 86 additions and 11 deletions

View file

@ -129,6 +129,8 @@ class DiaryEntryControllerTest < ActionController::TestCase
assert_response :success
assert_template :edit
assert_nil UserPreference.where(:user_id => users(:normal_user).id, :k => "diary.default_language").first
# Now try creating a diary entry
assert_difference "DiaryEntry.count", 1 do
post :new, { :commit => "save",
@ -145,6 +147,29 @@ class DiaryEntryControllerTest < ActionController::TestCase
assert_equal new_latitude.to_f, entry.latitude
assert_equal new_longitude.to_f, entry.longitude
assert_equal new_language_code, entry.language_code
assert_equal new_language_code, UserPreference.where(:user_id => users(:normal_user).id, :k => "diary.default_language").first.v
new_language_code = "de"
# Now try creating a diary entry in a different language
assert_difference "DiaryEntry.count", 1 do
post :new, { :commit => "save",
:diary_entry => { :title => new_title, :body => new_body, :latitude => new_latitude,
:longitude => new_longitude, :language_code => new_language_code } },
{ :user => users(:normal_user).id }
end
assert_response :redirect
assert_redirected_to :action => :list, :display_name => users(:normal_user).display_name
entry = DiaryEntry.order(:id).last
assert_equal users(:normal_user).id, entry.user_id
assert_equal new_title, entry.title
assert_equal new_body, entry.body
assert_equal new_latitude.to_f, entry.latitude
assert_equal new_longitude.to_f, entry.longitude
assert_equal new_language_code, entry.language_code
assert_equal new_language_code, UserPreference.where(:user_id => users(:normal_user).id, :k => "diary.default_language").first.v
end
def test_new_spammy

View file

@ -618,6 +618,39 @@ class NotesControllerTest < ActionController::TestCase
end
end
def test_index_limit
get :index, :bbox => "1,1,1.2,1.2", :limit => 1, :format => "rss"
assert_response :success
assert_equal "application/rss+xml", @response.content_type
assert_select "rss", :count => 1 do
assert_select "channel", :count => 1 do
assert_select "item", :count => 1
end
end
get :index, :bbox => "1,1,1.2,1.2", :limit => 1, :format => "json"
assert_response :success
assert_equal "application/json", @response.content_type
js = ActiveSupport::JSON.decode(@response.body)
assert_not_nil js
assert_equal "FeatureCollection", js["type"]
assert_equal 1, js["features"].count
get :index, :bbox => "1,1,1.2,1.2", :limit => 1, :format => "xml"
assert_response :success
assert_equal "application/xml", @response.content_type
assert_select "osm", :count => 1 do
assert_select "note", :count => 1
end
get :index, :bbox => "1,1,1.2,1.2", :limit => 1, :format => "gpx"
assert_response :success
assert_equal "application/gpx+xml", @response.content_type
assert_select "gpx", :count => 1 do
assert_select "wpt", :count => 1
end
end
def test_index_empty_area
get :index, :bbox => "5,5,5.1,5.1", :format => "rss"
assert_response :success

View file

@ -221,6 +221,33 @@ class SiteControllerTest < ActionController::TestCase
assert_template "index"
end
# Test the right editor gets used when the browser is IE
def test_edit_with_ie
@request.env["HTTP_USER_AGENT"] = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; Trident/7.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E)"
get :edit, {}, { :user => users(:public_user).id }
assert_response :success
assert_template "edit"
assert_template :partial => "_potlatch2", :count => 1
get :edit, { :editor => "id" }, { :user => users(:public_user).id }
assert_response :success
assert_template "edit"
assert_template :partial => "_potlatch2", :count => 1
@request.env["HTTP_USER_AGENT"] = "Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; rv:11.0) like Gecko"
get :edit, {}, { :user => users(:public_user).id }
assert_response :success
assert_template "edit"
assert_template :partial => "_potlatch2", :count => 1
get :edit, { :editor => "id" }, { :user => users(:public_user).id }
assert_response :success
assert_template "edit"
assert_template :partial => "_potlatch2", :count => 1
end
# Test editing a specific node
def test_edit_with_node
user = users(:public_user)