From 1701f4cdfb27989a8a07d7f44f2bbea6f6050261 Mon Sep 17 00:00:00 2001 From: Aleksandr Zykov Date: Sun, 6 Dec 2020 19:09:45 +0100 Subject: [PATCH] rubocop fixes --- .rubocop_todo.yml | 40 +----- spec/controllers/deposits_controller_spec.rb | 9 -- spec/controllers/home_controller_spec.rb | 32 ----- spec/controllers/projects_controller_spec.rb | 125 +----------------- spec/controllers/tips_controller_spec.rb | 9 -- spec/controllers/users_controller_spec.rb | 64 --------- .../withdrawals_controller_spec.rb | 9 -- spec/{misc_spec.rb => features/assets.rb} | 2 +- spec/models/send_many_spec.rb | 9 -- spec/routing/deposits_routing_spec.rb | 12 ++ spec/routing/home_routing_spec.rb | 28 ++++ spec/routing/projects_routing_spec.rb | 124 +++++++++++++++++ spec/routing/tips_routing_spec.rb | 12 ++ spec/routing/users_routing_spec.rb | 67 ++++++++++ spec/routing/withdrawals_routing_spec.rb | 12 ++ 15 files changed, 264 insertions(+), 290 deletions(-) rename spec/{misc_spec.rb => features/assets.rb} (90%) delete mode 100644 spec/models/send_many_spec.rb create mode 100644 spec/routing/deposits_routing_spec.rb create mode 100644 spec/routing/home_routing_spec.rb create mode 100644 spec/routing/projects_routing_spec.rb create mode 100644 spec/routing/tips_routing_spec.rb create mode 100644 spec/routing/users_routing_spec.rb create mode 100644 spec/routing/withdrawals_routing_spec.rb diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 02fa5094..708ba3d1 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,6 +1,6 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2020-12-06 17:32:53 UTC using RuboCop version 1.5.2. +# on 2020-12-06 18:08:51 UTC using RuboCop version 1.5.2. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new @@ -11,11 +11,11 @@ Metrics/AbcSize: Max: 34 -# Offense count: 17 +# Offense count: 15 # Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods. # IgnoredMethods: refine Metrics/BlockLength: - Max: 224 + Max: 117 # Offense count: 2 # Configuration parameters: CountComments, CountAsOne. @@ -47,45 +47,22 @@ Naming/PredicateName: Exclude: - 'app/models/project.rb' -# Offense count: 3 +# Offense count: 1 # Configuration parameters: Prefixes. # Prefixes: when, with, without RSpec/ContextWording: Exclude: - 'spec/controllers/projects_controller_spec.rb' -# Offense count: 1 -# Configuration parameters: IgnoredMetadata. -RSpec/DescribeClass: - Exclude: - - 'spec/misc_spec.rb' - # Offense count: 13 # Configuration parameters: Max. RSpec/ExampleLength: Exclude: - 'spec/controllers/projects_controller_spec.rb' - - 'spec/controllers/users_controller_spec.rb' - 'spec/lib/blacklist_spec.rb' - 'spec/models/deposit_spec.rb' - -# Offense count: 25 -# Cop supports --auto-correct. -RSpec/ExpectActual: - Exclude: - - 'spec/controllers/deposits_controller_spec.rb' - - 'spec/controllers/home_controller_spec.rb' - - 'spec/controllers/projects_controller_spec.rb' - - 'spec/controllers/tips_controller_spec.rb' - - 'spec/controllers/users_controller_spec.rb' - - 'spec/controllers/withdrawals_controller_spec.rb' - -# Offense count: 1 -# Configuration parameters: Include, CustomTransform, IgnoreMethods, SpecSuffixOnly. -# Include: **/*_spec*rb*, **/spec/**/* -RSpec/FilePath: - Exclude: - - 'spec/models/send_many_spec.rb' + - 'spec/routing/projects_routing_spec.rb' + - 'spec/routing/users_routing_spec.rb' # Offense count: 2 # Configuration parameters: AssignmentOnly. @@ -117,11 +94,6 @@ RSpec/NamedSubject: RSpec/NestedGroups: Max: 5 -# Offense count: 2 -RSpec/RepeatedExample: - Exclude: - - 'spec/controllers/home_controller_spec.rb' - # Offense count: 2 RSpec/RepeatedExampleGroupBody: Exclude: diff --git a/spec/controllers/deposits_controller_spec.rb b/spec/controllers/deposits_controller_spec.rb index 287e58bf..40f18930 100644 --- a/spec/controllers/deposits_controller_spec.rb +++ b/spec/controllers/deposits_controller_spec.rb @@ -9,13 +9,4 @@ expect(response).to be_successful end end - - describe 'routing' do - it 'routes GET / to Deposits#index' do - expect({ get: '/deposits' }).to route_to( - controller: 'deposits', - action: 'index' - ) - end - end end diff --git a/spec/controllers/home_controller_spec.rb b/spec/controllers/home_controller_spec.rb index 8a6b1e79..09c20eed 100644 --- a/spec/controllers/home_controller_spec.rb +++ b/spec/controllers/home_controller_spec.rb @@ -14,36 +14,4 @@ expect(subject.status).to eq 200 end end - - describe 'routing' do - it 'routes GET / to Home#index' do - expect({ get: '/' }).to route_to( - controller: 'home', - action: 'index' - ) - end - - it 'routes GET /home to Home#index' do - expect({ get: '/' }).to route_to( - controller: 'home', - action: 'index' - ) - end - - it 'routes GET /users/999999/no-such-path to Home#index' do - expect({ get: '/users/999999/no-such-path' }).to route_to( - controller: 'home', - action: 'index', - path: 'users/999999/no-such-path' - ) - end - - it 'routes GET /any/non-existent/path to Home#index' do - expect({ get: '/any/non-existent/path' }).to route_to( - controller: 'home', - action: 'index', - path: 'any/non-existent/path' - ) - end - end end diff --git a/spec/controllers/projects_controller_spec.rb b/spec/controllers/projects_controller_spec.rb index 11f8347f..c166f257 100644 --- a/spec/controllers/projects_controller_spec.rb +++ b/spec/controllers/projects_controller_spec.rb @@ -71,7 +71,7 @@ shared_context 'accessing_project' do |verb, action| let(:a_project) { create :project, host: 'github', full_name: 'test/test' } - context 'existing_project' do + context 'with existsing project' do it 'via project id returns 302 status code' do case verb when :get @@ -93,7 +93,7 @@ end end - context 'nonexisting_project' do + context 'with non-existing project' do it 'via project id returns 302 status code' do case verb when :get @@ -158,125 +158,4 @@ expect(response).to be_redirect end end - - describe 'routing' do - it 'routes GET /projects to Project#index' do - expect({ get: '/projects' }).to route_to( - controller: 'projects', - action: 'index' - ) - end - - it 'routes GET /projects/search?query= to Project#search' do - expect({ get: '/projects/search?query=seldon&order=balance' }).to route_to( - controller: 'projects', - action: 'search', - query: 'seldon', - order: 'balance' - ) - end - - it 'routes GET /projects/1 to Project#show' do - expect({ get: '/projects/1' }).to route_to( - controller: 'projects', - action: 'show', - id: '1' - ) - end - - it 'routes GET /projects/1/edit to Project#edit' do - expect({ get: '/projects/1/edit' }).to route_to( - controller: 'projects', - action: 'edit', - id: '1' - ) - end - - it 'routes PUT /projects/1 to Project#update' do - expect({ put: '/projects/1' }).to route_to( - controller: 'projects', - action: 'update', - id: '1' - ) - end - - it 'routes GET /projects/1/decide_tip_amounts to Project#decide_tip_amounts' do - expect({ get: '/projects/1/decide_tip_amounts' }).to route_to( - controller: 'projects', - action: 'decide_tip_amounts', - id: '1' - ) - end - - it 'routes PATCH /projects/1/decide_tip_amounts to Project#decide_tip_amounts' do - expect({ patch: '/projects/1/decide_tip_amounts' }).to route_to( - controller: 'projects', - action: 'decide_tip_amounts', - id: '1' - ) - end - - it 'routes GET /projects/1/tips to Tips#index' do - expect({ get: '/projects/1/tips' }).to route_to( - controller: 'tips', - action: 'index', - project_id: '1' - ) - end - - it 'routes GET /projects/1/deposits to Deposits#index' do - expect({ get: '/projects/1/deposits' }).to route_to( - controller: 'deposits', - action: 'index', - project_id: '1' - ) - end - end - - describe 'Project pretty url routing' do - it 'routes GET /:provider/:repo to Project#show' do - expect({ get: '/github/test/test' }).to route_to( - controller: 'projects', - action: 'show', - service: 'github', - repo: 'test/test' - ) - end - - it 'routes GET /:provider/:repo/edit to Project#edit' do - expect({ get: '/github/test/test/edit' }).to route_to( - controller: 'projects', - action: 'edit', - service: 'github', - repo: 'test/test' - ) - end - - it 'routes GET /:provider/:repo/decide_tip_amounts to Project#decide_tip_amounts' do - expect({ get: '/github/test/test/decide_tip_amounts' }).to route_to( - controller: 'projects', - action: 'decide_tip_amounts', - service: 'github', - repo: 'test/test' - ) - end - - it 'routes GET /:provider/:repo/tips to Project#tips' do - expect({ get: '/github/test/test/tips' }).to route_to( - controller: 'tips', - action: 'index', - service: 'github', - repo: 'test/test' - ) - end - - it 'routes GET /:provider/:repo/deposits to Project#deposits' do - expect({ get: '/github/test/test/deposits' }).to route_to( - controller: 'deposits', - action: 'index', - service: 'github', - repo: 'test/test' - ) - end - end end diff --git a/spec/controllers/tips_controller_spec.rb b/spec/controllers/tips_controller_spec.rb index d060ccf2..c64e8395 100644 --- a/spec/controllers/tips_controller_spec.rb +++ b/spec/controllers/tips_controller_spec.rb @@ -9,13 +9,4 @@ expect(response).to be_successful end end - - describe 'routing' do - it 'routes GET / to Tips#index' do - expect({ get: '/tips' }).to route_to( - controller: 'tips', - action: 'index' - ) - end - end end diff --git a/spec/controllers/users_controller_spec.rb b/spec/controllers/users_controller_spec.rb index c9c52616..3cc59d1f 100644 --- a/spec/controllers/users_controller_spec.rb +++ b/spec/controllers/users_controller_spec.rb @@ -95,68 +95,4 @@ end end end - - describe 'routing' do - it 'routes GET /users to User#index' do - expect({ get: '/users' }).to route_to( - controller: 'users', - action: 'index' - ) - end - - it 'routes GET /users/nick-name321 to User#show' do - expect({ get: '/users/nick-name321' }).to route_to( - controller: 'users', - action: 'show', - nickname: 'nick-name321' - ) - end - - it 'routes GET /users/login to User#login' do - expect({ get: '/users/login' }).to route_to( - controller: 'users', - action: 'login' - ) - end - - it 'routes GET /users/1/tips to Tips#index' do - expect({ get: '/users/1/tips' }).to route_to( - controller: 'tips', - action: 'index', - user_id: '1' - ) - end - end - - describe 'pretty url routing' do - let(:user) { create(:user) } - - it 'regex rejects reserved user paths' do - # accepted pertty url usernames - should_accept = [' ', 'logi', 'ogin', 's4c2', '42x', 'nick name', 'kd'] - # reserved routes (rejected pertty url usernames) - should_reject = ['', '1', '42'] - - accepted = should_accept.select { |ea| ea =~ /\D+/ } - rejected = should_reject.select { |ea| (ea =~ /\D+/).nil? } - (expect(accepted.size).to eq(should_accept.size)) && - (expect(rejected.size).to eq(should_reject.size)) - end - - it 'routes GET /users/:nickname to User#show' do - expect({ get: "/users/#{user.nickname}" }).to route_to( - controller: 'users', - action: 'show', - nickname: 'kd' - ) - end - - it 'routes GET /users/:nickname/tips to Tips#index' do - expect({ get: "/users/#{user.nickname}/tips" }).to route_to( - controller: 'tips', - action: 'index', - nickname: 'kd' - ) - end - end end diff --git a/spec/controllers/withdrawals_controller_spec.rb b/spec/controllers/withdrawals_controller_spec.rb index d1db2351..6bbbea1f 100644 --- a/spec/controllers/withdrawals_controller_spec.rb +++ b/spec/controllers/withdrawals_controller_spec.rb @@ -9,13 +9,4 @@ expect(response).to be_successful end end - - describe 'routing' do - it 'routes GET / to Withdrawals#index' do - expect({ get: '/withdrawals' }).to route_to( - controller: 'withdrawals', - action: 'index' - ) - end - end end diff --git a/spec/misc_spec.rb b/spec/features/assets.rb similarity index 90% rename from spec/misc_spec.rb rename to spec/features/assets.rb index bd3988b5..1814fabb 100644 --- a/spec/misc_spec.rb +++ b/spec/features/assets.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe 'Misc tets' do +describe 'Assets', type: :feature do let(:locales) { Rails.application.config.available_locales } it 'has a flag image for each locale' do diff --git a/spec/models/send_many_spec.rb b/spec/models/send_many_spec.rb deleted file mode 100644 index 428efb30..00000000 --- a/spec/models/send_many_spec.rb +++ /dev/null @@ -1,9 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -describe Sendmany, type: :model do - describe 'Associations' do - it { is_expected.to have_many :tips } - end -end diff --git a/spec/routing/deposits_routing_spec.rb b/spec/routing/deposits_routing_spec.rb new file mode 100644 index 00000000..8289c3aa --- /dev/null +++ b/spec/routing/deposits_routing_spec.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe 'routes for Deposits', type: :routing do + it 'routes GET / to Deposits#index' do + expect({ get: '/deposits' }).to route_to( + controller: 'deposits', + action: 'index' + ) + end +end diff --git a/spec/routing/home_routing_spec.rb b/spec/routing/home_routing_spec.rb new file mode 100644 index 00000000..b8c3e81d --- /dev/null +++ b/spec/routing/home_routing_spec.rb @@ -0,0 +1,28 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe 'routes for Home', type: :routing do + it 'routes GET / to Home#index' do + expect({ get: '/' }).to route_to( + controller: 'home', + action: 'index' + ) + end + + it 'routes GET /users/999999/no-such-path to Home#index' do + expect({ get: '/users/999999/no-such-path' }).to route_to( + controller: 'home', + action: 'index', + path: 'users/999999/no-such-path' + ) + end + + it 'routes GET /any/non-existent/path to Home#index' do + expect({ get: '/any/non-existent/path' }).to route_to( + controller: 'home', + action: 'index', + path: 'any/non-existent/path' + ) + end +end diff --git a/spec/routing/projects_routing_spec.rb b/spec/routing/projects_routing_spec.rb new file mode 100644 index 00000000..41d1040f --- /dev/null +++ b/spec/routing/projects_routing_spec.rb @@ -0,0 +1,124 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe 'routes for Projects', type: :routing do + it 'routes GET /projects to Project#index' do + expect({ get: '/projects' }).to route_to( + controller: 'projects', + action: 'index' + ) + end + + it 'routes GET /projects/search?query= to Project#search' do + expect({ get: '/projects/search?query=seldon&order=balance' }).to route_to( + controller: 'projects', + action: 'search', + query: 'seldon', + order: 'balance' + ) + end + + it 'routes GET /projects/1 to Project#show' do + expect({ get: '/projects/1' }).to route_to( + controller: 'projects', + action: 'show', + id: '1' + ) + end + + it 'routes GET /projects/1/edit to Project#edit' do + expect({ get: '/projects/1/edit' }).to route_to( + controller: 'projects', + action: 'edit', + id: '1' + ) + end + + it 'routes PUT /projects/1 to Project#update' do + expect({ put: '/projects/1' }).to route_to( + controller: 'projects', + action: 'update', + id: '1' + ) + end + + it 'routes GET /projects/1/decide_tip_amounts to Project#decide_tip_amounts' do + expect({ get: '/projects/1/decide_tip_amounts' }).to route_to( + controller: 'projects', + action: 'decide_tip_amounts', + id: '1' + ) + end + + it 'routes PATCH /projects/1/decide_tip_amounts to Project#decide_tip_amounts' do + expect({ patch: '/projects/1/decide_tip_amounts' }).to route_to( + controller: 'projects', + action: 'decide_tip_amounts', + id: '1' + ) + end + + it 'routes GET /projects/1/tips to Tips#index' do + expect({ get: '/projects/1/tips' }).to route_to( + controller: 'tips', + action: 'index', + project_id: '1' + ) + end + + it 'routes GET /projects/1/deposits to Deposits#index' do + expect({ get: '/projects/1/deposits' }).to route_to( + controller: 'deposits', + action: 'index', + project_id: '1' + ) + end + + describe 'Project pretty url routing' do + it 'routes GET /:provider/:repo to Project#show' do + expect({ get: '/github/test/test' }).to route_to( + controller: 'projects', + action: 'show', + service: 'github', + repo: 'test/test' + ) + end + + it 'routes GET /:provider/:repo/edit to Project#edit' do + expect({ get: '/github/test/test/edit' }).to route_to( + controller: 'projects', + action: 'edit', + service: 'github', + repo: 'test/test' + ) + end + + it 'routes GET /:provider/:repo/decide_tip_amounts to Project#decide_tip_amounts' do + expect({ get: '/github/test/test/decide_tip_amounts' }).to route_to( + controller: 'projects', + action: 'decide_tip_amounts', + service: 'github', + repo: 'test/test' + ) + end + + it 'routes GET /:provider/:repo/tips to Project#tips' do + expect({ get: '/github/test/test/tips' }).to route_to( + controller: 'tips', + action: 'index', + service: 'github', + repo: 'test/test' + ) + end + + it 'routes GET /:provider/:repo/deposits to Project#deposits' do + expect({ get: '/github/test/test/deposits' }).to route_to( + controller: 'deposits', + action: 'index', + service: 'github', + repo: 'test/test' + ) + end + end +end diff --git a/spec/routing/tips_routing_spec.rb b/spec/routing/tips_routing_spec.rb new file mode 100644 index 00000000..23216754 --- /dev/null +++ b/spec/routing/tips_routing_spec.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe 'routes for Tips', type: :routing do + it 'routes GET / to Tips#index' do + expect({ get: '/tips' }).to route_to( + controller: 'tips', + action: 'index' + ) + end +end diff --git a/spec/routing/users_routing_spec.rb b/spec/routing/users_routing_spec.rb new file mode 100644 index 00000000..2f8e6993 --- /dev/null +++ b/spec/routing/users_routing_spec.rb @@ -0,0 +1,67 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe 'routes for Users', type: :routing do + it 'routes GET /users to User#index' do + expect({ get: '/users' }).to route_to( + controller: 'users', + action: 'index' + ) + end + + it 'routes GET /users/nick-name321 to User#show' do + expect({ get: '/users/nick-name321' }).to route_to( + controller: 'users', + action: 'show', + nickname: 'nick-name321' + ) + end + + it 'routes GET /users/login to User#login' do + expect({ get: '/users/login' }).to route_to( + controller: 'users', + action: 'login' + ) + end + + it 'routes GET /users/1/tips to Tips#index' do + expect({ get: '/users/1/tips' }).to route_to( + controller: 'tips', + action: 'index', + user_id: '1' + ) + end + + describe 'pretty url routing' do + let(:user) { create(:user) } + + it 'regex rejects reserved user paths' do + # accepted pertty url usernames + should_accept = [' ', 'logi', 'ogin', 's4c2', '42x', 'nick name', 'kd'] + # reserved routes (rejected pertty url usernames) + should_reject = ['', '1', '42'] + + accepted = should_accept.select { |ea| ea =~ /\D+/ } + rejected = should_reject.select { |ea| (ea =~ /\D+/).nil? } + (expect(accepted.size).to eq(should_accept.size)) && + (expect(rejected.size).to eq(should_reject.size)) + end + + it 'routes GET /users/:nickname to User#show' do + expect({ get: "/users/#{user.nickname}" }).to route_to( + controller: 'users', + action: 'show', + nickname: 'kd' + ) + end + + it 'routes GET /users/:nickname/tips to Tips#index' do + expect({ get: "/users/#{user.nickname}/tips" }).to route_to( + controller: 'tips', + action: 'index', + nickname: 'kd' + ) + end + end +end diff --git a/spec/routing/withdrawals_routing_spec.rb b/spec/routing/withdrawals_routing_spec.rb new file mode 100644 index 00000000..e64eac7f --- /dev/null +++ b/spec/routing/withdrawals_routing_spec.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe 'routes for Withdrawals', type: :routing do + it 'routes GET / to Withdrawals#index' do + expect({ get: '/withdrawals' }).to route_to( + controller: 'withdrawals', + action: 'index' + ) + end +end