From 93fb360a08e388997e402faa6d5804580b11b1c5 Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Sat, 7 Mar 2015 00:50:35 +0000 Subject: [PATCH] Add a few more tests --- app/controllers/notes_controller.rb | 11 ------- .../diary_entry_controller_test.rb | 25 ++++++++++++++ test/controllers/notes_controller_test.rb | 33 +++++++++++++++++++ test/controllers/site_controller_test.rb | 27 +++++++++++++++ test/fixtures/users.yml | 1 + 5 files changed, 86 insertions(+), 11 deletions(-) diff --git a/app/controllers/notes_controller.rb b/app/controllers/notes_controller.rb index f1ac6baa8..ea32441f2 100644 --- a/app/controllers/notes_controller.rb +++ b/app/controllers/notes_controller.rb @@ -299,17 +299,6 @@ class NotesController < ApplicationController # utility functions below. #------------------------------------------------------------ - ## - # Render an OK response - def render_ok - if params[:format] == "js" - render :text => "osbResponse();", :content_type => "text/javascript" - else - render :text => "ok " + @note.id.to_s + "\n", :content_type => "text/plain" if @note - render :text => "ok\n", :content_type => "text/plain" unless @note - end - end - ## # Get the maximum number of results to return def result_limit diff --git a/test/controllers/diary_entry_controller_test.rb b/test/controllers/diary_entry_controller_test.rb index 1e700da87..f86321bc3 100644 --- a/test/controllers/diary_entry_controller_test.rb +++ b/test/controllers/diary_entry_controller_test.rb @@ -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 diff --git a/test/controllers/notes_controller_test.rb b/test/controllers/notes_controller_test.rb index c80a95e5a..b0fc3e1ee 100644 --- a/test/controllers/notes_controller_test.rb +++ b/test/controllers/notes_controller_test.rb @@ -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 diff --git a/test/controllers/site_controller_test.rb b/test/controllers/site_controller_test.rb index 7fa558e78..776e9448a 100644 --- a/test/controllers/site_controller_test.rb +++ b/test/controllers/site_controller_test.rb @@ -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) diff --git a/test/fixtures/users.yml b/test/fixtures/users.yml index 50e24d904..bee36dcce 100644 --- a/test/fixtures/users.yml +++ b/test/fixtures/users.yml @@ -75,6 +75,7 @@ moderator_user: terms_agreed: "2010-01-01 11:22:33" terms_seen: true languages: en + image_use_gravatar: false administrator_user: id: 6 -- 2.43.2