Skip to content

Commit

Permalink
rubocop: Layout/MultilineBlockLayout, 166
Browse files Browse the repository at this point in the history
Except in user.rb, these were all oddities of 80-char line length.
  • Loading branch information
pushcx committed Mar 19, 2018
1 parent 5b3478d commit 56d8f1a
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 22 deletions.
3 changes: 1 addition & 2 deletions app/controllers/home_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions app/models/story.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand Down
6 changes: 4 additions & 2 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions script/mail_new_activity
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
31 changes: 17 additions & 14 deletions spec/models/story_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 56d8f1a

Please sign in to comment.