Skip to content

Commit

Permalink
Address review's feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
hmdros committed Sep 19, 2023
1 parent 49b4ed4 commit c9a7282
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 29 deletions.
7 changes: 2 additions & 5 deletions app/controllers/comments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ def edit
def create
@comment = current_user.comments.build(story: @story)
@comment.attributes = comment_params
@comment.user_id = current_user.id
saved = @comment.save
respond_to do |format|
format.html do
Expand All @@ -21,7 +20,6 @@ def create

redirect_to project_story_path(@comment.story.project_id, @comment.story_id)
end
format.js
end
end

Expand All @@ -37,15 +35,14 @@ def update
render :edit
end
end
format.js
end
end

def destroy
@comment.destroy
respond_to do |format|
format.html { redirect_to project_story_path(@comment.story.project_id, @comment.story_id), notice: "comment was successfully destroyed." }
format.json { head :no_content }
flash[:success] = "Comment deleted!"
format.html { redirect_to project_story_path(@comment.story.project_id, @comment.story_id) }
end
end

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/stories_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def bulk_destroy

def show
@estimate = Estimate.find_by(story: @story, user: current_user)
@comments = Comment.order("created_at").where(story: @story)
@comments = @story.comments.order(:created_at)
@comment = Comment.new
end

Expand Down
10 changes: 5 additions & 5 deletions app/views/comments/_comment.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div class="comment-card">
<p class="bold"><%= comment.user.name %>:</p>
<p><%= comment.body %></p>
<p><%= comment.created_at %><p>
<%= link_to "Edit Comment", edit_project_story_comment_path(@project.id, @story.id, comment.id), class: "link-blue" %> |
<%= link_to "Delete", project_story_comment_path(@project.id, @story.id, comment.id), method: :delete, data: { confirm: "Are you sure?", comment_id: @comment.id }, remote: true , title: "Delete" %>
<p class="bold"><%= comment.user.name %>: <%= markdown(comment.body) %> <%= comment.created_at %><p>
<% if current_user == comment.user %>
<%= link_to "Edit Comment", edit_project_story_comment_path(@project.id, @story.id, comment.id), class: "link-blue" %> |
<%= link_to "Delete", project_story_comment_path(@project.id, @story.id, comment.id), method: :delete, data: { confirm: "Are you sure?", comment_id: @comment.id }, remote: true , title: "Delete" %>
<% end %>
</div>
12 changes: 5 additions & 7 deletions app/views/comments/_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<div>
<%= form_with model: [@project, @story, @comment] do |form| %>
<%= form.text_area :body, rows: 6 %>
<%= form.submit class: "button green"%>
<%= link_to "Back", project_story_path(@comment.story.project_id, @comment.story_id), id:"back", class: "button" if action_name == "edit" %>
<% end %>
</div>
<%= form_with model: [project, story, comment] do |form| %>
<%= form.text_area :body, rows: 6 %>
<%= form.submit class: "button green"%>
<%= link_to "Back", project_story_path(comment.story.project_id, @comment.story_id), id:"back", class: "button" if action_name == "edit" %>
<% end %>
14 changes: 6 additions & 8 deletions app/views/stories/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,12 @@
<% end %>
</div>

<% if @comments %>
<div class="comments-section">
<h4>Comments</h4>
<% @comments.each do |comment| %>
<%= render "comments/comment", story: @story, project: @project, comment: comment %>
<% end %>
</div>
<% end %>
<div class="comments-section">
<h4>Comments</h4>
<% @comments.each do |comment| %>
<%= render "comments/comment", story: @story, project: @project, comment: comment %>
<% end %>
</div>

<div class="comment-form-container">
<p class="bold">Add a new comment</p>
Expand Down
6 changes: 3 additions & 3 deletions spec/controllers/comments_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
expect(response).to redirect_to project_story_path(project.id, story.id)
end

it "disallows destroying another users' estimate" do
it "disallows destroying another users' comment" do
user2 = FactoryBot.create(:user)
comment2 = FactoryBot.create(:comment, story: story, user: user2)

Expand All @@ -73,7 +73,7 @@
end

describe "#edit as other user" do
it "disallows editing another users' estimate" do
it "disallows editing another users' comment" do
user2 = FactoryBot.create(:user)
comment2 = FactoryBot.create(:comment, story: story, user: user2)

Expand All @@ -97,7 +97,7 @@
expect(comment.reload.body).to eq "test123"
end

it "disallows updating another users' estimate" do
it "disallows updating another users' comment" do
user2 = FactoryBot.create(:user)
comment2 = FactoryBot.create(:comment, story: story, user: user2)

Expand Down

0 comments on commit c9a7282

Please sign in to comment.