forked from tildeverse/tilde.news
rubocop: Style/FrozenStringLiteralComment, 1396
It's a transitional thing, let future me suffer with Ruby 3.0.
This commit is contained in:
parent
69df281738
commit
8138d9e7a4
|
@ -54,6 +54,8 @@ Style/BlockDelimiters:
|
|||
Style/Documentation:
|
||||
Enabled: false
|
||||
Exclude: [db/migrate/**/*, spec/**/*, test/**/*]
|
||||
Style/FrozenStringLiteralComment:
|
||||
EnforcedStyle: never
|
||||
Style/HashSyntax:
|
||||
EnforcedStyle: no_mixed_keys
|
||||
Style/IfUnlessModifier:
|
||||
|
|
|
@ -49,7 +49,7 @@ class ApplicationController < ActionController::Base
|
|||
traffic = traffic_kv.value.to_i
|
||||
|
||||
# don't increase traffic counter for bots or api requests
|
||||
unless agent_is_spider? || [ "json", "rss" ].include?(params[:format])
|
||||
unless agent_is_spider? || ["json", "rss"].include?(params[:format])
|
||||
traffic += 100
|
||||
end
|
||||
|
||||
|
@ -57,7 +57,7 @@ class ApplicationController < ActionController::Base
|
|||
traffic -= (100.0 * (now_i - date_kv.value) * TRAFFIC_DECREMENTER).to_i
|
||||
|
||||
# clamp to 100, 1000
|
||||
traffic = [ [ 100, traffic ].max, 10000 ].min
|
||||
traffic = [[100, traffic].max, 10000].min
|
||||
|
||||
@traffic = traffic * 0.01
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
class AvatarsController < ApplicationController
|
||||
before_action :require_logged_in_user, :only => [ :expire ]
|
||||
before_action :require_logged_in_user, :only => [:expire]
|
||||
|
||||
ALLOWED_SIZES = [ 16, 32, 100, 200 ]
|
||||
ALLOWED_SIZES = [16, 32, 100, 200]
|
||||
|
||||
CACHE_DIR = "#{Rails.root}/public/avatars/"
|
||||
|
||||
|
|
|
@ -2,12 +2,12 @@ class CommentsController < ApplicationController
|
|||
COMMENTS_PER_PAGE = 20
|
||||
|
||||
# for rss feeds, load the user's tag filters if a token is passed
|
||||
before_action :find_user_from_rss_token, :only => [ :index ]
|
||||
before_action :find_user_from_rss_token, :only => [:index]
|
||||
before_action :require_logged_in_user_or_400,
|
||||
:only => [ :create, :preview, :upvote, :downvote, :unvote ]
|
||||
:only => [:create, :preview, :upvote, :downvote, :unvote]
|
||||
|
||||
# for rss feeds, load the user's tag filters if a token is passed
|
||||
before_action :find_user_from_rss_token, :only => [ :index ]
|
||||
before_action :find_user_from_rss_token, :only => [:index]
|
||||
|
||||
def create
|
||||
if !(story = Story.where(:short_id => params[:story_id]).first) ||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
class HatsController < ApplicationController
|
||||
before_action :require_logged_in_user, :except => [ :index ]
|
||||
before_action :require_logged_in_user, :except => [:index]
|
||||
before_action :require_logged_in_moderator,
|
||||
:except => [ :build_request, :index, :create_request ]
|
||||
:except => [:build_request, :index, :create_request]
|
||||
|
||||
def build_request
|
||||
@title = "Request a Hat"
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
class HomeController < ApplicationController
|
||||
# for rss feeds, load the user's tag filters if a token is passed
|
||||
before_action :find_user_from_rss_token, :only => [ :index, :newest, :saved ]
|
||||
before_action :find_user_from_rss_token, :only => [:index, :newest, :saved]
|
||||
before_action { @page = page }
|
||||
before_action :require_logged_in_user, :only => [ :upvoted ]
|
||||
before_action :require_logged_in_user, :only => [:upvoted]
|
||||
|
||||
def four_oh_four
|
||||
begin
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
class InvitationsController < ApplicationController
|
||||
before_action :require_logged_in_user,
|
||||
:except => [ :build, :create_by_request, :confirm_email ]
|
||||
:except => [:build, :create_by_request, :confirm_email]
|
||||
|
||||
def build
|
||||
if Rails.application.allow_invitation_requests?
|
||||
|
|
|
@ -5,7 +5,7 @@ class LoginFailedError < StandardError; end
|
|||
|
||||
class LoginController < ApplicationController
|
||||
before_action :authenticate_user
|
||||
before_action :check_for_read_only_mode, :except => [ :index ]
|
||||
before_action :check_for_read_only_mode, :except => [:index]
|
||||
|
||||
def logout
|
||||
if @user
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
class MessagesController < ApplicationController
|
||||
before_action :require_logged_in_user
|
||||
before_action :find_message, :only => [ :show, :destroy, :keep_as_new ]
|
||||
before_action :find_message, :only => [:show, :destroy, :keep_as_new]
|
||||
|
||||
def index
|
||||
@messages = @user.undeleted_received_messages
|
||||
|
|
|
@ -2,7 +2,7 @@ class RepliesController < ApplicationController
|
|||
REPLIES_PER_PAGE = 25
|
||||
|
||||
before_action :require_logged_in_user, :set_page
|
||||
after_action :update_read_ribbons, only: [ :unread ]
|
||||
after_action :update_read_ribbons, only: [:unread]
|
||||
|
||||
def all
|
||||
@heading = @title = "All Your Replies"
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
class StoriesController < ApplicationController
|
||||
before_action :require_logged_in_user_or_400,
|
||||
:only => [ :upvote, :downvote, :unvote, :hide, :unhide, :preview, :save, :unsave ]
|
||||
before_action :require_logged_in_user, :only => [ :destroy, :create, :edit,
|
||||
:fetch_url_attributes, :new, :suggest, ]
|
||||
before_action :verify_user_can_submit_stories, :only => [ :new, :create ]
|
||||
before_action :find_user_story, :only => [ :destroy, :edit, :undelete, :update ]
|
||||
before_action :find_story!, :only => [ :suggest, :submit_suggestions ]
|
||||
around_action :track_story_reads, only: [ :show ], if: -> { @user.present? }
|
||||
:only => [:upvote, :downvote, :unvote, :hide, :unhide, :preview, :save, :unsave]
|
||||
before_action :require_logged_in_user, :only => [:destroy, :create, :edit,
|
||||
:fetch_url_attributes, :new, :suggest,]
|
||||
before_action :verify_user_can_submit_stories, :only => [:new, :create]
|
||||
before_action :find_user_story, :only => [:destroy, :edit, :undelete, :update]
|
||||
before_action :find_story!, :only => [:suggest, :submit_suggestions]
|
||||
around_action :track_story_reads, only: [:show], if: -> { @user.present? }
|
||||
|
||||
def create
|
||||
@title = "Submit Story"
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
class UsersController < ApplicationController
|
||||
before_action :require_logged_in_moderator,
|
||||
:only => [ :enable_invitation, :disable_invitation, :ban, :unban ]
|
||||
:only => [:enable_invitation, :disable_invitation, :ban, :unban]
|
||||
|
||||
def show
|
||||
@showing_user = User.where(:username => params[:username]).first!
|
||||
|
|
|
@ -76,7 +76,7 @@ module ApplicationHelper
|
|||
if @user
|
||||
if (count = @user.unread_replies_count) > 0
|
||||
@right_header_links[replies_unread_path] = {
|
||||
:class => [ "new_messages" ],
|
||||
:class => ["new_messages"],
|
||||
:title => "Replies (#{count})",
|
||||
}
|
||||
else
|
||||
|
@ -85,7 +85,7 @@ module ApplicationHelper
|
|||
|
||||
if (count = @user.unread_message_count) > 0
|
||||
@right_header_links[messages_path] = {
|
||||
:class => [ "new_messages" ],
|
||||
:class => ["new_messages"],
|
||||
:title => "#{count} New Message#{count == 1 ? "" : "s"}",
|
||||
}
|
||||
else
|
||||
|
|
|
@ -6,7 +6,7 @@ class ReplyingComment < ApplicationRecord
|
|||
scope :for_user, ->(user_id) {
|
||||
where(user_id: user_id)
|
||||
.order(comment_created_at: :desc)
|
||||
.preload(:comment => [ :story, :user ])
|
||||
.preload(:comment => [:story, :user])
|
||||
}
|
||||
scope :unread_replies_for, ->(user_id) { for_user(user_id).where(is_unread: true) }
|
||||
scope :comment_replies_for, ->(user_id) { for_user(user_id).where('parent_comment_id is not null') }
|
||||
|
|
|
@ -112,8 +112,8 @@ class Story < ActiveRecord::Base
|
|||
|
||||
# returns a story or nil
|
||||
def self.find_similar_by_url(url)
|
||||
urls = [ url.to_s ]
|
||||
urls2 = [ url.to_s ]
|
||||
urls = [url.to_s]
|
||||
urls2 = [url.to_s]
|
||||
|
||||
# https
|
||||
urls.each do |u|
|
||||
|
@ -244,7 +244,7 @@ class Story < ActiveRecord::Base
|
|||
end
|
||||
|
||||
# don't immediately kill stories at 0 by bumping up score by one
|
||||
order = Math.log([ (score + 1).abs + cpoints, 1 ].max, 10)
|
||||
order = Math.log([(score + 1).abs + cpoints, 1].max, 10)
|
||||
if score > 0
|
||||
sign = 1
|
||||
elsif score < 0
|
||||
|
@ -516,7 +516,7 @@ class Story < ActiveRecord::Base
|
|||
def merged_comments
|
||||
# TODO: make this a normal has_many?
|
||||
Comment.where(:story_id => Story.select(:id)
|
||||
.where(:merged_story_id => self.id) + [ self.id ])
|
||||
.where(:merged_story_id => self.id) + [self.id])
|
||||
end
|
||||
|
||||
def merge_story_short_id=(sid)
|
||||
|
@ -562,7 +562,7 @@ class Story < ActiveRecord::Base
|
|||
if old_tags_a == new_tags_a
|
||||
{}
|
||||
else
|
||||
{ "tags" => [ old_tags_a, new_tags_a ] }
|
||||
{ "tags" => [old_tags_a, new_tags_a] }
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -694,9 +694,12 @@ class Story < ActiveRecord::Base
|
|||
wl = 0
|
||||
words = []
|
||||
|
||||
self.title.parameterize.gsub(/[^a-z0-9]/, "_").split("_")
|
||||
.reject {|z| [ "", "a", "an", "and", "but", "in", "of", "or", "that", "the",
|
||||
"to", ].include?(z) }.each do |w|
|
||||
self.title
|
||||
.parameterize
|
||||
.gsub(/[^a-z0-9]/, "_")
|
||||
.split("_")
|
||||
.reject {|z| ["", "a", "an", "and", "but", "in", "of", "or", "that", "the", "to"] .include?(z) }
|
||||
.each do |w|
|
||||
if wl + w.length <= max_len
|
||||
words.push w
|
||||
wl += w.length
|
||||
|
|
|
@ -82,10 +82,10 @@ class User < ActiveRecord::Base
|
|||
self.create_mailing_list_token
|
||||
end
|
||||
|
||||
BANNED_USERNAMES = [ "admin", "administrator", "contact", "fraud", "guest",
|
||||
BANNED_USERNAMES = ["admin", "administrator", "contact", "fraud", "guest",
|
||||
"help", "hostmaster", "inactive-user", "mailer-daemon", "moderator",
|
||||
"moderators", "nobody", "postmaster", "root", "security", "support",
|
||||
"sysop", "webmaster", "enable", "new", "signup", ]
|
||||
"sysop", "webmaster", "enable", "new", "signup",]
|
||||
|
||||
# days old accounts are considered new for
|
||||
NEW_USER_DAYS = 7
|
||||
|
|
|
@ -45,7 +45,7 @@ Lobsters::Application.configure do
|
|||
config.log_level = :info
|
||||
|
||||
# Prepend all log lines with the following tags.
|
||||
config.log_tags = [ :uuid ]
|
||||
config.log_tags = [:uuid]
|
||||
|
||||
# Use a different logger for distributed setups.
|
||||
# config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
|
||||
|
|
|
@ -30,11 +30,11 @@ class Github
|
|||
res = s.fetch("https://api.github.com/user?access_token=#{tok}")
|
||||
js = JSON.parse(res)
|
||||
if js && js["login"].present?
|
||||
return [ tok, js["login"] ]
|
||||
return [tok, js["login"]]
|
||||
end
|
||||
end
|
||||
|
||||
return [ nil, nil ]
|
||||
return [nil, nil]
|
||||
end
|
||||
|
||||
def self.oauth_auth_url(state)
|
||||
|
|
|
@ -67,7 +67,7 @@ class Twitter
|
|||
return nil
|
||||
end
|
||||
|
||||
[ at.token, at.secret, js["screen_name"] ]
|
||||
[at.token, at.secret, js["screen_name"]]
|
||||
end
|
||||
|
||||
def self.oauth_request_token(state)
|
||||
|
|
|
@ -9,7 +9,7 @@ Rails.application.require_environment!
|
|||
|
||||
class String
|
||||
def quoted_printable(encoded_word = false)
|
||||
s = [ self ].pack("M")
|
||||
s = [self].pack("M")
|
||||
|
||||
if encoded_word
|
||||
s.split(/\r?\n/).map {|l| "=?UTF-8?Q?" <<
|
||||
|
@ -182,7 +182,7 @@ last_comment_id, false, false).order(:id).each do |c|
|
|||
mail.puts "Content-Transfer-Encoding: quoted-printable"
|
||||
mail.puts "Message-ID: <#{c.mailing_list_message_id}>"
|
||||
|
||||
refs = [ "<#{c.story.mailing_list_message_id}>" ]
|
||||
refs = ["<#{c.story.mailing_list_message_id}>"]
|
||||
|
||||
if c.parent_comment_id
|
||||
mail.puts "In-Reply-To: <#{c.parent_comment.mailing_list_message_id}>"
|
||||
|
|
|
@ -4,19 +4,19 @@ describe ApplicationHelper do
|
|||
describe "#page_numbers_for_pagination" do
|
||||
it "returns the right number of pages" do
|
||||
expect(helper.page_numbers_for_pagination(10, 1))
|
||||
.to eq([ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ])
|
||||
.to eq([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
|
||||
|
||||
expect(helper.page_numbers_for_pagination(20, 1))
|
||||
.to eq([ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, "...", 20 ])
|
||||
.to eq([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, "...", 20])
|
||||
|
||||
expect(helper.page_numbers_for_pagination(25, 1))
|
||||
.to eq([ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, "...", 25 ])
|
||||
.to eq([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, "...", 25])
|
||||
|
||||
expect(helper.page_numbers_for_pagination(25, 10))
|
||||
.to eq([ 1, "...", 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, "...", 25 ])
|
||||
.to eq([1, "...", 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, "...", 25])
|
||||
|
||||
expect(helper.page_numbers_for_pagination(25, 20))
|
||||
.to eq([ 1, "...", 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25 ])
|
||||
.to eq([1, "...", 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -30,9 +30,9 @@ describe Story do
|
|||
|
||||
it "must have at least one tag" do
|
||||
expect { Story.make!(:tags_a => nil) }.to raise_error
|
||||
expect { Story.make!(:tags_a => [ "", " " ]) }.to raise_error
|
||||
expect { Story.make!(:tags_a => ["", " "]) }.to raise_error
|
||||
|
||||
expect { Story.make!(:tags_a => [ "", "tag1" ]) }.to_not raise_error
|
||||
expect { Story.make!(:tags_a => ["", "tag1"]) }.to_not raise_error
|
||||
end
|
||||
|
||||
it "checks for invalid urls" do
|
||||
|
@ -115,21 +115,21 @@ describe Story do
|
|||
end
|
||||
|
||||
it "calculates tag changes properly" do
|
||||
s = Story.make!(:title => "blah", :tags_a => [ "tag1", "tag2" ])
|
||||
s = Story.make!(:title => "blah", :tags_a => ["tag1", "tag2"])
|
||||
|
||||
s.tags_a = [ "tag2" ]
|
||||
expect(s.tagging_changes).to eq({ "tags" => [ "tag1 tag2", "tag2" ] })
|
||||
s.tags_a = ["tag2"]
|
||||
expect(s.tagging_changes).to eq({ "tags" => ["tag1 tag2", "tag2"] })
|
||||
end
|
||||
|
||||
it "logs moderations properly" do
|
||||
mod = User.make!(:username => "mod", :is_moderator => true)
|
||||
|
||||
s = Story.make!(:title => "blah", :tags_a => [ "tag1", "tag2" ],
|
||||
s = Story.make!(:title => "blah", :tags_a => ["tag1", "tag2"],
|
||||
:description => "desc")
|
||||
|
||||
s.title = "changed title"
|
||||
s.description = nil
|
||||
s.tags_a = [ "tag1" ]
|
||||
s.tags_a = ["tag1"]
|
||||
|
||||
s.editor = mod
|
||||
s.moderation_reason = "because i hate you"
|
||||
|
|
|
@ -29,7 +29,7 @@ Story.blueprint do
|
|||
user_id { User.make!.id }
|
||||
title { "story title #{sn}" }
|
||||
url { "http://example.com/#{sn}" }
|
||||
tags_a { [ "tag1", "tag2" ] }
|
||||
tags_a { ["tag1", "tag2"] }
|
||||
end
|
||||
|
||||
Comment.blueprint do
|
||||
|
|
Loading…
Reference in New Issue
Block a user