diff --git a/.codeclimate.yml b/.codeclimate.yml index 8f4d9228f..96e3fcad5 100644 --- a/.codeclimate.yml +++ b/.codeclimate.yml @@ -2,7 +2,7 @@ version: "2" plugins: rubocop: enabled: true - channel: rubocop-0-67 + channel: rubocop-0-71 brakeman: enabled: true eslint: diff --git a/.rubocop.yml b/.rubocop.yml index e3eee16cb..7f6fc778f 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -2,6 +2,7 @@ inherit_from: .rubocop_todo.yml require: - rubocop-performance + - rubocop-rails - rubocop-rspec # our custom config diff --git a/Gemfile b/Gemfile index 6fb9e35db..27c17f98b 100644 --- a/Gemfile +++ b/Gemfile @@ -132,6 +132,7 @@ group :development, :test do gem "rspec-rails", "~> 3.8" # rspec-rails is a testing framework for Rails 3+ gem "rubocop", "~> 0.71", require: false # Automatic Ruby code style checking tool gem "rubocop-performance", "~> 1.0", require: false # A collection of RuboCop cops to check for performance optimizations in Ruby code + gem "rubocop-rails", "~> 2.0", require: false # Automatic Rails code style checking tool gem "rubocop-rspec", "~> 1.33", require: false # Code style checking for RSpec files gem "spring", "~> 2.0" # Preloads your application so things like console, rake and tests run faster gem "spring-commands-rspec", "~> 1.0" # rspec command for spring diff --git a/Gemfile.lock b/Gemfile.lock index 918abf1f8..db613026f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -649,6 +649,9 @@ GEM unicode-display_width (>= 1.4.0, < 1.7) rubocop-performance (1.3.0) rubocop (>= 0.68.0) + rubocop-rails (2.0.0) + rack (>= 2.0) + rubocop (>= 0.70.0) rubocop-rspec (1.33.0) rubocop (>= 0.60.0) ruby-prof (0.17.0) @@ -924,6 +927,7 @@ DEPENDENCIES rspec-retry (~> 0.6) rubocop (~> 0.71) rubocop-performance (~> 1.0) + rubocop-rails (~> 2.0) rubocop-rspec (~> 1.33) ruby-prof (~> 0.17) rubyzip (~> 1.2) diff --git a/app/controllers/api/v0/reactions_controller.rb b/app/controllers/api/v0/reactions_controller.rb index 8cade8705..dd33a8e54 100644 --- a/app/controllers/api/v0/reactions_controller.rb +++ b/app/controllers/api/v0/reactions_controller.rb @@ -5,7 +5,7 @@ module Api def create @user = valid_user unless @user - render json: { message: "invalid_user" }, status: 422 + render json: { message: "invalid_user" }, status: :unprocessable_entity return end Rails.cache.delete "count_for_reactable-#{params[:reactable_type]}-#{params[:reactable_id]}" diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 2d40358cc..5411aa1ad 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -27,7 +27,7 @@ class ApplicationController < ActionController::Base respond_to do |format| format.html { redirect_to "/enter" } - format.json { render json: { error: "Please sign in" }, status: 401 } + format.json { render json: { error: "Please sign in" }, status: :unauthorized } end end diff --git a/app/controllers/chat_channel_memberships_controller.rb b/app/controllers/chat_channel_memberships_controller.rb index bc5750187..f8e0aa10d 100644 --- a/app/controllers/chat_channel_memberships_controller.rb +++ b/app/controllers/chat_channel_memberships_controller.rb @@ -47,7 +47,7 @@ class ChatChannelMembershipsController < ApplicationController @chat_channel_membership.remove_from_index! @chat_channel_membership.chat_channel.index! @chat_channels_memberships = [] - render json: { result: "left channel" }, status: 201 + render json: { result: "left channel" }, status: :created end def permitted_params diff --git a/app/controllers/chat_channels_controller.rb b/app/controllers/chat_channels_controller.rb index f4917f220..1acfed66e 100644 --- a/app/controllers/chat_channels_controller.rb +++ b/app/controllers/chat_channels_controller.rb @@ -26,7 +26,7 @@ class ChatChannelsController < ApplicationController if @chat_channel.valid? render json: { status: "success", chat_channel: @chat_channel.to_json(only: %i[channel_name slug]) }, - status: 200 + status: :ok else render json: { errors: @chat_channel.errors.full_messages } end @@ -39,7 +39,7 @@ class ChatChannelsController < ApplicationController if @chat_channel.valid? render json: { status: "success", chat_channel: @chat_channel.to_json(only: %i[channel_name slug]) }, - status: 200 + status: :ok else render json: { errors: @chat_channel.errors.full_messages } end @@ -52,7 +52,7 @@ class ChatChannelsController < ApplicationController membership.update(last_opened_at: 1.second.from_now, has_unopened_messages: false) @chat_channel.index! membership.index! - render json: { status: "success", channel: params[:id] }, status: 200 + render json: { status: "success", channel: params[:id] }, status: :ok end def moderate @@ -68,29 +68,29 @@ class ChatChannelsController < ApplicationController Pusher.trigger(@chat_channel.pusher_channels, "user-banned", { userId: banned_user.id }.to_json) - render json: { status: "success", message: "banned!" }, status: 200 + render json: { status: "success", message: "banned!" }, status: :ok else - render json: { status: "error", message: "username not found" }, status: 400 + render json: { status: "error", message: "username not found" }, status: :bad_request end when "/unban" banned_user = User.find_by(username: command[1]) if banned_user banned_user.remove_role :banned - render json: { status: "success", message: "unbanned!" }, status: 200 + render json: { status: "success", message: "unbanned!" }, status: :ok else - render json: { status: "error", message: "username not found" }, status: 400 + render json: { status: "error", message: "username not found" }, status: :bad_request end when "/clearchannel" @chat_channel.clear_channel - render json: { status: "success", message: "cleared!" }, status: 200 + render json: { status: "success", message: "cleared!" }, status: :ok else - render json: { status: "error", message: "invalid command" }, status: 400 + render json: { status: "error", message: "invalid command" }, status: :bad_request end end def create_chat chat_recipient = User.find(params[:user_id]) - valid_listing = ClassifiedListing.where({ user_id: params[:user_id], contact_via_connect: true }).limit(1) + valid_listing = ClassifiedListing.where(user_id: params[:user_id], contact_via_connect: true).limit(1) authorize ChatChannel if chat_recipient.inbox_type == "open" || valid_listing.length == 1 chat = ChatChannel.create_with_users([current_user, chat_recipient], "direct") @@ -101,9 +101,9 @@ class ChatChannelsController < ApplicationController user: current_user, ) chat.messages.append(message) - render json: { status: "success", message: "chat channel created!" }, status: 200 + render json: { status: "success", message: "chat channel created!" }, status: :ok else - render json: { status: "error", message: "not allowed!" }, status: 400 + render json: { status: "error", message: "not allowed!" }, status: :bad_request end end @@ -113,7 +113,7 @@ class ChatChannelsController < ApplicationController chat_channel.status = "blocked" chat_channel.save chat_channel.chat_channel_memberships.map(&:remove_from_index!) - render json: { status: "success", message: "chat channel blocked" }, status: 200 + render json: { status: "success", message: "chat channel blocked" }, status: :ok end private diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index 2f38cf72e..76b51f7d6 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -143,7 +143,7 @@ class CommentsController < ApplicationController processed_html = "

😔 There was a error in your markdown


#{e}

" end respond_to do |format| - format.json { render json: { processed_html: processed_html }, status: 200 } + format.json { render json: { processed_html: processed_html }, status: :ok } end end diff --git a/app/controllers/image_uploads_controller.rb b/app/controllers/image_uploads_controller.rb index 842d3bca1..81b7a9a40 100644 --- a/app/controllers/image_uploads_controller.rb +++ b/app/controllers/image_uploads_controller.rb @@ -39,7 +39,7 @@ class ImageUploadsController < ApplicationController end respond_to do |format| - format.json { render json: { link: link }, status: 200 } + format.json { render json: { link: link }, status: :ok } end end end diff --git a/app/controllers/messages_controller.rb b/app/controllers/messages_controller.rb index 114b63d89..3bda4ec04 100644 --- a/app/controllers/messages_controller.rb +++ b/app/controllers/messages_controller.rb @@ -20,10 +20,10 @@ class MessagesController < ApplicationController end if success - render json: { status: "success", message: "Message created" }, status: 201 + render json: { status: "success", message: "Message created" }, status: :created else error_message = "Message created but could not trigger Pusher" - render json: { status: "error", message: error_message }, status: 201 + render json: { status: "error", message: error_message }, status: :created end else render json: { @@ -33,7 +33,7 @@ class MessagesController < ApplicationController message: @message.errors.full_messages, type: "error" } - }, status: 401 + }, status: :unauthorized end end @@ -67,7 +67,7 @@ class MessagesController < ApplicationController message: "You can not do that because you are banned", type: "error" } - }, status: 401 + }, status: :unauthorized end end end diff --git a/app/controllers/push_notification_subscriptions_controller.rb b/app/controllers/push_notification_subscriptions_controller.rb index 6ae9bf24b..ab15e84b3 100644 --- a/app/controllers/push_notification_subscriptions_controller.rb +++ b/app/controllers/push_notification_subscriptions_controller.rb @@ -8,7 +8,7 @@ class PushNotificationSubscriptionsController < ApplicationController user_id: current_user.id, notification_type: "browser", ) - render json: { status: "success", endpoint: @subscription.endpoint }, status: 201 + render json: { status: "success", endpoint: @subscription.endpoint }, status: :created end private diff --git a/app/controllers/social_previews_controller.rb b/app/controllers/social_previews_controller.rb index a10c626a3..c6eafeeda 100644 --- a/app/controllers/social_previews_controller.rb +++ b/app/controllers/social_previews_controller.rb @@ -16,7 +16,7 @@ class SocialPreviewsController < ApplicationController end format.png do html = render_to_string(template, formats: :html, layout: false) - redirect_to HtmlCssToImage.fetch_url(html: html, css: PNG_CSS, google_fonts: "Roboto|Roboto+Condensed"), status: 302 + redirect_to HtmlCssToImage.fetch_url(html: html, css: PNG_CSS, google_fonts: "Roboto|Roboto+Condensed"), status: :found end end end @@ -30,7 +30,7 @@ class SocialPreviewsController < ApplicationController end format.png do html = render_to_string(formats: :html, layout: false) - redirect_to HtmlCssToImage.fetch_url(html: html, css: PNG_CSS, google_fonts: "Roboto"), status: 302 + redirect_to HtmlCssToImage.fetch_url(html: html, css: PNG_CSS, google_fonts: "Roboto"), status: :found end end end @@ -44,7 +44,7 @@ class SocialPreviewsController < ApplicationController end format.png do html = render_to_string("user", formats: :html, layout: false) - redirect_to HtmlCssToImage.fetch_url(html: html, css: PNG_CSS, google_fonts: "Roboto"), status: 302 + redirect_to HtmlCssToImage.fetch_url(html: html, css: PNG_CSS, google_fonts: "Roboto"), status: :found end end end @@ -58,7 +58,7 @@ class SocialPreviewsController < ApplicationController end format.png do html = render_to_string(formats: :html, layout: false) - redirect_to HtmlCssToImage.fetch_url(html: html, css: PNG_CSS, google_fonts: "Roboto"), status: 302 + redirect_to HtmlCssToImage.fetch_url(html: html, css: PNG_CSS, google_fonts: "Roboto"), status: :found end end end diff --git a/app/controllers/stripe_cancellations_controller.rb b/app/controllers/stripe_cancellations_controller.rb index eda31ff16..adb9a4c0f 100644 --- a/app/controllers/stripe_cancellations_controller.rb +++ b/app/controllers/stripe_cancellations_controller.rb @@ -32,8 +32,8 @@ class StripeCancellationsController < ApplicationController monthly_dues = event.data.object.items.data[0].plan.amount user = User.where(stripe_id_code: stripe_id).first MembershipService.new(customer, user, monthly_dues).unsubscribe_customer - render body: nil, status: 200 + render body: nil, status: :ok rescue Stripe::APIConnectionError, Stripe::StripeError - render body: nil, status: 400 + render body: nil, status: :bad_request end end diff --git a/app/controllers/twilio_tokens_controller.rb b/app/controllers/twilio_tokens_controller.rb index b9b649969..b2516e2e7 100644 --- a/app/controllers/twilio_tokens_controller.rb +++ b/app/controllers/twilio_tokens_controller.rb @@ -5,12 +5,12 @@ class TwilioTokensController < ApplicationController video_channel = params[:id].split("private-video-channel-")[1] if params[:id].start_with?("private-video-channel-") unless video_channel skip_authorization - render json: { status: "failure", token: @twilio_token }, status: 404 + render json: { status: "failure", token: @twilio_token }, status: :not_found return end @chat_channel = ChatChannel.find(video_channel.to_i) authorize @chat_channel # show pundit method for chat_channel_policy works here, should always check though @twilio_token = TwilioToken.new(current_user, params[:id]).get - render json: { status: "success", token: @twilio_token }, status: 200 + render json: { status: "success", token: @twilio_token }, status: :ok end end diff --git a/app/controllers/video_states_controller.rb b/app/controllers/video_states_controller.rb index 4949b4410..97639ff56 100644 --- a/app/controllers/video_states_controller.rb +++ b/app/controllers/video_states_controller.rb @@ -5,7 +5,7 @@ class VideoStatesController < ApplicationController def create unless valid_user - render json: { message: "invalid_user" }, status: 422 + render json: { message: "invalid_user" }, status: :unprocessable_entity return end begin