Skip to content

Commit

Permalink
allow editing the data and time of a post after it has been published
Browse files Browse the repository at this point in the history
  • Loading branch information
mawise committed Oct 16, 2024
1 parent 7405e25 commit 58e17ed
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
1 change: 1 addition & 0 deletions app/controllers/posts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def new
end

def edit
@show_date = true
@settings = SettingsController.get_setting
@post = Post.find(params[:id])
verify_can_modify_post(@post)
Expand Down
4 changes: 2 additions & 2 deletions app/views/posts/_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<hr>
<%= form_with model: @post, local: true do |form| %>
<%= form.date_field :date, :style => 'display:inline;', :value => @post.datetime.strftime("%Y-%m-%d"), type: (@settings.show_post_date ? :date : :hidden) %>
<%= form.time_field :time, :style => 'display:inline;', :value => @post.datetime.strftime("%H:%M"), type: (@settings.show_post_date ? :time : :hidden) %>
<%= form.date_field :date, :style => 'display:inline;', :value => @post.datetime.strftime("%Y-%m-%d"), type: (@show_date ? :date : :hidden) %>
<%= form.time_field :time, :style => 'display:inline;', :value => @post.datetime.strftime("%H:%M"), type: (@show_date ? :time : :hidden) %>
<%= form.text_area :content, :rows => 10, :dir => "auto", :style => 'display:block;width:100%;', :oninput => "doRender();", :value => @post.content %>
<%= form.file_field :pic, :accept => "image/*,.mp4,.mp3", :style => "display:inline;" %>
<%= form.submit :value => "Upload Selected Image", data: {disable_with: "Upload Selected Image"}, :style => "display:inline;" %>
Expand Down
29 changes: 29 additions & 0 deletions test/system/editing_posts_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,35 @@ class EditingPostsTest < ApplicationSystemTestCase
click_on "Save Post"
assert_text m3
click_on "Logout"
end

test "can_edit_post_date_but_not_visible_on_post_creation" do
log_in_with test_users[:jackson] #publisher
click_on "New Post Button"

## ensure we cannot edit the date and time of the post
assert_no_selector 'input[id="post_date"][type="date"]'
assert_no_selector 'input[id="post_time"][type="time"]'

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 "Edit"
## ensure we can edit the date and time of the post
assert_selector 'input[id="post_date"][type="date"]'
assert_selector 'input[id="post_time"][type="time"]'

## edit the date/time and see it persist
fill_in "post_date", with: "01022023"
fill_in "post_time", with: "0123p"
click_on "Save Post"
assert_text "January 02, 2023"
click_on "Edit"
assert_selector 'input[id="post_date"][type="date"][value="2023-01-02"]'
assert_selector 'input[id="post_time"][type="time"][value="13:23"]'

click_on "Logout"
end
end

0 comments on commit 58e17ed

Please sign in to comment.