Skip to content

Commit

Permalink
Ensure post owner doesn't change when a post is modified
Browse files Browse the repository at this point in the history
  • Loading branch information
mawise committed Jun 28, 2024
1 parent 9be3972 commit 62bd567
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/controllers/posts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ def post_from_form(params)
time = params[:post][:time]
post.datetime = DateTime.parse("#{date} #{time}")
post.content = params[:post][:content]
post.author = current_user
post.author = current_user unless !!post.author
post
end

Expand Down
58 changes: 58 additions & 0 deletions test/system/editing_posts_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
require "application_system_test_case"
require_relative 'systemtest_helpers.rb'

class EditingPostsTest < ApplicationSystemTestCase
test_users = {
washington: {email: "[email protected]", pass: "georgepass"}, # admin
jackson: {email: "[email protected]", pass: "jacksonpass"}, # publisher
lincoln: {email: "[email protected]", pass: "lincolnpass"} # subscriber
}

test "publisher and admin can edit their own posts" do
[test_users[:washington], test_users[:jackson]].each do |test_user|
log_in_with test_user
click_on "New Post Button"
m = "#{rand} I cannot tell a lie!"
fill_in "post_content", with: m
click_on "Save Post"
assert_text m # page previw shows post content
click_on "Home"
assert_text m # recent posts page also shows content of new post"
## Find edit button
## click edit button
## change post content
## validate new post content is saved
click_on "Logout"
end
end

test "admin editing a post doesn't change ownership of the post" do
log_in_with test_users[:jackson] #publisher
click_on "New Post Button"
m = "#{rand} I cannot tell a lie"
fill_in "post_content", with: m
click_on "Save Post"
assert_text m # page previw shows post content
post_url = current_url
click_on "Logout"

log_in_with test_users[:washington] #admin
visit post_url
click_on "Edit"
m2 = "#{rand} what a lie"
fill_in "post_content", with: m2
click_on "Save Post"
assert_text m2
click_on "Logout"

log_in_with test_users[:jackson] #publisher
visit post_url
click_on "Edit"
m3 = "#{rand} no lies here"
fill_in "post_content", with: m3
click_on "Save Post"
assert_text m3
click_on "Logout"

end
end

0 comments on commit 62bd567

Please sign in to comment.