Notifier.message_notification(@message).deliver_later
redirect_to :action => :inbox
else
+ @title = t "messages.new.title"
render :action => "new"
end
end
errors:
messages:
invalid_email_address: не падобны на карэктны адрас электроннай пошты
- email_address_not_routable: мемагчыма пракласці маршрут
+ email_address_not_routable: немагчыма пракласці маршрут
models:
acl: Спіс правоў доступу
changeset: Пакет правак
diary_comment: Каментар дзённіка
diary_entry: Запіс дзённіка
friend: Сябар
+ issue: Праблема
language: Мова
message: Паведамленне
node: Пункт
relation: Дачыненне
relation_member: Удзельнік дачынення
relation_tag: Тэг дачынення
+ report: Справаздача
session: Сеанс
trace: След
tracepoint: Пункт следу
datetime:
distance_in_words_ago:
about_x_hours:
- one: прыкладна гадзіну таму
+ one: прыкладна 1 гадзіну таму
+ few: прыкладна %{count} гадзіны таму
+ many: прыкладна %{count} гадзін таму
other: прыкладна %{count} гадзін(ы) таму
about_x_months:
one: прыкладна 1 месяц таму
less_than_x_seconds:
one: менш за секунду таму
few: менш за %{count} секунды таму
- many: менш за %{count} секундаў таму
- other: менш за %{count} секунды(аў) таму
+ many: менш за %{count} секунд таму
+ other: менш за %{count} секунд(ы) таму
less_than_x_minutes:
one: менш за хвіліну таму
few: менш за %{count} хвіліны таму
x_seconds:
one: 1 секунду таму
few: '%{count} секунды таму'
- many: '%{count} секундаў таму'
- other: '%{count} секунды(аў) таму'
+ many: '%{count} секунд таму'
+ other: '%{count} секунд(ы) таму'
x_minutes:
one: 1 хвіліну таму
few: '%{count} хвіліны таму'
remote:
name: Вонкавы рэдактар
description: вонкавага рэдактара (JOSM або Merkaartor)
+ auth:
+ providers:
+ none: Няма
+ openid: OpenID
+ google: Google
+ facebook: Facebook
+ windowslive: Windows Live
+ github: GitHub
+ wikipedia: Вікіпедыя
api:
notes:
comment:
open_title: 'Нявырашаная заўвага #%{note_name}'
closed_title: 'Вырашаная заўвага #%{note_name}'
hidden_title: 'Схаваная заўвага #%{note_name}'
- opened_by: Створана %{user} <abbr title='%{exact_time}'>%{when} таму</abbr>
- opened_by_anonymous: Створана ананімным карыстальнікам <abbr title='%{exact_time}'>%{when}
- таму</abbr>
+ opened_by: Створана %{user} <abbr title='%{exact_time}'>%{when}</abbr>
+ opened_by_anonymous: Створана ананімным карыстальнікам <abbr title='%{exact_time}'>%{when}</abbr>
commented_by: Каментарый ад %{user} <abbr title='%{exact_time}'>%{when} </abbr>
commented_by_anonymous: Ананімны каментарый <abbr title='%{exact_time}'>%{when}
</abbr>
more_info_2: 'збой, можна знайсці тут:'
success:
subject: '[OpenStreetMap] Паспяховы імпарт GPX'
- loaded_successfully: паспяхова загружаны з %{trace_points} з магчымых %{possible_points}
- кропак.
+ loaded_successfully:
+ one: паспяхова загружаны (%{trace_points} з магчымага 1 пункта).
+ few: паспяхова загружаны (%{trace_points} з магчымых %{possible_points}
+ пунктаў).
+ many: паспяхова загружаны (%{trace_points} з магчымых %{possible_points}
+ пунктаў).
+ other: паспяхова загружаны (%{trace_points} з магчымых %{possible_points}
+ пунктаў).
signup_confirm:
subject: '[OpenStreetMap] Сардэчна запрашаем у OpenStreetMap'
greeting: Прывітанне!
my_traces: Мае GPS-сляды
public_traces_from: Агульныя GPS-сляды карыстальніка %{user}
description: Агляд нядаўна дададзеных GPS-слядоў
- tagged_with: ' адмечана як %{tags}'
+ tagged_with: 'з тэгамі: %{tags}'
empty_html: Пакуль тут нічога няма. <a href='%{upload_link}'>Загрузіце новы
след</a> або пачытайце пра GPS-сляды на <a href='http://wiki.openstreetmap.org/wiki/Beginners_Guide_1.2'>вікі-старонцы</
a>.
out: Паменшыць
locate:
title: Паказаць маё месцазнаходжанне
+ metersPopup:
+ one: Вы знаходзіцеся ў адным метры ад гэтага пункту
+ few: Вы знаходзіцеся ў %{count} метрах ад гэтага пункту
+ many: Вы знаходзіцеся ў %{count} метрах ад гэтага пункту
+ other: Вы знаходзіцеся ў %{count} метрах ад гэтага пункту
+ feetPopup:
+ one: Вы знаходзіцеся ў адным фуце ад гэтага пункту
+ few: Вы знаходзіцеся ў %{count} футах ад гэтага пункту
+ many: Вы знаходзіцеся ў %{count} футах ад гэтага пункту
+ other: Вы знаходзіцеся ў %{count} футах ад гэтага пункту
base:
standard: Звычайная карта
cycle_map: Веласіпедная карта
copyright: © <a href='%{copyright_url}'>OpenStreetMap contributors</a>
donate_link_text: <a class='donate-attr' href='%{donate_url}'>Зрабіць ахвяраванне</a>
terms: <a href='%{terms_url}' target='_blank'>Умовы выкарыстання сайта і API</a>
+ thunderforest: Тайлы прадастаўлены <a href="%{thunderforest_url}">Andy Allan</a>
+ hotosm: Афармленне тайлаў <a href="%{hotosm_url}">Humanitarian OpenStreetMap
+ Team</a>, хостынг ад <a href="%{osmfrance_url}">OpenStreetMap France</a>
site:
edit_tooltip: Рэдагаваць карту
edit_disabled_tooltip: Наблізце, каб рэдагаваць карту
# Author: Elias Ahmmad
# Author: Gronthokeet
# Author: Kayser Ahmad
+# Author: Md. Golam Mukit Khan
# Author: Nasir8891
# Author: R4bb1
# Author: Rasal Lia
diary_comment: ডাইরিতে মন্তব্য
diary_entry: ডাইরির ভুক্তি
friend: বন্ধু
+ issue: সমস্যা
language: ভাষা
message: বার্তা
node: সংযোগস্থল
relation: সম্পর্ক
relation_member: সম্পর্ক সদস্য
relation_tag: সম্পর্ক ট্যাগ
+ report: অভিযোগ
session: সেশন
trace: ট্রেস
tracepoint: পথচিহ্ন বিন্দু
remote:
name: রিমোট কন্ট্রোল
description: রিমোট কন্ট্রোল (JOSM অথবা Merkaartor)
+ auth:
+ providers:
+ google: গুগল
+ facebook: ফেসবুক
+ windowslive: উইন্ডোজ লাইভ
+ github: গিটহাব
+ wikipedia: উইকিপিডিয়া
api:
notes:
comment:
administrative: প্রশাসন
architect: স্থপতি
company: কোম্পানি
+ educational_institution: শিক্ষা প্রতিষ্ঠান
employment_agency: কর্মসংস্থান সংস্থা
estate_agent: এস্টেট এজেন্ট
government: সরকারি দপ্তর
more_1_html: برای اطلاعات بیشتر دربارهٔ استفاده از دادههای ما و چگونگی یادکرد
ما <a href="https://osmfoundation.org/Licence">صفحهٔ پروانهٔ بنیاد OSM</a>
را بخوانید.
- more_2_html: اگرچه دادههای اوپناستریتمپ آزاد است، اما نمیتوانیم API نقشه
- را بÙ\87â\80\8cراÛ\8cگاÙ\86 در اختÛ\8cار تÙ\88سعÙ\87â\80\8cدÙ\87Ù\86دگاÙ\86 شخص ثاÙ\84Ø« Ù\82رار دÙ\87Û\8cÙ\85. <a href="http://wiki.openstreetmap.org/wiki/API_usage_policy">سÛ\8cاست
+ more_2_html: اگرچه دادهٔ اوپناستریتمپ آزاد است، اما نمیتوانیم API نقشه
+ را بهرایگان در اختیار توسعهدهندگان ثالث قرار دهیم. <a href="http://wiki.openstreetmap.org/wiki/API_usage_policy">سیاست
استفاده از API </a> ، <a href="http://wiki.openstreetmap.org/wiki/Tile_usage_policy">سیاست
استفاده از کاشیها</a> و <a href="http://wiki.openstreetmap.org/wiki/Nominatim#Usage_Policy">سیاست
استفاده از Nominatim</a> را ببینید.
register now: اکنون ثبتنام کنید
with username: 'از قبل حساب OpenStreetMap دارید؟ لطفاً با نام کاربری و رمز عبورتان
وارد شوید:'
- with external: 'ورود به روش دیگر: از طریق شخص ثالث'
+ with external: 'بهجای ثبت نام، از روش شخص ثالث استفاده کنید:'
new to osm: در OpenStreetMap تازهوارد هستید؟
to make changes: برای ویرایش دادههای OpenStreetMap، باید یک حساب کاربری داشته
باشید.
مشارکتکننده</a> موافقت کنید.
email address: 'نشانی ایمیل:'
confirm email address: 'تأیید نشانی ایمیل:'
- not_displayed_publicly_html: نشانی شما به دیگران نشان داده نمیشود. برای اطلاعات
+ not_displayed_publicly_html: ایمیل شما به دیگران نشان داده نمیشود. برای اطلاعات
بیشتر <a href="https://wiki.osmfoundation.org/wiki/Privacy_Policy" title="سیاست
حریم خصوصی بنیاد OSM، بخش نشانیهای ایمیل">سیاست حریم خصوصی</a> را ببینید
display name: 'نام نمایشی:'
display name description: نام کاربری شما که دیگران آن را میبینند. میتوانید
بعداً آن را در تنظیمات تغییر دهید.
- external auth: 'اعتبارسÙ\86جÛ\8c طرÙ\81 سÙ\88Ù\85:'
+ external auth: 'اØراز Ù\87Ù\88Û\8cت شخص ثاÙ\84Ø«:'
password: 'کلمهٔ عبور:'
confirm password: 'تأیید کلمهٔ عبور:'
- use external auth: 'ورود به روش دیگر: از طریق شخص ثالث'
+ use external auth: بهجای ثبت نام، از روش شخص ثالث استفاده کنید
auth no password: در اعتبارسنجی بهروش شخص ثالث نیازی به گذرواژهٔ اوپناستریتمپ
ندارید اما شاید میزبان انتخابی شما گذرواژهٔ خودش را بخواهد.
continue: ثبت نام
canal: Kanał
dam: Tama
derelict_canal: Opuszczony kanał
- ditch: Rów
+ ditch: Rów przydrożny
dock: Basen portowy
- drain: Rów odpływowy
+ drain: Rów odwadniający
lock: Śluza
lock_gate: Wrota śluzy
mooring: Kotwicowisko
more_info_2: 'de kan hittas på:'
success:
subject: '[OpenStreetMap] Lyckades importera GPX'
- loaded_successfully: inläst med %{trace_points} av %{possible_points} möjliga
- punkter.
+ loaded_successfully:
+ one: |-
+ inläst med %{trace_points} av 1 möjlig punkt.
+
+ inläst med %{trace_points} av %{possible_points} möjliga punkter.
+ other: |-
+ inläst med %{trace_points} av %{possible_points} möjliga punkter.
+
+ inläst med %{trace_points} av %{possible_points} möjliga punkter.
signup_confirm:
subject: '[OpenStreetMap] Välkommen till OpenStreetMap'
greeting: Hej där!
diary_comment: Bình luận Nhật ký
diary_entry: Mục Nhật ký
friend: Người bạn
+ issue: Vấn đề
language: Ngôn ngữ
message: Thư
node: Nốt
relation: Quan hệ
relation_member: Thành viên Quan hệ
relation_tag: Thẻ Quan hệ
+ report: Báo cáo
session: Phiên
trace: Tuyến đường
tracepoint: Điểm Tuyến đường
remote:
name: phần điều khiển từ xa
description: phần điều khiển từ xa (JOSM hoặc Merkaartor)
+ auth:
+ providers:
+ none: Không có
+ openid: OpenID
+ google: Google
+ facebook: Facebook
+ windowslive: Windows Live
+ github: GitHub
+ wikipedia: Wikipedia
api:
notes:
comment:
relation:
title_html: 'Quan hệ: %{name}'
history_title_html: 'Lịch sử Quan hệ: %{name}'
- members: Các thành viên
+ members: Thành viên
relation_member:
entry_role_html: '%{type} %{name} với vai trò %{role}'
type:
comment: Tóm lược
area: Vùng
index:
- title: Các bộ thay đổi
+ title: Bộ thay đổi
title_user: Những bộ thay đổi bởi %{user}
title_friend: Những bộ thay đổi bởi bạn bè của bạn
title_nearby: Những bộ thay đổi bởi người dùng ở gần
platter: Đĩa Treo
pylon: Cột tháp
station: Trạm Cáp treo
+ t-bar: T-Bar Lift
aeroway:
aerodrome: Sân bay
airstrip: Bãi hạ cánh
bird_hide: Căn nhà Quan sát Chim
common: Đất Công
dog_park: Công viên Chó
+ firepit: Fire Pit
fishing: Hồ Đánh cá
fitness_centre: Trung tâm Thể dục
fitness_station: Trạm Thể dục
# Data browsing
get "/way/:id" => "browse#way", :id => /\d+/, :as => :way
- get "/way/:id/history" => "browse#way_history", :id => /\d+/
+ get "/way/:id/history" => "browse#way_history", :id => /\d+/, :as => :way_history
get "/node/:id" => "browse#node", :id => /\d+/, :as => :node
- get "/node/:id/history" => "browse#node_history", :id => /\d+/
+ get "/node/:id/history" => "browse#node_history", :id => /\d+/, :as => :node_history
get "/relation/:id" => "browse#relation", :id => /\d+/, :as => :relation
- get "/relation/:id/history" => "browse#relation_history", :id => /\d+/
+ get "/relation/:id/history" => "browse#relation_history", :id => /\d+/, :as => :relation_history
get "/changeset/:id" => "browse#changeset", :as => :changeset, :id => /\d+/
get "/changeset/:id/comments/feed" => "changeset_comments#index", :as => :changeset_comments_feed, :id => /\d*/, :defaults => { :format => "rss" }
get "/note/:id" => "browse#note", :id => /\d+/, :as => "browse_note"
get "/note/new" => "browse#new_note"
get "/user/:display_name/history" => "changesets#index"
get "/user/:display_name/history/feed" => "changesets#feed", :defaults => { :format => :atom }
- get "/user/:display_name/notes" => "notes#mine"
+ get "/user/:display_name/notes" => "notes#mine", :as => :my_notes
get "/history/friends" => "changesets#index", :friends => true, :as => "friend_changesets", :defaults => { :format => :html }
get "/history/nearby" => "changesets#index", :nearby => true, :as => "nearby_changesets", :defaults => { :format => :html }
get "/user/:display_name/traces" => "traces#index"
get "/user/:display_name/traces/tag/:tag/rss" => "traces#georss", :defaults => { :format => :rss }
get "/user/:display_name/traces/rss" => "traces#georss", :defaults => { :format => :rss }
- get "/user/:display_name/traces/:id" => "traces#show"
- get "/user/:display_name/traces/:id/picture" => "traces#picture"
- get "/user/:display_name/traces/:id/icon" => "traces#icon"
+ get "/user/:display_name/traces/:id" => "traces#show", :as => "show_trace"
+ get "/user/:display_name/traces/:id/picture" => "traces#picture", :as => "trace_picture"
+ get "/user/:display_name/traces/:id/icon" => "traces#icon", :as => "trace_icon"
get "/traces/tag/:tag/page/:page" => "traces#index", :page => /[1-9][0-9]*/
get "/traces/tag/:tag" => "traces#index"
get "/traces/page/:page" => "traces#index", :page => /[1-9][0-9]*/
get "/diary/:language/rss" => "diary_entries#rss", :defaults => { :format => :rss }
get "/diary/rss" => "diary_entries#rss", :defaults => { :format => :rss }
get "/user/:display_name/diary/comments/:page" => "diary_entries#comments", :page => /[1-9][0-9]*/
- get "/user/:display_name/diary/comments/" => "diary_entries#comments"
+ get "/user/:display_name/diary/comments/" => "diary_entries#comments", :as => :diary_comments
get "/user/:display_name/diary" => "diary_entries#index"
get "/diary/:language" => "diary_entries#index"
scope "/user/:display_name" do
resources :diary_entries, :path => "diary", :only => [:edit, :update, :show]
end
- post "/user/:display_name/diary/:id/newcomment" => "diary_entries#comment", :id => /\d+/
+ post "/user/:display_name/diary/:id/newcomment" => "diary_entries#comment", :id => /\d+/, :as => :comment_diary_entry
post "/user/:display_name/diary/:id/hide" => "diary_entries#hide", :id => /\d+/, :as => :hide_diary_entry
post "/user/:display_name/diary/:id/unhide" => "diary_entries#unhide", :id => /\d+/, :as => :unhide_diary_entry
post "/user/:display_name/diary/:id/hidecomment/:comment" => "diary_entries#hidecomment", :id => /\d+/, :comment => /\d+/, :as => :hide_diary_comment
# roles and banning pages
post "/user/:display_name/role/:role/grant" => "user_roles#grant", :as => "grant_role"
post "/user/:display_name/role/:role/revoke" => "user_roles#revoke", :as => "revoke_role"
- get "/user/:display_name/blocks" => "user_blocks#blocks_on"
- get "/user/:display_name/blocks_by" => "user_blocks#blocks_by"
+ get "/user/:display_name/blocks" => "user_blocks#blocks_on", :as => "user_blocks_on"
+ get "/user/:display_name/blocks_by" => "user_blocks#blocks_by", :as => "user_blocks_by"
get "/blocks/new/:display_name" => "user_blocks#new", :as => "new_user_block"
resources :user_blocks
match "/blocks/:id/revoke" => "user_blocks#revoke", :via => [:get, :post], :as => "revoke_user_block"
require "test_helper"
-class BrowseControllerTest < ActionController::TestCase
+class BrowseControllerTest < ActionDispatch::IntegrationTest
##
# test all routes which lead to this controller
def test_routes
end
def test_read_relation
- browse_check "relation", create(:relation).id, "browse/feature"
+ browse_check :relation_path, create(:relation).id, "browse/feature"
end
def test_read_relation_history
- browse_check "relation_history", create(:relation, :with_history).id, "browse/history"
+ browse_check :relation_history_path, create(:relation, :with_history).id, "browse/history"
end
def test_read_way
- browse_check "way", create(:way).id, "browse/feature"
+ browse_check :way_path, create(:way).id, "browse/feature"
end
def test_read_way_history
- browse_check "way_history", create(:way, :with_history).id, "browse/history"
+ browse_check :way_history_path, create(:way, :with_history).id, "browse/history"
end
def test_read_node
- browse_check "node", create(:node).id, "browse/feature"
+ browse_check :node_path, create(:node).id, "browse/feature"
end
def test_read_node_history
- browse_check "node_history", create(:node, :with_history).id, "browse/history"
+ browse_check :node_history_path, create(:node, :with_history).id, "browse/history"
end
def test_read_changeset
user = create(:user)
- private_changeset = create(:changeset, :user => create(:user, :data_public => false))
changeset = create(:changeset, :user => user)
create(:changeset, :user => user)
- browse_check "changeset", private_changeset.id, "browse/changeset"
- browse_check "changeset", changeset.id, "browse/changeset"
+ browse_check :changeset_path, changeset.id, "browse/changeset"
+ end
+
+ def test_read_private_changeset
+ user = create(:user)
+ changeset = create(:changeset, :user => create(:user, :data_public => false))
+ create(:changeset, :user => user)
+ browse_check :changeset_path, changeset.id, "browse/changeset"
end
def test_read_changeset_hidden_comments
create_list(:changeset_comment, 3, :changeset => changeset)
create(:changeset_comment, :visible => false, :changeset => changeset)
- browse_check "changeset", changeset.id, "browse/changeset"
+ browse_check :changeset_path, changeset.id, "browse/changeset"
assert_select "div.changeset-comments ul li", :count => 3
- session[:user] = create(:moderator_user).id
+ session_for(create(:moderator_user))
- browse_check "changeset", changeset.id, "browse/changeset"
+ browse_check :changeset_path, changeset.id, "browse/changeset"
assert_select "div.changeset-comments ul li", :count => 4
end
def test_read_note
open_note = create(:note_with_comments)
- browse_check "note", open_note.id, "browse/note"
+ browse_check :browse_note_path, open_note.id, "browse/note"
end
def test_read_hidden_note
hidden_note_with_comment = create(:note_with_comments, :status => "hidden")
- get :note, :params => { :id => hidden_note_with_comment.id }
+ get browse_note_path(:id => hidden_note_with_comment)
assert_response :not_found
assert_template "browse/not_found"
assert_template :layout => "map"
- get :note, :params => { :id => hidden_note_with_comment.id }, :xhr => true
+ get browse_note_path(:id => hidden_note_with_comment), :xhr => true
assert_response :not_found
assert_template "browse/not_found"
assert_template :layout => "xhr"
- session[:user] = create(:moderator_user).id
+ session_for(create(:moderator_user))
- browse_check "note", hidden_note_with_comment.id, "browse/note"
+ browse_check :browse_note_path, hidden_note_with_comment.id, "browse/note"
end
def test_read_note_hidden_comments
create(:note_comment, :note => note, :visible => false)
end
- browse_check "note", note_with_hidden_comment.id, "browse/note"
+ browse_check :browse_note_path, note_with_hidden_comment.id, "browse/note"
assert_select "div.note-comments ul li", :count => 1
- session[:user] = create(:moderator_user).id
+ session_for(create(:moderator_user))
- browse_check "note", note_with_hidden_comment.id, "browse/note"
+ browse_check :browse_note_path, note_with_hidden_comment.id, "browse/note"
assert_select "div.note-comments ul li", :count => 2
end
create(:note_comment, :note => note, :author => hidden_user)
end
- browse_check "note", note_with_hidden_user_comment.id, "browse/note"
+ browse_check :browse_note_path, note_with_hidden_user_comment.id, "browse/note"
assert_select "div.note-comments ul li", :count => 1
- session[:user] = create(:moderator_user).id
+ session_for(create(:moderator_user))
- browse_check "note", note_with_hidden_user_comment.id, "browse/note"
+ browse_check :browse_note_path, note_with_hidden_user_comment.id, "browse/note"
assert_select "div.note-comments ul li", :count => 1
end
node_v1 = node.old_nodes.find_by(:version => 1)
node_v1.redact!(create(:redaction))
- get :node, :params => { :id => node.id }
+ get node_path(:id => node)
assert_response :success
assert_template "feature"
node_v1 = node.old_nodes.find_by(:version => 1)
node_v1.redact!(create(:redaction))
- get :node_history, :params => { :id => node.id }
+ get node_history_path(:id => node)
assert_response :success
assert_template "browse/history"
way_v3 = way.old_ways.find_by(:version => 3)
way_v3.redact!(create(:redaction))
- get :way_history, :params => { :id => way.id }
+ get way_history_path(:id => way)
assert_response :success
assert_template "browse/history"
relation_v3 = relation.old_relations.find_by(:version => 3)
relation_v3.redact!(create(:redaction))
- get :relation_history, :params => { :id => relation.id }
+ get relation_history_path(:id => relation)
assert_response :success
assert_template "browse/history"
end
def test_new_note
- get :new_note
+ get note_new_path
assert_response :success
assert_template "browse/new_note"
end
def test_query
- get :query
+ get query_path
assert_response :success
assert_template "browse/query"
end
# First we check that when we don't have an id, it will correctly return a 404
# then we check that we get the correct 404 when a non-existant id is passed
# then we check that it will get a successful response, when we do pass an id
- def browse_check(type, id, template)
+ def browse_check(path, id, template)
+ path_method = method(path)
+
assert_raise ActionController::UrlGenerationError do
- get type
+ get path_method.call
end
assert_raise ActionController::UrlGenerationError do
- get type, :params => { :id => -10 } # we won't have an id that's negative
+ get path_method.call(:id => -10) # we won't have an id that's negative
end
- get type, :params => { :id => 0 }
+ get path_method.call(:id => 0)
assert_response :not_found
assert_template "browse/not_found"
assert_template :layout => "map"
- get type, :params => { :id => 0 }, :xhr => true
+ get path_method.call(:id => 0), :xhr => true
assert_response :not_found
assert_template "browse/not_found"
assert_template :layout => "xhr"
- get type, :params => { :id => id }
+ get path_method.call(:id => id)
assert_response :success
assert_template template
assert_template :layout => "map"
- get type, :params => { :id => id }, :xhr => true
+ get path_method.call(:id => id), :xhr => true
assert_response :success
assert_template template
assert_template :layout => "xhr"
require "test_helper"
-class DiaryEntriesControllerTest < ActionController::TestCase
+class DiaryEntriesControllerTest < ActionDispatch::IntegrationTest
include ActionView::Helpers::NumberHelper
def setup
def test_new_no_login
# Make sure that you are redirected to the login page when you
# are not logged in
- get :new
+ get new_diary_entry_path
assert_response :redirect
assert_redirected_to :controller => :users, :action => :login, :referer => "/diary/new"
end
def test_new_form
# Now try again when logged in
- get :new, :session => { :user => create(:user) }
+ session_for(create(:user))
+ get new_diary_entry_path
assert_response :success
assert_select "title", :text => /New Diary Entry/, :count => 1
assert_select "div.content-heading", :count => 1 do
def test_new_get_with_params
# Now try creating a diary entry using get
+ session_for(create(:user))
assert_difference "DiaryEntry.count", 0 do
- get :new,
- :params => { :commit => "save",
- :diary_entry => { :title => "New Title", :body => "This is a new body for the diary entry", :latitude => "1.1",
- :longitude => "2.2", :language_code => "en" } },
- :session => { :user => create(:user).id }
+ get new_diary_entry_path(:commit => "save",
+ :diary_entry => { :title => "New Title", :body => "This is a new body for the diary entry", :latitude => "1.1",
+ :longitude => "2.2", :language_code => "en" })
end
assert_response :success
assert_template :new
def test_create_no_body
# Now try creating a invalid diary entry with an empty body
user = create(:user)
+ session_for(user)
assert_no_difference "DiaryEntry.count" do
- post :create,
- :params => { :commit => "save",
- :diary_entry => { :title => "New Title", :body => "", :latitude => "1.1",
- :longitude => "2.2", :language_code => "en" } },
- :session => { :user => user.id }
+ post diary_entries_path(:commit => "save",
+ :diary_entry => { :title => "New Title", :body => "", :latitude => "1.1",
+ :longitude => "2.2", :language_code => "en" })
end
assert_response :success
assert_template :new
def test_create
# Now try creating a diary entry
user = create(:user)
+ session_for(user)
assert_difference "DiaryEntry.count", 1 do
- post :create,
- :params => { :commit => "save",
- :diary_entry => { :title => "New Title", :body => "This is a new body for the diary entry", :latitude => "1.1",
- :longitude => "2.2", :language_code => "en" } },
- :session => { :user => user.id }
+ post diary_entries_path(:commit => "save",
+ :diary_entry => { :title => "New Title", :body => "This is a new body for the diary entry", :latitude => "1.1",
+ :longitude => "2.2", :language_code => "en" })
end
assert_response :redirect
assert_redirected_to :action => :index, :display_name => user.display_name
def test_create_german
create(:language, :code => "de")
user = create(:user)
+ session_for(user)
# Now try creating a diary entry in a different language
assert_difference "DiaryEntry.count", 1 do
- post :create,
- :params => { :commit => "save",
- :diary_entry => { :title => "New Title", :body => "This is a new body for the diary entry", :latitude => "1.1",
- :longitude => "2.2", :language_code => "de" } },
- :session => { :user => user.id }
+ post diary_entries_path(:commit => "save",
+ :diary_entry => { :title => "New Title", :body => "This is a new body for the diary entry", :latitude => "1.1",
+ :longitude => "2.2", :language_code => "de" })
end
assert_response :redirect
assert_redirected_to :action => :index, :display_name => user.display_name
def test_new_spammy
user = create(:user)
+ session_for(user)
+
# Generate some spammy content
spammy_title = "Spam Spam Spam Spam Spam"
spammy_body = 1.upto(50).map { |n| "http://example.com/spam#{n}" }.join(" ")
# Try creating a spammy diary entry
assert_difference "DiaryEntry.count", 1 do
- post :create,
- :params => { :commit => "save",
- :diary_entry => { :title => spammy_title, :body => spammy_body, :language_code => "en" } },
- :session => { :user => user.id }
+ post diary_entries_path(:commit => "save",
+ :diary_entry => { :title => spammy_title, :body => spammy_body, :language_code => "en" })
end
assert_response :redirect
assert_redirected_to :action => :index, :display_name => user.display_name
assert_equal "suspended", User.find(user.id).status
# Follow the redirect
- get :index,
- :params => { :display_name => user.display_name },
- :session => { :user => user }
+ get diary_entries_path(:display_name => user.display_name)
assert_response :redirect
assert_redirected_to :controller => :users, :action => :suspended
end
# Make sure that you are redirected to the login page when you are
# not logged in, without and with the id of the entry you want to edit
- get :edit,
- :params => { :display_name => entry.user.display_name, :id => entry.id }
+ get edit_diary_entry_path(:display_name => entry.user.display_name, :id => entry)
assert_response :redirect
assert_redirected_to :controller => :users, :action => :login, :referer => "/user/#{ERB::Util.u(entry.user.display_name)}/diary/#{entry.id}/edit"
- # Verify that you get a not found error, when you pass a bogus id
- get :edit,
- :params => { :display_name => entry.user.display_name, :id => 9999 },
- :session => { :user => entry.user }
- assert_response :not_found
- assert_select "div.content-heading", :count => 1 do
- assert_select "h2", :text => "No entry with the id: 9999", :count => 1
- end
+ session_for(other_user)
# Verify that you get redirected to show if you are not the user
# that created the entry
- get :edit,
- :params => { :display_name => entry.user.display_name, :id => entry.id },
- :session => { :user => other_user }
+ get edit_diary_entry_path(:display_name => entry.user.display_name, :id => entry)
assert_response :redirect
assert_redirected_to :action => :show, :display_name => entry.user.display_name, :id => entry.id
+ session_for(entry.user)
+
+ # Verify that you get a not found error, when you pass a bogus id
+ get edit_diary_entry_path(:display_name => entry.user.display_name, :id => 9999)
+ assert_response :not_found
+ assert_select "div.content-heading", :count => 1 do
+ assert_select "h2", :text => "No entry with the id: 9999", :count => 1
+ end
+
# Now pass the id, and check that you can edit it, when using the same
# user as the person who created the entry
- get :edit,
- :params => { :display_name => entry.user.display_name, :id => entry.id },
- :session => { :user => entry.user }
+ get edit_diary_entry_path(:display_name => entry.user.display_name, :id => entry)
assert_response :success
assert_select "title", :text => /Edit Diary Entry/, :count => 1
assert_select "div.content-heading", :count => 1 do
new_latitude = "1.1"
new_longitude = "2.2"
new_language_code = "en"
- put :update,
- :params => { :display_name => entry.user.display_name, :id => entry.id, :commit => "save",
- :diary_entry => { :title => new_title, :body => new_body, :latitude => new_latitude,
- :longitude => new_longitude, :language_code => new_language_code } },
- :session => { :user => entry.user.id }
+ put diary_entry_path(:display_name => entry.user.display_name, :id => entry, :commit => "save",
+ :diary_entry => { :title => new_title, :body => new_body, :latitude => new_latitude,
+ :longitude => new_longitude, :language_code => new_language_code })
assert_response :redirect
assert_redirected_to :action => :show, :display_name => entry.user.display_name, :id => entry.id
# Now check that the new data is rendered, when logged in
- get :show,
- :params => { :display_name => entry.user.display_name, :id => entry.id },
- :session => { :user => entry.user }
+ get diary_entry_path(:display_name => entry.user.display_name, :id => entry)
assert_response :success
assert_template "show"
assert_select "title", :text => /Users' diaries | /, :count => 1
end
# and when not logged in as the user who wrote the entry
- get :show,
- :params => { :display_name => entry.user.display_name, :id => entry.id },
- :session => { :user => create(:user) }
+ session_for(create(:user))
+ get diary_entry_path(:display_name => entry.user.display_name, :id => entry)
assert_response :success
assert_template "show"
assert_select "title", :text => /Users' diaries | /, :count => 1
def test_edit_i18n
user = create(:user)
diary_entry = create(:diary_entry, :language_code => "en", :user => user)
- get :edit,
- :params => { :display_name => user.display_name, :id => diary_entry.id },
- :session => { :user => user }
+ session_for(user)
+ get edit_diary_entry_path(:display_name => user.display_name, :id => diary_entry)
assert_response :success
assert_select "span[class=translation_missing]", false, "Missing translation in edit diary entry"
end
user = create(:user)
other_user = create(:user)
entry = create(:diary_entry, :user => user)
+ create(:diary_entry_subscription, :diary_entry => entry, :user => user)
# Make sure that you are denied when you are not logged in
- post :comment,
- :params => { :display_name => entry.user.display_name, :id => entry.id }
+ post comment_diary_entry_path(:display_name => entry.user.display_name, :id => entry)
assert_response :forbidden
+ session_for(other_user)
+
# Verify that you get a not found error, when you pass a bogus id
- post :comment,
- :params => { :display_name => entry.user.display_name, :id => 9999 },
- :session => { :user => other_user }
+ post comment_diary_entry_path(:display_name => entry.user.display_name, :id => 9999)
assert_response :not_found
assert_select "div.content-heading", :count => 1 do
assert_select "h2", :text => "No entry with the id: 9999", :count => 1
end
- post :subscribe,
- :params => { :id => entry.id, :display_name => entry.user.display_name },
- :session => { :user => user }
-
# Now try an invalid comment with an empty body
assert_no_difference "ActionMailer::Base.deliveries.size" do
assert_no_difference "DiaryComment.count" do
assert_no_difference "entry.subscribers.count" do
perform_enqueued_jobs do
- post :comment,
- :params => { :display_name => entry.user.display_name, :id => entry.id, :diary_comment => { :body => "" } },
- :session => { :user => other_user }
+ post comment_diary_entry_path(:display_name => entry.user.display_name, :id => entry, :diary_comment => { :body => "" })
end
end
end
assert_difference "DiaryComment.count", 1 do
assert_difference "entry.subscribers.count", 1 do
perform_enqueued_jobs do
- post :comment,
- :params => { :display_name => entry.user.display_name, :id => entry.id, :diary_comment => { :body => "New comment" } },
- :session => { :user => other_user }
+ post comment_diary_entry_path(:display_name => entry.user.display_name, :id => entry, :diary_comment => { :body => "New comment" })
end
end
end
assert_equal "New comment", comment.body
# Now show the diary entry, and check the new comment is present
- get :show,
- :params => { :display_name => entry.user.display_name, :id => entry.id }
+ get diary_entry_path(:display_name => entry.user.display_name, :id => entry)
assert_response :success
assert_select ".diary-comment", :count => 1 do
assert_select "#comment#{comment.id}", :count => 1 do
def test_comment_spammy
user = create(:user)
other_user = create(:user)
-
- # Find the entry to comment on
entry = create(:diary_entry, :user => user)
- post :subscribe,
- :params => { :id => entry.id, :display_name => entry.user.display_name },
- :session => { :user => user }
+ create(:diary_entry_subscription, :diary_entry => entry, :user => user)
+
+ session_for(other_user)
# Generate some spammy content
spammy_text = 1.upto(50).map { |n| "http://example.com/spam#{n}" }.join(" ")
assert_difference "ActionMailer::Base.deliveries.size", 1 do
assert_difference "DiaryComment.count", 1 do
perform_enqueued_jobs do
- post :comment,
- :params => { :display_name => entry.user.display_name, :id => entry.id, :diary_comment => { :body => spammy_text } },
- :session => { :user => other_user }
+ post comment_diary_entry_path(:display_name => entry.user.display_name, :id => entry, :diary_comment => { :body => spammy_text })
end
end
end
assert_equal "suspended", User.find(other_user.id).status
# Follow the redirect
- get :index,
- :params => { :display_name => user.display_name },
- :session => { :user => other_user }
+ get diary_entries_path(:display_name => user.display_name)
assert_response :redirect
assert_redirected_to :controller => :users, :action => :suspended
# Now show the diary entry, and check the new comment is not present
- get :show,
- :params => { :display_name => entry.user.display_name, :id => entry.id }
+ get diary_entry_path(:display_name => entry.user.display_name, :id => entry)
assert_response :success
assert_select ".diary-comment", :count => 0
end
public_entry = create(:diary_entry, :user => create(:user))
# Try a list of all diary entries
- get :index
+ get diary_entries_path
check_diary_index diary_entry, geo_entry, public_entry
end
_other_entry = create(:diary_entry, :user => other_user)
# Try a list of diary entries for a valid user
- get :index, :params => { :display_name => user.display_name }
+ get diary_entries_path(:display_name => user.display_name)
check_diary_index diary_entry, geo_entry
# Try a list of diary entries for an invalid user
- get :index, :params => { :display_name => "No Such User" }
+ get diary_entries_path(:display_name => "No Such User")
assert_response :not_found
assert_template "users/no_such_user"
end
_other_entry = create(:diary_entry, :user => other_user)
# Try a list of diary entries for your friends when not logged in
- get :index, :params => { :friends => true }
+ get friends_diary_entries_path
assert_response :redirect
assert_redirected_to :controller => :users, :action => :login, :referer => "/diary/friends"
# Try a list of diary entries for your friends when logged in
- get :index, :params => { :friends => true }, :session => { :user => user }
+ session_for(user)
+ get friends_diary_entries_path
check_diary_index diary_entry
- get :index, :params => { :friends => true }, :session => { :user => other_user }
+ session_for(other_user)
+ get friends_diary_entries_path
check_diary_index
end
diary_entry = create(:diary_entry, :user => user)
# Try a list of diary entries for nearby users when not logged in
- get :index, :params => { :nearby => true }
+ get nearby_diary_entries_path
assert_response :redirect
assert_redirected_to :controller => :users, :action => :login, :referer => "/diary/nearby"
# Try a list of diary entries for nearby users when logged in
- get :index, :params => { :nearby => true }, :session => { :user => nearby_user }
+ session_for(nearby_user)
+ get nearby_diary_entries_path
check_diary_index diary_entry
- get :index, :params => { :nearby => true }, :session => { :user => user }
+ session_for(user)
+ get nearby_diary_entries_path
check_diary_index
end
diary_entry_de = create(:diary_entry, :language_code => "de")
# Try a list of diary entries in english
- get :index, :params => { :language => "en" }
+ get diary_entries_path(:language => "en")
check_diary_index diary_entry_en, diary_entry_en2
# Try a list of diary entries in german
- get :index, :params => { :language => "de" }
+ get diary_entries_path(:language => "de")
check_diary_index diary_entry_de
# Try a list of diary entries in slovenian
- get :index, :params => { :language => "sl" }
+ get diary_entries_path(:language => "sl")
check_diary_index
end
create_list(:diary_entry, 50)
# Try and get the index
- get :index
+ get diary_entries_path
assert_response :success
assert_select "div.diary_post", :count => 20
# Try and get the second page
- get :index, :params => { :page => 2 }
+ get diary_entries_path(:page => 2)
assert_response :success
assert_select "div.diary_post", :count => 20
end
create(:diary_entry, :language_code => "en")
create(:diary_entry, :language_code => "de")
- get :rss, :params => { :format => :rss }
+ get diary_rss_path
assert_response :success, "Should be able to get a diary RSS"
assert_select "rss", :count => 1 do
assert_select "channel", :count => 1 do
create(:diary_entry, :language_code => "en")
create(:diary_entry, :language_code => "de")
- get :rss, :params => { :language => "en", :format => :rss }
+ get diary_rss_path(:language => "en")
assert_response :success, "Should be able to get a specific language diary RSS"
assert_select "rss>channel>item", :count => 2 # , "Diary entries should be filtered by language"
end
create(:language, :code => "sl")
create(:diary_entry, :language_code => "en")
- get :rss, :params => { :language => "sl", :format => :rss }
+ get diary_rss_path(:language => "sl")
assert_response :success, "Should be able to get a specific language diary RSS"
assert_select "rss>channel>item", :count => 0 # , "Diary entries should be filtered by language"
end
create(:diary_entry, :user => user)
create(:diary_entry, :user => other_user)
- get :rss, :params => { :display_name => user.display_name, :format => :rss }
+ get diary_rss_path(:display_name => user.display_name)
assert_response :success, "Should be able to get a specific users diary RSS"
assert_select "rss>channel>item", :count => 2 # , "Diary entries should be filtered by user"
end
def test_rss_nonexisting_user
# Try a user that has never existed
- get :rss, :params => { :display_name => "fakeUsername76543", :format => :rss }
+ get diary_rss_path(:display_name => "fakeUsername76543")
assert_response :not_found, "Should not be able to get a nonexisting users diary RSS"
# Try a suspended user
- get :rss, :params => { :display_name => create(:user, :suspended).display_name, :format => :rss }
+ get diary_rss_path(:display_name => create(:user, :suspended).display_name)
assert_response :not_found, "Should not be able to get a suspended users diary RSS"
# Try a deleted user
- get :rss, :params => { :display_name => create(:user, :deleted).display_name, :format => :rss }
+ get diary_rss_path(:display_name => create(:user, :deleted).display_name)
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, :params => { :format => :rss }
+ get diary_rss_path
assert_match "<title><script></title>", response.body
end
def test_feed_delay
create(:diary_entry, :created_at => 7.hours.ago)
create(:diary_entry, :created_at => 5.hours.ago)
- get :rss, :params => { :format => :rss }
+ get diary_rss_path
assert_select "rss>channel>item", :count => 2
with_diary_feed_delay(6) do
- get :rss, :params => { :format => :rss }
+ get diary_rss_path
assert_select "rss>channel>item", :count => 1
end
end
# Try a normal entry that should work
diary_entry = create(:diary_entry, :user => user)
- get :show, :params => { :display_name => user.display_name, :id => diary_entry.id }
+ get diary_entry_path(:display_name => user.display_name, :id => diary_entry)
assert_response :success
assert_template :show
# Try a deleted entry
diary_entry_deleted = create(:diary_entry, :user => user, :visible => false)
- get :show, :params => { :display_name => user.display_name, :id => diary_entry_deleted.id }
+ get diary_entry_path(:display_name => user.display_name, :id => diary_entry_deleted)
assert_response :not_found
# Try an entry by a suspended user
diary_entry_suspended = create(:diary_entry, :user => suspended_user)
- get :show, :params => { :display_name => suspended_user.display_name, :id => diary_entry_suspended.id }
+ get diary_entry_path(:display_name => suspended_user.display_name, :id => diary_entry_suspended)
assert_response :not_found
# Try an entry by a deleted user
diary_entry_deleted = create(:diary_entry, :user => deleted_user)
- get :show, :params => { :display_name => deleted_user.display_name, :id => diary_entry_deleted.id }
+ get diary_entry_path(:display_name => deleted_user.display_name, :id => diary_entry_deleted)
assert_response :not_found
end
deleted_user_comment = create(:diary_comment, :diary_entry => diary_entry, :user => create(:user, :deleted))
hidden_comment = create(:diary_comment, :diary_entry => diary_entry, :visible => false)
- get :show, :params => { :display_name => user.display_name, :id => diary_entry.id }
+ get diary_entry_path(:display_name => user.display_name, :id => diary_entry)
assert_response :success
assert_template :show
assert_select "div.comments" do
diary_entry = create(:diary_entry, :user => user)
# Try without logging in
- post :hide,
- :params => { :display_name => user.display_name, :id => diary_entry.id }
+ post hide_diary_entry_path(:display_name => user.display_name, :id => diary_entry)
assert_response :forbidden
assert DiaryEntry.find(diary_entry.id).visible
# Now try as a normal user
- post :hide,
- :params => { :display_name => user.display_name, :id => diary_entry.id },
- :session => { :user => user }
+ session_for(user)
+ post hide_diary_entry_path(:display_name => user.display_name, :id => diary_entry)
assert_response :redirect
assert_redirected_to :controller => :errors, :action => :forbidden
assert DiaryEntry.find(diary_entry.id).visible
# Now try as a moderator
- post :hide,
- :params => { :display_name => user.display_name, :id => diary_entry.id },
- :session => { :user => create(:moderator_user) }
+ session_for(create(:moderator_user))
+ post hide_diary_entry_path(:display_name => user.display_name, :id => diary_entry)
assert_response :redirect
assert_redirected_to :action => :index, :display_name => user.display_name
assert_not DiaryEntry.find(diary_entry.id).visible
diary_entry.reload.update(:visible => true)
# Finally try as an administrator
- post :hide,
- :params => { :display_name => user.display_name, :id => diary_entry.id },
- :session => { :user => create(:administrator_user) }
+ session_for(create(:administrator_user))
+ post hide_diary_entry_path(:display_name => user.display_name, :id => diary_entry)
assert_response :redirect
assert_redirected_to :action => :index, :display_name => user.display_name
assert_not DiaryEntry.find(diary_entry.id).visible
# Try without logging in
diary_entry = create(:diary_entry, :user => user, :visible => false)
- post :unhide,
- :params => { :display_name => user.display_name, :id => diary_entry.id }
+ post unhide_diary_entry_path(:display_name => user.display_name, :id => diary_entry)
assert_response :forbidden
assert_not DiaryEntry.find(diary_entry.id).visible
# Now try as a normal user
- post :unhide,
- :params => { :display_name => user.display_name, :id => diary_entry.id },
- :session => { :user => user }
+ session_for(user)
+ post unhide_diary_entry_path(:display_name => user.display_name, :id => diary_entry)
+ assert_response :redirect
+ assert_redirected_to :controller => :errors, :action => :forbidden
+ assert_not DiaryEntry.find(diary_entry.id).visible
+
+ # Now try as a moderator
+ session_for(create(:moderator_user))
+ post unhide_diary_entry_path(:display_name => user.display_name, :id => diary_entry)
assert_response :redirect
assert_redirected_to :controller => :errors, :action => :forbidden
assert_not DiaryEntry.find(diary_entry.id).visible
# Finally try as an administrator
- post :unhide,
- :params => { :display_name => user.display_name, :id => diary_entry.id },
- :session => { :user => create(:administrator_user) }
+ session_for(create(:administrator_user))
+ post unhide_diary_entry_path(:display_name => user.display_name, :id => diary_entry)
assert_response :redirect
assert_redirected_to :action => :index, :display_name => user.display_name
assert DiaryEntry.find(diary_entry.id).visible
diary_comment = create(:diary_comment, :diary_entry => diary_entry)
# Try without logging in
- post :hidecomment,
- :params => { :display_name => user.display_name, :id => diary_entry.id, :comment => diary_comment.id }
+ post hide_diary_comment_path(:display_name => user.display_name, :id => diary_entry, :comment => diary_comment)
assert_response :forbidden
assert DiaryComment.find(diary_comment.id).visible
# Now try as a normal user
- post :hidecomment,
- :params => { :display_name => user.display_name, :id => diary_entry.id, :comment => diary_comment.id },
- :session => { :user => user }
+ session_for(user)
+ post hide_diary_comment_path(:display_name => user.display_name, :id => diary_entry, :comment => diary_comment)
assert_response :redirect
assert_redirected_to :controller => :errors, :action => :forbidden
assert DiaryComment.find(diary_comment.id).visible
# Try as a moderator
- post :hidecomment,
- :params => { :display_name => user.display_name, :id => diary_entry.id, :comment => diary_comment.id },
- :session => { :user => create(:moderator_user) }
+ session_for(create(:moderator_user))
+ post hide_diary_comment_path(:display_name => user.display_name, :id => diary_entry, :comment => diary_comment)
assert_response :redirect
assert_redirected_to :action => :show, :display_name => user.display_name, :id => diary_entry.id
assert_not DiaryComment.find(diary_comment.id).visible
diary_comment.reload.update(:visible => true)
# Finally try as an administrator
- post :hidecomment,
- :params => { :display_name => user.display_name, :id => diary_entry.id, :comment => diary_comment.id },
- :session => { :user => create(:administrator_user) }
+ session_for(create(:administrator_user))
+ post hide_diary_comment_path(:display_name => user.display_name, :id => diary_entry, :comment => diary_comment)
assert_response :redirect
assert_redirected_to :action => :show, :display_name => user.display_name, :id => diary_entry.id
assert_not DiaryComment.find(diary_comment.id).visible
def test_unhidecomment
user = create(:user)
- administrator_user = create(:administrator_user)
diary_entry = create(:diary_entry, :user => user)
diary_comment = create(:diary_comment, :diary_entry => diary_entry, :visible => false)
+
# Try without logging in
- post :unhidecomment,
- :params => { :display_name => user.display_name, :id => diary_entry.id, :comment => diary_comment.id }
+ post unhide_diary_comment_path(:display_name => user.display_name, :id => diary_entry, :comment => diary_comment)
assert_response :forbidden
assert_not DiaryComment.find(diary_comment.id).visible
# Now try as a normal user
- post :unhidecomment,
- :params => { :display_name => user.display_name, :id => diary_entry.id, :comment => diary_comment.id },
- :session => { :user => user }
+ session_for(user)
+ post unhide_diary_comment_path(:display_name => user.display_name, :id => diary_entry, :comment => diary_comment)
+ assert_response :redirect
+ assert_redirected_to :controller => :errors, :action => :forbidden
+ assert_not DiaryComment.find(diary_comment.id).visible
+
+ # Now try as a moderator
+ session_for(create(:moderator_user))
+ post unhide_diary_comment_path(:display_name => user.display_name, :id => diary_entry, :comment => diary_comment)
assert_response :redirect
assert_redirected_to :controller => :errors, :action => :forbidden
assert_not DiaryComment.find(diary_comment.id).visible
# Finally try as an administrator
- post :unhidecomment,
- :params => { :display_name => user.display_name, :id => diary_entry.id, :comment => diary_comment.id },
- :session => { :user => administrator_user }
+ session_for(create(:administrator_user))
+ post unhide_diary_comment_path(:display_name => user.display_name, :id => diary_entry, :comment => diary_comment)
assert_response :redirect
assert_redirected_to :action => :show, :display_name => user.display_name, :id => diary_entry.id
assert DiaryComment.find(diary_comment.id).visible
other_user = create(:user)
suspended_user = create(:user, :suspended)
deleted_user = create(:user, :deleted)
+
# Test a user with no comments
- get :comments, :params => { :display_name => user.display_name }
+ get diary_comments_path(:display_name => user.display_name)
assert_response :success
assert_template :comments
assert_select "table.table-striped" do
# Test a user with a comment
create(:diary_comment, :user => other_user)
- get :comments, :params => { :display_name => other_user.display_name }
+ get diary_comments_path(:display_name => other_user.display_name)
assert_response :success
assert_template :comments
assert_select "table.table-striped" do
end
# Test a suspended user
- get :comments, :params => { :display_name => suspended_user.display_name }
+ get diary_comments_path(:display_name => suspended_user.display_name)
assert_response :not_found
# Test a deleted user
- get :comments, :params => { :display_name => deleted_user.display_name }
+ get diary_comments_path(:display_name => deleted_user.display_name)
assert_response :not_found
end
other_user = create(:user)
diary_entry = create(:diary_entry, :user => user)
+ session_for(other_user)
assert_difference "diary_entry.subscribers.count", 1 do
- post :subscribe,
- :params => { :id => diary_entry.id, :display_name => diary_entry.user.display_name },
- :session => { :user => other_user }
+ post diary_entry_subscribe_path(:id => diary_entry, :display_name => diary_entry.user.display_name)
end
assert_response :redirect
end
# not signed in
assert_no_difference "diary_entry.subscribers.count" do
- post :subscribe,
- :params => { :id => diary_entry.id, :display_name => diary_entry.user.display_name }
+ post diary_entry_subscribe_path(:id => diary_entry, :display_name => diary_entry.user.display_name)
end
assert_response :forbidden
+ session_for(other_user)
+
# bad diary id
- post :subscribe,
- :params => { :id => 999111, :display_name => "username" },
- :session => { :user => other_user }
+ post diary_entry_subscribe_path(:id => 999111, :display_name => "username")
assert_response :not_found
# trying to subscribe when already subscribed
- post :subscribe,
- :params => { :id => diary_entry.id, :display_name => diary_entry.user.display_name },
- :session => { :user => other_user }
+ post diary_entry_subscribe_path(:id => diary_entry, :display_name => diary_entry.user.display_name)
assert_no_difference "diary_entry.subscribers.count" do
- post :subscribe,
- :params => { :id => diary_entry.id, :display_name => diary_entry.user.display_name },
- :session => { :user => other_user }
+ post diary_entry_subscribe_path(:id => diary_entry, :display_name => diary_entry.user.display_name)
end
end
other_user = create(:user)
diary_entry = create(:diary_entry, :user => user)
+ create(:diary_entry_subscription, :diary_entry => diary_entry, :user => other_user)
- post :subscribe,
- :params => { :id => diary_entry.id, :display_name => diary_entry.user.display_name },
- :session => { :user => other_user }
+ session_for(other_user)
assert_difference "diary_entry.subscribers.count", -1 do
- post :unsubscribe,
- :params => { :id => diary_entry.id, :display_name => diary_entry.user.display_name },
- :session => { :user => other_user }
+ post diary_entry_unsubscribe_path(:id => diary_entry, :display_name => diary_entry.user.display_name)
end
assert_response :redirect
end
# not signed in
assert_no_difference "diary_entry.subscribers.count" do
- post :unsubscribe,
- :params => { :id => diary_entry.id, :display_name => diary_entry.user.display_name }
+ post diary_entry_unsubscribe_path(:id => diary_entry, :display_name => diary_entry.user.display_name)
end
assert_response :forbidden
+ session_for(other_user)
+
# bad diary id
- post :unsubscribe,
- :params => { :id => 999111, :display_name => "username" },
- :session => { :user => other_user }
+ post diary_entry_unsubscribe_path(:id => 999111, :display_name => "username")
assert_response :not_found
# trying to unsubscribe when not subscribed
assert_no_difference "diary_entry.subscribers.count" do
- post :unsubscribe,
- :params => { :id => diary_entry.id, :display_name => diary_entry.user.display_name },
- :session => { :user => other_user }
+ post diary_entry_unsubscribe_path(:id => diary_entry, :display_name => diary_entry.user.display_name)
end
end
require "test_helper"
-class ExportControllerTest < ActionController::TestCase
+class ExportControllerTest < ActionDispatch::IntegrationTest
##
# test all routes which lead to this controller
def test_routes
###
# test the finish action for raw OSM data
def test_finish_osm
- get :finish, :params => { :minlon => 0, :minlat => 50, :maxlon => 1, :maxlat => 51, :format => "osm" }
+ post export_finish_path(:minlon => 0, :minlat => 50, :maxlon => 1, :maxlat => 51, :format => "osm")
assert_response :redirect
assert_redirected_to "controller" => "api/map", "action" => "index", "bbox" => "0.0,50.0,1.0,51.0"
end
###
# test the finish action for mapnik images
def test_finish_mapnik
- get :finish, :params => { :minlon => 0, :minlat => 50, :maxlon => 1, :maxlat => 51, :format => "mapnik", :mapnik_format => "test", :mapnik_scale => "12" }
+ post export_finish_path(:minlon => 0, :minlat => 50, :maxlon => 1, :maxlat => 51, :format => "mapnik", :mapnik_format => "test", :mapnik_scale => "12")
assert_response :redirect
assert_redirected_to "https://render.openstreetmap.org/cgi-bin/export?bbox=0.0,50.0,1.0,51.0&scale=12&format=test"
end
##
# test the embed action
def test_embed
- get :embed
+ get export_embed_path
assert_response :success
assert_template "export/embed"
end
require "test_helper"
-class GeocoderControllerTest < ActionController::TestCase
+class GeocoderControllerTest < ActionDispatch::IntegrationTest
##
# test all routes which lead to this controller
def test_routes
##
# Test identification with no arguments
def test_identify_error
- get :search
+ get search_path
assert_response :bad_request
- get :search, :xhr => true
+ get search_path, :xhr => true
assert_response :bad_request
end
12345
12345-6789
].each do |code|
- post :search, :params => { :query => code }
- assert_response :success
- assert_equal %w[osm_nominatim], assigns(:sources)
+ search_check code, %w[osm_nominatim]
end
end
##
# Test the builtin latitude+longitude search
def test_search_latlon
- get :search_latlon, :params => { :lat => 1.23, :lon => 4.56, :zoom => 16 }, :xhr => true
+ get geocoder_search_latlon_path(:lat => 1.23, :lon => 4.56, :zoom => 16), :xhr => true
results_check :name => "1.23, 4.56", :lat => 1.23, :lon => 4.56, :zoom => 16
- get :search_latlon, :params => { :lat => -91.23, :lon => 4.56, :zoom => 16 }, :xhr => true
+ get geocoder_search_latlon_path(:lat => -91.23, :lon => 4.56, :zoom => 16), :xhr => true
results_check_error "Latitude -91.23 out of range"
- get :search_latlon, :params => { :lat => 91.23, :lon => 4.56, :zoom => 16 }, :xhr => true
+ get geocoder_search_latlon_path(:lat => 91.23, :lon => 4.56, :zoom => 16), :xhr => true
results_check_error "Latitude 91.23 out of range"
- get :search_latlon, :params => { :lat => 1.23, :lon => -180.23, :zoom => 16 }, :xhr => true
+ get geocoder_search_latlon_path(:lat => 1.23, :lon => -180.23, :zoom => 16), :xhr => true
results_check_error "Longitude -180.23 out of range"
- get :search_latlon, :params => { :lat => 1.23, :lon => 180.23, :zoom => 16 }, :xhr => true
+ get geocoder_search_latlon_path(:lat => 1.23, :lon => 180.23, :zoom => 16), :xhr => true
results_check_error "Longitude 180.23 out of range"
end
def test_search_latlon_digits
- get :search_latlon, :params => { :lat => 1.23, :lon => 4.56, :zoom => 16, :latlon_digits => true }, :xhr => true
+ get geocoder_search_latlon_path(:lat => 1.23, :lon => 4.56, :zoom => 16, :latlon_digits => true), :xhr => true
results_check({ :name => "1.23, 4.56", :lat => 1.23, :lon => 4.56, :zoom => 16 },
{ :name => "4.56, 1.23", :lat => 4.56, :lon => 1.23, :zoom => 16 })
- get :search_latlon, :params => { :lat => -91.23, :lon => 4.56, :zoom => 16, :latlon_digits => true }, :xhr => true
+ get geocoder_search_latlon_path(:lat => -91.23, :lon => 4.56, :zoom => 16, :latlon_digits => true), :xhr => true
results_check :name => "4.56, -91.23", :lat => 4.56, :lon => -91.23, :zoom => 16
- get :search_latlon, :params => { :lat => -1.23, :lon => 170.23, :zoom => 16, :latlon_digits => true }, :xhr => true
+ get geocoder_search_latlon_path(:lat => -1.23, :lon => 170.23, :zoom => 16, :latlon_digits => true), :xhr => true
results_check :name => "-1.23, 170.23", :lat => -1.23, :lon => 170.23, :zoom => 16
- get :search_latlon, :params => { :lat => 91.23, :lon => 94.56, :zoom => 16, :latlon_digits => true }, :xhr => true
+ get geocoder_search_latlon_path(:lat => 91.23, :lon => 94.56, :zoom => 16, :latlon_digits => true), :xhr => true
results_check_error "Latitude or longitude are out of range"
- get :search_latlon, :params => { :lat => -91.23, :lon => -94.56, :zoom => 16, :latlon_digits => true }, :xhr => true
+ get geocoder_search_latlon_path(:lat => -91.23, :lon => -94.56, :zoom => 16, :latlon_digits => true), :xhr => true
results_check_error "Latitude or longitude are out of range"
- get :search_latlon, :params => { :lat => 1.23, :lon => -180.23, :zoom => 16, :latlon_digits => true }, :xhr => true
+ get geocoder_search_latlon_path(:lat => 1.23, :lon => -180.23, :zoom => 16, :latlon_digits => true), :xhr => true
results_check_error "Latitude or longitude are out of range"
- get :search_latlon, :params => { :lat => 1.23, :lon => 180.23, :zoom => 16, :latlon_digits => true }, :xhr => true
+ get geocoder_search_latlon_path(:lat => 1.23, :lon => 180.23, :zoom => 16, :latlon_digits => true), :xhr => true
results_check_error "Latitude or longitude are out of range"
end
# Test the Canadian postcode search
def test_search_ca_postcode
with_http_stubs "geocoder_ca" do
- get :search_ca_postcode, :xhr => true,
- :params => { :query => "A1B 2C3", :zoom => 10,
- :minlon => -0.559, :minlat => 51.217,
- :maxlon => 0.836, :maxlat => 51.766 }
+ get geocoder_search_ca_postcode_path(:query => "A1B 2C3", :zoom => 10,
+ :minlon => -0.559, :minlat => 51.217,
+ :maxlon => 0.836, :maxlat => 51.766), :xhr => true
+
results_check :name => "A1B 2C3", :lat => "47.172520", :lon => "-55.440515"
- get :search_ca_postcode, :xhr => true,
- :params => { :query => "k1a 0b1", :zoom => 10,
- :minlon => -0.559, :minlat => 51.217,
- :maxlon => 0.836, :maxlat => 51.766 }
+ get geocoder_search_ca_postcode_path(:query => "k1a 0b1", :zoom => 10,
+ :minlon => -0.559, :minlat => 51.217,
+ :maxlon => 0.836, :maxlat => 51.766), :xhr => true
results_check :name => "K1A 0B1", :lat => "45.375437", :lon => "-75.691041"
- get :search_ca_postcode, :xhr => true,
- :params => { :query => "Q0Q 0Q0", :zoom => 10,
- :minlon => -0.559, :minlat => 51.217,
- :maxlon => 0.836, :maxlat => 51.766 }
+ get geocoder_search_ca_postcode_path(:query => "Q0Q 0Q0", :zoom => 10,
+ :minlon => -0.559, :minlat => 51.217,
+ :maxlon => 0.836, :maxlat => 51.766), :xhr => true
results_check
end
end
# Test the nominatim forward search
def test_search_osm_nominatim
with_http_stubs "nominatim" do
- get :search_osm_nominatim, :xhr => true,
- :params => { :query => "Hoddesdon", :zoom => 10,
- :minlon => -0.559, :minlat => 51.217,
- :maxlon => 0.836, :maxlat => 51.766 }
+ get geocoder_search_osm_nominatim_path(:query => "Hoddesdon", :zoom => 10,
+ :minlon => -0.559, :minlat => 51.217,
+ :maxlon => 0.836, :maxlat => 51.766), :xhr => true
results_check "name" => "Hoddesdon, Hertfordshire, East of England, England, United Kingdom",
"min-lat" => 51.7216709, "max-lat" => 51.8016709,
"min-lon" => -0.0512898, "max-lon" => 0.0287102,
"type" => "node", "id" => 18007599
- get :search_osm_nominatim, :xhr => true,
- :params => { :query => "Broxbourne", :zoom => 10,
- :minlon => -0.559, :minlat => 51.217,
- :maxlon => 0.836, :maxlat => 51.766 }
+ get geocoder_search_osm_nominatim_path(:query => "Broxbourne", :zoom => 10,
+ :minlon => -0.559, :minlat => 51.217,
+ :maxlon => 0.836, :maxlat => 51.766), :xhr => true
results_check({ "prefix" => "Suburb",
"name" => "Broxbourne, Hertfordshire, East of England, England, United Kingdom",
"min-lat" => 51.7265723, "max-lat" => 51.7665723,
# Test the geonames forward search
def test_search_geonames
with_http_stubs "geonames" do
- get :search_geonames, :xhr => true,
- :params => { :query => "Hoddesdon", :zoom => 10,
- :minlon => -0.559, :minlat => 51.217,
- :maxlon => 0.836, :maxlat => 51.766 }
+ get geocoder_search_geonames_path(:query => "Hoddesdon", :zoom => 10, :minlon => -0.559, :minlat => 51.217,
+ :maxlon => 0.836, :maxlat => 51.766), :xhr => true
results_check :name => "Hoddesdon", :lat => 51.76148, :lon => -0.01144
- get :search_geonames, :xhr => true,
- :params => { :query => "Broxbourne", :zoom => 10,
- :minlon => -0.559, :minlat => 51.217,
- :maxlon => 0.836, :maxlat => 51.766 }
+ get geocoder_search_geonames_path(:query => "Broxbourne", :zoom => 10,
+ :minlon => -0.559, :minlat => 51.217,
+ :maxlon => 0.836, :maxlat => 51.766), :xhr => true
results_check({ :name => "Broxbourne", :lat => 51.74712, :lon => -0.01923 },
{ :name => "Broxbourne District", :lat => 51.73026, :lon => -0.04821 },
{ :name => "Cheshunt", :lat => 51.70791, :lon => -0.03739 },
# Test the nominatim reverse search
def test_search_osm_nominatim_reverse
with_http_stubs "nominatim" do
- get :search_osm_nominatim_reverse, :xhr => true,
- :params => { :lat => 51.7632, :lon => -0.0076, :zoom => 15 }
+ get geocoder_search_osm_nominatim_reverse_path(:lat => 51.7632, :lon => -0.0076, :zoom => 15), :xhr => true
results_check :name => "Broxbourne, Hertfordshire, East of England, England, United Kingdom",
:lat => 51.7465723, :lon => -0.0190782,
:type => "node", :id => 28825933, :zoom => 15
- get :search_osm_nominatim_reverse, :xhr => true,
- :params => { :lat => 51.7632, :lon => -0.0076, :zoom => 17 }
+ get geocoder_search_osm_nominatim_reverse_path(:lat => 51.7632, :lon => -0.0076, :zoom => 17), :xhr => true
results_check :name => "Dinant Link Road, Broxbourne, Hertfordshire, East of England, England, EN11 8HX, United Kingdom",
:lat => 51.7634883, :lon => -0.0088373,
:type => "way", :id => 3489841, :zoom => 17
- get :search_osm_nominatim_reverse, :xhr => true,
- :params => { :lat => 13.7709, :lon => 100.50507, :zoom => 19 }
+ get geocoder_search_osm_nominatim_reverse_path(:lat => 13.7709, :lon => 100.50507, :zoom => 19), :xhr => true
results_check :name => "MM Steak&Grill, ถนนศรีอยุธยา, บางขุนพรหม, กรุงเทพมหานคร, เขตดุสิต, กรุงเทพมหานคร, 10300, ประเทศไทย",
:lat => 13.7708691, :lon => 100.505073233221,
:type => "way", :id => 542901374, :zoom => 19
# Test the geonames reverse search
def test_search_geonames_reverse
with_http_stubs "geonames" do
- get :search_geonames_reverse, :xhr => true,
- :params => { :lat => 51.7632, :lon => -0.0076, :zoom => 15 }
+ get geocoder_search_geonames_reverse_path(:lat => 51.7632, :lon => -0.0076, :zoom => 15), :xhr => true
results_check :name => "England", :suffix => ", United Kingdom",
:lat => 51.7632, :lon => -0.0076
end
private
def latlon_check(query, lat, lon)
- get :search, :params => { :query => query }
+ get search_path(:query => query)
assert_response :success
assert_template :search
assert_template :layout => "map"
assert_in_delta lat, @controller.params[:lat]
assert_in_delta lon, @controller.params[:lon]
- get :search, :params => { :query => query }, :xhr => true
+ get search_path(:query => query), :xhr => true
assert_response :success
assert_template :search
assert_template :layout => "xhr"
end
def search_check(query, sources)
- get :search, :params => { :query => query }
+ get search_path(:query => query)
assert_response :success
assert_template :search
assert_template :layout => "map"
assert_equal sources, assigns(:sources)
- get :search, :params => { :query => query }, :xhr => true
+ get search_path(:query => query), :xhr => true
assert_response :success
assert_template :search
assert_template :layout => "xhr"
require "test_helper"
-class IssueCommentsControllerTest < ActionController::TestCase
+class IssueCommentsControllerTest < ActionDispatch::IntegrationTest
def test_comment_by_normal_user
issue = create(:issue)
# Login as normal user
- session[:user] = create(:user).id
+ session_for(create(:user))
- post :create, :params => { :issue_id => issue.id }
+ post issue_comments_path(:issue_id => issue)
assert_response :redirect
assert_redirected_to :controller => :errors, :action => :forbidden
assert_equal 0, issue.comments.length
issue = create(:issue)
# Login as administrator
- session[:user] = create(:administrator_user).id
+ session_for(create(:administrator_user))
- post :create, :params => { :issue_id => issue.id, :issue_comment => { :body => "test comment" } }
+ post issue_comments_path(:issue_id => issue, :issue_comment => { :body => "test comment" })
assert_response :redirect
assert_redirected_to issue
assert_equal 1, issue.comments.length
require "test_helper"
-class IssuesControllerTest < ActionController::TestCase
+class IssuesControllerTest < ActionDispatch::IntegrationTest
def test_index
# Access issues list without login
- get :index
+ get issues_path
assert_response :redirect
assert_redirected_to login_path(:referer => issues_path)
# Access issues list as normal user
- session[:user] = create(:user).id
- get :index
+ session_for(create(:user))
+ get issues_path
assert_response :redirect
assert_redirected_to :controller => :errors, :action => :forbidden
# Access issues list as administrator
- session[:user] = create(:administrator_user).id
- get :index
+ session_for(create(:administrator_user))
+ get issues_path
assert_response :success
# Access issues list as moderator
- session[:user] = create(:moderator_user).id
- get :index
+ session_for(create(:moderator_user))
+ get issues_path
assert_response :success
end
issue = create(:issue, :reportable => target_user, :reported_user => target_user, :assigned_role => "moderator")
# Access issue without login
- get :show, :params => { :id => issue.id }
+ get issue_path(:id => issue)
assert_response :redirect
assert_redirected_to login_path(:referer => issue_path(issue))
# Access issue as normal user
- session[:user] = create(:user).id
- get :show, :params => { :id => issue.id }
+ session_for(create(:user))
+ get issue_path(:id => issue)
assert_response :redirect
assert_redirected_to :controller => :errors, :action => :forbidden
# Access issue as administrator
- session[:user] = create(:administrator_user).id
- get :show, :params => { :id => issue.id }
+ session_for(create(:administrator_user))
+ get issue_path(:id => issue)
assert_redirected_to :controller => :errors, :action => :not_found
# Access issue as moderator
- session[:user] = create(:moderator_user).id
- get :show, :params => { :id => issue.id }
+ session_for(create(:moderator_user))
+ get issue_path(:id => issue)
assert_response :success
end
issue = create(:issue, :reportable => target_user, :reported_user => target_user, :assigned_role => "administrator")
# Access issue without login
- get :show, :params => { :id => issue.id }
+ get issue_path(:id => issue)
assert_response :redirect
assert_redirected_to login_path(:referer => issue_path(issue))
# Access issue as normal user
- session[:user] = create(:user).id
- get :show, :params => { :id => issue.id }
+ session_for(create(:user))
+ get issue_path(:id => issue)
assert_response :redirect
assert_redirected_to :controller => :errors, :action => :forbidden
# Access issue as moderator
- session[:user] = create(:moderator_user).id
- get :show, :params => { :id => issue.id }
+ session_for(create(:moderator_user))
+ get issue_path(:id => issue)
assert_redirected_to :controller => :errors, :action => :not_found
# Access issue as administrator
- session[:user] = create(:administrator_user).id
- get :show, :params => { :id => issue.id }
+ session_for(create(:administrator_user))
+ get issue_path(:id => issue)
assert_response :success
end
issue = create(:issue, :reportable => target_user, :reported_user => target_user, :assigned_role => "moderator")
# Resolve issue without login
- get :resolve, :params => { :id => issue.id }
- assert_response :redirect
- assert_redirected_to login_path(:referer => resolve_issue_path(issue))
+ post resolve_issue_path(:id => issue)
+ assert_response :forbidden
# Resolve issue as normal user
- session[:user] = create(:user).id
- get :resolve, :params => { :id => issue.id }
+ session_for(create(:user))
+ post resolve_issue_path(:id => issue)
assert_response :redirect
assert_redirected_to :controller => :errors, :action => :forbidden
# Resolve issue as administrator
- session[:user] = create(:administrator_user).id
- get :resolve, :params => { :id => issue.id }
+ session_for(create(:administrator_user))
+ post resolve_issue_path(:id => issue)
assert_redirected_to :controller => :errors, :action => :not_found
assert_not issue.reload.resolved?
# Resolve issue as moderator
- session[:user] = create(:moderator_user).id
- get :resolve, :params => { :id => issue.id }
+ session_for(create(:moderator_user))
+ post resolve_issue_path(:id => issue)
assert_response :redirect
assert issue.reload.resolved?
end
issue = create(:issue, :reportable => target_user, :reported_user => target_user, :assigned_role => "administrator")
# Resolve issue without login
- get :resolve, :params => { :id => issue.id }
- assert_response :redirect
- assert_redirected_to login_path(:referer => resolve_issue_path(issue))
+ post resolve_issue_path(:id => issue)
+ assert_response :forbidden
# Resolve issue as normal user
- session[:user] = create(:user).id
- get :resolve, :params => { :id => issue.id }
+ session_for(create(:user))
+ post resolve_issue_path(:id => issue)
assert_response :redirect
assert_redirected_to :controller => :errors, :action => :forbidden
# Resolve issue as moderator
- session[:user] = create(:moderator_user).id
- get :resolve, :params => { :id => issue.id }
+ session_for(create(:moderator_user))
+ post resolve_issue_path(:id => issue)
assert_redirected_to :controller => :errors, :action => :not_found
assert_not issue.reload.resolved?
# Resolve issue as administrator
- session[:user] = create(:administrator_user).id
- get :resolve, :params => { :id => issue.id }
+ session_for(create(:administrator_user))
+ post resolve_issue_path(:id => issue)
assert_response :redirect
assert issue.reload.resolved?
end
issue = create(:issue, :reportable => target_user, :reported_user => target_user, :assigned_role => "moderator")
# Ignore issue without login
- get :ignore, :params => { :id => issue.id }
- assert_response :redirect
- assert_redirected_to login_path(:referer => ignore_issue_path(issue))
+ post ignore_issue_path(:id => issue)
+ assert_response :forbidden
# Ignore issue as normal user
- session[:user] = create(:user).id
- get :ignore, :params => { :id => issue.id }
+ session_for(create(:user))
+ post ignore_issue_path(:id => issue)
assert_response :redirect
assert_redirected_to :controller => :errors, :action => :forbidden
# Ignore issue as administrator
- session[:user] = create(:administrator_user).id
- get :ignore, :params => { :id => issue.id }
+ session_for(create(:administrator_user))
+ post ignore_issue_path(:id => issue)
assert_redirected_to :controller => :errors, :action => :not_found
assert_not issue.reload.ignored?
# Ignore issue as moderator
- session[:user] = create(:moderator_user).id
- get :ignore, :params => { :id => issue.id }
+ session_for(create(:moderator_user))
+ post ignore_issue_path(:id => issue)
assert_response :redirect
assert issue.reload.ignored?
end
issue = create(:issue, :reportable => target_user, :reported_user => target_user, :assigned_role => "administrator")
# Ignore issue without login
- get :ignore, :params => { :id => issue.id }
- assert_response :redirect
- assert_redirected_to login_path(:referer => ignore_issue_path(issue))
+ post ignore_issue_path(:id => issue)
+ assert_response :forbidden
# Ignore issue as normal user
- session[:user] = create(:user).id
- get :ignore, :params => { :id => issue.id }
+ session_for(create(:user))
+ post ignore_issue_path(:id => issue)
assert_response :redirect
assert_redirected_to :controller => :errors, :action => :forbidden
# Ignore issue as moderator
- session[:user] = create(:moderator_user).id
- get :ignore, :params => { :id => issue.id }
+ session_for(create(:moderator_user))
+ post ignore_issue_path(:id => issue)
assert_redirected_to :controller => :errors, :action => :not_found
assert_not issue.reload.ignored?
# Ignore issue as administrator
- session[:user] = create(:administrator_user).id
- get :ignore, :params => { :id => issue.id }
+ session_for(create(:administrator_user))
+ post ignore_issue_path(:id => issue)
assert_response :redirect
assert issue.reload.ignored?
end
issue.resolve!
# Reopen issue without login
- get :reopen, :params => { :id => issue.id }
- assert_response :redirect
- assert_redirected_to login_path(:referer => reopen_issue_path(issue))
+ post reopen_issue_path(:id => issue)
+ assert_response :forbidden
# Reopen issue as normal user
- session[:user] = create(:user).id
- get :reopen, :params => { :id => issue.id }
+ session_for(create(:user))
+ post reopen_issue_path(:id => issue)
assert_response :redirect
assert_redirected_to :controller => :errors, :action => :forbidden
# Reopen issue as administrator
- session[:user] = create(:administrator_user).id
- get :reopen, :params => { :id => issue.id }
+ session_for(create(:administrator_user))
+ post reopen_issue_path(:id => issue)
assert_redirected_to :controller => :errors, :action => :not_found
assert_not issue.reload.open?
# Reopen issue as moderator
- session[:user] = create(:moderator_user).id
- get :reopen, :params => { :id => issue.id }
+ session_for(create(:moderator_user))
+ post reopen_issue_path(:id => issue)
assert_response :redirect
assert issue.reload.open?
end
issue.resolve!
# Reopen issue without login
- get :reopen, :params => { :id => issue.id }
- assert_response :redirect
- assert_redirected_to login_path(:referer => reopen_issue_path(issue))
+ post reopen_issue_path(:id => issue)
+ assert_response :forbidden
# Reopen issue as normal user
- session[:user] = create(:user).id
- get :reopen, :params => { :id => issue.id }
+ session_for(create(:user))
+ post reopen_issue_path(:id => issue)
assert_response :redirect
assert_redirected_to :controller => :errors, :action => :forbidden
# Reopen issue as moderator
- session[:user] = create(:moderator_user).id
- get :reopen, :params => { :id => issue.id }
+ session_for(create(:moderator_user))
+ post reopen_issue_path(:id => issue)
assert_redirected_to :controller => :errors, :action => :not_found
assert_not issue.reload.open?
# Reopen issue as administrator
- session[:user] = create(:administrator_user).id
- get :reopen, :params => { :id => issue.id }
+ session_for(create(:administrator_user))
+ post reopen_issue_path(:id => issue)
assert_response :redirect
assert issue.reload.open?
end
require "test_helper"
-class MessagesControllerTest < ActionController::TestCase
+class MessagesControllerTest < ActionDispatch::IntegrationTest
##
# test all routes which lead to this controller
def test_routes
def test_new_no_login
# Check that the new message page requires us to login
user = create(:user)
- get :new, :params => { :display_name => user.display_name }
+ get new_message_path(:display_name => user.display_name)
assert_redirected_to login_path(:referer => new_message_path(:display_name => user.display_name))
end
# Login as a normal user
user = create(:user)
recipient_user = create(:user)
- session[:user] = user.id
+ session_for(user)
# Check that the new message page loads
- get :new, :params => { :display_name => recipient_user.display_name }
+ get new_message_path(:display_name => recipient_user.display_name)
assert_response :success
assert_template "new"
assert_select "title", "Send message | OpenStreetMap"
# Login as a normal user
user = create(:user)
recipient_user = create(:user)
- session[:user] = user.id
+ session_for(user)
# Check that we can't send a message from a GET request
assert_difference "ActionMailer::Base.deliveries.size", 0 do
assert_difference "Message.count", 0 do
perform_enqueued_jobs do
- get :new,
- :params => { :display_name => recipient_user.display_name,
- :message => { :title => "Test Message", :body => "Test message body" } }
+ get new_message_path(:display_name => recipient_user.display_name,
+ :message => { :title => "Test Message", :body => "Test message body" })
end
end
end
# Login as a normal user
user = create(:user)
recipient_user = create(:user)
- session[:user] = user.id
+ session_for(user)
# Check that the subject is preserved over errors
assert_difference "ActionMailer::Base.deliveries.size", 0 do
assert_difference "Message.count", 0 do
perform_enqueued_jobs do
- post :new,
- :params => { :display_name => recipient_user.display_name,
- :message => { :title => "Test Message", :body => "" } }
+ post messages_path(:display_name => recipient_user.display_name,
+ :message => { :title => "Test Message", :body => "" })
end
end
end
# Login as a normal user
user = create(:user)
recipient_user = create(:user)
- session[:user] = user.id
+ session_for(user)
# Check that the body text is preserved over errors
assert_difference "ActionMailer::Base.deliveries.size", 0 do
assert_difference "Message.count", 0 do
perform_enqueued_jobs do
- post :new,
- :params => { :display_name => recipient_user.display_name,
- :message => { :title => "", :body => "Test message body" } }
+ post messages_path(:display_name => recipient_user.display_name,
+ :message => { :title => "", :body => "Test message body" })
end
end
end
# Login as a normal user
user = create(:user)
recipient_user = create(:user)
- session[:user] = user.id
+ session_for(user)
# Check that sending a message works
assert_difference "ActionMailer::Base.deliveries.size", 1 do
assert_difference "Message.count", 1 do
perform_enqueued_jobs do
- post :create,
- :params => { :display_name => recipient_user.display_name,
- :message => { :title => "Test Message", :body => "Test message body" } }
+ post messages_path(:display_name => recipient_user.display_name,
+ :message => { :title => "Test Message", :body => "Test message body" })
end
end
end
assert_equal "markdown", m.body_format
# Asking to send a message with a bogus user name should fail
- get :new, :params => { :display_name => "non_existent_user" }
+ get new_message_path(:display_name => "non_existent_user")
assert_response :not_found
assert_template "users/no_such_user"
assert_select "h1", "The user non_existent_user does not exist"
# Login as a normal user
user = create(:user)
recipient_user = create(:user)
- session[:user] = user.id
+ session_for(user)
# Check that sending a message fails when the message limit is hit
assert_no_difference "ActionMailer::Base.deliveries.size" do
assert_no_difference "Message.count" do
with_message_limit(0) do
perform_enqueued_jobs do
- post :create,
- :params => { :display_name => recipient_user.display_name,
- :message => { :title => "Test Message", :body => "Test message body" } }
+ post messages_path(:display_name => recipient_user.display_name,
+ :message => { :title => "Test Message", :body => "Test message body" })
assert_response :success
assert_template "new"
assert_select ".error", /wait a while/
unread_message = create(:message, :unread, :sender => user, :recipient => recipient_user)
# Check that the message reply page requires us to login
- get :reply, :params => { :message_id => unread_message.id }
+ get message_reply_path(:message_id => unread_message)
assert_redirected_to login_path(:referer => message_reply_path(:message_id => unread_message.id))
# Login as the wrong user
- session[:user] = other_user.id
+ session_for(other_user)
# Check that we can't reply to somebody else's message
- get :reply, :params => { :message_id => unread_message.id }
+ get message_reply_path(:message_id => unread_message)
assert_redirected_to login_path(:referer => message_reply_path(:message_id => unread_message.id))
assert_equal "You are logged in as `#{other_user.display_name}' but the message you have asked to reply to was not sent to that user. Please login as the correct user in order to reply.", flash[:notice]
# Login as the right user
- session[:user] = recipient_user.id
+ session_for(recipient_user)
# Check that the message reply page loads
- get :reply, :params => { :message_id => unread_message.id }
+ get message_reply_path(:message_id => unread_message)
assert_response :success
assert_template "new"
assert_select "title", "Re: #{unread_message.title} | OpenStreetMap"
assert Message.find(unread_message.id).message_read
# Asking to reply to a message with no ID should fail
- assert_raise ActionController::UrlGenerationError do
- get :reply
- end
+ get message_reply_path
+ assert_response :success
# Asking to reply to a message with a bogus ID should fail
- get :reply, :params => { :message_id => 99999 }
+ get message_reply_path(:message_id => 99999)
assert_response :not_found
assert_template "no_such_message"
end
unread_message = create(:message, :unread, :sender => user, :recipient => recipient_user)
# Check that the show message page requires us to login
- get :show, :params => { :id => unread_message.id }
+ get message_path(:id => unread_message)
assert_redirected_to login_path(:referer => message_path(:id => unread_message.id))
# Login as the wrong user
- session[:user] = other_user.id
+ session_for(other_user)
# Check that we can't read the message
- get :show, :params => { :id => unread_message.id }
+ get message_path(:id => unread_message)
assert_redirected_to login_path(:referer => message_path(:id => unread_message.id))
assert_equal "You are logged in as `#{other_user.display_name}' but the message you have asked to read was not sent by or to that user. Please login as the correct user in order to read it.", flash[:notice]
# Login as the message sender
- session[:user] = user.id
+ session_for(user)
# Check that the message sender can read the message
- get :show, :params => { :id => unread_message.id }
+ get message_path(:id => unread_message)
assert_response :success
assert_template "show"
assert_not Message.find(unread_message.id).message_read
# Login as the message recipient
- session[:user] = recipient_user.id
+ session_for(recipient_user)
# Check that the message recipient can read the message
- get :show, :params => { :id => unread_message.id }
+ get message_path(:id => unread_message)
assert_response :success
assert_template "show"
assert Message.find(unread_message.id).message_read
# Asking to read a message with no ID should fail
- assert_raise ActionController::UrlGenerationError do
- get :show
- end
+ get message_path
+ assert_response :success
# Asking to read a message with a bogus ID should fail
- get :show, :params => { :id => 99999 }
+ get message_path(:id => 99999)
assert_response :not_found
assert_template "no_such_message"
end
user = create(:user)
read_message = create(:message, :read, :recipient => user)
# Check that the inbox page requires us to login
- get :inbox
+ get inbox_messages_path
assert_redirected_to login_path(:referer => inbox_messages_path)
# Login
- session[:user] = user.id
+ session_for(user)
# Check that we can view our inbox when logged in
- get :inbox
+ get inbox_messages_path
assert_response :success
assert_template "inbox"
assert_select ".content-inner > table", :count => 1 do
create(:message, :sender => user)
# Check that the outbox page requires us to login
- get :outbox
+ get outbox_messages_path
assert_redirected_to login_path(:referer => outbox_messages_path)
# Login
- session[:user] = user.id
+ session_for(user)
# Check that we can view our outbox when logged in
- get :outbox
+ get outbox_messages_path
assert_response :success
assert_template "outbox"
assert_select ".content-inner > table", :count => 1 do
unread_message = create(:message, :unread, :sender => user, :recipient => recipient_user)
# Check that the marking a message requires us to login
- post :mark, :params => { :message_id => unread_message.id }
+ post message_mark_path(:message_id => unread_message)
assert_response :forbidden
# Login as a user with no messages
- session[:user] = other_user.id
+ session_for(other_user)
# Check that marking a message we didn't send or receive fails
- post :mark, :params => { :message_id => unread_message.id }
+ post message_mark_path(:message_id => unread_message)
assert_response :not_found
assert_template "no_such_message"
# Login as the message recipient_user
- session[:user] = recipient_user.id
+ session_for(recipient_user)
# Check that the marking a message read works
- post :mark, :params => { :message_id => unread_message.id, :mark => "read" }
+ post message_mark_path(:message_id => unread_message, :mark => "read")
assert_redirected_to inbox_messages_path
assert Message.find(unread_message.id).message_read
# Check that the marking a message unread works
- post :mark, :params => { :message_id => unread_message.id, :mark => "unread" }
+ post message_mark_path(:message_id => unread_message, :mark => "unread")
assert_redirected_to inbox_messages_path
assert_not Message.find(unread_message.id).message_read
# Check that the marking a message read via XHR works
- post :mark, :xhr => true, :params => { :message_id => unread_message.id, :mark => "read" }
+ post message_mark_path(:message_id => unread_message, :mark => "read"), :xhr => true
assert_response :success
assert_template "mark"
assert Message.find(unread_message.id).message_read
# Check that the marking a message unread via XHR works
- post :mark, :xhr => true, :params => { :message_id => unread_message.id, :mark => "unread" }
+ post message_mark_path(:message_id => unread_message, :mark => "unread"), :xhr => true
assert_response :success
assert_template "mark"
assert_not Message.find(unread_message.id).message_read
# Asking to mark a message with no ID should fail
- assert_raise ActionController::UrlGenerationError do
- post :mark
- end
+ post message_mark_path
+ assert_response :redirect
+ assert_redirected_to inbox_messages_path
# Asking to mark a message with a bogus ID should fail
- post :mark, :params => { :message_id => 99999 }
+ post message_mark_path(:message_id => 99999)
assert_response :not_found
assert_template "no_such_message"
end
sent_message = create(:message, :unread, :recipient => second_user, :sender => user)
# Check that destroying a message requires us to login
- delete :destroy, :params => { :id => read_message.id }
+ delete message_path(:id => read_message)
assert_response :forbidden
# Login as a user with no messages
- session[:user] = other_user.id
+ session_for(other_user)
# Check that destroying a message we didn't send or receive fails
- delete :destroy, :params => { :id => read_message.id }
+ delete message_path(:id => read_message)
assert_response :not_found
assert_template "no_such_message"
# Login as the message recipient_user
- session[:user] = user.id
+ session_for(user)
# Check that the destroy a received message works
- delete :destroy, :params => { :id => read_message.id }
+ delete message_path(:id => read_message)
assert_redirected_to inbox_messages_path
assert_equal "Message deleted", flash[:notice]
m = Message.find(read_message.id)
assert_not m.to_user_visible
# Check that the destroying a sent message works
- delete :destroy, :params => { :id => sent_message.id, :referer => outbox_messages_path }
+ delete message_path(:id => sent_message, :referer => outbox_messages_path)
assert_redirected_to outbox_messages_path
assert_equal "Message deleted", flash[:notice]
m = Message.find(sent_message.id)
assert m.to_user_visible
# Asking to destroy a message with no ID should fail
- assert_raise ActionController::UrlGenerationError do
- post :destroy
- end
+ delete message_path
+ assert_response :redirect
+ assert_redirected_to inbox_messages_path
# Asking to destroy a message with a bogus ID should fail
- delete :destroy, :params => { :id => 99999 }
+ delete message_path(:id => 99999)
assert_response :not_found
assert_template "no_such_message"
end
require "test_helper"
-class NotesControllerTest < ActionController::TestCase
+class NotesControllerTest < ActionDispatch::IntegrationTest
def setup
super
# Stub nominatim response for note locations
end
# Note that the table rows include a header row
- get :mine, :params => { :display_name => first_user.display_name }
+ get my_notes_path(:display_name => first_user.display_name)
assert_response :success
assert_select "table.note_list tr", :count => 2
- get :mine, :params => { :display_name => second_user.display_name }
+ get my_notes_path(:display_name => second_user.display_name)
assert_response :success
assert_select "table.note_list tr", :count => 2
- get :mine, :params => { :display_name => "non-existent" }
+ get my_notes_path(:display_name => "non-existent")
assert_response :not_found
- session[:user] = moderator_user.id
+ session_for(moderator_user)
- get :mine, :params => { :display_name => first_user.display_name }
+ get my_notes_path(:display_name => first_user.display_name)
assert_response :success
assert_select "table.note_list tr", :count => 2
- get :mine, :params => { :display_name => second_user.display_name }
+ get my_notes_path(:display_name => second_user.display_name)
assert_response :success
assert_select "table.note_list tr", :count => 3
- get :mine, :params => { :display_name => "non-existent" }
+ get my_notes_path(:display_name => "non-existent")
assert_response :not_found
end
create(:note_comment, :note => note, :author => user)
end
- get :mine, :params => { :display_name => user.display_name }
+ get my_notes_path(:display_name => user.display_name)
assert_response :success
assert_select "table.note_list tr", :count => 11
- get :mine, :params => { :display_name => user.display_name, :page => 2 }
+ get my_notes_path(:display_name => user.display_name, :page => 2)
assert_response :success
assert_select "table.note_list tr", :count => 11
end
require "test_helper"
-class OauthClientsControllerTest < ActionController::TestCase
+class OauthClientsControllerTest < ActionDispatch::IntegrationTest
##
# test all routes which lead to this controller
def test_routes
create_list(:client_application, 2, :user => user)
create_list(:access_token, 2, :user => user)
- get :index,
- :params => { :display_name => user.display_name }
+ get oauth_clients_path(:display_name => user.display_name)
assert_response :redirect
assert_redirected_to login_path(:referer => oauth_clients_path(:display_name => user.display_name))
- get :index,
- :params => { :display_name => user.display_name },
- :session => { :user => user }
+ session_for(user)
+
+ get oauth_clients_path(:display_name => user.display_name)
assert_response :success
assert_template "index"
assert_select "div.client_application", 2
def test_new
user = create(:user)
- get :new,
- :params => { :display_name => user.display_name }
+ get new_oauth_client_path(:display_name => user.display_name)
assert_response :redirect
assert_redirected_to login_path(:referer => new_oauth_client_path(:display_name => user.display_name))
- get :new,
- :params => { :display_name => user.display_name },
- :session => { :user => user }
+ session_for(user)
+
+ get new_oauth_client_path(:display_name => user.display_name)
assert_response :success
assert_template "new"
assert_select "form", 1 do
user = create(:user)
assert_difference "ClientApplication.count", 0 do
- post :create, :params => { :display_name => user.display_name }
+ post oauth_clients_path(:display_name => user.display_name)
end
assert_response :forbidden
+ session_for(user)
+
assert_difference "ClientApplication.count", 0 do
- post :create,
- :params => { :display_name => user.display_name,
- :client_application => { :name => "Test Application" } },
- :session => { :user => user }
+ post oauth_clients_path(:display_name => user.display_name,
+ :client_application => { :name => "Test Application" })
end
assert_response :success
assert_template "new"
assert_difference "ClientApplication.count", 1 do
- post :create,
- :params => { :display_name => user.display_name,
- :client_application => { :name => "Test Application",
- :url => "http://test.example.com/" } },
- :session => { :user => user }
+ post oauth_clients_path(:display_name => user.display_name,
+ :client_application => { :name => "Test Application",
+ :url => "http://test.example.com/" })
end
assert_response :redirect
assert_redirected_to oauth_client_path(:id => ClientApplication.find_by(:name => "Test Application").id)
client = create(:client_application, :user => user)
other_client = create(:client_application)
- get :show,
- :params => { :display_name => user.display_name, :id => client.id }
+ get oauth_client_path(:display_name => user.display_name, :id => client)
assert_response :redirect
assert_redirected_to login_path(:referer => oauth_client_path(:display_name => user.display_name, :id => client.id))
- get :show,
- :params => { :display_name => user.display_name, :id => other_client.id },
- :session => { :user => user }
+ session_for(user)
+
+ get oauth_client_path(:display_name => user.display_name, :id => other_client)
assert_response :not_found
assert_template "not_found"
- get :show,
- :params => { :display_name => user.display_name, :id => client.id },
- :session => { :user => user }
+ get oauth_client_path(:display_name => user.display_name, :id => client)
assert_response :success
assert_template "show"
end
client = create(:client_application, :user => user)
other_client = create(:client_application)
- get :edit,
- :params => { :display_name => user.display_name, :id => client.id }
+ get edit_oauth_client_path(:display_name => user.display_name, :id => client)
assert_response :redirect
assert_redirected_to login_path(:referer => edit_oauth_client_path(:display_name => user.display_name, :id => client.id))
- get :edit,
- :params => { :display_name => user.display_name, :id => other_client.id },
- :session => { :user => user }
+ session_for(user)
+
+ get edit_oauth_client_path(:display_name => user.display_name, :id => other_client)
assert_response :not_found
assert_template "not_found"
- get :edit,
- :params => { :display_name => user.display_name, :id => client.id },
- :session => { :user => user }
+ get edit_oauth_client_path(:display_name => user.display_name, :id => client)
assert_response :success
assert_template "edit"
assert_select "form", 1 do
client = create(:client_application, :user => user)
other_client = create(:client_application)
- put :update,
- :params => { :display_name => user.display_name, :id => client.id }
+ put oauth_client_path(:display_name => user.display_name, :id => client)
assert_response :forbidden
- put :update,
- :params => { :display_name => user.display_name, :id => other_client.id },
- :session => { :user => user }
+ session_for(user)
+
+ put oauth_client_path(:display_name => user.display_name, :id => other_client)
assert_response :not_found
assert_template "not_found"
- put :update,
- :params => { :display_name => user.display_name,
- :id => client.id,
- :client_application => { :name => "New Name", :url => nil } },
- :session => { :user => user }
+ put oauth_client_path(:display_name => user.display_name, :id => client,
+ :client_application => { :name => "New Name", :url => nil })
assert_response :success
assert_template "edit"
- put :update,
- :params => { :display_name => user.display_name,
- :id => client.id,
- :client_application => { :name => "New Name", :url => "http://new.example.com/url" } },
- :session => { :user => user }
+ put oauth_client_path(:display_name => user.display_name, :id => client,
+ :client_application => { :name => "New Name", :url => "http://new.example.com/url" })
assert_response :redirect
assert_redirected_to oauth_client_path(:id => client.id)
end
other_client = create(:client_application)
assert_difference "ClientApplication.count", 0 do
- delete :destroy,
- :params => { :display_name => user.display_name, :id => client.id }
+ delete oauth_client_path(:display_name => user.display_name, :id => client)
end
assert_response :forbidden
+ session_for(user)
+
assert_difference "ClientApplication.count", 0 do
- delete :destroy,
- :params => { :display_name => user.display_name, :id => other_client.id },
- :session => { :user => user }
+ delete oauth_client_path(:display_name => user.display_name, :id => other_client)
end
assert_response :not_found
assert_template "not_found"
assert_difference "ClientApplication.count", -1 do
- delete :destroy,
- :params => { :display_name => user.display_name, :id => client.id },
- :session => { :user => user }
+ delete oauth_client_path(:display_name => user.display_name, :id => client)
end
assert_response :redirect
assert_redirected_to oauth_clients_path(:display_name => user.display_name)
require "test_helper"
-class OauthControllerTest < ActionController::TestCase
+class OauthControllerTest < ActionDispatch::IntegrationTest
##
# test all routes which lead to this controller
def test_routes
require "test_helper"
-class RedactionsControllerTest < ActionController::TestCase
+class RedactionsControllerTest < ActionDispatch::IntegrationTest
##
# test all routes which lead to this controller
def test_routes
def test_index
create(:redaction)
- get :index
+ get redactions_path
assert_response :success
assert_template :index
assert_select "ul#redaction_list", 1 do
end
def test_new
- get :new
+ get new_redaction_path
assert_response :redirect
assert_redirected_to login_path(:referer => new_redaction_path)
end
def test_new_moderator
- session[:user] = create(:moderator_user).id
+ session_for(create(:moderator_user))
- get :new
+ get new_redaction_path
assert_response :success
assert_template :new
end
def test_new_non_moderator
- session[:user] = create(:user).id
+ session_for(create(:user))
- get :new
+ get new_redaction_path
assert_response :redirect
assert_redirected_to :controller => "errors", :action => "forbidden"
end
def test_create_moderator
- session[:user] = create(:moderator_user).id
+ session_for(create(:moderator_user))
- post :create, :params => { :redaction => { :title => "Foo", :description => "Description here." } }
+ post redactions_path(:redaction => { :title => "Foo", :description => "Description here." })
assert_response :redirect
assert_redirected_to(redaction_path(Redaction.find_by(:title => "Foo")))
end
def test_create_moderator_invalid
- session[:user] = create(:moderator_user).id
+ session_for(create(:moderator_user))
- post :create, :params => { :redaction => { :title => "Foo", :description => "" } }
+ post redactions_path(:redaction => { :title => "Foo", :description => "" })
assert_response :success
assert_template :new
end
def test_create_non_moderator
- session[:user] = create(:user).id
+ session_for(create(:user))
- post :create, :params => { :redaction => { :title => "Foo", :description => "Description here." } }
+ post redactions_path(:redaction => { :title => "Foo", :description => "Description here." })
assert_response :redirect
assert_redirected_to :controller => "errors", :action => "forbidden"
end
def test_destroy_moderator_empty
- session[:user] = create(:moderator_user).id
+ session_for(create(:moderator_user))
# create an empty redaction
redaction = create(:redaction)
- delete :destroy, :params => { :id => redaction.id }
+ delete redaction_path(:id => redaction)
assert_response :redirect
assert_redirected_to(redactions_path)
end
def test_destroy_moderator_non_empty
- session[:user] = create(:moderator_user).id
+ session_for(create(:moderator_user))
# create elements in the redaction
redaction = create(:redaction)
create(:old_node, :redaction => redaction)
- delete :destroy, :params => { :id => redaction.id }
+ delete redaction_path(:id => redaction)
assert_response :redirect
assert_redirected_to(redaction_path(redaction))
assert_match(/^Redaction is not empty/, flash[:error])
end
def test_delete_non_moderator
- session[:user] = create(:user).id
+ session_for(create(:user))
- delete :destroy, :params => { :id => create(:redaction).id }
+ delete redaction_path(:id => create(:redaction))
assert_response :redirect
assert_redirected_to :controller => "errors", :action => "forbidden"
end
def test_edit
redaction = create(:redaction)
- get :edit, :params => { :id => redaction.id }
+ get edit_redaction_path(:id => redaction)
assert_response :redirect
assert_redirected_to login_path(:referer => edit_redaction_path(redaction))
end
def test_edit_moderator
- session[:user] = create(:moderator_user).id
+ session_for(create(:moderator_user))
- get :edit, :params => { :id => create(:redaction).id }
+ get edit_redaction_path(:id => create(:redaction))
assert_response :success
end
def test_edit_non_moderator
- session[:user] = create(:user).id
+ session_for(create(:user))
- get :edit, :params => { :id => create(:redaction).id }
+ get edit_redaction_path(:id => create(:redaction))
assert_response :redirect
assert_redirected_to :controller => "errors", :action => "forbidden"
end
def test_update_moderator
- session[:user] = create(:moderator_user).id
+ session_for(create(:moderator_user))
redaction = create(:redaction)
- put :update, :params => { :id => redaction.id, :redaction => { :title => "Foo", :description => "Description here." } }
+ put redaction_path(:id => redaction, :redaction => { :title => "Foo", :description => "Description here." })
assert_response :redirect
assert_redirected_to(redaction_path(redaction))
end
def test_update_moderator_invalid
- session[:user] = create(:moderator_user).id
+ session_for(create(:moderator_user))
redaction = create(:redaction)
- put :update, :params => { :id => redaction.id, :redaction => { :title => "Foo", :description => "" } }
+ put redaction_path(:id => redaction, :redaction => { :title => "Foo", :description => "" })
assert_response :success
assert_template :edit
end
def test_updated_non_moderator
- session[:user] = create(:user).id
+ session_for(create(:user))
redaction = create(:redaction)
- put :update, :params => { :id => redaction.id, :redaction => { :title => "Foo", :description => "Description here." } }
+ put redaction_path(:id => redaction, :redaction => { :title => "Foo", :description => "Description here." })
assert_response :redirect
assert_redirected_to :controller => "errors", :action => "forbidden"
end
require "test_helper"
-class ReportsControllerTest < ActionController::TestCase
+class ReportsControllerTest < ActionDispatch::IntegrationTest
def test_new_report_without_login
target_user = create(:user)
- get :new, :params => { :reportable_id => target_user.id, :reportable_type => "User" }
+ get new_report_path(:reportable_id => target_user.id, :reportable_type => "User")
assert_response :redirect
assert_redirected_to login_path(:referer => new_report_path(:reportable_id => target_user.id, :reportable_type => "User"))
end
def test_new_report_after_login
target_user = create(:user)
- session[:user] = create(:user).id
+ session_for(create(:user))
# Create an Issue and a report
- get :new, :params => { :reportable_id => target_user.id, :reportable_type => "User" }
+ get new_report_path(:reportable_id => target_user.id, :reportable_type => "User")
assert_response :success
assert_difference "Issue.count", 1 do
details = "Details of a report"
category = "other"
- post :create,
- :params => {
- :report => {
- :details => details,
- :category => category,
- :issue => { :reportable_id => target_user.id, :reportable_type => "User" }
- }
- }
+ post reports_path(:report => {
+ :details => details,
+ :category => category,
+ :issue => { :reportable_id => target_user.id, :reportable_type => "User" }
+ })
end
assert_response :redirect
assert_redirected_to user_path(target_user)
target_user = create(:user)
# Login
- session[:user] = create(:user).id
+ session_for(create(:user))
# Create an Issue and a report
- get :new, :params => { :reportable_id => target_user.id, :reportable_type => "User" }
+ get new_report_path(:reportable_id => target_user.id, :reportable_type => "User")
assert_response :success
assert_difference "Issue.count", 1 do
details = "Details of a report"
category = "other"
- post :create,
- :params => {
- :report => {
- :details => details,
- :category => category,
- :issue => { :reportable_id => target_user.id, :reportable_type => "User" }
- }
- }
+ post reports_path(:report => {
+ :details => details,
+ :category => category,
+ :issue => { :reportable_id => target_user.id, :reportable_type => "User" }
+ })
end
assert_response :redirect
assert_redirected_to user_path(target_user)
assert_equal 1, issue.reports.count
- get :new, :params => { :reportable_id => target_user.id, :reportable_type => "User" }
+ get new_report_path(:reportable_id => target_user.id, :reportable_type => "User")
assert_response :success
# Report without details
assert_no_difference "Issue.count" do
category = "other"
- post :create,
- :params => {
- :report => {
- :category => category,
- :issue => { :reportable_id => 1, :reportable_type => "User" }
- }
- }
+ post reports_path(:report => {
+ :category => category,
+ :issue => { :reportable_id => 1, :reportable_type => "User" }
+ })
end
assert_response :redirect
target_user = create(:user)
# Login
- session[:user] = create(:user).id
+ session_for(create(:user))
# Create an Issue and a report
- get :new, :params => { :reportable_id => target_user.id, :reportable_type => "User" }
+ get new_report_path(:reportable_id => target_user.id, :reportable_type => "User")
assert_response :success
assert_difference "Issue.count", 1 do
details = "Details of a report"
category = "other"
- post :create,
- :params => {
- :report => {
- :details => details,
- :category => category,
- :issue => { :reportable_id => target_user.id, :reportable_type => "User" }
- }
- }
+ post reports_path(:report => {
+ :details => details,
+ :category => category,
+ :issue => { :reportable_id => target_user.id, :reportable_type => "User" }
+ })
end
assert_response :redirect
assert_redirected_to user_path(target_user)
assert_equal 1, issue.reports.count
# Create a report for an existing Issue
- get :new, :params => { :reportable_id => target_user.id, :reportable_type => "User" }
+ get new_report_path(:reportable_id => target_user.id, :reportable_type => "User")
assert_response :success
assert_no_difference "Issue.count" do
details = "Details of another report under the same issue"
category = "other"
- post :create,
- :params => {
- :report => {
- :details => details,
- :category => category,
- :issue => { :reportable_id => target_user.id, :reportable_type => "User" }
- }
- }
+ post reports_path(:report => {
+ :details => details,
+ :category => category,
+ :issue => { :reportable_id => target_user.id, :reportable_type => "User" }
+ })
end
assert_response :redirect
require "test_helper"
-class TracesControllerTest < ActionController::TestCase
+class TracesControllerTest < ActionDispatch::IntegrationTest
# Use temporary directories with unique names for each test
# This allows the tests to be run in parallel.
def setup
end
# First with the public index
- get :index
+ get traces_path
check_trace_index [trace_b, trace_a]
# Restrict traces to those with a given tag
- get :index, :params => { :tag => "London" }
+ get traces_path(:tag => "London")
check_trace_index [trace_a]
+ session_for(user)
+
# Should see more when we are logged in
- get :index, :session => { :user => user }
+ get traces_path
check_trace_index [trace_d, trace_c, trace_b, trace_a]
# Again, we should see more when we are logged in
- get :index, :params => { :tag => "London" }, :session => { :user => user }
+ get traces_path(:tag => "London")
check_trace_index [trace_c, trace_a]
end
end
# First try to get it when not logged in
- get :mine
+ get traces_mine_path
assert_redirected_to :controller => "users", :action => "login", :referer => "/traces/mine"
+ session_for(user)
+
# Now try when logged in
- get :mine, :session => { :user => user }
+ get traces_mine_path
assert_redirected_to :action => "index", :display_name => user.display_name
# Fetch the actual index
- get :index, :params => { :display_name => user.display_name }, :session => { :user => user }
+ get traces_path(:display_name => user.display_name)
check_trace_index [trace_b]
end
end
# Test a user with no traces
- get :index, :params => { :display_name => second_user.display_name }
+ get traces_path(:display_name => second_user.display_name)
check_trace_index []
# Test the user with the traces - should see only public ones
- get :index, :params => { :display_name => user.display_name }
+ get traces_path(:display_name => user.display_name)
check_trace_index [trace_b]
+ session_for(third_user)
+
# Should still see only public ones when authenticated as another user
- get :index, :params => { :display_name => user.display_name }, :session => { :user => third_user }
+ get traces_path(:display_name => user.display_name)
check_trace_index [trace_b]
+ session_for(user)
+
# Should see all traces when authenticated as the target user
- get :index, :params => { :display_name => user.display_name }, :session => { :user => user }
+ get traces_path(:display_name => user.display_name)
check_trace_index [trace_c, trace_b]
# Should only see traces with the correct tag when a tag is specified
- get :index, :params => { :display_name => user.display_name, :tag => "London" }, :session => { :user => user }
+ get traces_path(:display_name => user.display_name, :tag => "London")
check_trace_index [trace_c]
# Should get an error if the user does not exist
- get :index, :params => { :display_name => "UnknownUser" }
+ get traces_path(:display_name => "UnknownUser")
assert_response :not_found
assert_template "users/no_such_user"
end
create_list(:trace, 50)
# Try and get the index
- get :index
+ get traces_path
assert_response :success
assert_select "table#trace_list tbody", :count => 1 do
assert_select "tr", :count => 20
end
# Try and get the second page
- get :index, :params => { :page => 2 }
+ get traces_path(:page => 2)
assert_response :success
assert_select "table#trace_list tbody", :count => 1 do
assert_select "tr", :count => 20
end
# First with the public feed
- get :georss, :params => { :format => :rss }
+ get traces_rss_path
check_trace_feed [trace_b, trace_a]
# Restrict traces to those with a given tag
- get :georss, :params => { :tag => "London", :format => :rss }
+ get traces_rss_path(:tag => "London")
check_trace_feed [trace_a]
end
create(:trace, :visibility => "private")
# Test a user with no traces
- get :georss, :params => { :display_name => second_user.display_name, :format => :rss }
+ get traces_rss_path(:display_name => second_user.display_name)
check_trace_feed []
# Test the user with the traces - should see only public ones
- get :georss, :params => { :display_name => user.display_name, :format => :rss }
+ get traces_rss_path(:display_name => user.display_name)
check_trace_feed [trace_c, trace_b]
# Should only see traces with the correct tag when a tag is specified
- get :georss, :params => { :display_name => user.display_name, :tag => "London", :format => :rss }
+ get traces_rss_path(:display_name => user.display_name, :tag => "London")
check_trace_feed [trace_c]
# Should no traces if the user does not exist
- get :georss, :params => { :display_name => "UnknownUser", :format => :rss }
+ get traces_rss_path(:display_name => "UnknownUser")
check_trace_feed []
end
public_trace_file = create(:trace, :visibility => "public")
# First with no auth, which should work since the trace is public
- get :show, :params => { :display_name => public_trace_file.user.display_name, :id => public_trace_file.id }
+ get show_trace_path(:display_name => public_trace_file.user.display_name, :id => public_trace_file)
check_trace_show public_trace_file
# Now with some other user, which should work since the trace is public
- get :show, :params => { :display_name => public_trace_file.user.display_name, :id => public_trace_file.id }, :session => { :user => create(:user) }
+ session_for(create(:user))
+ get show_trace_path(:display_name => public_trace_file.user.display_name, :id => public_trace_file)
check_trace_show public_trace_file
# And finally we should be able to do it with the owner of the trace
- get :show, :params => { :display_name => public_trace_file.user.display_name, :id => public_trace_file.id }, :session => { :user => public_trace_file.user }
+ session_for(public_trace_file.user)
+ get show_trace_path(:display_name => public_trace_file.user.display_name, :id => public_trace_file)
check_trace_show public_trace_file
end
anon_trace_file = create(:trace, :visibility => "private")
# First with no auth
- get :show, :params => { :display_name => anon_trace_file.user.display_name, :id => anon_trace_file.id }
+ get show_trace_path(:display_name => anon_trace_file.user.display_name, :id => anon_trace_file)
assert_response :redirect
assert_redirected_to :action => :index
# Now with some other user, which should not work since the trace is anon
- get :show, :params => { :display_name => anon_trace_file.user.display_name, :id => anon_trace_file.id }, :session => { :user => create(:user) }
+ session_for(create(:user))
+ get show_trace_path(:display_name => anon_trace_file.user.display_name, :id => anon_trace_file)
assert_response :redirect
assert_redirected_to :action => :index
# And finally we should be able to do it with the owner of the trace
- get :show, :params => { :display_name => anon_trace_file.user.display_name, :id => anon_trace_file.id }, :session => { :user => anon_trace_file.user }
+ session_for(anon_trace_file.user)
+ get show_trace_path(:display_name => anon_trace_file.user.display_name, :id => anon_trace_file)
check_trace_show anon_trace_file
end
deleted_trace_file = create(:trace, :deleted)
# First with a trace that has never existed
- get :show, :params => { :display_name => create(:user).display_name, :id => 0 }
+ get show_trace_path(:display_name => create(:user).display_name, :id => 0)
assert_response :redirect
assert_redirected_to :action => :index
# Now with a trace that has been deleted
- get :show, :params => { :display_name => deleted_trace_file.user.display_name, :id => deleted_trace_file.id }, :session => { :user => deleted_trace_file.user }
+ session_for(deleted_trace_file.user)
+ get show_trace_path(:display_name => deleted_trace_file.user.display_name, :id => deleted_trace_file)
assert_response :redirect
assert_redirected_to :action => :index
end
public_trace_file = create(:trace, :visibility => "public", :fixture => "a")
# First with no auth, which should work since the trace is public
- get :data, :params => { :display_name => public_trace_file.user.display_name, :id => public_trace_file.id }
+ get trace_data_path(:display_name => public_trace_file.user.display_name, :id => public_trace_file)
check_trace_data public_trace_file, "848caa72f2f456d1bd6a0fdf228aa1b9"
# Now with some other user, which should work since the trace is public
- get :data, :params => { :display_name => public_trace_file.user.display_name, :id => public_trace_file.id }, :session => { :user => create(:user) }
+ session_for(create(:user))
+ get trace_data_path(:display_name => public_trace_file.user.display_name, :id => public_trace_file)
check_trace_data public_trace_file, "848caa72f2f456d1bd6a0fdf228aa1b9"
# And finally we should be able to do it with the owner of the trace
- get :data, :params => { :display_name => public_trace_file.user.display_name, :id => public_trace_file.id }, :session => { :user => public_trace_file.user }
+ session_for(public_trace_file.user)
+ get trace_data_path(:display_name => public_trace_file.user.display_name, :id => public_trace_file)
check_trace_data public_trace_file, "848caa72f2f456d1bd6a0fdf228aa1b9"
end
identifiable_trace_file = create(:trace, :visibility => "identifiable", :fixture => "d")
# First get the data as is
- get :data, :params => { :display_name => identifiable_trace_file.user.display_name, :id => identifiable_trace_file.id }
+ get trace_data_path(:display_name => identifiable_trace_file.user.display_name, :id => identifiable_trace_file)
check_trace_data identifiable_trace_file, "c6422a3d8750faae49ed70e7e8a51b93", "application/x-gzip", "gpx.gz"
# Now ask explicitly for XML format
- get :data, :params => { :display_name => identifiable_trace_file.user.display_name, :id => identifiable_trace_file.id, :format => "xml" }
+ get trace_data_path(:display_name => identifiable_trace_file.user.display_name, :id => identifiable_trace_file.id, :format => "xml")
check_trace_data identifiable_trace_file, "abd6675fdf3024a84fc0a1deac147c0d", "application/xml", "xml"
# Now ask explicitly for GPX format
- get :data, :params => { :display_name => identifiable_trace_file.user.display_name, :id => identifiable_trace_file.id, :format => "gpx" }
+ get trace_data_path(:display_name => identifiable_trace_file.user.display_name, :id => identifiable_trace_file.id, :format => "gpx")
check_trace_data identifiable_trace_file, "abd6675fdf3024a84fc0a1deac147c0d"
end
anon_trace_file = create(:trace, :visibility => "private", :fixture => "b")
# First with no auth
- get :data, :params => { :display_name => anon_trace_file.user.display_name, :id => anon_trace_file.id }
+ get trace_data_path(:display_name => anon_trace_file.user.display_name, :id => anon_trace_file)
assert_response :not_found
# Now with some other user, which shouldn't work since the trace is anon
- get :data, :params => { :display_name => anon_trace_file.user.display_name, :id => anon_trace_file.id }, :session => { :user => create(:user) }
+ session_for(create(:user))
+ get trace_data_path(:display_name => anon_trace_file.user.display_name, :id => anon_trace_file)
assert_response :not_found
# And finally we should be able to do it with the owner of the trace
- get :data, :params => { :display_name => anon_trace_file.user.display_name, :id => anon_trace_file.id }, :session => { :user => anon_trace_file.user }
+ session_for(anon_trace_file.user)
+ get trace_data_path(:display_name => anon_trace_file.user.display_name, :id => anon_trace_file)
check_trace_data anon_trace_file, "db4cb5ed2d7d2b627b3b504296c4f701"
end
deleted_trace_file = create(:trace, :deleted)
# First with a trace that has never existed
- get :data, :params => { :display_name => create(:user).display_name, :id => 0 }
+ get trace_data_path(:display_name => create(:user).display_name, :id => 0)
assert_response :not_found
# Now with a trace that has been deleted
- get :data, :params => { :display_name => deleted_trace_file.user.display_name, :id => deleted_trace_file.id }, :session => { :user => deleted_trace_file.user }
+ session_for(deleted_trace_file.user)
+ get trace_data_path(:display_name => deleted_trace_file.user.display_name, :id => deleted_trace_file)
assert_response :not_found
end
public_trace_file = create(:trace, :visibility => "public", :fixture => "a")
# First with no auth, which should work since the trace is public
- get :picture, :params => { :display_name => public_trace_file.user.display_name, :id => public_trace_file.id }
+ get trace_picture_path(:display_name => public_trace_file.user.display_name, :id => public_trace_file)
check_trace_picture public_trace_file
# Now with some other user, which should work since the trace is public
- get :picture, :params => { :display_name => public_trace_file.user.display_name, :id => public_trace_file.id }, :session => { :user => create(:user) }
+ session_for(create(:user))
+ get trace_picture_path(:display_name => public_trace_file.user.display_name, :id => public_trace_file)
check_trace_picture public_trace_file
# And finally we should be able to do it with the owner of the trace
- get :picture, :params => { :display_name => public_trace_file.user.display_name, :id => public_trace_file.id }, :session => { :user => public_trace_file.user }
+ session_for(public_trace_file.user)
+ get trace_picture_path(:display_name => public_trace_file.user.display_name, :id => public_trace_file)
check_trace_picture public_trace_file
end
anon_trace_file = create(:trace, :visibility => "private", :fixture => "b")
# First with no auth
- get :picture, :params => { :display_name => anon_trace_file.user.display_name, :id => anon_trace_file.id }
+ get trace_picture_path(:display_name => anon_trace_file.user.display_name, :id => anon_trace_file)
assert_response :forbidden
# Now with some other user, which shouldn't work since the trace is anon
- get :picture, :params => { :display_name => anon_trace_file.user.display_name, :id => anon_trace_file.id }, :session => { :user => create(:user) }
+ session_for(create(:user))
+ get trace_picture_path(:display_name => anon_trace_file.user.display_name, :id => anon_trace_file)
assert_response :forbidden
# And finally we should be able to do it with the owner of the trace
- get :picture, :params => { :display_name => anon_trace_file.user.display_name, :id => anon_trace_file.id }, :session => { :user => anon_trace_file.user }
+ session_for(anon_trace_file.user)
+ get trace_picture_path(:display_name => anon_trace_file.user.display_name, :id => anon_trace_file)
check_trace_picture anon_trace_file
end
deleted_trace_file = create(:trace, :deleted)
# First with a trace that has never existed
- get :picture, :params => { :display_name => create(:user).display_name, :id => 0 }
+ get trace_picture_path(:display_name => create(:user).display_name, :id => 0)
assert_response :not_found
# Now with a trace that has been deleted
- get :picture, :params => { :display_name => deleted_trace_file.user.display_name, :id => deleted_trace_file.id }, :session => { :user => deleted_trace_file.user }
+ session_for(deleted_trace_file.user)
+ get trace_picture_path(:display_name => deleted_trace_file.user.display_name, :id => deleted_trace_file)
assert_response :not_found
end
public_trace_file = create(:trace, :visibility => "public", :fixture => "a")
# First with no auth, which should work since the trace is public
- get :icon, :params => { :display_name => public_trace_file.user.display_name, :id => public_trace_file.id }
+ get trace_icon_path(:display_name => public_trace_file.user.display_name, :id => public_trace_file)
check_trace_icon public_trace_file
# Now with some other user, which should work since the trace is public
- get :icon, :params => { :display_name => public_trace_file.user.display_name, :id => public_trace_file.id }, :session => { :user => create(:user) }
+ session_for(create(:user))
+ get trace_icon_path(:display_name => public_trace_file.user.display_name, :id => public_trace_file)
check_trace_icon public_trace_file
# And finally we should be able to do it with the owner of the trace
- get :icon, :params => { :display_name => public_trace_file.user.display_name, :id => public_trace_file.id }, :session => { :user => public_trace_file.user }
+ session_for(public_trace_file.user)
+ get trace_icon_path(:display_name => public_trace_file.user.display_name, :id => public_trace_file)
check_trace_icon public_trace_file
end
anon_trace_file = create(:trace, :visibility => "private", :fixture => "b")
# First with no auth
- get :icon, :params => { :display_name => anon_trace_file.user.display_name, :id => anon_trace_file.id }
+ get trace_icon_path(:display_name => anon_trace_file.user.display_name, :id => anon_trace_file)
assert_response :forbidden
# Now with some other user, which shouldn't work since the trace is anon
- get :icon, :params => { :display_name => anon_trace_file.user.display_name, :id => anon_trace_file.id }, :session => { :user => create(:user) }
+ session_for(create(:user))
+ get trace_icon_path(:display_name => anon_trace_file.user.display_name, :id => anon_trace_file)
assert_response :forbidden
# And finally we should be able to do it with the owner of the trace
- get :icon, :params => { :display_name => anon_trace_file.user.display_name, :id => anon_trace_file.id }, :session => { :user => anon_trace_file.user }
+ session_for(anon_trace_file.user)
+ get trace_icon_path(:display_name => anon_trace_file.user.display_name, :id => anon_trace_file)
check_trace_icon anon_trace_file
end
deleted_trace_file = create(:trace, :deleted)
# First with a trace that has never existed
- get :icon, :params => { :display_name => create(:user).display_name, :id => 0 }
+ get trace_icon_path(:display_name => create(:user).display_name, :id => 0)
assert_response :not_found
# Now with a trace that has been deleted
- get :icon, :params => { :display_name => deleted_trace_file.user.display_name, :id => deleted_trace_file.id }, :session => { :user => deleted_trace_file.user }
+ session_for(deleted_trace_file.user)
+ get trace_icon_path(:display_name => deleted_trace_file.user.display_name, :id => deleted_trace_file)
assert_response :not_found
end
# Test fetching the new trace page
def test_new_get
# First with no auth
- get :new
+ get new_trace_path
assert_response :redirect
assert_redirected_to :controller => :users, :action => :login, :referer => new_trace_path
# Now authenticated as a user with gps.trace.visibility set
user = create(:user)
create(:user_preference, :user => user, :k => "gps.trace.visibility", :v => "identifiable")
- get :new, :session => { :user => user }
+ session_for(user)
+ get new_trace_path
assert_response :success
assert_template :new
assert_select "select#trace_visibility option[value=identifiable][selected]", 1
# Now authenticated as a user with gps.trace.public set
second_user = create(:user)
create(:user_preference, :user => second_user, :k => "gps.trace.public", :v => "default")
- get :new, :session => { :user => second_user }
+ session_for(second_user)
+ get new_trace_path
assert_response :success
assert_template :new
assert_select "select#trace_visibility option[value=public][selected]", 1
# Now authenticated as a user with no preferences
third_user = create(:user)
- get :new, :session => { :user => third_user }
+ session_for(third_user)
+ get new_trace_path
assert_response :success
assert_template :new
assert_select "select#trace_visibility option[value=private][selected]", 1
user = create(:user)
# First with no auth
- post :create, :params => { :trace => { :gpx_file => file, :description => "New Trace", :tagstring => "new,trace", :visibility => "trackable" } }
+ post traces_path(:trace => { :gpx_file => file, :description => "New Trace", :tagstring => "new,trace", :visibility => "trackable" })
assert_response :forbidden
# Rewind the file
# Now authenticated
create(:user_preference, :user => user, :k => "gps.trace.visibility", :v => "identifiable")
assert_not_equal "trackable", user.preferences.where(:k => "gps.trace.visibility").first.v
- post :create, :params => { :trace => { :gpx_file => file, :description => "New Trace", :tagstring => "new,trace", :visibility => "trackable" } }, :session => { :user => user }
+ session_for(user)
+ post traces_path, :params => { :trace => { :gpx_file => file, :description => "New Trace", :tagstring => "new,trace", :visibility => "trackable" } }
assert_response :redirect
assert_redirected_to :action => :index, :display_name => user.display_name
assert_match(/file has been uploaded/, flash[:notice])
# Now authenticated
create(:user_preference, :user => user, :k => "gps.trace.visibility", :v => "identifiable")
assert_not_equal "trackable", user.preferences.where(:k => "gps.trace.visibility").first.v
- post :create, :params => { :trace => { :gpx_file => file, :description => "", :tagstring => "new,trace", :visibility => "trackable" } }, :session => { :user => user }
+ session_for(user)
+ post traces_path, :params => { :trace => { :gpx_file => file, :description => "", :tagstring => "new,trace", :visibility => "trackable" } }
assert_template :new
assert_match "Description is too short (minimum is 1 character)", response.body
end
deleted_trace_file = create(:trace, :deleted)
# First with no auth
- get :edit, :params => { :display_name => public_trace_file.user.display_name, :id => public_trace_file.id }
+ get edit_trace_path(:display_name => public_trace_file.user.display_name, :id => public_trace_file)
assert_response :redirect
assert_redirected_to :controller => :users, :action => :login, :referer => edit_trace_path(:display_name => public_trace_file.user.display_name, :id => public_trace_file.id)
# Now with some other user, which should fail
- get :edit, :params => { :display_name => public_trace_file.user.display_name, :id => public_trace_file.id }, :session => { :user => create(:user) }
+ session_for(create(:user))
+ get edit_trace_path(:display_name => public_trace_file.user.display_name, :id => public_trace_file)
assert_response :forbidden
# Now with a trace which doesn't exist
- get :edit, :params => { :display_name => create(:user).display_name, :id => 0 }, :session => { :user => create(:user) }
+ session_for(create(:user))
+ get edit_trace_path(:display_name => create(:user).display_name, :id => 0)
assert_response :not_found
# Now with a trace which has been deleted
- get :edit, :params => { :display_name => deleted_trace_file.user.display_name, :id => deleted_trace_file.id }, :session => { :user => deleted_trace_file.user }
+ session_for(deleted_trace_file.user)
+ get edit_trace_path(:display_name => deleted_trace_file.user.display_name, :id => deleted_trace_file)
assert_response :not_found
# Finally with a trace that we are allowed to edit
- get :edit, :params => { :display_name => public_trace_file.user.display_name, :id => public_trace_file.id }, :session => { :user => public_trace_file.user }
+ session_for(public_trace_file.user)
+ get edit_trace_path(:display_name => public_trace_file.user.display_name, :id => public_trace_file)
assert_response :success
end
new_details = { :description => "Changed description", :tagstring => "new_tag", :visibility => "private" }
# First with no auth
- put :update, :params => { :display_name => public_trace_file.user.display_name, :id => public_trace_file.id, :trace => new_details }
+ put trace_path(:display_name => public_trace_file.user.display_name, :id => public_trace_file, :trace => new_details)
assert_response :forbidden
# Now with some other user, which should fail
- put :update, :params => { :display_name => public_trace_file.user.display_name, :id => public_trace_file.id, :trace => new_details }, :session => { :user => create(:user) }
+ session_for(create(:user))
+ put trace_path(:display_name => public_trace_file.user.display_name, :id => public_trace_file, :trace => new_details)
assert_response :forbidden
# Now with a trace which doesn't exist
- put :update, :params => { :display_name => create(:user).display_name, :id => 0 }, :session => { :user => create(:user), :trace => new_details }
+ session_for(create(:user))
+ put trace_path(:display_name => create(:user).display_name, :id => 0, :trace => new_details)
assert_response :not_found
# Now with a trace which has been deleted
- put :update, :params => { :display_name => deleted_trace_file.user.display_name, :id => deleted_trace_file.id, :trace => new_details }, :session => { :user => deleted_trace_file.user }
+ session_for(deleted_trace_file.user)
+ put trace_path(:display_name => deleted_trace_file.user.display_name, :id => deleted_trace_file, :trace => new_details)
assert_response :not_found
# Finally with a trace that we are allowed to edit
- put :update, :params => { :display_name => public_trace_file.user.display_name, :id => public_trace_file.id, :trace => new_details }, :session => { :user => public_trace_file.user }
+ session_for(public_trace_file.user)
+ put trace_path(:display_name => public_trace_file.user.display_name, :id => public_trace_file, :trace => new_details)
assert_response :redirect
assert_redirected_to :action => :show, :display_name => public_trace_file.user.display_name
trace = Trace.find(public_trace_file.id)
deleted_trace_file = create(:trace, :deleted)
# First with no auth
- delete :destroy, :params => { :display_name => public_trace_file.user.display_name, :id => public_trace_file.id }
+ delete trace_path(:display_name => public_trace_file.user.display_name, :id => public_trace_file)
assert_response :forbidden
# Now with some other user, which should fail
- delete :destroy, :params => { :display_name => public_trace_file.user.display_name, :id => public_trace_file.id }, :session => { :user => create(:user) }
+ session_for(create(:user))
+ delete trace_path(:display_name => public_trace_file.user.display_name, :id => public_trace_file)
assert_response :forbidden
# Now with a trace which doesn't exist
- delete :destroy, :params => { :display_name => create(:user).display_name, :id => 0 }, :session => { :user => create(:user) }
+ session_for(create(:user))
+ delete trace_path(:display_name => create(:user).display_name, :id => 0)
assert_response :not_found
# Now with a trace has already been deleted
- delete :destroy, :params => { :display_name => deleted_trace_file.user.display_name, :id => deleted_trace_file.id }, :session => { :user => deleted_trace_file.user }
+ session_for(deleted_trace_file.user)
+ delete trace_path(:display_name => deleted_trace_file.user.display_name, :id => deleted_trace_file)
assert_response :not_found
# Now with a trace that we are allowed to delete
- delete :destroy, :params => { :display_name => public_trace_file.user.display_name, :id => public_trace_file.id }, :session => { :user => public_trace_file.user }
+ session_for(public_trace_file.user)
+ delete trace_path(:display_name => public_trace_file.user.display_name, :id => public_trace_file)
assert_response :redirect
assert_redirected_to :action => :index, :display_name => public_trace_file.user.display_name
trace = Trace.find(public_trace_file.id)
# Finally with a trace that is destroyed by an admin
public_trace_file = create(:trace, :visibility => "public")
admin = create(:administrator_user)
-
- delete :destroy, :params => { :display_name => public_trace_file.user.display_name, :id => public_trace_file.id }, :session => { :user => admin }
+ session_for(admin)
+ delete trace_path(:display_name => public_trace_file.user.display_name, :id => public_trace_file)
assert_response :redirect
assert_redirected_to :action => :index, :display_name => public_trace_file.user.display_name
trace = Trace.find(public_trace_file.id)
assert_select "item", :count => traces.length do |items|
traces.zip(items).each do |trace, item|
assert_select item, "title", trace.name
- assert_select item, "link", "http://test.host/user/#{ERB::Util.u(trace.user.display_name)}/traces/#{trace.id}"
- assert_select item, "guid", "http://test.host/user/#{ERB::Util.u(trace.user.display_name)}/traces/#{trace.id}"
+ assert_select item, "link", "http://www.example.com/user/#{ERB::Util.u(trace.user.display_name)}/traces/#{trace.id}"
+ assert_select item, "guid", "http://www.example.com/user/#{ERB::Util.u(trace.user.display_name)}/traces/#{trace.id}"
assert_select item, "description"
# assert_select item, "dc:creator", trace.user.display_name
assert_select item, "pubDate", trace.timestamp.rfc822
require "test_helper"
-class UserBlocksControllerTest < ActionController::TestCase
+class UserBlocksControllerTest < ActionDispatch::IntegrationTest
##
# test all routes which lead to this controller
def test_routes
expired_block = create(:user_block, :expired)
revoked_block = create(:user_block, :revoked)
- get :index
+ get user_blocks_path
assert_response :success
assert_select "table#block_list", :count => 1 do
assert_select "tr", 4
def test_index_paged
create_list(:user_block, 50)
- get :index
+ get user_blocks_path
assert_response :success
assert_select "table#block_list", :count => 1 do
assert_select "tr", :count => 21
end
- get :index, :params => { :page => 2 }
+ get user_blocks_path(:page => 2)
assert_response :success
assert_select "table#block_list", :count => 1 do
assert_select "tr", :count => 21
expired_block = create(:user_block, :expired)
revoked_block = create(:user_block, :revoked)
- # Viewing a block should fail when no ID is given
- assert_raise ActionController::UrlGenerationError do
- get :show
- end
-
# Viewing a block should fail when a bogus ID is given
- get :show, :params => { :id => 99999 }
+ get user_block_path(:id => 99999)
assert_response :not_found
assert_template "not_found"
assert_select "p", "Sorry, the user block with ID 99999 could not be found."
# Viewing an expired block should work
- get :show, :params => { :id => expired_block.id }
+ get user_block_path(:id => expired_block)
assert_response :success
# Viewing a revoked block should work
- get :show, :params => { :id => revoked_block.id }
+ get user_block_path(:id => revoked_block)
assert_response :success
# Viewing an active block should work, but shouldn't mark it as seen
- get :show, :params => { :id => active_block.id }
+ get user_block_path(:id => active_block)
assert_response :success
assert UserBlock.find(active_block.id).needs_view
# Login as the blocked user
- session[:user] = active_block.user.id
+ session_for(active_block.user)
# Now viewing it should mark it as seen
- get :show, :params => { :id => active_block.id }
+ get user_block_path(:id => active_block)
assert_response :success
assert_not UserBlock.find(active_block.id).needs_view
end
target_user = create(:user)
# Check that the block creation page requires us to login
- get :new, :params => { :display_name => target_user.display_name }
+ get new_user_block_path(:display_name => target_user.display_name)
assert_redirected_to login_path(:referer => new_user_block_path(:display_name => target_user.display_name))
# Login as a normal user
- session[:user] = create(:user).id
+ session_for(create(:user))
# Check that normal users can't load the block creation page
- get :new, :params => { :display_name => target_user.display_name }
+ get new_user_block_path(:display_name => target_user.display_name)
assert_response :redirect
assert_redirected_to :controller => "errors", :action => "forbidden"
# Login as a moderator
- session[:user] = create(:moderator_user).id
+ session_for(create(:moderator_user))
# Check that the block creation page loads for moderators
- get :new, :params => { :display_name => target_user.display_name }
+ get new_user_block_path(:display_name => target_user.display_name)
assert_response :success
assert_select "form#new_user_block", :count => 1 do
assert_select "textarea#user_block_reason", :count => 1
assert_select "input[type='submit'][value='Create block']", :count => 1
end
- # We should get an error if no user is specified
- get :new
- assert_response :not_found
- assert_template "users/no_such_user"
- assert_select "h1", "The user does not exist"
-
# We should get an error if the user doesn't exist
- get :new, :params => { :display_name => "non_existent_user" }
+ get new_user_block_path(:display_name => "non_existent_user")
assert_response :not_found
assert_template "users/no_such_user"
assert_select "h1", "The user non_existent_user does not exist"
active_block = create(:user_block)
# Check that the block edit page requires us to login
- get :edit, :params => { :id => active_block.id }
+ get edit_user_block_path(:id => active_block)
assert_redirected_to login_path(:referer => edit_user_block_path(active_block))
# Login as a normal user
- session[:user] = create(:user).id
+ session_for(create(:user))
# Check that normal users can't load the block edit page
- get :edit, :params => { :id => active_block.id }
+ get edit_user_block_path(:id => active_block)
assert_response :redirect
assert_redirected_to :controller => "errors", :action => "forbidden"
# Login as a moderator
- session[:user] = create(:moderator_user).id
+ session_for(create(:moderator_user))
# Check that the block edit page loads for moderators
- get :edit, :params => { :id => active_block.id }
+ get edit_user_block_path(:id => active_block)
assert_response :success
assert_select "form#edit_user_block_#{active_block.id}", :count => 1 do
assert_select "textarea#user_block_reason", :count => 1
assert_select "input[type='submit'][value='Update block']", :count => 1
end
- # We should get an error if no user is specified
- assert_raise ActionController::UrlGenerationError do
- get :edit
- end
-
# We should get an error if the user doesn't exist
- get :edit, :params => { :id => 99999 }
+ get edit_user_block_path(:id => 99999)
assert_response :not_found
assert_template "not_found"
assert_select "p", "Sorry, the user block with ID 99999 could not be found."
moderator_user = create(:moderator_user)
# Not logged in yet, so creating a block should fail
- post :create
+ post user_blocks_path
assert_response :forbidden
# Login as a normal user
- session[:user] = create(:user).id
+ session_for(create(:user))
# Check that normal users can't create blocks
- post :create
+ post user_blocks_path
assert_response :redirect
assert_redirected_to :controller => "errors", :action => "forbidden"
# Login as a moderator
- session[:user] = moderator_user.id
+ session_for(moderator_user)
# A bogus block period should result in an error
assert_no_difference "UserBlock.count" do
- post :create,
- :params => { :display_name => target_user.display_name,
- :user_block_period => "99" }
+ post user_blocks_path(:display_name => target_user.display_name,
+ :user_block_period => "99")
end
assert_redirected_to new_user_block_path(:display_name => target_user.display_name)
assert_equal "The blocking period must be one of the values selectable in the drop-down list.", flash[:error]
# Check that creating a block works
assert_difference "UserBlock.count", 1 do
- post :create,
- :params => { :display_name => target_user.display_name,
- :user_block_period => "12",
- :user_block => { :needs_view => false, :reason => "Vandalism" } }
+ post user_blocks_path(:display_name => target_user.display_name,
+ :user_block_period => "12",
+ :user_block => { :needs_view => false, :reason => "Vandalism" })
end
id = UserBlock.order(:id).ids.last
assert_redirected_to user_block_path(:id => id)
assert_equal moderator_user.id, b.creator_id
# We should get an error if no user is specified
- post :create
+ post user_blocks_path
assert_response :not_found
assert_template "users/no_such_user"
assert_select "h1", "The user does not exist"
# We should get an error if the user doesn't exist
- post :create, :params => { :display_name => "non_existent_user" }
+ post user_blocks_path(:display_name => "non_existent_user")
assert_response :not_found
assert_template "users/no_such_user"
assert_select "h1", "The user non_existent_user does not exist"
active_block = create(:user_block, :creator => moderator_user)
# Not logged in yet, so updating a block should fail
- put :update, :params => { :id => active_block.id }
+ put user_block_path(:id => active_block)
assert_response :forbidden
# Login as a normal user
- session[:user] = create(:user).id
+ session_for(create(:user))
# Check that normal users can't update blocks
- put :update, :params => { :id => active_block.id }
+ put user_block_path(:id => active_block)
assert_response :redirect
assert_redirected_to :controller => "errors", :action => "forbidden"
# Login as the wrong moderator
- session[:user] = second_moderator_user.id
+ session_for(second_moderator_user)
# Check that only the person who created a block can update it
assert_no_difference "UserBlock.count" do
- put :update,
- :params => { :id => active_block.id,
- :user_block_period => "12",
- :user_block => { :needs_view => true, :reason => "Vandalism" } }
+ put user_block_path(:id => active_block,
+ :user_block_period => "12",
+ :user_block => { :needs_view => true, :reason => "Vandalism" })
end
assert_redirected_to edit_user_block_path(active_block)
assert_equal "Only the moderator who created this block can edit it.", flash[:error]
# Login as the correct moderator
- session[:user] = moderator_user.id
+ session_for(moderator_user)
# A bogus block period should result in an error
assert_no_difference "UserBlock.count" do
- put :update,
- :params => { :id => active_block.id,
- :user_block_period => "99" }
+ put user_block_path(:id => active_block, :user_block_period => "99")
end
assert_redirected_to edit_user_block_path(active_block)
assert_equal "The blocking period must be one of the values selectable in the drop-down list.", flash[:error]
# Check that updating a block works
assert_no_difference "UserBlock.count" do
- put :update,
- :params => { :id => active_block.id,
- :user_block_period => "12",
- :user_block => { :needs_view => true, :reason => "Vandalism" } }
+ put user_block_path(:id => active_block,
+ :user_block_period => "12",
+ :user_block => { :needs_view => true, :reason => "Vandalism" })
end
assert_redirected_to user_block_path(active_block)
assert_equal "Block updated.", flash[:notice]
assert b.needs_view
assert_equal "Vandalism", b.reason
- # We should get an error if no block ID is specified
- assert_raise ActionController::UrlGenerationError do
- put :update
- end
-
# We should get an error if the block doesn't exist
- put :update, :params => { :id => 99999 }
+ put user_block_path(:id => 99999)
assert_response :not_found
assert_template "not_found"
assert_select "p", "Sorry, the user block with ID 99999 could not be found."
active_block = create(:user_block)
# Check that the block revoke page requires us to login
- get :revoke, :params => { :id => active_block.id }
- assert_redirected_to login_path(:referer => revoke_user_block_path(:id => active_block.id))
+ get revoke_user_block_path(:id => active_block)
+ assert_redirected_to login_path(:referer => revoke_user_block_path(:id => active_block))
# Login as a normal user
- session[:user] = create(:user).id
+ session_for(create(:user))
# Check that normal users can't load the block revoke page
- get :revoke, :params => { :id => active_block.id }
+ get revoke_user_block_path(:id => active_block)
assert_response :redirect
assert_redirected_to :controller => "errors", :action => "forbidden"
# Login as a moderator
- session[:user] = create(:moderator_user).id
+ session_for(create(:moderator_user))
# Check that the block revoke page loads for moderators
- get :revoke, :params => { :id => active_block.id }
+ get revoke_user_block_path(:id => active_block)
assert_response :success
assert_template "revoke"
assert_select "form", :count => 1 do
end
# Check that revoking a block works
- post :revoke, :params => { :id => active_block.id, :confirm => true }
+ post revoke_user_block_path(:id => active_block, :confirm => true)
assert_redirected_to user_block_path(active_block)
b = UserBlock.find(active_block.id)
assert_in_delta Time.now, b.ends_at, 1
- # We should get an error if no block ID is specified
- assert_raise ActionController::UrlGenerationError do
- get :revoke
- end
-
# We should get an error if the block doesn't exist
- get :revoke, :params => { :id => 99999 }
+ get revoke_user_block_path(:id => 99999)
assert_response :not_found
assert_template "not_found"
assert_select "p", "Sorry, the user block with ID 99999 could not be found."
revoked_block = create(:user_block, :revoked, :user => blocked_user)
expired_block = create(:user_block, :expired, :user => unblocked_user)
- # Asking for a list of blocks with no user name should fail
- assert_raise ActionController::UrlGenerationError do
- get :blocks_on
- end
-
# Asking for a list of blocks with a bogus user name should fail
- get :blocks_on, :params => { :display_name => "non_existent_user" }
+ get user_blocks_on_path(:display_name => "non_existent_user")
assert_response :not_found
assert_template "users/no_such_user"
assert_select "h1", "The user non_existent_user does not exist"
# Check the list of blocks for a user that has never been blocked
- get :blocks_on, :params => { :display_name => normal_user.display_name }
+ get user_blocks_on_path(:display_name => normal_user.display_name)
assert_response :success
assert_select "table#block_list", false
assert_select "p", "#{normal_user.display_name} has not been blocked yet."
# Check the list of blocks for a user that is currently blocked
- get :blocks_on, :params => { :display_name => blocked_user.display_name }
+ get user_blocks_on_path(:display_name => blocked_user.display_name)
assert_response :success
assert_select "table#block_list", :count => 1 do
assert_select "tr", 3
end
# Check the list of blocks for a user that has previously been blocked
- get :blocks_on, :params => { :display_name => unblocked_user.display_name }
+ get user_blocks_on_path(:display_name => unblocked_user.display_name)
assert_response :success
assert_select "table#block_list", :count => 1 do
assert_select "tr", 2
user = create(:user)
create_list(:user_block, 50, :user => user)
- get :blocks_on, :params => { :display_name => user.display_name }
+ get user_blocks_on_path(:display_name => user.display_name)
assert_response :success
assert_select "table#block_list", :count => 1 do
assert_select "tr", :count => 21
end
- get :blocks_on, :params => { :display_name => user.display_name, :page => 2 }
+ get user_blocks_on_path(:display_name => user.display_name, :page => 2)
assert_response :success
assert_select "table#block_list", :count => 1 do
assert_select "tr", :count => 21
expired_block = create(:user_block, :expired, :creator => second_moderator_user)
revoked_block = create(:user_block, :revoked, :creator => second_moderator_user)
- # Asking for a list of blocks with no user name should fail
- assert_raise ActionController::UrlGenerationError do
- get :blocks_by
- end
-
# Asking for a list of blocks with a bogus user name should fail
- get :blocks_by, :params => { :display_name => "non_existent_user" }
+ get user_blocks_by_path(:display_name => "non_existent_user")
assert_response :not_found
assert_template "users/no_such_user"
assert_select "h1", "The user non_existent_user does not exist"
# Check the list of blocks given by one moderator
- get :blocks_by, :params => { :display_name => moderator_user.display_name }
+ get user_blocks_by_path(:display_name => moderator_user.display_name)
assert_response :success
assert_select "table#block_list", :count => 1 do
assert_select "tr", 2
end
# Check the list of blocks given by a different moderator
- get :blocks_by, :params => { :display_name => second_moderator_user.display_name }
+ get user_blocks_by_path(:display_name => second_moderator_user.display_name)
assert_response :success
assert_select "table#block_list", :count => 1 do
assert_select "tr", 3
end
# Check the list of blocks (not) given by a normal user
- get :blocks_by, :params => { :display_name => normal_user.display_name }
+ get user_blocks_by_path(:display_name => normal_user.display_name)
assert_response :success
assert_select "table#block_list", false
assert_select "p", "#{normal_user.display_name} has not made any blocks yet."
user = create(:moderator_user)
create_list(:user_block, 50, :creator => user)
- get :blocks_by, :params => { :display_name => user.display_name }
+ get user_blocks_by_path(:display_name => user.display_name)
assert_response :success
assert_select "table#block_list", :count => 1 do
assert_select "tr", :count => 21
end
- get :blocks_by, :params => { :display_name => user.display_name, :page => 2 }
+ get user_blocks_by_path(:display_name => user.display_name, :page => 2)
assert_response :success
assert_select "table#block_list", :count => 1 do
assert_select "tr", :count => 21
require "test_helper"
-class UserRolesControllerTest < ActionController::TestCase
+class UserRolesControllerTest < ActionDispatch::IntegrationTest
##
# test all routes which lead to this controller
def test_routes
super_user = create(:super_user)
# Granting should fail when not logged in
- post :grant, :params => { :display_name => target_user.display_name, :role => "moderator" }
+ post grant_role_path(:display_name => target_user.display_name, :role => "moderator")
assert_response :forbidden
# Login as an unprivileged user
- session[:user] = normal_user.id
+ session_for(normal_user)
# Granting should still fail
- post :grant, :params => { :display_name => target_user.display_name, :role => "moderator" }
+ post grant_role_path(:display_name => target_user.display_name, :role => "moderator")
assert_redirected_to :controller => :errors, :action => :forbidden
# Login as an administrator
- session[:user] = administrator_user.id
+ session_for(administrator_user)
UserRole::ALL_ROLES.each do |role|
# Granting a role to a non-existent user should fail
assert_difference "UserRole.count", 0 do
- post :grant, :params => { :display_name => "non_existent_user", :role => role }
+ post grant_role_path(:display_name => "non_existent_user", :role => role)
end
assert_response :not_found
assert_template "users/no_such_user"
# Granting a role to a user that already has it should fail
assert_no_difference "UserRole.count" do
- post :grant, :params => { :display_name => super_user.display_name, :role => role }
+ post grant_role_path(:display_name => super_user.display_name, :role => role)
end
assert_redirected_to user_path(super_user)
assert_equal "The user already has role #{role}.", flash[:error]
# Granting a role to a user that doesn't have it should work...
assert_difference "UserRole.count", 1 do
- post :grant, :params => { :display_name => target_user.display_name, :role => role }
+ post grant_role_path(:display_name => target_user.display_name, :role => role)
end
assert_redirected_to user_path(target_user)
# ...but trying a second time should fail
assert_no_difference "UserRole.count" do
- post :grant, :params => { :display_name => target_user.display_name, :role => role }
+ post grant_role_path(:display_name => target_user.display_name, :role => role)
end
assert_redirected_to user_path(target_user)
assert_equal "The user already has role #{role}.", flash[:error]
# Granting a non-existent role should fail
assert_difference "UserRole.count", 0 do
- post :grant, :params => { :display_name => target_user.display_name, :role => "no_such_role" }
+ post grant_role_path(:display_name => target_user.display_name, :role => "no_such_role")
end
assert_redirected_to user_path(target_user)
assert_equal "The string `no_such_role' is not a valid role.", flash[:error]
super_user = create(:super_user)
# Revoking should fail when not logged in
- post :revoke, :params => { :display_name => target_user.display_name, :role => "moderator" }
+ post revoke_role_path(:display_name => target_user.display_name, :role => "moderator")
assert_response :forbidden
# Login as an unprivileged user
- session[:user] = normal_user.id
+ session_for(normal_user)
# Revoking should still fail
- post :revoke, :params => { :display_name => target_user.display_name, :role => "moderator" }
+ post revoke_role_path(:display_name => target_user.display_name, :role => "moderator")
assert_redirected_to :controller => :errors, :action => :forbidden
# Login as an administrator
- session[:user] = administrator_user.id
+ session_for(administrator_user)
UserRole::ALL_ROLES.each do |role|
# Removing a role from a non-existent user should fail
assert_difference "UserRole.count", 0 do
- post :revoke, :params => { :display_name => "non_existent_user", :role => role }
+ post revoke_role_path(:display_name => "non_existent_user", :role => role)
end
assert_response :not_found
assert_template "users/no_such_user"
# Removing a role from a user that doesn't have it should fail
assert_no_difference "UserRole.count" do
- post :revoke, :params => { :display_name => target_user.display_name, :role => role }
+ post revoke_role_path(:display_name => target_user.display_name, :role => role)
end
assert_redirected_to user_path(target_user)
assert_equal "The user does not have role #{role}.", flash[:error]
# Removing a role from a user that has it should work...
assert_difference "UserRole.count", -1 do
- post :revoke, :params => { :display_name => super_user.display_name, :role => role }
+ post revoke_role_path(:display_name => super_user.display_name, :role => role)
end
assert_redirected_to user_path(super_user)
# ...but trying a second time should fail
assert_no_difference "UserRole.count" do
- post :revoke, :params => { :display_name => super_user.display_name, :role => role }
+ post revoke_role_path(:display_name => super_user.display_name, :role => role)
end
assert_redirected_to user_path(super_user)
assert_equal "The user does not have role #{role}.", flash[:error]
# Revoking a non-existent role should fail
assert_difference "UserRole.count", 0 do
- post :revoke, :params => { :display_name => target_user.display_name, :role => "no_such_role" }
+ post revoke_role_path(:display_name => target_user.display_name, :role => "no_such_role")
end
assert_redirected_to user_path(target_user)
assert_equal "The string `no_such_role' is not a valid role.", flash[:error]
# Revoking administrator role from current user should fail
- post :revoke, :params => { :display_name => administrator_user.display_name, :role => "administrator" }
+ post revoke_role_path(:display_name => administrator_user.display_name, :role => "administrator")
assert_redirected_to user_path(administrator_user)
assert_equal "Cannot revoke administrator role from current user.", flash[:error]
end
--- /dev/null
+FactoryBot.define do
+ factory :diary_entry_subscription do
+ end
+end