Browse Source

rubocop issues - Cleaning up (#8912)

* cleanup pass

* undo mistakes

* fixed.

* revert
master
ashleyhull-versent 5 years ago
committed by Eugen Rochko
parent
commit
f194857ac9
15 changed files with 33 additions and 33 deletions
  1. +2
    -2
      app/models/concerns/omniauthable.rb
  2. +1
    -1
      config/initializers/open_uri_redirection.rb
  3. +5
    -5
      lib/mastodon/migration_helpers.rb
  4. +2
    -2
      spec/controllers/api/salmon_controller_spec.rb
  5. +1
    -1
      spec/controllers/api/subscriptions_controller_spec.rb
  6. +1
    -1
      spec/fabricators/user_fabricator.rb
  7. +1
    -1
      spec/features/log_in_spec.rb
  8. +12
    -12
      spec/lib/ostatus/atom_serializer_spec.rb
  9. +1
    -1
      spec/models/status_spec.rb
  10. +1
    -1
      spec/models/user_spec.rb
  11. +2
    -2
      spec/rails_helper.rb
  12. +1
    -1
      spec/services/batched_remove_status_service_spec.rb
  13. +1
    -1
      spec/services/fetch_remote_account_service_spec.rb
  14. +1
    -1
      spec/services/process_feed_service_spec.rb
  15. +1
    -1
      spec/services/update_remote_profile_service_spec.rb

+ 2
- 2
app/models/concerns/omniauthable.rb View File

@@ -26,7 +26,7 @@ module Omniauthable
# to prevent the identity being locked with accidentally created accounts. # to prevent the identity being locked with accidentally created accounts.
# Note that this may leave zombie accounts (with no associated identity) which # Note that this may leave zombie accounts (with no associated identity) which
# can be cleaned up at a later date. # can be cleaned up at a later date.
user = signed_in_resource ? signed_in_resource : identity.user
user = signed_in_resource || identity.user
user = create_for_oauth(auth) if user.nil? user = create_for_oauth(auth) if user.nil?


if identity.user.nil? if identity.user.nil?
@@ -61,7 +61,7 @@ module Omniauthable
display_name = auth.info.full_name || [auth.info.first_name, auth.info.last_name].join(' ') display_name = auth.info.full_name || [auth.info.first_name, auth.info.last_name].join(' ')


{ {
email: email ? email : "#{TEMP_EMAIL_PREFIX}-#{auth.uid}-#{auth.provider}.com",
email: email || "#{TEMP_EMAIL_PREFIX}-#{auth.uid}-#{auth.provider}.com",
password: Devise.friendly_token[0, 20], password: Devise.friendly_token[0, 20],
account_attributes: { account_attributes: {
username: ensure_unique_username(auth.uid), username: ensure_unique_username(auth.uid),


+ 1
- 1
config/initializers/open_uri_redirection.rb View File

@@ -2,7 +2,7 @@ require 'open-uri'


module OpenURI module OpenURI
def self.redirectable?(uri1, uri2) # :nodoc: def self.redirectable?(uri1, uri2) # :nodoc:
uri1.scheme.downcase == uri2.scheme.downcase ||
uri1.scheme.casecmp(uri2.scheme).zero? ||
(/\A(?:http|https|ftp)\z/i =~ uri1.scheme && /\A(?:http|https|ftp)\z/i =~ uri2.scheme) (/\A(?:http|https|ftp)\z/i =~ uri1.scheme && /\A(?:http|https|ftp)\z/i =~ uri2.scheme)
end end
end end

+ 5
- 5
lib/mastodon/migration_helpers.rb View File

@@ -342,8 +342,8 @@ module Mastodon


say "Migrating #{table_name}.#{column} (~#{total.to_i} rows)" say "Migrating #{table_name}.#{column} (~#{total.to_i} rows)"


started_time = Time.now
last_time = Time.now
started_time = Time.zone.now
last_time = Time.zone.now
migrated = 0 migrated = 0
loop do loop do
stop_row = nil stop_row = nil
@@ -375,13 +375,13 @@ module Mastodon
end end


migrated += batch_size migrated += batch_size
if Time.now - last_time > 1
if Time.zone.now - last_time > 1
status = "Migrated #{migrated} rows" status = "Migrated #{migrated} rows"


percentage = 100.0 * migrated / total percentage = 100.0 * migrated / total
status += " (~#{sprintf('%.2f', percentage)}%, " status += " (~#{sprintf('%.2f', percentage)}%, "


remaining_time = (100.0 - percentage) * (Time.now - started_time) / percentage
remaining_time = (100.0 - percentage) * (Time.zone.now - started_time) / percentage


status += "#{(remaining_time / 60).to_i}:" status += "#{(remaining_time / 60).to_i}:"
status += sprintf('%02d', remaining_time.to_i % 60) status += sprintf('%02d', remaining_time.to_i % 60)
@@ -397,7 +397,7 @@ module Mastodon
status += ')' status += ')'


say status, true say status, true
last_time = Time.now
last_time = Time.zone.now
end end


# There are no more rows left to update. # There are no more rows left to update.


+ 2
- 2
spec/controllers/api/salmon_controller_spec.rb View File

@@ -15,7 +15,7 @@ RSpec.describe Api::SalmonController, type: :controller do
describe 'POST #update' do describe 'POST #update' do
context 'with valid post data' do context 'with valid post data' do
before do before do
post :update, params: { id: account.id }, body: File.read(File.join(Rails.root, 'spec', 'fixtures', 'salmon', 'mention.xml'))
post :update, params: { id: account.id }, body: File.read(Rails.root.join('spec', 'fixtures', 'salmon', 'mention.xml'))
end end


it 'contains XML in the request body' do it 'contains XML in the request body' do
@@ -54,7 +54,7 @@ RSpec.describe Api::SalmonController, type: :controller do
service = double(call: false) service = double(call: false)
allow(VerifySalmonService).to receive(:new).and_return(service) allow(VerifySalmonService).to receive(:new).and_return(service)


post :update, params: { id: account.id }, body: File.read(File.join(Rails.root, 'spec', 'fixtures', 'salmon', 'mention.xml'))
post :update, params: { id: account.id }, body: File.read(Rails.root.join('spec', 'fixtures', 'salmon', 'mention.xml'))
end end


it 'returns http client error' do it 'returns http client error' do


+ 1
- 1
spec/controllers/api/subscriptions_controller_spec.rb View File

@@ -33,7 +33,7 @@ RSpec.describe Api::SubscriptionsController, type: :controller do
end end


describe 'POST #update' do describe 'POST #update' do
let(:feed) { File.read(File.join(Rails.root, 'spec', 'fixtures', 'push', 'feed.atom')) }
let(:feed) { File.read(Rails.root.join('spec', 'fixtures', 'push', 'feed.atom')) }


before do before do
stub_request(:post, "https://quitter.no/main/push/hub").to_return(:status => 200, :body => "", :headers => {}) stub_request(:post, "https://quitter.no/main/push/hub").to_return(:status => 200, :body => "", :headers => {})


+ 1
- 1
spec/fabricators/user_fabricator.rb View File

@@ -2,5 +2,5 @@ Fabricator(:user) do
account account
email { sequence(:email) { |i| "#{i}#{Faker::Internet.email}" } } email { sequence(:email) { |i| "#{i}#{Faker::Internet.email}" } }
password "123456789" password "123456789"
confirmed_at { Time.now }
confirmed_at { Time.zone.now }
end end

+ 1
- 1
spec/features/log_in_spec.rb View File

@@ -3,7 +3,7 @@ require "rails_helper"
feature "Log in" do feature "Log in" do
given(:email) { "test@examle.com" } given(:email) { "test@examle.com" }
given(:password) { "password" } given(:password) { "password" }
given(:confirmed_at) { Time.now }
given(:confirmed_at) { Time.zone.now }


background do background do
Fabricate(:user, email: email, password: password, confirmed_at: confirmed_at) Fabricate(:user, email: email, password: password, confirmed_at: confirmed_at)


+ 12
- 12
spec/lib/ostatus/atom_serializer_spec.rb View File

@@ -728,9 +728,9 @@ RSpec.describe OStatus::AtomSerializer do
it 'appends id element with unique tag' do it 'appends id element with unique tag' do
block = Fabricate(:block) block = Fabricate(:block)


time_before = Time.now
time_before = Time.zone.now
block_salmon = OStatus::AtomSerializer.new.block_salmon(block) block_salmon = OStatus::AtomSerializer.new.block_salmon(block)
time_after = Time.now
time_after = Time.zone.now


expect(block_salmon.id.text).to( expect(block_salmon.id.text).to(
eq(OStatus::TagManager.instance.unique_tag(time_before.utc, block.id, 'Block')) eq(OStatus::TagManager.instance.unique_tag(time_before.utc, block.id, 'Block'))
@@ -815,9 +815,9 @@ RSpec.describe OStatus::AtomSerializer do
it 'appends id element with unique tag' do it 'appends id element with unique tag' do
block = Fabricate(:block) block = Fabricate(:block)


time_before = Time.now
time_before = Time.zone.now
unblock_salmon = OStatus::AtomSerializer.new.unblock_salmon(block) unblock_salmon = OStatus::AtomSerializer.new.unblock_salmon(block)
time_after = Time.now
time_after = Time.zone.now


expect(unblock_salmon.id.text).to( expect(unblock_salmon.id.text).to(
eq(OStatus::TagManager.instance.unique_tag(time_before.utc, block.id, 'Block')) eq(OStatus::TagManager.instance.unique_tag(time_before.utc, block.id, 'Block'))
@@ -994,9 +994,9 @@ RSpec.describe OStatus::AtomSerializer do
it 'appends id element with unique tag' do it 'appends id element with unique tag' do
favourite = Fabricate(:favourite) favourite = Fabricate(:favourite)


time_before = Time.now
time_before = Time.zone.now
unfavourite_salmon = OStatus::AtomSerializer.new.unfavourite_salmon(favourite) unfavourite_salmon = OStatus::AtomSerializer.new.unfavourite_salmon(favourite)
time_after = Time.now
time_after = Time.zone.now


expect(unfavourite_salmon.id.text).to( expect(unfavourite_salmon.id.text).to(
eq(OStatus::TagManager.instance.unique_tag(time_before.utc, favourite.id, 'Favourite')) eq(OStatus::TagManager.instance.unique_tag(time_before.utc, favourite.id, 'Favourite'))
@@ -1179,9 +1179,9 @@ RSpec.describe OStatus::AtomSerializer do
follow = Fabricate(:follow) follow = Fabricate(:follow)
follow.destroy! follow.destroy!


time_before = Time.now
time_before = Time.zone.now
unfollow_salmon = OStatus::AtomSerializer.new.unfollow_salmon(follow) unfollow_salmon = OStatus::AtomSerializer.new.unfollow_salmon(follow)
time_after = Time.now
time_after = Time.zone.now


expect(unfollow_salmon.id.text).to( expect(unfollow_salmon.id.text).to(
eq(OStatus::TagManager.instance.unique_tag(time_before.utc, follow.id, 'Follow')) eq(OStatus::TagManager.instance.unique_tag(time_before.utc, follow.id, 'Follow'))
@@ -1327,9 +1327,9 @@ RSpec.describe OStatus::AtomSerializer do
it 'appends id element with unique tag' do it 'appends id element with unique tag' do
follow_request = Fabricate(:follow_request) follow_request = Fabricate(:follow_request)


time_before = Time.now
time_before = Time.zone.now
authorize_follow_request_salmon = OStatus::AtomSerializer.new.authorize_follow_request_salmon(follow_request) authorize_follow_request_salmon = OStatus::AtomSerializer.new.authorize_follow_request_salmon(follow_request)
time_after = Time.now
time_after = Time.zone.now


expect(authorize_follow_request_salmon.id.text).to( expect(authorize_follow_request_salmon.id.text).to(
eq(OStatus::TagManager.instance.unique_tag(time_before.utc, follow_request.id, 'FollowRequest')) eq(OStatus::TagManager.instance.unique_tag(time_before.utc, follow_request.id, 'FollowRequest'))
@@ -1396,9 +1396,9 @@ RSpec.describe OStatus::AtomSerializer do
it 'appends id element with unique tag' do it 'appends id element with unique tag' do
follow_request = Fabricate(:follow_request) follow_request = Fabricate(:follow_request)


time_before = Time.now
time_before = Time.zone.now
reject_follow_request_salmon = OStatus::AtomSerializer.new.reject_follow_request_salmon(follow_request) reject_follow_request_salmon = OStatus::AtomSerializer.new.reject_follow_request_salmon(follow_request)
time_after = Time.now
time_after = Time.zone.now


expect(reject_follow_request_salmon.id.text).to( expect(reject_follow_request_salmon.id.text).to(
eq(OStatus::TagManager.instance.unique_tag(time_before.utc, follow_request.id, 'FollowRequest')) eq(OStatus::TagManager.instance.unique_tag(time_before.utc, follow_request.id, 'FollowRequest'))


+ 1
- 1
spec/models/status_spec.rb View File

@@ -154,7 +154,7 @@ RSpec.describe Status, type: :model do


describe '#target' do describe '#target' do
it 'returns nil if the status is self-contained' do it 'returns nil if the status is self-contained' do
expect(subject.target).to be_nil
expect(subject.target).to be_nil
end end


it 'returns nil if the status is a reply' do it 'returns nil if the status is a reply' do


+ 1
- 1
spec/models/user_spec.rb View File

@@ -67,7 +67,7 @@ RSpec.describe User, type: :model do
describe 'confirmed' do describe 'confirmed' do
it 'returns an array of users who are confirmed' do it 'returns an array of users who are confirmed' do
user_1 = Fabricate(:user, confirmed_at: nil) user_1 = Fabricate(:user, confirmed_at: nil)
user_2 = Fabricate(:user, confirmed_at: Time.now)
user_2 = Fabricate(:user, confirmed_at: Time.zone.now)
expect(User.confirmed).to match_array([user_2]) expect(User.confirmed).to match_array([user_2])
end end
end end


+ 2
- 2
spec/rails_helper.rb View File

@@ -72,11 +72,11 @@ RSpec::Sidekiq.configure do |config|
end end


def request_fixture(name) def request_fixture(name)
File.read(File.join(Rails.root, 'spec', 'fixtures', 'requests', name))
File.read(Rails.root.join('spec', 'fixtures', 'requests', name))
end end


def attachment_fixture(name) def attachment_fixture(name)
File.open(File.join(Rails.root, 'spec', 'fixtures', 'files', name))
File.open(Rails.root.join('spec', 'fixtures', 'files', name))
end end


def stub_jsonld_contexts! def stub_jsonld_contexts!


+ 1
- 1
spec/services/batched_remove_status_service_spec.rb View File

@@ -19,7 +19,7 @@ RSpec.describe BatchedRemoveStatusService, type: :service do
stub_request(:post, 'http://example.com/inbox').to_return(status: 200) stub_request(:post, 'http://example.com/inbox').to_return(status: 200)


Fabricate(:subscription, account: alice, callback_url: 'http://example.com/push', confirmed: true, expires_at: 30.days.from_now) Fabricate(:subscription, account: alice, callback_url: 'http://example.com/push', confirmed: true, expires_at: 30.days.from_now)
jeff.user.update(current_sign_in_at: Time.now)
jeff.user.update(current_sign_in_at: Time.zone.now)
jeff.follow!(alice) jeff.follow!(alice)
hank.follow!(alice) hank.follow!(alice)




+ 1
- 1
spec/services/fetch_remote_account_service_spec.rb View File

@@ -19,7 +19,7 @@ RSpec.describe FetchRemoteAccountService, type: :service do
end end


let(:webfinger) { { subject: 'acct:alice@example.com', links: [{ rel: 'self', href: 'https://example.com/alice' }] } } let(:webfinger) { { subject: 'acct:alice@example.com', links: [{ rel: 'self', href: 'https://example.com/alice' }] } }
let(:xml) { File.read(File.join(Rails.root, 'spec', 'fixtures', 'xml', 'mastodon.atom')) }
let(:xml) { File.read(Rails.root.join('spec', 'fixtures', 'xml', 'mastodon.atom')) }


shared_examples 'return Account' do shared_examples 'return Account' do
it { is_expected.to be_an Account } it { is_expected.to be_an Account }


+ 1
- 1
spec/services/process_feed_service_spec.rb View File

@@ -4,7 +4,7 @@ RSpec.describe ProcessFeedService, type: :service do
subject { ProcessFeedService.new } subject { ProcessFeedService.new }


describe 'processing a feed' do describe 'processing a feed' do
let(:body) { File.read(File.join(Rails.root, 'spec', 'fixtures', 'xml', 'mastodon.atom')) }
let(:body) { File.read(Rails.root.join('spec', 'fixtures', 'xml', 'mastodon.atom')) }
let(:account) { Fabricate(:account, username: 'localhost', domain: 'kickass.zone') } let(:account) { Fabricate(:account, username: 'localhost', domain: 'kickass.zone') }


before do before do


+ 1
- 1
spec/services/update_remote_profile_service_spec.rb View File

@@ -1,7 +1,7 @@
require 'rails_helper' require 'rails_helper'


RSpec.describe UpdateRemoteProfileService, type: :service do RSpec.describe UpdateRemoteProfileService, type: :service do
let(:xml) { File.read(File.join(Rails.root, 'spec', 'fixtures', 'push', 'feed.atom')) }
let(:xml) { File.read(Rails.root.join('spec', 'fixtures', 'push', 'feed.atom')) }


subject { UpdateRemoteProfileService.new } subject { UpdateRemoteProfileService.new }




Loading…
Cancel
Save