require "test_helper"
class DiaryEntryControllerTest < ActionController::TestCase
- fixtures :users, :user_roles, :languages
+ fixtures :users, :user_roles
include ActionView::Helpers::NumberHelper
+ def setup
+ # Create the default language for diary entries
+ create(:language, :code => "en")
+ # Stub nominatim response for diary entry locations
+ stub_request(:get, %r{^http://nominatim\.openstreetmap\.org/reverse\?})
+ .to_return(:status => 404)
+ end
+
##
# test all routes which lead to this controller
def test_routes
assert_equal new_language_code, UserPreference.where(:user_id => users(:normal_user).id, :k => "diary.default_language").first.v
new_language_code = "de"
+ create(:language, :code => new_language_code)
# Now try creating a diary entry in a different language
assert_difference "DiaryEntry.count", 1 do
end
def test_list_language
+ create(:language, :code => "de")
+ create(:language, :code => "sl")
diary_entry_en = create(:diary_entry, :language_code => "en")
diary_entry_en2 = create(:diary_entry, :language_code => "en")
diary_entry_de = create(:diary_entry, :language_code => "de")
end
def test_rss
+ create(:language, :code => "de")
create(:diary_entry, :language_code => "en")
create(:diary_entry, :language_code => "en")
create(:diary_entry, :language_code => "de")
end
def test_rss_language
+ create(:language, :code => "de")
create(:diary_entry, :language_code => "en")
create(:diary_entry, :language_code => "en")
create(:diary_entry, :language_code => "de")
# end
def test_rss_language_with_no_entries
+ create(:language, :code => "sl")
create(:diary_entry, :language_code => "en")
get :rss, :language => "sl", :format => :rss
assert_response :not_found, "Should not be able to get a deleted users diary RSS"
end
+ def test_rss_character_escaping
+ create(:diary_entry, :title => "<script>")
+ get :rss, :format => :rss
+
+ assert_match "<title><script></title>", response.body
+ end
+
def test_view
# Try a normal entry that should work
diary_entry = create(:diary_entry, :user => users(:normal_user))