Skip to content

Commit

Permalink
Add a few more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tomhughes committed Mar 7, 2015
1 parent 11af851 commit 93fb360
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 11 deletions.
11 changes: 0 additions & 11 deletions app/controllers/notes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -299,17 +299,6 @@ def mine
# 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
Expand Down
25 changes: 25 additions & 0 deletions test/controllers/diary_entry_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ def test_new
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",
Expand All @@ -145,6 +147,29 @@ def test_new
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
Expand Down
33 changes: 33 additions & 0 deletions test/controllers/notes_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,39 @@ def test_index_success
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
Expand Down
27 changes: 27 additions & 0 deletions test/controllers/site_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,33 @@ def test_edit_with_override
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)
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/users.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 93fb360

Please sign in to comment.