From 1f98eae1cf916a18007a26e1740b0e65aa7ff752 Mon Sep 17 00:00:00 2001 From: aus-social <42644106+aus-social@users.noreply.github.com> Date: Thu, 4 Oct 2018 20:36:53 +1000 Subject: Lint pass (#8876) --- spec/controllers/admin/accounts_controller_spec.rb | 1 - spec/controllers/admin/email_domain_blocks_controller_spec.rb | 4 ++-- spec/controllers/admin/invites_controller_spec.rb | 2 +- spec/controllers/admin/report_notes_controller_spec.rb | 11 +++++------ spec/controllers/admin/reported_statuses_controller_spec.rb | 2 +- 5 files changed, 9 insertions(+), 11 deletions(-) (limited to 'spec/controllers/admin') diff --git a/spec/controllers/admin/accounts_controller_spec.rb b/spec/controllers/admin/accounts_controller_spec.rb index 197e019fe..fa2786c9b 100644 --- a/spec/controllers/admin/accounts_controller_spec.rb +++ b/spec/controllers/admin/accounts_controller_spec.rb @@ -75,7 +75,6 @@ RSpec.describe Admin::AccountsController, type: :controller do end end - describe 'POST #subscribe' do subject { post :subscribe, params: { id: account.id } } diff --git a/spec/controllers/admin/email_domain_blocks_controller_spec.rb b/spec/controllers/admin/email_domain_blocks_controller_spec.rb index 133d38ff1..52db56f4e 100644 --- a/spec/controllers/admin/email_domain_blocks_controller_spec.rb +++ b/spec/controllers/admin/email_domain_blocks_controller_spec.rb @@ -40,7 +40,7 @@ RSpec.describe Admin::EmailDomainBlocksController, type: :controller do describe 'POST #create' do it 'blocks the domain when succeeded to save' do - post :create, params: { email_domain_block: { domain: 'example.com'} } + post :create, params: { email_domain_block: { domain: 'example.com' } } expect(flash[:notice]).to eq I18n.t('admin.email_domain_blocks.created_msg') expect(response).to redirect_to(admin_email_domain_blocks_path) @@ -50,7 +50,7 @@ RSpec.describe Admin::EmailDomainBlocksController, type: :controller do describe 'DELETE #destroy' do it 'unblocks the domain' do email_domain_block = Fabricate(:email_domain_block) - delete :destroy, params: { id: email_domain_block.id } + delete :destroy, params: { id: email_domain_block.id } expect(flash[:notice]).to eq I18n.t('admin.email_domain_blocks.destroyed_msg') expect(response).to redirect_to(admin_email_domain_blocks_path) diff --git a/spec/controllers/admin/invites_controller_spec.rb b/spec/controllers/admin/invites_controller_spec.rb index e7d995411..34b51a6aa 100644 --- a/spec/controllers/admin/invites_controller_spec.rb +++ b/spec/controllers/admin/invites_controller_spec.rb @@ -24,7 +24,7 @@ describe Admin::InvitesController do subject { post :create, params: { invite: { max_uses: '10', expires_in: 1800 } } } it 'succeeds to create a invite' do - expect{ subject }.to change { Invite.count }.by(1) + expect { subject }.to change { Invite.count }.by(1) expect(subject).to redirect_to admin_invites_path expect(Invite.last).to have_attributes(user_id: user.id, max_uses: 10) end diff --git a/spec/controllers/admin/report_notes_controller_spec.rb b/spec/controllers/admin/report_notes_controller_spec.rb index 2c32303fb..ec5872c7d 100644 --- a/spec/controllers/admin/report_notes_controller_spec.rb +++ b/spec/controllers/admin/report_notes_controller_spec.rb @@ -15,7 +15,6 @@ describe Admin::ReportNotesController do let(:report) { Fabricate(:report, action_taken: action_taken, action_taken_by_account_id: account_id) } context 'when parameter is valid' do - context 'when report is unsolved' do let(:action_taken) { false } let(:account_id) { nil } @@ -24,7 +23,7 @@ describe Admin::ReportNotesController do let(:params) { { report_note: { content: 'test content', report_id: report.id }, create_and_resolve: nil } } it 'creates a report note and resolves report' do - expect{ subject }.to change{ ReportNote.count }.by(1) + expect { subject }.to change { ReportNote.count }.by(1) expect(report.reload).to be_action_taken expect(subject).to redirect_to admin_reports_path end @@ -34,7 +33,7 @@ describe Admin::ReportNotesController do let(:params) { { report_note: { content: 'test content', report_id: report.id } } } it 'creates a report note and does not resolve report' do - expect{ subject }.to change{ ReportNote.count }.by(1) + expect { subject }.to change { ReportNote.count }.by(1) expect(report.reload).not_to be_action_taken expect(subject).to redirect_to admin_report_path(report) end @@ -49,7 +48,7 @@ describe Admin::ReportNotesController do let(:params) { { report_note: { content: 'test content', report_id: report.id }, create_and_unresolve: nil } } it 'creates a report note and unresolves report' do - expect{ subject }.to change{ ReportNote.count }.by(1) + expect { subject }.to change { ReportNote.count }.by(1) expect(report.reload).not_to be_action_taken expect(subject).to redirect_to admin_report_path(report) end @@ -59,7 +58,7 @@ describe Admin::ReportNotesController do let(:params) { { report_note: { content: 'test content', report_id: report.id } } } it 'creates a report note and does not unresolve report' do - expect{ subject }.to change{ ReportNote.count }.by(1) + expect { subject }.to change { ReportNote.count }.by(1) expect(report.reload).to be_action_taken expect(subject).to redirect_to admin_report_path(report) end @@ -84,7 +83,7 @@ describe Admin::ReportNotesController do let!(:report_note) { Fabricate(:report_note) } it 'deletes note' do - expect{ subject }.to change{ ReportNote.count }.by(-1) + expect { subject }.to change { ReportNote.count }.by(-1) expect(subject).to redirect_to admin_report_path(report_note.report) end end diff --git a/spec/controllers/admin/reported_statuses_controller_spec.rb b/spec/controllers/admin/reported_statuses_controller_spec.rb index 7adbf36b9..c358506d6 100644 --- a/spec/controllers/admin/reported_statuses_controller_spec.rb +++ b/spec/controllers/admin/reported_statuses_controller_spec.rb @@ -13,7 +13,7 @@ describe Admin::ReportedStatusesController do describe 'POST #create' do subject do - -> { post :create, params: { :report_id => report, action => '', :form_status_batch => { status_ids: status_ids } } } + -> { post :create, params: { :report_id => report, action => '', :form_status_batch => { status_ids: status_ids } } } end let(:action) { 'nsfw_on' } -- cgit From e645ae95610fcb69d15366bc32ab60014d2ebdcf Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Thu, 4 Oct 2018 16:05:38 +0200 Subject: Change admin accounts default sort to most recent (#8813) --- app/controllers/admin/accounts_controller.rb | 2 +- app/helpers/admin/filter_helper.rb | 2 +- app/models/account_filter.rb | 6 +++--- app/views/admin/accounts/index.html.haml | 4 ++-- spec/controllers/admin/accounts_controller_spec.rb | 4 ++-- spec/models/account_filter_spec.rb | 6 +++--- 6 files changed, 12 insertions(+), 12 deletions(-) (limited to 'spec/controllers/admin') diff --git a/app/controllers/admin/accounts_controller.rb b/app/controllers/admin/accounts_controller.rb index e7ca6b907..5d57fe361 100644 --- a/app/controllers/admin/accounts_controller.rb +++ b/app/controllers/admin/accounts_controller.rb @@ -95,7 +95,7 @@ module Admin :remote, :by_domain, :silenced, - :recent, + :alphabetic, :suspended, :username, :display_name, diff --git a/app/helpers/admin/filter_helper.rb b/app/helpers/admin/filter_helper.rb index 359c43d0e..60e5142e3 100644 --- a/app/helpers/admin/filter_helper.rb +++ b/app/helpers/admin/filter_helper.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true module Admin::FilterHelper - ACCOUNT_FILTERS = %i(local remote by_domain silenced suspended recent username display_name email ip staff).freeze + ACCOUNT_FILTERS = %i(local remote by_domain silenced suspended alphabetic username display_name email ip staff).freeze REPORT_FILTERS = %i(resolved account_id target_account_id).freeze INVITE_FILTER = %i(available expired).freeze CUSTOM_EMOJI_FILTERS = %i(local remote by_domain shortcode).freeze diff --git a/app/models/account_filter.rb b/app/models/account_filter.rb index dc7a03039..84364bf1b 100644 --- a/app/models/account_filter.rb +++ b/app/models/account_filter.rb @@ -8,7 +8,7 @@ class AccountFilter end def results - scope = Account.alphabetic + scope = Account.recent params.each do |key, value| scope.merge!(scope_for(key, value)) if value.present? @@ -29,8 +29,8 @@ class AccountFilter Account.where(domain: value) when 'silenced' Account.silenced - when 'recent' - Account.recent + when 'alphabetic' + Account.reorder(nil).alphabetic when 'suspended' Account.suspended when 'username' diff --git a/app/views/admin/accounts/index.html.haml b/app/views/admin/accounts/index.html.haml index 6aa39a80a..4bee73adc 100644 --- a/app/views/admin/accounts/index.html.haml +++ b/app/views/admin/accounts/index.html.haml @@ -38,8 +38,8 @@ .filter-subset %strong= t('admin.accounts.order.title') %ul - %li= filter_link_to t('admin.accounts.order.alphabetic'), recent: nil - %li= filter_link_to t('admin.accounts.order.most_recent'), recent: '1' + %li= filter_link_to t('admin.accounts.order.most_recent'), alphabetic: nil + %li= filter_link_to t('admin.accounts.order.alphabetic'), alphabetic: '1' = form_tag admin_accounts_url, method: 'GET', class: 'simple_form' do .fields-group diff --git a/spec/controllers/admin/accounts_controller_spec.rb b/spec/controllers/admin/accounts_controller_spec.rb index fa2786c9b..ae9e058c8 100644 --- a/spec/controllers/admin/accounts_controller_spec.rb +++ b/spec/controllers/admin/accounts_controller_spec.rb @@ -25,7 +25,7 @@ RSpec.describe Admin::AccountsController, type: :controller do expect(h[:remote]).to eq '1' expect(h[:by_domain]).to eq 'domain' expect(h[:silenced]).to eq '1' - expect(h[:recent]).to eq '1' + expect(h[:alphabetic]).to eq '1' expect(h[:suspended]).to eq '1' expect(h[:username]).to eq 'username' expect(h[:display_name]).to eq 'display name' @@ -40,7 +40,7 @@ RSpec.describe Admin::AccountsController, type: :controller do remote: '1', by_domain: 'domain', silenced: '1', - recent: '1', + alphabetic: '1', suspended: '1', username: 'username', display_name: 'display name', diff --git a/spec/models/account_filter_spec.rb b/spec/models/account_filter_spec.rb index 8441939c5..0a0252642 100644 --- a/spec/models/account_filter_spec.rb +++ b/spec/models/account_filter_spec.rb @@ -2,10 +2,10 @@ require 'rails_helper' describe AccountFilter do describe 'with empty params' do - it 'defaults to alphabetic account list' do + it 'defaults to recent account list' do filter = described_class.new({}) - expect(filter.results).to eq Account.alphabetic + expect(filter.results).to eq Account.recent end end @@ -60,7 +60,7 @@ describe AccountFilter do end describe 'that call account methods' do - %i(local remote silenced recent suspended).each do |option| + %i(local remote silenced alphabetic suspended).each do |option| it "delegates the #{option} option" do allow(Account).to receive(option).and_return(Account.none) filter = described_class.new({ option => true }) -- cgit From 0a4739c7324a96cee148373ccc7b57b9c7097b42 Mon Sep 17 00:00:00 2001 From: aus-social <42644106+aus-social@users.noreply.github.com> Date: Fri, 5 Oct 2018 01:38:04 +1000 Subject: lint pass 2 (#8878) * Code quality pass * Typofix * Update applications_controller_spec.rb * Update applications_controller_spec.rb --- config/environments/production.rb | 2 +- config/initializers/http_client_proxy.rb | 2 +- config/initializers/omniauth.rb | 2 +- config/initializers/open_uri_redirection.rb | 2 +- config/initializers/rack_attack.rb | 2 +- config/initializers/sidekiq.rb | 2 +- config/puma.rb | 2 +- .../20160314164231_add_owner_to_application.rb | 2 +- ...105224407_add_shortcode_to_media_attachments.rb | 4 +- spec/controllers/admin/statuses_controller_spec.rb | 2 +- .../concerns/export_controller_concern_spec.rb | 1 + .../settings/applications_controller_spec.rb | 64 +++++++++++----------- spec/models/account_spec.rb | 2 +- spec/models/user_spec.rb | 2 +- spec/views/stream_entries/show.html.haml_spec.rb | 2 +- 15 files changed, 47 insertions(+), 46 deletions(-) (limited to 'spec/controllers/admin') diff --git a/config/environments/production.rb b/config/environments/production.rb index 30239671c..ed2d885b0 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -42,7 +42,7 @@ Rails.application.configure do config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX # Allow to specify public IP of reverse proxy if it's needed - config.action_dispatch.trusted_proxies = ENV['TRUSTED_PROXY_IP'].split.map { |item| IPAddr.new(item) } unless ENV['TRUSTED_PROXY_IP'].blank? + config.action_dispatch.trusted_proxies = ENV['TRUSTED_PROXY_IP'].split.map { |item| IPAddr.new(item) } if ENV['TRUSTED_PROXY_IP'].present? # Use the lowest log level to ensure availability of diagnostic information # when problems arise. diff --git a/config/initializers/http_client_proxy.rb b/config/initializers/http_client_proxy.rb index e607aff3c..9d7b16e69 100644 --- a/config/initializers/http_client_proxy.rb +++ b/config/initializers/http_client_proxy.rb @@ -6,7 +6,7 @@ Rails.application.configure do raise "No proxy host" unless proxy.host host = proxy.host - host = host[1...-1] if host[0] == '[' #for IPv6 address + host = host[1...-1] if host[0] == '[' # for IPv6 address config.x.http_client_proxy[:proxy] = { proxy_address: host, proxy_port: proxy.port, proxy_username: proxy.user, proxy_password: proxy.password }.compact end diff --git a/config/initializers/omniauth.rb b/config/initializers/omniauth.rb index 21b58eb5b..254e751d4 100644 --- a/config/initializers/omniauth.rb +++ b/config/initializers/omniauth.rb @@ -3,7 +3,7 @@ Rails.application.config.middleware.use OmniAuth::Builder do end Devise.setup do |config| - # Devise omniauth strategies + # Devise omniauth strategies options = {} options[:redirect_at_sign_in] = ENV['OAUTH_REDIRECT_AT_SIGN_IN'] == 'true' diff --git a/config/initializers/open_uri_redirection.rb b/config/initializers/open_uri_redirection.rb index e24fdecab..ea2dcffea 100644 --- a/config/initializers/open_uri_redirection.rb +++ b/config/initializers/open_uri_redirection.rb @@ -1,7 +1,7 @@ require 'open-uri' module OpenURI - def OpenURI.redirectable?(uri1, uri2) # :nodoc: + def self.redirectable?(uri1, uri2) # :nodoc: uri1.scheme.downcase == uri2.scheme.downcase || (/\A(?:http|https|ftp)\z/i =~ uri1.scheme && /\A(?:http|https|ftp)\z/i =~ uri2.scheme) end diff --git a/config/initializers/rack_attack.rb b/config/initializers/rack_attack.rb index 0ca0a7e7f..8756b8fbf 100644 --- a/config/initializers/rack_attack.rb +++ b/config/initializers/rack_attack.rb @@ -42,7 +42,7 @@ class Rack::Attack # (blocklist & throttles are skipped) Rack::Attack.safelist('allow from localhost') do |req| # Requests are allowed if the return value is truthy - '127.0.0.1' == req.ip || '::1' == req.ip + req.ip == '127.0.0.1' || req.ip == '::1' end throttle('throttle_authenticated_api', limit: 300, period: 5.minutes) do |req| diff --git a/config/initializers/sidekiq.rb b/config/initializers/sidekiq.rb index 05c804100..7f8a40d7b 100644 --- a/config/initializers/sidekiq.rb +++ b/config/initializers/sidekiq.rb @@ -19,4 +19,4 @@ Sidekiq.configure_client do |config| config.redis = redis_params end -Sidekiq::Logging.logger.level = ::Logger::const_get(ENV.fetch('RAILS_LOG_LEVEL', 'info').upcase.to_s) +Sidekiq::Logging.logger.level = ::Logger.const_get(ENV.fetch('RAILS_LOG_LEVEL', 'info').upcase.to_s) diff --git a/config/puma.rb b/config/puma.rb index 0397b8920..5ebf5ed19 100644 --- a/config/puma.rb +++ b/config/puma.rb @@ -1,7 +1,7 @@ threads_count = ENV.fetch('MAX_THREADS') { 5 }.to_i threads threads_count, threads_count -if ENV['SOCKET'] then +if ENV['SOCKET'] bind 'unix://' + ENV['SOCKET'] else port ENV.fetch('PORT') { 3000 } diff --git a/db/migrate/20160314164231_add_owner_to_application.rb b/db/migrate/20160314164231_add_owner_to_application.rb index 1919f09a1..553c18b5e 100644 --- a/db/migrate/20160314164231_add_owner_to_application.rb +++ b/db/migrate/20160314164231_add_owner_to_application.rb @@ -4,4 +4,4 @@ class AddOwnerToApplication < ActiveRecord::Migration[4.2] add_column :oauth_applications, :owner_type, :string, null: true add_index :oauth_applications, [:owner_id, :owner_type] end -end \ No newline at end of file +end diff --git a/db/migrate/20170105224407_add_shortcode_to_media_attachments.rb b/db/migrate/20170105224407_add_shortcode_to_media_attachments.rb index 2685ae150..fba46a4b6 100644 --- a/db/migrate/20170105224407_add_shortcode_to_media_attachments.rb +++ b/db/migrate/20170105224407_add_shortcode_to_media_attachments.rb @@ -8,7 +8,7 @@ class AddShortcodeToMediaAttachments < ActiveRecord::Migration[5.0] end def down - remove_index :media_attachments, :shortcode - remove_column :media_attachments, :shortcode + remove_index :media_attachments, :shortcode + remove_column :media_attachments, :shortcode end end diff --git a/spec/controllers/admin/statuses_controller_spec.rb b/spec/controllers/admin/statuses_controller_spec.rb index 6afcc1442..1a08c10b7 100644 --- a/spec/controllers/admin/statuses_controller_spec.rb +++ b/spec/controllers/admin/statuses_controller_spec.rb @@ -24,7 +24,7 @@ describe Admin::StatusesController do end it 'returns http success with media' do - get :index, params: { account_id: account.id , media: true } + get :index, params: { account_id: account.id, media: true } statuses = assigns(:statuses).to_a expect(statuses.size).to eq 1 diff --git a/spec/controllers/concerns/export_controller_concern_spec.rb b/spec/controllers/concerns/export_controller_concern_spec.rb index 6a13db69d..e5861c801 100644 --- a/spec/controllers/concerns/export_controller_concern_spec.rb +++ b/spec/controllers/concerns/export_controller_concern_spec.rb @@ -8,6 +8,7 @@ describe ApplicationController, type: :controller do def index send_export_file end + def export_data @export.account.username end diff --git a/spec/controllers/settings/applications_controller_spec.rb b/spec/controllers/settings/applications_controller_spec.rb index fd4b10071..29c278148 100644 --- a/spec/controllers/settings/applications_controller_spec.rb +++ b/spec/controllers/settings/applications_controller_spec.rb @@ -47,13 +47,13 @@ describe Settings::ApplicationsController do context 'success (passed scopes as a String)' do def call_create post :create, params: { - doorkeeper_application: { - name: 'My New App', - redirect_uri: 'urn:ietf:wg:oauth:2.0:oob', - website: 'http://google.com', - scopes: 'read write follow' - } - } + doorkeeper_application: { + name: 'My New App', + redirect_uri: 'urn:ietf:wg:oauth:2.0:oob', + website: 'http://google.com', + scopes: 'read write follow' + } + } response end @@ -69,13 +69,13 @@ describe Settings::ApplicationsController do context 'success (passed scopes as an Array)' do def call_create post :create, params: { - doorkeeper_application: { - name: 'My New App', - redirect_uri: 'urn:ietf:wg:oauth:2.0:oob', - website: 'http://google.com', - scopes: [ 'read', 'write', 'follow' ] - } - } + doorkeeper_application: { + name: 'My New App', + redirect_uri: 'urn:ietf:wg:oauth:2.0:oob', + website: 'http://google.com', + scopes: [ 'read', 'write', 'follow' ] + } + } response end @@ -91,13 +91,13 @@ describe Settings::ApplicationsController do context 'failure' do before do post :create, params: { - doorkeeper_application: { - name: '', - redirect_uri: '', - website: '', - scopes: [] - } - } + doorkeeper_application: { + name: '', + redirect_uri: '', + website: '', + scopes: [] + } + } end it 'returns http success' do @@ -120,9 +120,9 @@ describe Settings::ApplicationsController do def call_update patch :update, params: { - id: app.id, - doorkeeper_application: opts - } + id: app.id, + doorkeeper_application: opts + } response end @@ -139,14 +139,14 @@ describe Settings::ApplicationsController do context 'failure' do before do patch :update, params: { - id: app.id, - doorkeeper_application: { - name: '', - redirect_uri: '', - website: '', - scopes: [] - } - } + id: app.id, + doorkeeper_application: { + name: '', + redirect_uri: '', + website: '', + scopes: [] + } + } end it 'returns http success' do diff --git a/spec/models/account_spec.rb b/spec/models/account_spec.rb index ae19251ae..60d13d32e 100644 --- a/spec/models/account_spec.rb +++ b/spec/models/account_spec.rb @@ -275,7 +275,7 @@ RSpec.describe Account, type: :model do subject { Fabricate(:account) } - context 'when the status is a reblog of another status'do + context 'when the status is a reblog of another status' do let(:original_reblog) do author = Fabricate(:account, username: 'original_reblogger') Fabricate(:status, reblog: original_status, account: author) diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 015e90edc..42198cb4d 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -254,7 +254,7 @@ RSpec.describe User, type: :model do it_behaves_like 'Settings-extended' do def create! - User.create!(account: Fabricate(:account), email: 'foo@mastodon.space', password: 'abcd1234' ) + User.create!(account: Fabricate(:account), email: 'foo@mastodon.space', password: 'abcd1234') end def fabricate diff --git a/spec/views/stream_entries/show.html.haml_spec.rb b/spec/views/stream_entries/show.html.haml_spec.rb index e08419596..93f0adb99 100644 --- a/spec/views/stream_entries/show.html.haml_spec.rb +++ b/spec/views/stream_entries/show.html.haml_spec.rb @@ -49,7 +49,7 @@ describe 'stream_entries/show.html.haml', without_verify_partial_doubles: true d assign(:stream_entry, reply.stream_entry) assign(:account, alice) assign(:type, reply.stream_entry.activity_type.downcase) - assign(:ancestors, reply.stream_entry.activity.ancestors(1, bob) ) + assign(:ancestors, reply.stream_entry.activity.ancestors(1, bob)) assign(:descendant_threads, [{ statuses: reply.stream_entry.activity.descendants(1) }]) render -- cgit