# Make sure that you are redirected to the login page when you
# are not logged in
get new_diary_entry_path
- assert_response :redirect
assert_redirected_to login_path(:referer => "/diary/new")
end
: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
entry = DiaryEntry.order(:id).last
assert_equal user.id, entry.user_id
: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
entry = DiaryEntry.order(:id).last
assert_equal user.id, entry.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
entry = DiaryEntry.order(:id).last
assert_equal user.id, entry.user_id
# Follow the redirect
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_diary_entry_path(:display_name => entry.user.display_name, :id => entry)
- assert_response :redirect
+ get edit_diary_entry_path(entry.user, entry)
assert_redirected_to login_path(:referer => "/user/#{ERB::Util.u(entry.user.display_name)}/diary/#{entry.id}/edit")
session_for(other_user)
# Verify that you get redirected to show if you are not the user
# that created the entry
- get edit_diary_entry_path(:display_name => entry.user.display_name, :id => entry)
- assert_response :redirect
+ get edit_diary_entry_path(entry.user, entry)
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)
+ get edit_diary_entry_path(entry.user, :id => 9999)
assert_response :not_found
assert_select "div.content-heading", :count => 1 do
assert_select "h1", :text => "No entry with the id: 9999", :count => 1
# 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_diary_entry_path(:display_name => entry.user.display_name, :id => entry)
+ get edit_diary_entry_path(entry.user, 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 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
+ put diary_entry_path(entry.user, entry, :commit => "save",
+ :diary_entry => { :title => new_title, :body => new_body, :latitude => new_latitude,
+ :longitude => new_longitude, :language_code => new_language_code })
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 diary_entry_path(:display_name => entry.user.display_name, :id => entry)
+ get diary_entry_path(entry.user, entry)
assert_response :success
assert_template "show"
assert_select "title", :text => /Users' Diaries | /, :count => 1
# and when not logged in as the user who wrote the entry
session_for(create(:user))
- get diary_entry_path(:display_name => entry.user.display_name, :id => entry)
+ get diary_entry_path(entry.user, entry)
assert_response :success
assert_template "show"
assert_select "title", :text => /Users' Diaries | /, :count => 1
user = create(:user)
diary_entry = create(:diary_entry, :language_code => "en", :user => user)
session_for(user)
- get edit_diary_entry_path(:display_name => user.display_name, :id => diary_entry)
+ get edit_diary_entry_path(user, diary_entry)
assert_response :success
assert_select "span[class=translation_missing]", false, "Missing translation in edit diary entry"
end
create(:diary_entry_subscription, :diary_entry => entry, :user => user)
# Make sure that you are denied when you are not logged in
- post comment_diary_entry_path(:display_name => entry.user.display_name, :id => entry)
+ post comment_diary_entry_path(entry.user, entry)
assert_response :forbidden
session_for(other_user)
# Verify that you get a not found error, when you pass a bogus id
- post comment_diary_entry_path(:display_name => entry.user.display_name, :id => 9999)
+ post comment_diary_entry_path(entry.user, :id => 9999)
assert_response :not_found
assert_select "div.content-heading", :count => 1 do
assert_select "h1", :text => "No entry with the id: 9999", :count => 1
assert_no_difference "DiaryComment.count" do
assert_no_difference "entry.subscribers.count" do
perform_enqueued_jobs do
- post comment_diary_entry_path(:display_name => entry.user.display_name, :id => entry, :diary_comment => { :body => "" })
+ post comment_diary_entry_path(entry.user, 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_diary_entry_path(:display_name => entry.user.display_name, :id => entry, :diary_comment => { :body => "New comment" })
+ post comment_diary_entry_path(entry.user, entry, :diary_comment => { :body => "New comment" })
end
end
end
end
- assert_response :redirect
assert_redirected_to :action => :show, :display_name => entry.user.display_name, :id => entry.id
email = ActionMailer::Base.deliveries.first
assert_equal [user.email], email.to
assert_equal "New comment", comment.body
# Now show the diary entry, and check the new comment is present
- get diary_entry_path(:display_name => entry.user.display_name, :id => entry)
+ get diary_entry_path(entry.user, entry)
assert_response :success
assert_select ".diary-comment", :count => 1 do
assert_select "#comment#{comment.id}", :count => 1 do
assert_difference "ActionMailer::Base.deliveries.size", 1 do
assert_difference "DiaryComment.count", 1 do
perform_enqueued_jobs do
- post comment_diary_entry_path(:display_name => entry.user.display_name, :id => entry, :diary_comment => { :body => spammy_text })
+ post comment_diary_entry_path(entry.user, entry, :diary_comment => { :body => spammy_text })
end
end
end
- assert_response :redirect
assert_redirected_to :action => :show, :display_name => entry.user.display_name, :id => entry.id
email = ActionMailer::Base.deliveries.first
assert_equal [user.email], email.to
# Follow the redirect
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 diary_entry_path(:display_name => entry.user.display_name, :id => entry)
+ get diary_entry_path(entry.user, entry)
assert_response :success
assert_select ".diary-comment", :count => 0
end
# Try a list of diary entries for your friends when not logged in
get friends_diary_entries_path
- assert_response :redirect
assert_redirected_to login_path(:referer => "/diary/friends")
# Try a list of diary entries for your friends when logged in
# Try a list of diary entries for nearby users when not logged in
get nearby_diary_entries_path
- assert_response :redirect
assert_redirected_to login_path(:referer => "/diary/nearby")
# Try a list of diary entries for nearby users when logged in
# Try a normal entry that should work
diary_entry = create(:diary_entry, :user => user)
- get diary_entry_path(:display_name => user.display_name, :id => diary_entry)
+ get diary_entry_path(user, diary_entry)
assert_response :success
assert_template :show
# Try a deleted entry
diary_entry_deleted = create(:diary_entry, :user => user, :visible => false)
- get diary_entry_path(:display_name => user.display_name, :id => diary_entry_deleted)
+ get diary_entry_path(user, diary_entry_deleted)
assert_response :not_found
# Try an entry by a suspended user
diary_entry_suspended_user = create(:diary_entry, :user => suspended_user)
- get diary_entry_path(:display_name => suspended_user.display_name, :id => diary_entry_suspended_user)
+ get diary_entry_path(suspended_user, diary_entry_suspended_user)
assert_response :not_found
# Try an entry by a deleted user
diary_entry_deleted_user = create(:diary_entry, :user => deleted_user)
- get diary_entry_path(:display_name => deleted_user.display_name, :id => diary_entry_deleted_user)
+ get diary_entry_path(deleted_user, diary_entry_deleted_user)
assert_response :not_found
# Now try as a moderator
session_for(create(:moderator_user))
- get diary_entry_path(:display_name => user.display_name, :id => diary_entry_deleted)
+ get diary_entry_path(user, diary_entry_deleted)
assert_response :success
assert_template :show
# Finally try as an administrator
session_for(create(:administrator_user))
- get diary_entry_path(:display_name => user.display_name, :id => diary_entry_deleted)
+ get diary_entry_path(user, diary_entry_deleted)
assert_response :success
assert_template :show
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 diary_entry_path(:display_name => user.display_name, :id => diary_entry)
+ get diary_entry_path(user, 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_diary_entry_path(:display_name => user.display_name, :id => diary_entry)
+ post hide_diary_entry_path(user, diary_entry)
assert_response :forbidden
assert DiaryEntry.find(diary_entry.id).visible
# Now try as a normal user
session_for(user)
- post hide_diary_entry_path(:display_name => user.display_name, :id => diary_entry)
- assert_response :redirect
+ post hide_diary_entry_path(user, diary_entry)
assert_redirected_to :controller => :errors, :action => :forbidden
assert DiaryEntry.find(diary_entry.id).visible
# Now try as a moderator
session_for(create(:moderator_user))
- post hide_diary_entry_path(:display_name => user.display_name, :id => diary_entry)
- assert_response :redirect
+ post hide_diary_entry_path(user, diary_entry)
assert_redirected_to :action => :index, :display_name => user.display_name
assert_not DiaryEntry.find(diary_entry.id).visible
# Finally try as an administrator
session_for(create(:administrator_user))
- post hide_diary_entry_path(:display_name => user.display_name, :id => diary_entry)
- assert_response :redirect
+ post hide_diary_entry_path(user, diary_entry)
assert_redirected_to :action => :index, :display_name => user.display_name
assert_not DiaryEntry.find(diary_entry.id).visible
end
# Try without logging in
diary_entry = create(:diary_entry, :user => user, :visible => false)
- post unhide_diary_entry_path(:display_name => user.display_name, :id => diary_entry)
+ post unhide_diary_entry_path(user, diary_entry)
assert_response :forbidden
assert_not DiaryEntry.find(diary_entry.id).visible
# Now try as a normal user
session_for(user)
- post unhide_diary_entry_path(:display_name => user.display_name, :id => diary_entry)
- assert_response :redirect
+ post unhide_diary_entry_path(user, diary_entry)
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
+ post unhide_diary_entry_path(user, diary_entry)
assert_redirected_to :action => :index, :display_name => user.display_name
assert DiaryEntry.find(diary_entry.id).visible
# Finally try as an administrator
session_for(create(:administrator_user))
- post unhide_diary_entry_path(:display_name => user.display_name, :id => diary_entry)
- assert_response :redirect
+ post unhide_diary_entry_path(user, diary_entry)
assert_redirected_to :action => :index, :display_name => user.display_name
assert DiaryEntry.find(diary_entry.id).visible
end
diary_comment = create(:diary_comment, :diary_entry => diary_entry)
# Try without logging in
- post hide_diary_comment_path(:display_name => user.display_name, :id => diary_entry, :comment => diary_comment)
+ post hide_diary_comment_path(user, diary_entry, diary_comment)
assert_response :forbidden
assert DiaryComment.find(diary_comment.id).visible
# Now try as a normal user
session_for(user)
- post hide_diary_comment_path(:display_name => user.display_name, :id => diary_entry, :comment => diary_comment)
- assert_response :redirect
+ post hide_diary_comment_path(user, diary_entry, diary_comment)
assert_redirected_to :controller => :errors, :action => :forbidden
assert DiaryComment.find(diary_comment.id).visible
# Try as a moderator
session_for(create(:moderator_user))
- post hide_diary_comment_path(:display_name => user.display_name, :id => diary_entry, :comment => diary_comment)
- assert_response :redirect
+ post hide_diary_comment_path(user, diary_entry, diary_comment)
assert_redirected_to :action => :show, :display_name => user.display_name, :id => diary_entry.id
assert_not DiaryComment.find(diary_comment.id).visible
# Finally try as an administrator
session_for(create(:administrator_user))
- post hide_diary_comment_path(:display_name => user.display_name, :id => diary_entry, :comment => diary_comment)
- assert_response :redirect
+ post hide_diary_comment_path(user, diary_entry, diary_comment)
assert_redirected_to :action => :show, :display_name => user.display_name, :id => diary_entry.id
assert_not DiaryComment.find(diary_comment.id).visible
end
diary_comment = create(:diary_comment, :diary_entry => diary_entry, :visible => false)
# Try without logging in
- post unhide_diary_comment_path(:display_name => user.display_name, :id => diary_entry, :comment => diary_comment)
+ post unhide_diary_comment_path(user, diary_entry, diary_comment)
assert_response :forbidden
assert_not DiaryComment.find(diary_comment.id).visible
# Now try as a normal user
session_for(user)
- post unhide_diary_comment_path(:display_name => user.display_name, :id => diary_entry, :comment => diary_comment)
- assert_response :redirect
+ post unhide_diary_comment_path(user, diary_entry, diary_comment)
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
+ post unhide_diary_comment_path(user, diary_entry, diary_comment)
assert_redirected_to :action => :show, :display_name => user.display_name, :id => diary_entry.id
assert DiaryComment.find(diary_comment.id).visible
# Finally try as an administrator
session_for(create(:administrator_user))
- post unhide_diary_comment_path(:display_name => user.display_name, :id => diary_entry, :comment => diary_comment)
- assert_response :redirect
+ post unhide_diary_comment_path(user, diary_entry, diary_comment)
assert_redirected_to :action => :show, :display_name => user.display_name, :id => diary_entry.id
assert DiaryComment.find(diary_comment.id).visible
end
get diary_comments_path(:display_name => other_user.display_name)
assert_response :success
assert_template :comments
- assert_select "table.table-striped" do
- assert_select "tr", :count => 2 # header and one comment
+ assert_dom "a[href='#{user_path(other_user)}']", :text => other_user.display_name
+ assert_select "table.table-striped tbody" do
+ assert_select "tr", :count => 1
end
# Test a suspended user
user = create(:user)
other_user = create(:user)
diary_entry = create(:diary_entry, :user => user)
- path = diary_entry_subscribe_path(:id => diary_entry, :display_name => user.display_name)
+ path = diary_entry_subscribe_path(user, diary_entry)
get path
- assert_response :redirect
assert_redirected_to login_path(:referer => path)
session_for(other_user)
get path
assert_response :success
assert_dom ".content-body" do
- assert_dom "a[href='#{diary_entry_path(:id => diary_entry, :display_name => user.display_name)}']", :text => diary_entry.title
+ assert_dom "a[href='#{diary_entry_path(user, diary_entry)}']", :text => diary_entry.title
assert_dom "a[href='#{user_path(user)}']", :text => user.display_name
end
end
session_for(other_user)
assert_difference "diary_entry.subscribers.count", 1 do
- post diary_entry_subscribe_path(:id => diary_entry, :display_name => diary_entry.user.display_name)
+ post diary_entry_subscribe_path(user, diary_entry)
end
assert_response :redirect
end
# not signed in
assert_no_difference "diary_entry.subscribers.count" do
- post diary_entry_subscribe_path(:id => diary_entry, :display_name => diary_entry.user.display_name)
+ post diary_entry_subscribe_path(user, diary_entry)
end
assert_response :forbidden
session_for(other_user)
# bad diary id
- post diary_entry_subscribe_path(:id => 999111, :display_name => "username")
+ post diary_entry_subscribe_path("username", 999111)
assert_response :not_found
# trying to subscribe when already subscribed
- post diary_entry_subscribe_path(:id => diary_entry, :display_name => diary_entry.user.display_name)
+ post diary_entry_subscribe_path(user, diary_entry)
assert_no_difference "diary_entry.subscribers.count" do
- post diary_entry_subscribe_path(:id => diary_entry, :display_name => diary_entry.user.display_name)
+ post diary_entry_subscribe_path(user, diary_entry)
end
end
user = create(:user)
other_user = create(:user)
diary_entry = create(:diary_entry, :user => user)
- path = diary_entry_unsubscribe_path(:id => diary_entry, :display_name => user.display_name)
+ path = diary_entry_unsubscribe_path(user, diary_entry)
get path
- assert_response :redirect
assert_redirected_to login_path(:referer => path)
session_for(other_user)
get path
assert_response :success
assert_dom ".content-body" do
- assert_dom "a[href='#{diary_entry_path(:id => diary_entry, :display_name => user.display_name)}']", :text => diary_entry.title
+ assert_dom "a[href='#{diary_entry_path(user, diary_entry)}']", :text => diary_entry.title
assert_dom "a[href='#{user_path(user)}']", :text => user.display_name
end
end
session_for(other_user)
assert_difference "diary_entry.subscribers.count", -1 do
- post diary_entry_unsubscribe_path(:id => diary_entry, :display_name => diary_entry.user.display_name)
+ post diary_entry_unsubscribe_path(user, diary_entry)
end
assert_response :redirect
end
# not signed in
assert_no_difference "diary_entry.subscribers.count" do
- post diary_entry_unsubscribe_path(:id => diary_entry, :display_name => diary_entry.user.display_name)
+ post diary_entry_unsubscribe_path(user, diary_entry)
end
assert_response :forbidden
session_for(other_user)
# bad diary id
- post diary_entry_unsubscribe_path(:id => 999111, :display_name => "username")
+ post diary_entry_unsubscribe_path("username", 999111)
assert_response :not_found
# trying to unsubscribe when not subscribed
assert_no_difference "diary_entry.subscribers.count" do
- post diary_entry_unsubscribe_path(:id => diary_entry, :display_name => diary_entry.user.display_name)
+ post diary_entry_unsubscribe_path(user, diary_entry)
end
end