diff --git a/app/controllers/api/v0/comments_controller.rb b/app/controllers/api/v0/comments_controller.rb index 2e23dca9a..5474ee532 100644 --- a/app/controllers/api/v0/comments_controller.rb +++ b/app/controllers/api/v0/comments_controller.rb @@ -1,7 +1,6 @@ module Api module V0 class CommentsController < Api::V0::BaseController - before_action only: %i(create destroy) do require_access_token %w(read write) end diff --git a/app/controllers/api/v0/likes_controller.rb b/app/controllers/api/v0/likes_controller.rb index e23808238..834bf2c80 100644 --- a/app/controllers/api/v0/likes_controller.rb +++ b/app/controllers/api/v0/likes_controller.rb @@ -23,7 +23,7 @@ module Api end def destroy - @like = Like.find_by_id_and_author_id!(params[:id], current_user.person.id) + @like = Like.find_by!(id: params[:id], author_id: current_user.person.id) current_user.retract(@like) render nothing: true, status: 204 end diff --git a/app/controllers/api/v0/streams_controller.rb b/app/controllers/api/v0/streams_controller.rb index fed4b1acb..5430f8376 100644 --- a/app/controllers/api/v0/streams_controller.rb +++ b/app/controllers/api/v0/streams_controller.rb @@ -1,7 +1,6 @@ module Api module V0 class StreamsController < Api::V0::BaseController - before_action do require_access_token %w(read) end @@ -43,12 +42,11 @@ module Api private def stream_responder(stream_klass=nil) - if stream_klass.present? @stream ||= stream_klass.new(current_user, max_time: max_time) end - render json: @stream.stream_posts.map {|p| LastThreeCommentsDecorator.new(PostPresenter.new(p, current_user))} + render json: @stream.stream_posts.map {|p| LastThreeCommentsDecorator.new(PostPresenter.new(p, current_user)) } end end end diff --git a/app/services/post_service.rb b/app/services/post_service.rb index d0d203086..34b9635e6 100644 --- a/app/services/post_service.rb +++ b/app/services/post_service.rb @@ -25,7 +25,8 @@ class PostService service = CommentService.new(post_id: post.id, user: user) @presenter = PostPresenter.new(post, user) @presenter.as_json.tap do |post| - post[:interactions] = ({comments: service.comments}).merge!(post[:interactions]) + comments_hash = {comments: service.comments} + post[:interactions] = comments_hash.merge!(post[:interactions]) end end diff --git a/spec/integration/api/comments_controller_spec.rb b/spec/integration/api/comments_controller_spec.rb index ffd5f3fb9..bf42e64bf 100644 --- a/spec/integration/api/comments_controller_spec.rb +++ b/spec/integration/api/comments_controller_spec.rb @@ -18,7 +18,10 @@ describe Api::V0::PostsController do context "comment too long" do before do - post api_v0_post_comments_path(post_id: @status.id), text: "This is a long comment" * 99999, access_token: access_token + post( + api_v0_post_comments_path(post_id: @status.id), + text: "This is a long comment" * 99_999, access_token: access_token + ) end it "fails with appropriate error message" do @@ -46,7 +49,7 @@ describe Api::V0::PostsController do end it "fails to delete" do - delete api_v0_post_comment_path(id: 1234567), access_token: access_token + delete api_v0_post_comment_path(id: 1_234_567), access_token: access_token expect(response.body).to eq("Post or comment not found") end end diff --git a/spec/integration/api/likes_controller_spec.rb b/spec/integration/api/likes_controller_spec.rb index 772f38566..d5e8e360c 100644 --- a/spec/integration/api/likes_controller_spec.rb +++ b/spec/integration/api/likes_controller_spec.rb @@ -16,7 +16,7 @@ describe Api::V0::LikesController do end it "fails on random post id" do - post api_v0_post_likes_path(post_id: 9999999), access_token: access_token + post api_v0_post_likes_path(post_id: 99_999_999), access_token: access_token expect(response.body).to eq("Post or like not found") end end @@ -33,7 +33,7 @@ describe Api::V0::LikesController do end it "fails on random like id" do - delete api_v0_post_like_path(post_id: @status.id, id: 99999999), access_token: access_token + delete api_v0_post_like_path(post_id: @status.id, id: 99_999_999), access_token: access_token expect(response.body).to eq("Post or like not found") end end