From 86a1abf62a46c280779edbb7efcf08a11908c75d Mon Sep 17 00:00:00 2001 From: Robert Brodie Date: Sun, 28 Apr 2024 02:41:47 -0400 Subject: [PATCH 01/59] Initialize Rubocop, work on files in the root --- .rubocop.yml | 5 +++++ Gemfile | 4 ++++ Guardfile | 2 ++ Rakefile | 7 +++---- jira-ruby.gemspec | 7 +++++-- 5 files changed, 19 insertions(+), 6 deletions(-) create mode 100644 .rubocop.yml diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 00000000..3affd351 --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,5 @@ +require: + - rubocop-rspec + +AllCops: + NewCops: enable \ No newline at end of file diff --git a/Gemfile b/Gemfile index 4912c25c..82a5d33b 100644 --- a/Gemfile +++ b/Gemfile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + source 'https://rubygems.org' group :development do @@ -8,6 +10,8 @@ end group :development, :test do gem 'pry' # this was in the original Gemfile - but only needed in development & test + gem 'rubocop' + gem 'rubocop-rspec', require: false end # Specify your gem's dependencies in jira_api.gemspec diff --git a/Guardfile b/Guardfile index 478391e2..a4442c29 100644 --- a/Guardfile +++ b/Guardfile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + gem 'wdm', '>= 0.1.0' if Gem.win_platform? gem 'rspec', '~> 3.0.0' diff --git a/Rakefile b/Rakefile index cdb06d6f..97702a53 100644 --- a/Rakefile +++ b/Rakefile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'bundler/gem_tasks' require 'rubygems' @@ -13,13 +15,10 @@ task test: %i[prepare spec] desc 'Prepare and run rspec tests' task :prepare do rsa_key = File.expand_path('rsakey.pem') - unless File.exist?(rsa_key) - Rake::Task['jira:generate_public_cert'].invoke - end + Rake::Task['jira:generate_public_cert'].invoke unless File.exist?(rsa_key) end desc 'Run RSpec tests' -# RSpec::Core::RakeTask.new(:spec) RSpec::Core::RakeTask.new(:spec, [] => [:prepare]) do |task| task.rspec_opts = ['--color', '--format', 'doc'] end diff --git a/jira-ruby.gemspec b/jira-ruby.gemspec index 70ce734b..d4aaac81 100644 --- a/jira-ruby.gemspec +++ b/jira-ruby.gemspec @@ -1,3 +1,5 @@ +# frozen_string_literal: true + $LOAD_PATH.push File.expand_path('lib', __dir__) require 'jira/version' @@ -9,12 +11,13 @@ Gem::Specification.new do |s| s.summary = 'Ruby Gem for use with the Atlassian JIRA REST API' s.description = 'API for JIRA' s.licenses = ['MIT'] - s.metadata = { 'source_code_uri' => 'https://github.com/sumoheavy/jira-ruby' } + s.metadata = { + 'source_code_uri' => 'https://github.com/sumoheavy/jira-ruby', + 'rubygems_mfa_required' => 'true' } s.required_ruby_version = '>= 3.1.0' s.files = `git ls-files`.split("\n") - s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) } s.require_paths = ['lib'] From cda3da21320f03523963080f3a730809aadfcafe Mon Sep 17 00:00:00 2001 From: Robert Brodie Date: Sun, 28 Apr 2024 02:44:52 -0400 Subject: [PATCH 02/59] Add Rubocop to CI --- .github/workflows/CI.yml | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 2e1387f7..e9c002c2 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -3,6 +3,27 @@ name: Ruby on: [push, pull_request] jobs: + lint: + name: CI-lint + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + ruby: + - '3.1' + steps: + - uses: actions/checkout@v4 + + - name: Setup Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby }} + bundler-cache: true + + - name: Lint + run: | + bundle exec rubocop + test: name: CI-tests runs-on: ubuntu-latest From 205616b8c24f4c28c0d137123eeec4a4a2c8c3ad Mon Sep 17 00:00:00 2001 From: Robert Brodie Date: Sun, 28 Apr 2024 02:48:55 -0400 Subject: [PATCH 03/59] Add frozen_string_literal to resources --- lib/jira/resource/agile.rb | 2 ++ lib/jira/resource/applinks.rb | 2 ++ lib/jira/resource/attachment.rb | 2 ++ lib/jira/resource/board.rb | 2 ++ lib/jira/resource/board_configuration.rb | 2 ++ lib/jira/resource/comment.rb | 2 ++ lib/jira/resource/component.rb | 2 ++ lib/jira/resource/createmeta.rb | 2 ++ lib/jira/resource/field.rb | 2 ++ lib/jira/resource/filter.rb | 2 ++ lib/jira/resource/issue.rb | 3 ++- lib/jira/resource/issue_picker_suggestions.rb | 2 ++ lib/jira/resource/issue_picker_suggestions_issue.rb | 2 ++ lib/jira/resource/issuelink.rb | 2 ++ lib/jira/resource/issuelinktype.rb | 2 ++ lib/jira/resource/issuetype.rb | 2 ++ lib/jira/resource/priority.rb | 2 ++ lib/jira/resource/project.rb | 2 ++ lib/jira/resource/rapidview.rb | 2 ++ lib/jira/resource/remotelink.rb | 2 ++ lib/jira/resource/resolution.rb | 2 ++ lib/jira/resource/serverinfo.rb | 2 ++ lib/jira/resource/sprint.rb | 2 ++ lib/jira/resource/sprint_report.rb | 2 ++ lib/jira/resource/status.rb | 2 ++ lib/jira/resource/status_category.rb | 2 ++ lib/jira/resource/suggested_issue.rb | 2 ++ lib/jira/resource/transition.rb | 2 ++ lib/jira/resource/user.rb | 2 ++ lib/jira/resource/version.rb | 2 ++ lib/jira/resource/watcher.rb | 2 ++ lib/jira/resource/webhook.rb | 2 ++ lib/jira/resource/worklog.rb | 2 ++ 33 files changed, 66 insertions(+), 1 deletion(-) diff --git a/lib/jira/resource/agile.rb b/lib/jira/resource/agile.rb index 5f8f93e8..5fd091b6 100644 --- a/lib/jira/resource/agile.rb +++ b/lib/jira/resource/agile.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'cgi' module JIRA diff --git a/lib/jira/resource/applinks.rb b/lib/jira/resource/applinks.rb index 55f15ee2..67e807c3 100644 --- a/lib/jira/resource/applinks.rb +++ b/lib/jira/resource/applinks.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module JIRA module Resource class ApplicationLinkFactory < JIRA::BaseFactory # :nodoc: diff --git a/lib/jira/resource/attachment.rb b/lib/jira/resource/attachment.rb index 9e58b132..b6bb7c73 100644 --- a/lib/jira/resource/attachment.rb +++ b/lib/jira/resource/attachment.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'net/http/post/multipart' require 'open-uri' diff --git a/lib/jira/resource/board.rb b/lib/jira/resource/board.rb index d78ec68a..c6b7fd88 100644 --- a/lib/jira/resource/board.rb +++ b/lib/jira/resource/board.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'cgi' module JIRA diff --git a/lib/jira/resource/board_configuration.rb b/lib/jira/resource/board_configuration.rb index fa152f8b..a8d15628 100644 --- a/lib/jira/resource/board_configuration.rb +++ b/lib/jira/resource/board_configuration.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module JIRA module Resource class BoardConfigurationFactory < JIRA::BaseFactory # :nodoc: diff --git a/lib/jira/resource/comment.rb b/lib/jira/resource/comment.rb index 8b521149..d1475f67 100644 --- a/lib/jira/resource/comment.rb +++ b/lib/jira/resource/comment.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module JIRA module Resource class CommentFactory < JIRA::BaseFactory # :nodoc: diff --git a/lib/jira/resource/component.rb b/lib/jira/resource/component.rb index 52ef8bea..881e4091 100644 --- a/lib/jira/resource/component.rb +++ b/lib/jira/resource/component.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module JIRA module Resource class ComponentFactory < JIRA::BaseFactory # :nodoc: diff --git a/lib/jira/resource/createmeta.rb b/lib/jira/resource/createmeta.rb index e77c972b..2c4c6085 100644 --- a/lib/jira/resource/createmeta.rb +++ b/lib/jira/resource/createmeta.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module JIRA module Resource class CreatemetaFactory < JIRA::BaseFactory # :nodoc: diff --git a/lib/jira/resource/field.rb b/lib/jira/resource/field.rb index 5879002c..5a11e0d7 100644 --- a/lib/jira/resource/field.rb +++ b/lib/jira/resource/field.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module JIRA module Resource class FieldFactory < JIRA::BaseFactory # :nodoc: diff --git a/lib/jira/resource/filter.rb b/lib/jira/resource/filter.rb index 8a42d319..d32eac98 100644 --- a/lib/jira/resource/filter.rb +++ b/lib/jira/resource/filter.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module JIRA module Resource class FilterFactory < JIRA::BaseFactory # :nodoc: diff --git a/lib/jira/resource/issue.rb b/lib/jira/resource/issue.rb index 2d9e75b8..a39c3b47 100644 --- a/lib/jira/resource/issue.rb +++ b/lib/jira/resource/issue.rb @@ -1,7 +1,8 @@ +# frozen_string_literal: true + require 'cgi' require 'json' - module JIRA module Resource class IssueFactory < JIRA::BaseFactory # :nodoc: diff --git a/lib/jira/resource/issue_picker_suggestions.rb b/lib/jira/resource/issue_picker_suggestions.rb index 2834c16a..7fd48a06 100644 --- a/lib/jira/resource/issue_picker_suggestions.rb +++ b/lib/jira/resource/issue_picker_suggestions.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module JIRA module Resource class IssuePickerSuggestionsFactory < JIRA::BaseFactory # :nodoc: diff --git a/lib/jira/resource/issue_picker_suggestions_issue.rb b/lib/jira/resource/issue_picker_suggestions_issue.rb index 4d54c90b..2756e2d4 100644 --- a/lib/jira/resource/issue_picker_suggestions_issue.rb +++ b/lib/jira/resource/issue_picker_suggestions_issue.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module JIRA module Resource class IssuePickerSuggestionsIssueFactory < JIRA::BaseFactory # :nodoc: diff --git a/lib/jira/resource/issuelink.rb b/lib/jira/resource/issuelink.rb index a960bd67..cf3e5e29 100644 --- a/lib/jira/resource/issuelink.rb +++ b/lib/jira/resource/issuelink.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module JIRA module Resource class IssuelinkFactory < JIRA::BaseFactory # :nodoc: diff --git a/lib/jira/resource/issuelinktype.rb b/lib/jira/resource/issuelinktype.rb index 29010c67..4cf1e4c2 100644 --- a/lib/jira/resource/issuelinktype.rb +++ b/lib/jira/resource/issuelinktype.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module JIRA module Resource class IssuelinktypeFactory < JIRA::BaseFactory # :nodoc: diff --git a/lib/jira/resource/issuetype.rb b/lib/jira/resource/issuetype.rb index 9f47d7e1..20d762de 100644 --- a/lib/jira/resource/issuetype.rb +++ b/lib/jira/resource/issuetype.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module JIRA module Resource class IssuetypeFactory < JIRA::BaseFactory # :nodoc: diff --git a/lib/jira/resource/priority.rb b/lib/jira/resource/priority.rb index 385443b4..296e4313 100644 --- a/lib/jira/resource/priority.rb +++ b/lib/jira/resource/priority.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module JIRA module Resource class PriorityFactory < JIRA::BaseFactory # :nodoc: diff --git a/lib/jira/resource/project.rb b/lib/jira/resource/project.rb index 5db9403d..dc5df445 100644 --- a/lib/jira/resource/project.rb +++ b/lib/jira/resource/project.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module JIRA module Resource class ProjectFactory < JIRA::BaseFactory # :nodoc: diff --git a/lib/jira/resource/rapidview.rb b/lib/jira/resource/rapidview.rb index 9b96285c..e28f666b 100644 --- a/lib/jira/resource/rapidview.rb +++ b/lib/jira/resource/rapidview.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'cgi' module JIRA diff --git a/lib/jira/resource/remotelink.rb b/lib/jira/resource/remotelink.rb index 63c6a9e6..6d8fe86d 100644 --- a/lib/jira/resource/remotelink.rb +++ b/lib/jira/resource/remotelink.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module JIRA module Resource class RemotelinkFactory < JIRA::BaseFactory # :nodoc: diff --git a/lib/jira/resource/resolution.rb b/lib/jira/resource/resolution.rb index a3a6359c..557e87f3 100644 --- a/lib/jira/resource/resolution.rb +++ b/lib/jira/resource/resolution.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module JIRA module Resource class ResolutionFactory < JIRA::BaseFactory # :nodoc: diff --git a/lib/jira/resource/serverinfo.rb b/lib/jira/resource/serverinfo.rb index 8a290871..ad29eff0 100644 --- a/lib/jira/resource/serverinfo.rb +++ b/lib/jira/resource/serverinfo.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module JIRA module Resource class ServerInfoFactory < JIRA::BaseFactory # :nodoc: diff --git a/lib/jira/resource/sprint.rb b/lib/jira/resource/sprint.rb index 6b90710b..ef551a0d 100644 --- a/lib/jira/resource/sprint.rb +++ b/lib/jira/resource/sprint.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module JIRA module Resource class SprintFactory < JIRA::BaseFactory # :nodoc: diff --git a/lib/jira/resource/sprint_report.rb b/lib/jira/resource/sprint_report.rb index 8f179229..1e3eeff0 100644 --- a/lib/jira/resource/sprint_report.rb +++ b/lib/jira/resource/sprint_report.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module JIRA module Resource class SprintReportFactory < JIRA::BaseFactory # :nodoc: diff --git a/lib/jira/resource/status.rb b/lib/jira/resource/status.rb index be53507f..10d18d8a 100644 --- a/lib/jira/resource/status.rb +++ b/lib/jira/resource/status.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require_relative 'status_category' module JIRA diff --git a/lib/jira/resource/status_category.rb b/lib/jira/resource/status_category.rb index c900308c..e82c7f52 100644 --- a/lib/jira/resource/status_category.rb +++ b/lib/jira/resource/status_category.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module JIRA module Resource class StatusCategoryFactory < JIRA::BaseFactory # :nodoc: diff --git a/lib/jira/resource/suggested_issue.rb b/lib/jira/resource/suggested_issue.rb index 7fe7d00d..75d4ed22 100644 --- a/lib/jira/resource/suggested_issue.rb +++ b/lib/jira/resource/suggested_issue.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module JIRA module Resource class SuggestedIssueFactory < JIRA::BaseFactory # :nodoc: diff --git a/lib/jira/resource/transition.rb b/lib/jira/resource/transition.rb index e865c6f6..c1d4a8fe 100644 --- a/lib/jira/resource/transition.rb +++ b/lib/jira/resource/transition.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module JIRA module Resource class TransitionFactory < JIRA::BaseFactory # :nodoc: diff --git a/lib/jira/resource/user.rb b/lib/jira/resource/user.rb index fc2705d3..a283c860 100644 --- a/lib/jira/resource/user.rb +++ b/lib/jira/resource/user.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module JIRA module Resource class UserFactory < JIRA::BaseFactory # :nodoc: diff --git a/lib/jira/resource/version.rb b/lib/jira/resource/version.rb index 1861a951..e59cacdb 100644 --- a/lib/jira/resource/version.rb +++ b/lib/jira/resource/version.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module JIRA module Resource class VersionFactory < JIRA::BaseFactory # :nodoc: diff --git a/lib/jira/resource/watcher.rb b/lib/jira/resource/watcher.rb index be9f16da..b3f229d2 100644 --- a/lib/jira/resource/watcher.rb +++ b/lib/jira/resource/watcher.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module JIRA module Resource class WatcherFactory < JIRA::BaseFactory # :nodoc: diff --git a/lib/jira/resource/webhook.rb b/lib/jira/resource/webhook.rb index f35805a6..21628c9c 100644 --- a/lib/jira/resource/webhook.rb +++ b/lib/jira/resource/webhook.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module JIRA module Resource class WebhookFactory < JIRA::BaseFactory # :nodoc: diff --git a/lib/jira/resource/worklog.rb b/lib/jira/resource/worklog.rb index c57886ab..54fbb270 100644 --- a/lib/jira/resource/worklog.rb +++ b/lib/jira/resource/worklog.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module JIRA module Resource class WorklogFactory < JIRA::BaseFactory # :nodoc: From 05dd40c61ea564d9ac334c42710f2ebe7eb36a94 Mon Sep 17 00:00:00 2001 From: Robert Brodie Date: Sun, 28 Apr 2024 02:50:09 -0400 Subject: [PATCH 04/59] Don't warn about documentation (for now) --- .rubocop.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.rubocop.yml b/.rubocop.yml index 3affd351..c9cded55 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -2,4 +2,7 @@ require: - rubocop-rspec AllCops: - NewCops: enable \ No newline at end of file + NewCops: enable + +Documentation: + Enabled: false \ No newline at end of file From db34bfc232d9c8c0fa5479ddf72438da2cf05c40 Mon Sep 17 00:00:00 2001 From: Robert Brodie Date: Sun, 28 Apr 2024 03:01:10 -0400 Subject: [PATCH 05/59] Clean up resources --- .rubocop.yml | 1 + lib/jira/resource/agile.rb | 5 ++-- lib/jira/resource/applinks.rb | 4 +-- lib/jira/resource/attachment.rb | 2 +- lib/jira/resource/board.rb | 6 ++-- lib/jira/resource/createmeta.rb | 2 +- lib/jira/resource/field.rb | 2 ++ lib/jira/resource/issue.rb | 50 ++++++++++----------------------- lib/jira/resource/project.rb | 4 +-- lib/jira/resource/rapidview.rb | 6 ++-- lib/jira/resource/sprint.rb | 7 +++-- lib/jira/resource/user.rb | 2 +- lib/jira/resource/watcher.rb | 1 - lib/jira/resource/worklog.rb | 3 +- 14 files changed, 39 insertions(+), 56 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index c9cded55..2dc0d327 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -3,6 +3,7 @@ require: AllCops: NewCops: enable + TargetRubyVersion: 3.1 Documentation: Enabled: false \ No newline at end of file diff --git a/lib/jira/resource/agile.rb b/lib/jira/resource/agile.rb index 5fd091b6..c43a39ab 100644 --- a/lib/jira/resource/agile.rb +++ b/lib/jira/resource/agile.rb @@ -27,7 +27,8 @@ def self.get_board_issues(client, board_id, options = {}) response = client.get(path_base(client) + "/board/#{board_id}/issue?#{hash_to_query_string(options)}") json = parse_json(response.body) # To get Issue objects with the same structure as for Issue.all - return {} if json['issues'].size.zero? + return {} if json['issues'].empty? + issue_ids = json['issues'].map do |issue| issue['id'] end @@ -70,7 +71,7 @@ def self.get_projects(client, board_id, options = {}) private def self.path_base(client) - client.options[:context_path] + '/rest/agile/1.0' + "#{client.options[:context_path]}/rest/agile/1.0" end def path_base(client) diff --git a/lib/jira/resource/applinks.rb b/lib/jira/resource/applinks.rb index 67e807c3..8938df4b 100644 --- a/lib/jira/resource/applinks.rb +++ b/lib/jira/resource/applinks.rb @@ -7,7 +7,7 @@ class ApplicationLinkFactory < JIRA::BaseFactory # :nodoc: end class ApplicationLink < JIRA::Base - REST_BASE_PATH = '/rest/applinks/1.0'.freeze + REST_BASE_PATH = '/rest/applinks/1.0' def self.endpoint_name 'listApplicationlinks' @@ -31,7 +31,7 @@ def self.all(client, options = {}) end def self.manifest(client) - url = full_url(client) + '/manifest' + url = "#{full_url(client)}/manifest" response = client.get(url) json = parse_json(response.body) JIRA::Base.new(client, attrs: json) diff --git a/lib/jira/resource/attachment.rb b/lib/jira/resource/attachment.rb index b6bb7c73..56ff96e8 100644 --- a/lib/jira/resource/attachment.rb +++ b/lib/jira/resource/attachment.rb @@ -18,7 +18,7 @@ def self.endpoint_name end def self.meta(client) - response = client.get(client.options[:rest_base_path] + '/attachment/meta') + response = client.get("#{client.options[:rest_base_path]}/attachment/meta") parse_json(response.body) end diff --git a/lib/jira/resource/board.rb b/lib/jira/resource/board.rb index c6b7fd88..88a7df99 100644 --- a/lib/jira/resource/board.rb +++ b/lib/jira/resource/board.rb @@ -9,7 +9,7 @@ class BoardFactory < JIRA::BaseFactory # :nodoc: class Board < JIRA::Base def self.all(client) - path = path_base(client) + '/board' + path = "#{path_base(client)}/board" response = client.get(path) json = parse_json(response.body) results = json['values'] @@ -76,13 +76,13 @@ def project end def add_issue_to_backlog(issue) - client.post(path_base(client) + '/backlog/issue', { issues: [issue.id] }.to_json) + client.post("#{path_base(client)}/backlog/issue", { issues: [issue.id] }.to_json) end private def self.path_base(client) - client.options[:context_path] + '/rest/agile/1.0' + "#{client.options[:context_path]}/rest/agile/1.0" end def path_base(client) diff --git a/lib/jira/resource/createmeta.rb b/lib/jira/resource/createmeta.rb index 2c4c6085..6f53b0c6 100644 --- a/lib/jira/resource/createmeta.rb +++ b/lib/jira/resource/createmeta.rb @@ -38,7 +38,7 @@ def self.all(client, params = {}) json = parse_json(response.body) json['projects'].map do |attrs| - new(client, attrs: attrs) + new(client, attrs:) end end end diff --git a/lib/jira/resource/field.rb b/lib/jira/resource/field.rb index 5a11e0d7..73116121 100644 --- a/lib/jira/resource/field.rb +++ b/lib/jira/resource/field.rb @@ -28,6 +28,7 @@ def self.map_fields(client) # as a system field can't take precedence fields.each do |f| next if f.custom + name = safe_name(f.name) field_map_reverse[f.id] = [f.name, name] # capture both the official name, and the mapped name field_map[name] = f.id @@ -35,6 +36,7 @@ def self.map_fields(client) fields.each do |f| next unless f.custom + name = if field_map.key? f.name renamed = safer_name(f.name, f.id) warn "Duplicate Field name #{f.name} #{f.id} - renaming as #{renamed}" diff --git a/lib/jira/resource/issue.rb b/lib/jira/resource/issue.rb index a39c3b47..32d7141e 100644 --- a/lib/jira/resource/issue.rb +++ b/lib/jira/resource/issue.rb @@ -9,46 +9,25 @@ class IssueFactory < JIRA::BaseFactory # :nodoc: end class Issue < JIRA::Base - has_one :reporter, class: JIRA::Resource::User, - nested_under: 'fields' - has_one :assignee, class: JIRA::Resource::User, - nested_under: 'fields' - has_one :project, nested_under: 'fields' - + has_one :reporter, class: JIRA::Resource::User, nested_under: 'fields' + has_one :assignee, class: JIRA::Resource::User, nested_under: 'fields' + has_one :project, nested_under: 'fields' has_one :issuetype, nested_under: 'fields' - - has_one :priority, nested_under: 'fields' - - has_one :status, nested_under: 'fields' - + has_one :priority, nested_under: 'fields' + has_one :status, nested_under: 'fields' has_one :resolution, nested_under: 'fields' - has_many :transitions - has_many :components, nested_under: 'fields' - has_many :comments, nested_under: %w[fields comment] - - has_many :attachments, nested_under: 'fields', - attribute_key: 'attachment' - - has_many :versions, nested_under: 'fields' - has_many :fixVersions, class: JIRA::Resource::Version, - nested_under: 'fields' - + has_many :attachments, nested_under: 'fields', attribute_key: 'attachment' + has_many :versions, nested_under: 'fields' + has_many :fixVersions, class: JIRA::Resource::Version, nested_under: 'fields' has_many :worklogs, nested_under: %w[fields worklog] - has_one :sprint, class: JIRA::Resource::Sprint, - nested_under: 'fields' - - has_many :closed_sprints, class: JIRA::Resource::Sprint, - nested_under: 'fields', attribute_key: 'closedSprints' - + has_one :sprint, class: JIRA::Resource::Sprint, nested_under: 'fields' + has_many :closed_sprints, class: JIRA::Resource::Sprint, nested_under: 'fields', attribute_key: 'closedSprints' has_many :issuelinks, nested_under: 'fields' - has_many :remotelink, class: JIRA::Resource::Remotelink - - has_many :watchers, attribute_key: 'watches', - nested_under: %w[fields watches] + has_many :watchers, attribute_key: 'watches', nested_under: %w[fields watches] def self.all(client) start_at = 0 @@ -63,6 +42,7 @@ def self.all(client) result.push(client.Issue.build(issue)) end break if json['issues'].empty? + start_at += json['issues'].size end result @@ -83,9 +63,8 @@ def self.jql(client, jql, options = { fields: nil, start_at: nil, max_results: n response = client.get(url) json = parse_json(response.body) - if options[:max_results] && (options[:max_results] == 0) - return json['total'] - end + return json['total'] if options[:max_results] && (options[:max_results] == 0) + json['issues'].map do |issue| client.Issue.build(issue) end @@ -96,6 +75,7 @@ def self.jql(client, jql, options = { fields: nil, start_at: nil, max_results: n # is not set def fetch(reload = false, query_params = {}) return if expanded? && !reload + response = client.get(url_with_query_params(url, query_params)) set_attrs_from_response(response) if @attrs && @attrs['fields'] && @attrs['fields']['worklog'] && (@attrs['fields']['worklog']['total'] > @attrs['fields']['worklog']['maxResults']) diff --git a/lib/jira/resource/project.rb b/lib/jira/resource/project.rb index dc5df445..b51c1912 100644 --- a/lib/jira/resource/project.rb +++ b/lib/jira/resource/project.rb @@ -17,7 +17,7 @@ def self.key_attribute # Returns all the issues for this project def issues(options = {}) - search_url = client.options[:rest_base_path] + '/search' + search_url = "#{client.options[:rest_base_path]}/search" query_params = { jql: "project=\"#{key}\"" } query_params.update Base.query_params_for_search(options) response = client.get(url_with_query_params(search_url, query_params)) @@ -28,7 +28,7 @@ def issues(options = {}) end def users(start_at: nil, max_results: nil) - users_url = client.options[:rest_base_path] + '/user/assignable/search' + users_url = "#{client.options[:rest_base_path]}/user/assignable/search" query_params = { project: key_value } query_params['startAt'] = start_at if start_at query_params['maxResults'] = max_results if max_results diff --git a/lib/jira/resource/rapidview.rb b/lib/jira/resource/rapidview.rb index e28f666b..fede5c2d 100644 --- a/lib/jira/resource/rapidview.rb +++ b/lib/jira/resource/rapidview.rb @@ -9,7 +9,7 @@ class RapidViewFactory < JIRA::BaseFactory # :nodoc: class RapidView < JIRA::Base def self.all(client) - response = client.get(path_base(client) + '/rapidview') + response = client.get("#{path_base(client)}/rapidview") json = parse_json(response.body) json['views'].map do |view| client.RapidView.build(view) @@ -46,7 +46,7 @@ def issues(options = {}) def sprints(options = {}) params = { includeHistoricSprints: options.fetch(:include_historic, false), - includeFutureSprints: options.fetch(:include_future, false) } + includeFutureSprints: options.fetch(:include_future, false) } response = client.get(path_base(client) + "/sprintquery/#{id}?#{params.to_query}") json = self.class.parse_json(response.body) json['sprints'].map do |sprint| @@ -58,7 +58,7 @@ def sprints(options = {}) private def self.path_base(client) - client.options[:context_path] + '/rest/greenhopper/1.0' + "#{client.options[:context_path]}/rest/greenhopper/1.0" end def path_base(client) diff --git a/lib/jira/resource/sprint.rb b/lib/jira/resource/sprint.rb index ef551a0d..e7edf869 100644 --- a/lib/jira/resource/sprint.rb +++ b/lib/jira/resource/sprint.rb @@ -14,17 +14,17 @@ def self.find(client, key) # get all issues of sprint def issues(options = {}) - jql = 'sprint = ' + id.to_s + jql = "sprint = #{id}" jql += " and updated >= '#{options[:updated]}'" if options[:updated] Issue.jql(client, jql) end def add_issue(issue) - add_issues( [ issue ]) + add_issues([issue]) end def add_issues(issues) - issue_ids = issues.map{ |issue| issue.id } + issue_ids = issues.map(&:id) request_body = { issues: issue_ids }.to_json client.post("#{agile_path}/issue", request_body) true @@ -49,6 +49,7 @@ def complete_date def get_sprint_details_attribute(attribute_name) attribute = instance_variable_get("@#{attribute_name}") return attribute if attribute + get_sprint_details instance_variable_get("@#{attribute_name}") end diff --git a/lib/jira/resource/user.rb b/lib/jira/resource/user.rb index a283c860..33b2197c 100644 --- a/lib/jira/resource/user.rb +++ b/lib/jira/resource/user.rb @@ -15,7 +15,7 @@ class User < JIRA::Base MAX_RESULTS = 1000 def self.singular_path(client, key, prefix = '/') - collection_path(client, prefix) + '?username=' + key + "#{collection_path(client, prefix)}?username=#{key}" end # Cannot retrieve more than 1,000 users through the api, please see: https://jira.atlassian.com/browse/JRASERVER-65089 diff --git a/lib/jira/resource/watcher.rb b/lib/jira/resource/watcher.rb index b3f229d2..3259a359 100644 --- a/lib/jira/resource/watcher.rb +++ b/lib/jira/resource/watcher.rb @@ -31,7 +31,6 @@ def save!(user_id, path = nil) response = client.post(path, user_id.to_json) true end - end end end diff --git a/lib/jira/resource/worklog.rb b/lib/jira/resource/worklog.rb index 54fbb270..325d8534 100644 --- a/lib/jira/resource/worklog.rb +++ b/lib/jira/resource/worklog.rb @@ -7,8 +7,7 @@ class WorklogFactory < JIRA::BaseFactory # :nodoc: class Worklog < JIRA::Base has_one :author, class: JIRA::Resource::User - has_one :update_author, class: JIRA::Resource::User, - attribute_key: 'updateAuthor' + has_one :update_author, class: JIRA::Resource::User, attribute_key: 'updateAuthor' belongs_to :issue nested_collections true end From facac2360a7840710f98241f1a1abe0173234ce7 Mon Sep 17 00:00:00 2001 From: Robert Brodie Date: Sun, 28 Apr 2024 03:08:58 -0400 Subject: [PATCH 06/59] Update remainder of frozen_string_literal --- .rubocop.yml | 6 +++++- http-basic-example.rb | 2 ++ lib/jira-ruby.rb | 2 ++ lib/jira/base.rb | 2 ++ lib/jira/base_factory.rb | 2 ++ lib/jira/client.rb | 2 ++ lib/jira/has_many_proxy.rb | 2 ++ lib/jira/http_client.rb | 2 ++ lib/jira/http_error.rb | 2 ++ lib/jira/jwt_client.rb | 2 ++ lib/jira/oauth_client.rb | 2 ++ lib/jira/railtie.rb | 2 ++ lib/jira/request_client.rb | 2 ++ lib/jira/version.rb | 2 ++ lib/tasks/generate.rake | 2 ++ 15 files changed, 33 insertions(+), 1 deletion(-) diff --git a/.rubocop.yml b/.rubocop.yml index 2dc0d327..f65d0301 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -6,4 +6,8 @@ AllCops: TargetRubyVersion: 3.1 Documentation: - Enabled: false \ No newline at end of file + Enabled: false + +Style/FrozenStringLiteralComment: + Exclude: + - 'spec/**/*' \ No newline at end of file diff --git a/http-basic-example.rb b/http-basic-example.rb index 41c31b09..4e287832 100644 --- a/http-basic-example.rb +++ b/http-basic-example.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rubygems' require 'pp' require 'jira-ruby' diff --git a/lib/jira-ruby.rb b/lib/jira-ruby.rb index ae464f8e..620077fd 100644 --- a/lib/jira-ruby.rb +++ b/lib/jira-ruby.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + $LOAD_PATH << __dir__ require 'active_support' diff --git a/lib/jira/base.rb b/lib/jira/base.rb index 52c6dbf3..5bc56841 100644 --- a/lib/jira/base.rb +++ b/lib/jira/base.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'active_support/core_ext/string' require 'active_support/inflector' require 'set' diff --git a/lib/jira/base_factory.rb b/lib/jira/base_factory.rb index 230b2d9a..60f2858b 100644 --- a/lib/jira/base_factory.rb +++ b/lib/jira/base_factory.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module JIRA # This is the base class for all the JIRA resource factory instances. class BaseFactory diff --git a/lib/jira/client.rb b/lib/jira/client.rb index fa631050..13647093 100644 --- a/lib/jira/client.rb +++ b/lib/jira/client.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'json' require 'forwardable' require 'ostruct' diff --git a/lib/jira/has_many_proxy.rb b/lib/jira/has_many_proxy.rb index c32c392e..fe86e728 100644 --- a/lib/jira/has_many_proxy.rb +++ b/lib/jira/has_many_proxy.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # # Whenever a collection from a has_many relationship is accessed, an instance # of this class is returned. This instance wraps the Array of instances in diff --git a/lib/jira/http_client.rb b/lib/jira/http_client.rb index 6a659322..3826759d 100644 --- a/lib/jira/http_client.rb +++ b/lib/jira/http_client.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'json' require 'net/https' require 'cgi/cookie' diff --git a/lib/jira/http_error.rb b/lib/jira/http_error.rb index 9733531f..874e9867 100644 --- a/lib/jira/http_error.rb +++ b/lib/jira/http_error.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'forwardable' require 'active_support/core_ext/object' diff --git a/lib/jira/jwt_client.rb b/lib/jira/jwt_client.rb index 843d810a..a32f98ee 100644 --- a/lib/jira/jwt_client.rb +++ b/lib/jira/jwt_client.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'atlassian/jwt' module JIRA diff --git a/lib/jira/oauth_client.rb b/lib/jira/oauth_client.rb index bcbed350..15b2757a 100644 --- a/lib/jira/oauth_client.rb +++ b/lib/jira/oauth_client.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'oauth' require 'json' require 'forwardable' diff --git a/lib/jira/railtie.rb b/lib/jira/railtie.rb index 84809adb..0ba37b88 100644 --- a/lib/jira/railtie.rb +++ b/lib/jira/railtie.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'jira-ruby' require 'rails' diff --git a/lib/jira/request_client.rb b/lib/jira/request_client.rb index d90ae9d6..dcffa767 100644 --- a/lib/jira/request_client.rb +++ b/lib/jira/request_client.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'oauth' require 'json' require 'net/https' diff --git a/lib/jira/version.rb b/lib/jira/version.rb index 09231406..2584af7e 100644 --- a/lib/jira/version.rb +++ b/lib/jira/version.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module JIRA VERSION = '2.3.0'.freeze end diff --git a/lib/tasks/generate.rake b/lib/tasks/generate.rake index 51690670..fb64f560 100644 --- a/lib/tasks/generate.rake +++ b/lib/tasks/generate.rake @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'securerandom' namespace :jira do From f7cbc56356f27a3f76eac33c4a1c6bfcdc837503 Mon Sep 17 00:00:00 2001 From: Robert Brodie Date: Sun, 28 Apr 2024 03:15:21 -0400 Subject: [PATCH 07/59] Updated Rubocop configuration --- .rubocop.yml | 14 ++++++++++++-- Gemfile | 8 ++++++-- jira-ruby.gemspec | 13 ++----------- lib/jira/base.rb | 6 ++++++ lib/jira/client.rb | 1 + lib/jira/oauth_client.rb | 1 + lib/jira/request_client.rb | 2 ++ lib/jira/resource/field.rb | 1 + spec/spec_helper.rb | 1 + 9 files changed, 32 insertions(+), 15 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index f65d0301..57ea727a 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -2,12 +2,22 @@ require: - rubocop-rspec AllCops: - NewCops: enable - TargetRubyVersion: 3.1 + Exclude: + - 'example.rb' + - 'http-basic-example.rb' + NewCops: enable + TargetRubyVersion: 3.1 Documentation: Enabled: false +Naming/FileName: + Exclude: + - 'lib/jira-ruby.rb' + +Naming/MethodName: + Enabled: false + Style/FrozenStringLiteralComment: Exclude: - 'spec/**/*' \ No newline at end of file diff --git a/Gemfile b/Gemfile index 82a5d33b..f22f0f44 100644 --- a/Gemfile +++ b/Gemfile @@ -3,9 +3,13 @@ source 'https://rubygems.org' group :development do - gem 'guard' - gem 'guard-rspec' + gem 'guard', '~> 2.18', '>= 2.18.1' + gem 'guard-rspec', '~> 4.7', '>= 4.7.3' + gem 'railties' + gem 'rake', '~> 13.2', '>= 13.2.1' + gem 'rspec', '~> 3.0', '>= 3.13' gem 'wdm', '>= 0.1.0' if Gem.win_platform? + gem 'webmock', '~> 3.23', '>= 3.23.0' end group :development, :test do diff --git a/jira-ruby.gemspec b/jira-ruby.gemspec index d4aaac81..f9471627 100644 --- a/jira-ruby.gemspec +++ b/jira-ruby.gemspec @@ -13,7 +13,8 @@ Gem::Specification.new do |s| s.licenses = ['MIT'] s.metadata = { 'source_code_uri' => 'https://github.com/sumoheavy/jira-ruby', - 'rubygems_mfa_required' => 'true' } + 'rubygems_mfa_required' => 'true' + } s.required_ruby_version = '>= 3.1.0' @@ -21,18 +22,8 @@ Gem::Specification.new do |s| s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) } s.require_paths = ['lib'] - # Runtime Dependencies s.add_runtime_dependency 'activesupport' s.add_runtime_dependency 'atlassian-jwt' s.add_runtime_dependency 'multipart-post' s.add_runtime_dependency 'oauth', '~> 1.0' - - # Development Dependencies - s.add_development_dependency 'guard', '~> 2.18', '>= 2.18.1' - s.add_development_dependency 'guard-rspec', '~> 4.7', '>= 4.7.3' - s.add_development_dependency 'pry', '~> 0.14', '>= 0.14.3' - s.add_development_dependency 'railties' - s.add_development_dependency 'rake', '~> 13.2', '>= 13.2.1' - s.add_development_dependency 'rspec', '~> 3.0', '>= 3.13' - s.add_development_dependency 'webmock', '~> 3.23', '>= 3.23.0' end diff --git a/lib/jira/base.rb b/lib/jira/base.rb index 5bc56841..a3d0c93a 100644 --- a/lib/jira/base.rb +++ b/lib/jira/base.rb @@ -199,6 +199,7 @@ def self.has_one(resource, options = {}) define_method(resource) do attribute = maybe_nested_attribute(attribute_key, options[:nested_under]) return nil unless attribute + child_class.new(client, attrs: attribute) end end @@ -333,6 +334,7 @@ def path_component # is not set def fetch(reload = false, query_params = {}) return if expanded? && !reload + response = client.get(url_with_query_params(url, query_params)) set_attrs_from_response(response) @expanded = true @@ -445,6 +447,7 @@ def url def patched_url result = url return result if result.start_with?('/', 'http') + "/#{result}" end @@ -478,12 +481,15 @@ def maybe_nested_attribute(attribute_name, nested_under = nil) def self.maybe_nested_attribute(attributes, attribute_name, nested_under = nil) return attributes[attribute_name] if nested_under.nil? + if nested_under.instance_of? Array final = nested_under.inject(attributes) do |parent, key| break if parent.nil? + parent[key] end return nil if final.nil? + final[attribute_name] else return attributes[nested_under][attribute_name] diff --git a/lib/jira/client.rb b/lib/jira/client.rb index 13647093..0a4c761f 100644 --- a/lib/jira/client.rb +++ b/lib/jira/client.rb @@ -138,6 +138,7 @@ def initialize(options = {}) @request_client = HttpClient.new(@options) when :cookie raise ArgumentError, 'Options: :use_cookies must be true for :cookie authorization type' if @options.key?(:use_cookies) && !@options[:use_cookies] + @options[:use_cookies] = true @request_client = HttpClient.new(@options) @request_client.make_cookie_auth_request diff --git a/lib/jira/oauth_client.rb b/lib/jira/oauth_client.rb index 15b2757a..fc7cb37b 100644 --- a/lib/jira/oauth_client.rb +++ b/lib/jira/oauth_client.rb @@ -73,6 +73,7 @@ def set_access_token(token, secret) # JIRA::Client::UninitializedAccessTokenError exception if it is not set. def access_token raise UninitializedAccessTokenError unless @access_token + @access_token end diff --git a/lib/jira/request_client.rb b/lib/jira/request_client.rb index dcffa767..3091e8fc 100644 --- a/lib/jira/request_client.rb +++ b/lib/jira/request_client.rb @@ -13,12 +13,14 @@ class RequestClient def request(*args) response = make_request(*args) raise HTTPError, response unless response.is_a?(Net::HTTPSuccess) + response end def request_multipart(*args) response = make_multipart_request(*args) raise HTTPError, response unless response.is_a?(Net::HTTPSuccess) + response end diff --git a/lib/jira/resource/field.rb b/lib/jira/resource/field.rb index 73116121..5d4b8009 100644 --- a/lib/jira/resource/field.rb +++ b/lib/jira/resource/field.rb @@ -59,6 +59,7 @@ def self.field_map(client) def self.name_to_id(client, field_name) field_name = field_name.to_s return field_name unless client.cache.field_map && client.cache.field_map[field_name] + client.cache.field_map[field_name] end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 1f215500..76d49c49 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -17,5 +17,6 @@ def get_mock_response(file, value_if_file_not_found = false) File.read(File.join(File.dirname(__FILE__), 'mock_responses/', file)) rescue Errno::ENOENT => e raise e if value_if_file_not_found == false + value_if_file_not_found end From d1b4af5fc75884eb20a13c51be1e285591b2bee4 Mon Sep 17 00:00:00 2001 From: Robert Brodie Date: Sun, 28 Apr 2024 03:16:16 -0400 Subject: [PATCH 08/59] Fixed Style/StringConcatenation --- lib/jira/base.rb | 12 ++++++------ lib/jira/http_client.rb | 2 +- lib/jira/oauth_client.rb | 2 +- spec/integration/issue_spec.rb | 8 ++++---- spec/integration/project_spec.rb | 2 +- spec/integration/rapidview_spec.rb | 9 ++++----- spec/integration/watcher_spec.rb | 6 +++--- spec/support/shared_examples/integration.rb | 15 ++++++--------- 8 files changed, 26 insertions(+), 30 deletions(-) diff --git a/lib/jira/base.rb b/lib/jira/base.rb index a3d0c93a..d4f584f8 100644 --- a/lib/jira/base.rb +++ b/lib/jira/base.rb @@ -143,7 +143,7 @@ def self.collection_path(client, prefix = '/') # JIRA::Resource::Comment.singular_path('456','/issue/123/') # # => /jira/rest/api/2/issue/123/comment/456 def self.singular_path(client, key, prefix = '/') - collection_path(client, prefix) + '/' + key.to_s + "#{collection_path(client, prefix)}/#{key.to_s}" end # Returns the attribute name of the attribute used for find. @@ -195,7 +195,7 @@ def self.parse_json(string) # :nodoc: # # => Looks for {"foo":{"bar":{"baz":{"child":{}}}}} def self.has_one(resource, options = {}) attribute_key = options[:attribute_key] || resource.to_s - child_class = options[:class] || ('JIRA::Resource::' + resource.to_s.classify).constantize + child_class = options[:class] || ("JIRA::Resource::#{resource.to_s.classify}").constantize define_method(resource) do attribute = maybe_nested_attribute(attribute_key, options[:nested_under]) return nil unless attribute @@ -247,7 +247,7 @@ def self.has_one(resource, options = {}) # # => Looks for {"foo":{"bar":{"baz":{"children":{}}}}} def self.has_many(collection, options = {}) attribute_key = options[:attribute_key] || collection.to_s - child_class = options[:class] || ('JIRA::Resource::' + collection.to_s.classify).constantize + child_class = options[:class] || ("JIRA::Resource::#{collection.to_s.classify}").constantize self_class_basename = name.split('::').last.downcase.to_sym define_method(collection) do child_class_options = { self_class_basename => self } @@ -325,7 +325,7 @@ def collection_path(prefix = '/') # issue it returns '/issue' def path_component path_component = "/#{self.class.endpoint_name}" - path_component += '/' + key_value if key_value + path_component += "/#{key_value}" if key_value path_component end @@ -423,7 +423,7 @@ def url prefix = '/' unless self.class.belongs_to_relationships.empty? prefix = self.class.belongs_to_relationships.inject(prefix) do |prefix_so_far, relationship| - prefix_so_far.to_s + relationship.to_s + '/' + send("#{relationship}_id").to_s + '/' + "#{prefix_so_far.to_s}#{relationship.to_s}/#{send("#{relationship}_id").to_s}/" end end if @attrs['self'] @@ -514,7 +514,7 @@ def hash_to_query_string(query_params) def self.hash_to_query_string(query_params) query_params.map do |k, v| - CGI.escape(k.to_s) + '=' + CGI.escape(v.to_s) + "#{CGI.escape(k.to_s)}=#{CGI.escape(v.to_s)}" end.join('&') end diff --git a/lib/jira/http_client.rb b/lib/jira/http_client.rb index 3826759d..5c16d8f8 100644 --- a/lib/jira/http_client.rb +++ b/lib/jira/http_client.rb @@ -23,7 +23,7 @@ def make_cookie_auth_request body = { username: @options[:username].to_s, password: @options[:password].to_s }.to_json @options.delete(:username) @options.delete(:password) - make_request(:post, @options[:context_path] + '/rest/auth/1/session', body, 'Content-Type' => 'application/json') + make_request(:post, "#{@options[:context_path]}/rest/auth/1/session", body, 'Content-Type' => 'application/json') end def make_request(http_method, url, body = '', headers = {}) diff --git a/lib/jira/oauth_client.rb b/lib/jira/oauth_client.rb index fc7cb37b..05d99383 100644 --- a/lib/jira/oauth_client.rb +++ b/lib/jira/oauth_client.rb @@ -85,7 +85,7 @@ def make_request(http_method, url, body = '', headers = {}) uri.query = if uri.query.to_s == '' oauth_params_str else - uri.query + '&' + oauth_params_str + "#{uri.query}&#{oauth_params_str}" end url = uri.to_s end diff --git a/spec/integration/issue_spec.rb b/spec/integration/issue_spec.rb index c1384376..7351ec19 100644 --- a/spec/integration/issue_spec.rb +++ b/spec/integration/issue_spec.rb @@ -44,10 +44,10 @@ } end before(:each) do - stub_request(:get, site_url + '/jira/rest/api/2/search?expand=transitions.fields&maxResults=1000&startAt=0') + stub_request(:get, "#{site_url}/jira/rest/api/2/search?expand=transitions.fields&maxResults=1000&startAt=0") .to_return(status: 200, body: get_mock_response('issue.json')) - stub_request(:get, site_url + '/jira/rest/api/2/search?expand=transitions.fields&maxResults=1000&startAt=11') + stub_request(:get, "#{site_url}/jira/rest/api/2/search?expand=transitions.fields&maxResults=1000&startAt=11") .to_return(status: 200, body: get_mock_response('empty_issues.json')) end it_should_behave_like 'a resource with a collection GET endpoint' @@ -60,9 +60,9 @@ describe 'errors' do before(:each) do stub_request(:get, - site_url + '/jira/rest/api/2/issue/10002') + "#{site_url}/jira/rest/api/2/issue/10002") .to_return(status: 200, body: get_mock_response('issue/10002.json')) - stub_request(:put, site_url + '/jira/rest/api/2/issue/10002') + stub_request(:put, "#{site_url}/jira/rest/api/2/issue/10002") .with(body: '{"missing":"fields and update"}') .to_return(status: 400, body: get_mock_response('issue/10002.put.missing_field_update.json')) end diff --git a/spec/integration/project_spec.rb b/spec/integration/project_spec.rb index 19a9b1ec..eac2c6f3 100644 --- a/spec/integration/project_spec.rb +++ b/spec/integration/project_spec.rb @@ -23,7 +23,7 @@ describe 'issues' do it 'returns all the issues' do - stub_request(:get, site_url + '/jira/rest/api/2/search?jql=project="SAMPLEPROJECT"') + stub_request(:get, "#{site_url}/jira/rest/api/2/search?jql=project=\"SAMPLEPROJECT\"") .to_return(status: 200, body: get_mock_response('project/SAMPLEPROJECT.issues.json')) subject = client.Project.build('key' => key) issues = subject.issues diff --git a/spec/integration/rapidview_spec.rb b/spec/integration/rapidview_spec.rb index 042cc7b3..d161812a 100644 --- a/spec/integration/rapidview_spec.rb +++ b/spec/integration/rapidview_spec.rb @@ -27,7 +27,7 @@ let(:site_url) { site_url } before(:each) do - stub_request(:get, site_url + '/jira/rest/greenhopper/1.0/rapidview') + stub_request(:get, "#{site_url}/jira/rest/greenhopper/1.0/rapidview") .to_return(status: 200, body: get_mock_response('rapidview.json')) end it_should_behave_like 'a resource with a collection GET endpoint' @@ -37,8 +37,7 @@ it 'should return all the issues' do stub_request( :get, - site_url + - '/jira/rest/greenhopper/1.0/xboard/plan/backlog/data?rapidViewId=1' + "#{site_url}/jira/rest/greenhopper/1.0/xboard/plan/backlog/data?rapidViewId=1" ).to_return( status: 200, body: get_mock_response('rapidview/SAMPLEPROJECT.issues.json') @@ -46,7 +45,7 @@ stub_request( :get, - site_url + '/jira/rest/api/2/search?jql=id IN(10001, 10000)' + "#{site_url}/jira/rest/api/2/search?jql=id IN(10001, 10000)" ).to_return( status: 200, body: get_mock_response('rapidview/SAMPLEPROJECT.issues.full.json') @@ -54,7 +53,7 @@ stub_request( :get, - site_url + '/jira/rest/api/2/search?jql=id IN(10000, 10001) AND sprint IS NOT EMPTY' + "#{site_url}/jira/rest/api/2/search?jql=id IN(10000, 10001) AND sprint IS NOT EMPTY" ).to_return( status: 200, body: get_mock_response('rapidview/SAMPLEPROJECT.issues.full.json') diff --git a/spec/integration/watcher_spec.rb b/spec/integration/watcher_spec.rb index 3edb5813..ac17285a 100644 --- a/spec/integration/watcher_spec.rb +++ b/spec/integration/watcher_spec.rb @@ -34,13 +34,13 @@ describe 'watchers' do before(:each) do - stub_request(:get, site_url + '/jira/rest/api/2/issue/10002') + stub_request(:get, "#{site_url}/jira/rest/api/2/issue/10002") .to_return(status: 200, body: get_mock_response('issue/10002.json')) - stub_request(:get, site_url + '/jira/rest/api/2/issue/10002/watchers') + stub_request(:get, "#{site_url}/jira/rest/api/2/issue/10002/watchers") .to_return(status: 200, body: get_mock_response('issue/10002/watchers.json')) - stub_request(:post, site_url + '/jira/rest/api/2/issue/10002/watchers') + stub_request(:post, "#{site_url}/jira/rest/api/2/issue/10002/watchers") .to_return(status: 204, body: nil) end diff --git a/spec/support/shared_examples/integration.rb b/spec/support/shared_examples/integration.rb index 1c3e0a17..70e49b65 100644 --- a/spec/support/shared_examples/integration.rb +++ b/spec/support/shared_examples/integration.rb @@ -2,7 +2,7 @@ def get_mock_from_path(method, options = {}) prefix = if defined? belongs_to - belongs_to.path_component + '/' + "#{belongs_to.path_component}/" else '' end @@ -15,8 +15,8 @@ def get_mock_from_path(method, options = {}) described_class.collection_path(client, prefix) end file_path = url.sub(client.options[:rest_base_path], '') - file_path = file_path + '.' + options[:suffix] if options[:suffix] - file_path = file_path + '.' + method.to_s unless method == :get + file_path = "#{file_path}.#{options[:suffix]}" if options[:suffix] + file_path = "#{file_path}.#{method.to_s}" unless method == :get value_if_not_found = options.key?(:value_if_not_found) ? options[:value_if_not_found] : false get_mock_response("#{file_path}.json", value_if_not_found) end @@ -33,7 +33,7 @@ def options def prefix prefix = '/' - prefix = belongs_to.path_component + '/' if defined? belongs_to + prefix = "#{belongs_to.path_component}/" if defined? belongs_to prefix end @@ -76,10 +76,7 @@ def build_receiver it 'should get the collection' do stub_request( :get, - site_url + - client.options[:rest_base_path] + - '/search?jql=' + - CGI.escape(jql_query_string) + "#{site_url}#{client.options[:rest_base_path]}/search?jql=#{CGI.escape(jql_query_string)}" ).to_return(status: 200, body: get_mock_response('issue.json')) collection = build_receiver.jql(jql_query_string) @@ -114,7 +111,7 @@ def build_receiver it 'handles a 404' do stub_request(:get, site_url + described_class.singular_path(client, '99999', prefix)) - .to_return(status: 404, body: '{"errorMessages":["' + class_basename + ' Does Not Exist"],"errors": {}}') + .to_return(status: 404, body: "{\"errorMessages\":[\"#{class_basename} Does Not Exist\"],\"errors\": {}}") expect do client.send(class_basename).find('99999', options) end.to raise_exception(JIRA::HTTPError) From b584d1260bd43527059d1751f8e1733378d2b04a Mon Sep 17 00:00:00 2001 From: Robert Brodie Date: Sun, 28 Apr 2024 03:17:07 -0400 Subject: [PATCH 09/59] Fixed Layout/SpaceInsideHashLiteralBraces --- lib/jira/jwt_client.rb | 2 +- spec/jira/client_spec.rb | 4 ++-- spec/jira/resource/attachment_spec.rb | 4 ++-- spec/jira/resource/issue_picker_suggestions_spec.rb | 2 +- spec/jira/resource/jira_picker_suggestions_issue_spec.rb | 2 +- spec/jira/resource/sprint_spec.rb | 4 ++-- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/jira/jwt_client.rb b/lib/jira/jwt_client.rb index a32f98ee..39c98548 100644 --- a/lib/jira/jwt_client.rb +++ b/lib/jira/jwt_client.rb @@ -25,7 +25,7 @@ def make_multipart_request(url, data, headers = {}) def build_jwt_header(url) jwt = build_jwt(url) - {'Authorization' => "JWT #{jwt}"} + { 'Authorization' => "JWT #{jwt}" } end def build_jwt(url) diff --git a/spec/jira/client_spec.rb b/spec/jira/client_spec.rb index dfd04948..b98325f3 100644 --- a/spec/jira/client_spec.rb +++ b/spec/jira/client_spec.rb @@ -234,7 +234,7 @@ before(:each) do stub_request(:get, 'https://localhost:2990/jira/rest/api/2/project') - .with(headers: {"Authorization" => /JWT .+/}) + .with(headers: { "Authorization" => /JWT .+/ }) .to_return(status: 200, body: '[]', headers: {}) end @@ -250,7 +250,7 @@ context 'with a incorrect jwt key' do before do stub_request(:get, 'https://localhost:2990/jira/rest/api/2/project') - .with(headers: {"Authorization" => /JWT .+/}) + .with(headers: { "Authorization" => /JWT .+/ }) .to_return(status: 401, body: '[]', headers: {}) end diff --git a/spec/jira/resource/attachment_spec.rb b/spec/jira/resource/attachment_spec.rb index 13cf249d..4aaeff5a 100644 --- a/spec/jira/resource/attachment_spec.rb +++ b/spec/jira/resource/attachment_spec.rb @@ -145,7 +145,7 @@ default_headers: default_headers_given ) end let(:merged_headers) do - {"Accept"=>"application/json", "X-Atlassian-Token"=>"nocheck"}.merge(default_headers_given) + { "Accept"=>"application/json", "X-Atlassian-Token"=>"nocheck" }.merge(default_headers_given) end it 'passes the custom headers' do @@ -199,7 +199,7 @@ default_headers: default_headers_given ) end let(:merged_headers) do - {"Accept"=>"application/json", "X-Atlassian-Token"=>"nocheck"}.merge(default_headers_given) + { "Accept"=>"application/json", "X-Atlassian-Token"=>"nocheck" }.merge(default_headers_given) end it 'passes the custom headers' do diff --git a/spec/jira/resource/issue_picker_suggestions_spec.rb b/spec/jira/resource/issue_picker_suggestions_spec.rb index 6cbc3512..837ac02d 100644 --- a/spec/jira/resource/issue_picker_suggestions_spec.rb +++ b/spec/jira/resource/issue_picker_suggestions_spec.rb @@ -10,7 +10,7 @@ describe 'relationships' do subject do JIRA::Resource::IssuePickerSuggestions.new(client, attrs: { - 'sections' => [{ 'id' => 'hs'}, { 'id' => 'cs' }] + 'sections' => [{ 'id' => 'hs' }, { 'id' => 'cs' }] }) end diff --git a/spec/jira/resource/jira_picker_suggestions_issue_spec.rb b/spec/jira/resource/jira_picker_suggestions_issue_spec.rb index c584b87a..edeef934 100644 --- a/spec/jira/resource/jira_picker_suggestions_issue_spec.rb +++ b/spec/jira/resource/jira_picker_suggestions_issue_spec.rb @@ -6,7 +6,7 @@ describe 'relationships' do subject do JIRA::Resource::IssuePickerSuggestionsIssue.new(client, attrs: { - 'issues' => [{ 'id' => '1'}, { 'id' => '2' }] + 'issues' => [{ 'id' => '1' }, { 'id' => '2' }] }) end diff --git a/spec/jira/resource/sprint_spec.rb b/spec/jira/resource/sprint_spec.rb index b766abb8..0853f72d 100644 --- a/spec/jira/resource/sprint_spec.rb +++ b/spec/jira/resource/sprint_spec.rb @@ -99,7 +99,7 @@ issue end let(:post_issue_input) do - {"issues":[issue.id]} + { "issues":[issue.id] } end @@ -129,7 +129,7 @@ end end let(:post_issue_input) do - {"issues": issue_ids} + { "issues": issue_ids } end describe '#add_issues' do From 0d45b6b09711c69cb32da7d2a2e0f94a1e3fd52d Mon Sep 17 00:00:00 2001 From: Robert Brodie Date: Sun, 28 Apr 2024 03:19:17 -0400 Subject: [PATCH 10/59] Fixed Layout/HashAlignment --- spec/integration/comment_spec.rb | 2 +- spec/integration/component_spec.rb | 2 +- spec/integration/issue_spec.rb | 4 ++-- spec/integration/project_spec.rb | 6 +++--- spec/integration/version_spec.rb | 2 +- spec/integration/worklog_spec.rb | 2 +- spec/jira/resource/issue_spec.rb | 22 +++++++++++----------- spec/jira/resource/project_spec.rb | 8 ++++---- 8 files changed, 24 insertions(+), 24 deletions(-) diff --git a/spec/integration/comment_spec.rb b/spec/integration/comment_spec.rb index a8157467..2ecf6e49 100644 --- a/spec/integration/comment_spec.rb +++ b/spec/integration/comment_spec.rb @@ -23,7 +23,7 @@ let(:expected_attributes) do { 'self' => 'http://localhost:2990/jira/rest/api/2/issue/10002/comment/10000', - 'id' => key, + 'id' => key, 'body' => 'This is a comment. Creative.' } end diff --git a/spec/integration/component_spec.rb b/spec/integration/component_spec.rb index 8e76bf58..271bccb7 100644 --- a/spec/integration/component_spec.rb +++ b/spec/integration/component_spec.rb @@ -10,7 +10,7 @@ let(:expected_attributes) do { 'self' => 'http://localhost:2990/jira/rest/api/2/component/10000', - 'id' => key, + 'id' => key, 'name' => 'Cheesecake' } end diff --git a/spec/integration/issue_spec.rb b/spec/integration/issue_spec.rb index 7351ec19..967b2d3e 100644 --- a/spec/integration/issue_spec.rb +++ b/spec/integration/issue_spec.rb @@ -9,8 +9,8 @@ let(:expected_attributes) do { - 'self' => 'http://localhost:2990/jira/rest/api/2/issue/10002', - 'key' => 'SAMPLEPROJECT-1', + 'self' => 'http://localhost:2990/jira/rest/api/2/issue/10002', + 'key' => 'SAMPLEPROJECT-1', 'expand' => 'renderedFields,names,schema,transitions,editmeta,changelog' } end diff --git a/spec/integration/project_spec.rb b/spec/integration/project_spec.rb index eac2c6f3..785382da 100644 --- a/spec/integration/project_spec.rb +++ b/spec/integration/project_spec.rb @@ -9,9 +9,9 @@ let(:expected_attributes) do { - 'self' => 'http://localhost:2990/jira/rest/api/2/project/SAMPLEPROJECT', - 'key' => key, - 'name' => 'Sample Project for Developing RoR RESTful API' + 'self' => 'http://localhost:2990/jira/rest/api/2/project/SAMPLEPROJECT', + 'key' => key, + 'name' => 'Sample Project for Developing RoR RESTful API' } end diff --git a/spec/integration/version_spec.rb b/spec/integration/version_spec.rb index bd24ac26..03684092 100644 --- a/spec/integration/version_spec.rb +++ b/spec/integration/version_spec.rb @@ -10,7 +10,7 @@ let(:expected_attributes) do { 'self' => 'http://localhost:2990/jira/rest/api/2/version/10000', - 'id' => key, + 'id' => key, 'description' => 'Initial version' } end diff --git a/spec/integration/worklog_spec.rb b/spec/integration/worklog_spec.rb index 15ff7b0f..104a1d53 100644 --- a/spec/integration/worklog_spec.rb +++ b/spec/integration/worklog_spec.rb @@ -22,7 +22,7 @@ let(:expected_attributes) do { 'self' => 'http://localhost:2990/jira/rest/api/2/issue/10002/worklog/10000', - 'id' => key, + 'id' => key, 'comment' => 'Some epic work.' } end diff --git a/spec/jira/resource/issue_spec.rb b/spec/jira/resource/issue_spec.rb index 9fbcb5d2..e63ce4f3 100644 --- a/spec/jira/resource/issue_spec.rb +++ b/spec/jira/resource/issue_spec.rb @@ -175,17 +175,17 @@ class JIRAResourceDelegation < SimpleDelegator # :nodoc: 'id' => '123', 'fields' => { 'reporter' => { 'foo' => 'bar' }, - 'assignee' => { 'foo' => 'bar' }, - 'project' => { 'foo' => 'bar' }, - 'priority' => { 'foo' => 'bar' }, - 'issuetype' => { 'foo' => 'bar' }, - 'status' => { 'foo' => 'bar' }, - 'resolution' => { 'foo' => 'bar' }, - 'components' => [{ 'foo' => 'bar' }, { 'baz' => 'flum' }], - 'versions' => [{ 'foo' => 'bar' }, { 'baz' => 'flum' }], - 'comment' => { 'comments' => [{ 'foo' => 'bar' }, { 'baz' => 'flum' }] }, - 'attachment' => [{ 'foo' => 'bar' }, { 'baz' => 'flum' }], - 'worklog' => { 'worklogs' => [{ 'foo' => 'bar' }, { 'baz' => 'flum' }] } + 'assignee' => { 'foo' => 'bar' }, + 'project' => { 'foo' => 'bar' }, + 'priority' => { 'foo' => 'bar' }, + 'issuetype' => { 'foo' => 'bar' }, + 'status' => { 'foo' => 'bar' }, + 'resolution' => { 'foo' => 'bar' }, + 'components' => [{ 'foo' => 'bar' }, { 'baz' => 'flum' }], + 'versions' => [{ 'foo' => 'bar' }, { 'baz' => 'flum' }], + 'comment' => { 'comments' => [{ 'foo' => 'bar' }, { 'baz' => 'flum' }] }, + 'attachment' => [{ 'foo' => 'bar' }, { 'baz' => 'flum' }], + 'worklog' => { 'worklogs' => [{ 'foo' => 'bar' }, { 'baz' => 'flum' }] } } }) end diff --git a/spec/jira/resource/project_spec.rb b/spec/jira/resource/project_spec.rb index df8e102b..24123a81 100644 --- a/spec/jira/resource/project_spec.rb +++ b/spec/jira/resource/project_spec.rb @@ -10,9 +10,9 @@ describe 'relationships' do subject do JIRA::Resource::Project.new(client, attrs: { - 'lead' => { 'foo' => 'bar' }, - 'issueTypes' => [{ 'foo' => 'bar' }, { 'baz' => 'flum' }], - 'versions' => [{ 'foo' => 'bar' }, { 'baz' => 'flum' }] + 'lead' => { 'foo' => 'bar' }, + 'issueTypes' => [{ 'foo' => 'bar' }, { 'baz' => 'flum' }], + 'versions' => [{ 'foo' => 'bar' }, { 'baz' => 'flum' }] }) end @@ -31,7 +31,7 @@ describe 'issues' do subject do JIRA::Resource::Project.new(client, attrs: { - 'key' => 'test' + 'key' => 'test' }) end From ec5fb07773a005aa5143daf7c08dd48c07f226f0 Mon Sep 17 00:00:00 2001 From: Robert Brodie Date: Sun, 28 Apr 2024 03:20:21 -0400 Subject: [PATCH 11/59] Fixed Style/StringLiterals --- spec/integration/watcher_spec.rb | 2 +- spec/jira/client_spec.rb | 4 ++-- spec/jira/resource/attachment_spec.rb | 10 +++++----- spec/jira/resource/sprint_spec.rb | 4 ++-- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/spec/integration/watcher_spec.rb b/spec/integration/watcher_spec.rb index ac17285a..b323c69f 100644 --- a/spec/integration/watcher_spec.rb +++ b/spec/integration/watcher_spec.rb @@ -53,7 +53,7 @@ it 'should add a watcher' do issue = client.Issue.find('10002') watcher = JIRA::Resource::Watcher.new(client, issue: issue) - user_id = "tester" + user_id = 'tester' watcher.save!(user_id) end end diff --git a/spec/jira/client_spec.rb b/spec/jira/client_spec.rb index b98325f3..e1b3f5ca 100644 --- a/spec/jira/client_spec.rb +++ b/spec/jira/client_spec.rb @@ -234,7 +234,7 @@ before(:each) do stub_request(:get, 'https://localhost:2990/jira/rest/api/2/project') - .with(headers: { "Authorization" => /JWT .+/ }) + .with(headers: { 'Authorization' => /JWT .+/ }) .to_return(status: 200, body: '[]', headers: {}) end @@ -250,7 +250,7 @@ context 'with a incorrect jwt key' do before do stub_request(:get, 'https://localhost:2990/jira/rest/api/2/project') - .with(headers: { "Authorization" => /JWT .+/ }) + .with(headers: { 'Authorization' => /JWT .+/ }) .to_return(status: 401, body: '[]', headers: {}) end diff --git a/spec/jira/resource/attachment_spec.rb b/spec/jira/resource/attachment_spec.rb index 4aaeff5a..8d377d5a 100644 --- a/spec/jira/resource/attachment_spec.rb +++ b/spec/jira/resource/attachment_spec.rb @@ -65,7 +65,7 @@ end let(:attachment_file_contents) { 'file contents' } let(:file_target) { double(read: :attachment_file_contents) } - let(:attachment_url) { "https:jirahost/secure/attachment/32323/myfile.txt" } + let(:attachment_url) { 'https:jirahost/secure/attachment/32323/myfile.txt' } subject(:attachment) do JIRA::Resource::Attachment.new( client, @@ -139,13 +139,13 @@ attrs: { 'author' => { 'foo' => 'bar' } } ) end - let(:default_headers_given) { { 'authorization' => "Bearer 83CF8B609DE60036A8277BD0E96135751BBC07EB234256D4B65B893360651BF2" } } + let(:default_headers_given) { { 'authorization' => 'Bearer 83CF8B609DE60036A8277BD0E96135751BBC07EB234256D4B65B893360651BF2' } } let(:bearer_client) do JIRA::Client.new(username: 'username', password: 'password', auth_type: :basic, use_ssl: false, default_headers: default_headers_given ) end let(:merged_headers) do - { "Accept"=>"application/json", "X-Atlassian-Token"=>"nocheck" }.merge(default_headers_given) + { 'Accept'=>'application/json', 'X-Atlassian-Token'=>'nocheck' }.merge(default_headers_given) end it 'passes the custom headers' do @@ -193,13 +193,13 @@ attrs: { 'author' => { 'foo' => 'bar' } } ) end - let(:default_headers_given) { { 'authorization' => "Bearer 83CF8B609DE60036A8277BD0E96135751BBC07EB234256D4B65B893360651BF2" } } + let(:default_headers_given) { { 'authorization' => 'Bearer 83CF8B609DE60036A8277BD0E96135751BBC07EB234256D4B65B893360651BF2' } } let(:bearer_client) do JIRA::Client.new(username: 'username', password: 'password', auth_type: :basic, use_ssl: false, default_headers: default_headers_given ) end let(:merged_headers) do - { "Accept"=>"application/json", "X-Atlassian-Token"=>"nocheck" }.merge(default_headers_given) + { 'Accept'=>'application/json', 'X-Atlassian-Token'=>'nocheck' }.merge(default_headers_given) end it 'passes the custom headers' do diff --git a/spec/jira/resource/sprint_spec.rb b/spec/jira/resource/sprint_spec.rb index 0853f72d..f71625d7 100644 --- a/spec/jira/resource/sprint_spec.rb +++ b/spec/jira/resource/sprint_spec.rb @@ -91,7 +91,7 @@ let(:issue_id) { 1001 } let(:post_issue_path) do described_class.agile_path(client, sprint.id) - "/jira/rest/agile/1.0/sprint//issue" + '/jira/rest/agile/1.0/sprint//issue' end let(:issue) do issue = double @@ -119,7 +119,7 @@ let(:issue_ids) { [ 1001, 1012 ] } let(:post_issue_path) do described_class.agile_path(client, sprint.id) - "/jira/rest/agile/1.0/sprint//issue" + '/jira/rest/agile/1.0/sprint//issue' end let(:issues) do issue_ids.map do |issue_id| From 08d48f120d323653ad74dc5a0b8e95cd31494002 Mon Sep 17 00:00:00 2001 From: Robert Brodie Date: Sun, 28 Apr 2024 19:05:53 -0400 Subject: [PATCH 12/59] Fixed Layout/LineLength --- lib/jira/base_factory.rb | 3 +- lib/jira/client.rb | 15 +++++--- lib/jira/http_client.rb | 3 +- lib/jira/resource/issue.rb | 9 +++-- lib/jira/resource/issue_picker_suggestions.rb | 3 +- spec/integration/webhook.rb | 3 +- spec/jira/base_spec.rb | 15 +++++--- spec/jira/client_spec.rb | 20 +++++++---- spec/jira/http_client_spec.rb | 18 ++++++---- spec/jira/oauth_client_spec.rb | 9 +++-- spec/jira/resource/attachment_spec.rb | 12 ++++--- spec/jira/resource/field_spec.rb | 36 ++++++++++++++----- 12 files changed, 101 insertions(+), 45 deletions(-) diff --git a/lib/jira/base_factory.rb b/lib/jira/base_factory.rb index 60f2858b..92d5e1ca 100644 --- a/lib/jira/base_factory.rb +++ b/lib/jira/base_factory.rb @@ -38,7 +38,8 @@ def self.delegate_to_target_class(*method_names) # The principle purpose of this class is to delegate methods to the corresponding # non-factory class and automatically prepend the client argument to the argument # list. - delegate_to_target_class :all, :find, :collection_path, :singular_path, :jql, :get_backlog_issues, :get_board_issues, :get_sprints, :get_sprint_issues, :get_projects, :get_projects_full + delegate_to_target_class :all, :find, :collection_path, :singular_path, :jql, :get_backlog_issues, +:get_board_issues, :get_sprints, :get_sprint_issues, :get_projects, :get_projects_full # This method needs special handling as it has a default argument value def build(attrs = {}) diff --git a/lib/jira/client.rb b/lib/jira/client.rb index 0a4c761f..7fc09c94 100644 --- a/lib/jira/client.rb +++ b/lib/jira/client.rb @@ -60,7 +60,8 @@ class Client # The configuration options for this client instance attr_reader :options - def_delegators :@request_client, :init_access_token, :set_access_token, :set_request_token, :request_token, :access_token, :authenticated? + def_delegators :@request_client, :init_access_token, :set_access_token, :set_request_token, :request_token, +:access_token, :authenticated? DEFINED_OPTIONS = [ :site, @@ -121,11 +122,14 @@ def initialize(options = {}) raise ArgumentError, "Unknown option(s) given: #{unknown_options}" unless unknown_options.empty? if options[:use_client_cert] - @options[:ssl_client_cert] = OpenSSL::X509::Certificate.new(File.read(@options[:cert_path])) if @options[:cert_path] + @options[:ssl_client_cert] = +OpenSSL::X509::Certificate.new(File.read(@options[:cert_path])) if @options[:cert_path] @options[:ssl_client_key] = OpenSSL::PKey::RSA.new(File.read(@options[:key_path])) if @options[:key_path] - raise ArgumentError, 'Options: :cert_path or :ssl_client_cert must be set when :use_client_cert is true' unless @options[:ssl_client_cert] - raise ArgumentError, 'Options: :key_path or :ssl_client_key must be set when :use_client_cert is true' unless @options[:ssl_client_key] + raise ArgumentError, +'Options: :cert_path or :ssl_client_cert must be set when :use_client_cert is true' unless @options[:ssl_client_cert] + raise ArgumentError, +'Options: :key_path or :ssl_client_key must be set when :use_client_cert is true' unless @options[:ssl_client_key] end case options[:auth_type] @@ -137,7 +141,8 @@ def initialize(options = {}) when :basic @request_client = HttpClient.new(@options) when :cookie - raise ArgumentError, 'Options: :use_cookies must be true for :cookie authorization type' if @options.key?(:use_cookies) && !@options[:use_cookies] + raise ArgumentError, +'Options: :use_cookies must be true for :cookie authorization type' if @options.key?(:use_cookies) && !@options[:use_cookies] @options[:use_cookies] = true @request_client = HttpClient.new(@options) diff --git a/lib/jira/http_client.rb b/lib/jira/http_client.rb index 5c16d8f8..ce88ce4c 100644 --- a/lib/jira/http_client.rb +++ b/lib/jira/http_client.rb @@ -49,7 +49,8 @@ def basic_auth_http_conn def http_conn(uri) http_conn = if @options[:proxy_address] - Net::HTTP.new(uri.host, uri.port, @options[:proxy_address], @options[:proxy_port] || 80, @options[:proxy_username], @options[:proxy_password]) + Net::HTTP.new(uri.host, uri.port, @options[:proxy_address], @options[:proxy_port] || 80, +@options[:proxy_username], @options[:proxy_password]) else Net::HTTP.new(uri.host, uri.port) end diff --git a/lib/jira/resource/issue.rb b/lib/jira/resource/issue.rb index 32d7141e..efca5bce 100644 --- a/lib/jira/resource/issue.rb +++ b/lib/jira/resource/issue.rb @@ -48,10 +48,12 @@ def self.all(client) result end - def self.jql(client, jql, options = { fields: nil, start_at: nil, max_results: nil, expand: nil, validate_query: true }) + def self.jql(client, jql, options = { fields: nil, start_at: nil, max_results: nil, expand: nil, +validate_query: true }) url = client.options[:rest_base_path] + "/search?jql=#{CGI.escape(jql)}" - url << "&fields=#{options[:fields].map { |value| CGI.escape(client.Field.name_to_id(value)) }.join(',')}" if options[:fields] + url << "&fields=#{options[:fields].map { |value| + CGI.escape(client.Field.name_to_id(value)) }.join(',')}" if options[:fields] url << "&startAt=#{CGI.escape(options[:start_at].to_s)}" if options[:start_at] url << "&maxResults=#{CGI.escape(options[:max_results].to_s)}" if options[:max_results] url << '&validateQuery=false' if options[:validate_query] === false @@ -97,7 +99,8 @@ def editmeta end def respond_to?(method_name, _include_all = false) - if attrs.key?('fields') && [method_name.to_s, client.Field.name_to_id(method_name)].any? { |k| attrs['fields'].key?(k) } + if attrs.key?('fields') && [method_name.to_s, client.Field.name_to_id(method_name)].any? { |k| + attrs['fields'].key?(k) } true else super(method_name) diff --git a/lib/jira/resource/issue_picker_suggestions.rb b/lib/jira/resource/issue_picker_suggestions.rb index 7fd48a06..6a31e454 100644 --- a/lib/jira/resource/issue_picker_suggestions.rb +++ b/lib/jira/resource/issue_picker_suggestions.rb @@ -8,7 +8,8 @@ class IssuePickerSuggestionsFactory < JIRA::BaseFactory # :nodoc: class IssuePickerSuggestions < JIRA::Base has_many :sections, class: JIRA::Resource::IssuePickerSuggestionsIssue - def self.all(client, query = '', options = { current_jql: nil, current_issue_key: nil, current_project_id: nil, show_sub_tasks: nil, show_sub_tasks_parent: nil }) + def self.all(client, query = '', options = { current_jql: nil, current_issue_key: nil, current_project_id: nil, +show_sub_tasks: nil, show_sub_tasks_parent: nil }) url = client.options[:rest_base_path] + "/issue/picker?query=#{CGI.escape(query)}" url << "¤tJQL=#{CGI.escape(options[:current_jql])}" if options[:current_jql] diff --git a/spec/integration/webhook.rb b/spec/integration/webhook.rb index 2c53278b..f1ae6d98 100644 --- a/spec/integration/webhook.rb +++ b/spec/integration/webhook.rb @@ -8,7 +8,8 @@ let(:key) { '2' } let(:expected_attributes) do - { 'name' => 'from API', 'url' => 'http://localhost:3000/webhooks/1', 'excludeBody' => false, 'filters' => { 'issue-related-events-section' => '' }, 'events' => [], 'enabled' => true, 'self' => 'http://localhost:2990/jira/rest/webhooks/1.0/webhook/2', 'lastUpdatedUser' => 'admin', 'lastUpdatedDisplayName' => 'admin', 'lastUpdated' => 1_453_306_520_188 } + { 'name' => 'from API', 'url' => 'http://localhost:3000/webhooks/1', 'excludeBody' => false, +'filters' => { 'issue-related-events-section' => '' }, 'events' => [], 'enabled' => true, 'self' => 'http://localhost:2990/jira/rest/webhooks/1.0/webhook/2', 'lastUpdatedUser' => 'admin', 'lastUpdatedDisplayName' => 'admin', 'lastUpdated' => 1_453_306_520_188 } end let(:expected_collection_length) { 1 } diff --git a/spec/jira/base_spec.rb b/spec/jira/base_spec.rb index 0833a940..8e4ddb98 100644 --- a/spec/jira/base_spec.rb +++ b/spec/jira/base_spec.rb @@ -258,7 +258,8 @@ class JIRA::Resource::HasManyExample < JIRA::Base # :nodoc: it 'returns false when an invalid field is set' do # The JIRA REST API apparently ignores fields that you aren't allowed to set manually response = instance_double('Response', body: '{"errorMessages":["blah"]}', status: 400) allow(subject).to receive(:new_record?) { false } - expect(client).to receive(:put).with('/foo/bar', '{"invalid_field":"foobar"}').and_raise(JIRA::HTTPError.new(response)) + expect(client).to receive(:put).with('/foo/bar', +'{"invalid_field":"foobar"}').and_raise(JIRA::HTTPError.new(response)) expect(subject.save('invalid_field' => 'foobar')).to be_falsey end @@ -300,7 +301,8 @@ class JIRA::Resource::HasManyExample < JIRA::Base # :nodoc: it 'throws an exception when an invalid field is set' do response = instance_double('Response', body: '{"errorMessages":["blah"]}', status: 400) allow(subject).to receive(:new_record?) { false } - expect(client).to receive(:put).with('/foo/bar', '{"invalid_field":"foobar"}').and_raise(JIRA::HTTPError.new(response)) + expect(client).to receive(:put).with('/foo/bar', +'{"invalid_field":"foobar"}').and_raise(JIRA::HTTPError.new(response)) expect{ subject.save!('invalid_field' => 'foobar') }.to raise_error(JIRA::HTTPError) end end @@ -487,7 +489,8 @@ class JIRA::Resource::HasManyExample < JIRA::Base # :nodoc: end it 'allows the has_many attributes to be nested inside another attribute' do - subject = JIRA::Resource::HasManyExample.new(client, attrs: { 'nested' => { 'brunchmuffins' => [{ 'id' => '123' }, { 'id' => '456' }] } }) + subject = JIRA::Resource::HasManyExample.new(client, +attrs: { 'nested' => { 'brunchmuffins' => [{ 'id' => '123' }, { 'id' => '456' }] } }) expect(subject.brunchmuffins.length).to eq(2) subject.brunchmuffins.each do |brunchmuffin| expect(brunchmuffin.class).to eq(JIRA::Resource::Deadbeef) @@ -512,7 +515,8 @@ class JIRA::Resource::HasManyExample < JIRA::Base # :nodoc: end it 'allows the attribute key to be specified' do - subject = JIRA::Resource::HasManyExample.new(client, attrs: { 'irregularlyNamedThings' => [{ 'id' => '123' }, { 'id' => '456' }] }) + subject = JIRA::Resource::HasManyExample.new(client, +attrs: { 'irregularlyNamedThings' => [{ 'id' => '123' }, { 'id' => '456' }] }) expect(subject.irregularly_named_things.length).to eq(2) subject.irregularly_named_things.each do |thing| expect(thing.class).to eq(JIRA::Resource::Deadbeef) @@ -545,7 +549,8 @@ class JIRA::Resource::HasManyExample < JIRA::Base # :nodoc: end it 'allows the has_one attributes to be nested inside another attribute' do - subject = JIRA::Resource::HasOneExample.new(client, attrs: { 'nested' => { 'brunchmuffin' => { 'id' => '123' } } }) + subject = JIRA::Resource::HasOneExample.new(client, +attrs: { 'nested' => { 'brunchmuffin' => { 'id' => '123' } } }) expect(subject.brunchmuffin.class).to eq(JIRA::Resource::Deadbeef) expect(subject.brunchmuffin.id).to eq('123') end diff --git a/spec/jira/client_spec.rb b/spec/jira/client_spec.rb index e1b3f5ca..25642e86 100644 --- a/spec/jira/client_spec.rb +++ b/spec/jira/client_spec.rb @@ -66,9 +66,13 @@ subject { JIRA::Client.new(options) } it 'raises an ArgumentError' do - expect { subject }.to raise_exception(ArgumentError, 'Options: :cert_path or :ssl_client_cert must be set when :use_client_cert is true') + expect { + subject }.to raise_exception(ArgumentError, +'Options: :cert_path or :ssl_client_cert must be set when :use_client_cert is true') options[:ssl_client_cert] = '' - expect { subject }.to raise_exception(ArgumentError, 'Options: :key_path or :ssl_client_key must be set when :use_client_cert is true') + expect { + subject }.to raise_exception(ArgumentError, +'Options: :key_path or :ssl_client_key must be set when :use_client_cert is true') end end end @@ -77,11 +81,13 @@ RSpec.shared_examples 'HttpClient tests' do it 'makes a valid request' do %i[delete get head].each do |method| - expect(subject.request_client).to receive(:make_request).with(method, '/path', nil, headers).and_return(successful_response) + expect(subject.request_client).to receive(:make_request).with(method, '/path', nil, +headers).and_return(successful_response) subject.send(method, '/path', headers) end %i[post put].each do |method| - expect(subject.request_client).to receive(:make_request).with(method, '/path', '', merged_headers).and_return(successful_response) + expect(subject.request_client).to receive(:make_request).with(method, '/path', '', +merged_headers).and_return(successful_response) subject.send(method, '/path', '', headers) end end @@ -106,11 +112,13 @@ describe 'that call a oauth client' do specify 'which makes a request' do %i[delete get head].each do |method| - expect(subject.request_client).to receive(:make_request).with(method, '/path', nil, headers).and_return(successful_response) + expect(subject.request_client).to receive(:make_request).with(method, '/path', nil, +headers).and_return(successful_response) subject.send(method, '/path', {}) end %i[post put].each do |method| - expect(subject.request_client).to receive(:make_request).with(method, '/path', '', merged_headers).and_return(successful_response) + expect(subject.request_client).to receive(:make_request).with(method, '/path', '', +merged_headers).and_return(successful_response) subject.send(method, '/path', '', {}) end end diff --git a/spec/jira/http_client_spec.rb b/spec/jira/http_client_spec.rb index 9a0a96da..436b5e9a 100644 --- a/spec/jira/http_client_spec.rb +++ b/spec/jira/http_client_spec.rb @@ -149,7 +149,8 @@ basic_auth_http_conn = double request = double allow(basic_client).to receive(:basic_auth_http_conn).and_return(basic_auth_http_conn) - expect(request).to receive(:basic_auth).with(basic_client.options[:username], basic_client.options[:password]).exactly(5).times.and_return(request) + expect(request).to receive(:basic_auth).with(basic_client.options[:username], +basic_client.options[:password]).exactly(5).times.and_return(request) expect(basic_auth_http_conn).to receive(:request).exactly(5).times.with(request).and_return(response) %i[delete get head].each do |method| expect(Net::HTTP.const_get(method.to_s.capitalize)).to receive(:new).with('/path', headers).and_return(request) @@ -168,7 +169,8 @@ basic_auth_http_conn = double request = double allow(basic_cookie_client).to receive(:basic_auth_http_conn).and_return(basic_auth_http_conn) - expect(request).to receive(:basic_auth).with(basic_cookie_client.options[:username], basic_cookie_client.options[:password]).exactly(5).times.and_return(request) + expect(request).to receive(:basic_auth).with(basic_cookie_client.options[:username], +basic_cookie_client.options[:password]).exactly(5).times.and_return(request) expect(cookie_response).to receive(:get_fields).with('set-cookie').exactly(5).times expect(basic_auth_http_conn).to receive(:request).exactly(5).times.with(request).and_return(cookie_response) %i[delete get head].each do |method| @@ -189,7 +191,8 @@ basic_auth_http_conn = double request = double allow(client).to receive(:basic_auth_http_conn).and_return(basic_auth_http_conn) - expect(request).to receive(:basic_auth).with(client.options[:username], client.options[:password]).exactly(5).times.and_return(request) + expect(request).to receive(:basic_auth).with(client.options[:username], +client.options[:password]).exactly(5).times.and_return(request) expect(request).to receive(:add_field).with('Cookie', 'sessionToken=abc123; internal=true').exactly(5).times expect(cookie_response).to receive(:get_fields).with('set-cookie').exactly(5).times expect(basic_auth_http_conn).to receive(:request).exactly(5).times.with(request).and_return(cookie_response) @@ -212,7 +215,8 @@ expect(Net::HTTP::Get).to receive(:new).with('/foo', headers).and_return(http_request) expect(basic_auth_http_conn).to receive(:request).with(http_request).and_return(response) - expect(http_request).to receive(:basic_auth).with(basic_client.options[:username], basic_client.options[:password]).and_return(http_request) + expect(http_request).to receive(:basic_auth).with(basic_client.options[:username], +basic_client.options[:password]).and_return(http_request) allow(basic_client).to receive(:basic_auth_http_conn).and_return(basic_auth_http_conn) basic_client.make_request(:get, '/foo', body, headers) end @@ -225,7 +229,8 @@ expect(Net::HTTP::Get).to receive(:new).with('/foo', headers).and_return(http_request) expect(basic_auth_http_conn).to receive(:request).with(http_request).and_return(response) - expect(http_request).to receive(:basic_auth).with(basic_client.options[:username], basic_client.options[:password]).and_return(http_request) + expect(http_request).to receive(:basic_auth).with(basic_client.options[:username], +basic_client.options[:password]).and_return(http_request) allow(basic_client).to receive(:basic_auth_http_conn).and_return(basic_auth_http_conn) basic_client.make_request(:get, 'http://mydomain.com/foo', body, headers) end @@ -381,7 +386,8 @@ end it 'performs a basic http client request' do - expect(request).to receive(:basic_auth).with(basic_client.options[:username], basic_client.options[:password]).and_return(request) + expect(request).to receive(:basic_auth).with(basic_client.options[:username], +basic_client.options[:password]).and_return(request) subject end diff --git a/spec/jira/oauth_client_spec.rb b/spec/jira/oauth_client_spec.rb index 165443e8..5f665c59 100644 --- a/spec/jira/oauth_client_spec.rb +++ b/spec/jira/oauth_client_spec.rb @@ -136,7 +136,8 @@ it 'signs the access_token and performs the request' do expect(access_token).to receive(:sign!).with(an_instance_of(Net::HTTP::Post::Multipart)) - expect(oauth_client.consumer).to receive_message_chain(:http, :request).with(an_instance_of(Net::HTTP::Post::Multipart)) + expect(oauth_client.consumer).to receive_message_chain(:http, +:request).with(an_instance_of(Net::HTTP::Post::Multipart)) subject end @@ -169,11 +170,13 @@ mock_access_token = double allow(oauth__2legged_client).to receive(:access_token).and_return(mock_access_token) %i[delete get head].each do |method| - expect(mock_access_token).to receive(method).with('/path?any_param=toto&oauth_token=', headers).and_return(response) + expect(mock_access_token).to receive(method).with('/path?any_param=toto&oauth_token=', +headers).and_return(response) oauth__2legged_client.make_request(method, '/path?any_param=toto', '', headers) end %i[post put].each do |method| - expect(mock_access_token).to receive(method).with('/path?any_param=toto&oauth_token=', '', headers).and_return(response) + expect(mock_access_token).to receive(method).with('/path?any_param=toto&oauth_token=', '', +headers).and_return(response) oauth__2legged_client.make_request(method, '/path?any_param=toto', '', headers) end end diff --git a/spec/jira/resource/attachment_spec.rb b/spec/jira/resource/attachment_spec.rb index 8d377d5a..8fa30547 100644 --- a/spec/jira/resource/attachment_spec.rb +++ b/spec/jira/resource/attachment_spec.rb @@ -139,7 +139,8 @@ attrs: { 'author' => { 'foo' => 'bar' } } ) end - let(:default_headers_given) { { 'authorization' => 'Bearer 83CF8B609DE60036A8277BD0E96135751BBC07EB234256D4B65B893360651BF2' } } + let(:default_headers_given) { + { 'authorization' => 'Bearer 83CF8B609DE60036A8277BD0E96135751BBC07EB234256D4B65B893360651BF2' } } let(:bearer_client) do JIRA::Client.new(username: 'username', password: 'password', auth_type: :basic, use_ssl: false, default_headers: default_headers_given ) @@ -149,7 +150,8 @@ end it 'passes the custom headers' do - expect(bearer_client.request_client).to receive(:request_multipart).with(anything, anything, merged_headers).and_return(response) + expect(bearer_client.request_client).to receive(:request_multipart).with(anything, anything, +merged_headers).and_return(response) bearer_attachment.save('file' => path_to_file) @@ -193,7 +195,8 @@ attrs: { 'author' => { 'foo' => 'bar' } } ) end - let(:default_headers_given) { { 'authorization' => 'Bearer 83CF8B609DE60036A8277BD0E96135751BBC07EB234256D4B65B893360651BF2' } } + let(:default_headers_given) { + { 'authorization' => 'Bearer 83CF8B609DE60036A8277BD0E96135751BBC07EB234256D4B65B893360651BF2' } } let(:bearer_client) do JIRA::Client.new(username: 'username', password: 'password', auth_type: :basic, use_ssl: false, default_headers: default_headers_given ) @@ -203,7 +206,8 @@ end it 'passes the custom headers' do - expect(bearer_client.request_client).to receive(:request_multipart).with(anything, anything, merged_headers).and_return(response) + expect(bearer_client.request_client).to receive(:request_multipart).with(anything, anything, +merged_headers).and_return(response) bearer_attachment.save!('file' => path_to_file) diff --git a/spec/jira/resource/field_spec.rb b/spec/jira/resource/field_spec.rb index eb4aadcd..355cfcd6 100644 --- a/spec/jira/resource/field_spec.rb +++ b/spec/jira/resource/field_spec.rb @@ -10,15 +10,33 @@ allow(client).to receive(:cache).and_return(cache) # info about all fields on the client allow(client.Field).to receive(:all).and_return([ - JIRA::Resource::Field.new(client, attrs: { 'id' => 'customfield_10666', 'name' => 'Priority', 'custom' => true, 'orderable' => true, 'navigable' => true, 'searchable' => true, 'clauseNames' => ['cf[10666]', 'Priority'], 'schema' => { 'type' => 'string', 'custom' => 'com.atlassian.jira.plugin.system.customfieldtypes:select', 'customId' => 10_666 } }), - JIRA::Resource::Field.new(client, attrs: { 'id' => 'issuekey', 'name' => 'Key', 'custom' => false, 'orderable' => false, 'navigable' => true, 'searchable' => false, 'clauseNames' => %w[id issue issuekey key] }), - JIRA::Resource::Field.new(client, attrs: { 'id' => 'priority', 'name' => 'Priority', 'custom' => false, 'orderable' => true, 'navigable' => true, 'searchable' => true, 'clauseNames' => ['priority'], 'schema' => { 'type' => 'priority', 'system' => 'priority' } }), - JIRA::Resource::Field.new(client, attrs: { 'id' => 'summary', 'name' => 'Summary', 'custom' => false, 'orderable' => true, 'navigable' => true, 'searchable' => true, 'clauseNames' => ['summary'], 'schema' => { 'type' => 'string', 'system' => 'summary' } }), - JIRA::Resource::Field.new(client, attrs: { 'id' => 'issuetype', 'name' => 'Issue Type', 'custom' => false, 'orderable' => true, 'navigable' => true, 'searchable' => true, 'clauseNames' => %w[issuetype type], 'schema' => { 'type' => 'issuetype', 'system' => 'issuetype' } }), - JIRA::Resource::Field.new(client, attrs: { 'id' => 'customfield_10111', 'name' => 'SingleWord', 'custom' => true, 'orderable' => true, 'navigable' => true, 'searchable' => true, 'clauseNames' => ['cf[10111]', 'SingleWord'], 'schema' => { 'type' => 'string', 'custom' => 'com.atlassian.jira.plugin.system.customfieldtypes:select', 'customId' => 10_111 } }), - JIRA::Resource::Field.new(client, attrs: { 'id' => 'customfield_10222', 'name' => 'Multi Word', 'custom' => true, 'orderable' => true, 'navigable' => true, 'searchable' => true, 'clauseNames' => ['cf[10222]', 'Multi Word'], 'schema' => { 'type' => 'string', 'custom' => 'com.atlassian.jira.plugin.system.customfieldtypes:select', 'customId' => 10_222 } }), - JIRA::Resource::Field.new(client, attrs: { 'id' => 'customfield_10333', 'name' => 'Why/N@t', 'custom' => true, 'orderable' => true, 'navigable' => true, 'searchable' => true, 'clauseNames' => ['cf[10333]', 'Why/N@t'], 'schema' => { 'type' => 'string', 'custom' => 'com.atlassian.jira.plugin.system.customfieldtypes:select', 'customId' => 10_333 } }), - JIRA::Resource::Field.new(client, attrs: { 'id' => 'customfield_10444', 'name' => 'SingleWord', 'custom' => true, 'orderable' => true, 'navigable' => true, 'searchable' => true, 'clauseNames' => ['cf[10444]', 'SingleWord'], 'schema' => { 'type' => 'string', 'custom' => 'com.atlassian.jira.plugin.system.customfieldtypes:select', 'customId' => 10_444 } }) + JIRA::Resource::Field.new(client, +attrs: { 'id' => 'customfield_10666', 'name' => 'Priority', 'custom' => true, 'orderable' => true, 'navigable' => true, +'searchable' => true, 'clauseNames' => ['cf[10666]', 'Priority'], 'schema' => { 'type' => 'string', 'custom' => 'com.atlassian.jira.plugin.system.customfieldtypes:select', 'customId' => 10_666 } }), + JIRA::Resource::Field.new(client, +attrs: { 'id' => 'issuekey', 'name' => 'Key', 'custom' => false, 'orderable' => false, +'navigable' => true, 'searchable' => false, 'clauseNames' => %w[id issue issuekey key] }), + JIRA::Resource::Field.new(client, +attrs: { 'id' => 'priority', 'name' => 'Priority', 'custom' => false, 'orderable' => true, +'navigable' => true, 'searchable' => true, 'clauseNames' => ['priority'], 'schema' => { 'type' => 'priority', 'system' => 'priority' } }), + JIRA::Resource::Field.new(client, +attrs: { 'id' => 'summary', 'name' => 'Summary', 'custom' => false, 'orderable' => true, +'navigable' => true, 'searchable' => true, 'clauseNames' => ['summary'], 'schema' => { 'type' => 'string', 'system' => 'summary' } }), + JIRA::Resource::Field.new(client, +attrs: { 'id' => 'issuetype', 'name' => 'Issue Type', 'custom' => false, 'orderable' => true, +'navigable' => true, 'searchable' => true, 'clauseNames' => %w[issuetype type], 'schema' => { 'type' => 'issuetype', 'system' => 'issuetype' } }), + JIRA::Resource::Field.new(client, +attrs: { 'id' => 'customfield_10111', 'name' => 'SingleWord', 'custom' => true, 'orderable' => true, +'navigable' => true, 'searchable' => true, 'clauseNames' => ['cf[10111]', 'SingleWord'], 'schema' => { 'type' => 'string', 'custom' => 'com.atlassian.jira.plugin.system.customfieldtypes:select', 'customId' => 10_111 } }), + JIRA::Resource::Field.new(client, +attrs: { 'id' => 'customfield_10222', 'name' => 'Multi Word', 'custom' => true, 'orderable' => true, +'navigable' => true, 'searchable' => true, 'clauseNames' => ['cf[10222]', 'Multi Word'], 'schema' => { 'type' => 'string', 'custom' => 'com.atlassian.jira.plugin.system.customfieldtypes:select', 'customId' => 10_222 } }), + JIRA::Resource::Field.new(client, +attrs: { 'id' => 'customfield_10333', 'name' => 'Why/N@t', 'custom' => true, 'orderable' => true, +'navigable' => true, 'searchable' => true, 'clauseNames' => ['cf[10333]', 'Why/N@t'], 'schema' => { 'type' => 'string', 'custom' => 'com.atlassian.jira.plugin.system.customfieldtypes:select', 'customId' => 10_333 } }), + JIRA::Resource::Field.new(client, +attrs: { 'id' => 'customfield_10444', 'name' => 'SingleWord', 'custom' => true, 'orderable' => true, +'navigable' => true, 'searchable' => true, 'clauseNames' => ['cf[10444]', 'SingleWord'], 'schema' => { 'type' => 'string', 'custom' => 'com.atlassian.jira.plugin.system.customfieldtypes:select', 'customId' => 10_444 } }) ]) client end From b6063b021c094334384509963cb9b374dc51e51b Mon Sep 17 00:00:00 2001 From: Robert Brodie Date: Sun, 28 Apr 2024 19:07:43 -0400 Subject: [PATCH 13/59] Fixed RSpec/ItBehavesLike --- spec/integration/attachment_spec.rb | 4 ++-- spec/integration/comment_spec.rb | 12 ++++++------ spec/integration/component_spec.rb | 12 ++++++------ spec/integration/field_spec.rb | 6 +++--- spec/integration/issue_spec.rb | 16 ++++++++-------- spec/integration/issuelinktype_spec.rb | 6 +++--- spec/integration/issuetype_spec.rb | 6 +++--- spec/integration/priority_spec.rb | 6 +++--- spec/integration/project_spec.rb | 6 +++--- spec/integration/rapidview_spec.rb | 4 ++-- spec/integration/resolution_spec.rb | 6 +++--- spec/integration/status_category_spec.rb | 6 +++--- spec/integration/status_spec.rb | 6 +++--- spec/integration/transition_spec.rb | 2 +- spec/integration/user_spec.rb | 4 ++-- spec/integration/version_spec.rb | 12 ++++++------ spec/integration/webhook.rb | 6 +++--- spec/integration/worklog_spec.rb | 12 ++++++------ 18 files changed, 66 insertions(+), 66 deletions(-) diff --git a/spec/integration/attachment_spec.rb b/spec/integration/attachment_spec.rb index 1a945608..22dfb62a 100644 --- a/spec/integration/attachment_spec.rb +++ b/spec/integration/attachment_spec.rb @@ -26,7 +26,7 @@ }) end - it_should_behave_like 'a resource with a singular GET endpoint' - it_should_behave_like 'a resource with a DELETE endpoint' + it_behaves_like 'a resource with a singular GET endpoint' + it_behaves_like 'a resource with a DELETE endpoint' end end diff --git a/spec/integration/comment_spec.rb b/spec/integration/comment_spec.rb index 2ecf6e49..2798b39e 100644 --- a/spec/integration/comment_spec.rb +++ b/spec/integration/comment_spec.rb @@ -42,11 +42,11 @@ { 'id' => '10000', 'body' => 'new body' } end - it_should_behave_like 'a resource' - it_should_behave_like 'a resource with a collection GET endpoint' - it_should_behave_like 'a resource with a singular GET endpoint' - it_should_behave_like 'a resource with a DELETE endpoint' - it_should_behave_like 'a resource with a POST endpoint' - it_should_behave_like 'a resource with a PUT endpoint' + it_behaves_like 'a resource' + it_behaves_like 'a resource with a collection GET endpoint' + it_behaves_like 'a resource with a singular GET endpoint' + it_behaves_like 'a resource with a DELETE endpoint' + it_behaves_like 'a resource with a POST endpoint' + it_behaves_like 'a resource with a PUT endpoint' end end diff --git a/spec/integration/component_spec.rb b/spec/integration/component_spec.rb index 271bccb7..ee5771f5 100644 --- a/spec/integration/component_spec.rb +++ b/spec/integration/component_spec.rb @@ -29,11 +29,11 @@ { 'id' => '10000', 'name' => 'Jammy' } end - it_should_behave_like 'a resource' - it_should_behave_like 'a resource with a singular GET endpoint' - it_should_behave_like 'a resource with a DELETE endpoint' - it_should_behave_like 'a resource with a POST endpoint' - it_should_behave_like 'a resource with a PUT endpoint' - it_should_behave_like 'a resource with a PUT endpoint that rejects invalid fields' + it_behaves_like 'a resource' + it_behaves_like 'a resource with a singular GET endpoint' + it_behaves_like 'a resource with a DELETE endpoint' + it_behaves_like 'a resource with a POST endpoint' + it_behaves_like 'a resource with a PUT endpoint' + it_behaves_like 'a resource with a PUT endpoint that rejects invalid fields' end end diff --git a/spec/integration/field_spec.rb b/spec/integration/field_spec.rb index 6eca3549..e3912699 100644 --- a/spec/integration/field_spec.rb +++ b/spec/integration/field_spec.rb @@ -25,8 +25,8 @@ let(:expected_collection_length) { 2 } - it_should_behave_like 'a resource' - it_should_behave_like 'a resource with a collection GET endpoint' - it_should_behave_like 'a resource with a singular GET endpoint' + it_behaves_like 'a resource' + it_behaves_like 'a resource with a collection GET endpoint' + it_behaves_like 'a resource with a singular GET endpoint' end end diff --git a/spec/integration/issue_spec.rb b/spec/integration/issue_spec.rb index 967b2d3e..fe960def 100644 --- a/spec/integration/issue_spec.rb +++ b/spec/integration/issue_spec.rb @@ -30,8 +30,8 @@ end let(:expected_collection_length) { 11 } - it_should_behave_like 'a resource' - it_should_behave_like 'a resource with a singular GET endpoint' + it_behaves_like 'a resource' + it_behaves_like 'a resource with a singular GET endpoint' describe 'GET all issues' do # JIRA::Resource::Issue.all uses the search endpoint let(:client) { client } let(:site_url) { site_url } @@ -50,12 +50,12 @@ stub_request(:get, "#{site_url}/jira/rest/api/2/search?expand=transitions.fields&maxResults=1000&startAt=11") .to_return(status: 200, body: get_mock_response('empty_issues.json')) end - it_should_behave_like 'a resource with a collection GET endpoint' + it_behaves_like 'a resource with a collection GET endpoint' end - it_should_behave_like 'a resource with a DELETE endpoint' - it_should_behave_like 'a resource with a POST endpoint' - it_should_behave_like 'a resource with a PUT endpoint' - it_should_behave_like 'a resource with a PUT endpoint that rejects invalid fields' + it_behaves_like 'a resource with a DELETE endpoint' + it_behaves_like 'a resource with a POST endpoint' + it_behaves_like 'a resource with a PUT endpoint' + it_behaves_like 'a resource with a PUT endpoint that rejects invalid fields' describe 'errors' do before(:each) do @@ -87,7 +87,7 @@ 'key' => 'SAMPLEPROJECT-13' } end - it_should_behave_like 'a resource with JQL inputs and a collection GET endpoint' + it_behaves_like 'a resource with JQL inputs and a collection GET endpoint' end end end diff --git a/spec/integration/issuelinktype_spec.rb b/spec/integration/issuelinktype_spec.rb index ac9dbbd3..8b9dd3d9 100644 --- a/spec/integration/issuelinktype_spec.rb +++ b/spec/integration/issuelinktype_spec.rb @@ -19,8 +19,8 @@ let(:expected_collection_length) { 3 } - it_should_behave_like 'a resource' - it_should_behave_like 'a resource with a collection GET endpoint' - it_should_behave_like 'a resource with a singular GET endpoint' + it_behaves_like 'a resource' + it_behaves_like 'a resource with a collection GET endpoint' + it_behaves_like 'a resource with a singular GET endpoint' end end diff --git a/spec/integration/issuetype_spec.rb b/spec/integration/issuetype_spec.rb index 1618a58a..2433492c 100644 --- a/spec/integration/issuetype_spec.rb +++ b/spec/integration/issuetype_spec.rb @@ -17,8 +17,8 @@ let(:expected_collection_length) { 5 } - it_should_behave_like 'a resource' - it_should_behave_like 'a resource with a collection GET endpoint' - it_should_behave_like 'a resource with a singular GET endpoint' + it_behaves_like 'a resource' + it_behaves_like 'a resource with a collection GET endpoint' + it_behaves_like 'a resource with a singular GET endpoint' end end diff --git a/spec/integration/priority_spec.rb b/spec/integration/priority_spec.rb index d4194626..f4e6e335 100644 --- a/spec/integration/priority_spec.rb +++ b/spec/integration/priority_spec.rb @@ -17,8 +17,8 @@ let(:expected_collection_length) { 5 } - it_should_behave_like 'a resource' - it_should_behave_like 'a resource with a collection GET endpoint' - it_should_behave_like 'a resource with a singular GET endpoint' + it_behaves_like 'a resource' + it_behaves_like 'a resource with a collection GET endpoint' + it_behaves_like 'a resource with a singular GET endpoint' end end diff --git a/spec/integration/project_spec.rb b/spec/integration/project_spec.rb index 785382da..0903ebdc 100644 --- a/spec/integration/project_spec.rb +++ b/spec/integration/project_spec.rb @@ -17,9 +17,9 @@ let(:expected_collection_length) { 1 } - it_should_behave_like 'a resource' - it_should_behave_like 'a resource with a collection GET endpoint' - it_should_behave_like 'a resource with a singular GET endpoint' + it_behaves_like 'a resource' + it_behaves_like 'a resource with a collection GET endpoint' + it_behaves_like 'a resource with a singular GET endpoint' describe 'issues' do it 'returns all the issues' do diff --git a/spec/integration/rapidview_spec.rb b/spec/integration/rapidview_spec.rb index d161812a..be6f6437 100644 --- a/spec/integration/rapidview_spec.rb +++ b/spec/integration/rapidview_spec.rb @@ -18,7 +18,7 @@ } end - it_should_behave_like 'a resource' + it_behaves_like 'a resource' # TODO@Anton: Add json file # it_should_behave_like 'a resource with a singular GET endpoint' @@ -30,7 +30,7 @@ stub_request(:get, "#{site_url}/jira/rest/greenhopper/1.0/rapidview") .to_return(status: 200, body: get_mock_response('rapidview.json')) end - it_should_behave_like 'a resource with a collection GET endpoint' + it_behaves_like 'a resource with a collection GET endpoint' end describe 'issues' do diff --git a/spec/integration/resolution_spec.rb b/spec/integration/resolution_spec.rb index 725ef0b7..7b7f6293 100644 --- a/spec/integration/resolution_spec.rb +++ b/spec/integration/resolution_spec.rb @@ -19,8 +19,8 @@ let(:expected_collection_length) { 2 } - it_should_behave_like 'a resource' - it_should_behave_like 'a resource with a collection GET endpoint' - it_should_behave_like 'a resource with a singular GET endpoint' + it_behaves_like 'a resource' + it_behaves_like 'a resource with a collection GET endpoint' + it_behaves_like 'a resource with a singular GET endpoint' end end diff --git a/spec/integration/status_category_spec.rb b/spec/integration/status_category_spec.rb index 5453f807..f95fd733 100644 --- a/spec/integration/status_category_spec.rb +++ b/spec/integration/status_category_spec.rb @@ -13,8 +13,8 @@ let(:expected_collection_length) { 4 } - it_should_behave_like 'a resource' - it_should_behave_like 'a resource with a collection GET endpoint' - it_should_behave_like 'a resource with a singular GET endpoint' + it_behaves_like 'a resource' + it_behaves_like 'a resource with a collection GET endpoint' + it_behaves_like 'a resource with a singular GET endpoint' end end diff --git a/spec/integration/status_spec.rb b/spec/integration/status_spec.rb index 3a74e764..c3087f96 100644 --- a/spec/integration/status_spec.rb +++ b/spec/integration/status_spec.rb @@ -13,8 +13,8 @@ let(:expected_collection_length) { 5 } - it_should_behave_like 'a resource' - it_should_behave_like 'a resource with a collection GET endpoint' - it_should_behave_like 'a resource with a singular GET endpoint' + it_behaves_like 'a resource' + it_behaves_like 'a resource with a collection GET endpoint' + it_behaves_like 'a resource with a singular GET endpoint' end end diff --git a/spec/integration/transition_spec.rb b/spec/integration/transition_spec.rb index 6c6f0835..a3ff5e8f 100644 --- a/spec/integration/transition_spec.rb +++ b/spec/integration/transition_spec.rb @@ -34,7 +34,7 @@ } end - it_should_behave_like 'a resource' + it_behaves_like 'a resource' describe 'POST endpoint' do it 'saves a new resource' do diff --git a/spec/integration/user_spec.rb b/spec/integration/user_spec.rb index efe66e1f..d0b352d7 100644 --- a/spec/integration/user_spec.rb +++ b/spec/integration/user_spec.rb @@ -15,8 +15,8 @@ } end - it_should_behave_like 'a resource' - it_should_behave_like 'a resource with a singular GET endpoint' + it_behaves_like 'a resource' + it_behaves_like 'a resource with a singular GET endpoint' describe '#all' do let(:client) do diff --git a/spec/integration/version_spec.rb b/spec/integration/version_spec.rb index 03684092..e4abf5c1 100644 --- a/spec/integration/version_spec.rb +++ b/spec/integration/version_spec.rb @@ -29,11 +29,11 @@ { 'id' => '10000', 'name' => '2.0.0' } end - it_should_behave_like 'a resource' - it_should_behave_like 'a resource with a singular GET endpoint' - it_should_behave_like 'a resource with a DELETE endpoint' - it_should_behave_like 'a resource with a POST endpoint' - it_should_behave_like 'a resource with a PUT endpoint' - it_should_behave_like 'a resource with a PUT endpoint that rejects invalid fields' + it_behaves_like 'a resource' + it_behaves_like 'a resource with a singular GET endpoint' + it_behaves_like 'a resource with a DELETE endpoint' + it_behaves_like 'a resource with a POST endpoint' + it_behaves_like 'a resource with a PUT endpoint' + it_behaves_like 'a resource with a PUT endpoint that rejects invalid fields' end end diff --git a/spec/integration/webhook.rb b/spec/integration/webhook.rb index f1ae6d98..1bbea255 100644 --- a/spec/integration/webhook.rb +++ b/spec/integration/webhook.rb @@ -14,9 +14,9 @@ let(:expected_collection_length) { 1 } - it_should_behave_like 'a resource' - it_should_behave_like 'a resource with a collection GET endpoint' - it_should_behave_like 'a resource with a singular GET endpoint' + it_behaves_like 'a resource' + it_behaves_like 'a resource with a collection GET endpoint' + it_behaves_like 'a resource with a singular GET endpoint' it 'returns a collection of components' do stub_request(:get, site_url + described_class.singular_path(client, key)) diff --git a/spec/integration/worklog_spec.rb b/spec/integration/worklog_spec.rb index 104a1d53..2db5fd4d 100644 --- a/spec/integration/worklog_spec.rb +++ b/spec/integration/worklog_spec.rb @@ -41,11 +41,11 @@ { 'id' => '10001', 'timeSpent' => '4d' } end - it_should_behave_like 'a resource' - it_should_behave_like 'a resource with a collection GET endpoint' - it_should_behave_like 'a resource with a singular GET endpoint' - it_should_behave_like 'a resource with a DELETE endpoint' - it_should_behave_like 'a resource with a POST endpoint' - it_should_behave_like 'a resource with a PUT endpoint' + it_behaves_like 'a resource' + it_behaves_like 'a resource with a collection GET endpoint' + it_behaves_like 'a resource with a singular GET endpoint' + it_behaves_like 'a resource with a DELETE endpoint' + it_behaves_like 'a resource with a POST endpoint' + it_behaves_like 'a resource with a PUT endpoint' end end From 3769e1a215ff8a3662b1d0d4cb5e17d498ed3208 Mon Sep 17 00:00:00 2001 From: Robert Brodie Date: Sun, 28 Apr 2024 19:12:55 -0400 Subject: [PATCH 14/59] Move rubocop to its own workflow --- .github/workflows/.rubocop.yml | 18 ++++++++++++++++++ .github/workflows/CI.yml | 23 +---------------------- 2 files changed, 19 insertions(+), 22 deletions(-) create mode 100644 .github/workflows/.rubocop.yml diff --git a/.github/workflows/.rubocop.yml b/.github/workflows/.rubocop.yml new file mode 100644 index 00000000..d22cf590 --- /dev/null +++ b/.github/workflows/.rubocop.yml @@ -0,0 +1,18 @@ +name: Rubocop + +on: [push, pull_request] + +jobs: + rubocop: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: '3.1' + bundler-cache: true + - name: Run rubocop + run: | + bundle exec rubocop \ No newline at end of file diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index e9c002c2..f86e909b 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -3,27 +3,6 @@ name: Ruby on: [push, pull_request] jobs: - lint: - name: CI-lint - runs-on: ubuntu-latest - strategy: - fail-fast: false - matrix: - ruby: - - '3.1' - steps: - - uses: actions/checkout@v4 - - - name: Setup Ruby - uses: ruby/setup-ruby@v1 - with: - ruby-version: ${{ matrix.ruby }} - bundler-cache: true - - - name: Lint - run: | - bundle exec rubocop - test: name: CI-tests runs-on: ubuntu-latest @@ -37,7 +16,7 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Setup Ruby + - name: Set up Ruby uses: ruby/setup-ruby@v1 with: ruby-version: ${{ matrix.ruby }} From cc09d1cf4b6a725eaa5d128f8324e3dd9e66de1f Mon Sep 17 00:00:00 2001 From: Robert Brodie Date: Sun, 28 Apr 2024 19:16:54 -0400 Subject: [PATCH 15/59] Exclude vendor dir on GitHub Actions --- .rubocop.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 57ea727a..6e3fced1 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -5,12 +5,10 @@ AllCops: Exclude: - 'example.rb' - 'http-basic-example.rb' + - 'vendor/**/*' NewCops: enable TargetRubyVersion: 3.1 -Documentation: - Enabled: false - Naming/FileName: Exclude: - 'lib/jira-ruby.rb' @@ -18,6 +16,9 @@ Naming/FileName: Naming/MethodName: Enabled: false +Style/Documentation: + Enabled: false + Style/FrozenStringLiteralComment: Exclude: - 'spec/**/*' \ No newline at end of file From ead14d3ffbc153298cf03382d359fdcec742d076 Mon Sep 17 00:00:00 2001 From: Robert Brodie Date: Sun, 28 Apr 2024 19:19:35 -0400 Subject: [PATCH 16/59] Use GitHub formatter --- .github/workflows/.rubocop.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/.rubocop.yml b/.github/workflows/.rubocop.yml index d22cf590..3bcaa948 100644 --- a/.github/workflows/.rubocop.yml +++ b/.github/workflows/.rubocop.yml @@ -15,4 +15,4 @@ jobs: bundler-cache: true - name: Run rubocop run: | - bundle exec rubocop \ No newline at end of file + bundle exec rubocop --format github \ No newline at end of file From 7777ab5fd0d3d8f3497a8c9083076140f15034a8 Mon Sep 17 00:00:00 2001 From: Robert Brodie Date: Sun, 28 Apr 2024 19:21:49 -0400 Subject: [PATCH 17/59] Fixed RSpec/ExampleWording --- spec/integration/rapidview_spec.rb | 2 +- spec/integration/watcher_spec.rb | 4 +- spec/jira/resource/agile_spec.rb | 26 +++++----- spec/jira/resource/board_spec.rb | 10 ++-- spec/jira/resource/createmeta_spec.rb | 48 +++++++++---------- .../resource/issue_picker_suggestions_spec.rb | 12 ++--- spec/jira/resource/issue_spec.rb | 18 +++---- spec/support/shared_examples/integration.rb | 4 +- 8 files changed, 62 insertions(+), 62 deletions(-) diff --git a/spec/integration/rapidview_spec.rb b/spec/integration/rapidview_spec.rb index be6f6437..ebf96780 100644 --- a/spec/integration/rapidview_spec.rb +++ b/spec/integration/rapidview_spec.rb @@ -34,7 +34,7 @@ end describe 'issues' do - it 'should return all the issues' do + it 'returns all the issues' do stub_request( :get, "#{site_url}/jira/rest/greenhopper/1.0/xboard/plan/backlog/data?rapidViewId=1" diff --git a/spec/integration/watcher_spec.rb b/spec/integration/watcher_spec.rb index b323c69f..04b7f06e 100644 --- a/spec/integration/watcher_spec.rb +++ b/spec/integration/watcher_spec.rb @@ -44,13 +44,13 @@ .to_return(status: 204, body: nil) end - it 'should returns all the watchers' do + it 'returnses all the watchers' do issue = client.Issue.find('10002') watchers = client.Watcher.all(options = { issue: issue }) expect(watchers.length).to eq(1) end - it 'should add a watcher' do + it 'adds a watcher' do issue = client.Issue.find('10002') watcher = JIRA::Resource::Watcher.new(client, issue: issue) user_id = 'tester' diff --git a/spec/jira/resource/agile_spec.rb b/spec/jira/resource/agile_spec.rb index 6b488df3..dcf7b665 100644 --- a/spec/jira/resource/agile_spec.rb +++ b/spec/jira/resource/agile_spec.rb @@ -9,7 +9,7 @@ let(:response) { double } describe '#all' do - it 'should query url without parameters' do + it 'queries url without parameters' do expect(client).to receive(:get).with('/jira/rest/agile/1.0/board').and_return(response) expect(response).to receive(:body).and_return(get_mock_response('board/1.json')) @@ -18,7 +18,7 @@ end describe '#get_backlog_issues' do - it 'should query the url without parameters' do + it 'queries the url without parameters' do expect(client).to receive(:get).with('/jira/rest/agile/1.0/board/1/backlog?maxResults=100').and_return(response) expect(response).to receive(:body).and_return(get_mock_response('board/1.json')) @@ -27,7 +27,7 @@ end describe '#get_board_issues' do - it 'should query correct url without parameters' do + it 'queries correct url without parameters' do expect(client).to receive(:get).with('/jira/rest/agile/1.0/board/1/issue?').and_return(response) expect(response).to receive(:body).and_return(get_mock_response('board/1_issues.json')) @@ -44,7 +44,7 @@ end end - it 'should query correct url with parameters' do + it 'queries correct url with parameters' do expect(client).to receive(:get).with('/jira/rest/agile/1.0/board/1/issue?startAt=50').and_return(response) expect(response).to receive(:body).and_return(get_mock_response('board/1_issues.json')) @@ -63,28 +63,28 @@ end describe '#get_sprints' do - it 'should query correct url without parameters' do + it 'queries correct url without parameters' do expect(client).to receive(:get).with('/jira/rest/agile/1.0/board/1/sprint?maxResults=100').and_return(response) expect(response).to receive(:body).and_return(get_mock_response('board/1.json')) JIRA::Resource::Agile.get_sprints(client, 1) end - it 'should query correct url with parameters' do + it 'queries correct url with parameters' do expect(client).to receive(:get).with('/jira/rest/agile/1.0/board/1/sprint?startAt=50&maxResults=100').and_return(response) expect(response).to receive(:body).and_return(get_mock_response('board/1.json')) JIRA::Resource::Agile.get_sprints(client, 1, startAt: 50) end - it 'should work with pagination starting at 0' do + it 'works with pagination starting at 0' do expect(client).to receive(:get).with('/jira/rest/agile/1.0/board/1/sprint?maxResults=1&startAt=0').and_return(response) expect(response).to receive(:body).and_return(get_mock_response('board/1.json')) JIRA::Resource::Agile.get_sprints(client, 1, maxResults: 1, startAt: 0) end - it 'should work with pagination not starting at 0' do + it 'works with pagination not starting at 0' do expect(client).to receive(:get).with('/jira/rest/agile/1.0/board/1/sprint?maxResults=1&startAt=1').and_return(response) expect(response).to receive(:body).and_return(get_mock_response('board/1.json')) @@ -93,14 +93,14 @@ end describe '#get_sprint_issues' do - it 'should query correct url without parameters' do + it 'queries correct url without parameters' do expect(client).to receive(:get).with('/jira/rest/agile/1.0/sprint/1/issue?maxResults=100').and_return(response) expect(response).to receive(:body).and_return(get_mock_response('sprint/1_issues.json')) JIRA::Resource::Agile.get_sprint_issues(client, 1) end - it 'should query correct url with parameters' do + it 'queries correct url with parameters' do expect(client).to receive(:get).with('/jira/rest/agile/1.0/sprint/1/issue?startAt=50&maxResults=100').and_return(response) expect(response).to receive(:body).and_return(get_mock_response('sprint/1_issues.json')) @@ -109,7 +109,7 @@ end describe '#get_projects_full' do - it 'should query correct url without parameters' do + it 'queries correct url without parameters' do expect(client).to receive(:get).with('/jira/rest/agile/1.0/board/1/project/full').and_return(response) expect(response).to receive(:body).and_return(get_mock_response('board/1.json')) @@ -118,14 +118,14 @@ end describe '#get_projects' do - it 'should query correct url without parameters' do + it 'queries correct url without parameters' do expect(client).to receive(:get).with('/jira/rest/agile/1.0/board/1/project?maxResults=100').and_return(response) expect(response).to receive(:body).and_return(get_mock_response('board/1.json')) JIRA::Resource::Agile.get_projects(client, 1) end - it 'should query correct url with parameters' do + it 'queries correct url with parameters' do expect(client).to receive(:get).with('/jira/rest/agile/1.0/board/1/project?startAt=50&maxResults=100').and_return(response) expect(response).to receive(:body).and_return(get_mock_response('board/1.json')) diff --git a/spec/jira/resource/board_spec.rb b/spec/jira/resource/board_spec.rb index 288889e6..2b14ab08 100644 --- a/spec/jira/resource/board_spec.rb +++ b/spec/jira/resource/board_spec.rb @@ -28,7 +28,7 @@ class JIRAResourceDelegation < SimpleDelegator # :nodoc: JIRA::Resource::Board.find(client, '84') end - it 'should find all boards' do + it 'finds all boards' do response = double api_json = < { 'key' => 'TST=123' } }) response = double diff --git a/spec/support/shared_examples/integration.rb b/spec/support/shared_examples/integration.rb index 70e49b65..d9a48a0b 100644 --- a/spec/support/shared_examples/integration.rb +++ b/spec/support/shared_examples/integration.rb @@ -62,7 +62,7 @@ def build_receiver end shared_examples 'a resource with a collection GET endpoint' do - it 'should get the collection' do + it 'gets the collection' do stub_request(:get, site_url + described_class.collection_path(client)) .to_return(status: 200, body: get_mock_from_path(:get)) collection = build_receiver.all @@ -73,7 +73,7 @@ def build_receiver end shared_examples 'a resource with JQL inputs and a collection GET endpoint' do - it 'should get the collection' do + it 'gets the collection' do stub_request( :get, "#{site_url}#{client.options[:rest_base_path]}/search?jql=#{CGI.escape(jql_query_string)}" From bea40721a02d8c0fe88937666916a297f0c0d2cc Mon Sep 17 00:00:00 2001 From: Robert Brodie Date: Sun, 28 Apr 2024 19:23:02 -0400 Subject: [PATCH 18/59] Fixed Layout/TrailingWhitespace --- lib/jira/base_factory.rb | 2 +- lib/jira/client.rb | 10 +++--- lib/jira/http_client.rb | 2 +- lib/jira/jwt_client.rb | 2 +- lib/jira/resource/issue.rb | 2 +- lib/jira/resource/issue_picker_suggestions.rb | 2 +- spec/integration/webhook.rb | 2 +- spec/jira/base_spec.rb | 10 +++--- spec/jira/client_spec.rb | 12 +++---- spec/jira/http_client_spec.rb | 12 +++---- spec/jira/oauth_client_spec.rb | 6 ++-- spec/jira/resource/attachment_spec.rb | 4 +-- spec/jira/resource/field_spec.rb | 36 +++++++++---------- 13 files changed, 51 insertions(+), 51 deletions(-) diff --git a/lib/jira/base_factory.rb b/lib/jira/base_factory.rb index 92d5e1ca..808ee355 100644 --- a/lib/jira/base_factory.rb +++ b/lib/jira/base_factory.rb @@ -38,7 +38,7 @@ def self.delegate_to_target_class(*method_names) # The principle purpose of this class is to delegate methods to the corresponding # non-factory class and automatically prepend the client argument to the argument # list. - delegate_to_target_class :all, :find, :collection_path, :singular_path, :jql, :get_backlog_issues, + delegate_to_target_class :all, :find, :collection_path, :singular_path, :jql, :get_backlog_issues, :get_board_issues, :get_sprints, :get_sprint_issues, :get_projects, :get_projects_full # This method needs special handling as it has a default argument value diff --git a/lib/jira/client.rb b/lib/jira/client.rb index 7fc09c94..1d395f45 100644 --- a/lib/jira/client.rb +++ b/lib/jira/client.rb @@ -60,7 +60,7 @@ class Client # The configuration options for this client instance attr_reader :options - def_delegators :@request_client, :init_access_token, :set_access_token, :set_request_token, :request_token, + def_delegators :@request_client, :init_access_token, :set_access_token, :set_request_token, :request_token, :access_token, :authenticated? DEFINED_OPTIONS = [ @@ -122,13 +122,13 @@ def initialize(options = {}) raise ArgumentError, "Unknown option(s) given: #{unknown_options}" unless unknown_options.empty? if options[:use_client_cert] - @options[:ssl_client_cert] = + @options[:ssl_client_cert] = OpenSSL::X509::Certificate.new(File.read(@options[:cert_path])) if @options[:cert_path] @options[:ssl_client_key] = OpenSSL::PKey::RSA.new(File.read(@options[:key_path])) if @options[:key_path] - raise ArgumentError, + raise ArgumentError, 'Options: :cert_path or :ssl_client_cert must be set when :use_client_cert is true' unless @options[:ssl_client_cert] - raise ArgumentError, + raise ArgumentError, 'Options: :key_path or :ssl_client_key must be set when :use_client_cert is true' unless @options[:ssl_client_key] end @@ -141,7 +141,7 @@ def initialize(options = {}) when :basic @request_client = HttpClient.new(@options) when :cookie - raise ArgumentError, + raise ArgumentError, 'Options: :use_cookies must be true for :cookie authorization type' if @options.key?(:use_cookies) && !@options[:use_cookies] @options[:use_cookies] = true diff --git a/lib/jira/http_client.rb b/lib/jira/http_client.rb index ce88ce4c..836750f4 100644 --- a/lib/jira/http_client.rb +++ b/lib/jira/http_client.rb @@ -49,7 +49,7 @@ def basic_auth_http_conn def http_conn(uri) http_conn = if @options[:proxy_address] - Net::HTTP.new(uri.host, uri.port, @options[:proxy_address], @options[:proxy_port] || 80, + Net::HTTP.new(uri.host, uri.port, @options[:proxy_address], @options[:proxy_port] || 80, @options[:proxy_username], @options[:proxy_password]) else Net::HTTP.new(uri.host, uri.port) diff --git a/lib/jira/jwt_client.rb b/lib/jira/jwt_client.rb index 39c98548..c5e7ea9b 100644 --- a/lib/jira/jwt_client.rb +++ b/lib/jira/jwt_client.rb @@ -24,7 +24,7 @@ def make_multipart_request(url, data, headers = {}) def build_jwt_header(url) jwt = build_jwt(url) - + { 'Authorization' => "JWT #{jwt}" } end diff --git a/lib/jira/resource/issue.rb b/lib/jira/resource/issue.rb index efca5bce..d5c00b8f 100644 --- a/lib/jira/resource/issue.rb +++ b/lib/jira/resource/issue.rb @@ -48,7 +48,7 @@ def self.all(client) result end - def self.jql(client, jql, options = { fields: nil, start_at: nil, max_results: nil, expand: nil, + def self.jql(client, jql, options = { fields: nil, start_at: nil, max_results: nil, expand: nil, validate_query: true }) url = client.options[:rest_base_path] + "/search?jql=#{CGI.escape(jql)}" diff --git a/lib/jira/resource/issue_picker_suggestions.rb b/lib/jira/resource/issue_picker_suggestions.rb index 6a31e454..6408749a 100644 --- a/lib/jira/resource/issue_picker_suggestions.rb +++ b/lib/jira/resource/issue_picker_suggestions.rb @@ -8,7 +8,7 @@ class IssuePickerSuggestionsFactory < JIRA::BaseFactory # :nodoc: class IssuePickerSuggestions < JIRA::Base has_many :sections, class: JIRA::Resource::IssuePickerSuggestionsIssue - def self.all(client, query = '', options = { current_jql: nil, current_issue_key: nil, current_project_id: nil, + def self.all(client, query = '', options = { current_jql: nil, current_issue_key: nil, current_project_id: nil, show_sub_tasks: nil, show_sub_tasks_parent: nil }) url = client.options[:rest_base_path] + "/issue/picker?query=#{CGI.escape(query)}" diff --git a/spec/integration/webhook.rb b/spec/integration/webhook.rb index 1bbea255..f5ce76f9 100644 --- a/spec/integration/webhook.rb +++ b/spec/integration/webhook.rb @@ -8,7 +8,7 @@ let(:key) { '2' } let(:expected_attributes) do - { 'name' => 'from API', 'url' => 'http://localhost:3000/webhooks/1', 'excludeBody' => false, + { 'name' => 'from API', 'url' => 'http://localhost:3000/webhooks/1', 'excludeBody' => false, 'filters' => { 'issue-related-events-section' => '' }, 'events' => [], 'enabled' => true, 'self' => 'http://localhost:2990/jira/rest/webhooks/1.0/webhook/2', 'lastUpdatedUser' => 'admin', 'lastUpdatedDisplayName' => 'admin', 'lastUpdated' => 1_453_306_520_188 } end diff --git a/spec/jira/base_spec.rb b/spec/jira/base_spec.rb index 8e4ddb98..7bbd40ce 100644 --- a/spec/jira/base_spec.rb +++ b/spec/jira/base_spec.rb @@ -258,7 +258,7 @@ class JIRA::Resource::HasManyExample < JIRA::Base # :nodoc: it 'returns false when an invalid field is set' do # The JIRA REST API apparently ignores fields that you aren't allowed to set manually response = instance_double('Response', body: '{"errorMessages":["blah"]}', status: 400) allow(subject).to receive(:new_record?) { false } - expect(client).to receive(:put).with('/foo/bar', + expect(client).to receive(:put).with('/foo/bar', '{"invalid_field":"foobar"}').and_raise(JIRA::HTTPError.new(response)) expect(subject.save('invalid_field' => 'foobar')).to be_falsey end @@ -301,7 +301,7 @@ class JIRA::Resource::HasManyExample < JIRA::Base # :nodoc: it 'throws an exception when an invalid field is set' do response = instance_double('Response', body: '{"errorMessages":["blah"]}', status: 400) allow(subject).to receive(:new_record?) { false } - expect(client).to receive(:put).with('/foo/bar', + expect(client).to receive(:put).with('/foo/bar', '{"invalid_field":"foobar"}').and_raise(JIRA::HTTPError.new(response)) expect{ subject.save!('invalid_field' => 'foobar') }.to raise_error(JIRA::HTTPError) end @@ -489,7 +489,7 @@ class JIRA::Resource::HasManyExample < JIRA::Base # :nodoc: end it 'allows the has_many attributes to be nested inside another attribute' do - subject = JIRA::Resource::HasManyExample.new(client, + subject = JIRA::Resource::HasManyExample.new(client, attrs: { 'nested' => { 'brunchmuffins' => [{ 'id' => '123' }, { 'id' => '456' }] } }) expect(subject.brunchmuffins.length).to eq(2) subject.brunchmuffins.each do |brunchmuffin| @@ -515,7 +515,7 @@ class JIRA::Resource::HasManyExample < JIRA::Base # :nodoc: end it 'allows the attribute key to be specified' do - subject = JIRA::Resource::HasManyExample.new(client, + subject = JIRA::Resource::HasManyExample.new(client, attrs: { 'irregularlyNamedThings' => [{ 'id' => '123' }, { 'id' => '456' }] }) expect(subject.irregularly_named_things.length).to eq(2) subject.irregularly_named_things.each do |thing| @@ -549,7 +549,7 @@ class JIRA::Resource::HasManyExample < JIRA::Base # :nodoc: end it 'allows the has_one attributes to be nested inside another attribute' do - subject = JIRA::Resource::HasOneExample.new(client, + subject = JIRA::Resource::HasOneExample.new(client, attrs: { 'nested' => { 'brunchmuffin' => { 'id' => '123' } } }) expect(subject.brunchmuffin.class).to eq(JIRA::Resource::Deadbeef) expect(subject.brunchmuffin.id).to eq('123') diff --git a/spec/jira/client_spec.rb b/spec/jira/client_spec.rb index 25642e86..e30d5e73 100644 --- a/spec/jira/client_spec.rb +++ b/spec/jira/client_spec.rb @@ -67,11 +67,11 @@ it 'raises an ArgumentError' do expect { - subject }.to raise_exception(ArgumentError, + subject }.to raise_exception(ArgumentError, 'Options: :cert_path or :ssl_client_cert must be set when :use_client_cert is true') options[:ssl_client_cert] = '' expect { - subject }.to raise_exception(ArgumentError, + subject }.to raise_exception(ArgumentError, 'Options: :key_path or :ssl_client_key must be set when :use_client_cert is true') end end @@ -81,12 +81,12 @@ RSpec.shared_examples 'HttpClient tests' do it 'makes a valid request' do %i[delete get head].each do |method| - expect(subject.request_client).to receive(:make_request).with(method, '/path', nil, + expect(subject.request_client).to receive(:make_request).with(method, '/path', nil, headers).and_return(successful_response) subject.send(method, '/path', headers) end %i[post put].each do |method| - expect(subject.request_client).to receive(:make_request).with(method, '/path', '', + expect(subject.request_client).to receive(:make_request).with(method, '/path', '', merged_headers).and_return(successful_response) subject.send(method, '/path', '', headers) end @@ -112,12 +112,12 @@ describe 'that call a oauth client' do specify 'which makes a request' do %i[delete get head].each do |method| - expect(subject.request_client).to receive(:make_request).with(method, '/path', nil, + expect(subject.request_client).to receive(:make_request).with(method, '/path', nil, headers).and_return(successful_response) subject.send(method, '/path', {}) end %i[post put].each do |method| - expect(subject.request_client).to receive(:make_request).with(method, '/path', '', + expect(subject.request_client).to receive(:make_request).with(method, '/path', '', merged_headers).and_return(successful_response) subject.send(method, '/path', '', {}) end diff --git a/spec/jira/http_client_spec.rb b/spec/jira/http_client_spec.rb index 436b5e9a..03b0ced3 100644 --- a/spec/jira/http_client_spec.rb +++ b/spec/jira/http_client_spec.rb @@ -149,7 +149,7 @@ basic_auth_http_conn = double request = double allow(basic_client).to receive(:basic_auth_http_conn).and_return(basic_auth_http_conn) - expect(request).to receive(:basic_auth).with(basic_client.options[:username], + expect(request).to receive(:basic_auth).with(basic_client.options[:username], basic_client.options[:password]).exactly(5).times.and_return(request) expect(basic_auth_http_conn).to receive(:request).exactly(5).times.with(request).and_return(response) %i[delete get head].each do |method| @@ -169,7 +169,7 @@ basic_auth_http_conn = double request = double allow(basic_cookie_client).to receive(:basic_auth_http_conn).and_return(basic_auth_http_conn) - expect(request).to receive(:basic_auth).with(basic_cookie_client.options[:username], + expect(request).to receive(:basic_auth).with(basic_cookie_client.options[:username], basic_cookie_client.options[:password]).exactly(5).times.and_return(request) expect(cookie_response).to receive(:get_fields).with('set-cookie').exactly(5).times expect(basic_auth_http_conn).to receive(:request).exactly(5).times.with(request).and_return(cookie_response) @@ -191,7 +191,7 @@ basic_auth_http_conn = double request = double allow(client).to receive(:basic_auth_http_conn).and_return(basic_auth_http_conn) - expect(request).to receive(:basic_auth).with(client.options[:username], + expect(request).to receive(:basic_auth).with(client.options[:username], client.options[:password]).exactly(5).times.and_return(request) expect(request).to receive(:add_field).with('Cookie', 'sessionToken=abc123; internal=true').exactly(5).times expect(cookie_response).to receive(:get_fields).with('set-cookie').exactly(5).times @@ -215,7 +215,7 @@ expect(Net::HTTP::Get).to receive(:new).with('/foo', headers).and_return(http_request) expect(basic_auth_http_conn).to receive(:request).with(http_request).and_return(response) - expect(http_request).to receive(:basic_auth).with(basic_client.options[:username], + expect(http_request).to receive(:basic_auth).with(basic_client.options[:username], basic_client.options[:password]).and_return(http_request) allow(basic_client).to receive(:basic_auth_http_conn).and_return(basic_auth_http_conn) basic_client.make_request(:get, '/foo', body, headers) @@ -229,7 +229,7 @@ expect(Net::HTTP::Get).to receive(:new).with('/foo', headers).and_return(http_request) expect(basic_auth_http_conn).to receive(:request).with(http_request).and_return(response) - expect(http_request).to receive(:basic_auth).with(basic_client.options[:username], + expect(http_request).to receive(:basic_auth).with(basic_client.options[:username], basic_client.options[:password]).and_return(http_request) allow(basic_client).to receive(:basic_auth_http_conn).and_return(basic_auth_http_conn) basic_client.make_request(:get, 'http://mydomain.com/foo', body, headers) @@ -386,7 +386,7 @@ end it 'performs a basic http client request' do - expect(request).to receive(:basic_auth).with(basic_client.options[:username], + expect(request).to receive(:basic_auth).with(basic_client.options[:username], basic_client.options[:password]).and_return(request) subject diff --git a/spec/jira/oauth_client_spec.rb b/spec/jira/oauth_client_spec.rb index 5f665c59..b637087e 100644 --- a/spec/jira/oauth_client_spec.rb +++ b/spec/jira/oauth_client_spec.rb @@ -136,7 +136,7 @@ it 'signs the access_token and performs the request' do expect(access_token).to receive(:sign!).with(an_instance_of(Net::HTTP::Post::Multipart)) - expect(oauth_client.consumer).to receive_message_chain(:http, + expect(oauth_client.consumer).to receive_message_chain(:http, :request).with(an_instance_of(Net::HTTP::Post::Multipart)) subject @@ -170,12 +170,12 @@ mock_access_token = double allow(oauth__2legged_client).to receive(:access_token).and_return(mock_access_token) %i[delete get head].each do |method| - expect(mock_access_token).to receive(method).with('/path?any_param=toto&oauth_token=', + expect(mock_access_token).to receive(method).with('/path?any_param=toto&oauth_token=', headers).and_return(response) oauth__2legged_client.make_request(method, '/path?any_param=toto', '', headers) end %i[post put].each do |method| - expect(mock_access_token).to receive(method).with('/path?any_param=toto&oauth_token=', '', + expect(mock_access_token).to receive(method).with('/path?any_param=toto&oauth_token=', '', headers).and_return(response) oauth__2legged_client.make_request(method, '/path?any_param=toto', '', headers) end diff --git a/spec/jira/resource/attachment_spec.rb b/spec/jira/resource/attachment_spec.rb index 8fa30547..9163b9cf 100644 --- a/spec/jira/resource/attachment_spec.rb +++ b/spec/jira/resource/attachment_spec.rb @@ -150,7 +150,7 @@ end it 'passes the custom headers' do - expect(bearer_client.request_client).to receive(:request_multipart).with(anything, anything, + expect(bearer_client.request_client).to receive(:request_multipart).with(anything, anything, merged_headers).and_return(response) bearer_attachment.save('file' => path_to_file) @@ -206,7 +206,7 @@ end it 'passes the custom headers' do - expect(bearer_client.request_client).to receive(:request_multipart).with(anything, anything, + expect(bearer_client.request_client).to receive(:request_multipart).with(anything, anything, merged_headers).and_return(response) bearer_attachment.save!('file' => path_to_file) diff --git a/spec/jira/resource/field_spec.rb b/spec/jira/resource/field_spec.rb index 355cfcd6..ca2f82dc 100644 --- a/spec/jira/resource/field_spec.rb +++ b/spec/jira/resource/field_spec.rb @@ -10,32 +10,32 @@ allow(client).to receive(:cache).and_return(cache) # info about all fields on the client allow(client.Field).to receive(:all).and_return([ - JIRA::Resource::Field.new(client, -attrs: { 'id' => 'customfield_10666', 'name' => 'Priority', 'custom' => true, 'orderable' => true, 'navigable' => true, + JIRA::Resource::Field.new(client, +attrs: { 'id' => 'customfield_10666', 'name' => 'Priority', 'custom' => true, 'orderable' => true, 'navigable' => true, 'searchable' => true, 'clauseNames' => ['cf[10666]', 'Priority'], 'schema' => { 'type' => 'string', 'custom' => 'com.atlassian.jira.plugin.system.customfieldtypes:select', 'customId' => 10_666 } }), - JIRA::Resource::Field.new(client, -attrs: { 'id' => 'issuekey', 'name' => 'Key', 'custom' => false, 'orderable' => false, + JIRA::Resource::Field.new(client, +attrs: { 'id' => 'issuekey', 'name' => 'Key', 'custom' => false, 'orderable' => false, 'navigable' => true, 'searchable' => false, 'clauseNames' => %w[id issue issuekey key] }), - JIRA::Resource::Field.new(client, -attrs: { 'id' => 'priority', 'name' => 'Priority', 'custom' => false, 'orderable' => true, + JIRA::Resource::Field.new(client, +attrs: { 'id' => 'priority', 'name' => 'Priority', 'custom' => false, 'orderable' => true, 'navigable' => true, 'searchable' => true, 'clauseNames' => ['priority'], 'schema' => { 'type' => 'priority', 'system' => 'priority' } }), - JIRA::Resource::Field.new(client, -attrs: { 'id' => 'summary', 'name' => 'Summary', 'custom' => false, 'orderable' => true, + JIRA::Resource::Field.new(client, +attrs: { 'id' => 'summary', 'name' => 'Summary', 'custom' => false, 'orderable' => true, 'navigable' => true, 'searchable' => true, 'clauseNames' => ['summary'], 'schema' => { 'type' => 'string', 'system' => 'summary' } }), - JIRA::Resource::Field.new(client, -attrs: { 'id' => 'issuetype', 'name' => 'Issue Type', 'custom' => false, 'orderable' => true, + JIRA::Resource::Field.new(client, +attrs: { 'id' => 'issuetype', 'name' => 'Issue Type', 'custom' => false, 'orderable' => true, 'navigable' => true, 'searchable' => true, 'clauseNames' => %w[issuetype type], 'schema' => { 'type' => 'issuetype', 'system' => 'issuetype' } }), - JIRA::Resource::Field.new(client, -attrs: { 'id' => 'customfield_10111', 'name' => 'SingleWord', 'custom' => true, 'orderable' => true, + JIRA::Resource::Field.new(client, +attrs: { 'id' => 'customfield_10111', 'name' => 'SingleWord', 'custom' => true, 'orderable' => true, 'navigable' => true, 'searchable' => true, 'clauseNames' => ['cf[10111]', 'SingleWord'], 'schema' => { 'type' => 'string', 'custom' => 'com.atlassian.jira.plugin.system.customfieldtypes:select', 'customId' => 10_111 } }), - JIRA::Resource::Field.new(client, -attrs: { 'id' => 'customfield_10222', 'name' => 'Multi Word', 'custom' => true, 'orderable' => true, + JIRA::Resource::Field.new(client, +attrs: { 'id' => 'customfield_10222', 'name' => 'Multi Word', 'custom' => true, 'orderable' => true, 'navigable' => true, 'searchable' => true, 'clauseNames' => ['cf[10222]', 'Multi Word'], 'schema' => { 'type' => 'string', 'custom' => 'com.atlassian.jira.plugin.system.customfieldtypes:select', 'customId' => 10_222 } }), - JIRA::Resource::Field.new(client, -attrs: { 'id' => 'customfield_10333', 'name' => 'Why/N@t', 'custom' => true, 'orderable' => true, + JIRA::Resource::Field.new(client, +attrs: { 'id' => 'customfield_10333', 'name' => 'Why/N@t', 'custom' => true, 'orderable' => true, 'navigable' => true, 'searchable' => true, 'clauseNames' => ['cf[10333]', 'Why/N@t'], 'schema' => { 'type' => 'string', 'custom' => 'com.atlassian.jira.plugin.system.customfieldtypes:select', 'customId' => 10_333 } }), - JIRA::Resource::Field.new(client, -attrs: { 'id' => 'customfield_10444', 'name' => 'SingleWord', 'custom' => true, 'orderable' => true, + JIRA::Resource::Field.new(client, +attrs: { 'id' => 'customfield_10444', 'name' => 'SingleWord', 'custom' => true, 'orderable' => true, 'navigable' => true, 'searchable' => true, 'clauseNames' => ['cf[10444]', 'SingleWord'], 'schema' => { 'type' => 'string', 'custom' => 'com.atlassian.jira.plugin.system.customfieldtypes:select', 'customId' => 10_444 } }) ]) client From 7127da55279ffc339ea367f55e3f91e20e2070e2 Mon Sep 17 00:00:00 2001 From: Robert Brodie Date: Sun, 28 Apr 2024 19:23:56 -0400 Subject: [PATCH 19/59] Fixed Layout/ArgumentAlignment --- lib/jira/base_factory.rb | 2 +- lib/jira/client.rb | 8 +++--- lib/jira/http_client.rb | 2 +- spec/jira/base_spec.rb | 10 ++++---- spec/jira/client_spec.rb | 12 ++++----- spec/jira/http_client_spec.rb | 12 ++++----- spec/jira/oauth_client_spec.rb | 6 ++--- spec/jira/resource/attachment_spec.rb | 4 +-- spec/jira/resource/field_spec.rb | 36 +++++++++++++-------------- 9 files changed, 46 insertions(+), 46 deletions(-) diff --git a/lib/jira/base_factory.rb b/lib/jira/base_factory.rb index 808ee355..02ec7087 100644 --- a/lib/jira/base_factory.rb +++ b/lib/jira/base_factory.rb @@ -39,7 +39,7 @@ def self.delegate_to_target_class(*method_names) # non-factory class and automatically prepend the client argument to the argument # list. delegate_to_target_class :all, :find, :collection_path, :singular_path, :jql, :get_backlog_issues, -:get_board_issues, :get_sprints, :get_sprint_issues, :get_projects, :get_projects_full + :get_board_issues, :get_sprints, :get_sprint_issues, :get_projects, :get_projects_full # This method needs special handling as it has a default argument value def build(attrs = {}) diff --git a/lib/jira/client.rb b/lib/jira/client.rb index 1d395f45..13f838db 100644 --- a/lib/jira/client.rb +++ b/lib/jira/client.rb @@ -61,7 +61,7 @@ class Client attr_reader :options def_delegators :@request_client, :init_access_token, :set_access_token, :set_request_token, :request_token, -:access_token, :authenticated? + :access_token, :authenticated? DEFINED_OPTIONS = [ :site, @@ -127,9 +127,9 @@ def initialize(options = {}) @options[:ssl_client_key] = OpenSSL::PKey::RSA.new(File.read(@options[:key_path])) if @options[:key_path] raise ArgumentError, -'Options: :cert_path or :ssl_client_cert must be set when :use_client_cert is true' unless @options[:ssl_client_cert] + 'Options: :cert_path or :ssl_client_cert must be set when :use_client_cert is true' unless @options[:ssl_client_cert] raise ArgumentError, -'Options: :key_path or :ssl_client_key must be set when :use_client_cert is true' unless @options[:ssl_client_key] + 'Options: :key_path or :ssl_client_key must be set when :use_client_cert is true' unless @options[:ssl_client_key] end case options[:auth_type] @@ -142,7 +142,7 @@ def initialize(options = {}) @request_client = HttpClient.new(@options) when :cookie raise ArgumentError, -'Options: :use_cookies must be true for :cookie authorization type' if @options.key?(:use_cookies) && !@options[:use_cookies] + 'Options: :use_cookies must be true for :cookie authorization type' if @options.key?(:use_cookies) && !@options[:use_cookies] @options[:use_cookies] = true @request_client = HttpClient.new(@options) diff --git a/lib/jira/http_client.rb b/lib/jira/http_client.rb index 836750f4..17a98ccf 100644 --- a/lib/jira/http_client.rb +++ b/lib/jira/http_client.rb @@ -50,7 +50,7 @@ def http_conn(uri) http_conn = if @options[:proxy_address] Net::HTTP.new(uri.host, uri.port, @options[:proxy_address], @options[:proxy_port] || 80, -@options[:proxy_username], @options[:proxy_password]) + @options[:proxy_username], @options[:proxy_password]) else Net::HTTP.new(uri.host, uri.port) end diff --git a/spec/jira/base_spec.rb b/spec/jira/base_spec.rb index 7bbd40ce..70b85268 100644 --- a/spec/jira/base_spec.rb +++ b/spec/jira/base_spec.rb @@ -259,7 +259,7 @@ class JIRA::Resource::HasManyExample < JIRA::Base # :nodoc: response = instance_double('Response', body: '{"errorMessages":["blah"]}', status: 400) allow(subject).to receive(:new_record?) { false } expect(client).to receive(:put).with('/foo/bar', -'{"invalid_field":"foobar"}').and_raise(JIRA::HTTPError.new(response)) + '{"invalid_field":"foobar"}').and_raise(JIRA::HTTPError.new(response)) expect(subject.save('invalid_field' => 'foobar')).to be_falsey end @@ -302,7 +302,7 @@ class JIRA::Resource::HasManyExample < JIRA::Base # :nodoc: response = instance_double('Response', body: '{"errorMessages":["blah"]}', status: 400) allow(subject).to receive(:new_record?) { false } expect(client).to receive(:put).with('/foo/bar', -'{"invalid_field":"foobar"}').and_raise(JIRA::HTTPError.new(response)) + '{"invalid_field":"foobar"}').and_raise(JIRA::HTTPError.new(response)) expect{ subject.save!('invalid_field' => 'foobar') }.to raise_error(JIRA::HTTPError) end end @@ -490,7 +490,7 @@ class JIRA::Resource::HasManyExample < JIRA::Base # :nodoc: it 'allows the has_many attributes to be nested inside another attribute' do subject = JIRA::Resource::HasManyExample.new(client, -attrs: { 'nested' => { 'brunchmuffins' => [{ 'id' => '123' }, { 'id' => '456' }] } }) + attrs: { 'nested' => { 'brunchmuffins' => [{ 'id' => '123' }, { 'id' => '456' }] } }) expect(subject.brunchmuffins.length).to eq(2) subject.brunchmuffins.each do |brunchmuffin| expect(brunchmuffin.class).to eq(JIRA::Resource::Deadbeef) @@ -516,7 +516,7 @@ class JIRA::Resource::HasManyExample < JIRA::Base # :nodoc: it 'allows the attribute key to be specified' do subject = JIRA::Resource::HasManyExample.new(client, -attrs: { 'irregularlyNamedThings' => [{ 'id' => '123' }, { 'id' => '456' }] }) + attrs: { 'irregularlyNamedThings' => [{ 'id' => '123' }, { 'id' => '456' }] }) expect(subject.irregularly_named_things.length).to eq(2) subject.irregularly_named_things.each do |thing| expect(thing.class).to eq(JIRA::Resource::Deadbeef) @@ -550,7 +550,7 @@ class JIRA::Resource::HasManyExample < JIRA::Base # :nodoc: it 'allows the has_one attributes to be nested inside another attribute' do subject = JIRA::Resource::HasOneExample.new(client, -attrs: { 'nested' => { 'brunchmuffin' => { 'id' => '123' } } }) + attrs: { 'nested' => { 'brunchmuffin' => { 'id' => '123' } } }) expect(subject.brunchmuffin.class).to eq(JIRA::Resource::Deadbeef) expect(subject.brunchmuffin.id).to eq('123') end diff --git a/spec/jira/client_spec.rb b/spec/jira/client_spec.rb index e30d5e73..978212fb 100644 --- a/spec/jira/client_spec.rb +++ b/spec/jira/client_spec.rb @@ -68,11 +68,11 @@ it 'raises an ArgumentError' do expect { subject }.to raise_exception(ArgumentError, -'Options: :cert_path or :ssl_client_cert must be set when :use_client_cert is true') + 'Options: :cert_path or :ssl_client_cert must be set when :use_client_cert is true') options[:ssl_client_cert] = '' expect { subject }.to raise_exception(ArgumentError, -'Options: :key_path or :ssl_client_key must be set when :use_client_cert is true') + 'Options: :key_path or :ssl_client_key must be set when :use_client_cert is true') end end end @@ -82,12 +82,12 @@ it 'makes a valid request' do %i[delete get head].each do |method| expect(subject.request_client).to receive(:make_request).with(method, '/path', nil, -headers).and_return(successful_response) + headers).and_return(successful_response) subject.send(method, '/path', headers) end %i[post put].each do |method| expect(subject.request_client).to receive(:make_request).with(method, '/path', '', -merged_headers).and_return(successful_response) + merged_headers).and_return(successful_response) subject.send(method, '/path', '', headers) end end @@ -113,12 +113,12 @@ specify 'which makes a request' do %i[delete get head].each do |method| expect(subject.request_client).to receive(:make_request).with(method, '/path', nil, -headers).and_return(successful_response) + headers).and_return(successful_response) subject.send(method, '/path', {}) end %i[post put].each do |method| expect(subject.request_client).to receive(:make_request).with(method, '/path', '', -merged_headers).and_return(successful_response) + merged_headers).and_return(successful_response) subject.send(method, '/path', '', {}) end end diff --git a/spec/jira/http_client_spec.rb b/spec/jira/http_client_spec.rb index 03b0ced3..ee4cfdc2 100644 --- a/spec/jira/http_client_spec.rb +++ b/spec/jira/http_client_spec.rb @@ -150,7 +150,7 @@ request = double allow(basic_client).to receive(:basic_auth_http_conn).and_return(basic_auth_http_conn) expect(request).to receive(:basic_auth).with(basic_client.options[:username], -basic_client.options[:password]).exactly(5).times.and_return(request) + basic_client.options[:password]).exactly(5).times.and_return(request) expect(basic_auth_http_conn).to receive(:request).exactly(5).times.with(request).and_return(response) %i[delete get head].each do |method| expect(Net::HTTP.const_get(method.to_s.capitalize)).to receive(:new).with('/path', headers).and_return(request) @@ -170,7 +170,7 @@ request = double allow(basic_cookie_client).to receive(:basic_auth_http_conn).and_return(basic_auth_http_conn) expect(request).to receive(:basic_auth).with(basic_cookie_client.options[:username], -basic_cookie_client.options[:password]).exactly(5).times.and_return(request) + basic_cookie_client.options[:password]).exactly(5).times.and_return(request) expect(cookie_response).to receive(:get_fields).with('set-cookie').exactly(5).times expect(basic_auth_http_conn).to receive(:request).exactly(5).times.with(request).and_return(cookie_response) %i[delete get head].each do |method| @@ -192,7 +192,7 @@ request = double allow(client).to receive(:basic_auth_http_conn).and_return(basic_auth_http_conn) expect(request).to receive(:basic_auth).with(client.options[:username], -client.options[:password]).exactly(5).times.and_return(request) + client.options[:password]).exactly(5).times.and_return(request) expect(request).to receive(:add_field).with('Cookie', 'sessionToken=abc123; internal=true').exactly(5).times expect(cookie_response).to receive(:get_fields).with('set-cookie').exactly(5).times expect(basic_auth_http_conn).to receive(:request).exactly(5).times.with(request).and_return(cookie_response) @@ -216,7 +216,7 @@ expect(basic_auth_http_conn).to receive(:request).with(http_request).and_return(response) expect(http_request).to receive(:basic_auth).with(basic_client.options[:username], -basic_client.options[:password]).and_return(http_request) + basic_client.options[:password]).and_return(http_request) allow(basic_client).to receive(:basic_auth_http_conn).and_return(basic_auth_http_conn) basic_client.make_request(:get, '/foo', body, headers) end @@ -230,7 +230,7 @@ expect(basic_auth_http_conn).to receive(:request).with(http_request).and_return(response) expect(http_request).to receive(:basic_auth).with(basic_client.options[:username], -basic_client.options[:password]).and_return(http_request) + basic_client.options[:password]).and_return(http_request) allow(basic_client).to receive(:basic_auth_http_conn).and_return(basic_auth_http_conn) basic_client.make_request(:get, 'http://mydomain.com/foo', body, headers) end @@ -387,7 +387,7 @@ it 'performs a basic http client request' do expect(request).to receive(:basic_auth).with(basic_client.options[:username], -basic_client.options[:password]).and_return(request) + basic_client.options[:password]).and_return(request) subject end diff --git a/spec/jira/oauth_client_spec.rb b/spec/jira/oauth_client_spec.rb index b637087e..4f7de9f9 100644 --- a/spec/jira/oauth_client_spec.rb +++ b/spec/jira/oauth_client_spec.rb @@ -137,7 +137,7 @@ it 'signs the access_token and performs the request' do expect(access_token).to receive(:sign!).with(an_instance_of(Net::HTTP::Post::Multipart)) expect(oauth_client.consumer).to receive_message_chain(:http, -:request).with(an_instance_of(Net::HTTP::Post::Multipart)) + :request).with(an_instance_of(Net::HTTP::Post::Multipart)) subject end @@ -171,12 +171,12 @@ allow(oauth__2legged_client).to receive(:access_token).and_return(mock_access_token) %i[delete get head].each do |method| expect(mock_access_token).to receive(method).with('/path?any_param=toto&oauth_token=', -headers).and_return(response) + headers).and_return(response) oauth__2legged_client.make_request(method, '/path?any_param=toto', '', headers) end %i[post put].each do |method| expect(mock_access_token).to receive(method).with('/path?any_param=toto&oauth_token=', '', -headers).and_return(response) + headers).and_return(response) oauth__2legged_client.make_request(method, '/path?any_param=toto', '', headers) end end diff --git a/spec/jira/resource/attachment_spec.rb b/spec/jira/resource/attachment_spec.rb index 9163b9cf..fd231b99 100644 --- a/spec/jira/resource/attachment_spec.rb +++ b/spec/jira/resource/attachment_spec.rb @@ -151,7 +151,7 @@ it 'passes the custom headers' do expect(bearer_client.request_client).to receive(:request_multipart).with(anything, anything, -merged_headers).and_return(response) + merged_headers).and_return(response) bearer_attachment.save('file' => path_to_file) @@ -207,7 +207,7 @@ it 'passes the custom headers' do expect(bearer_client.request_client).to receive(:request_multipart).with(anything, anything, -merged_headers).and_return(response) + merged_headers).and_return(response) bearer_attachment.save!('file' => path_to_file) diff --git a/spec/jira/resource/field_spec.rb b/spec/jira/resource/field_spec.rb index ca2f82dc..f1ee5b18 100644 --- a/spec/jira/resource/field_spec.rb +++ b/spec/jira/resource/field_spec.rb @@ -11,32 +11,32 @@ # info about all fields on the client allow(client.Field).to receive(:all).and_return([ JIRA::Resource::Field.new(client, -attrs: { 'id' => 'customfield_10666', 'name' => 'Priority', 'custom' => true, 'orderable' => true, 'navigable' => true, -'searchable' => true, 'clauseNames' => ['cf[10666]', 'Priority'], 'schema' => { 'type' => 'string', 'custom' => 'com.atlassian.jira.plugin.system.customfieldtypes:select', 'customId' => 10_666 } }), + attrs: { 'id' => 'customfield_10666', 'name' => 'Priority', 'custom' => true, 'orderable' => true, 'navigable' => true, + 'searchable' => true, 'clauseNames' => ['cf[10666]', 'Priority'], 'schema' => { 'type' => 'string', 'custom' => 'com.atlassian.jira.plugin.system.customfieldtypes:select', 'customId' => 10_666 } }), JIRA::Resource::Field.new(client, -attrs: { 'id' => 'issuekey', 'name' => 'Key', 'custom' => false, 'orderable' => false, -'navigable' => true, 'searchable' => false, 'clauseNames' => %w[id issue issuekey key] }), + attrs: { 'id' => 'issuekey', 'name' => 'Key', 'custom' => false, 'orderable' => false, + 'navigable' => true, 'searchable' => false, 'clauseNames' => %w[id issue issuekey key] }), JIRA::Resource::Field.new(client, -attrs: { 'id' => 'priority', 'name' => 'Priority', 'custom' => false, 'orderable' => true, -'navigable' => true, 'searchable' => true, 'clauseNames' => ['priority'], 'schema' => { 'type' => 'priority', 'system' => 'priority' } }), + attrs: { 'id' => 'priority', 'name' => 'Priority', 'custom' => false, 'orderable' => true, + 'navigable' => true, 'searchable' => true, 'clauseNames' => ['priority'], 'schema' => { 'type' => 'priority', 'system' => 'priority' } }), JIRA::Resource::Field.new(client, -attrs: { 'id' => 'summary', 'name' => 'Summary', 'custom' => false, 'orderable' => true, -'navigable' => true, 'searchable' => true, 'clauseNames' => ['summary'], 'schema' => { 'type' => 'string', 'system' => 'summary' } }), + attrs: { 'id' => 'summary', 'name' => 'Summary', 'custom' => false, 'orderable' => true, + 'navigable' => true, 'searchable' => true, 'clauseNames' => ['summary'], 'schema' => { 'type' => 'string', 'system' => 'summary' } }), JIRA::Resource::Field.new(client, -attrs: { 'id' => 'issuetype', 'name' => 'Issue Type', 'custom' => false, 'orderable' => true, -'navigable' => true, 'searchable' => true, 'clauseNames' => %w[issuetype type], 'schema' => { 'type' => 'issuetype', 'system' => 'issuetype' } }), + attrs: { 'id' => 'issuetype', 'name' => 'Issue Type', 'custom' => false, 'orderable' => true, + 'navigable' => true, 'searchable' => true, 'clauseNames' => %w[issuetype type], 'schema' => { 'type' => 'issuetype', 'system' => 'issuetype' } }), JIRA::Resource::Field.new(client, -attrs: { 'id' => 'customfield_10111', 'name' => 'SingleWord', 'custom' => true, 'orderable' => true, -'navigable' => true, 'searchable' => true, 'clauseNames' => ['cf[10111]', 'SingleWord'], 'schema' => { 'type' => 'string', 'custom' => 'com.atlassian.jira.plugin.system.customfieldtypes:select', 'customId' => 10_111 } }), + attrs: { 'id' => 'customfield_10111', 'name' => 'SingleWord', 'custom' => true, 'orderable' => true, + 'navigable' => true, 'searchable' => true, 'clauseNames' => ['cf[10111]', 'SingleWord'], 'schema' => { 'type' => 'string', 'custom' => 'com.atlassian.jira.plugin.system.customfieldtypes:select', 'customId' => 10_111 } }), JIRA::Resource::Field.new(client, -attrs: { 'id' => 'customfield_10222', 'name' => 'Multi Word', 'custom' => true, 'orderable' => true, -'navigable' => true, 'searchable' => true, 'clauseNames' => ['cf[10222]', 'Multi Word'], 'schema' => { 'type' => 'string', 'custom' => 'com.atlassian.jira.plugin.system.customfieldtypes:select', 'customId' => 10_222 } }), + attrs: { 'id' => 'customfield_10222', 'name' => 'Multi Word', 'custom' => true, 'orderable' => true, + 'navigable' => true, 'searchable' => true, 'clauseNames' => ['cf[10222]', 'Multi Word'], 'schema' => { 'type' => 'string', 'custom' => 'com.atlassian.jira.plugin.system.customfieldtypes:select', 'customId' => 10_222 } }), JIRA::Resource::Field.new(client, -attrs: { 'id' => 'customfield_10333', 'name' => 'Why/N@t', 'custom' => true, 'orderable' => true, -'navigable' => true, 'searchable' => true, 'clauseNames' => ['cf[10333]', 'Why/N@t'], 'schema' => { 'type' => 'string', 'custom' => 'com.atlassian.jira.plugin.system.customfieldtypes:select', 'customId' => 10_333 } }), + attrs: { 'id' => 'customfield_10333', 'name' => 'Why/N@t', 'custom' => true, 'orderable' => true, + 'navigable' => true, 'searchable' => true, 'clauseNames' => ['cf[10333]', 'Why/N@t'], 'schema' => { 'type' => 'string', 'custom' => 'com.atlassian.jira.plugin.system.customfieldtypes:select', 'customId' => 10_333 } }), JIRA::Resource::Field.new(client, -attrs: { 'id' => 'customfield_10444', 'name' => 'SingleWord', 'custom' => true, 'orderable' => true, -'navigable' => true, 'searchable' => true, 'clauseNames' => ['cf[10444]', 'SingleWord'], 'schema' => { 'type' => 'string', 'custom' => 'com.atlassian.jira.plugin.system.customfieldtypes:select', 'customId' => 10_444 } }) + attrs: { 'id' => 'customfield_10444', 'name' => 'SingleWord', 'custom' => true, 'orderable' => true, + 'navigable' => true, 'searchable' => true, 'clauseNames' => ['cf[10444]', 'SingleWord'], 'schema' => { 'type' => 'string', 'custom' => 'com.atlassian.jira.plugin.system.customfieldtypes:select', 'customId' => 10_444 } }) ]) client end From ea655e5815620205d8cd595086f4430aee25a213 Mon Sep 17 00:00:00 2001 From: Robert Brodie Date: Sun, 28 Apr 2024 19:26:30 -0400 Subject: [PATCH 20/59] Fixed Style/HashSyntax --- lib/jira/base.rb | 4 ++-- lib/jira/resource/applinks.rb | 2 +- lib/jira/resource/webhook.rb | 2 +- spec/integration/watcher_spec.rb | 4 ++-- spec/jira/base_spec.rb | 6 +++--- spec/jira/has_many_proxy_spec.rb | 4 ++-- spec/jira/http_client_spec.rb | 2 +- spec/jira/resource/project_spec.rb | 6 +++--- spec/support/shared_examples/integration.rb | 12 ++++++------ 9 files changed, 21 insertions(+), 21 deletions(-) diff --git a/lib/jira/base.rb b/lib/jira/base.rb index d4f584f8..a35c4cfe 100644 --- a/lib/jira/base.rb +++ b/lib/jira/base.rb @@ -98,7 +98,7 @@ def self.all(client, options = {}) json = parse_json(response.body) json = json[endpoint_name.pluralize] if collection_attributes_are_nested json.map do |attrs| - new(client, { attrs: attrs }.merge(options)) + new(client, { attrs: }.merge(options)) end end @@ -113,7 +113,7 @@ def self.find(client, key, options = {}) # Builds a new instance of the resource with the given attributes. # These attributes will be posted to the JIRA Api if save is called. def self.build(client, attrs) - new(client, attrs: attrs) + new(client, attrs:) end # Returns the name of this resource for use in URL components. diff --git a/lib/jira/resource/applinks.rb b/lib/jira/resource/applinks.rb index 8938df4b..80330341 100644 --- a/lib/jira/resource/applinks.rb +++ b/lib/jira/resource/applinks.rb @@ -26,7 +26,7 @@ def self.all(client, options = {}) json = parse_json(response.body) json = json['list'] json.map do |attrs| - new(client, { attrs: attrs }.merge(options)) + new(client, { attrs: }.merge(options)) end end diff --git a/lib/jira/resource/webhook.rb b/lib/jira/resource/webhook.rb index 21628c9c..31b5f5ab 100644 --- a/lib/jira/resource/webhook.rb +++ b/lib/jira/resource/webhook.rb @@ -24,7 +24,7 @@ def self.all(client, options = {}) response = client.get(collection_path(client)) json = parse_json(response.body) json.map do |attrs| - new(client, { attrs: attrs }.merge(options)) + new(client, { attrs: }.merge(options)) end end diff --git a/spec/integration/watcher_spec.rb b/spec/integration/watcher_spec.rb index 04b7f06e..4e1b611b 100644 --- a/spec/integration/watcher_spec.rb +++ b/spec/integration/watcher_spec.rb @@ -46,13 +46,13 @@ it 'returnses all the watchers' do issue = client.Issue.find('10002') - watchers = client.Watcher.all(options = { issue: issue }) + watchers = client.Watcher.all(options = { issue: }) expect(watchers.length).to eq(1) end it 'adds a watcher' do issue = client.Issue.find('10002') - watcher = JIRA::Resource::Watcher.new(client, issue: issue) + watcher = JIRA::Resource::Watcher.new(client, issue:) user_id = 'tester' watcher.save!(user_id) end diff --git a/spec/jira/base_spec.rb b/spec/jira/base_spec.rb index 70b85268..c18315c2 100644 --- a/spec/jira/base_spec.rb +++ b/spec/jira/base_spec.rb @@ -35,7 +35,7 @@ class JIRA::Resource::HasManyExample < JIRA::Base # :nodoc: let(:client) { double('client') } let(:attrs) { {} } - subject { JIRA::Resource::Deadbeef.new(client, attrs: attrs) } + subject { JIRA::Resource::Deadbeef.new(client, attrs:) } let(:decorated) { JIRADelegation.new(subject) } @@ -148,7 +148,7 @@ class JIRA::Resource::HasManyExample < JIRA::Base # :nodoc: describe 'dynamic instance methods' do let(:attrs) { { 'foo' => 'bar', 'flum' => 'goo', 'object_id' => 'dummy' } } - subject { JIRA::Resource::Deadbeef.new(client, attrs: attrs) } + subject { JIRA::Resource::Deadbeef.new(client, attrs:) } it 'responds to each of the top level attribute names' do expect(subject).to respond_to(:foo) @@ -577,7 +577,7 @@ class JIRA::Resource::BelongsToExample < JIRA::Base let(:deadbeef) { JIRA::Resource::Deadbeef.new(client, attrs: { 'id' => '999' }) } - subject { JIRA::Resource::BelongsToExample.new(client, attrs: { 'id' => '123' }, deadbeef: deadbeef) } + subject { JIRA::Resource::BelongsToExample.new(client, attrs: { 'id' => '123' }, deadbeef:) } it 'sets up an accessor for the belongs to relationship' do expect(subject.deadbeef).to eq(deadbeef) diff --git a/spec/jira/has_many_proxy_spec.rb b/spec/jira/has_many_proxy_spec.rb index d3979aa9..c8c118f5 100644 --- a/spec/jira/has_many_proxy_spec.rb +++ b/spec/jira/has_many_proxy_spec.rb @@ -25,7 +25,7 @@ class Foo; end foo = double('foo') allow(parent).to receive(:client).and_return(client) allow(parent).to receive(:to_sym).and_return(:parent) - expect(Foo).to receive(:new).with(client, attrs: { 'foo' => 'bar' }, parent: parent).and_return(foo) + expect(Foo).to receive(:new).with(client, attrs: { 'foo' => 'bar' }, parent:).and_return(foo) expect(collection).to receive(:<<).with(foo) expect(subject.build('foo' => 'bar')).to eq(foo) end @@ -35,7 +35,7 @@ class Foo; end client = double('client') allow(parent).to receive(:client).and_return(client) allow(parent).to receive(:to_sym).and_return(:parent) - expect(Foo).to receive(:all).with(client, parent: parent).and_return(foo) + expect(Foo).to receive(:all).with(client, parent:).and_return(foo) expect(subject.all).to eq(foo) end diff --git a/spec/jira/http_client_spec.rb b/spec/jira/http_client_spec.rb index ee4cfdc2..f36d6234 100644 --- a/spec/jira/http_client_spec.rb +++ b/spec/jira/http_client_spec.rb @@ -375,7 +375,7 @@ let(:data) { {} } let(:headers) { { 'X-Atlassian-Token' => 'no-check' } } let(:basic_auth_http_conn) { double } - let(:request) { double('Http Request', path: path) } + let(:request) { double('Http Request', path:) } let(:response) { double('response') } before do diff --git a/spec/jira/resource/project_spec.rb b/spec/jira/resource/project_spec.rb index 24123a81..648fcf00 100644 --- a/spec/jira/resource/project_spec.rb +++ b/spec/jira/resource/project_spec.rb @@ -95,7 +95,7 @@ .with("/jira/rest/api/2/user/assignable/search?project=#{project_key}&startAt=#{start_at}") .and_return(response) - project.users(start_at: start_at) + project.users(start_at:) end it 'accepts max_results option' do @@ -105,7 +105,7 @@ .with("/jira/rest/api/2/user/assignable/search?project=#{project_key}&maxResults=#{max_results}") .and_return(response) - project.users(max_results: max_results) + project.users(max_results:) end it 'accepts start_at and max_results options' do @@ -116,7 +116,7 @@ .with("/jira/rest/api/2/user/assignable/search?project=#{project_key}&startAt=#{start_at}&maxResults=#{max_results}") .and_return(response) - project.users(start_at: start_at, max_results: max_results) + project.users(start_at:, max_results:) end end end diff --git a/spec/support/shared_examples/integration.rb b/spec/support/shared_examples/integration.rb index d9a48a0b..e2195087 100644 --- a/spec/support/shared_examples/integration.rb +++ b/spec/support/shared_examples/integration.rb @@ -91,7 +91,7 @@ def build_receiver # E.g., for JIRA::Resource::Project, we need to call # client.Project.find() stub_request(:get, site_url + described_class.singular_path(client, key, prefix)) - .to_return(status: 200, body: get_mock_from_path(:get, key: key)) + .to_return(status: 200, body: get_mock_from_path(:get, key:)) subject = client.send(class_basename).find(key, options) expect(subject).to have_attributes(expected_attributes) @@ -101,7 +101,7 @@ def build_receiver # E.g., for JIRA::Resource::Project, we need to call # client.Project.build('key' => 'ABC123') stub_request(:get, site_url + described_class.singular_path(client, key, prefix)) - .to_return(status: 200, body: get_mock_from_path(:get, key: key)) + .to_return(status: 200, body: get_mock_from_path(:get, key:)) subject = build_receiver.build(described_class.key_attribute.to_s => key) subject.fetch @@ -145,9 +145,9 @@ def build_receiver shared_examples 'a resource with a PUT endpoint' do it 'saves an existing component' do stub_request(:get, site_url + described_class.singular_path(client, key, prefix)) - .to_return(status: 200, body: get_mock_from_path(:get, key: key)) + .to_return(status: 200, body: get_mock_from_path(:get, key:)) stub_request(:put, site_url + described_class.singular_path(client, key, prefix)) - .to_return(status: 200, body: get_mock_from_path(:put, key: key, value_if_not_found: nil)) + .to_return(status: 200, body: get_mock_from_path(:put, key:, value_if_not_found: nil)) subject = build_receiver.build(described_class.key_attribute.to_s => key) subject.fetch expect(subject.save(attributes_for_put)).to be_truthy @@ -160,9 +160,9 @@ def build_receiver shared_examples 'a resource with a PUT endpoint that rejects invalid fields' do it 'fails to save with an invalid field' do stub_request(:get, site_url + described_class.singular_path(client, key)) - .to_return(status: 200, body: get_mock_from_path(:get, key: key)) + .to_return(status: 200, body: get_mock_from_path(:get, key:)) stub_request(:put, site_url + described_class.singular_path(client, key)) - .to_return(status: 400, body: get_mock_from_path(:put, key: key, suffix: 'invalid')) + .to_return(status: 400, body: get_mock_from_path(:put, key:, suffix: 'invalid')) subject = client.send(class_basename).build(described_class.key_attribute.to_s => key) subject.fetch From c639f38aee1dd301551c86d6b9b6e7248730a09e Mon Sep 17 00:00:00 2001 From: Robert Brodie Date: Sun, 28 Apr 2024 20:49:54 -0400 Subject: [PATCH 21/59] Fixed RSpec/DescribedClass --- spec/integration/attachment_spec.rb | 2 +- spec/integration/comment_spec.rb | 2 +- spec/integration/transition_spec.rb | 2 +- spec/integration/user_spec.rb | 2 +- spec/integration/watcher_spec.rb | 4 +- spec/integration/worklog_spec.rb | 2 +- spec/jira/client_spec.rb | 18 +++---- spec/jira/has_many_proxy_spec.rb | 2 +- spec/jira/http_client_spec.rb | 24 +++++----- spec/jira/oauth_client_spec.rb | 4 +- spec/jira/request_client_spec.rb | 2 +- spec/jira/resource/agile_spec.rb | 26 +++++----- spec/jira/resource/attachment_spec.rb | 10 ++-- spec/jira/resource/board_spec.rb | 6 +-- spec/jira/resource/createmeta_spec.rb | 48 +++++++++---------- spec/jira/resource/field_spec.rb | 20 ++++---- spec/jira/resource/filter_spec.rb | 4 +- .../resource/issue_picker_suggestions_spec.rb | 14 +++--- spec/jira/resource/issue_spec.rb | 30 ++++++------ .../jira_picker_suggestions_issue_spec.rb | 2 +- spec/jira/resource/project_factory_spec.rb | 4 +- spec/jira/resource/project_spec.rb | 6 +-- spec/jira/resource/sprint_spec.rb | 2 +- spec/jira/resource/status_spec.rb | 2 +- spec/jira/resource/user_factory_spec.rb | 2 +- spec/jira/resource/worklog_spec.rb | 2 +- 26 files changed, 121 insertions(+), 121 deletions(-) diff --git a/spec/integration/attachment_spec.rb b/spec/integration/attachment_spec.rb index 22dfb62a..0804318f 100644 --- a/spec/integration/attachment_spec.rb +++ b/spec/integration/attachment_spec.rb @@ -7,7 +7,7 @@ let(:key) { '10000' } - let(:target) { JIRA::Resource::Attachment.new(client, attrs: { 'id' => '99999' }, issue_id: '10002') } + let(:target) { described_class.new(client, attrs: { 'id' => '99999' }, issue_id: '10002') } let(:expected_attributes) do { diff --git a/spec/integration/comment_spec.rb b/spec/integration/comment_spec.rb index 2798b39e..b644efa3 100644 --- a/spec/integration/comment_spec.rb +++ b/spec/integration/comment_spec.rb @@ -7,7 +7,7 @@ let(:key) { '10000' } - let(:target) { JIRA::Resource::Comment.new(client, attrs: { 'id' => '99999' }, issue_id: '54321') } + let(:target) { described_class.new(client, attrs: { 'id' => '99999' }, issue_id: '54321') } let(:expected_collection_length) { 2 } diff --git a/spec/integration/transition_spec.rb b/spec/integration/transition_spec.rb index a3ff5e8f..d8a6518b 100644 --- a/spec/integration/transition_spec.rb +++ b/spec/integration/transition_spec.rb @@ -7,7 +7,7 @@ let(:key) { '10000' } - let(:target) { JIRA::Resource::Transition.new(client, attrs: { 'id' => '99999' }, issue_id: '10014') } + let(:target) { described_class.new(client, attrs: { 'id' => '99999' }, issue_id: '10014') } let(:belongs_to) do JIRA::Resource::Issue.new(client, attrs: { diff --git a/spec/integration/user_spec.rb b/spec/integration/user_spec.rb index d0b352d7..b9b1a3a2 100644 --- a/spec/integration/user_spec.rb +++ b/spec/integration/user_spec.rb @@ -34,7 +34,7 @@ it 'gets users with maxResults of 1000' do expect(client).to receive(:get).with('/rest/api/2/users/search?username=_&maxResults=1000') expect(client).to receive_message_chain(:User, :build).with('User1') - JIRA::Resource::User.all(client) + described_class.all(client) end end end diff --git a/spec/integration/watcher_spec.rb b/spec/integration/watcher_spec.rb index 4e1b611b..d7677054 100644 --- a/spec/integration/watcher_spec.rb +++ b/spec/integration/watcher_spec.rb @@ -5,7 +5,7 @@ let(:client) { client } let(:site_url) { site_url } - let(:target) { JIRA::Resource::Watcher.new(client, attrs: { 'id' => '99999' }, issue_id: '10002') } + let(:target) { described_class.new(client, attrs: { 'id' => '99999' }, issue_id: '10002') } let(:belongs_to) do JIRA::Resource::Issue.new(client, attrs: { @@ -52,7 +52,7 @@ it 'adds a watcher' do issue = client.Issue.find('10002') - watcher = JIRA::Resource::Watcher.new(client, issue:) + watcher = described_class.new(client, issue:) user_id = 'tester' watcher.save!(user_id) end diff --git a/spec/integration/worklog_spec.rb b/spec/integration/worklog_spec.rb index 2db5fd4d..46c896a4 100644 --- a/spec/integration/worklog_spec.rb +++ b/spec/integration/worklog_spec.rb @@ -7,7 +7,7 @@ let(:key) { '10000' } - let(:target) { JIRA::Resource::Worklog.new(client, attrs: { 'id' => '99999' }, issue_id: '54321') } + let(:target) { described_class.new(client, attrs: { 'id' => '99999' }, issue_id: '54321') } let(:expected_collection_length) { 3 } diff --git a/spec/jira/client_spec.rb b/spec/jira/client_spec.rb index 978212fb..75d7cd66 100644 --- a/spec/jira/client_spec.rb +++ b/spec/jira/client_spec.rb @@ -138,14 +138,14 @@ context 'behaviour that applies to all client classes irrespective of authentication method' do it 'allows the overriding of some options' do - client = JIRA::Client.new(consumer_key: 'foo', consumer_secret: 'bar', site: 'http://foo.com/') + client = described_class.new(consumer_key: 'foo', consumer_secret: 'bar', site: 'http://foo.com/') expect(client.options[:site]).to eq('http://foo.com/') expect(JIRA::Client::DEFAULT_OPTIONS[:site]).not_to eq('http://foo.com/') end end context 'with basic http authentication' do - subject { JIRA::Client.new(username: 'foo', password: 'bar', auth_type: :basic) } + subject { described_class.new(username: 'foo', password: 'bar', auth_type: :basic) } before(:each) do stub_request(:get, 'https://localhost:2990/jira/rest/api/2/project') @@ -174,14 +174,14 @@ end it 'fails with wrong user name and password' do - bad_login = JIRA::Client.new(username: 'foo', password: 'badpassword', auth_type: :basic) + bad_login = described_class.new(username: 'foo', password: 'badpassword', auth_type: :basic) expect(bad_login.authenticated?).to be_falsey expect { bad_login.Project.all }.to raise_error JIRA::HTTPError end end context 'with cookie authentication' do - subject { JIRA::Client.new(username: 'foo', password: 'bar', auth_type: :cookie) } + subject { described_class.new(username: 'foo', password: 'bar', auth_type: :cookie) } let(:session_cookie) { '6E3487971234567896704A9EB4AE501F' } let(:session_body) do @@ -220,7 +220,7 @@ end it 'does not authenticate with an incorrect username and password' do - bad_client = JIRA::Client.new(username: 'foo', password: 'bad_password', auth_type: :cookie) + bad_client = described_class.new(username: 'foo', password: 'bad_password', auth_type: :cookie) expect(bad_client).not_to be_authenticated end @@ -232,7 +232,7 @@ context 'with jwt authentication' do subject do - JIRA::Client.new( + described_class.new( issuer: 'foo', base_url: 'https://host.tld', shared_secret: 'shared_secret_key', @@ -279,20 +279,20 @@ end context 'oauth authentication' do - subject { JIRA::Client.new(consumer_key: 'foo', consumer_secret: 'bar') } + subject { described_class.new(consumer_key: 'foo', consumer_secret: 'bar') } include_examples 'OAuth Common Tests' end context 'with oauth_2legged' do - subject { JIRA::Client.new(consumer_key: 'foo', consumer_secret: 'bar', auth_type: :oauth_2legged) } + subject { described_class.new(consumer_key: 'foo', consumer_secret: 'bar', auth_type: :oauth_2legged) } include_examples 'OAuth Common Tests' end context 'with unknown options' do let(:options) { { 'username' => 'foo', 'password' => 'bar', auth_type: :basic } } - subject { JIRA::Client.new(options) } + subject { described_class.new(options) } it 'raises an ArgumentError' do expect { subject }.to raise_exception(ArgumentError, 'Unknown option(s) given: ["username", "password"]') diff --git a/spec/jira/has_many_proxy_spec.rb b/spec/jira/has_many_proxy_spec.rb index c8c118f5..ac2ea2da 100644 --- a/spec/jira/has_many_proxy_spec.rb +++ b/spec/jira/has_many_proxy_spec.rb @@ -3,7 +3,7 @@ describe JIRA::HasManyProxy do class Foo; end - subject { JIRA::HasManyProxy.new(parent, Foo, collection) } + subject { described_class.new(parent, Foo, collection) } let(:parent) { double('parent') } let(:collection) { double('collection') } diff --git a/spec/jira/http_client_spec.rb b/spec/jira/http_client_spec.rb index f36d6234..c97094d0 100644 --- a/spec/jira/http_client_spec.rb +++ b/spec/jira/http_client_spec.rb @@ -5,7 +5,7 @@ options = JIRA::Client::DEFAULT_OPTIONS .merge(JIRA::HttpClient::DEFAULT_OPTIONS) .merge(basic_auth_credentials) - JIRA::HttpClient.new(options) + described_class.new(options) end let(:basic_cookie_client) do @@ -13,12 +13,12 @@ .merge(JIRA::HttpClient::DEFAULT_OPTIONS) .merge(use_cookies: true) .merge(basic_auth_credentials) - JIRA::HttpClient.new(options) + described_class.new(options) end let(:custom_ssl_version_client) do options = JIRA::Client::DEFAULT_OPTIONS.merge(JIRA::HttpClient::DEFAULT_OPTIONS).merge(ssl_version: :TLSv1_2) - JIRA::HttpClient.new(options) + described_class.new(options) end let(:basic_cookie_client_with_context_path) do @@ -26,7 +26,7 @@ use_cookies: true, context_path: '/context' ) - JIRA::HttpClient.new(options) + described_class.new(options) end let(:basic_cookie_client_with_additional_cookies) do @@ -37,7 +37,7 @@ additional_cookies: ['sessionToken=abc123', 'internal=true'] ) .merge(basic_auth_credentials) - JIRA::HttpClient.new(options) + described_class.new(options) end let(:basic_client_cert_client) do @@ -46,13 +46,13 @@ cert: 'public certificate contents', key: 'private key contents' ) - JIRA::HttpClient.new(options) + described_class.new(options) end let(:basic_client_with_no_auth_credentials) do options = JIRA::Client::DEFAULT_OPTIONS .merge(JIRA::HttpClient::DEFAULT_OPTIONS) - JIRA::HttpClient.new(options) + described_class.new(options) end let(:basic_auth_credentials) do @@ -66,14 +66,14 @@ proxy_username: 'proxyUsername', proxy_password: 'proxyPassword' ) - JIRA::HttpClient.new(options) + described_class.new(options) end let(:basic_client_with_max_retries) do options = JIRA::Client::DEFAULT_OPTIONS.merge(JIRA::HttpClient::DEFAULT_OPTIONS).merge( max_retries: 2 ) - JIRA::HttpClient.new(options) + described_class.new(options) end let(:response) do @@ -96,7 +96,7 @@ proxy_username: 'proxyUsername', proxy_password: 'proxyPassword' ) - JIRA::HttpClient.new(options_local) + described_class.new(options_local) end describe 'HttpClient#basic_auth_http_conn' do @@ -305,7 +305,7 @@ proxy_username: 'proxyUsername', proxy_password: 'proxyPassword' ) - JIRA::HttpClient.new(options_local) + described_class.new(options_local) end subject(:proxy_conn) { proxy_client.basic_auth_http_conn } @@ -339,7 +339,7 @@ end it 'can use a certificate authority file' do - client = JIRA::HttpClient.new(JIRA::Client::DEFAULT_OPTIONS.merge(ca_file: '/opt/custom.ca.pem')) + client = described_class.new(JIRA::Client::DEFAULT_OPTIONS.merge(ca_file: '/opt/custom.ca.pem')) expect(client.http_conn(client.uri).ca_file).to eql('/opt/custom.ca.pem') end diff --git a/spec/jira/oauth_client_spec.rb b/spec/jira/oauth_client_spec.rb index 4f7de9f9..d0d4ae6b 100644 --- a/spec/jira/oauth_client_spec.rb +++ b/spec/jira/oauth_client_spec.rb @@ -4,7 +4,7 @@ let(:oauth_client) do options = { consumer_key: 'foo', consumer_secret: 'bar' } options = JIRA::Client::DEFAULT_OPTIONS.merge(options) - JIRA::OauthClient.new(options) + described_class.new(options) end let(:response) do @@ -148,7 +148,7 @@ let(:oauth__2legged_client) do options = { consumer_key: 'foo', consumer_secret: 'bar', auth_type: :oauth_2legged } options = JIRA::Client::DEFAULT_OPTIONS.merge(options) - JIRA::OauthClient.new(options) + described_class.new(options) end it 'responds to the http methods adding oauth_token parameter' do diff --git a/spec/jira/request_client_spec.rb b/spec/jira/request_client_spec.rb index 1de1fcee..e4351c7b 100644 --- a/spec/jira/request_client_spec.rb +++ b/spec/jira/request_client_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' describe JIRA::RequestClient do - let(:request_client) { JIRA::RequestClient.new } + let(:request_client) { described_class.new } describe '#request' do subject(:request) { request_client.request(:get, '/foo', '', {}) } diff --git a/spec/jira/resource/agile_spec.rb b/spec/jira/resource/agile_spec.rb index dcf7b665..14f2da4d 100644 --- a/spec/jira/resource/agile_spec.rb +++ b/spec/jira/resource/agile_spec.rb @@ -13,7 +13,7 @@ expect(client).to receive(:get).with('/jira/rest/agile/1.0/board').and_return(response) expect(response).to receive(:body).and_return(get_mock_response('board/1.json')) - JIRA::Resource::Agile.all(client) + described_class.all(client) end end @@ -22,7 +22,7 @@ expect(client).to receive(:get).with('/jira/rest/agile/1.0/board/1/backlog?maxResults=100').and_return(response) expect(response).to receive(:body).and_return(get_mock_response('board/1.json')) - JIRA::Resource::Agile.get_backlog_issues(client, 1) + described_class.get_backlog_issues(client, 1) end end @@ -34,7 +34,7 @@ expect(client).to receive(:get).with('/jira/rest/api/2/search?jql=id+IN%2810546%2C+10547%2C+10556%2C+10557%2C+10558%2C+10559%2C+10600%2C+10601%2C+10604%29').and_return(response) expect(response).to receive(:body).and_return(get_mock_response('board/1_issues.json')) - issues = JIRA::Resource::Agile.get_board_issues(client, 1) + issues = described_class.get_board_issues(client, 1) expect(issues).to be_an(Array) expect(issues.size).to eql(9) @@ -51,7 +51,7 @@ expect(client).to receive(:get).with('/jira/rest/api/2/search?jql=id+IN%2810546%2C+10547%2C+10556%2C+10557%2C+10558%2C+10559%2C+10600%2C+10601%2C+10604%29').and_return(response) expect(response).to receive(:body).and_return(get_mock_response('board/1_issues.json')) - issues = JIRA::Resource::Agile.get_board_issues(client, 1, startAt: 50) + issues = described_class.get_board_issues(client, 1, startAt: 50) expect(issues).to be_an(Array) expect(issues.size).to eql(9) @@ -67,28 +67,28 @@ expect(client).to receive(:get).with('/jira/rest/agile/1.0/board/1/sprint?maxResults=100').and_return(response) expect(response).to receive(:body).and_return(get_mock_response('board/1.json')) - JIRA::Resource::Agile.get_sprints(client, 1) + described_class.get_sprints(client, 1) end it 'queries correct url with parameters' do expect(client).to receive(:get).with('/jira/rest/agile/1.0/board/1/sprint?startAt=50&maxResults=100').and_return(response) expect(response).to receive(:body).and_return(get_mock_response('board/1.json')) - JIRA::Resource::Agile.get_sprints(client, 1, startAt: 50) + described_class.get_sprints(client, 1, startAt: 50) end it 'works with pagination starting at 0' do expect(client).to receive(:get).with('/jira/rest/agile/1.0/board/1/sprint?maxResults=1&startAt=0').and_return(response) expect(response).to receive(:body).and_return(get_mock_response('board/1.json')) - JIRA::Resource::Agile.get_sprints(client, 1, maxResults: 1, startAt: 0) + described_class.get_sprints(client, 1, maxResults: 1, startAt: 0) end it 'works with pagination not starting at 0' do expect(client).to receive(:get).with('/jira/rest/agile/1.0/board/1/sprint?maxResults=1&startAt=1').and_return(response) expect(response).to receive(:body).and_return(get_mock_response('board/1.json')) - JIRA::Resource::Agile.get_sprints(client, 1, maxResults: 1, startAt: 1) + described_class.get_sprints(client, 1, maxResults: 1, startAt: 1) end end @@ -97,14 +97,14 @@ expect(client).to receive(:get).with('/jira/rest/agile/1.0/sprint/1/issue?maxResults=100').and_return(response) expect(response).to receive(:body).and_return(get_mock_response('sprint/1_issues.json')) - JIRA::Resource::Agile.get_sprint_issues(client, 1) + described_class.get_sprint_issues(client, 1) end it 'queries correct url with parameters' do expect(client).to receive(:get).with('/jira/rest/agile/1.0/sprint/1/issue?startAt=50&maxResults=100').and_return(response) expect(response).to receive(:body).and_return(get_mock_response('sprint/1_issues.json')) - JIRA::Resource::Agile.get_sprint_issues(client, 1, startAt: 50) + described_class.get_sprint_issues(client, 1, startAt: 50) end end @@ -113,7 +113,7 @@ expect(client).to receive(:get).with('/jira/rest/agile/1.0/board/1/project/full').and_return(response) expect(response).to receive(:body).and_return(get_mock_response('board/1.json')) - JIRA::Resource::Agile.get_projects_full(client, 1) + described_class.get_projects_full(client, 1) end end @@ -122,14 +122,14 @@ expect(client).to receive(:get).with('/jira/rest/agile/1.0/board/1/project?maxResults=100').and_return(response) expect(response).to receive(:body).and_return(get_mock_response('board/1.json')) - JIRA::Resource::Agile.get_projects(client, 1) + described_class.get_projects(client, 1) end it 'queries correct url with parameters' do expect(client).to receive(:get).with('/jira/rest/agile/1.0/board/1/project?startAt=50&maxResults=100').and_return(response) expect(response).to receive(:body).and_return(get_mock_response('board/1.json')) - JIRA::Resource::Agile.get_projects(client, 1, startAt: 50) + described_class.get_projects(client, 1, startAt: 50) end end end diff --git a/spec/jira/resource/attachment_spec.rb b/spec/jira/resource/attachment_spec.rb index fd231b99..f669d5db 100644 --- a/spec/jira/resource/attachment_spec.rb +++ b/spec/jira/resource/attachment_spec.rb @@ -2,7 +2,7 @@ describe JIRA::Resource::Attachment do subject(:attachment) do - JIRA::Resource::Attachment.new( + described_class.new( client, issue: JIRA::Resource::Issue.new(client), attrs: { 'author' => { 'foo' => 'bar' } } @@ -35,7 +35,7 @@ end describe '.meta' do - subject { JIRA::Resource::Attachment.meta(client) } + subject { described_class.meta(client) } let(:response) do double( @@ -67,7 +67,7 @@ let(:file_target) { double(read: :attachment_file_contents) } let(:attachment_url) { 'https:jirahost/secure/attachment/32323/myfile.txt' } subject(:attachment) do - JIRA::Resource::Attachment.new( + described_class.new( client, issue: JIRA::Resource::Issue.new(client), attrs: { 'author' => { 'foo' => 'bar' }, 'content' => attachment_url } @@ -133,7 +133,7 @@ end context 'when using custom client headers' do subject(:bearer_attachment) do - JIRA::Resource::Attachment.new( + described_class.new( bearer_client, issue: JIRA::Resource::Issue.new(bearer_client), attrs: { 'author' => { 'foo' => 'bar' } } @@ -189,7 +189,7 @@ context 'when using custom client headers' do subject(:bearer_attachment) do - JIRA::Resource::Attachment.new( + described_class.new( bearer_client, issue: JIRA::Resource::Issue.new(bearer_client), attrs: { 'author' => { 'foo' => 'bar' } } diff --git a/spec/jira/resource/board_spec.rb b/spec/jira/resource/board_spec.rb index 2b14ab08..5645f894 100644 --- a/spec/jira/resource/board_spec.rb +++ b/spec/jira/resource/board_spec.rb @@ -25,7 +25,7 @@ class JIRAResourceDelegation < SimpleDelegator # :nodoc: .and_return(response) expect(client).to receive(:Board).and_return(JIRA::Resource::BoardFactory.new(client)) - JIRA::Resource::Board.find(client, '84') + described_class.find(client, '84') end it 'finds all boards' do @@ -53,12 +53,12 @@ class JIRAResourceDelegation < SimpleDelegator # :nodoc: expect(client).to receive(:get).with('/rest/agile/1.0/board') .and_return(response) expect(client).to receive(:Board).twice.and_return(JIRA::Resource::BoardFactory.new(client)) - boards = JIRA::Resource::Board.all(client) + boards = described_class.all(client) expect(boards.count).to eq(2) end it 'finds one board by id' do - expect(board).to be_a(JIRA::Resource::Board) + expect(board).to be_a(described_class) end describe '#issues' do diff --git a/spec/jira/resource/createmeta_spec.rb b/spec/jira/resource/createmeta_spec.rb index d3c120a4..ac43b332 100644 --- a/spec/jira/resource/createmeta_spec.rb +++ b/spec/jira/resource/createmeta_spec.rb @@ -20,22 +20,22 @@ describe 'general' do it 'queries correct url without parameters' do expect(client).to receive(:get).with('/jira/rest/api/2/issue/createmeta').and_return(response) - JIRA::Resource::Createmeta.all(client) + described_class.all(client) end it 'queries correct url with `expand` parameter' do expect(client).to receive(:get).with('/jira/rest/api/2/issue/createmeta?expand=projects.issuetypes.fields').and_return(response) - JIRA::Resource::Createmeta.all(client, expand: 'projects.issuetypes.fields') + described_class.all(client, expand: 'projects.issuetypes.fields') end it 'queries correct url with `foo` parameter' do expect(client).to receive(:get).with('/jira/rest/api/2/issue/createmeta?foo=bar').and_return(response) - JIRA::Resource::Createmeta.all(client, foo: 'bar') + described_class.all(client, foo: 'bar') end it 'returns an array of createmeta objects' do expect(client).to receive(:get).with('/jira/rest/api/2/issue/createmeta').and_return(response) - createmetas = JIRA::Resource::Createmeta.all(client) + createmetas = described_class.all(client) expect(createmetas).to be_an Array createmeta = createmetas.first expect(createmeta.id).to eq '10200' @@ -47,7 +47,7 @@ describe 'projectKeys' do it 'queries correct url when only one `projectKeys` given as string' do expect(client).to receive(:get).with('/jira/rest/api/2/issue/createmeta?projectKeys=PROJECT_1').and_return(response) - JIRA::Resource::Createmeta.all( + described_class.all( client, projectKeys: 'PROJECT_1' ) @@ -55,7 +55,7 @@ it 'queries correct url when multiple `projectKeys` given as string' do expect(client).to receive(:get).with('/jira/rest/api/2/issue/createmeta?projectKeys=PROJECT_1%2CPROJECT_2').and_return(response) - JIRA::Resource::Createmeta.all( + described_class.all( client, projectKeys: %w[PROJECT_1 PROJECT_2] ) @@ -66,7 +66,7 @@ allow(prj).to receive(:key).and_return('PRJ') expect(client).to receive(:get).with('/jira/rest/api/2/issue/createmeta?projectKeys=PRJ').and_return(response) - JIRA::Resource::Createmeta.all( + described_class.all( client, projectKeys: prj ) @@ -79,7 +79,7 @@ allow(prj_2).to receive(:key).and_return('PRJ_2') expect(client).to receive(:get).with('/jira/rest/api/2/issue/createmeta?projectKeys=PRJ_2%2CPRJ_1').and_return(response) - JIRA::Resource::Createmeta.all( + described_class.all( client, projectKeys: [prj_2, prj_1] ) @@ -90,7 +90,7 @@ allow(prj_5).to receive(:key).and_return('PRJ_5') expect(client).to receive(:get).with('/jira/rest/api/2/issue/createmeta?projectKeys=PROJECT_1%2CPRJ_5').and_return(response) - JIRA::Resource::Createmeta.all( + described_class.all( client, projectKeys: ['PROJECT_1', prj_5] ) @@ -100,7 +100,7 @@ describe 'projectIds' do it 'queries correct url when only one `projectIds` given as string' do expect(client).to receive(:get).with('/jira/rest/api/2/issue/createmeta?projectIds=10101').and_return(response) - JIRA::Resource::Createmeta.all( + described_class.all( client, projectIds: '10101' ) @@ -108,7 +108,7 @@ it 'queries correct url when multiple `projectIds` given as string' do expect(client).to receive(:get).with('/jira/rest/api/2/issue/createmeta?projectIds=10101%2C20202').and_return(response) - JIRA::Resource::Createmeta.all( + described_class.all( client, projectIds: %w[10101 20202] ) @@ -119,7 +119,7 @@ allow(prj).to receive(:id).and_return('30303') expect(client).to receive(:get).with('/jira/rest/api/2/issue/createmeta?projectIds=30303').and_return(response) - JIRA::Resource::Createmeta.all( + described_class.all( client, projectIds: prj ) @@ -132,7 +132,7 @@ allow(prj_2).to receive(:id).and_return('50505') expect(client).to receive(:get).with('/jira/rest/api/2/issue/createmeta?projectIds=50505%2C30303').and_return(response) - JIRA::Resource::Createmeta.all( + described_class.all( client, projectIds: [prj_2, prj_1] ) @@ -143,7 +143,7 @@ allow(prj_5).to receive(:id).and_return('60606') expect(client).to receive(:get).with('/jira/rest/api/2/issue/createmeta?projectIds=10101%2C60606').and_return(response) - JIRA::Resource::Createmeta.all( + described_class.all( client, projectIds: ['10101', prj_5] ) @@ -153,7 +153,7 @@ describe 'issuetypeNames' do it 'queries correct url when only one `issuetypeNames` given as string' do expect(client).to receive(:get).with('/jira/rest/api/2/issue/createmeta?issuetypeNames=Feature').and_return(response) - JIRA::Resource::Createmeta.all( + described_class.all( client, issuetypeNames: 'Feature' ) @@ -161,7 +161,7 @@ it 'queries correct url when multiple `issuetypeNames` given as string' do expect(client).to receive(:get).with('/jira/rest/api/2/issue/createmeta?issuetypeNames=Feature%2CBug').and_return(response) - JIRA::Resource::Createmeta.all( + described_class.all( client, issuetypeNames: %w[Feature Bug] ) @@ -172,7 +172,7 @@ allow(issue_type).to receive(:name).and_return('Epic') expect(client).to receive(:get).with('/jira/rest/api/2/issue/createmeta?issuetypeNames=Epic').and_return(response) - JIRA::Resource::Createmeta.all( + described_class.all( client, issuetypeNames: issue_type ) @@ -185,7 +185,7 @@ allow(issue_type_2).to receive(:name).and_return('Sub-Task') expect(client).to receive(:get).with('/jira/rest/api/2/issue/createmeta?issuetypeNames=Sub-Task%2CEpic').and_return(response) - JIRA::Resource::Createmeta.all( + described_class.all( client, issuetypeNames: [issue_type_2, issue_type_1] ) @@ -196,7 +196,7 @@ allow(issue_type).to receive(:name).and_return('Epic') expect(client).to receive(:get).with('/jira/rest/api/2/issue/createmeta?issuetypeNames=Feature%2CEpic').and_return(response) - JIRA::Resource::Createmeta.all( + described_class.all( client, issuetypeNames: ['Feature', issue_type] ) @@ -206,7 +206,7 @@ describe 'issuetypeIds' do it 'queries correct url when only one `issuetypeIds` given as string' do expect(client).to receive(:get).with('/jira/rest/api/2/issue/createmeta?issuetypeIds=10101').and_return(response) - JIRA::Resource::Createmeta.all( + described_class.all( client, issuetypeIds: '10101' ) @@ -214,7 +214,7 @@ it 'queries correct url when multiple `issuetypeIds` given as string' do expect(client).to receive(:get).with('/jira/rest/api/2/issue/createmeta?issuetypeIds=10101%2C20202').and_return(response) - JIRA::Resource::Createmeta.all( + described_class.all( client, issuetypeIds: %w[10101 20202] ) @@ -225,7 +225,7 @@ allow(issue_type).to receive(:id).and_return('30303') expect(client).to receive(:get).with('/jira/rest/api/2/issue/createmeta?issuetypeIds=30303').and_return(response) - JIRA::Resource::Createmeta.all( + described_class.all( client, issuetypeIds: issue_type ) @@ -238,7 +238,7 @@ allow(issue_type_2).to receive(:id).and_return('50505') expect(client).to receive(:get).with('/jira/rest/api/2/issue/createmeta?issuetypeIds=50505%2C30303').and_return(response) - JIRA::Resource::Createmeta.all( + described_class.all( client, issuetypeIds: [issue_type_2, issue_type_1] ) @@ -249,7 +249,7 @@ allow(issue_type).to receive(:id).and_return('30303') expect(client).to receive(:get).with('/jira/rest/api/2/issue/createmeta?issuetypeIds=10101%2C30303').and_return(response) - JIRA::Resource::Createmeta.all( + described_class.all( client, issuetypeIds: ['10101', issue_type] ) diff --git a/spec/jira/resource/field_spec.rb b/spec/jira/resource/field_spec.rb index f1ee5b18..5d89d5d8 100644 --- a/spec/jira/resource/field_spec.rb +++ b/spec/jira/resource/field_spec.rb @@ -10,31 +10,31 @@ allow(client).to receive(:cache).and_return(cache) # info about all fields on the client allow(client.Field).to receive(:all).and_return([ - JIRA::Resource::Field.new(client, + described_class.new(client, attrs: { 'id' => 'customfield_10666', 'name' => 'Priority', 'custom' => true, 'orderable' => true, 'navigable' => true, 'searchable' => true, 'clauseNames' => ['cf[10666]', 'Priority'], 'schema' => { 'type' => 'string', 'custom' => 'com.atlassian.jira.plugin.system.customfieldtypes:select', 'customId' => 10_666 } }), - JIRA::Resource::Field.new(client, + described_class.new(client, attrs: { 'id' => 'issuekey', 'name' => 'Key', 'custom' => false, 'orderable' => false, 'navigable' => true, 'searchable' => false, 'clauseNames' => %w[id issue issuekey key] }), - JIRA::Resource::Field.new(client, + described_class.new(client, attrs: { 'id' => 'priority', 'name' => 'Priority', 'custom' => false, 'orderable' => true, 'navigable' => true, 'searchable' => true, 'clauseNames' => ['priority'], 'schema' => { 'type' => 'priority', 'system' => 'priority' } }), - JIRA::Resource::Field.new(client, + described_class.new(client, attrs: { 'id' => 'summary', 'name' => 'Summary', 'custom' => false, 'orderable' => true, 'navigable' => true, 'searchable' => true, 'clauseNames' => ['summary'], 'schema' => { 'type' => 'string', 'system' => 'summary' } }), - JIRA::Resource::Field.new(client, + described_class.new(client, attrs: { 'id' => 'issuetype', 'name' => 'Issue Type', 'custom' => false, 'orderable' => true, 'navigable' => true, 'searchable' => true, 'clauseNames' => %w[issuetype type], 'schema' => { 'type' => 'issuetype', 'system' => 'issuetype' } }), - JIRA::Resource::Field.new(client, + described_class.new(client, attrs: { 'id' => 'customfield_10111', 'name' => 'SingleWord', 'custom' => true, 'orderable' => true, 'navigable' => true, 'searchable' => true, 'clauseNames' => ['cf[10111]', 'SingleWord'], 'schema' => { 'type' => 'string', 'custom' => 'com.atlassian.jira.plugin.system.customfieldtypes:select', 'customId' => 10_111 } }), - JIRA::Resource::Field.new(client, + described_class.new(client, attrs: { 'id' => 'customfield_10222', 'name' => 'Multi Word', 'custom' => true, 'orderable' => true, 'navigable' => true, 'searchable' => true, 'clauseNames' => ['cf[10222]', 'Multi Word'], 'schema' => { 'type' => 'string', 'custom' => 'com.atlassian.jira.plugin.system.customfieldtypes:select', 'customId' => 10_222 } }), - JIRA::Resource::Field.new(client, + described_class.new(client, attrs: { 'id' => 'customfield_10333', 'name' => 'Why/N@t', 'custom' => true, 'orderable' => true, 'navigable' => true, 'searchable' => true, 'clauseNames' => ['cf[10333]', 'Why/N@t'], 'schema' => { 'type' => 'string', 'custom' => 'com.atlassian.jira.plugin.system.customfieldtypes:select', 'customId' => 10_333 } }), - JIRA::Resource::Field.new(client, + described_class.new(client, attrs: { 'id' => 'customfield_10444', 'name' => 'SingleWord', 'custom' => true, 'orderable' => true, 'navigable' => true, 'searchable' => true, 'clauseNames' => ['cf[10444]', 'SingleWord'], 'schema' => { 'type' => 'string', 'custom' => 'com.atlassian.jira.plugin.system.customfieldtypes:select', 'customId' => 10_444 } }) ]) @@ -44,7 +44,7 @@ describe 'field_mappings' do shared_context 'mapped or not' do subject do - JIRA::Resource::Field.new(client, attrs: { + described_class.new(client, attrs: { 'priority' => 1, 'customfield_10111' => 'data_in_custom_field', 'customfield_10222' => 'multi word custom name', diff --git a/spec/jira/resource/filter_spec.rb b/spec/jira/resource/filter_spec.rb index 20ef909a..30908e89 100644 --- a/spec/jira/resource/filter_spec.rb +++ b/spec/jira/resource/filter_spec.rb @@ -49,8 +49,8 @@ end let(:filter) do expect(client).to receive(:get).with("#{collection_path}/42").and_return(filter_response) - allow(JIRA::Resource::Filter).to receive(:collection_path).and_return(collection_path) - JIRA::Resource::Filter.find(client, 42) + allow(described_class).to receive(:collection_path).and_return(collection_path) + described_class.find(client, 42) end let(:jql_issue) do { diff --git a/spec/jira/resource/issue_picker_suggestions_spec.rb b/spec/jira/resource/issue_picker_suggestions_spec.rb index ed46a2d2..a84b3622 100644 --- a/spec/jira/resource/issue_picker_suggestions_spec.rb +++ b/spec/jira/resource/issue_picker_suggestions_spec.rb @@ -9,7 +9,7 @@ describe 'relationships' do subject do - JIRA::Resource::IssuePickerSuggestions.new(client, attrs: { + described_class.new(client, attrs: { 'sections' => [{ 'id' => 'hs' }, { 'id' => 'cs' }] }) end @@ -38,42 +38,42 @@ expect(client).to receive(:IssuePickerSuggestions).and_return(issue_picker_suggestions) expect(issue_picker_suggestions).to receive(:build).with({ 'sections' => [{ 'id' => 'cs' }] }) - JIRA::Resource::IssuePickerSuggestions.all(client, 'query') + described_class.all(client, 'query') end it 'autocompletes issues with current jql' do expect(client).to receive(:get).with('/jira/rest/api/2/issue/picker?query=query¤tJQL=project+%3D+PR') .and_return(response) - JIRA::Resource::IssuePickerSuggestions.all(client, 'query', current_jql: 'project = PR') + described_class.all(client, 'query', current_jql: 'project = PR') end it 'autocompletes issues with current issue jey' do expect(client).to receive(:get).with('/jira/rest/api/2/issue/picker?query=query¤tIssueKey=PR-42') .and_return(response) - JIRA::Resource::IssuePickerSuggestions.all(client, 'query', current_issue_key: 'PR-42') + described_class.all(client, 'query', current_issue_key: 'PR-42') end it 'autocompletes issues with current project id' do expect(client).to receive(:get).with('/jira/rest/api/2/issue/picker?query=query¤tProjectId=PR') .and_return(response) - JIRA::Resource::IssuePickerSuggestions.all(client, 'query', current_project_id: 'PR') + described_class.all(client, 'query', current_project_id: 'PR') end it 'autocompletes issues with show sub tasks' do expect(client).to receive(:get).with('/jira/rest/api/2/issue/picker?query=query&showSubTasks=true') .and_return(response) - JIRA::Resource::IssuePickerSuggestions.all(client, 'query', show_sub_tasks: true) + described_class.all(client, 'query', show_sub_tasks: true) end it 'autocompletes issues with show sub tasks parent' do expect(client).to receive(:get).with('/jira/rest/api/2/issue/picker?query=query&showSubTaskParent=true') .and_return(response) - JIRA::Resource::IssuePickerSuggestions.all(client, 'query', show_sub_task_parent: true) + described_class.all(client, 'query', show_sub_task_parent: true) end end end diff --git a/spec/jira/resource/issue_spec.rb b/spec/jira/resource/issue_spec.rb index 00fe3b2b..fe7eb1c4 100644 --- a/spec/jira/resource/issue_spec.rb +++ b/spec/jira/resource/issue_spec.rb @@ -16,11 +16,11 @@ class JIRAResourceDelegation < SimpleDelegator # :nodoc: before(:each) do response = double allow(response).to receive(:body).and_return('{"key":"foo","id":"101"}') - allow(JIRA::Resource::Issue).to receive(:collection_path).and_return('/jira/rest/api/2/issue') + allow(described_class).to receive(:collection_path).and_return('/jira/rest/api/2/issue') allow(client).to receive(:get).with('/jira/rest/api/2/issue/101') .and_return(response) - issue = JIRA::Resource::Issue.find(client, 101) + issue = described_class.find(client, 101) @decorated = JIRAResourceDelegation.new(issue) end it 'responds to key' do @@ -49,21 +49,21 @@ class JIRAResourceDelegation < SimpleDelegator # :nodoc: expect(client).to receive(:Issue).and_return(issue) expect(issue).to receive(:build).with({ 'id' => '1', 'summary' => 'Bugs Everywhere' }) - issues = JIRA::Resource::Issue.all(client) + issues = described_class.all(client) end it 'finds an issue by key or id' do response = double allow(response).to receive(:body).and_return('{"key":"foo","id":"101"}') - allow(JIRA::Resource::Issue).to receive(:collection_path).and_return('/jira/rest/api/2/issue') + allow(described_class).to receive(:collection_path).and_return('/jira/rest/api/2/issue') expect(client).to receive(:get).with('/jira/rest/api/2/issue/foo') .and_return(response) expect(client).to receive(:get).with('/jira/rest/api/2/issue/101') .and_return(response) - issue_from_id = JIRA::Resource::Issue.find(client, 101) - issue_from_key = JIRA::Resource::Issue.find(client, 'foo') + issue_from_id = described_class.find(client, 101) + issue_from_key = described_class.find(client, 'foo') expect(issue_from_id.attrs).to eq(issue_from_key.attrs) end @@ -78,7 +78,7 @@ class JIRAResourceDelegation < SimpleDelegator # :nodoc: expect(client).to receive(:Issue).and_return(issue) expect(issue).to receive(:build).with(%w[key foo]).and_return('') - expect(JIRA::Resource::Issue.jql(client, 'foo bar')).to eq(['']) + expect(described_class.jql(client, 'foo bar')).to eq(['']) end it 'searches an issue with a jql query string and fields' do @@ -92,7 +92,7 @@ class JIRAResourceDelegation < SimpleDelegator # :nodoc: expect(client).to receive(:Issue).and_return(issue) expect(issue).to receive(:build).with(%w[key foo]).and_return('') - expect(JIRA::Resource::Issue.jql(client, 'foo bar', fields: %w[foo bar])).to eq(['']) + expect(described_class.jql(client, 'foo bar', fields: %w[foo bar])).to eq(['']) end it 'searches an issue with a jql query string, start at, and maxResults' do @@ -106,7 +106,7 @@ class JIRAResourceDelegation < SimpleDelegator # :nodoc: expect(client).to receive(:Issue).and_return(issue) expect(issue).to receive(:build).with(%w[key foo]).and_return('') - expect(JIRA::Resource::Issue.jql(client, 'foo bar', start_at: 1, max_results: 3)).to eq(['']) + expect(described_class.jql(client, 'foo bar', start_at: 1, max_results: 3)).to eq(['']) end it 'searches an issue with a jql query string and maxResults equals zero and should return the count of tickets' do @@ -118,7 +118,7 @@ class JIRAResourceDelegation < SimpleDelegator # :nodoc: .with('/jira/rest/api/2/search?jql=foo+bar&maxResults=0') .and_return(response) - expect(JIRA::Resource::Issue.jql(client, 'foo bar', max_results: 0)).to eq(1) + expect(described_class.jql(client, 'foo bar', max_results: 0)).to eq(1) end it 'searches an issue with a jql query string and string expand' do @@ -132,7 +132,7 @@ class JIRAResourceDelegation < SimpleDelegator # :nodoc: expect(client).to receive(:Issue).and_return(issue) expect(issue).to receive(:build).with(%w[key foo]).and_return('') - expect(JIRA::Resource::Issue.jql(client, 'foo bar', expand: 'transitions')).to eq(['']) + expect(described_class.jql(client, 'foo bar', expand: 'transitions')).to eq(['']) end it 'searches an issue with a jql query string and array expand' do @@ -146,11 +146,11 @@ class JIRAResourceDelegation < SimpleDelegator # :nodoc: expect(client).to receive(:Issue).and_return(issue) expect(issue).to receive(:build).with(%w[key foo]).and_return('') - expect(JIRA::Resource::Issue.jql(client, 'foo bar', expand: %w[transitions])).to eq(['']) + expect(described_class.jql(client, 'foo bar', expand: %w[transitions])).to eq(['']) end it 'returns meta data available for editing an issue' do - subject = JIRA::Resource::Issue.new(client, attrs: { 'fields' => { 'key' => 'TST=123' } }) + subject = described_class.new(client, attrs: { 'fields' => { 'key' => 'TST=123' } }) response = double allow(response).to receive(:body).and_return( @@ -164,14 +164,14 @@ class JIRAResourceDelegation < SimpleDelegator # :nodoc: end it 'provides direct accessors to the fields' do - subject = JIRA::Resource::Issue.new(client, attrs: { 'fields' => { 'foo' => 'bar' } }) + subject = described_class.new(client, attrs: { 'fields' => { 'foo' => 'bar' } }) expect(subject).to respond_to(:foo) expect(subject.foo).to eq('bar') end describe 'relationships' do subject do - JIRA::Resource::Issue.new(client, attrs: { + described_class.new(client, attrs: { 'id' => '123', 'fields' => { 'reporter' => { 'foo' => 'bar' }, diff --git a/spec/jira/resource/jira_picker_suggestions_issue_spec.rb b/spec/jira/resource/jira_picker_suggestions_issue_spec.rb index edeef934..bf420144 100644 --- a/spec/jira/resource/jira_picker_suggestions_issue_spec.rb +++ b/spec/jira/resource/jira_picker_suggestions_issue_spec.rb @@ -5,7 +5,7 @@ describe 'relationships' do subject do - JIRA::Resource::IssuePickerSuggestionsIssue.new(client, attrs: { + described_class.new(client, attrs: { 'issues' => [{ 'id' => '1' }, { 'id' => '2' }] }) end diff --git a/spec/jira/resource/project_factory_spec.rb b/spec/jira/resource/project_factory_spec.rb index 50b9c827..1cafc807 100644 --- a/spec/jira/resource/project_factory_spec.rb +++ b/spec/jira/resource/project_factory_spec.rb @@ -2,10 +2,10 @@ describe JIRA::Resource::ProjectFactory do let(:client) { double } - subject { JIRA::Resource::ProjectFactory.new(client) } + subject { described_class.new(client) } it 'initializes correctly' do - expect(subject.class).to eq(JIRA::Resource::ProjectFactory) + expect(subject.class).to eq(described_class) expect(subject.client).to eq(client) end end diff --git a/spec/jira/resource/project_spec.rb b/spec/jira/resource/project_spec.rb index 648fcf00..1885742f 100644 --- a/spec/jira/resource/project_spec.rb +++ b/spec/jira/resource/project_spec.rb @@ -9,7 +9,7 @@ describe 'relationships' do subject do - JIRA::Resource::Project.new(client, attrs: { + described_class.new(client, attrs: { 'lead' => { 'foo' => 'bar' }, 'issueTypes' => [{ 'foo' => 'bar' }, { 'baz' => 'flum' }], 'versions' => [{ 'foo' => 'bar' }, { 'baz' => 'flum' }] @@ -30,7 +30,7 @@ describe 'issues' do subject do - JIRA::Resource::Project.new(client, attrs: { + described_class.new(client, attrs: { 'key' => 'test' }) end @@ -69,7 +69,7 @@ end describe 'users' do - let(:project) { JIRA::Resource::Project.new(client, attrs: { 'key' => project_key }) } + let(:project) { described_class.new(client, attrs: { 'key' => project_key }) } let(:project_key) { SecureRandom.hex } let(:response) { double('response', body: '[{}]') } diff --git a/spec/jira/resource/sprint_spec.rb b/spec/jira/resource/sprint_spec.rb index f71625d7..806c887a 100644 --- a/spec/jira/resource/sprint_spec.rb +++ b/spec/jira/resource/sprint_spec.rb @@ -14,7 +14,7 @@ it 'fetches the sprint from JIRA' do expect(client).to receive(:get).with('/jira/rest/agile/1.0/sprint/111').and_return(response) - expect(JIRA::Resource::Sprint.find(client, '111')).to be_a(JIRA::Resource::Sprint) + expect(described_class.find(client, '111')).to be_a(described_class) end end diff --git a/spec/jira/resource/status_spec.rb b/spec/jira/resource/status_spec.rb index e3023dc6..244c2b9b 100644 --- a/spec/jira/resource/status_spec.rb +++ b/spec/jira/resource/status_spec.rb @@ -11,7 +11,7 @@ describe '#status_category' do subject do - JIRA::Resource::Status.new(client, attrs: JSON.parse(File.read('spec/mock_responses/status/1.json'))) + described_class.new(client, attrs: JSON.parse(File.read('spec/mock_responses/status/1.json'))) end it 'has a status_category relationship' do diff --git a/spec/jira/resource/user_factory_spec.rb b/spec/jira/resource/user_factory_spec.rb index e1d60ab7..8f0d4870 100644 --- a/spec/jira/resource/user_factory_spec.rb +++ b/spec/jira/resource/user_factory_spec.rb @@ -5,7 +5,7 @@ instance_double('Client', options: { rest_base_path: '/jira/rest/api/2' }) end - subject { JIRA::Resource::UserFactory.new(client) } + subject { described_class.new(client) } describe '#myself' do let(:response) do diff --git a/spec/jira/resource/worklog_spec.rb b/spec/jira/resource/worklog_spec.rb index 4ec0b8ff..08f97cce 100644 --- a/spec/jira/resource/worklog_spec.rb +++ b/spec/jira/resource/worklog_spec.rb @@ -5,7 +5,7 @@ describe 'relationships' do subject do - JIRA::Resource::Worklog.new(client, issue_id: '99999', attrs: { + described_class.new(client, issue_id: '99999', attrs: { 'author' => { 'foo' => 'bar' }, 'updateAuthor' => { 'foo' => 'bar' } }) From 9cfcbfd7498b031f3415bdfee2d9d6391d18c35b Mon Sep 17 00:00:00 2001 From: Robert Brodie Date: Sun, 28 Apr 2024 20:51:34 -0400 Subject: [PATCH 22/59] Fixed Lint/SymbolConversion --- lib/jira/base.rb | 4 ++-- spec/integration/watcher_spec.rb | 14 +++++++------- spec/jira/client_spec.rb | 4 ++-- spec/jira/resource/attachment_spec.rb | 12 ++++++------ spec/jira/resource/sprint_spec.rb | 4 ++-- 5 files changed, 19 insertions(+), 19 deletions(-) diff --git a/lib/jira/base.rb b/lib/jira/base.rb index a35c4cfe..cc7dfe04 100644 --- a/lib/jira/base.rb +++ b/lib/jira/base.rb @@ -83,8 +83,8 @@ def initialize(client, options = {}) if options[relation] instance_variable_set("@#{relation}", options[relation]) instance_variable_set("@#{relation}_id", options[relation].key_value) - elsif options["#{relation}_id".to_sym] - instance_variable_set("@#{relation}_id", options["#{relation}_id".to_sym]) + elsif options[:"#{relation}_id"] + instance_variable_set("@#{relation}_id", options[:"#{relation}_id"]) else raise ArgumentError, "Required option #{relation.inspect} missing" unless options[relation] end diff --git a/spec/integration/watcher_spec.rb b/spec/integration/watcher_spec.rb index d7677054..1fb0711a 100644 --- a/spec/integration/watcher_spec.rb +++ b/spec/integration/watcher_spec.rb @@ -19,14 +19,14 @@ let(:expected_attributes) do { 'self' => 'http://localhost:2990/jira/rest/api/2/issue/10002/watchers', - "isWatching": false, - "watchCount": 1, - "watchers": [ + isWatching: false, + watchCount: 1, + watchers: [ { - "self": 'http://www.example.com/jira/rest/api/2/user?username=admin', - "name": 'admin', - "displayName": 'admin', - "active": false + self: 'http://www.example.com/jira/rest/api/2/user?username=admin', + name: 'admin', + displayName: 'admin', + active: false } ] } diff --git a/spec/jira/client_spec.rb b/spec/jira/client_spec.rb index 75d7cd66..a7858125 100644 --- a/spec/jira/client_spec.rb +++ b/spec/jira/client_spec.rb @@ -186,8 +186,8 @@ let(:session_cookie) { '6E3487971234567896704A9EB4AE501F' } let(:session_body) do { - 'session': { 'name' => 'JSESSIONID', 'value' => session_cookie }, - 'loginInfo': { 'failedLoginCount' => 1, 'loginCount' => 2, + session: { 'name' => 'JSESSIONID', 'value' => session_cookie }, + loginInfo: { 'failedLoginCount' => 1, 'loginCount' => 2, 'lastFailedLoginTime' => (DateTime.now - 2).iso8601, 'previousLoginTime' => (DateTime.now - 5).iso8601 } } diff --git a/spec/jira/resource/attachment_spec.rb b/spec/jira/resource/attachment_spec.rb index f669d5db..18434dc5 100644 --- a/spec/jira/resource/attachment_spec.rb +++ b/spec/jira/resource/attachment_spec.rb @@ -105,12 +105,12 @@ double( body: [ { - "id": 10_001, - "self": 'http://www.example.com/jira/rest/api/2.0/attachments/10000', - "filename": file_name, - "created": '2017-07-19T12:23:06.572+0000', - "size": file_size, - "mimeType": file_mime_type + id: 10_001, + self: 'http://www.example.com/jira/rest/api/2.0/attachments/10000', + filename: file_name, + created: '2017-07-19T12:23:06.572+0000', + size: file_size, + mimeType: file_mime_type } ].to_json ) diff --git a/spec/jira/resource/sprint_spec.rb b/spec/jira/resource/sprint_spec.rb index 806c887a..0418abd0 100644 --- a/spec/jira/resource/sprint_spec.rb +++ b/spec/jira/resource/sprint_spec.rb @@ -99,7 +99,7 @@ issue end let(:post_issue_input) do - { "issues":[issue.id] } + { issues:[issue.id] } end @@ -129,7 +129,7 @@ end end let(:post_issue_input) do - { "issues": issue_ids } + { issues: issue_ids } end describe '#add_issues' do From 2d60892a204b8e4ece36938d79f8b6816378bf78 Mon Sep 17 00:00:00 2001 From: Robert Brodie Date: Sun, 28 Apr 2024 20:52:27 -0400 Subject: [PATCH 23/59] Fixed Layout/LineLength --- spec/jira/base_spec.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/spec/jira/base_spec.rb b/spec/jira/base_spec.rb index c18315c2..e494f222 100644 --- a/spec/jira/base_spec.rb +++ b/spec/jira/base_spec.rb @@ -490,7 +490,8 @@ class JIRA::Resource::HasManyExample < JIRA::Base # :nodoc: it 'allows the has_many attributes to be nested inside another attribute' do subject = JIRA::Resource::HasManyExample.new(client, - attrs: { 'nested' => { 'brunchmuffins' => [{ 'id' => '123' }, { 'id' => '456' }] } }) + attrs: { 'nested' => { 'brunchmuffins' => [{ 'id' => '123' }, +{ 'id' => '456' }] } }) expect(subject.brunchmuffins.length).to eq(2) subject.brunchmuffins.each do |brunchmuffin| expect(brunchmuffin.class).to eq(JIRA::Resource::Deadbeef) @@ -516,7 +517,8 @@ class JIRA::Resource::HasManyExample < JIRA::Base # :nodoc: it 'allows the attribute key to be specified' do subject = JIRA::Resource::HasManyExample.new(client, - attrs: { 'irregularlyNamedThings' => [{ 'id' => '123' }, { 'id' => '456' }] }) + attrs: { 'irregularlyNamedThings' => [{ 'id' => '123' }, +{ 'id' => '456' }] }) expect(subject.irregularly_named_things.length).to eq(2) subject.irregularly_named_things.each do |thing| expect(thing.class).to eq(JIRA::Resource::Deadbeef) From 6fdb71a548e0bdb03bb8a0ecd2120f7fb59565b5 Mon Sep 17 00:00:00 2001 From: Robert Brodie Date: Sun, 28 Apr 2024 20:54:51 -0400 Subject: [PATCH 24/59] Fixed Layout/ExtraSpacing --- spec/jira/resource/field_spec.rb | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/spec/jira/resource/field_spec.rb b/spec/jira/resource/field_spec.rb index 5d89d5d8..c243dd87 100644 --- a/spec/jira/resource/field_spec.rb +++ b/spec/jira/resource/field_spec.rb @@ -14,29 +14,29 @@ attrs: { 'id' => 'customfield_10666', 'name' => 'Priority', 'custom' => true, 'orderable' => true, 'navigable' => true, 'searchable' => true, 'clauseNames' => ['cf[10666]', 'Priority'], 'schema' => { 'type' => 'string', 'custom' => 'com.atlassian.jira.plugin.system.customfieldtypes:select', 'customId' => 10_666 } }), described_class.new(client, - attrs: { 'id' => 'issuekey', 'name' => 'Key', 'custom' => false, 'orderable' => false, + attrs: { 'id' => 'issuekey', 'name' => 'Key', 'custom' => false, 'orderable' => false, 'navigable' => true, 'searchable' => false, 'clauseNames' => %w[id issue issuekey key] }), described_class.new(client, - attrs: { 'id' => 'priority', 'name' => 'Priority', 'custom' => false, 'orderable' => true, - 'navigable' => true, 'searchable' => true, 'clauseNames' => ['priority'], 'schema' => { 'type' => 'priority', 'system' => 'priority' } }), + attrs: { 'id' => 'priority', 'name' => 'Priority', 'custom' => false, 'orderable' => true, + 'navigable' => true, 'searchable' => true, 'clauseNames' => ['priority'], 'schema' => { 'type' => 'priority', 'system' => 'priority' } }), described_class.new(client, - attrs: { 'id' => 'summary', 'name' => 'Summary', 'custom' => false, 'orderable' => true, - 'navigable' => true, 'searchable' => true, 'clauseNames' => ['summary'], 'schema' => { 'type' => 'string', 'system' => 'summary' } }), + attrs: { 'id' => 'summary', 'name' => 'Summary', 'custom' => false, 'orderable' => true, + 'navigable' => true, 'searchable' => true, 'clauseNames' => ['summary'], 'schema' => { 'type' => 'string', 'system' => 'summary' } }), described_class.new(client, - attrs: { 'id' => 'issuetype', 'name' => 'Issue Type', 'custom' => false, 'orderable' => true, - 'navigable' => true, 'searchable' => true, 'clauseNames' => %w[issuetype type], 'schema' => { 'type' => 'issuetype', 'system' => 'issuetype' } }), + attrs: { 'id' => 'issuetype', 'name' => 'Issue Type', 'custom' => false, 'orderable' => true, + 'navigable' => true, 'searchable' => true, 'clauseNames' => %w[issuetype type], 'schema' => { 'type' => 'issuetype', 'system' => 'issuetype' } }), described_class.new(client, - attrs: { 'id' => 'customfield_10111', 'name' => 'SingleWord', 'custom' => true, 'orderable' => true, - 'navigable' => true, 'searchable' => true, 'clauseNames' => ['cf[10111]', 'SingleWord'], 'schema' => { 'type' => 'string', 'custom' => 'com.atlassian.jira.plugin.system.customfieldtypes:select', 'customId' => 10_111 } }), + attrs: { 'id' => 'customfield_10111', 'name' => 'SingleWord', 'custom' => true, 'orderable' => true, + 'navigable' => true, 'searchable' => true, 'clauseNames' => ['cf[10111]', 'SingleWord'], 'schema' => { 'type' => 'string', 'custom' => 'com.atlassian.jira.plugin.system.customfieldtypes:select', 'customId' => 10_111 } }), described_class.new(client, - attrs: { 'id' => 'customfield_10222', 'name' => 'Multi Word', 'custom' => true, 'orderable' => true, - 'navigable' => true, 'searchable' => true, 'clauseNames' => ['cf[10222]', 'Multi Word'], 'schema' => { 'type' => 'string', 'custom' => 'com.atlassian.jira.plugin.system.customfieldtypes:select', 'customId' => 10_222 } }), + attrs: { 'id' => 'customfield_10222', 'name' => 'Multi Word', 'custom' => true, 'orderable' => true, + 'navigable' => true, 'searchable' => true, 'clauseNames' => ['cf[10222]', 'Multi Word'], 'schema' => { 'type' => 'string', 'custom' => 'com.atlassian.jira.plugin.system.customfieldtypes:select', 'customId' => 10_222 } }), described_class.new(client, - attrs: { 'id' => 'customfield_10333', 'name' => 'Why/N@t', 'custom' => true, 'orderable' => true, - 'navigable' => true, 'searchable' => true, 'clauseNames' => ['cf[10333]', 'Why/N@t'], 'schema' => { 'type' => 'string', 'custom' => 'com.atlassian.jira.plugin.system.customfieldtypes:select', 'customId' => 10_333 } }), + attrs: { 'id' => 'customfield_10333', 'name' => 'Why/N@t', 'custom' => true, 'orderable' => true, + 'navigable' => true, 'searchable' => true, 'clauseNames' => ['cf[10333]', 'Why/N@t'], 'schema' => { 'type' => 'string', 'custom' => 'com.atlassian.jira.plugin.system.customfieldtypes:select', 'customId' => 10_333 } }), described_class.new(client, - attrs: { 'id' => 'customfield_10444', 'name' => 'SingleWord', 'custom' => true, 'orderable' => true, - 'navigable' => true, 'searchable' => true, 'clauseNames' => ['cf[10444]', 'SingleWord'], 'schema' => { 'type' => 'string', 'custom' => 'com.atlassian.jira.plugin.system.customfieldtypes:select', 'customId' => 10_444 } }) + attrs: { 'id' => 'customfield_10444', 'name' => 'SingleWord', 'custom' => true, 'orderable' => true, + 'navigable' => true, 'searchable' => true, 'clauseNames' => ['cf[10444]', 'SingleWord'], 'schema' => { 'type' => 'string', 'custom' => 'com.atlassian.jira.plugin.system.customfieldtypes:select', 'customId' => 10_444 } }) ]) client end From 5fbb83564d6b3706314b7aa5b871e17e3f94d583 Mon Sep 17 00:00:00 2001 From: Robert Brodie Date: Sun, 28 Apr 2024 20:57:18 -0400 Subject: [PATCH 25/59] Fixed Layout/FirstHashElementIndentation --- spec/jira/resource/field_spec.rb | 4 ++-- spec/jira/resource/issue_picker_suggestions_spec.rb | 8 ++++---- spec/jira/resource/issue_spec.rb | 4 ++-- spec/jira/resource/jira_picker_suggestions_issue_spec.rb | 4 ++-- spec/jira/resource/project_spec.rb | 8 ++++---- spec/jira/resource/worklog_spec.rb | 4 ++-- 6 files changed, 16 insertions(+), 16 deletions(-) diff --git a/spec/jira/resource/field_spec.rb b/spec/jira/resource/field_spec.rb index c243dd87..8da29e7d 100644 --- a/spec/jira/resource/field_spec.rb +++ b/spec/jira/resource/field_spec.rb @@ -45,13 +45,13 @@ shared_context 'mapped or not' do subject do described_class.new(client, attrs: { - 'priority' => 1, + 'priority' => 1, 'customfield_10111' => 'data_in_custom_field', 'customfield_10222' => 'multi word custom name', 'customfield_10333' => 'complex custom name', 'customfield_10444' => 'duplicated custom name', 'customfield_10666' => 'duplicate of a system name' - }) + }) end it 'can find a standard field by id' do diff --git a/spec/jira/resource/issue_picker_suggestions_spec.rb b/spec/jira/resource/issue_picker_suggestions_spec.rb index a84b3622..d398dc7d 100644 --- a/spec/jira/resource/issue_picker_suggestions_spec.rb +++ b/spec/jira/resource/issue_picker_suggestions_spec.rb @@ -3,15 +3,15 @@ describe JIRA::Resource::IssuePickerSuggestions do let(:client) do double('client', options: { - rest_base_path: '/jira/rest/api/2' - }) + rest_base_path: '/jira/rest/api/2' + }) end describe 'relationships' do subject do described_class.new(client, attrs: { - 'sections' => [{ 'id' => 'hs' }, { 'id' => 'cs' }] - }) + 'sections' => [{ 'id' => 'hs' }, { 'id' => 'cs' }] + }) end it 'has the correct relationships' do diff --git a/spec/jira/resource/issue_spec.rb b/spec/jira/resource/issue_spec.rb index fe7eb1c4..ed8ca505 100644 --- a/spec/jira/resource/issue_spec.rb +++ b/spec/jira/resource/issue_spec.rb @@ -172,7 +172,7 @@ class JIRAResourceDelegation < SimpleDelegator # :nodoc: describe 'relationships' do subject do described_class.new(client, attrs: { - 'id' => '123', + 'id' => '123', 'fields' => { 'reporter' => { 'foo' => 'bar' }, 'assignee' => { 'foo' => 'bar' }, @@ -187,7 +187,7 @@ class JIRAResourceDelegation < SimpleDelegator # :nodoc: 'attachment' => [{ 'foo' => 'bar' }, { 'baz' => 'flum' }], 'worklog' => { 'worklogs' => [{ 'foo' => 'bar' }, { 'baz' => 'flum' }] } } - }) + }) end it 'has the correct relationships' do diff --git a/spec/jira/resource/jira_picker_suggestions_issue_spec.rb b/spec/jira/resource/jira_picker_suggestions_issue_spec.rb index bf420144..44e4afb5 100644 --- a/spec/jira/resource/jira_picker_suggestions_issue_spec.rb +++ b/spec/jira/resource/jira_picker_suggestions_issue_spec.rb @@ -6,8 +6,8 @@ describe 'relationships' do subject do described_class.new(client, attrs: { - 'issues' => [{ 'id' => '1' }, { 'id' => '2' }] - }) + 'issues' => [{ 'id' => '1' }, { 'id' => '2' }] + }) end it 'has the correct relationships' do diff --git a/spec/jira/resource/project_spec.rb b/spec/jira/resource/project_spec.rb index 1885742f..1facc87e 100644 --- a/spec/jira/resource/project_spec.rb +++ b/spec/jira/resource/project_spec.rb @@ -10,10 +10,10 @@ describe 'relationships' do subject do described_class.new(client, attrs: { - 'lead' => { 'foo' => 'bar' }, + 'lead' => { 'foo' => 'bar' }, 'issueTypes' => [{ 'foo' => 'bar' }, { 'baz' => 'flum' }], 'versions' => [{ 'foo' => 'bar' }, { 'baz' => 'flum' }] - }) + }) end it 'has the correct relationships' do @@ -31,8 +31,8 @@ describe 'issues' do subject do described_class.new(client, attrs: { - 'key' => 'test' - }) + 'key' => 'test' + }) end it 'returns issues' do diff --git a/spec/jira/resource/worklog_spec.rb b/spec/jira/resource/worklog_spec.rb index 08f97cce..02f1dea1 100644 --- a/spec/jira/resource/worklog_spec.rb +++ b/spec/jira/resource/worklog_spec.rb @@ -6,9 +6,9 @@ describe 'relationships' do subject do described_class.new(client, issue_id: '99999', attrs: { - 'author' => { 'foo' => 'bar' }, + 'author' => { 'foo' => 'bar' }, 'updateAuthor' => { 'foo' => 'bar' } - }) + }) end it 'has the correct relationships' do From 313c704dce8847701119155f5cc22c58118fbcde Mon Sep 17 00:00:00 2001 From: Robert Brodie Date: Sun, 28 Apr 2024 20:58:02 -0400 Subject: [PATCH 26/59] Fixed Style/SymbolArray --- lib/jira/client.rb | 72 +++++++++++++++++++++++----------------------- 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/lib/jira/client.rb b/lib/jira/client.rb index 13f838db..76e54bbf 100644 --- a/lib/jira/client.rb +++ b/lib/jira/client.rb @@ -63,42 +63,42 @@ class Client def_delegators :@request_client, :init_access_token, :set_access_token, :set_request_token, :request_token, :access_token, :authenticated? - DEFINED_OPTIONS = [ - :site, - :context_path, - :signature_method, - :request_token_path, - :authorize_path, - :access_token_path, - :private_key, - :private_key_file, - :rest_base_path, - :consumer_key, - :consumer_secret, - :ssl_verify_mode, - :ssl_version, - :use_ssl, - :username, - :password, - :auth_type, - :proxy_address, - :proxy_port, - :proxy_username, - :proxy_password, - :use_cookies, - :additional_cookies, - :default_headers, - :use_client_cert, - :read_timeout, - :max_retries, - :http_debug, - :issuer, - :base_url, - :shared_secret, - :cert_path, - :key_path, - :ssl_client_cert, - :ssl_client_key + DEFINED_OPTIONS = %i[ + site + context_path + signature_method + request_token_path + authorize_path + access_token_path + private_key + private_key_file + rest_base_path + consumer_key + consumer_secret + ssl_verify_mode + ssl_version + use_ssl + username + password + auth_type + proxy_address + proxy_port + proxy_username + proxy_password + use_cookies + additional_cookies + default_headers + use_client_cert + read_timeout + max_retries + http_debug + issuer + base_url + shared_secret + cert_path + key_path + ssl_client_cert + ssl_client_key ].freeze DEFAULT_OPTIONS = { From 503718b3734121ca9e8b0d6008d3ae175515ff0e Mon Sep 17 00:00:00 2001 From: Robert Brodie Date: Sun, 28 Apr 2024 20:59:26 -0400 Subject: [PATCH 27/59] Fixed Style/RedundantReturn --- lib/jira/base.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/jira/base.rb b/lib/jira/base.rb index cc7dfe04..ab2141ee 100644 --- a/lib/jira/base.rb +++ b/lib/jira/base.rb @@ -492,7 +492,7 @@ def self.maybe_nested_attribute(attributes, attribute_name, nested_under = nil) final[attribute_name] else - return attributes[nested_under][attribute_name] + attributes[nested_under][attribute_name] end end From bdb240528a5b04a92c2654b3311264a7d2fe7059 Mon Sep 17 00:00:00 2001 From: Robert Brodie Date: Sun, 28 Apr 2024 21:00:42 -0400 Subject: [PATCH 28/59] Fixed RSpec/HookArgument --- spec/integration/issue_spec.rb | 4 ++-- spec/integration/rapidview_spec.rb | 2 +- spec/integration/watcher_spec.rb | 2 +- spec/jira/base_spec.rb | 12 ++++++------ spec/jira/client_spec.rb | 6 +++--- spec/jira/resource/issue_spec.rb | 2 +- spec/jira/resource/project_spec.rb | 2 +- spec/jira/resource/user_factory_spec.rb | 2 +- 8 files changed, 16 insertions(+), 16 deletions(-) diff --git a/spec/integration/issue_spec.rb b/spec/integration/issue_spec.rb index fe960def..8a7cbed0 100644 --- a/spec/integration/issue_spec.rb +++ b/spec/integration/issue_spec.rb @@ -43,7 +43,7 @@ 'key' => 'SAMPLEPROJECT-13' } end - before(:each) do + before do stub_request(:get, "#{site_url}/jira/rest/api/2/search?expand=transitions.fields&maxResults=1000&startAt=0") .to_return(status: 200, body: get_mock_response('issue.json')) @@ -58,7 +58,7 @@ it_behaves_like 'a resource with a PUT endpoint that rejects invalid fields' describe 'errors' do - before(:each) do + before do stub_request(:get, "#{site_url}/jira/rest/api/2/issue/10002") .to_return(status: 200, body: get_mock_response('issue/10002.json')) diff --git a/spec/integration/rapidview_spec.rb b/spec/integration/rapidview_spec.rb index ebf96780..e62f0098 100644 --- a/spec/integration/rapidview_spec.rb +++ b/spec/integration/rapidview_spec.rb @@ -26,7 +26,7 @@ let(:client) { client } let(:site_url) { site_url } - before(:each) do + before do stub_request(:get, "#{site_url}/jira/rest/greenhopper/1.0/rapidview") .to_return(status: 200, body: get_mock_response('rapidview.json')) end diff --git a/spec/integration/watcher_spec.rb b/spec/integration/watcher_spec.rb index 1fb0711a..82c6da3a 100644 --- a/spec/integration/watcher_spec.rb +++ b/spec/integration/watcher_spec.rb @@ -33,7 +33,7 @@ end describe 'watchers' do - before(:each) do + before do stub_request(:get, "#{site_url}/jira/rest/api/2/issue/10002") .to_return(status: 200, body: get_mock_response('issue/10002.json')) diff --git a/spec/jira/base_spec.rb b/spec/jira/base_spec.rb index e494f222..fdcd3d91 100644 --- a/spec/jira/base_spec.rb +++ b/spec/jira/base_spec.rb @@ -125,7 +125,7 @@ class JIRA::Resource::HasManyExample < JIRA::Base # :nodoc: end describe 'collection_path' do - before(:each) do + before do expect(client).to receive(:options).and_return(rest_base_path: '/deadbeef/bar') end @@ -169,7 +169,7 @@ class JIRA::Resource::HasManyExample < JIRA::Base # :nodoc: subject { JIRA::Resource::Deadbeef.new(client, attrs: { 'id' => '98765' }) } describe 'not cached' do - before(:each) do + before do response = instance_double('Response', body: '{"self":"http://deadbeef/","id":"98765"}') expect(client).to receive(:get).with('/jira/rest/api/2/deadbeef/98765').and_return(response) expect(JIRA::Resource::Deadbeef).to receive(:collection_path).and_return('/jira/rest/api/2/deadbeef') @@ -226,7 +226,7 @@ class JIRA::Resource::HasManyExample < JIRA::Base # :nodoc: subject { JIRA::Resource::Deadbeef.new(client) } - before(:each) do + before do expect(subject).to receive(:url).and_return('/foo/bar') end @@ -277,7 +277,7 @@ class JIRA::Resource::HasManyExample < JIRA::Base # :nodoc: subject { JIRA::Resource::Deadbeef.new(client) } - before(:each) do + before do expect(subject).to receive(:url).and_return('/foo/bar') end @@ -322,7 +322,7 @@ class JIRA::Resource::HasManyExample < JIRA::Base # :nodoc: end describe 'delete' do - before(:each) do + before do expect(client).to receive(:delete).with('/foo/bar') allow(subject).to receive(:url) { '/foo/bar' } end @@ -362,7 +362,7 @@ class JIRA::Resource::HasManyExample < JIRA::Base # :nodoc: end describe 'url' do - before(:each) do + before do allow(client).to receive(:options) { { rest_base_path: '/foo/bar' } } end diff --git a/spec/jira/client_spec.rb b/spec/jira/client_spec.rb index a7858125..87f70053 100644 --- a/spec/jira/client_spec.rb +++ b/spec/jira/client_spec.rb @@ -147,7 +147,7 @@ context 'with basic http authentication' do subject { described_class.new(username: 'foo', password: 'bar', auth_type: :basic) } - before(:each) do + before do stub_request(:get, 'https://localhost:2990/jira/rest/api/2/project') .with(headers: { 'Authorization' => "Basic #{Base64.strict_encode64('foo:bar').chomp}" }) .to_return(status: 200, body: '[]', headers: {}) @@ -193,7 +193,7 @@ } end - before(:each) do + before do # General case of API call with no authentication, or wrong authentication stub_request(:post, 'https://localhost:2990/jira/rest/auth/1/session') .to_return(status: 401, headers: {}) @@ -240,7 +240,7 @@ ) end - before(:each) do + before do stub_request(:get, 'https://localhost:2990/jira/rest/api/2/project') .with(headers: { 'Authorization' => /JWT .+/ }) .to_return(status: 200, body: '[]', headers: {}) diff --git a/spec/jira/resource/issue_spec.rb b/spec/jira/resource/issue_spec.rb index ed8ca505..4828d44e 100644 --- a/spec/jira/resource/issue_spec.rb +++ b/spec/jira/resource/issue_spec.rb @@ -13,7 +13,7 @@ class JIRAResourceDelegation < SimpleDelegator # :nodoc: describe '#respond_to?' do describe 'when decorated by SimpleDelegator' do - before(:each) do + before do response = double allow(response).to receive(:body).and_return('{"key":"foo","id":"101"}') allow(described_class).to receive(:collection_path).and_return('/jira/rest/api/2/issue') diff --git a/spec/jira/resource/project_spec.rb b/spec/jira/resource/project_spec.rb index 1facc87e..2122c8c0 100644 --- a/spec/jira/resource/project_spec.rb +++ b/spec/jira/resource/project_spec.rb @@ -74,7 +74,7 @@ let(:response) { double('response', body: '[{}]') } context 'pagination' do - before(:each) do + before do user_factory = double('user factory') expect(client).to receive(:User).and_return(user_factory) expect(user_factory).to receive(:build).with(any_args) diff --git a/spec/jira/resource/user_factory_spec.rb b/spec/jira/resource/user_factory_spec.rb index 8f0d4870..33fa30c6 100644 --- a/spec/jira/resource/user_factory_spec.rb +++ b/spec/jira/resource/user_factory_spec.rb @@ -16,7 +16,7 @@ let(:user) { subject.myself } - before(:each) do + before do allow(client).to receive(:get).with( '/jira/rest/api/2/myself' ).and_return(response) From 6b3030f193f41d02524fc5f84f96ef7f8745aa69 Mon Sep 17 00:00:00 2001 From: Robert Brodie Date: Sun, 28 Apr 2024 21:02:56 -0400 Subject: [PATCH 29/59] Fixed RSpec/LeadingSubject and RSpec/EmptyLineAfterSubject --- spec/jira/base_factory_spec.rb | 3 ++- spec/jira/base_spec.rb | 15 ++++++++++----- spec/jira/client_spec.rb | 6 ++++-- spec/jira/http_client_spec.rb | 3 ++- spec/jira/http_error_spec.rb | 3 ++- spec/jira/resource/attachment_spec.rb | 15 +++++++++------ spec/jira/resource/board_spec.rb | 1 + spec/jira/resource/project_factory_spec.rb | 3 ++- spec/jira/resource/user_factory_spec.rb | 3 ++- 9 files changed, 34 insertions(+), 18 deletions(-) diff --git a/spec/jira/base_factory_spec.rb b/spec/jira/base_factory_spec.rb index 991d67e1..636b6ecb 100644 --- a/spec/jira/base_factory_spec.rb +++ b/spec/jira/base_factory_spec.rb @@ -4,9 +4,10 @@ class JIRA::Resource::FooFactory < JIRA::BaseFactory; end class JIRA::Resource::Foo; end - let(:client) { double } subject { JIRA::Resource::FooFactory.new(client) } + let(:client) { double } + it 'initializes correctly' do expect(subject.class).to eq(JIRA::Resource::FooFactory) expect(subject.client).to eq(client) diff --git a/spec/jira/base_spec.rb b/spec/jira/base_spec.rb index fdcd3d91..044123b2 100644 --- a/spec/jira/base_spec.rb +++ b/spec/jira/base_spec.rb @@ -32,10 +32,11 @@ class JIRA::Resource::HasManyExample < JIRA::Base # :nodoc: attribute_key: 'irregularlyNamedThings' end + subject { JIRA::Resource::Deadbeef.new(client, attrs:) } + let(:client) { double('client') } let(:attrs) { {} } - subject { JIRA::Resource::Deadbeef.new(client, attrs:) } let(:decorated) { JIRADelegation.new(subject) } @@ -147,9 +148,10 @@ class JIRA::Resource::HasManyExample < JIRA::Base # :nodoc: end describe 'dynamic instance methods' do - let(:attrs) { { 'foo' => 'bar', 'flum' => 'goo', 'object_id' => 'dummy' } } subject { JIRA::Resource::Deadbeef.new(client, attrs:) } + let(:attrs) { { 'foo' => 'bar', 'flum' => 'goo', 'object_id' => 'dummy' } } + it 'responds to each of the top level attribute names' do expect(subject).to respond_to(:foo) expect(subject).to respond_to('flum') @@ -222,9 +224,10 @@ class JIRA::Resource::HasManyExample < JIRA::Base # :nodoc: end describe 'save' do + subject { JIRA::Resource::Deadbeef.new(client) } + let(:response) { double } - subject { JIRA::Resource::Deadbeef.new(client) } before do expect(subject).to receive(:url).and_return('/foo/bar') @@ -273,9 +276,10 @@ class JIRA::Resource::HasManyExample < JIRA::Base # :nodoc: end describe 'save!' do + subject { JIRA::Resource::Deadbeef.new(client) } + let(:response) { double } - subject { JIRA::Resource::Deadbeef.new(client) } before do expect(subject).to receive(:url).and_return('/foo/bar') @@ -577,9 +581,10 @@ class JIRA::Resource::BelongsToExample < JIRA::Base belongs_to :deadbeef end + subject { JIRA::Resource::BelongsToExample.new(client, attrs: { 'id' => '123' }, deadbeef:) } + let(:deadbeef) { JIRA::Resource::Deadbeef.new(client, attrs: { 'id' => '999' }) } - subject { JIRA::Resource::BelongsToExample.new(client, attrs: { 'id' => '123' }, deadbeef:) } it 'sets up an accessor for the belongs to relationship' do expect(subject.deadbeef).to eq(deadbeef) diff --git a/spec/jira/client_spec.rb b/spec/jira/client_spec.rb index 87f70053..bf6894a3 100644 --- a/spec/jira/client_spec.rb +++ b/spec/jira/client_spec.rb @@ -62,9 +62,10 @@ describe 'SSL client options' do context 'without certificate and key' do - let(:options) { { use_client_cert: true } } subject { JIRA::Client.new(options) } + let(:options) { { use_client_cert: true } } + it 'raises an ArgumentError' do expect { subject }.to raise_exception(ArgumentError, @@ -291,9 +292,10 @@ end context 'with unknown options' do - let(:options) { { 'username' => 'foo', 'password' => 'bar', auth_type: :basic } } subject { described_class.new(options) } + let(:options) { { 'username' => 'foo', 'password' => 'bar', auth_type: :basic } } + it 'raises an ArgumentError' do expect { subject }.to raise_exception(ArgumentError, 'Unknown option(s) given: ["username", "password"]') end diff --git a/spec/jira/http_client_spec.rb b/spec/jira/http_client_spec.rb index c97094d0..1bf39f85 100644 --- a/spec/jira/http_client_spec.rb +++ b/spec/jira/http_client_spec.rb @@ -298,6 +298,8 @@ end context 'client has proxy settings' do + subject(:proxy_conn) { proxy_client.basic_auth_http_conn } + let(:proxy_client) do options_local = JIRA::Client::DEFAULT_OPTIONS.merge(JIRA::HttpClient::DEFAULT_OPTIONS).merge( proxy_address: 'proxyAddress', @@ -307,7 +309,6 @@ ) described_class.new(options_local) end - subject(:proxy_conn) { proxy_client.basic_auth_http_conn } describe 'HttpClient#basic_auth_http_conn' do it 'creates a Net:HTTP instance for a basic auth client setting up a proxied http connection' do diff --git a/spec/jira/http_error_spec.rb b/spec/jira/http_error_spec.rb index a94120b2..bfab6cda 100644 --- a/spec/jira/http_error_spec.rb +++ b/spec/jira/http_error_spec.rb @@ -1,6 +1,8 @@ require 'spec_helper' describe JIRA::HTTPError do + subject { described_class.new(response) } + let(:response) do response = double('response') allow(response).to receive(:code).and_return(401) @@ -8,7 +10,6 @@ response end - subject { described_class.new(response) } it 'takes the response object as an argument' do expect(subject.response).to eq(response) diff --git a/spec/jira/resource/attachment_spec.rb b/spec/jira/resource/attachment_spec.rb index 18434dc5..566bf2a3 100644 --- a/spec/jira/resource/attachment_spec.rb +++ b/spec/jira/resource/attachment_spec.rb @@ -60,12 +60,6 @@ end context 'there is an attachment on an issue' do - let(:client) do - JIRA::Client.new(username: 'username', password: 'password', auth_type: :basic, use_ssl: false ) - end - let(:attachment_file_contents) { 'file contents' } - let(:file_target) { double(read: :attachment_file_contents) } - let(:attachment_url) { 'https:jirahost/secure/attachment/32323/myfile.txt' } subject(:attachment) do described_class.new( client, @@ -74,6 +68,13 @@ ) end + let(:client) do + JIRA::Client.new(username: 'username', password: 'password', auth_type: :basic, use_ssl: false ) + end + let(:attachment_file_contents) { 'file contents' } + let(:file_target) { double(read: :attachment_file_contents) } + let(:attachment_url) { 'https:jirahost/secure/attachment/32323/myfile.txt' } + describe '.download_file' do it 'passes file object to block' do expect(URI).to receive(:open).with(attachment_url, anything).and_yield(file_target) @@ -139,6 +140,7 @@ attrs: { 'author' => { 'foo' => 'bar' } } ) end + let(:default_headers_given) { { 'authorization' => 'Bearer 83CF8B609DE60036A8277BD0E96135751BBC07EB234256D4B65B893360651BF2' } } let(:bearer_client) do @@ -195,6 +197,7 @@ attrs: { 'author' => { 'foo' => 'bar' } } ) end + let(:default_headers_given) { { 'authorization' => 'Bearer 83CF8B609DE60036A8277BD0E96135751BBC07EB234256D4B65B893360651BF2' } } let(:bearer_client) do diff --git a/spec/jira/resource/board_spec.rb b/spec/jira/resource/board_spec.rb index 5645f894..f04131bd 100644 --- a/spec/jira/resource/board_spec.rb +++ b/spec/jira/resource/board_spec.rb @@ -98,6 +98,7 @@ class JIRAResourceDelegation < SimpleDelegator # :nodoc: describe 'pagination' do subject { described_class.new(client) } + let(:client) { JIRA::Client.new } before do diff --git a/spec/jira/resource/project_factory_spec.rb b/spec/jira/resource/project_factory_spec.rb index 1cafc807..a4989cad 100644 --- a/spec/jira/resource/project_factory_spec.rb +++ b/spec/jira/resource/project_factory_spec.rb @@ -1,9 +1,10 @@ require 'spec_helper' describe JIRA::Resource::ProjectFactory do - let(:client) { double } subject { described_class.new(client) } + let(:client) { double } + it 'initializes correctly' do expect(subject.class).to eq(described_class) expect(subject.client).to eq(client) diff --git a/spec/jira/resource/user_factory_spec.rb b/spec/jira/resource/user_factory_spec.rb index 33fa30c6..8030cee6 100644 --- a/spec/jira/resource/user_factory_spec.rb +++ b/spec/jira/resource/user_factory_spec.rb @@ -1,11 +1,12 @@ require 'spec_helper' describe JIRA::Resource::UserFactory do + subject { described_class.new(client) } + let(:client) do instance_double('Client', options: { rest_base_path: '/jira/rest/api/2' }) end - subject { described_class.new(client) } describe '#myself' do let(:response) do From 107779033cebe94d22129476ba7bbe7e9857c728 Mon Sep 17 00:00:00 2001 From: Robert Brodie Date: Sun, 28 Apr 2024 21:45:25 -0400 Subject: [PATCH 30/59] Fixed Layout/EmptyLines --- spec/jira/base_spec.rb | 4 ---- spec/jira/http_error_spec.rb | 1 - spec/jira/oauth_client_spec.rb | 1 - spec/jira/resource/sprint_spec.rb | 1 - spec/jira/resource/user_factory_spec.rb | 1 - 5 files changed, 8 deletions(-) diff --git a/spec/jira/base_spec.rb b/spec/jira/base_spec.rb index 044123b2..801e99b9 100644 --- a/spec/jira/base_spec.rb +++ b/spec/jira/base_spec.rb @@ -37,7 +37,6 @@ class JIRA::Resource::HasManyExample < JIRA::Base # :nodoc: let(:client) { double('client') } let(:attrs) { {} } - let(:decorated) { JIRADelegation.new(subject) } describe '#respond_to?' do @@ -228,7 +227,6 @@ class JIRA::Resource::HasManyExample < JIRA::Base # :nodoc: let(:response) { double } - before do expect(subject).to receive(:url).and_return('/foo/bar') end @@ -280,7 +278,6 @@ class JIRA::Resource::HasManyExample < JIRA::Base # :nodoc: let(:response) { double } - before do expect(subject).to receive(:url).and_return('/foo/bar') end @@ -585,7 +582,6 @@ class JIRA::Resource::BelongsToExample < JIRA::Base let(:deadbeef) { JIRA::Resource::Deadbeef.new(client, attrs: { 'id' => '999' }) } - it 'sets up an accessor for the belongs to relationship' do expect(subject.deadbeef).to eq(deadbeef) end diff --git a/spec/jira/http_error_spec.rb b/spec/jira/http_error_spec.rb index bfab6cda..c2ddf1d7 100644 --- a/spec/jira/http_error_spec.rb +++ b/spec/jira/http_error_spec.rb @@ -10,7 +10,6 @@ response end - it 'takes the response object as an argument' do expect(subject.response).to eq(response) end diff --git a/spec/jira/oauth_client_spec.rb b/spec/jira/oauth_client_spec.rb index d0d4ae6b..5666b6c6 100644 --- a/spec/jira/oauth_client_spec.rb +++ b/spec/jira/oauth_client_spec.rb @@ -124,7 +124,6 @@ it 'performs a request' do expect(access_token).to receive(:send).with(:get, '/foo', headers).and_return(response) - oauth_client.request(:get, '/foo', body, headers) end diff --git a/spec/jira/resource/sprint_spec.rb b/spec/jira/resource/sprint_spec.rb index 0418abd0..3c066928 100644 --- a/spec/jira/resource/sprint_spec.rb +++ b/spec/jira/resource/sprint_spec.rb @@ -102,7 +102,6 @@ { issues:[issue.id] } end - describe '#add_issu' do context 'when an issue is passed' do diff --git a/spec/jira/resource/user_factory_spec.rb b/spec/jira/resource/user_factory_spec.rb index 8030cee6..934df524 100644 --- a/spec/jira/resource/user_factory_spec.rb +++ b/spec/jira/resource/user_factory_spec.rb @@ -7,7 +7,6 @@ instance_double('Client', options: { rest_base_path: '/jira/rest/api/2' }) end - describe '#myself' do let(:response) do instance_double( From af938b1dc842a5b364e06ab6534d224c10b304d7 Mon Sep 17 00:00:00 2001 From: Robert Brodie Date: Sun, 28 Apr 2024 21:48:04 -0400 Subject: [PATCH 31/59] Fixed RSpec/ReturnFromStub --- spec/jira/base_spec.rb | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/spec/jira/base_spec.rb b/spec/jira/base_spec.rb index 801e99b9..44ee4806 100644 --- a/spec/jira/base_spec.rb +++ b/spec/jira/base_spec.rb @@ -233,7 +233,7 @@ class JIRA::Resource::HasManyExample < JIRA::Base # :nodoc: it 'POSTs a new record' do response = instance_double('Response', body: '{"id":"123"}') - allow(subject).to receive(:new_record?) { true } + allow(subject).to receive(:new_record?).and_return(true) expect(client).to receive(:post).with('/foo/bar', '{"foo":"bar"}').and_return(response) expect(subject.save('foo' => 'bar')).to be_truthy expect(subject.id).to eq('123') @@ -242,7 +242,7 @@ class JIRA::Resource::HasManyExample < JIRA::Base # :nodoc: it 'PUTs an existing record' do response = instance_double('Response', body: nil) - allow(subject).to receive(:new_record?) { false } + allow(subject).to receive(:new_record?).and_return(false) expect(client).to receive(:put).with('/foo/bar', '{"foo":"bar"}').and_return(response) expect(subject.save('foo' => 'bar')).to be_truthy expect(subject.expanded).to be_falsey @@ -258,7 +258,7 @@ class JIRA::Resource::HasManyExample < JIRA::Base # :nodoc: it 'returns false when an invalid field is set' do # The JIRA REST API apparently ignores fields that you aren't allowed to set manually response = instance_double('Response', body: '{"errorMessages":["blah"]}', status: 400) - allow(subject).to receive(:new_record?) { false } + allow(subject).to receive(:new_record?).and_return(false) expect(client).to receive(:put).with('/foo/bar', '{"invalid_field":"foobar"}').and_raise(JIRA::HTTPError.new(response)) expect(subject.save('invalid_field' => 'foobar')).to be_falsey @@ -284,7 +284,7 @@ class JIRA::Resource::HasManyExample < JIRA::Base # :nodoc: it 'POSTs a new record' do response = instance_double('Response', body: '{"id":"123"}') - allow(subject).to receive(:new_record?) { true } + allow(subject).to receive(:new_record?).and_return(true) expect(client).to receive(:post).with('/foo/bar', '{"foo":"bar"}').and_return(response) expect(subject.save!('foo' => 'bar')).to be_truthy expect(subject.id).to eq('123') @@ -293,7 +293,7 @@ class JIRA::Resource::HasManyExample < JIRA::Base # :nodoc: it 'PUTs an existing record' do response = instance_double('Response', body: nil) - allow(subject).to receive(:new_record?) { false } + allow(subject).to receive(:new_record?).and_return(false) expect(client).to receive(:put).with('/foo/bar', '{"foo":"bar"}').and_return(response) expect(subject.save!('foo' => 'bar')).to be_truthy expect(subject.expanded).to be_falsey @@ -301,7 +301,7 @@ class JIRA::Resource::HasManyExample < JIRA::Base # :nodoc: it 'throws an exception when an invalid field is set' do response = instance_double('Response', body: '{"errorMessages":["blah"]}', status: 400) - allow(subject).to receive(:new_record?) { false } + allow(subject).to receive(:new_record?).and_return(false) expect(client).to receive(:put).with('/foo/bar', '{"invalid_field":"foobar"}').and_raise(JIRA::HTTPError.new(response)) expect{ subject.save!('invalid_field' => 'foobar') }.to raise_error(JIRA::HTTPError) @@ -325,7 +325,7 @@ class JIRA::Resource::HasManyExample < JIRA::Base # :nodoc: describe 'delete' do before do expect(client).to receive(:delete).with('/foo/bar') - allow(subject).to receive(:url) { '/foo/bar' } + allow(subject).to receive(:url).and_return('/foo/bar') end it 'flags itself as deleted' do @@ -364,7 +364,7 @@ class JIRA::Resource::HasManyExample < JIRA::Base # :nodoc: describe 'url' do before do - allow(client).to receive(:options) { { rest_base_path: '/foo/bar' } } + allow(client).to receive(:options).and_return({ rest_base_path: '/foo/bar' }) end it 'returns self as the URL if set' do @@ -373,13 +373,13 @@ class JIRA::Resource::HasManyExample < JIRA::Base # :nodoc: end it 'returns path as the URL if set and site options is specified' do - allow(client).to receive(:options) { { site: 'http://foo' } } + allow(client).to receive(:options).and_return({ site: 'http://foo' }) attrs['self'] = 'http://foo/bar' expect(subject.url).to eq('/bar') end it 'returns path as the URL if set and site options is specified and ends with a slash' do - allow(client).to receive(:options) { { site: 'http://foo/' } } + allow(client).to receive(:options).and_return({ site: 'http://foo/' }) attrs['self'] = 'http://foo/bar' expect(subject.url).to eq('/bar') end @@ -593,12 +593,12 @@ class JIRA::Resource::BelongsToExample < JIRA::Base end it 'returns the right url' do - allow(client).to receive(:options) { { rest_base_path: '/foo' } } + allow(client).to receive(:options).and_return({ rest_base_path: '/foo' }) expect(subject.url).to eq('/foo/deadbeef/999/belongstoexample/123') end it 'can be initialized with an instance or a key value' do - allow(client).to receive(:options) { { rest_base_path: '/foo' } } + allow(client).to receive(:options).and_return({ rest_base_path: '/foo' }) subject = JIRA::Resource::BelongsToExample.new(client, attrs: { 'id' => '123' }, deadbeef_id: '987') expect(subject.url).to eq('/foo/deadbeef/987/belongstoexample/123') end From 30d191264124f42364a1f58f0c4473daaeedbdac Mon Sep 17 00:00:00 2001 From: Robert Brodie Date: Sun, 28 Apr 2024 21:48:46 -0400 Subject: [PATCH 32/59] Fixed Layout/EmptyLinesAroundBlockBody --- spec/integration/watcher_spec.rb | 1 - spec/jira/http_client_spec.rb | 3 --- spec/jira/resource/attachment_spec.rb | 4 ---- spec/jira/resource/sprint_spec.rb | 2 -- spec/jira/resource/status_spec.rb | 1 - 5 files changed, 11 deletions(-) diff --git a/spec/integration/watcher_spec.rb b/spec/integration/watcher_spec.rb index 82c6da3a..00fa199b 100644 --- a/spec/integration/watcher_spec.rb +++ b/spec/integration/watcher_spec.rb @@ -57,6 +57,5 @@ watcher.save!(user_id) end end - end end diff --git a/spec/jira/http_client_spec.rb b/spec/jira/http_client_spec.rb index 1bf39f85..5ad17eaa 100644 --- a/spec/jira/http_client_spec.rb +++ b/spec/jira/http_client_spec.rb @@ -103,12 +103,10 @@ subject(:http_conn) { basic_client.basic_auth_http_conn } it 'creates an instance of Net:HTTP for a basic auth client' do - expect(http_conn.class).to eq(Net::HTTP) end it 'the connection created has no proxy' do - http_conn expect(http_conn.proxy_address).to be_nil @@ -312,7 +310,6 @@ describe 'HttpClient#basic_auth_http_conn' do it 'creates a Net:HTTP instance for a basic auth client setting up a proxied http connection' do - expect(proxy_conn.class).to eq(Net::HTTP) expect(proxy_conn.proxy_address).to eq(proxy_client.options[:proxy_address]) diff --git a/spec/jira/resource/attachment_spec.rb b/spec/jira/resource/attachment_spec.rb index 566bf2a3..3c8290e6 100644 --- a/spec/jira/resource/attachment_spec.rb +++ b/spec/jira/resource/attachment_spec.rb @@ -82,7 +82,6 @@ attachment.download_file do |file| expect(file).to eq(file_target) end - end end @@ -156,10 +155,8 @@ merged_headers).and_return(response) bearer_attachment.save('file' => path_to_file) - end end - end describe '#save!' do @@ -213,7 +210,6 @@ merged_headers).and_return(response) bearer_attachment.save!('file' => path_to_file) - end end end diff --git a/spec/jira/resource/sprint_spec.rb b/spec/jira/resource/sprint_spec.rb index 3c066928..8ef04caf 100644 --- a/spec/jira/resource/sprint_spec.rb +++ b/spec/jira/resource/sprint_spec.rb @@ -104,7 +104,6 @@ describe '#add_issu' do context 'when an issue is passed' do - it 'posts with the issue id' do expect(client).to receive(:post).with(post_issue_path, post_issue_input.to_json) @@ -133,7 +132,6 @@ describe '#add_issues' do context 'when an issue is passed' do - it 'posts with the issue id' do expect(client).to receive(:post).with(post_issue_path, post_issue_input.to_json) diff --git a/spec/jira/resource/status_spec.rb b/spec/jira/resource/status_spec.rb index 244c2b9b..bbc6b24e 100644 --- a/spec/jira/resource/status_spec.rb +++ b/spec/jira/resource/status_spec.rb @@ -1,7 +1,6 @@ require 'spec_helper' describe JIRA::Resource::Status do - let(:client) do client = double(options: { rest_base_path: '/jira/rest/api/2' }) allow(client).to receive(:Field).and_return(JIRA::Resource::FieldFactory.new(client)) From f007500959db94eda275a99b4939f783b493d908 Mon Sep 17 00:00:00 2001 From: Robert Brodie Date: Sun, 28 Apr 2024 21:49:27 -0400 Subject: [PATCH 33/59] Fixed Naming/BlockForwarding --- lib/jira/has_many_proxy.rb | 4 ++-- lib/jira/oauth_client.rb | 4 ++-- lib/jira/resource/attachment.rb | 4 ++-- lib/jira/resource/field.rb | 4 ++-- lib/jira/resource/issue.rb | 6 +++--- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/jira/has_many_proxy.rb b/lib/jira/has_many_proxy.rb index fe86e728..4bfee913 100644 --- a/lib/jira/has_many_proxy.rb +++ b/lib/jira/has_many_proxy.rb @@ -38,7 +38,7 @@ def all end # Delegate any missing methods to the collection that this proxy wraps - def method_missing(method_name, *args, &block) - collection.send(method_name, *args, &block) + def method_missing(method_name, *args, &) + collection.send(method_name, *args, &) end end diff --git a/lib/jira/oauth_client.rb b/lib/jira/oauth_client.rb index 05d99383..749a5ac9 100644 --- a/lib/jira/oauth_client.rb +++ b/lib/jira/oauth_client.rb @@ -47,8 +47,8 @@ def init_oauth_consumer(_options) # Returns the current request token if it is set, else it creates # and sets a new token. - def request_token(options = {}, *arguments, &block) - @request_token ||= get_request_token(options, *arguments, &block) + def request_token(options = {}, *arguments, &) + @request_token ||= get_request_token(options, *arguments, &) end # Sets the request token from a given token and secret. diff --git a/lib/jira/resource/attachment.rb b/lib/jira/resource/attachment.rb index 56ff96e8..e57b6641 100644 --- a/lib/jira/resource/attachment.rb +++ b/lib/jira/resource/attachment.rb @@ -42,9 +42,9 @@ def self.meta(client) # @param [Hash] headers Any additional headers to call Jira. # @yield |file| # @yieldparam [IO] file The IO object streaming the download. - def download_file(headers = {}, &block) + def download_file(headers = {}, &) default_headers = client.options[:default_headers] - URI.open(content, default_headers.merge(headers), &block) + URI.open(content, default_headers.merge(headers), &) end # Downloads the file contents as a string object. diff --git a/lib/jira/resource/field.rb b/lib/jira/resource/field.rb index 5d4b8009..78c8a7fe 100644 --- a/lib/jira/resource/field.rb +++ b/lib/jira/resource/field.rb @@ -71,7 +71,7 @@ def respond_to?(method_name, _include_all = false) end end - def method_missing(method_name, *args, &block) + def method_missing(method_name, *args, &) if attrs.key?(method_name.to_s) attrs[method_name.to_s] else @@ -79,7 +79,7 @@ def method_missing(method_name, *args, &block) if attrs.key?(official_name) attrs[official_name] else - super(method_name, *args, &block) + super(method_name, *args, &) end end end diff --git a/lib/jira/resource/issue.rb b/lib/jira/resource/issue.rb index d5c00b8f..50eccbe3 100644 --- a/lib/jira/resource/issue.rb +++ b/lib/jira/resource/issue.rb @@ -107,7 +107,7 @@ def respond_to?(method_name, _include_all = false) end end - def method_missing(method_name, *args, &block) + def method_missing(method_name, *args, &) if attrs.key?('fields') if attrs['fields'].key?(method_name.to_s) attrs['fields'][method_name.to_s] @@ -116,11 +116,11 @@ def method_missing(method_name, *args, &block) if attrs['fields'].key?(official_name) attrs['fields'][official_name] else - super(method_name, *args, &block) + super(method_name, *args, &) end end else - super(method_name, *args, &block) + super(method_name, *args, &) end end end From 885ffbbb6b06f88160c390b8ebfe7fc391790d6d Mon Sep 17 00:00:00 2001 From: Robert Brodie Date: Sun, 28 Apr 2024 21:50:20 -0400 Subject: [PATCH 34/59] Fixed Layout/ArgumentAlignment --- spec/jira/resource/field_spec.rb | 36 ++++++++++++++++---------------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/spec/jira/resource/field_spec.rb b/spec/jira/resource/field_spec.rb index 8da29e7d..01a43a43 100644 --- a/spec/jira/resource/field_spec.rb +++ b/spec/jira/resource/field_spec.rb @@ -11,32 +11,32 @@ # info about all fields on the client allow(client.Field).to receive(:all).and_return([ described_class.new(client, - attrs: { 'id' => 'customfield_10666', 'name' => 'Priority', 'custom' => true, 'orderable' => true, 'navigable' => true, - 'searchable' => true, 'clauseNames' => ['cf[10666]', 'Priority'], 'schema' => { 'type' => 'string', 'custom' => 'com.atlassian.jira.plugin.system.customfieldtypes:select', 'customId' => 10_666 } }), + attrs: { 'id' => 'customfield_10666', 'name' => 'Priority', 'custom' => true, 'orderable' => true, 'navigable' => true, + 'searchable' => true, 'clauseNames' => ['cf[10666]', 'Priority'], 'schema' => { 'type' => 'string', 'custom' => 'com.atlassian.jira.plugin.system.customfieldtypes:select', 'customId' => 10_666 } }), described_class.new(client, - attrs: { 'id' => 'issuekey', 'name' => 'Key', 'custom' => false, 'orderable' => false, - 'navigable' => true, 'searchable' => false, 'clauseNames' => %w[id issue issuekey key] }), + attrs: { 'id' => 'issuekey', 'name' => 'Key', 'custom' => false, 'orderable' => false, + 'navigable' => true, 'searchable' => false, 'clauseNames' => %w[id issue issuekey key] }), described_class.new(client, - attrs: { 'id' => 'priority', 'name' => 'Priority', 'custom' => false, 'orderable' => true, - 'navigable' => true, 'searchable' => true, 'clauseNames' => ['priority'], 'schema' => { 'type' => 'priority', 'system' => 'priority' } }), + attrs: { 'id' => 'priority', 'name' => 'Priority', 'custom' => false, 'orderable' => true, + 'navigable' => true, 'searchable' => true, 'clauseNames' => ['priority'], 'schema' => { 'type' => 'priority', 'system' => 'priority' } }), described_class.new(client, - attrs: { 'id' => 'summary', 'name' => 'Summary', 'custom' => false, 'orderable' => true, - 'navigable' => true, 'searchable' => true, 'clauseNames' => ['summary'], 'schema' => { 'type' => 'string', 'system' => 'summary' } }), + attrs: { 'id' => 'summary', 'name' => 'Summary', 'custom' => false, 'orderable' => true, + 'navigable' => true, 'searchable' => true, 'clauseNames' => ['summary'], 'schema' => { 'type' => 'string', 'system' => 'summary' } }), described_class.new(client, - attrs: { 'id' => 'issuetype', 'name' => 'Issue Type', 'custom' => false, 'orderable' => true, - 'navigable' => true, 'searchable' => true, 'clauseNames' => %w[issuetype type], 'schema' => { 'type' => 'issuetype', 'system' => 'issuetype' } }), + attrs: { 'id' => 'issuetype', 'name' => 'Issue Type', 'custom' => false, 'orderable' => true, + 'navigable' => true, 'searchable' => true, 'clauseNames' => %w[issuetype type], 'schema' => { 'type' => 'issuetype', 'system' => 'issuetype' } }), described_class.new(client, - attrs: { 'id' => 'customfield_10111', 'name' => 'SingleWord', 'custom' => true, 'orderable' => true, - 'navigable' => true, 'searchable' => true, 'clauseNames' => ['cf[10111]', 'SingleWord'], 'schema' => { 'type' => 'string', 'custom' => 'com.atlassian.jira.plugin.system.customfieldtypes:select', 'customId' => 10_111 } }), + attrs: { 'id' => 'customfield_10111', 'name' => 'SingleWord', 'custom' => true, 'orderable' => true, + 'navigable' => true, 'searchable' => true, 'clauseNames' => ['cf[10111]', 'SingleWord'], 'schema' => { 'type' => 'string', 'custom' => 'com.atlassian.jira.plugin.system.customfieldtypes:select', 'customId' => 10_111 } }), described_class.new(client, - attrs: { 'id' => 'customfield_10222', 'name' => 'Multi Word', 'custom' => true, 'orderable' => true, - 'navigable' => true, 'searchable' => true, 'clauseNames' => ['cf[10222]', 'Multi Word'], 'schema' => { 'type' => 'string', 'custom' => 'com.atlassian.jira.plugin.system.customfieldtypes:select', 'customId' => 10_222 } }), + attrs: { 'id' => 'customfield_10222', 'name' => 'Multi Word', 'custom' => true, 'orderable' => true, + 'navigable' => true, 'searchable' => true, 'clauseNames' => ['cf[10222]', 'Multi Word'], 'schema' => { 'type' => 'string', 'custom' => 'com.atlassian.jira.plugin.system.customfieldtypes:select', 'customId' => 10_222 } }), described_class.new(client, - attrs: { 'id' => 'customfield_10333', 'name' => 'Why/N@t', 'custom' => true, 'orderable' => true, - 'navigable' => true, 'searchable' => true, 'clauseNames' => ['cf[10333]', 'Why/N@t'], 'schema' => { 'type' => 'string', 'custom' => 'com.atlassian.jira.plugin.system.customfieldtypes:select', 'customId' => 10_333 } }), + attrs: { 'id' => 'customfield_10333', 'name' => 'Why/N@t', 'custom' => true, 'orderable' => true, + 'navigable' => true, 'searchable' => true, 'clauseNames' => ['cf[10333]', 'Why/N@t'], 'schema' => { 'type' => 'string', 'custom' => 'com.atlassian.jira.plugin.system.customfieldtypes:select', 'customId' => 10_333 } }), described_class.new(client, - attrs: { 'id' => 'customfield_10444', 'name' => 'SingleWord', 'custom' => true, 'orderable' => true, - 'navigable' => true, 'searchable' => true, 'clauseNames' => ['cf[10444]', 'SingleWord'], 'schema' => { 'type' => 'string', 'custom' => 'com.atlassian.jira.plugin.system.customfieldtypes:select', 'customId' => 10_444 } }) + attrs: { 'id' => 'customfield_10444', 'name' => 'SingleWord', 'custom' => true, 'orderable' => true, + 'navigable' => true, 'searchable' => true, 'clauseNames' => ['cf[10444]', 'SingleWord'], 'schema' => { 'type' => 'string', 'custom' => 'com.atlassian.jira.plugin.system.customfieldtypes:select', 'customId' => 10_444 } }) ]) client end From 3d166ba60ef1f457f18dd42a8e8c63efa1ae39e8 Mon Sep 17 00:00:00 2001 From: Robert Brodie Date: Sun, 28 Apr 2024 21:51:47 -0400 Subject: [PATCH 35/59] Fixed Style/BlockDelimiters --- lib/jira/resource/issue.rb | 8 ++++---- spec/jira/base_spec.rb | 4 ++-- spec/jira/client_spec.rb | 8 ++++---- spec/jira/resource/attachment_spec.rb | 8 ++++---- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/lib/jira/resource/issue.rb b/lib/jira/resource/issue.rb index 50eccbe3..3f21e6a8 100644 --- a/lib/jira/resource/issue.rb +++ b/lib/jira/resource/issue.rb @@ -52,8 +52,8 @@ def self.jql(client, jql, options = { fields: nil, start_at: nil, max_results: n validate_query: true }) url = client.options[:rest_base_path] + "/search?jql=#{CGI.escape(jql)}" - url << "&fields=#{options[:fields].map { |value| - CGI.escape(client.Field.name_to_id(value)) }.join(',')}" if options[:fields] + url << "&fields=#{options[:fields].map do |value| + CGI.escape(client.Field.name_to_id(value)) end.join(',')}" if options[:fields] url << "&startAt=#{CGI.escape(options[:start_at].to_s)}" if options[:start_at] url << "&maxResults=#{CGI.escape(options[:max_results].to_s)}" if options[:max_results] url << '&validateQuery=false' if options[:validate_query] === false @@ -99,8 +99,8 @@ def editmeta end def respond_to?(method_name, _include_all = false) - if attrs.key?('fields') && [method_name.to_s, client.Field.name_to_id(method_name)].any? { |k| - attrs['fields'].key?(k) } + if attrs.key?('fields') && [method_name.to_s, client.Field.name_to_id(method_name)].any? do |k| + attrs['fields'].key?(k) end true else super(method_name) diff --git a/spec/jira/base_spec.rb b/spec/jira/base_spec.rb index 44ee4806..220c9797 100644 --- a/spec/jira/base_spec.rb +++ b/spec/jira/base_spec.rb @@ -587,9 +587,9 @@ class JIRA::Resource::BelongsToExample < JIRA::Base end it 'raises an exception when initialized without a belongs_to instance' do - expect{ + expect do JIRA::Resource::BelongsToExample.new(client, attrs: { 'id' => '123' }) - }.to raise_exception(ArgumentError, 'Required option :deadbeef missing') + end.to raise_exception(ArgumentError, 'Required option :deadbeef missing') end it 'returns the right url' do diff --git a/spec/jira/client_spec.rb b/spec/jira/client_spec.rb index bf6894a3..6e677cf7 100644 --- a/spec/jira/client_spec.rb +++ b/spec/jira/client_spec.rb @@ -67,12 +67,12 @@ let(:options) { { use_client_cert: true } } it 'raises an ArgumentError' do - expect { - subject }.to raise_exception(ArgumentError, + expect do + subject end.to raise_exception(ArgumentError, 'Options: :cert_path or :ssl_client_cert must be set when :use_client_cert is true') options[:ssl_client_cert] = '' - expect { - subject }.to raise_exception(ArgumentError, + expect do + subject end.to raise_exception(ArgumentError, 'Options: :key_path or :ssl_client_key must be set when :use_client_cert is true') end end diff --git a/spec/jira/resource/attachment_spec.rb b/spec/jira/resource/attachment_spec.rb index 3c8290e6..286d9693 100644 --- a/spec/jira/resource/attachment_spec.rb +++ b/spec/jira/resource/attachment_spec.rb @@ -140,8 +140,8 @@ ) end - let(:default_headers_given) { - { 'authorization' => 'Bearer 83CF8B609DE60036A8277BD0E96135751BBC07EB234256D4B65B893360651BF2' } } + let(:default_headers_given) do + { 'authorization' => 'Bearer 83CF8B609DE60036A8277BD0E96135751BBC07EB234256D4B65B893360651BF2' } end let(:bearer_client) do JIRA::Client.new(username: 'username', password: 'password', auth_type: :basic, use_ssl: false, default_headers: default_headers_given ) @@ -195,8 +195,8 @@ ) end - let(:default_headers_given) { - { 'authorization' => 'Bearer 83CF8B609DE60036A8277BD0E96135751BBC07EB234256D4B65B893360651BF2' } } + let(:default_headers_given) do + { 'authorization' => 'Bearer 83CF8B609DE60036A8277BD0E96135751BBC07EB234256D4B65B893360651BF2' } end let(:bearer_client) do JIRA::Client.new(username: 'username', password: 'password', auth_type: :basic, use_ssl: false, default_headers: default_headers_given ) From 9efb6a48f6ae4a3ff4b166c1695626adf12c8e52 Mon Sep 17 00:00:00 2001 From: Robert Brodie Date: Sun, 28 Apr 2024 21:52:25 -0400 Subject: [PATCH 36/59] Fixed Layout/BlockEndNewline --- lib/jira/resource/issue.rb | 6 ++++-- spec/jira/client_spec.rb | 6 ++++-- spec/jira/resource/attachment_spec.rb | 6 ++++-- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/lib/jira/resource/issue.rb b/lib/jira/resource/issue.rb index 3f21e6a8..51742d59 100644 --- a/lib/jira/resource/issue.rb +++ b/lib/jira/resource/issue.rb @@ -53,7 +53,8 @@ def self.jql(client, jql, options = { fields: nil, start_at: nil, max_results: n url = client.options[:rest_base_path] + "/search?jql=#{CGI.escape(jql)}" url << "&fields=#{options[:fields].map do |value| - CGI.escape(client.Field.name_to_id(value)) end.join(',')}" if options[:fields] + CGI.escape(client.Field.name_to_id(value)) +end.join(',')}" if options[:fields] url << "&startAt=#{CGI.escape(options[:start_at].to_s)}" if options[:start_at] url << "&maxResults=#{CGI.escape(options[:max_results].to_s)}" if options[:max_results] url << '&validateQuery=false' if options[:validate_query] === false @@ -100,7 +101,8 @@ def editmeta def respond_to?(method_name, _include_all = false) if attrs.key?('fields') && [method_name.to_s, client.Field.name_to_id(method_name)].any? do |k| - attrs['fields'].key?(k) end + attrs['fields'].key?(k) +end true else super(method_name) diff --git a/spec/jira/client_spec.rb b/spec/jira/client_spec.rb index 6e677cf7..ded48bc9 100644 --- a/spec/jira/client_spec.rb +++ b/spec/jira/client_spec.rb @@ -68,11 +68,13 @@ it 'raises an ArgumentError' do expect do - subject end.to raise_exception(ArgumentError, + subject +end.to raise_exception(ArgumentError, 'Options: :cert_path or :ssl_client_cert must be set when :use_client_cert is true') options[:ssl_client_cert] = '' expect do - subject end.to raise_exception(ArgumentError, + subject +end.to raise_exception(ArgumentError, 'Options: :key_path or :ssl_client_key must be set when :use_client_cert is true') end end diff --git a/spec/jira/resource/attachment_spec.rb b/spec/jira/resource/attachment_spec.rb index 286d9693..6fc8f356 100644 --- a/spec/jira/resource/attachment_spec.rb +++ b/spec/jira/resource/attachment_spec.rb @@ -141,7 +141,8 @@ end let(:default_headers_given) do - { 'authorization' => 'Bearer 83CF8B609DE60036A8277BD0E96135751BBC07EB234256D4B65B893360651BF2' } end + { 'authorization' => 'Bearer 83CF8B609DE60036A8277BD0E96135751BBC07EB234256D4B65B893360651BF2' } +end let(:bearer_client) do JIRA::Client.new(username: 'username', password: 'password', auth_type: :basic, use_ssl: false, default_headers: default_headers_given ) @@ -196,7 +197,8 @@ end let(:default_headers_given) do - { 'authorization' => 'Bearer 83CF8B609DE60036A8277BD0E96135751BBC07EB234256D4B65B893360651BF2' } end + { 'authorization' => 'Bearer 83CF8B609DE60036A8277BD0E96135751BBC07EB234256D4B65B893360651BF2' } +end let(:bearer_client) do JIRA::Client.new(username: 'username', password: 'password', auth_type: :basic, use_ssl: false, default_headers: default_headers_given ) From b341e3c4d0ae1d82ebf8333711d2e63b2eef6c2a Mon Sep 17 00:00:00 2001 From: Robert Brodie Date: Sun, 28 Apr 2024 21:57:06 -0400 Subject: [PATCH 37/59] Fixed Layout/MultilineMethodCallIndentation --- spec/jira/client_spec.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/spec/jira/client_spec.rb b/spec/jira/client_spec.rb index ded48bc9..d2b67c39 100644 --- a/spec/jira/client_spec.rb +++ b/spec/jira/client_spec.rb @@ -156,7 +156,7 @@ .to_return(status: 200, body: '[]', headers: {}) stub_request(:get, 'https://localhost:2990/jira/rest/api/2/project') - .with(headers: { 'Authorization' => "Basic #{Base64.strict_encode64('foo:badpassword').chomp}" }) + .with(headers: { 'Authorization' => "Basic #{Base64.strict_encode64('foo:badpassword').chomp}" }) .to_return(status: 401, headers: {}) end @@ -245,8 +245,8 @@ before do stub_request(:get, 'https://localhost:2990/jira/rest/api/2/project') - .with(headers: { 'Authorization' => /JWT .+/ }) - .to_return(status: 200, body: '[]', headers: {}) + .with(headers: { 'Authorization' => /JWT .+/ }) + .to_return(status: 200, body: '[]', headers: {}) end include_examples 'Client Common Tests' @@ -261,8 +261,8 @@ context 'with a incorrect jwt key' do before do stub_request(:get, 'https://localhost:2990/jira/rest/api/2/project') - .with(headers: { 'Authorization' => /JWT .+/ }) - .to_return(status: 401, body: '[]', headers: {}) + .with(headers: { 'Authorization' => /JWT .+/ }) + .to_return(status: 401, body: '[]', headers: {}) end it 'is not authenticated' do From 98affed335a6aa60f76e610030193f20204b042d Mon Sep 17 00:00:00 2001 From: Robert Brodie Date: Sun, 28 Apr 2024 21:57:51 -0400 Subject: [PATCH 38/59] Fixed Lint/RedundantStringCoercion --- lib/jira/base.rb | 4 ++-- spec/support/shared_examples/integration.rb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/jira/base.rb b/lib/jira/base.rb index ab2141ee..f51063f0 100644 --- a/lib/jira/base.rb +++ b/lib/jira/base.rb @@ -143,7 +143,7 @@ def self.collection_path(client, prefix = '/') # JIRA::Resource::Comment.singular_path('456','/issue/123/') # # => /jira/rest/api/2/issue/123/comment/456 def self.singular_path(client, key, prefix = '/') - "#{collection_path(client, prefix)}/#{key.to_s}" + "#{collection_path(client, prefix)}/#{key}" end # Returns the attribute name of the attribute used for find. @@ -423,7 +423,7 @@ def url prefix = '/' unless self.class.belongs_to_relationships.empty? prefix = self.class.belongs_to_relationships.inject(prefix) do |prefix_so_far, relationship| - "#{prefix_so_far.to_s}#{relationship.to_s}/#{send("#{relationship}_id").to_s}/" + "#{prefix_so_far}#{relationship}/#{send("#{relationship}_id")}/" end end if @attrs['self'] diff --git a/spec/support/shared_examples/integration.rb b/spec/support/shared_examples/integration.rb index e2195087..c7ef1f27 100644 --- a/spec/support/shared_examples/integration.rb +++ b/spec/support/shared_examples/integration.rb @@ -16,7 +16,7 @@ def get_mock_from_path(method, options = {}) end file_path = url.sub(client.options[:rest_base_path], '') file_path = "#{file_path}.#{options[:suffix]}" if options[:suffix] - file_path = "#{file_path}.#{method.to_s}" unless method == :get + file_path = "#{file_path}.#{method}" unless method == :get value_if_not_found = options.key?(:value_if_not_found) ? options[:value_if_not_found] : false get_mock_response("#{file_path}.json", value_if_not_found) end From 5c9ccfc524aab182a4af0d5b2f5b71f850c6aa74 Mon Sep 17 00:00:00 2001 From: Robert Brodie Date: Sun, 28 Apr 2024 21:59:39 -0400 Subject: [PATCH 39/59] Fixed Style/MultilineIfModifier --- lib/jira/client.rb | 24 ++++++++++++++++-------- lib/jira/resource/issue.rb | 6 ++++-- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/lib/jira/client.rb b/lib/jira/client.rb index 76e54bbf..bfbce300 100644 --- a/lib/jira/client.rb +++ b/lib/jira/client.rb @@ -122,14 +122,20 @@ def initialize(options = {}) raise ArgumentError, "Unknown option(s) given: #{unknown_options}" unless unknown_options.empty? if options[:use_client_cert] - @options[:ssl_client_cert] = -OpenSSL::X509::Certificate.new(File.read(@options[:cert_path])) if @options[:cert_path] + if @options[:cert_path] + @options[:ssl_client_cert] = +OpenSSL::X509::Certificate.new(File.read(@options[:cert_path])) + end @options[:ssl_client_key] = OpenSSL::PKey::RSA.new(File.read(@options[:key_path])) if @options[:key_path] - raise ArgumentError, - 'Options: :cert_path or :ssl_client_cert must be set when :use_client_cert is true' unless @options[:ssl_client_cert] - raise ArgumentError, - 'Options: :key_path or :ssl_client_key must be set when :use_client_cert is true' unless @options[:ssl_client_key] + unless @options[:ssl_client_cert] + raise ArgumentError, + 'Options: :cert_path or :ssl_client_cert must be set when :use_client_cert is true' + end + unless @options[:ssl_client_key] + raise ArgumentError, + 'Options: :key_path or :ssl_client_key must be set when :use_client_cert is true' + end end case options[:auth_type] @@ -141,8 +147,10 @@ def initialize(options = {}) when :basic @request_client = HttpClient.new(@options) when :cookie - raise ArgumentError, - 'Options: :use_cookies must be true for :cookie authorization type' if @options.key?(:use_cookies) && !@options[:use_cookies] + if @options.key?(:use_cookies) && !@options[:use_cookies] + raise ArgumentError, + 'Options: :use_cookies must be true for :cookie authorization type' + end @options[:use_cookies] = true @request_client = HttpClient.new(@options) diff --git a/lib/jira/resource/issue.rb b/lib/jira/resource/issue.rb index 51742d59..e845541d 100644 --- a/lib/jira/resource/issue.rb +++ b/lib/jira/resource/issue.rb @@ -52,9 +52,11 @@ def self.jql(client, jql, options = { fields: nil, start_at: nil, max_results: n validate_query: true }) url = client.options[:rest_base_path] + "/search?jql=#{CGI.escape(jql)}" - url << "&fields=#{options[:fields].map do |value| + if options[:fields] + url << "&fields=#{options[:fields].map do |value| CGI.escape(client.Field.name_to_id(value)) -end.join(',')}" if options[:fields] +end.join(',')}" + end url << "&startAt=#{CGI.escape(options[:start_at].to_s)}" if options[:start_at] url << "&maxResults=#{CGI.escape(options[:max_results].to_s)}" if options[:max_results] url << '&validateQuery=false' if options[:validate_query] === false From 9b3d95ba9319f7cab584c0f30f570579e0d8bfd4 Mon Sep 17 00:00:00 2001 From: Robert Brodie Date: Sun, 28 Apr 2024 22:01:04 -0400 Subject: [PATCH 40/59] Fixed Layout/SpaceAroundOperators --- spec/jira/resource/attachment_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/jira/resource/attachment_spec.rb b/spec/jira/resource/attachment_spec.rb index 6fc8f356..34cbdcad 100644 --- a/spec/jira/resource/attachment_spec.rb +++ b/spec/jira/resource/attachment_spec.rb @@ -148,7 +148,7 @@ default_headers: default_headers_given ) end let(:merged_headers) do - { 'Accept'=>'application/json', 'X-Atlassian-Token'=>'nocheck' }.merge(default_headers_given) + { 'Accept' => 'application/json', 'X-Atlassian-Token' => 'nocheck' }.merge(default_headers_given) end it 'passes the custom headers' do @@ -204,7 +204,7 @@ default_headers: default_headers_given ) end let(:merged_headers) do - { 'Accept'=>'application/json', 'X-Atlassian-Token'=>'nocheck' }.merge(default_headers_given) + { 'Accept' => 'application/json', 'X-Atlassian-Token' => 'nocheck' }.merge(default_headers_given) end it 'passes the custom headers' do From 93e9fc4f04943d1b881e761b8b1306c595d8978f Mon Sep 17 00:00:00 2001 From: Robert Brodie Date: Sun, 28 Apr 2024 22:01:34 -0400 Subject: [PATCH 41/59] Fixed Layout/TrailingEmptyLines --- lib/jira/jwt_client.rb | 2 +- lib/jira/request_client.rb | 2 +- spec/jira/request_client_spec.rb | 2 +- spec/jira/resource/status_spec.rb | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/jira/jwt_client.rb b/lib/jira/jwt_client.rb index c5e7ea9b..1fa441ef 100644 --- a/lib/jira/jwt_client.rb +++ b/lib/jira/jwt_client.rb @@ -40,4 +40,4 @@ def build_jwt(url) JWT.encode claim, @options[:shared_secret] end end -end \ No newline at end of file +end diff --git a/lib/jira/request_client.rb b/lib/jira/request_client.rb index 3091e8fc..5a7d37d4 100644 --- a/lib/jira/request_client.rb +++ b/lib/jira/request_client.rb @@ -32,4 +32,4 @@ def make_multipart_request(*args) raise NotImplementedError end end -end \ No newline at end of file +end diff --git a/spec/jira/request_client_spec.rb b/spec/jira/request_client_spec.rb index e4351c7b..a338eb0f 100644 --- a/spec/jira/request_client_spec.rb +++ b/spec/jira/request_client_spec.rb @@ -38,4 +38,4 @@ end end end -end \ No newline at end of file +end diff --git a/spec/jira/resource/status_spec.rb b/spec/jira/resource/status_spec.rb index bbc6b24e..de2652fe 100644 --- a/spec/jira/resource/status_spec.rb +++ b/spec/jira/resource/status_spec.rb @@ -18,4 +18,4 @@ expect(subject.status_category.name).to eq('To Do') end end -end \ No newline at end of file +end From 6e00a0e50f6663a5c6ef303d91350ac9e0a38e4d Mon Sep 17 00:00:00 2001 From: Robert Brodie Date: Sun, 28 Apr 2024 22:02:30 -0400 Subject: [PATCH 42/59] Fixed Naming/HeredocDelimiterCase --- spec/jira/resource/board_spec.rb | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/spec/jira/resource/board_spec.rb b/spec/jira/resource/board_spec.rb index f04131bd..6ce0b275 100644 --- a/spec/jira/resource/board_spec.rb +++ b/spec/jira/resource/board_spec.rb @@ -30,7 +30,7 @@ class JIRAResourceDelegation < SimpleDelegator # :nodoc: it 'finds all boards' do response = double - api_json = < Date: Sun, 28 Apr 2024 22:03:21 -0400 Subject: [PATCH 43/59] Fixed Style/ArgumentsForwarding --- lib/jira/has_many_proxy.rb | 4 ++-- lib/jira/oauth_client.rb | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/jira/has_many_proxy.rb b/lib/jira/has_many_proxy.rb index 4bfee913..6e4764f9 100644 --- a/lib/jira/has_many_proxy.rb +++ b/lib/jira/has_many_proxy.rb @@ -38,7 +38,7 @@ def all end # Delegate any missing methods to the collection that this proxy wraps - def method_missing(method_name, *args, &) - collection.send(method_name, *args, &) + def method_missing(method_name, ...) + collection.send(method_name, ...) end end diff --git a/lib/jira/oauth_client.rb b/lib/jira/oauth_client.rb index 749a5ac9..4a1c47c5 100644 --- a/lib/jira/oauth_client.rb +++ b/lib/jira/oauth_client.rb @@ -47,8 +47,8 @@ def init_oauth_consumer(_options) # Returns the current request token if it is set, else it creates # and sets a new token. - def request_token(options = {}, *arguments, &) - @request_token ||= get_request_token(options, *arguments, &) + def request_token(options = {}, ...) + @request_token ||= get_request_token(options, ...) end # Sets the request token from a given token and secret. From 06dac0103ea2eeab1173b396298250d84c4bd077 Mon Sep 17 00:00:00 2001 From: Robert Brodie Date: Sun, 28 Apr 2024 22:07:40 -0400 Subject: [PATCH 44/59] Fixed Style issues --- lib/jira/base.rb | 14 +++++++------- lib/jira/http_client.rb | 4 ++-- lib/jira/resource/webhook.rb | 2 +- lib/jira/version.rb | 2 +- lib/tasks/generate.rake | 2 +- spec/support/clients_helper.rb | 6 ++---- spec/support/shared_examples/integration.rb | 8 ++++---- 7 files changed, 18 insertions(+), 20 deletions(-) diff --git a/lib/jira/base.rb b/lib/jira/base.rb index f51063f0..f9f79c63 100644 --- a/lib/jira/base.rb +++ b/lib/jira/base.rb @@ -195,7 +195,7 @@ def self.parse_json(string) # :nodoc: # # => Looks for {"foo":{"bar":{"baz":{"child":{}}}}} def self.has_one(resource, options = {}) attribute_key = options[:attribute_key] || resource.to_s - child_class = options[:class] || ("JIRA::Resource::#{resource.to_s.classify}").constantize + child_class = options[:class] || "JIRA::Resource::#{resource.to_s.classify}".constantize define_method(resource) do attribute = maybe_nested_attribute(attribute_key, options[:nested_under]) return nil unless attribute @@ -247,7 +247,7 @@ def self.has_one(resource, options = {}) # # => Looks for {"foo":{"bar":{"baz":{"children":{}}}}} def self.has_many(collection, options = {}) attribute_key = options[:attribute_key] || collection.to_s - child_class = options[:class] || ("JIRA::Resource::#{collection.to_s.classify}").constantize + child_class = options[:class] || "JIRA::Resource::#{collection.to_s.classify}".constantize self_class_basename = name.split('::').last.downcase.to_sym define_method(collection) do child_class_options = { self_class_basename => self } @@ -382,10 +382,10 @@ def save(attrs, path = url) # Sets the attributes hash from a HTTPResponse object from JIRA if it is # not nil or is not a json response. def set_attrs_from_response(response) - unless response.body.nil? || (response.body.length < 2) + return if response.body.nil? || (response.body.length < 2) json = self.class.parse_json(response.body) set_attrs(json) - end + end # Set the current attributes from a hash. If clobber is true, any existing @@ -501,10 +501,10 @@ def url_with_query_params(url, query_params) end def self.url_with_query_params(url, query_params) - if !query_params.empty? - "#{url}?#{hash_to_query_string query_params}" - else + if query_params.empty? url + else + "#{url}?#{hash_to_query_string query_params}" end end diff --git a/lib/jira/http_client.rb b/lib/jira/http_client.rb index 17a98ccf..53ad8ae3 100644 --- a/lib/jira/http_client.rb +++ b/lib/jira/http_client.rb @@ -98,13 +98,13 @@ def request_path(url) def store_cookies(response) cookies = response.get_fields('set-cookie') - if cookies + return unless cookies cookies.each do |cookie| data = CGI::Cookie.parse(cookie) data.delete('Path') @cookies.merge!(data) end - end + end def add_cookies(request) diff --git a/lib/jira/resource/webhook.rb b/lib/jira/resource/webhook.rb index 31b5f5ab..6c6c2fd0 100644 --- a/lib/jira/resource/webhook.rb +++ b/lib/jira/resource/webhook.rb @@ -6,7 +6,7 @@ class WebhookFactory < JIRA::BaseFactory # :nodoc: end class Webhook < JIRA::Base - REST_BASE_PATH = '/rest/webhooks/1.0'.freeze + REST_BASE_PATH = '/rest/webhooks/1.0' def self.endpoint_name 'webhook' diff --git a/lib/jira/version.rb b/lib/jira/version.rb index 2584af7e..1f48c2ee 100644 --- a/lib/jira/version.rb +++ b/lib/jira/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module JIRA - VERSION = '2.3.0'.freeze + VERSION = '2.3.0' end diff --git a/lib/tasks/generate.rake b/lib/tasks/generate.rake index fb64f560..8b20d142 100644 --- a/lib/tasks/generate.rake +++ b/lib/tasks/generate.rake @@ -13,7 +13,7 @@ namespace :jira do task :generate_public_cert do puts "Executing 'openssl req -x509 -nodes -newkey rsa:1024 -sha1 -keyout rsakey.pem -out rsacert.pem'" system('openssl req -x509 -subj "/C=US/ST=New York/L=New York/O=SUMO Heavy Industries/CN=www.sumoheavy.com" -nodes -newkey rsa:1024 -sha1 -keyout rsakey.pem -out rsacert.pem') - puts "Done. The RSA-SHA1 private keyfile is in the current directory: \'rsakey.pem\'." + puts "Done. The RSA-SHA1 private keyfile is in the current directory: 'rsakey.pem'." puts 'You will need to copy the following certificate into your application link configuration in Jira:' system('cat rsacert.pem') end diff --git a/spec/support/clients_helper.rb b/spec/support/clients_helper.rb index c022b0fe..344b5302 100644 --- a/spec/support/clients_helper.rb +++ b/spec/support/clients_helper.rb @@ -1,5 +1,5 @@ module ClientsHelper - def with_each_client + def with_each_client(&block) clients = {} oauth_client = JIRA::Client.new(consumer_key: 'foo', consumer_secret: 'bar') @@ -9,8 +9,6 @@ def with_each_client basic_client = JIRA::Client.new(username: 'foo', password: 'bar', auth_type: :basic, use_ssl: false) clients['http://localhost:2990'] = basic_client - clients.each do |site_url, client| - yield site_url, client - end + clients.each(&block) end end diff --git a/spec/support/shared_examples/integration.rb b/spec/support/shared_examples/integration.rb index c7ef1f27..ae55f719 100644 --- a/spec/support/shared_examples/integration.rb +++ b/spec/support/shared_examples/integration.rb @@ -47,11 +47,11 @@ def build_receiver shared_examples 'a resource' do it 'gracefully handles non-json responses' do - if defined? target - subject = target + subject = if defined? target + target else - subject = client.send(class_basename).build(described_class.key_attribute.to_s => '99999') - end + client.send(class_basename).build(described_class.key_attribute.to_s => '99999') + end stub_request(:put, site_url + subject.url) .to_return(status: 405, body: 'Some HTML') expect(subject.save('foo' => 'bar')).to be_falsey From 6cec323d66c9255bb462ea653bd17a0e9573372a Mon Sep 17 00:00:00 2001 From: Robert Brodie Date: Sun, 28 Apr 2024 22:10:58 -0400 Subject: [PATCH 45/59] Fix Style/RedundantFreeze after merge conflicts --- lib/jira/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/jira/version.rb b/lib/jira/version.rb index ec87018b..dad2941f 100644 --- a/lib/jira/version.rb +++ b/lib/jira/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module JIRA - VERSION = '3.0.0'.freeze + VERSION = '3.0.0' end From 3f252977cddeadf1b3baa30f5e69f20e83b254f1 Mon Sep 17 00:00:00 2001 From: Robert Brodie Date: Sun, 28 Apr 2024 22:13:24 -0400 Subject: [PATCH 46/59] Fix RSpec issues --- spec/integration/issue_spec.rb | 2 ++ spec/integration/rapidview_spec.rb | 1 + spec/jira/base_spec.rb | 1 + spec/jira/client_spec.rb | 2 +- spec/jira/resource/attachment_spec.rb | 1 + spec/jira/resource/board_spec.rb | 2 +- spec/jira/resource/issue_spec.rb | 2 ++ 7 files changed, 9 insertions(+), 2 deletions(-) diff --git a/spec/integration/issue_spec.rb b/spec/integration/issue_spec.rb index 8a7cbed0..ba910416 100644 --- a/spec/integration/issue_spec.rb +++ b/spec/integration/issue_spec.rb @@ -50,8 +50,10 @@ stub_request(:get, "#{site_url}/jira/rest/api/2/search?expand=transitions.fields&maxResults=1000&startAt=11") .to_return(status: 200, body: get_mock_response('empty_issues.json')) end + it_behaves_like 'a resource with a collection GET endpoint' end + it_behaves_like 'a resource with a DELETE endpoint' it_behaves_like 'a resource with a POST endpoint' it_behaves_like 'a resource with a PUT endpoint' diff --git a/spec/integration/rapidview_spec.rb b/spec/integration/rapidview_spec.rb index e62f0098..b3ccfbc7 100644 --- a/spec/integration/rapidview_spec.rb +++ b/spec/integration/rapidview_spec.rb @@ -30,6 +30,7 @@ stub_request(:get, "#{site_url}/jira/rest/greenhopper/1.0/rapidview") .to_return(status: 200, body: get_mock_response('rapidview.json')) end + it_behaves_like 'a resource with a collection GET endpoint' end diff --git a/spec/jira/base_spec.rb b/spec/jira/base_spec.rb index 220c9797..467ae41d 100644 --- a/spec/jira/base_spec.rb +++ b/spec/jira/base_spec.rb @@ -44,6 +44,7 @@ class JIRA::Resource::HasManyExample < JIRA::Base # :nodoc: it 'responds to client' do expect(decorated.respond_to?(:client)).to eq(true) end + it 'does not raise an error' do expect do decorated.respond_to?(:client) diff --git a/spec/jira/client_spec.rb b/spec/jira/client_spec.rb index d2b67c39..230e5025 100644 --- a/spec/jira/client_spec.rb +++ b/spec/jira/client_spec.rb @@ -28,7 +28,7 @@ expect(subject).to receive(:merge_default_headers).exactly(3).times.with({}) # response for merging headers for http methods with body - expect(subject).to receive(:merge_default_headers).exactly(2).times.with(content_type_header) + expect(subject).to receive(:merge_default_headers).twice.with(content_type_header) %i[delete get head].each { |method| subject.send(method, '/path', {}) } %i[post put].each { |method| subject.send(method, '/path', '', content_type_header) } diff --git a/spec/jira/resource/attachment_spec.rb b/spec/jira/resource/attachment_spec.rb index 34cbdcad..1fc31da2 100644 --- a/spec/jira/resource/attachment_spec.rb +++ b/spec/jira/resource/attachment_spec.rb @@ -131,6 +131,7 @@ expect(attachment.mimeType).to eq file_mime_type expect(attachment.size).to eq file_size end + context 'when using custom client headers' do subject(:bearer_attachment) do described_class.new( diff --git a/spec/jira/resource/board_spec.rb b/spec/jira/resource/board_spec.rb index 6ce0b275..229b174f 100644 --- a/spec/jira/resource/board_spec.rb +++ b/spec/jira/resource/board_spec.rb @@ -220,6 +220,6 @@ class JIRAResourceDelegation < SimpleDelegator # :nodoc: allow(board).to receive(:id).and_return(84) expect(client).to receive(:get).with('/rest/agile/1.0/board/84/configuration').and_return(response) expect(client).to receive(:BoardConfiguration).and_return(JIRA::Resource::BoardConfigurationFactory.new(client)) - expect(board.configuration).not_to be(nil) + expect(board.configuration).not_to be_nil end end diff --git a/spec/jira/resource/issue_spec.rb b/spec/jira/resource/issue_spec.rb index 4828d44e..2943ab1d 100644 --- a/spec/jira/resource/issue_spec.rb +++ b/spec/jira/resource/issue_spec.rb @@ -23,9 +23,11 @@ class JIRAResourceDelegation < SimpleDelegator # :nodoc: issue = described_class.find(client, 101) @decorated = JIRAResourceDelegation.new(issue) end + it 'responds to key' do expect(@decorated.respond_to?(:key)).to eq(true) end + it 'does not raise an error' do expect do @issue.respond_to?(:project) From 3d04164eca3d46d6c3d7f7150bff47512110410d Mon Sep 17 00:00:00 2001 From: Robert Brodie Date: Sun, 28 Apr 2024 22:14:07 -0400 Subject: [PATCH 47/59] Fix Naming/RescuedExceptionsVariableName --- lib/jira/base.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/jira/base.rb b/lib/jira/base.rb index f9f79c63..e7e8f86c 100644 --- a/lib/jira/base.rb +++ b/lib/jira/base.rb @@ -363,14 +363,14 @@ def save!(attrs, path = nil) def save(attrs, path = url) begin save_status = save!(attrs, path) - rescue JIRA::HTTPError => exception + rescue JIRA::HTTPError => e begin - set_attrs_from_response(exception.response) # Merge error status generated by JIRA REST API + set_attrs_from_response(e.response) # Merge error status generated by JIRA REST API rescue JSON::ParserError => parse_exception set_attrs('exception' => { - 'class' => exception.response.class.name, - 'code' => exception.response.code, - 'message' => exception.response.message + 'class' => e.response.class.name, + 'code' => e.response.code, + 'message' => e.response.message }) end # raise exception From 821c25b2a0dd8b52fcb42420fe18fde9a6d2f331 Mon Sep 17 00:00:00 2001 From: Robert Brodie Date: Sun, 28 Apr 2024 22:17:12 -0400 Subject: [PATCH 48/59] Fix Layout issues --- lib/jira-ruby.rb | 2 +- lib/jira/base.rb | 6 ++--- lib/jira/client.rb | 2 +- lib/jira/http_client.rb | 12 +++++----- lib/jira/resource/attachment.rb | 2 +- lib/jira/resource/field.rb | 2 +- lib/jira/resource/issue.rb | 8 +++---- spec/jira/base_spec.rb | 10 ++++---- spec/jira/client_spec.rb | 12 +++++----- spec/jira/request_client_spec.rb | 4 ++-- spec/jira/resource/attachment_spec.rb | 26 ++++++++++----------- spec/jira/resource/sprint_spec.rb | 4 ++-- spec/support/shared_examples/integration.rb | 2 +- 13 files changed, 46 insertions(+), 46 deletions(-) diff --git a/lib/jira-ruby.rb b/lib/jira-ruby.rb index c0547463..a5ccd060 100644 --- a/lib/jira-ruby.rb +++ b/lib/jira-ruby.rb @@ -5,7 +5,7 @@ require 'active_support' require 'active_support/inflector' ActiveSupport::Inflector.inflections do |inflector| - inflector.singular /status$/, 'status' + inflector.singular(/status$/, 'status') end require 'jira/base' diff --git a/lib/jira/base.rb b/lib/jira/base.rb index e7e8f86c..fe78c79f 100644 --- a/lib/jira/base.rb +++ b/lib/jira/base.rb @@ -383,9 +383,9 @@ def save(attrs, path = url) # not nil or is not a json response. def set_attrs_from_response(response) return if response.body.nil? || (response.body.length < 2) - json = self.class.parse_json(response.body) - set_attrs(json) - + json = self.class.parse_json(response.body) + set_attrs(json) + end # Set the current attributes from a hash. If clobber is true, any existing diff --git a/lib/jira/client.rb b/lib/jira/client.rb index aa14c800..a4a206ca 100644 --- a/lib/jira/client.rb +++ b/lib/jira/client.rb @@ -124,7 +124,7 @@ def initialize(options = {}) if options[:use_client_cert] if @options[:cert_path] @options[:ssl_client_cert] = -OpenSSL::X509::Certificate.new(File.read(@options[:cert_path])) + OpenSSL::X509::Certificate.new(File.read(@options[:cert_path])) end @options[:ssl_client_key] = OpenSSL::PKey::RSA.new(File.read(@options[:key_path])) if @options[:key_path] diff --git a/lib/jira/http_client.rb b/lib/jira/http_client.rb index 53ad8ae3..c395303c 100644 --- a/lib/jira/http_client.rb +++ b/lib/jira/http_client.rb @@ -99,12 +99,12 @@ def request_path(url) def store_cookies(response) cookies = response.get_fields('set-cookie') return unless cookies - cookies.each do |cookie| - data = CGI::Cookie.parse(cookie) - data.delete('Path') - @cookies.merge!(data) - end - + cookies.each do |cookie| + data = CGI::Cookie.parse(cookie) + data.delete('Path') + @cookies.merge!(data) + end + end def add_cookies(request) diff --git a/lib/jira/resource/attachment.rb b/lib/jira/resource/attachment.rb index e57b6641..2e0bb523 100644 --- a/lib/jira/resource/attachment.rb +++ b/lib/jira/resource/attachment.rb @@ -68,7 +68,7 @@ def save!(attrs, path = url) headers = { 'X-Atlassian-Token' => 'nocheck' } data = { 'file' => Multipart::Post::UploadIO.new(file, mime_type, file) } - response = client.post_multipart(path, data , headers) + response = client.post_multipart(path, data, headers) set_attributes(attrs, response) diff --git a/lib/jira/resource/field.rb b/lib/jira/resource/field.rb index 78c8a7fe..e6ac6e0f 100644 --- a/lib/jira/resource/field.rb +++ b/lib/jira/resource/field.rb @@ -43,7 +43,7 @@ def self.map_fields(client) renamed else safe_name(f.name) - end + end field_map_reverse[f.id] = [f.name, name] # capture both the official name, and the mapped name field_map[name] = f.id end diff --git a/lib/jira/resource/issue.rb b/lib/jira/resource/issue.rb index e845541d..9537ff73 100644 --- a/lib/jira/resource/issue.rb +++ b/lib/jira/resource/issue.rb @@ -54,8 +54,8 @@ def self.jql(client, jql, options = { fields: nil, start_at: nil, max_results: n if options[:fields] url << "&fields=#{options[:fields].map do |value| - CGI.escape(client.Field.name_to_id(value)) -end.join(',')}" + CGI.escape(client.Field.name_to_id(value)) + end.join(',')}" end url << "&startAt=#{CGI.escape(options[:start_at].to_s)}" if options[:start_at] url << "&maxResults=#{CGI.escape(options[:max_results].to_s)}" if options[:max_results] @@ -103,8 +103,8 @@ def editmeta def respond_to?(method_name, _include_all = false) if attrs.key?('fields') && [method_name.to_s, client.Field.name_to_id(method_name)].any? do |k| - attrs['fields'].key?(k) -end + attrs['fields'].key?(k) + end true else super(method_name) diff --git a/spec/jira/base_spec.rb b/spec/jira/base_spec.rb index 467ae41d..0d080c2f 100644 --- a/spec/jira/base_spec.rb +++ b/spec/jira/base_spec.rb @@ -305,7 +305,7 @@ class JIRA::Resource::HasManyExample < JIRA::Base # :nodoc: allow(subject).to receive(:new_record?).and_return(false) expect(client).to receive(:put).with('/foo/bar', '{"invalid_field":"foobar"}').and_raise(JIRA::HTTPError.new(response)) - expect{ subject.save!('invalid_field' => 'foobar') }.to raise_error(JIRA::HTTPError) + expect { subject.save!('invalid_field' => 'foobar') }.to raise_error(JIRA::HTTPError) end end @@ -492,8 +492,8 @@ class JIRA::Resource::HasManyExample < JIRA::Base # :nodoc: it 'allows the has_many attributes to be nested inside another attribute' do subject = JIRA::Resource::HasManyExample.new(client, - attrs: { 'nested' => { 'brunchmuffins' => [{ 'id' => '123' }, -{ 'id' => '456' }] } }) + attrs: { 'nested' => { 'brunchmuffins' => [{ 'id' => '123' }, + { 'id' => '456' }] } }) expect(subject.brunchmuffins.length).to eq(2) subject.brunchmuffins.each do |brunchmuffin| expect(brunchmuffin.class).to eq(JIRA::Resource::Deadbeef) @@ -519,8 +519,8 @@ class JIRA::Resource::HasManyExample < JIRA::Base # :nodoc: it 'allows the attribute key to be specified' do subject = JIRA::Resource::HasManyExample.new(client, - attrs: { 'irregularlyNamedThings' => [{ 'id' => '123' }, -{ 'id' => '456' }] }) + attrs: { 'irregularlyNamedThings' => [{ 'id' => '123' }, + { 'id' => '456' }] }) expect(subject.irregularly_named_things.length).to eq(2) subject.irregularly_named_things.each do |thing| expect(thing.class).to eq(JIRA::Resource::Deadbeef) diff --git a/spec/jira/client_spec.rb b/spec/jira/client_spec.rb index 230e5025..0014862b 100644 --- a/spec/jira/client_spec.rb +++ b/spec/jira/client_spec.rb @@ -68,14 +68,14 @@ it 'raises an ArgumentError' do expect do - subject -end.to raise_exception(ArgumentError, - 'Options: :cert_path or :ssl_client_cert must be set when :use_client_cert is true') + subject + end.to raise_exception(ArgumentError, + 'Options: :cert_path or :ssl_client_cert must be set when :use_client_cert is true') options[:ssl_client_cert] = '' expect do - subject -end.to raise_exception(ArgumentError, - 'Options: :key_path or :ssl_client_key must be set when :use_client_cert is true') + subject + end.to raise_exception(ArgumentError, + 'Options: :key_path or :ssl_client_key must be set when :use_client_cert is true') end end end diff --git a/spec/jira/request_client_spec.rb b/spec/jira/request_client_spec.rb index a338eb0f..416253a2 100644 --- a/spec/jira/request_client_spec.rb +++ b/spec/jira/request_client_spec.rb @@ -15,7 +15,7 @@ end it 'raises an exception' do - expect{ subject }.to raise_exception(JIRA::HTTPError) + expect { subject }.to raise_exception(JIRA::HTTPError) end end end @@ -34,7 +34,7 @@ end it 'raises an exception' do - expect{ subject }.to raise_exception(JIRA::HTTPError) + expect { subject }.to raise_exception(JIRA::HTTPError) end end end diff --git a/spec/jira/resource/attachment_spec.rb b/spec/jira/resource/attachment_spec.rb index 1fc31da2..d6e35b82 100644 --- a/spec/jira/resource/attachment_spec.rb +++ b/spec/jira/resource/attachment_spec.rb @@ -3,9 +3,9 @@ describe JIRA::Resource::Attachment do subject(:attachment) do described_class.new( - client, - issue: JIRA::Resource::Issue.new(client), - attrs: { 'author' => { 'foo' => 'bar' } } + client, + issue: JIRA::Resource::Issue.new(client), + attrs: { 'author' => { 'foo' => 'bar' } } ) end @@ -39,8 +39,8 @@ let(:response) do double( - 'response', - body: '{"enabled":true,"uploadLimit":10485760}' + 'response', + body: '{"enabled":true,"uploadLimit":10485760}' ) end @@ -69,7 +69,7 @@ end let(:client) do - JIRA::Client.new(username: 'username', password: 'password', auth_type: :basic, use_ssl: false ) + JIRA::Client.new(username: 'username', password: 'password', auth_type: :basic, use_ssl: false) end let(:attachment_file_contents) { 'file contents' } let(:file_target) { double(read: :attachment_file_contents) } @@ -142,11 +142,11 @@ end let(:default_headers_given) do - { 'authorization' => 'Bearer 83CF8B609DE60036A8277BD0E96135751BBC07EB234256D4B65B893360651BF2' } -end + { 'authorization' => 'Bearer 83CF8B609DE60036A8277BD0E96135751BBC07EB234256D4B65B893360651BF2' } + end let(:bearer_client) do JIRA::Client.new(username: 'username', password: 'password', auth_type: :basic, use_ssl: false, - default_headers: default_headers_given ) + default_headers: default_headers_given) end let(:merged_headers) do { 'Accept' => 'application/json', 'X-Atlassian-Token' => 'nocheck' }.merge(default_headers_given) @@ -162,7 +162,7 @@ end describe '#save!' do - subject { attachment.save!('file' => path_to_file) } + subject { attachment.save!('file' => path_to_file) } before do allow(client).to receive(:post_multipart).and_return(response) @@ -198,11 +198,11 @@ end let(:default_headers_given) do - { 'authorization' => 'Bearer 83CF8B609DE60036A8277BD0E96135751BBC07EB234256D4B65B893360651BF2' } -end + { 'authorization' => 'Bearer 83CF8B609DE60036A8277BD0E96135751BBC07EB234256D4B65B893360651BF2' } + end let(:bearer_client) do JIRA::Client.new(username: 'username', password: 'password', auth_type: :basic, use_ssl: false, - default_headers: default_headers_given ) + default_headers: default_headers_given) end let(:merged_headers) do { 'Accept' => 'application/json', 'X-Atlassian-Token' => 'nocheck' }.merge(default_headers_given) diff --git a/spec/jira/resource/sprint_spec.rb b/spec/jira/resource/sprint_spec.rb index 0b79d18d..830e0b7e 100644 --- a/spec/jira/resource/sprint_spec.rb +++ b/spec/jira/resource/sprint_spec.rb @@ -111,7 +111,7 @@ issue end let(:post_issue_input) do - { issues:[issue.id] } + { issues: [issue.id] } end describe '#add_issu' do @@ -126,7 +126,7 @@ end context 'multiple issues exists' do - let(:issue_ids) { [ 1001, 1012 ] } + let(:issue_ids) { [1001, 1012] } let(:post_issue_path) do described_class.agile_path(client, sprint.id) '/jira/rest/agile/1.0/sprint//issue' diff --git a/spec/support/shared_examples/integration.rb b/spec/support/shared_examples/integration.rb index ae55f719..5e12633c 100644 --- a/spec/support/shared_examples/integration.rb +++ b/spec/support/shared_examples/integration.rb @@ -48,7 +48,7 @@ def build_receiver shared_examples 'a resource' do it 'gracefully handles non-json responses' do subject = if defined? target - target + target else client.send(class_basename).build(described_class.key_attribute.to_s => '99999') end From bdb09fbf0ff95969ff360433d0a20967ad49559f Mon Sep 17 00:00:00 2001 From: Robert Brodie Date: Sun, 28 Apr 2024 22:39:31 -0400 Subject: [PATCH 49/59] Line length cleanup --- lib/jira/base.rb | 3 ++- lib/jira/resource/agile.rb | 7 ------- lib/jira/resource/issue.rb | 6 ++++-- lib/tasks/generate.rake | 2 +- spec/integration/issue_spec.rb | 2 ++ spec/integration/user_spec.rb | 3 ++- spec/jira/base_spec.rb | 15 ++++++++++----- spec/jira/resource/project_spec.rb | 6 +++--- spec/jira/resource/sprint_spec.rb | 1 + 9 files changed, 25 insertions(+), 20 deletions(-) diff --git a/lib/jira/base.rb b/lib/jira/base.rb index fe78c79f..8cf9e066 100644 --- a/lib/jira/base.rb +++ b/lib/jira/base.rb @@ -438,7 +438,8 @@ def url end # This method fixes issue that there is no / prefix in url. It is happened when we call for instance - # Looks like this issue is actual only in case if you use atlassian sdk your app path is not root (like /jira in example below) + # Looks like this issue is actual only in case if you use atlassian sdk your app pathis not root + # (like /jira in example below) # issue.save() for existing resource. # As a result we got error 400 from JIRA API: # [07/Jun/2015:15:32:19 +0400] "PUT jira/rest/api/2/issue/10111 HTTP/1.1" 400 - diff --git a/lib/jira/resource/agile.rb b/lib/jira/resource/agile.rb index c43a39ab..3501c356 100644 --- a/lib/jira/resource/agile.rb +++ b/lib/jira/resource/agile.rb @@ -61,13 +61,6 @@ def self.get_projects(client, board_id, options = {}) parse_json(response.body) end - # def self.find(client, key, options = {}) - # options[:maxResults] ||= 100 - # fields = options[:fields].join(',') unless options[:fields].nil? - # response = client.get("/rest/api/latest/search?jql=sprint=#{key}&fields=#{fields}&maxResults=#{options[:maxResults]}") - # parse_json(response.body) - # end - private def self.path_base(client) diff --git a/lib/jira/resource/issue.rb b/lib/jira/resource/issue.rb index 9537ff73..fd249000 100644 --- a/lib/jira/resource/issue.rb +++ b/lib/jira/resource/issue.rb @@ -68,7 +68,7 @@ def self.jql(client, jql, options = { fields: nil, start_at: nil, max_results: n response = client.get(url) json = parse_json(response.body) - return json['total'] if options[:max_results] && (options[:max_results] == 0) + return json['total'] if options[:max_results] && (options[:max_results]).zero? json['issues'].map do |issue| client.Issue.build(issue) @@ -83,7 +83,9 @@ def fetch(reload = false, query_params = {}) response = client.get(url_with_query_params(url, query_params)) set_attrs_from_response(response) - if @attrs && @attrs['fields'] && @attrs['fields']['worklog'] && (@attrs['fields']['worklog']['total'] > @attrs['fields']['worklog']['maxResults']) + if @attrs && @attrs['fields'] && + @attrs['fields']['worklog'] && + (@attrs['fields']['worklog']['total'] > @attrs['fields']['worklog']['maxResults']) worklog_url = client.options[:rest_base_path] + "/#{self.class.endpoint_name}/#{id}/worklog" response = client.get(worklog_url) unless response.body.nil? || (response.body.length < 2) diff --git a/lib/tasks/generate.rake b/lib/tasks/generate.rake index 8b20d142..3880cc47 100644 --- a/lib/tasks/generate.rake +++ b/lib/tasks/generate.rake @@ -12,7 +12,7 @@ namespace :jira do desc 'Run the system call to generate a RSA public certificate' task :generate_public_cert do puts "Executing 'openssl req -x509 -nodes -newkey rsa:1024 -sha1 -keyout rsakey.pem -out rsacert.pem'" - system('openssl req -x509 -subj "/C=US/ST=New York/L=New York/O=SUMO Heavy Industries/CN=www.sumoheavy.com" -nodes -newkey rsa:1024 -sha1 -keyout rsakey.pem -out rsacert.pem') + system('openssl req -x509 -subj "/C=US/ST=New York/L=New York/O=SUMO Heavy Industries/CN=www.sumoheavy.com" -nodes -newkey rsa:1024 -sha1 -keyout rsakey.pem -out rsacert.pem') # rubocop:disable Layout/LineLength puts "Done. The RSA-SHA1 private keyfile is in the current directory: 'rsakey.pem'." puts 'You will need to copy the following certificate into your application link configuration in Jira:' system('cat rsacert.pem') diff --git a/spec/integration/issue_spec.rb b/spec/integration/issue_spec.rb index ba910416..8aa4b128 100644 --- a/spec/integration/issue_spec.rb +++ b/spec/integration/issue_spec.rb @@ -43,6 +43,7 @@ 'key' => 'SAMPLEPROJECT-13' } end + before do stub_request(:get, "#{site_url}/jira/rest/api/2/search?expand=transitions.fields&maxResults=1000&startAt=0") .to_return(status: 200, body: get_mock_response('issue.json')) @@ -89,6 +90,7 @@ 'key' => 'SAMPLEPROJECT-13' } end + it_behaves_like 'a resource with JQL inputs and a collection GET endpoint' end end diff --git a/spec/integration/user_spec.rb b/spec/integration/user_spec.rb index b9b1a3a2..a19783be 100644 --- a/spec/integration/user_spec.rb +++ b/spec/integration/user_spec.rb @@ -21,7 +21,8 @@ describe '#all' do let(:client) do client = double(options: { rest_base_path: '/jira/rest/api/2' }) - allow(client).to receive(:get).with('/rest/api/2/users/search?username=_&maxResults=1000').and_return(JIRA::Resource::UserFactory.new(client)) + allow(client).to receive(:get).with('/rest/api/2/users/search?username=_&maxResults=1000') + .and_return(JIRA::Resource::UserFactory.new(client)) client end diff --git a/spec/jira/base_spec.rb b/spec/jira/base_spec.rb index 0d080c2f..0089a406 100644 --- a/spec/jira/base_spec.rb +++ b/spec/jira/base_spec.rb @@ -257,7 +257,8 @@ class JIRA::Resource::HasManyExample < JIRA::Base # :nodoc: expect(subject.foo).to eq('bar' => 'baz', 'fum' => 'dum') end - it 'returns false when an invalid field is set' do # The JIRA REST API apparently ignores fields that you aren't allowed to set manually + it 'returns false when an invalid field is set' do + # The JIRA REST API apparently ignores fields that you aren't allowed to set manually response = instance_double('Response', body: '{"errorMessages":["blah"]}', status: 400) allow(subject).to receive(:new_record?).and_return(false) expect(client).to receive(:put).with('/foo/bar', @@ -265,7 +266,8 @@ class JIRA::Resource::HasManyExample < JIRA::Base # :nodoc: expect(subject.save('invalid_field' => 'foobar')).to be_falsey end - it 'returns false with exception details when non json response body (unauthorized)' do # Unauthorized requests return a non-json body. This makes sure we can handle non-json bodies on HTTPError + it 'returns false with exception details when non json response body (unauthorized)' do + # Unauthorized requests return a non-json body. This makes sure we can handle non-json bodies on HTTPError response = double('Response', body: 'totally invalid json', code: 401, message: 'Unauthorized') expect(client).to receive(:post).with('/foo/bar', '{"foo":"bar"}').and_raise(JIRA::HTTPError.new(response)) expect(subject.save('foo' => 'bar')).to be_falsey @@ -501,9 +503,12 @@ class JIRA::Resource::HasManyExample < JIRA::Base # :nodoc: end it 'allows it to be deeply nested' do - subject = JIRA::Resource::HasManyExample.new(client, attrs: { 'nested' => { - 'breakfastscone' => { 'breakfastscones' => [{ 'id' => '123' }, { 'id' => '456' }] } - } }) + subject = JIRA::Resource::HasManyExample.new( + client, + attrs: { + 'nested' => { 'breakfastscone' => { 'breakfastscones' => [{ 'id' => '123' }, { 'id' => '456' }] } } + } + ) expect(subject.breakfastscones.length).to eq(2) subject.breakfastscones.each do |breakfastscone| expect(breakfastscone.class).to eq(JIRA::Resource::Deadbeef) diff --git a/spec/jira/resource/project_spec.rb b/spec/jira/resource/project_spec.rb index 2122c8c0..67e83abe 100644 --- a/spec/jira/resource/project_spec.rb +++ b/spec/jira/resource/project_spec.rb @@ -36,7 +36,7 @@ end it 'returns issues' do - response_body = '{"expand":"schema,names","startAt":0,"maxResults":1,"total":1,"issues":[{"expand":"editmeta,renderedFields,transitions,changelog,operations","id":"53062","self":"/rest/api/2/issue/53062","key":"test key","fields":{"summary":"test summary"}}]}' + response_body = '{"expand":"schema,names","startAt":0,"maxResults":1,"total":1,"issues":[{"expand":"editmeta,renderedFields,transitions,changelog,operations","id":"53062","self":"/rest/api/2/issue/53062","key":"test key","fields":{"summary":"test summary"}}]}' # rubocop:disable Layout/LineLength response = double('response', body: response_body) issue_factory = double('issue factory') @@ -52,7 +52,7 @@ context 'with changelog' do it 'returns issues' do - response_body = '{"expand":"schema,names","startAt":0,"maxResults":1,"total":1,"issues":[{"expand":"editmeta,renderedFields,transitions,changelog,operations","id":"53062","self":"/rest/api/2/issue/53062","key":"test key","fields":{"summary":"test summary"},"changelog":{}}]}' + response_body = '{"expand":"schema,names","startAt":0,"maxResults":1,"total":1,"issues":[{"expand":"editmeta,renderedFields,transitions,changelog,operations","id":"53062","self":"/rest/api/2/issue/53062","key":"test key","fields":{"summary":"test summary"},"changelog":{}}]}' # rubocop:disable Layout/LineLength response = double('response', body: response_body) issue_factory = double('issue factory') @@ -113,7 +113,7 @@ max_results = rand(1000) expect(client).to receive(:get) - .with("/jira/rest/api/2/user/assignable/search?project=#{project_key}&startAt=#{start_at}&maxResults=#{max_results}") + .with("/jira/rest/api/2/user/assignable/search?project=#{project_key}&startAt=#{start_at}&maxResults=#{max_results}") # rubocop:disable Layout/LineLength .and_return(response) project.users(start_at:, max_results:) diff --git a/spec/jira/resource/sprint_spec.rb b/spec/jira/resource/sprint_spec.rb index 830e0b7e..b0490f41 100644 --- a/spec/jira/resource/sprint_spec.rb +++ b/spec/jira/resource/sprint_spec.rb @@ -12,6 +12,7 @@ describe 'get_sprint_details' do let(:sprint) { JIRA::Resource::Sprint.find(client, '1') } + it 'check each of the date attributes' do allow(client).to receive(:get).and_return(double(body: get_mock_response('sprint/1.json'))) From 17002cce282c60f7be36a5540e3c6ed0d08bf8f0 Mon Sep 17 00:00:00 2001 From: Robert Brodie Date: Sun, 28 Apr 2024 22:43:34 -0400 Subject: [PATCH 50/59] Designate self.path_base as private --- lib/jira/resource/agile.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/jira/resource/agile.rb b/lib/jira/resource/agile.rb index 3501c356..7ec278bc 100644 --- a/lib/jira/resource/agile.rb +++ b/lib/jira/resource/agile.rb @@ -70,6 +70,8 @@ def self.path_base(client) def path_base(client) self.class.path_base(client) end + + private_class_method :path_base end end end From fe7082139d985e841c02eb45705d1a94e002a3f6 Mon Sep 17 00:00:00 2001 From: Robert Brodie Date: Sun, 28 Apr 2024 22:52:46 -0400 Subject: [PATCH 51/59] Fix Style/IfUnlessModifier and disable some cops --- .rubocop.yml | 23 ++++++++++++++++++++++- lib/jira/resource/issue.rb | 4 +--- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 6e3fced1..55a9cc57 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -21,4 +21,25 @@ Style/Documentation: Style/FrozenStringLiteralComment: Exclude: - - 'spec/**/*' \ No newline at end of file + - 'spec/**/*' + +# Temporarily Disable + +Layout/LineLength: + Enabled: false + +RSpec/MessageSpies: + Enabled: false + +RSpec/NamedSubject: + Enabled: false + +RSpec/StubbedMock: + Enabled: false + +RSpec/ExampleLength: + Enabled: false + +RSpec/VerifiedDoubles: + Enabled: false + diff --git a/lib/jira/resource/issue.rb b/lib/jira/resource/issue.rb index fd249000..bda42eb5 100644 --- a/lib/jira/resource/issue.rb +++ b/lib/jira/resource/issue.rb @@ -88,9 +88,7 @@ def fetch(reload = false, query_params = {}) (@attrs['fields']['worklog']['total'] > @attrs['fields']['worklog']['maxResults']) worklog_url = client.options[:rest_base_path] + "/#{self.class.endpoint_name}/#{id}/worklog" response = client.get(worklog_url) - unless response.body.nil? || (response.body.length < 2) - set_attrs({ 'fields' => { 'worklog' => self.class.parse_json(response.body) } }, false) - end + set_attrs({ 'fields' => { 'worklog' => self.class.parse_json(response.body) } }, false) unless response.body.nil? || (response.body.length < 2) end @expanded = true end From 5884183648d04a9d480f90935c162a23b71cfad4 Mon Sep 17 00:00:00 2001 From: Robert Brodie Date: Sun, 28 Apr 2024 22:54:49 -0400 Subject: [PATCH 52/59] Disable Style/CombinableLoops in the two pass approach --- lib/jira/resource/field.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/jira/resource/field.rb b/lib/jira/resource/field.rb index e6ac6e0f..227e474c 100644 --- a/lib/jira/resource/field.rb +++ b/lib/jira/resource/field.rb @@ -34,7 +34,7 @@ def self.map_fields(client) field_map[name] = f.id end - fields.each do |f| + fields.each do |f| # rubocop:disable Style/CombinableLoops next unless f.custom name = if field_map.key? f.name From a4c7f551cf1a9ed95e64c045edc06e54c654ba19 Mon Sep 17 00:00:00 2001 From: Robert Brodie Date: Sun, 28 Apr 2024 23:01:26 -0400 Subject: [PATCH 53/59] Remove unused file - tasks.rb --- lib/jira/tasks.rb | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 lib/jira/tasks.rb diff --git a/lib/jira/tasks.rb b/lib/jira/tasks.rb deleted file mode 100644 index e69de29b..00000000 From 91cdf0143589188f17259b9c9b92b30ebba141ad Mon Sep 17 00:00:00 2001 From: Robert Brodie Date: Sun, 28 Apr 2024 23:03:11 -0400 Subject: [PATCH 54/59] Fix RSpec/DescribedClass --- spec/jira/resource/sprint_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/jira/resource/sprint_spec.rb b/spec/jira/resource/sprint_spec.rb index b0490f41..3041280a 100644 --- a/spec/jira/resource/sprint_spec.rb +++ b/spec/jira/resource/sprint_spec.rb @@ -11,7 +11,7 @@ let(:response) { double } describe 'get_sprint_details' do - let(:sprint) { JIRA::Resource::Sprint.find(client, '1') } + let(:sprint) { described_class.find(client, '1') } it 'check each of the date attributes' do allow(client).to receive(:get).and_return(double(body: get_mock_response('sprint/1.json'))) From de7e820621ee180e123475a74e4dea1a5c64e04e Mon Sep 17 00:00:00 2001 From: Robert Brodie Date: Sun, 28 Apr 2024 23:04:21 -0400 Subject: [PATCH 55/59] Fix Layout/ElseAlignment --- spec/support/shared_examples/integration.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/support/shared_examples/integration.rb b/spec/support/shared_examples/integration.rb index 5e12633c..f2b65344 100644 --- a/spec/support/shared_examples/integration.rb +++ b/spec/support/shared_examples/integration.rb @@ -49,8 +49,8 @@ def build_receiver it 'gracefully handles non-json responses' do subject = if defined? target target - else - client.send(class_basename).build(described_class.key_attribute.to_s => '99999') + else + client.send(class_basename).build(described_class.key_attribute.to_s => '99999') end stub_request(:put, site_url + subject.url) .to_return(status: 405, body: 'Some HTML') From 96ea2ebd2dba2b51f8509dbfd35d046cf54a8d1b Mon Sep 17 00:00:00 2001 From: Robert Brodie Date: Sun, 28 Apr 2024 23:06:07 -0400 Subject: [PATCH 56/59] Fix Style/HashConversion --- lib/jira/base.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/jira/base.rb b/lib/jira/base.rb index 8cf9e066..2a13fdfa 100644 --- a/lib/jira/base.rb +++ b/lib/jira/base.rb @@ -520,15 +520,15 @@ def self.hash_to_query_string(query_params) end def self.query_params_for_single_fetch(options) - Hash[options.select do |k, _v| + options.select do |k, _v| QUERY_PARAMS_FOR_SINGLE_FETCH.include? k - end] + end.to_h end def self.query_params_for_search(options) - Hash[options.select do |k, _v| + options.select do |k, _v| QUERY_PARAMS_FOR_SEARCH.include? k - end] + end.to_h end end end From 54eb5416d352cf89eadd023974a4714f4eee0899 Mon Sep 17 00:00:00 2001 From: Robert Brodie Date: Sun, 28 Apr 2024 23:20:01 -0400 Subject: [PATCH 57/59] Fix RSpec/BeEql --- spec/jira/resource/agile_spec.rb | 4 ++-- spec/jira/resource/filter_spec.rb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/jira/resource/agile_spec.rb b/spec/jira/resource/agile_spec.rb index 14f2da4d..c0502634 100644 --- a/spec/jira/resource/agile_spec.rb +++ b/spec/jira/resource/agile_spec.rb @@ -36,7 +36,7 @@ issues = described_class.get_board_issues(client, 1) expect(issues).to be_an(Array) - expect(issues.size).to eql(9) + expect(issues.size).to be(9) issues.each do |issue| expect(issue.class).to eq(JIRA::Resource::Issue) @@ -53,7 +53,7 @@ issues = described_class.get_board_issues(client, 1, startAt: 50) expect(issues).to be_an(Array) - expect(issues.size).to eql(9) + expect(issues.size).to be(9) issues.each do |issue| expect(issue.class).to eq(JIRA::Resource::Issue) diff --git a/spec/jira/resource/filter_spec.rb b/spec/jira/resource/filter_spec.rb index 30908e89..58117f51 100644 --- a/spec/jira/resource/filter_spec.rb +++ b/spec/jira/resource/filter_spec.rb @@ -90,7 +90,7 @@ .and_return(issue_jql_response) issues = filter.issues expect(issues).to be_an(Array) - expect(issues.size).to eql(1) + expect(issues.size).to be(1) expected_issue = client.Issue.build(JSON.parse(jql_issue.to_json)) expect(issues.first.attrs).to eql(expected_issue.attrs) end From e62baba6e2f8449d05d1aecb8f5476b3a9a7480c Mon Sep 17 00:00:00 2001 From: Robert Brodie Date: Sun, 28 Apr 2024 23:42:12 -0400 Subject: [PATCH 58/59] Disable remaining cops since they need more thought --- .rubocop.yml | 148 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 147 insertions(+), 1 deletion(-) diff --git a/.rubocop.yml b/.rubocop.yml index 55a9cc57..67695d6f 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -23,23 +23,169 @@ Style/FrozenStringLiteralComment: Exclude: - 'spec/**/*' +## # Temporarily Disable +# +# We are going to disable these and fix in pull requests +## +Layout/ClosingHeredocIndentation: + Enabled: false + +Layout/EmptyLineAfterGuardClause: + Enabled: false + +Layout/EmptyLinesAroundMethodBody: + Enabled: false + +Layout/HashAlignment: + Enabled: false Layout/LineLength: Enabled: false +Lint/ConstantDefinitionInBlock: + Enabled: false + +Lint/EmptyClass: + Enabled: false + +Lint/IneffectiveAccessModifier: + Enabled: false + +Lint/MissingSuper: + Enabled: false + +Lint/RedundantCopDisableDirective: + Enabled: false + +Lint/UselessAssignment: + Enabled: false + +Metrics/AbcSize: + Enabled: false + +Metrics/ClassLength: + Enabled: false + +Metrics/CyclomaticComplexity: + Enabled: false + +Metrics/MethodLength: + Enabled: false + +Metrics/PerceivedComplexity: + Enabled: false + +Naming/AccessorMethodName: + Enabled: false + +Naming/BlockForwarding: + Enabled: false + +Naming/HeredocDelimiterNaming: + Enabled: false + +Naming/PredicateName: + Enabled: false + +Naming/VariableNumber: + Enabled: false + +RSpec/AnyInstance: + Enabled: false + +RSpec/BeEq: + Enabled: false + +RSpec/ContextWording: + Enabled: false + +RSpec/ExampleLength: + Enabled: false + +RSpec/ExpectInHook: + Enabled: false + +RSpec/FilePath: + Enabled: false + +RSpec/IndexedLet: + Enabled: false + +RSpec/InstanceVariable: + Enabled: false + +RSpec/LeakyConstantDeclaration: + Enabled: false + +RSpec/MessageChain: + Enabled: false + RSpec/MessageSpies: Enabled: false +RSpec/MultipleExpectations: + Enabled: false + +RSpec/MultipleMemoizedHelpers: + Enabled: false + RSpec/NamedSubject: Enabled: false +RSpec/NestedGroups: + Enabled: false + +RSpec/NoExpectationExample: + Enabled: false + +RSpec/PredicateMatcher: + Enabled: false + +RSpec/ReceiveMessages: + Enabled: false + +RSpec/RepeatedSubjectCall: + Enabled: false + +RSpec/SpecFilePathFormat: + Enabled: false + +RSpec/SpecFilePathSuffix: + Enabled: false + RSpec/StubbedMock: Enabled: false -RSpec/ExampleLength: +RSpec/SubjectStub: + Enabled: false + +RSpec/VerifiedDoubleReference: Enabled: false RSpec/VerifiedDoubles: Enabled: false +Security/Open: + Enabled: false + +Style/ArgumentsForwarding: + Enabled: false + +Style/CaseEquality: + Enabled: false + +Style/ClassAndModuleChildren: + Enabled: false + +Style/MissingRespondToMissing: + Enabled: false + +Style/OpenStructUse: + Enabled: false + +Style/OptionalBooleanParameter: + Enabled: false + +Style/SymbolProc: + Enabled: false \ No newline at end of file From a975e5820790f872784b3e4e1f01ac8b73fa1dff Mon Sep 17 00:00:00 2001 From: Robert Brodie Date: Mon, 29 Apr 2024 23:00:20 -0400 Subject: [PATCH 59/59] Update attachment spec for rubocop --- spec/jira/resource/attachment_spec.rb | 48 +++++++++++++++------------ 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/spec/jira/resource/attachment_spec.rb b/spec/jira/resource/attachment_spec.rb index 0dde1697..b213461a 100644 --- a/spec/jira/resource/attachment_spec.rb +++ b/spec/jira/resource/attachment_spec.rb @@ -2,7 +2,7 @@ describe JIRA::Resource::Attachment do subject(:attachment) do - JIRA::Resource::Attachment.new( + described_class.new( client, issue: JIRA::Resource::Issue.new(client), attrs: { 'author' => { 'foo' => 'bar' } } @@ -35,7 +35,7 @@ end describe '.meta' do - subject { JIRA::Resource::Attachment.meta(client) } + subject { described_class.meta(client) } let(:response) do double( @@ -60,20 +60,21 @@ end context 'there is an attachment on an issue' do - let(:client) do - JIRA::Client.new(username: 'username', password: 'password', auth_type: :basic, use_ssl: false) - end - let(:attachment_file_contents) { 'file contents' } - let(:attachment_url) { 'https://localhost:2990/secure/attachment/32323/myfile.txt' } subject(:attachment) do - JIRA::Resource::Attachment.new( + described_class.new( client, issue: JIRA::Resource::Issue.new(client), attrs: { 'author' => { 'foo' => 'bar' }, 'content' => attachment_url } ) end - before(:each) do + let(:client) do + JIRA::Client.new(username: 'username', password: 'password', auth_type: :basic, use_ssl: false) + end + let(:attachment_file_contents) { 'file contents' } + let(:attachment_url) { 'https://localhost:2990/secure/attachment/32323/myfile.txt' } + + before do stub_request(:get, attachment_url).to_return(body: attachment_file_contents) end @@ -104,12 +105,12 @@ double( body: [ { - "id": 10_001, - "self": 'http://www.example.com/jira/rest/api/2.0/attachments/10000', - "filename": file_name, - "created": '2017-07-19T12:23:06.572+0000', - "size": file_size, - "mimeType": file_mime_type + id: 10_001, + self: 'http://www.example.com/jira/rest/api/2.0/attachments/10000', + filename: file_name, + created: '2017-07-19T12:23:06.572+0000', + size: file_size, + mimeType: file_mime_type } ].to_json ) @@ -130,22 +131,24 @@ expect(attachment.mimeType).to eq file_mime_type expect(attachment.size).to eq file_size end + context 'when using custom client headers' do subject(:bearer_attachment) do - JIRA::Resource::Attachment.new( + described_class.new( bearer_client, issue: JIRA::Resource::Issue.new(bearer_client), attrs: { 'author' => { 'foo' => 'bar' } } ) end - let(:default_headers_given) { + + let(:default_headers_given) do { 'authorization' => 'Bearer 83CF8B609DE60036A8277BD0E96135751BBC07EB234256D4B65B893360651BF2' } - } + end let(:bearer_client) do JIRA::Client.new(username: 'username', password: 'password', auth_type: :basic, use_ssl: false, - default_headers: default_headers_given ) + default_headers: default_headers_given) end let(:merged_headers) do { @@ -193,16 +196,17 @@ context 'when using custom client headers' do subject(:bearer_attachment) do - JIRA::Resource::Attachment.new( + described_class.new( bearer_client, issue: JIRA::Resource::Issue.new(bearer_client), attrs: { 'author' => { 'foo' => 'bar' } } ) end + let(:default_headers_given) { { 'authorization' => 'Bearer 83CF8B609DE60036A8277BD0E96135751BBC07EB234256D4B65B893360651BF2' } } let(:bearer_client) do JIRA::Client.new(username: 'username', password: 'password', auth_type: :basic, use_ssl: false, - default_headers: default_headers_given ) + default_headers: default_headers_given) end let(:merged_headers) do { @@ -221,4 +225,4 @@ end end end -end \ No newline at end of file +end