From 56d8f1a9bfd52102f370c3201015f3eeee810dd4 Mon Sep 17 00:00:00 2001 From: Peter Bhat Harkins Date: Sun, 18 Mar 2018 20:21:55 -0500 Subject: [PATCH] rubocop: Layout/MultilineBlockLayout, 166 Except in user.rb, these were all oddities of 80-char line length. --- app/controllers/home_controller.rb | 3 +-- app/models/story.rb | 3 +-- app/models/user.rb | 6 ++++-- script/mail_new_activity | 3 +-- spec/models/story_spec.rb | 31 ++++++++++++++++-------------- 5 files changed, 24 insertions(+), 22 deletions(-) diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index 8973b2e78..71a6eeb87 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -298,8 +298,7 @@ def get_from_cache(opts={}, &block) if Rails.env.development? || @user || tags_filtered_by_cookie.any? yield else - key = opts.merge(page: page).sort.map {|k, v| "#{k}=#{v.to_param}" - }.join(" ") + key = opts.merge(page: page).sort.map {|k, v| "#{k}=#{v.to_param}" }.join(" ") begin Rails.cache.fetch("stories #{key}", :expires_in => 45, &block) rescue Errno::ENOENT => e diff --git a/app/models/story.rb b/app/models/story.rb index 4ed0db117..4bf447ca3 100644 --- a/app/models/story.rb +++ b/app/models/story.rb @@ -293,8 +293,7 @@ def check_tags end end - if !self.taggings.reject {|t| t.marked_for_destruction? || t.tag.is_media? - }.any? + if self.taggings.reject {|t| t.marked_for_destruction? || t.tag.is_media? }.empty? errors.add(:base, "Must have at least one non-media (PDF, video) " << "tag. If no tags apply to your content, it probably doesn't " << "belong here.") diff --git a/app/models/user.rb b/app/models/user.rb index 3f9594da9..1f5b4ca34 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -84,10 +84,12 @@ class User < ApplicationRecord end scope :active, -> { where(:banned_at => nil, :deleted_at => nil) } - scope :moderators, -> { where(' + scope :moderators, -> { + where(' is_moderator = True OR users.id IN (select distinct moderator_user_id from moderations) - ') } + ') + } before_save :check_session_token before_validation :on => :create do diff --git a/script/mail_new_activity b/script/mail_new_activity index c63cd469c..245d77a9f 100755 --- a/script/mail_new_activity +++ b/script/mail_new_activity @@ -12,8 +12,7 @@ class String s = [self].pack("M") if encoded_word - s.split(/\r?\n/).map {|l| "=?UTF-8?Q?" << - l.gsub(/=*$/, "").gsub(" ", "_") << "?=" }.join("\n\t") + s.split(/\r?\n/).map {|l| "=?UTF-8?Q?" + l.gsub(/=*$/, "").tr(" ", "_") << "?=" }.join("\n\t") else s end diff --git a/spec/models/story_spec.rb b/spec/models/story_spec.rb index 943a37c1b..8189aebff 100644 --- a/spec/models/story_spec.rb +++ b/spec/models/story_spec.rb @@ -8,14 +8,13 @@ end it "requires a url or a description" do - expect { Story.make!(:title => "hello", :url => "", - :description => "") }.to raise_error + expect { Story.make!(:title => "hello", :url => "", :description => "") }.to raise_error - expect { Story.make!(:title => "hello", :description => "hi", :url => nil) - }.to_not raise_error + expect { Story.make!(:title => "hello", :description => "hi", :url => nil) }.to_not raise_error - expect { Story.make!(:title => "hello", :url => "http://ex.com/", - :description => nil) }.to_not raise_error + expect { + Story.make!(:title => "hello", :url => "http://ex.com/", :description => nil) + }.to_not raise_error end it "does not allow too-short titles" do @@ -36,11 +35,13 @@ end it "checks for invalid urls" do - expect { Story.make!(:title => "test", :url => "http://gooses.com/") - }.to_not raise_error + expect { + Story.make!(:title => "test", :url => "http://gooses.com/") + }.to_not raise_error - expect { Story.make!(:title => "test", url => "ftp://gooses/") - }.to raise_error + expect { + Story.make!(:title => "test", url => "ftp://gooses/") + }.to raise_error end it "checks for a previously posted story with same url" do @@ -49,13 +50,15 @@ Story.make!(:title => "flim flam", :url => "http://example.com/") expect(Story.count).to eq(1) - expect { Story.make!(:title => "flim flam 2", - :url => "http://example.com/") }.to raise_error + expect { + Story.make!(:title => "flim flam 2", :url => "http://example.com/") + }.to raise_error expect(Story.count).to eq(1) - expect { Story.make!(:title => "flim flam 2", - :url => "http://www.example.com/") }.to raise_error + expect { + Story.make!(:title => "flim flam 2", :url => "http://www.example.com/") + }.to raise_error expect(Story.count).to eq(1) end