Browse Source

rubocop issues - Cleaning up (#8912)

* cleanup pass

* undo mistakes

* fixed.

* revert
pull/3/head
ashleyhull-versent 9 months ago
parent
commit
f194857ac9

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

@@ -26,7 +26,7 @@ module Omniauthable
26 26
       # to prevent the identity being locked with accidentally created accounts.
27 27
       # Note that this may leave zombie accounts (with no associated identity) which
28 28
       # can be cleaned up at a later date.
29
-      user = signed_in_resource ? signed_in_resource : identity.user
29
+      user = signed_in_resource || identity.user
30 30
       user = create_for_oauth(auth) if user.nil?
31 31
 
32 32
       if identity.user.nil?
@@ -61,7 +61,7 @@ module Omniauthable
61 61
       display_name      = auth.info.full_name || [auth.info.first_name, auth.info.last_name].join(' ')
62 62
 
63 63
       {
64
-        email: email ? email : "#{TEMP_EMAIL_PREFIX}-#{auth.uid}-#{auth.provider}.com",
64
+        email: email || "#{TEMP_EMAIL_PREFIX}-#{auth.uid}-#{auth.provider}.com",
65 65
         password: Devise.friendly_token[0, 20],
66 66
         account_attributes: {
67 67
           username: ensure_unique_username(auth.uid),

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

@@ -2,7 +2,7 @@ require 'open-uri'
2 2
 
3 3
 module OpenURI
4 4
   def self.redirectable?(uri1, uri2) # :nodoc:
5
-    uri1.scheme.downcase == uri2.scheme.downcase ||
5
+    uri1.scheme.casecmp(uri2.scheme).zero? ||
6 6
       (/\A(?:http|https|ftp)\z/i =~ uri1.scheme && /\A(?:http|https|ftp)\z/i =~ uri2.scheme)
7 7
   end
8 8
 end

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

@@ -342,8 +342,8 @@ module Mastodon
342 342
 
343 343
       say "Migrating #{table_name}.#{column} (~#{total.to_i} rows)"
344 344
 
345
-      started_time = Time.now
346
-      last_time = Time.now
345
+      started_time = Time.zone.now
346
+      last_time = Time.zone.now
347 347
       migrated = 0
348 348
       loop do
349 349
         stop_row = nil
@@ -375,13 +375,13 @@ module Mastodon
375 375
         end
376 376
 
377 377
         migrated += batch_size
378
-        if Time.now - last_time > 1
378
+        if Time.zone.now - last_time > 1
379 379
           status = "Migrated #{migrated} rows"
380 380
 
381 381
           percentage = 100.0 * migrated / total
382 382
           status += " (~#{sprintf('%.2f', percentage)}%, "
383 383
 
384
-          remaining_time = (100.0 - percentage) * (Time.now - started_time) / percentage
384
+          remaining_time = (100.0 - percentage) * (Time.zone.now - started_time) / percentage
385 385
 
386 386
           status += "#{(remaining_time / 60).to_i}:"
387 387
           status += sprintf('%02d', remaining_time.to_i % 60)
@@ -397,7 +397,7 @@ module Mastodon
397 397
           status += ')'
398 398
 
399 399
           say status, true
400
-          last_time = Time.now
400
+          last_time = Time.zone.now
401 401
         end
402 402
 
403 403
         # 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
15 15
   describe 'POST #update' do
16 16
     context 'with valid post data' do
17 17
       before do
18
-        post :update, params: { id: account.id }, body: File.read(File.join(Rails.root, 'spec', 'fixtures', 'salmon', 'mention.xml'))
18
+        post :update, params: { id: account.id }, body: File.read(Rails.root.join('spec', 'fixtures', 'salmon', 'mention.xml'))
19 19
       end
20 20
 
21 21
       it 'contains XML in the request body' do
@@ -54,7 +54,7 @@ RSpec.describe Api::SalmonController, type: :controller do
54 54
         service = double(call: false)
55 55
         allow(VerifySalmonService).to receive(:new).and_return(service)
56 56
 
57
-        post :update, params: { id: account.id }, body: File.read(File.join(Rails.root, 'spec', 'fixtures', 'salmon', 'mention.xml'))
57
+        post :update, params: { id: account.id }, body: File.read(Rails.root.join('spec', 'fixtures', 'salmon', 'mention.xml'))
58 58
       end
59 59
 
60 60
       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
33 33
   end
34 34
 
35 35
   describe 'POST #update' do
36
-    let(:feed) { File.read(File.join(Rails.root, 'spec', 'fixtures', 'push', 'feed.atom')) }
36
+    let(:feed) { File.read(Rails.root.join('spec', 'fixtures', 'push', 'feed.atom')) }
37 37
 
38 38
     before do
39 39
       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
2 2
   account
3 3
   email        { sequence(:email) { |i| "#{i}#{Faker::Internet.email}" } }
4 4
   password     "123456789"
5
-  confirmed_at { Time.now }
5
+  confirmed_at { Time.zone.now }
6 6
 end

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

@@ -3,7 +3,7 @@ require "rails_helper"
3 3
 feature "Log in" do
4 4
   given(:email)        { "test@examle.com" }
5 5
   given(:password)     { "password" }
6
-  given(:confirmed_at) { Time.now }
6
+  given(:confirmed_at) { Time.zone.now }
7 7
 
8 8
   background do
9 9
     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
728 728
     it 'appends id element with unique tag' do
729 729
       block = Fabricate(:block)
730 730
 
731
-      time_before = Time.now
731
+      time_before = Time.zone.now
732 732
       block_salmon = OStatus::AtomSerializer.new.block_salmon(block)
733
-      time_after = Time.now
733
+      time_after = Time.zone.now
734 734
 
735 735
       expect(block_salmon.id.text).to(
736 736
         eq(OStatus::TagManager.instance.unique_tag(time_before.utc, block.id, 'Block'))
@@ -815,9 +815,9 @@ RSpec.describe OStatus::AtomSerializer do
815 815
     it 'appends id element with unique tag' do
816 816
       block = Fabricate(:block)
817 817
 
818
-      time_before = Time.now
818
+      time_before = Time.zone.now
819 819
       unblock_salmon = OStatus::AtomSerializer.new.unblock_salmon(block)
820
-      time_after = Time.now
820
+      time_after = Time.zone.now
821 821
 
822 822
       expect(unblock_salmon.id.text).to(
823 823
         eq(OStatus::TagManager.instance.unique_tag(time_before.utc, block.id, 'Block'))
@@ -994,9 +994,9 @@ RSpec.describe OStatus::AtomSerializer do
994 994
     it 'appends id element with unique tag' do
995 995
       favourite = Fabricate(:favourite)
996 996
 
997
-      time_before = Time.now
997
+      time_before = Time.zone.now
998 998
       unfavourite_salmon = OStatus::AtomSerializer.new.unfavourite_salmon(favourite)
999
-      time_after = Time.now
999
+      time_after = Time.zone.now
1000 1000
 
1001 1001
       expect(unfavourite_salmon.id.text).to(
1002 1002
         eq(OStatus::TagManager.instance.unique_tag(time_before.utc, favourite.id, 'Favourite'))
@@ -1179,9 +1179,9 @@ RSpec.describe OStatus::AtomSerializer do
1179 1179
       follow = Fabricate(:follow)
1180 1180
       follow.destroy!
1181 1181
 
1182
-      time_before = Time.now
1182
+      time_before = Time.zone.now
1183 1183
       unfollow_salmon = OStatus::AtomSerializer.new.unfollow_salmon(follow)
1184
-      time_after = Time.now
1184
+      time_after = Time.zone.now
1185 1185
 
1186 1186
       expect(unfollow_salmon.id.text).to(
1187 1187
         eq(OStatus::TagManager.instance.unique_tag(time_before.utc, follow.id, 'Follow'))
@@ -1327,9 +1327,9 @@ RSpec.describe OStatus::AtomSerializer do
1327 1327
     it 'appends id element with unique tag' do
1328 1328
       follow_request = Fabricate(:follow_request)
1329 1329
 
1330
-      time_before = Time.now
1330
+      time_before = Time.zone.now
1331 1331
       authorize_follow_request_salmon = OStatus::AtomSerializer.new.authorize_follow_request_salmon(follow_request)
1332
-      time_after = Time.now
1332
+      time_after = Time.zone.now
1333 1333
 
1334 1334
       expect(authorize_follow_request_salmon.id.text).to(
1335 1335
         eq(OStatus::TagManager.instance.unique_tag(time_before.utc, follow_request.id, 'FollowRequest'))
@@ -1396,9 +1396,9 @@ RSpec.describe OStatus::AtomSerializer do
1396 1396
     it 'appends id element with unique tag' do
1397 1397
       follow_request = Fabricate(:follow_request)
1398 1398
 
1399
-      time_before = Time.now
1399
+      time_before = Time.zone.now
1400 1400
       reject_follow_request_salmon = OStatus::AtomSerializer.new.reject_follow_request_salmon(follow_request)
1401
-      time_after = Time.now
1401
+      time_after = Time.zone.now
1402 1402
 
1403 1403
       expect(reject_follow_request_salmon.id.text).to(
1404 1404
         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
154 154
 
155 155
   describe '#target' do
156 156
     it 'returns nil if the status is self-contained' do
157
-     expect(subject.target).to be_nil
157
+      expect(subject.target).to be_nil
158 158
     end
159 159
 
160 160
     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
67 67
     describe 'confirmed' do
68 68
       it 'returns an array of users who are confirmed' do
69 69
         user_1 = Fabricate(:user, confirmed_at: nil)
70
-        user_2 = Fabricate(:user, confirmed_at: Time.now)
70
+        user_2 = Fabricate(:user, confirmed_at: Time.zone.now)
71 71
         expect(User.confirmed).to match_array([user_2])
72 72
       end
73 73
     end

+ 2
- 2
spec/rails_helper.rb View File

@@ -72,11 +72,11 @@ RSpec::Sidekiq.configure do |config|
72 72
 end
73 73
 
74 74
 def request_fixture(name)
75
-  File.read(File.join(Rails.root, 'spec', 'fixtures', 'requests', name))
75
+  File.read(Rails.root.join('spec', 'fixtures', 'requests', name))
76 76
 end
77 77
 
78 78
 def attachment_fixture(name)
79
-  File.open(File.join(Rails.root, 'spec', 'fixtures', 'files', name))
79
+  File.open(Rails.root.join('spec', 'fixtures', 'files', name))
80 80
 end
81 81
 
82 82
 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
19 19
     stub_request(:post, 'http://example.com/inbox').to_return(status: 200)
20 20
 
21 21
     Fabricate(:subscription, account: alice, callback_url: 'http://example.com/push', confirmed: true, expires_at: 30.days.from_now)
22
-    jeff.user.update(current_sign_in_at: Time.now)
22
+    jeff.user.update(current_sign_in_at: Time.zone.now)
23 23
     jeff.follow!(alice)
24 24
     hank.follow!(alice)
25 25
 

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

@@ -19,7 +19,7 @@ RSpec.describe FetchRemoteAccountService, type: :service do
19 19
   end
20 20
 
21 21
   let(:webfinger) { { subject: 'acct:alice@example.com', links: [{ rel: 'self', href: 'https://example.com/alice' }] } }
22
-  let(:xml) { File.read(File.join(Rails.root, 'spec', 'fixtures', 'xml', 'mastodon.atom')) }
22
+  let(:xml) { File.read(Rails.root.join('spec', 'fixtures', 'xml', 'mastodon.atom')) }
23 23
 
24 24
   shared_examples 'return Account' do
25 25
     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
4 4
   subject { ProcessFeedService.new }
5 5
 
6 6
   describe 'processing a feed' do
7
-    let(:body) { File.read(File.join(Rails.root, 'spec', 'fixtures', 'xml', 'mastodon.atom')) }
7
+    let(:body) { File.read(Rails.root.join('spec', 'fixtures', 'xml', 'mastodon.atom')) }
8 8
     let(:account) { Fabricate(:account, username: 'localhost', domain: 'kickass.zone') }
9 9
 
10 10
     before do

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

@@ -1,7 +1,7 @@
1 1
 require 'rails_helper'
2 2
 
3 3
 RSpec.describe UpdateRemoteProfileService, type: :service do
4
-  let(:xml) { File.read(File.join(Rails.root, 'spec', 'fixtures', 'push', 'feed.atom')) }
4
+  let(:xml) { File.read(Rails.root.join('spec', 'fixtures', 'push', 'feed.atom')) }
5 5
 
6 6
   subject { UpdateRemoteProfileService.new }
7 7
 

Loading…
Cancel
Save