Fix styles for some API controllers

* Comments
* Likes
* Streams
This commit is contained in:
Frank Rousseau 2017-05-21 13:14:07 +02:00
parent fa53656b3b
commit 2be3e9eaf3
6 changed files with 11 additions and 10 deletions

View file

@ -1,7 +1,6 @@
module Api module Api
module V0 module V0
class CommentsController < Api::V0::BaseController class CommentsController < Api::V0::BaseController
before_action only: %i(create destroy) do before_action only: %i(create destroy) do
require_access_token %w(read write) require_access_token %w(read write)
end end

View file

@ -23,7 +23,7 @@ module Api
end end
def destroy 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) current_user.retract(@like)
render nothing: true, status: 204 render nothing: true, status: 204
end end

View file

@ -1,7 +1,6 @@
module Api module Api
module V0 module V0
class StreamsController < Api::V0::BaseController class StreamsController < Api::V0::BaseController
before_action do before_action do
require_access_token %w(read) require_access_token %w(read)
end end
@ -43,12 +42,11 @@ module Api
private private
def stream_responder(stream_klass=nil) def stream_responder(stream_klass=nil)
if stream_klass.present? if stream_klass.present?
@stream ||= stream_klass.new(current_user, max_time: max_time) @stream ||= stream_klass.new(current_user, max_time: max_time)
end 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 end
end end

View file

@ -25,7 +25,8 @@ class PostService
service = CommentService.new(post_id: post.id, user: user) service = CommentService.new(post_id: post.id, user: user)
@presenter = PostPresenter.new(post, user) @presenter = PostPresenter.new(post, user)
@presenter.as_json.tap do |post| @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
end end

View file

@ -18,7 +18,10 @@ describe Api::V0::PostsController do
context "comment too long" do context "comment too long" do
before 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 end
it "fails with appropriate error message" do it "fails with appropriate error message" do
@ -46,7 +49,7 @@ describe Api::V0::PostsController do
end end
it "fails to delete" do 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") expect(response.body).to eq("Post or comment not found")
end end
end end

View file

@ -16,7 +16,7 @@ describe Api::V0::LikesController do
end end
it "fails on random post id" do 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") expect(response.body).to eq("Post or like not found")
end end
end end
@ -33,7 +33,7 @@ describe Api::V0::LikesController do
end end
it "fails on random like id" do 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") expect(response.body).to eq("Post or like not found")
end end
end end