# 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 "/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 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