Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove OpenStruct usage #454

Merged
merged 1 commit into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,6 @@ Style/ClassAndModuleChildren:
Style/MissingRespondToMissing:
Enabled: false

Style/OpenStructUse:
Enabled: false

Style/OptionalBooleanParameter:
Enabled: false

Expand Down
5 changes: 1 addition & 4 deletions lib/jira/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

require 'json'
require 'forwardable'
require 'ostruct'

module JIRA
# This class is the main access point for all JIRA::Resource instances.
Expand Down Expand Up @@ -55,7 +54,7 @@ class Client
#
# The authenticated client instance returned by the respective client type
# (Oauth, Basic)
attr_accessor :consumer, :request_client, :http_debug, :cache
attr_accessor :consumer, :request_client, :http_debug, :field_map_cache

# The configuration options for this client instance
attr_reader :options
Expand Down Expand Up @@ -164,8 +163,6 @@ def initialize(options = {})
@http_debug = @options[:http_debug]

@options.freeze

@cache = OpenStruct.new
end

def Project # :nodoc:
Expand Down
12 changes: 4 additions & 8 deletions lib/jira/resource/field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ def self.safer_name(description, jira_id)

def self.map_fields(client)
field_map = {}
field_map_reverse = {}
fields = client.Field.all

# two pass approach, so that a custom field with the same name
Expand All @@ -30,7 +29,6 @@ def self.map_fields(client)
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
end

Expand All @@ -44,23 +42,21 @@ def self.map_fields(client)
else
safe_name(f.name)
end
field_map_reverse[f.id] = [f.name, name] # capture both the official name, and the mapped name
field_map[name] = f.id
end

client.cache.field_map_reverse = field_map_reverse # not sure where this will be used yet, but sure to be useful
client.cache.field_map = field_map
client.field_map_cache = field_map
end

def self.field_map(client)
client.cache.field_map
client.field_map_cache
end

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]
return field_name unless client.field_map_cache && client.field_map_cache[field_name]

client.cache.field_map[field_name]
client.field_map_cache[field_name]
end

def respond_to?(method_name, _include_all = false)
Expand Down
2 changes: 1 addition & 1 deletion spec/integration/user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

before do
allow(client).to receive(:get)
.with('/rest/api/2/users/search?username=_&maxResults=1000') { OpenStruct.new(body: '["User1"]') }
.with('/rest/api/2/users/search?username=_&maxResults=1000') { double(body: '["User1"]') }
allow(client).to receive_message_chain(:User, :build).with('users') { [] }
end

Expand Down
6 changes: 3 additions & 3 deletions spec/jira/resource/board_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,15 @@ class JIRAResourceDelegation < SimpleDelegator # :nodoc:

context 'when there are multiple pages of results' do
let(:result_1) do
OpenStruct.new(body: {
double(body: {
'startAt' => 0,
'maxResults' => 1,
'total' => 2,
'issues' => []
}.to_json)
end
let(:result_2) do
OpenStruct.new(body: {
double(body: {
'startAt' => 1,
'maxResults' => 1,
'total' => 2,
Expand All @@ -132,7 +132,7 @@ class JIRAResourceDelegation < SimpleDelegator # :nodoc:

context 'when there is only one page of results' do
let(:result_1) do
OpenStruct.new(body: {
double(body: {
'startAt' => 0,
'maxResults' => 2,
'total' => 2,
Expand Down
5 changes: 2 additions & 3 deletions spec/jira/resource/field_spec.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
require 'spec_helper'

describe JIRA::Resource::Field do
let(:cache) { OpenStruct.new }

let(:client) do
client = double(options: { rest_base_path: '/jira/rest/api/2' })
field = JIRA::Resource::FieldFactory.new(client)
allow(client).to receive(:Field).and_return(field)
allow(client).to receive(:cache).and_return(cache)
allow(client).to receive(:field_map_cache).and_return(nil)
allow(client).to receive(:field_map_cache=)
# info about all fields on the client
allow(client.Field).to receive(:all).and_return([
described_class.new(client,
Expand Down
2 changes: 1 addition & 1 deletion spec/jira/resource/issue_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class JIRAResourceDelegation < SimpleDelegator # :nodoc:
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))
allow(client).to receive(:cache).and_return(OpenStruct.new)
allow(client).to receive(:field_map_cache).and_return(nil)
client
end

Expand Down
2 changes: 1 addition & 1 deletion spec/jira/resource/status_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
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))
allow(client).to receive(:cache).and_return(OpenStruct.new)
allow(client).to receive(:field_map_cache).and_return(nil)
client
end

Expand Down
Loading