]> git.openstreetmap.org Git - rails.git/commitdiff
Add a few more tests
authorTom Hughes <tom@compton.nu>
Sat, 7 Mar 2015 00:50:35 +0000 (00:50 +0000)
committerTom Hughes <tom@compton.nu>
Sat, 7 Mar 2015 00:50:35 +0000 (00:50 +0000)
app/controllers/notes_controller.rb
test/controllers/diary_entry_controller_test.rb
test/controllers/notes_controller_test.rb
test/controllers/site_controller_test.rb
test/fixtures/users.yml

index f1ac6baa8c4ec681a6c57fa691c548fbff827a1a..ea32441f2f5db86aa4ff7780cf0b629dcd9f4538 100644 (file)
@@ -299,17 +299,6 @@ class NotesController < ApplicationController
   # utility functions below.
   #------------------------------------------------------------
 
   # 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
   ##
   # Get the maximum number of results to return
   def result_limit
index 1e700da872b415bfb6ecf5aadffdc239d093b6cf..f86321bc34af8b2057c404e9efb3bb03fcdfe81c 100644 (file)
@@ -129,6 +129,8 @@ class DiaryEntryControllerTest < ActionController::TestCase
     assert_response :success
     assert_template :edit
 
     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",
     # 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_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
   end
 
   def test_new_spammy
index c80a95e5a450f88e49fadc9a5fe0db9ebd5b2b4a..b0fc3e1eee30f190ef138a6a3fe330c871fd2721 100644 (file)
@@ -618,6 +618,39 @@ class NotesControllerTest < ActionController::TestCase
     end
   end
 
     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
   def test_index_empty_area
     get :index, :bbox => "5,5,5.1,5.1", :format => "rss"
     assert_response :success
index 7fa558e781ba217a7a993cd4985e172f8e06ae0e..776e9448a6bd2f3bbfb6312586b47aa2e5f678a4 100644 (file)
@@ -221,6 +221,33 @@ class SiteControllerTest < ActionController::TestCase
     assert_template "index"
   end
 
     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)
   # Test editing a specific node
   def test_edit_with_node
     user = users(:public_user)
index 50e24d904b8e59729e5df9be38fe16f57304281a..bee36dcce6ef98ffc39d40640c8b83a4bec93a5e 100644 (file)
@@ -75,6 +75,7 @@ moderator_user:
   terms_agreed: "2010-01-01 11:22:33"
   terms_seen: true
   languages: en
   terms_agreed: "2010-01-01 11:22:33"
   terms_seen: true
   languages: en
+  image_use_gravatar: false
 
 administrator_user:
   id: 6
 
 administrator_user:
   id: 6