From 9e3f658c59bf6fc989b8c674e1ed078b392c398b Mon Sep 17 00:00:00 2001 From: Martin Gruner Date: Mon, 27 Apr 2026 14:02:18 +0200 Subject: [PATCH 1/3] Add rubocop --- .github/workflows/ci.yml | 15 +- .rubocop.yml | 205 ++++++------------ .rubocop_todo.yml | 47 ++++ Gemfile.lock | 39 ++++ lib/zammad_api/client.rb | 11 +- lib/zammad_api/dispatcher.rb | 1 - lib/zammad_api/list_all.rb | 1 - lib/zammad_api/list_base.rb | 14 +- lib/zammad_api/list_search.rb | 1 - lib/zammad_api/log.rb | 3 +- lib/zammad_api/resources.rb | 2 +- lib/zammad_api/resources/base.rb | 10 +- lib/zammad_api/resources/ticket.rb | 5 +- lib/zammad_api/resources/ticket_article.rb | 5 +- .../resources/ticket_article_attachment.rb | 5 +- lib/zammad_api/transport.rb | 10 +- spec/spec_helper.rb | 7 +- spec/zammad_api/client_spec.rb | 33 ++- spec/zammad_api/resources/group_spec.rb | 81 ++++--- spec/zammad_api/resources/list_base_spec.rb | 1 - .../zammad_api/resources/organization_spec.rb | 98 +++++---- .../resources/ticket_priority_spec.rb | 66 +++--- spec/zammad_api/resources/ticket_spec.rb | 107 ++++----- .../zammad_api/resources/ticket_state_spec.rb | 97 ++++----- spec/zammad_api/resources/user_spec.rb | 130 ++++++----- spec/zammad_api/transport_spec.rb | 26 +-- spec/zammad_api_spec.rb | 3 +- zammad_api.gemspec | 19 +- 28 files changed, 525 insertions(+), 517 deletions(-) create mode 100644 .rubocop_todo.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index dbb266a..07498e4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,7 +7,20 @@ on: # Run every on Friday to ensure everything works as expected. - cron: '0 6 * * 5' jobs: - CI: + lint: + runs-on: ubuntu-latest + container: + image: zammad/zammad-ci:latest + steps: + - uses: actions/checkout@v6 + - name: Run lint actions + shell: bash + run: | + source /etc/profile.d/rvm.sh # ensure RVM is loaded + bundle update --bundler + bundle install -j $(nproc) + bundle exec rubocop + test: runs-on: ubuntu-latest container: image: zammad/zammad-ci:latest diff --git a/.rubocop.yml b/.rubocop.yml index bd81feb..618ce33 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,21 +1,25 @@ # Default enabled cops # https://github.com/bbatsov/rubocop/blob/master/config/enabled.yml +plugins: + - rubocop-performance + - rubocop-rspec + +inherit_from: + - .rubocop_todo.yml + AllCops: + NewCops: enable Exclude: - 'bin/rails' - 'bin/rake' - 'bin/spring' - 'db/schema.rb' - -Rails: - Enabled: true + - 'examples/**/*' # Zammad StyleGuide -Metrics/LineLength: - Description: 'Limit lines to 80 characters.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#80-character-limits' +Style/FrozenStringLiteralComment: Enabled: false Style/NegatedIf: @@ -32,9 +36,13 @@ Style/IfUnlessModifier: StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#if-as-a-modifier' Enabled: false -Style/TrailingCommaInLiteral: - Description: 'Checks for trailing comma in array and hash literals.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-trailing-array-commas' +Style/TrailingCommaInArrayLiteral: + Description: 'Checks for trailing comma in array literals.' + StyleGuide: '#no-trailing-array-commas' + Enabled: false + +Style/TrailingCommaInHashLiteral: + Description: 'Checks for trailing comma in hash literals.' Enabled: false Style/TrailingCommaInArguments: @@ -42,71 +50,56 @@ Style/TrailingCommaInArguments: StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-trailing-array-commas' Enabled: false -Style/SpaceInsideParens: - Description: 'No spaces after ( or before ).' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-spaces-braces' - Enabled: false - -Style/SpaceAfterMethodName: - Description: >- - Do not put a space between a method name and the opening - parenthesis in a method definition. - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#parens-no-spaces' - Enabled: false - -Style/LeadingCommentSpace: +Layout/LeadingCommentSpace: Description: 'Comments should start with a space.' StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#hash-space' Enabled: false -Style/MethodCallParentheses: - Description: 'Do not use parentheses for method calls with no arguments.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-args-no-parens' - Enabled: false +Layout/HashAlignment: + Description: >- + Align the elements of a hash literal if they span more than + one line. + Enabled: true + EnforcedHashRocketStyle: table + EnforcedColonStyle: table + EnforcedLastArgumentHashStyle: always_inspect -Style/SpaceInsideBrackets: - Description: 'No spaces after [ or before ].' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-spaces-braces' +Style/ClassAndModuleChildren: + Description: 'Checks style of children classes and modules.' Enabled: false -Style/DefWithParentheses: - Description: 'Use def with parentheses when there are arguments.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#method-parens' - Enabled: false -Style/MethodDefParentheses: +Naming/MethodParameterName: Description: >- - Checks if the method definitions have or don't have - parentheses. - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#method-parens' - Enabled: false + Checks for method parameter names that contain capital letters, + end in numbers, or do not meet a minimal length. + Enabled: true + AllowedNames: [id] -Style/EmptyLinesAroundClassBody: - Description: "Keeps track of empty lines around class bodies." - Enabled: false +Layout/MultilineMethodCallIndentation: + Description: >- + Checks the indentation of the method name part in method calls + that span more than one line. + EnforcedStyle: indented -Style/EmptyLinesAroundMethodBody: - Description: "Keeps track of empty lines around method bodies." - Enabled: false +Style/RescueStandardError: + EnforcedStyle: implicit -Style/EmptyLinesAroundBlockBody: - Description: "Keeps track of empty lines around block bodies." +Style/Documentation: Enabled: false -Style/EmptyLinesAroundModuleBody: - Description: "Keeps track of empty lines around module bodies." +Style/PerlBackrefs: + Description: 'Avoid Perl-style regex back references.' + StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-perl-regexp-last-matchers' Enabled: false -Style/BlockDelimiters: - Description: >- - Avoid using {...} for multi-line blocks (multiline chaining is - always ugly). - Prefer {...} over do...end for single-line blocks. - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#single-line-blocks' +Style/BlockComments: + # Keep block comments (=begin ... =end) to allow for easy copy-pasting of examples. + Description: 'Do not use block comments.' Enabled: false -Style/MultilineBlockChain: - Description: 'Avoid multi-line chains of blocks.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#single-line-blocks' +Layout/LineLength: + Description: 'Limit lines to 80 characters.' + StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#80-character-limits' Enabled: false Metrics/ClassLength: @@ -118,98 +111,30 @@ Metrics/MethodLength: StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#short-methods' Enabled: false -Style/BlockComments: - Description: 'Do not use block comments.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-block-comments' - Enabled: false - -Style/PerlBackrefs: - Description: 'Avoid Perl-style regex back references.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-perl-regexp-last-matchers' - Enabled: false - -Style/SelfAssignment: - Description: >- - Checks for places where self-assignment shorthand should have - been used. - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#self-assignment' - Enabled: false - -Style/BracesAroundHashParameters: - Description: 'Enforce braces style around hash parameters.' - Enabled: false - -Rails/FindEach: - Description: 'Prefer all.find_each over all.find.' - Enabled: false - -Rails/HasAndBelongsToMany: - Description: 'Prefer has_many :through to has_and_belongs_to_many.' -# StyleGuide: 'https://github.com/bbatsov/rails-style-guide#has-many-through' - Enabled: false - -Style/ClassAndModuleChildren: - Description: 'Checks style of children classes and modules.' - Enabled: false - -Style/FileName: - Description: 'Use snake_case for source file names.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#snake-case-files' - Enabled: true - Exclude: - - 'script/websocket-server.rb' - - -# 2.0 - -Metrics/PerceivedComplexity: - Description: >- - A complexity metric geared towards measuring complexity for a - human reader. - Enabled: false - Metrics/AbcSize: - Description: >- - A calculated magnitude based on number of assignments, - branches, and conditions. - Enabled: false + Max: 34 Metrics/CyclomaticComplexity: - Description: >- - A complexity metric that is strongly correlated to the number - of test cases needed to validate a method. - Enabled: false - -Metrics/BlockNesting: - Description: 'Avoid excessive block nesting' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#three-is-the-number-thou-shalt-count' - Enabled: false + Max: 12 -Metrics/ModuleLength: - Description: 'Avoid modules longer than 100 lines of code.' - Enabled: false - -# TODO - -Style/Documentation: - Description: 'Document classes and non-namespace modules.' - Enabled: false +Metrics/PerceivedComplexity: + Max: 12 -Lint/UselessAssignment: - Enabled: false +RSpec/ExampleLength: + inherit_mode: + merge: + - Exclude + CountAsOne: + - 'array' + - 'hash' + - 'heredoc' + Max: 25 -Style/ExtraSpacing: - Description: 'Do not use unnecessary spacing.' - Enabled: false +RSpec/NestedGroups: + Max: 6 # Broken!!!! Generates broken code since "String".downcase == "strinG".downcase is not equals "String".casecmp("strinG") but "String".casecmp("strinG") == 0 !!! Performance/Casecmp: Description: 'Use `casecmp` rather than `downcase ==`.' Reference: 'https://github.com/JuanitoFatas/fast-ruby#stringcasecmp-vs-stringdowncase---code' Enabled: false - -# Disabled since we want that explicitly -Style/MethodMissing: - Description: 'Avoid using `method_missing`.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-method-missing' - Enabled: false diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml new file mode 100644 index 0000000..4945fff --- /dev/null +++ b/.rubocop_todo.yml @@ -0,0 +1,47 @@ +Gemspec/RequiredRubyVersion: + Enabled: false + +Gemspec/RequireMFA: + Enabled: false + +Gemspec/AddRuntimeDependency: + Enabled: false + +Gemspec/DevelopmentDependencies: + Enabled: false + +Naming/PredicateMethod: + Enabled: false + +Style/MissingRespondToMissing: + Enabled: false + +Style/StringConcatenation: + Enabled: false + +Naming/AccessorMethodName: + Enabled: false + +RSpec/MultipleExpectations: + Enabled: false + +RSpec/ExampleLength: + Enabled: false + +RSpec/SpecFilePathFormat: + Enabled: false + +RSpec/NoExpectationExample: + Enabled: false + +RSpec/DescribeMethod: + Enabled: false + +RSpec/ContextWording: + Enabled: false + +RSpec/BeforeAfterAll: + Enabled: false + +RSpec/LeakyLocalVariable: + Enabled: false diff --git a/Gemfile.lock b/Gemfile.lock index 02fbc99..fac704d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -9,6 +9,7 @@ GEM specs: addressable (2.9.0) public_suffix (>= 2.0.2, < 8.0) + ast (2.4.3) bigdecimal (4.1.2) crack (1.0.1) bigdecimal @@ -22,11 +23,21 @@ GEM net-http (~> 0.5) hashdiff (1.2.1) json (2.19.2) + language_server-protocol (3.17.0.5) + lint_roller (1.1.0) logger (1.7.0) net-http (0.9.1) uri (>= 0.11.1) + parallel (2.1.0) + parser (3.3.11.1) + ast (~> 2.4.1) + racc + prism (1.9.0) public_suffix (7.0.5) + racc (1.8.1) + rainbow (3.1.1) rake (13.4.2) + regexp_parser (2.12.0) rexml (3.4.4) rspec (3.13.2) rspec-core (~> 3.13.0) @@ -41,6 +52,31 @@ GEM diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.13.0) rspec-support (3.13.7) + rubocop (1.86.1) + json (~> 2.3) + language_server-protocol (~> 3.17.0.2) + lint_roller (~> 1.1.0) + parallel (>= 1.10) + parser (>= 3.3.0.2) + rainbow (>= 2.2.2, < 4.0) + regexp_parser (>= 2.9.3, < 3.0) + rubocop-ast (>= 1.49.0, < 2.0) + ruby-progressbar (~> 1.7) + unicode-display_width (>= 2.4.0, < 4.0) + rubocop-ast (1.49.1) + parser (>= 3.3.7.2) + prism (~> 1.7) + rubocop-performance (1.26.1) + lint_roller (~> 1.1) + rubocop (>= 1.75.0, < 2.0) + rubocop-ast (>= 1.47.1, < 2.0) + rubocop-rspec (3.9.0) + lint_roller (~> 1.1) + rubocop (~> 1.81) + ruby-progressbar (1.13.0) + unicode-display_width (3.2.0) + unicode-emoji (~> 4.1) + unicode-emoji (4.2.0) uri (1.1.1) webmock (3.26.2) addressable (>= 2.8.0) @@ -54,6 +90,9 @@ DEPENDENCIES bundler (>= 2.2.10) rake rspec + rubocop + rubocop-performance + rubocop-rspec webmock zammad_api! diff --git a/lib/zammad_api/client.rb b/lib/zammad_api/client.rb index b3827da..a2aba34 100644 --- a/lib/zammad_api/client.rb +++ b/lib/zammad_api/client.rb @@ -6,7 +6,6 @@ require 'zammad_api/resources' module ZammadAPI - class Client extend Forwardable @@ -27,7 +26,7 @@ def perform_on_behalf_of(identifier) end def method_missing(method, *_args) - method = modulize( method.to_s ) + method = modulize(method.to_s) class_name = "ZammadAPI::Resources::#{method}" begin class_object = Kernel.const_get(class_name) @@ -41,7 +40,7 @@ def method_missing(method, *_args) def check_config raise 'missing url in config' if !@config[:url] - raise 'config url needs to start with http:// or https://' if @config[:url] !~ %r{^(http|https)://} + raise 'config url needs to start with http:// or https://' if !%r{^(http|https)://}.match?(@config[:url]) # check for token auth return if @config[:http_token] && !@config[:http_token].empty? @@ -58,9 +57,9 @@ def check_config def modulize(string) string.gsub(/__(.?)/) { "::#{$1.upcase}" } - .gsub(%r{/(.?)}) { "::#{$1.upcase}" } - .gsub(/(?:_+|-+)([a-z])/) { $1.upcase } - .gsub(/(\A|\s)([a-z])/) { $1 + $2.upcase } + .gsub(%r{/(.?)}) { "::#{$1.upcase}" } + .gsub(/(?:_+|-+)([a-z])/) { $1.upcase } + .gsub(/(\A|\s)([a-z])/) { $1 + $2.upcase } end end end diff --git a/lib/zammad_api/dispatcher.rb b/lib/zammad_api/dispatcher.rb index 8872892..07b311b 100644 --- a/lib/zammad_api/dispatcher.rb +++ b/lib/zammad_api/dispatcher.rb @@ -1,6 +1,5 @@ module ZammadAPI class Dispatcher - def initialize(transport, resource) @transport = transport @resource = resource diff --git a/lib/zammad_api/list_all.rb b/lib/zammad_api/list_all.rb index cbf2d63..393c56a 100644 --- a/lib/zammad_api/list_all.rb +++ b/lib/zammad_api/list_all.rb @@ -2,7 +2,6 @@ module ZammadAPI class ListAll < ListBase - private def perform_request(parameter) diff --git a/lib/zammad_api/list_base.rb b/lib/zammad_api/list_base.rb index 7b70517..7ac483a 100644 --- a/lib/zammad_api/list_base.rb +++ b/lib/zammad_api/list_base.rb @@ -14,7 +14,6 @@ def initialize(resource, transport, parameter = {}) end def [](position) - local_parameter = @parameter.merge( page: position + 1, per_page: 1 @@ -23,7 +22,6 @@ def [](position) end def page(page, per_page, &block) - @parameter[:page] = page @parameter[:per_page] = per_page fetch_and_yield_each(&block) @@ -45,18 +43,14 @@ def each(&block) private - def fetch_and_yield_each + def fetch_and_yield_each(&block) result = perform_request(@parameter) - result.each { |item| - yield item - } + result.each(&block) end def request(request, url, parameter) - # convert parameters into a GET query url += '?' + parameter.map { |key, value| - if !value.is_a? String value = value.to_s end @@ -71,11 +65,11 @@ def request(request, url, parameter) end list = [] - data.each { |local_data| + data.each do |local_data| item = @resource.new(@transport, local_data) item.new_instance = false list.push item - } + end list end diff --git a/lib/zammad_api/list_search.rb b/lib/zammad_api/list_search.rb index 345bb2a..fac7f2b 100644 --- a/lib/zammad_api/list_search.rb +++ b/lib/zammad_api/list_search.rb @@ -2,7 +2,6 @@ module ZammadAPI class ListSearch < ListBase - private def perform_request(parameter) diff --git a/lib/zammad_api/log.rb b/lib/zammad_api/log.rb index bbdd57b..b67ad26 100644 --- a/lib/zammad_api/log.rb +++ b/lib/zammad_api/log.rb @@ -1,8 +1,8 @@ module ZammadAPI class Log - def initialize(config) return if !config[:logger] + require 'logger' @logger = Logger.new($stderr) #@logger.level = Logger::WARN @@ -11,6 +11,7 @@ def initialize(config) def method_missing(method, *args) return if !@logger + @logger.send(method, args) end end diff --git a/lib/zammad_api/resources.rb b/lib/zammad_api/resources.rb index d6ca2ca..8106a4d 100644 --- a/lib/zammad_api/resources.rb +++ b/lib/zammad_api/resources.rb @@ -12,6 +12,6 @@ require 'zammad_api/resources/ticket_priority' module ZammadAPI - class Resource + class Resource # rubocop:disable Lint/EmptyClass end end diff --git a/lib/zammad_api/resources/base.rb b/lib/zammad_api/resources/base.rb index 08ac31d..f329bfc 100644 --- a/lib/zammad_api/resources/base.rb +++ b/lib/zammad_api/resources/base.rb @@ -23,6 +23,7 @@ def initialize(transport, attributes = {}) def method_missing(method, *args) return @attributes[method] if !method.to_s.end_with?('=') + method = method.to_s[0, method.length - 1].to_sym @changes[method] = [@attributes[method], args[0]] @attributes[method] = args[0] @@ -43,6 +44,7 @@ def destroy data = JSON.parse(response.body) end return true if response.status == 200 + raise "Can't destroy object (#{self.class.name}): #{data['error']}" end @@ -78,6 +80,7 @@ def self.find(transport, id) if response.status != 200 raise "Can't find object (#{self.class.name}): #{data['error']}" end + item = new(transport, data) item.new_instance = false item @@ -99,6 +102,7 @@ def self.destroy(transport, id) def saved_attributes return save_new if @new_instance + save_existing end @@ -106,18 +110,20 @@ def save_new response = @transport.post(url: "#{@url}?expand=true", params: @attributes) attributes = JSON.parse(response.body) return attributes if response.status == 201 + save_error(attributes) end def save_existing attributes_to_post = {} - @changes.each { |name, values| + @changes.each do |name, values| attributes_to_post[name] = values[1] - } + end response = @transport.put(url: "#{@url}/#{@attributes[:id]}?expand=true", params: attributes_to_post) attributes = JSON.parse(response.body) return attributes if response.status == 200 + save_error(attributes) end diff --git a/lib/zammad_api/resources/ticket.rb b/lib/zammad_api/resources/ticket.rb index 8389319..8894ced 100644 --- a/lib/zammad_api/resources/ticket.rb +++ b/lib/zammad_api/resources/ticket.rb @@ -8,11 +8,11 @@ def articles raise "Can't get articles (#{self.class.name}): #{data['error']}" end - data.collect { |raw| + data.collect do |raw| item = ZammadAPI::Resources::TicketArticle.new(@transport, raw) item.new_instance = false item - } + end end def article(data) @@ -21,5 +21,4 @@ def article(data) item.save item end - end diff --git a/lib/zammad_api/resources/ticket_article.rb b/lib/zammad_api/resources/ticket_article.rb index 7892df4..890918b 100644 --- a/lib/zammad_api/resources/ticket_article.rb +++ b/lib/zammad_api/resources/ticket_article.rb @@ -2,11 +2,10 @@ class ZammadAPI::Resources::TicketArticle < ZammadAPI::Resources::Base url '/api/v1/ticket_articles' def attachments - @attributes[:attachments].collect { |raw| + @attributes[:attachments].collect do |raw| raw[:ticket_id] = @attributes[:ticket_id] raw[:article_id] = @attributes[:id] ZammadAPI::Resources::TicketArticleAttachment.new(@transport, raw) - } + end end - end diff --git a/lib/zammad_api/resources/ticket_article_attachment.rb b/lib/zammad_api/resources/ticket_article_attachment.rb index 4b9cbae..f0abb2e 100644 --- a/lib/zammad_api/resources/ticket_article_attachment.rb +++ b/lib/zammad_api/resources/ticket_article_attachment.rb @@ -1,6 +1,5 @@ class ZammadAPI::Resources::TicketArticleAttachment < ZammadAPI::Resources::Base - - def initialize(transport, attributes = {}) + def initialize(transport, attributes = {}) # rubocop:disable Lint/MissingSuper @transport = transport @attributes = attributes symbolize_keys_deep!(@attributes) @@ -13,8 +12,8 @@ def method_missing(method, *_args) def download response = @transport.get(url: "/api/v1/ticket_attachment/#{ticket_id}/#{article_id}/#{id}") return response.body if response.status == 200 + data = JSON.parse(response.body) raise "Can't get articles (#{self.class.name}): #{data['error']}" end - end diff --git a/lib/zammad_api/transport.rb b/lib/zammad_api/transport.rb index f7678f4..a0efa84 100644 --- a/lib/zammad_api/transport.rb +++ b/lib/zammad_api/transport.rb @@ -3,7 +3,6 @@ module ZammadAPI class Transport - attr_accessor :url, :user, :password, :on_behalf_of def initialize(config, logger) @@ -12,7 +11,7 @@ def initialize(config, logger) @conn = Faraday.new(url: config[:url]) do |faraday| #faraday.request :url_encoded # form-encode POST params #faraday.response :logger # log requests to STDOUT - faraday.adapter Faraday.default_adapter # make requests with Net::HTTP + faraday.adapter Faraday.default_adapter # make requests with Net::HTTP end @conn.headers[:user_agent] = 'Zammad API Ruby' if config[:http_token] && !config[:http_token].empty? @@ -26,16 +25,15 @@ def initialize(config, logger) %w[get post put delete].each do |method| class_eval <<-RUBY, __FILE__, __LINE__ + 1 - def #{method}(params) - run_request(:#{method}, params) - end + def #{method}(params) # def get(params) + run_request(:#{method}, params) # run_request(:get, params) + end # end RUBY end private def run_request(verb, param) - @logger.debug "#{verb.to_s.upcase}: #{@url}#{param[:url]}" with_params = !param[:params].nil? diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 12ff936..6c318c4 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,4 +1,4 @@ -$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__) +$LOAD_PATH.unshift File.expand_path('../lib', __dir__) # we don't require 'webmock/rspec' over here # since we want to mock only certain requests @@ -13,7 +13,6 @@ require 'zammad_api' class Helper - def self.config { url: ENV['TEST_URL'] || 'http://localhost:3000/', @@ -32,8 +31,8 @@ def self.client(params = {}) # start auto wizard def self.auto_wizard - conn = Faraday.new(url: config[:url] ) do |faraday| - faraday.adapter Faraday.default_adapter # make requests with Net::HTTP + conn = Faraday.new(url: config[:url]) do |faraday| + faraday.adapter Faraday.default_adapter # make requests with Net::HTTP end url_auto_wizard = '/api/v1/getting_started/auto_wizard' diff --git a/spec/zammad_api/client_spec.rb b/spec/zammad_api/client_spec.rb index 3c2ae33..d213b1e 100644 --- a/spec/zammad_api/client_spec.rb +++ b/spec/zammad_api/client_spec.rb @@ -2,7 +2,6 @@ require 'logger' describe ZammadAPI::Client do - before(:all) do WebMock.enable! end @@ -11,24 +10,22 @@ WebMock.disable! end - after(:each) do + after do WebMock.reset! end let(:config) { Helper.config } let(:instance) { described_class.new(config) } - context '#perform_on_behalf_of' do - + describe '#perform_on_behalf_of' do it 'performs a given block on behalft of a given user' do - on_behalf_of_identifier = 'some_login' - stub_request(:get, /#{config[:url]}/). - with( headers: { - 'X-On-Behalf-Of' => on_behalf_of_identifier - }). - to_return(status: 200, body: '{}', headers: {}) + stub_request(:get, /#{config[:url]}/) + .with(headers: { + 'X-On-Behalf-Of' => on_behalf_of_identifier + }) + .to_return(status: 200, body: '{}', headers: {}) instance.perform_on_behalf_of(on_behalf_of_identifier) do instance.user.find(1) @@ -36,15 +33,14 @@ end it "doesn't affect later requests outside of the block" do - # first perform request on behalf of a login on_behalf_of_identifier = 'some_login' - stub_request(:get, /#{config[:url]}/). - with( headers: { - 'X-On-Behalf-Of' => on_behalf_of_identifier - }). - to_return(status: 200, body: '{}', headers: {}) + stub_request(:get, /#{config[:url]}/) + .with(headers: { + 'X-On-Behalf-Of' => on_behalf_of_identifier + }) + .to_return(status: 200, body: '{}', headers: {}) instance.perform_on_behalf_of(on_behalf_of_identifier) do instance.user.find(1) @@ -52,8 +48,8 @@ # now without and check that # the header isn't set anymore - stub = stub_request(:get, /#{config[:url]}/). - to_return(status: 200, body: '{}', headers: {}) + stub = stub_request(:get, /#{config[:url]}/) + .to_return(status: 200, body: '{}', headers: {}) # this is kind of a hack/workaround to check if the # header was not set/send since webmock doesn't support @@ -62,6 +58,7 @@ def request_pattern.matches?(request_signature) return false if !super return true if request_signature.headers.empty? + !request_signature.headers.key?('X-On-Behalf-Of') end diff --git a/spec/zammad_api/resources/group_spec.rb b/spec/zammad_api/resources/group_spec.rb index 67300bc..9c1d2d9 100644 --- a/spec/zammad_api/resources/group_spec.rb +++ b/spec/zammad_api/resources/group_spec.rb @@ -1,52 +1,52 @@ require 'spec_helper' describe ZammadAPI, 'group object basics' do - client = Helper.client() + client = Helper.client - name = "some_group#{Helper.random()}" + name = "some_group#{Helper.random}" group = nil it 'new with invalid attributes' do - group_invalid = client.group.new() + group_invalid = client.group.new expect(group_invalid.class).to eq(ZammadAPI::Resources::Group) - expect(group_invalid.new_record?).to eq(true) + expect(group_invalid.new_record?).to be(true) expect { group_invalid.save }.to raise_error(RuntimeError) end it 'new with valid attributes' do group = client.group.new( - name: name, - assignment_timeout: 100, + name: name, + assignment_timeout: 100, follow_up_assignment: false, - follow_up_possible: 'yes', - note: '', - active: true, + follow_up_possible: 'yes', + note: '', + active: true, ) expect(group.class).to eq(ZammadAPI::Resources::Group) - expect(group.new_record?).to eq(true) - expect(group.id).to eq(nil) + expect(group.new_record?).to be(true) + expect(group.id).to be_nil expect(group.name).to eq(name) expect(group.assignment_timeout).to eq(100) - expect(group.follow_up_assignment).to eq(false) + expect(group.follow_up_assignment).to be(false) expect(group.follow_up_possible).to eq('yes') expect(group.note).to eq('') - expect(group.active).to eq(true) + expect(group.active).to be(true) end it 'save' do result = group.save - expect(result).to eq(true) - expect(group.id).not_to eq(nil) + expect(result).to be(true) + expect(group.id).not_to be_nil expect(group.name).to eq(name) expect(group.assignment_timeout).to eq(100) - expect(group.follow_up_assignment).to eq(false) + expect(group.follow_up_assignment).to be(false) expect(group.follow_up_possible).to eq('yes') expect(group.note).to eq('') - expect(group.active).to eq(true) + expect(group.active).to be(true) group.name = "#{name}-2" group.note = 'some note' @@ -54,26 +54,25 @@ group.active = false changes = group.changes - expect(changes.key?(:follow_up_possible)).to eq(false) + expect(changes.key?(:follow_up_possible)).to be(false) expect(changes[:name][0]).to eq(name) expect(changes[:name][1]).to eq("#{name}-2") expect(changes[:assignment_timeout][0]).to eq(100) expect(changes[:assignment_timeout][1]).to eq(4711) expect(changes[:note][0]).to eq('') expect(changes[:note][1]).to eq('some note') - expect(changes[:active][0]).to eq(true) - expect(changes[:active][1]).to eq(false) + expect(changes[:active][0]).to be(true) + expect(changes[:active][1]).to be(false) result = group.save - expect(result).to eq(true) - expect(group.id).to eq(group.id) + expect(result).to be(true) + expect(group.id).to be_present expect(group.name).to eq("#{name}-2") expect(group.assignment_timeout).to eq(4711) - expect(group.follow_up_assignment).to eq(false) + expect(group.follow_up_assignment).to be(false) expect(group.follow_up_possible).to eq('yes') expect(group.note).to eq('some note') - expect(group.active).to eq(false) - + expect(group.active).to be(false) end it 'find' do @@ -83,28 +82,29 @@ expect(group_lookup.id).to eq(group.id) expect(group_lookup.name).to eq("#{name}-2") expect(group_lookup.assignment_timeout).to eq(4711) - expect(group_lookup.follow_up_assignment).to eq(false) + expect(group_lookup.follow_up_assignment).to be(false) expect(group_lookup.follow_up_possible).to eq('yes') expect(group_lookup.note).to eq('some note') - expect(group_lookup.active).to eq(false) + expect(group_lookup.active).to be(false) end it 'all' do groups = client.group.all group_exists = nil - groups.each { |local_group| + groups.each do |local_group| next if local_group.id != group.id + group_exists = local_group - } + end expect(group_exists.class).to eq(ZammadAPI::Resources::Group) expect(group_exists.id).to eq(group.id) expect(group_exists.name).to eq("#{name}-2") expect(group_exists.assignment_timeout).to eq(4711) - expect(group_exists.follow_up_assignment).to eq(false) + expect(group_exists.follow_up_assignment).to be(false) expect(group_exists.follow_up_possible).to eq('yes') expect(group_exists.note).to eq('some note') - expect(group_exists.active).to eq(false) + expect(group_exists.active).to be(false) group_exists.active = true group_exists.save @@ -114,10 +114,10 @@ expect(group_lookup.id).to eq(group.id) expect(group_lookup.name).to eq("#{name}-2") expect(group_lookup.assignment_timeout).to eq(4711) - expect(group_lookup.follow_up_assignment).to eq(false) + expect(group_lookup.follow_up_assignment).to be(false) expect(group_lookup.follow_up_possible).to eq('yes') expect(group_lookup.note).to eq('some note') - expect(group_lookup.active).to eq(true) + expect(group_lookup.active).to be(true) end it 'pagination with all' do @@ -126,30 +126,29 @@ expect(groups[0].class).to eq(ZammadAPI::Resources::Group) count = 0 - groups.each { |local_group| + groups.each do |local_group| expect(local_group.class).to eq(ZammadAPI::Resources::Group) count += 1 - } + end expect(count).to eq(3) count = 0 groups = client.group.all - groups.page(1, 3) { |local_group| + groups.page(1, 3) do |local_group| expect(local_group.class).to eq(ZammadAPI::Resources::Group) count += 1 - } + end expect(count).to eq(3) - groups.page(2, 3) { |local_group| + groups.page(2, 3) do |local_group| expect(local_group.class).to eq(ZammadAPI::Resources::Group) count += 1 - } + end expect(count).to eq(3) end it 'destroy' do result = group.destroy - expect(result).to eq(true) + expect(result).to be(true) end - end diff --git a/spec/zammad_api/resources/list_base_spec.rb b/spec/zammad_api/resources/list_base_spec.rb index bfef103..c7018e3 100644 --- a/spec/zammad_api/resources/list_base_spec.rb +++ b/spec/zammad_api/resources/list_base_spec.rb @@ -1,7 +1,6 @@ require 'spec_helper' describe ZammadAPI::ListBase do - it 'is a Enumerable' do expect(described_class.ancestors).to include(Enumerable) end diff --git a/spec/zammad_api/resources/organization_spec.rb b/spec/zammad_api/resources/organization_spec.rb index 423c936..d63718f 100644 --- a/spec/zammad_api/resources/organization_spec.rb +++ b/spec/zammad_api/resources/organization_spec.rb @@ -1,46 +1,46 @@ require 'spec_helper' describe ZammadAPI, 'organization object basics' do - client = Helper.client() + client = Helper.client - name = "some_organization#{Helper.random()}" + name = "some_organization#{Helper.random}" organization = nil it 'new with invalid attributes' do - organization_invalid = client.organization.new() + organization_invalid = client.organization.new expect(organization_invalid.class).to eq(ZammadAPI::Resources::Organization) - expect(organization_invalid.new_record?).to eq(true) + expect(organization_invalid.new_record?).to be(true) expect { organization_invalid.save }.to raise_error(RuntimeError) end it 'new with valid attributes' do organization = client.organization.new( - name: name, + name: name, shared: false, - note: '', + note: '', active: true, ) expect(organization.class).to eq(ZammadAPI::Resources::Organization) - expect(organization.new_record?).to eq(true) - expect(organization.id).to eq(nil) + expect(organization.new_record?).to be(true) + expect(organization.id).to be_nil expect(organization.name).to eq(name) - expect(organization.shared).to eq(false) + expect(organization.shared).to be(false) expect(organization.note).to eq('') - expect(organization.active).to eq(true) + expect(organization.active).to be(true) end it 'save' do result = organization.save - expect(result).to eq(true) - expect(organization.id).not_to eq(nil) + expect(result).to be(true) + expect(organization.id).not_to be_nil expect(organization.name).to eq(name) - expect(organization.shared).to eq(false) + expect(organization.shared).to be(false) expect(organization.note).to eq('') - expect(organization.active).to eq(true) + expect(organization.active).to be(true) expect(organization.created_by).to eq('admin@example.com') expect(organization.updated_by).to eq('admin@example.com') @@ -50,23 +50,23 @@ organization.active = false changes = organization.changes - expect(changes.key?(:not_existing)).to eq(false) + expect(changes.key?(:not_existing)).to be(false) expect(changes[:name][0]).to eq(name) expect(changes[:name][1]).to eq("#{name}-2") - expect(changes[:shared][0]).to eq(false) - expect(changes[:shared][1]).to eq(true) + expect(changes[:shared][0]).to be(false) + expect(changes[:shared][1]).to be(true) expect(changes[:note][0]).to eq('') expect(changes[:note][1]).to eq('some note') - expect(changes[:active][0]).to eq(true) - expect(changes[:active][1]).to eq(false) + expect(changes[:active][0]).to be(true) + expect(changes[:active][1]).to be(false) result = organization.save - expect(result).to eq(true) - expect(organization.id).to eq(organization.id) + expect(result).to be(true) + expect(organization.id).to be_present expect(organization.name).to eq("#{name}-2") - expect(organization.shared).to eq(true) + expect(organization.shared).to be(true) expect(organization.note).to eq('some note') - expect(organization.active).to eq(false) + expect(organization.active).to be(false) expect(organization.created_by).to eq('admin@example.com') expect(organization.updated_by).to eq('admin@example.com') end @@ -77,9 +77,9 @@ expect(organization_lookup.class).to eq(ZammadAPI::Resources::Organization) expect(organization_lookup.id).to eq(organization.id) expect(organization_lookup.name).to eq("#{name}-2") - expect(organization_lookup.shared).to eq(true) + expect(organization_lookup.shared).to be(true) expect(organization_lookup.note).to eq('some note') - expect(organization_lookup.active).to eq(false) + expect(organization_lookup.active).to be(false) expect(organization_lookup.created_by).to eq('admin@example.com') expect(organization_lookup.updated_by).to eq('admin@example.com') end @@ -88,15 +88,16 @@ organizations = client.organization.all organization_exists = nil - organizations.each { |local_organization| + organizations.each do |local_organization| next if local_organization.id != organization.id + organization_exists = local_organization - } + end expect(organization_exists.class).to eq(ZammadAPI::Resources::Organization) expect(organization_exists.id).to eq(organization.id) expect(organization_exists.name).to eq("#{name}-2") expect(organization_exists.note).to eq('some note') - expect(organization_exists.active).to eq(false) + expect(organization_exists.active).to be(false) expect(organization_exists.created_by).to eq('admin@example.com') expect(organization_exists.updated_by).to eq('admin@example.com') @@ -108,7 +109,7 @@ expect(organization_lookup.id).to eq(organization.id) expect(organization_lookup.name).to eq("#{name}-2") expect(organization_lookup.note).to eq('some note') - expect(organization_lookup.active).to eq(true) + expect(organization_lookup.active).to be(true) expect(organization_lookup.created_by).to eq('admin@example.com') expect(organization_lookup.updated_by).to eq('admin@example.com') end @@ -119,23 +120,23 @@ expect(organizations[0].class).to eq(ZammadAPI::Resources::Organization) count = 0 - organizations.each { |local_organization| + organizations.each do |local_organization| expect(local_organization.class).to eq(ZammadAPI::Resources::Organization) count += 1 - } + end expect(count).to eq(2) count = 0 organizations = client.organization.all - organizations.page(1, 3) { |local_organization| + organizations.page(1, 3) do |local_organization| expect(local_organization.class).to eq(ZammadAPI::Resources::Organization) count += 1 - } + end expect(count).to eq(2) - organizations.page(2, 3) { |local_organization| + organizations.page(2, 3) do |local_organization| expect(local_organization.class).to eq(ZammadAPI::Resources::Organization) count += 1 - } + end expect(count).to eq(2) end @@ -143,15 +144,16 @@ organizations = client.organization.search(query: name) organization_exists = nil - organizations.each { |local_organization| + organizations.each do |local_organization| next if local_organization.id != organization.id + organization_exists = local_organization - } + end expect(organization_exists.class).to eq(ZammadAPI::Resources::Organization) expect(organization_exists.id).to eq(organization.id) expect(organization_exists.name).to eq("#{name}-2") expect(organization_exists.note).to eq('some note') - expect(organization_exists.active).to eq(true) + expect(organization_exists.active).to be(true) expect(organization_exists.created_by).to eq('admin@example.com') expect(organization_exists.updated_by).to eq('admin@example.com') @@ -163,7 +165,7 @@ expect(organization_lookup.id).to eq(organization.id) expect(organization_lookup.name).to eq("#{name}-2") expect(organization_lookup.note).to eq('some note') - expect(organization_lookup.active).to eq(false) + expect(organization_lookup.active).to be(false) expect(organization_lookup.created_by).to eq('admin@example.com') expect(organization_lookup.updated_by).to eq('admin@example.com') end @@ -175,39 +177,39 @@ count = 0 organization_exists = nil - organizations.each { |local_organization| + organizations.each do |local_organization| expect(local_organization.class).to eq(ZammadAPI::Resources::Organization) count += 1 next if local_organization.id != organization.id + organization_exists = local_organization - } + end expect(count).to eq(1) expect(organization_exists.class).to eq(ZammadAPI::Resources::Organization) expect(organization_exists.id).to eq(organization.id) expect(organization_exists.name).to eq("#{name}-2") expect(organization_exists.note).to eq('some note') - expect(organization_exists.active).to eq(false) + expect(organization_exists.active).to be(false) expect(organization_exists.created_by).to eq('admin@example.com') expect(organization_exists.updated_by).to eq('admin@example.com') count = 0 organizations = client.organization.search(query: 'zammad') - organizations.page(1, 3) { |local_organization| + organizations.page(1, 3) do |local_organization| expect(local_organization.class).to eq(ZammadAPI::Resources::Organization) count += 1 - } + end expect(count).to eq(1) - organizations.page(2, 3) { |local_organization| + organizations.page(2, 3) do |local_organization| expect(local_organization.class).to eq(ZammadAPI::Resources::Organization) count += 1 - } + end expect(count).to eq(1) end it 'destroy' do result = organization.destroy - expect(result).to eq(true) + expect(result).to be(true) end - end diff --git a/spec/zammad_api/resources/ticket_priority_spec.rb b/spec/zammad_api/resources/ticket_priority_spec.rb index 0b90c5b..1a2868c 100644 --- a/spec/zammad_api/resources/ticket_priority_spec.rb +++ b/spec/zammad_api/resources/ticket_priority_spec.rb @@ -1,63 +1,63 @@ require 'spec_helper' describe ZammadAPI, 'ticket priority object basics' do - client = Helper.client() + client = Helper.client - name = "some_ticket_priority#{Helper.random()}" + name = "some_ticket_priority#{Helper.random}" ticket_priority = nil it 'new with invalid attributes' do - ticket_priority_invalid = client.ticket_priority.new() + ticket_priority_invalid = client.ticket_priority.new expect(ticket_priority_invalid.class).to eq(ZammadAPI::Resources::TicketPriority) - expect(ticket_priority_invalid.new_record?).to eq(true) + expect(ticket_priority_invalid.new_record?).to be(true) expect { ticket_priority_invalid.save }.to raise_error(RuntimeError) end it 'new with valid attributes' do ticket_priority = client.ticket_priority.new( - name: name, - note: '', + name: name, + note: '', active: true, ) expect(ticket_priority.class).to eq(ZammadAPI::Resources::TicketPriority) - expect(ticket_priority.new_record?).to eq(true) - expect(ticket_priority.id).to eq(nil) + expect(ticket_priority.new_record?).to be(true) + expect(ticket_priority.id).to be_nil expect(ticket_priority.name).to eq(name) expect(ticket_priority.note).to eq('') - expect(ticket_priority.active).to eq(true) + expect(ticket_priority.active).to be(true) end it 'save' do result = ticket_priority.save - expect(result).to eq(true) - expect(ticket_priority.id).not_to eq(nil) + expect(result).to be(true) + expect(ticket_priority.id).not_to be_nil expect(ticket_priority.name).to eq(name) expect(ticket_priority.note).to eq('') - expect(ticket_priority.active).to eq(true) + expect(ticket_priority.active).to be(true) ticket_priority.name = "#{name}-2" ticket_priority.note = 'some note' ticket_priority.active = false changes = ticket_priority.changes - expect(changes.key?(:not_existing)).to eq(false) + expect(changes.key?(:not_existing)).to be(false) expect(changes[:name][0]).to eq(name) expect(changes[:name][1]).to eq("#{name}-2") expect(changes[:note][0]).to eq('') expect(changes[:note][1]).to eq('some note') - expect(changes[:active][0]).to eq(true) - expect(changes[:active][1]).to eq(false) + expect(changes[:active][0]).to be(true) + expect(changes[:active][1]).to be(false) result = ticket_priority.save - expect(result).to eq(true) - expect(ticket_priority.id).to eq(ticket_priority.id) + expect(result).to be(true) + expect(ticket_priority.id).to be_present expect(ticket_priority.name).to eq("#{name}-2") expect(ticket_priority.note).to eq('some note') - expect(ticket_priority.active).to eq(false) + expect(ticket_priority.active).to be(false) end it 'find' do @@ -67,22 +67,23 @@ expect(ticket_priority_lookup.id).to eq(ticket_priority.id) expect(ticket_priority_lookup.name).to eq("#{name}-2") expect(ticket_priority_lookup.note).to eq('some note') - expect(ticket_priority_lookup.active).to eq(false) + expect(ticket_priority_lookup.active).to be(false) end it 'all' do ticket_priorities = client.ticket_priority.all ticket_priority_exists = nil - ticket_priorities.each { |local_ticket_priority| + ticket_priorities.each do |local_ticket_priority| next if local_ticket_priority.id != ticket_priority.id + ticket_priority_exists = local_ticket_priority - } + end expect(ticket_priority_exists.class).to eq(ZammadAPI::Resources::TicketPriority) expect(ticket_priority_exists.id).to eq(ticket_priority.id) expect(ticket_priority_exists.name).to eq("#{name}-2") expect(ticket_priority_exists.note).to eq('some note') - expect(ticket_priority_exists.active).to eq(false) + expect(ticket_priority_exists.active).to be(false) ticket_priority_exists.active = true ticket_priority_exists.save @@ -92,7 +93,7 @@ expect(ticket_priority_lookup.id).to eq(ticket_priority.id) expect(ticket_priority_lookup.name).to eq("#{name}-2") expect(ticket_priority_lookup.note).to eq('some note') - expect(ticket_priority_lookup.active).to eq(true) + expect(ticket_priority_lookup.active).to be(true) end it 'pagination with all' do @@ -101,35 +102,34 @@ expect(ticket_priorities[0].class).to eq(ZammadAPI::Resources::TicketPriority) count = 0 - ticket_priorities.each { |local_ticket_priority| + ticket_priorities.each do |local_ticket_priority| expect(local_ticket_priority.class).to eq(ZammadAPI::Resources::TicketPriority) count += 1 - } + end expect(count).to eq(4) count = 0 ticket_priorities = client.ticket_priority.all - ticket_priorities.page(1, 2) { |local_ticket_priority| + ticket_priorities.page(1, 2) do |local_ticket_priority| expect(local_ticket_priority.class).to eq(ZammadAPI::Resources::TicketPriority) count += 1 - } + end expect(count).to eq(2) - ticket_priorities.page(2, 2) { |local_ticket_priority| + ticket_priorities.page(2, 2) do |local_ticket_priority| expect(local_ticket_priority.class).to eq(ZammadAPI::Resources::TicketPriority) count += 1 - } + end expect(count).to eq(4) - ticket_priorities.page(3, 2) { |local_ticket_priority| + ticket_priorities.page(3, 2) do |local_ticket_priority| expect(local_ticket_priority.class).to eq(ZammadAPI::Resources::TicketPriority) count += 1 - } + end expect(count).to eq(4) end it 'destroy' do result = ticket_priority.destroy - expect(result).to eq(true) + expect(result).to be(true) end - end diff --git a/spec/zammad_api/resources/ticket_spec.rb b/spec/zammad_api/resources/ticket_spec.rb index 0e0e219..3098e8c 100644 --- a/spec/zammad_api/resources/ticket_spec.rb +++ b/spec/zammad_api/resources/ticket_spec.rb @@ -1,40 +1,40 @@ require 'spec_helper' describe ZammadAPI, 'ticket object basics' do - client = Helper.client() + client = Helper.client - title = "some ticket title ##{Helper.random()}" + title = "some ticket title ##{Helper.random}" ticket = nil it 'new with invalid attributes' do - ticket_invalid = client.ticket.new() + ticket_invalid = client.ticket.new expect(ticket_invalid.class).to eq(ZammadAPI::Resources::Ticket) - expect(ticket_invalid.new_record?).to eq(true) + expect(ticket_invalid.new_record?).to be(true) expect { ticket_invalid.save }.to raise_error(RuntimeError) end it 'new with valid attributes' do ticket = client.ticket.new( - title: title, - state: 'new', + title: title, + state: 'new', priority: '2 normal', - owner: '-', + owner: '-', customer: 'nicole.braun@zammad.org', - group: 'Users', - article: { - sender: 'Customer', - type: 'note', - subject: 'some subject', + group: 'Users', + article: { + sender: 'Customer', + type: 'note', + subject: 'some subject', content_type: 'text/plain', - body: 'some body', + body: 'some body', } ) expect(ticket.class).to eq(ZammadAPI::Resources::Ticket) - expect(ticket.new_record?).to eq(true) - expect(ticket.id).to eq(nil) + expect(ticket.new_record?).to be(true) + expect(ticket.id).to be_nil expect(ticket.title).to eq(title) expect(ticket.state).to eq('new') expect(ticket.group).to eq('Users') @@ -44,9 +44,9 @@ it 'save' do result = ticket.save - expect(result).to eq(true) - expect(ticket.new_record?).to eq(false) - expect(ticket.id).not_to eq(nil) + expect(result).to be(true) + expect(ticket.new_record?).to be(false) + expect(ticket.id).not_to be_nil expect(ticket.title).to eq(title) expect(ticket.state).to eq('new') expect(ticket.state_id).to eq(1) @@ -59,17 +59,17 @@ ticket.state = 'open' changes = ticket.changes - expect(changes.key?(:state_id)).to eq(false) - expect(changes.key?(:state)).to eq(true) + expect(changes.key?(:state_id)).to be(false) + expect(changes.key?(:state)).to be(true) expect(changes[:title][0]).to eq(title) expect(changes[:title][1]).to eq("#{title}-2") expect(changes[:state][0]).to eq('new') expect(changes[:state][1]).to eq('open') result = ticket.save - expect(result).to eq(true) - expect(ticket.new_record?).to eq(false) - expect(ticket.id).to eq(ticket.id) + expect(result).to be(true) + expect(ticket.new_record?).to be(false) + expect(ticket.id).to be_present expect(ticket.title).to eq("#{title}-2") expect(ticket.state).to eq('open') expect(ticket.state_id).to eq(2) @@ -86,7 +86,7 @@ ticket.article( subject: 'some subject2', - body: 'some body2', + body: 'some body2', ) articles = ticket.articles @@ -97,12 +97,14 @@ expect(articles[1].attachments.count).to eq(0) ticket.article( - subject: 'some subject3', - body: 'some body3', + subject: 'some subject3', + body: 'some body3', attachments: [ - 'filename' => 'some_file.txt', - 'data' => 'dGVzdCAxMjM=', - 'mime-type' => 'text/plain', + { + 'filename' => 'some_file.txt', + 'data' => 'dGVzdCAxMjM=', + 'mime-type' => 'text/plain' + }, ] ) @@ -136,10 +138,11 @@ tickets = client.ticket.all ticket_exists = nil - tickets.each { |local_ticket| + tickets.each do |local_ticket| next if local_ticket.id != ticket.id + ticket_exists = local_ticket - } + end expect(ticket_exists.class).to eq(ZammadAPI::Resources::Ticket) expect(ticket_exists.id).to eq(ticket.id) expect(ticket_exists.title).to eq("#{title}-2") @@ -166,57 +169,55 @@ end it 'pagination with all' do - - (1..10).each { |local_count| + (1..10).each do |local_count| client.ticket.create( - title: "test count ticket #{local_count}", - state: 'new', + title: "test count ticket #{local_count}", + state: 'new', priority: '2 normal', - owner: '-', + owner: '-', customer: 'nicole.braun@zammad.org', - group: 'Users', - article: { - sender: 'Customer', - type: 'note', - subject: 'some subject', + group: 'Users', + article: { + sender: 'Customer', + type: 'note', + subject: 'some subject', content_type: 'text/plain', - body: 'some body', + body: 'some body', } ) - } + end tickets = client.ticket.all expect(tickets[0].class).to eq(ZammadAPI::Resources::Ticket) count = 0 - tickets.each { |local_ticket| + tickets.each do |local_ticket| expect(local_ticket.class).to eq(ZammadAPI::Resources::Ticket) count += 1 - } + end expect(count).to eq(12) count = 0 tickets = client.ticket.all - tickets.page(1, 5) { |local_ticket| + tickets.page(1, 5) do |local_ticket| expect(local_ticket.class).to eq(ZammadAPI::Resources::Ticket) count += 1 - } + end expect(count).to eq(5) - tickets.page(2, 5) { |local_ticket| + tickets.page(2, 5) do |local_ticket| expect(local_ticket.class).to eq(ZammadAPI::Resources::Ticket) count += 1 - } + end expect(count).to eq(10) - tickets.page(3, 5) { |local_ticket| + tickets.page(3, 5) do |local_ticket| expect(local_ticket.class).to eq(ZammadAPI::Resources::Ticket) count += 1 - } + end expect(count).to eq(12) end it 'destroy' do result = ticket.destroy - expect(result).to eq(true) + expect(result).to be(true) end - end diff --git a/spec/zammad_api/resources/ticket_state_spec.rb b/spec/zammad_api/resources/ticket_state_spec.rb index 546756d..6a8d90b 100644 --- a/spec/zammad_api/resources/ticket_state_spec.rb +++ b/spec/zammad_api/resources/ticket_state_spec.rb @@ -1,54 +1,54 @@ require 'spec_helper' describe ZammadAPI, 'ticket state object basics' do - client = Helper.client() + client = Helper.client - name = "some_ticket_state#{Helper.random()}" + name = "some_ticket_state#{Helper.random}" ticket_state = nil it 'new with invalid attributes' do - ticket_state_invalid = client.ticket_state.new() + ticket_state_invalid = client.ticket_state.new expect(ticket_state_invalid.class).to eq(ZammadAPI::Resources::TicketState) - expect(ticket_state_invalid.new_record?).to eq(true) + expect(ticket_state_invalid.new_record?).to be(true) expect { ticket_state_invalid.save }.to raise_error(RuntimeError) end it 'new with valid attributes' do ticket_state = client.ticket_state.new( - name: name, - state_type: 'new', - next_state_id: nil, + name: name, + state_type: 'new', + next_state_id: nil, ignore_escalation: false, - note: '', - active: true, + note: '', + active: true, ) expect(ticket_state.class).to eq(ZammadAPI::Resources::TicketState) - expect(ticket_state.new_record?).to eq(true) - expect(ticket_state.id).to eq(nil) + expect(ticket_state.new_record?).to be(true) + expect(ticket_state.id).to be_nil expect(ticket_state.name).to eq(name) expect(ticket_state.state_type).to eq('new') - expect(ticket_state.state_type_id).to eq(nil) - expect(ticket_state.next_state_id).to eq(nil) - expect(ticket_state.ignore_escalation).to eq(false) + expect(ticket_state.state_type_id).to be_nil + expect(ticket_state.next_state_id).to be_nil + expect(ticket_state.ignore_escalation).to be(false) expect(ticket_state.note).to eq('') - expect(ticket_state.active).to eq(true) + expect(ticket_state.active).to be(true) end it 'save' do result = ticket_state.save - expect(result).to eq(true) - expect(ticket_state.id).not_to eq(nil) + expect(result).to be(true) + expect(ticket_state.id).not_to be_nil expect(ticket_state.name).to eq(name) expect(ticket_state.state_type).to eq('new') expect(ticket_state.state_type_id).to eq(1) - expect(ticket_state.next_state_id).to eq(nil) - expect(ticket_state.ignore_escalation).to eq(false) + expect(ticket_state.next_state_id).to be_nil + expect(ticket_state.ignore_escalation).to be(false) expect(ticket_state.note).to eq('') - expect(ticket_state.active).to eq(true) + expect(ticket_state.active).to be(true) expect(ticket_state.created_by).to eq('admin@example.com') expect(ticket_state.updated_by).to eq('admin@example.com') @@ -60,32 +60,32 @@ ticket_state.active = false changes = ticket_state.changes - expect(changes.key?(:next_state_id)).to eq(false) - expect(changes.key?(:next_state)).to eq(true) + expect(changes.key?(:next_state_id)).to be(false) + expect(changes.key?(:next_state)).to be(true) expect(changes[:name][0]).to eq(name) expect(changes[:name][1]).to eq("#{name}-2") expect(changes[:state_type][0]).to eq('new') expect(changes[:state_type][1]).to eq('open') - expect(changes[:next_state][0]).to eq(nil) + expect(changes[:next_state][0]).to be_nil expect(changes[:next_state][1]).to eq('closed') - expect(changes[:ignore_escalation][0]).to eq(false) - expect(changes[:ignore_escalation][1]).to eq(true) + expect(changes[:ignore_escalation][0]).to be(false) + expect(changes[:ignore_escalation][1]).to be(true) expect(changes[:note][0]).to eq('') expect(changes[:note][1]).to eq('some note') - expect(changes[:active][0]).to eq(true) - expect(changes[:active][1]).to eq(false) + expect(changes[:active][0]).to be(true) + expect(changes[:active][1]).to be(false) result = ticket_state.save - expect(result).to eq(true) - expect(ticket_state.id).to eq(ticket_state.id) + expect(result).to be(true) + expect(ticket_state.id).to be_present expect(ticket_state.name).to eq("#{name}-2") expect(ticket_state.state_type).to eq('open') expect(ticket_state.state_type_id).to eq(2) expect(ticket_state.next_state).to eq('closed') expect(ticket_state.next_state_id).to eq(4) - expect(ticket_state.ignore_escalation).to eq(true) + expect(ticket_state.ignore_escalation).to be(true) expect(ticket_state.note).to eq('some note') - expect(ticket_state.active).to eq(false) + expect(ticket_state.active).to be(false) expect(ticket_state.created_by).to eq('admin@example.com') expect(ticket_state.updated_by).to eq('admin@example.com') end @@ -100,9 +100,9 @@ expect(ticket_state_lookup.state_type_id).to eq(2) expect(ticket_state_lookup.next_state).to eq('closed') expect(ticket_state_lookup.next_state_id).to eq(4) - expect(ticket_state_lookup.ignore_escalation).to eq(true) + expect(ticket_state_lookup.ignore_escalation).to be(true) expect(ticket_state_lookup.note).to eq('some note') - expect(ticket_state_lookup.active).to eq(false) + expect(ticket_state_lookup.active).to be(false) expect(ticket_state_lookup.created_by).to eq('admin@example.com') expect(ticket_state_lookup.updated_by).to eq('admin@example.com') end @@ -111,10 +111,11 @@ ticket_states = client.ticket_state.all ticket_state_exists = nil - ticket_states.each { |local_ticket_state| + ticket_states.each do |local_ticket_state| next if local_ticket_state.id != ticket_state.id + ticket_state_exists = local_ticket_state - } + end expect(ticket_state_exists.class).to eq(ZammadAPI::Resources::TicketState) expect(ticket_state_exists.id).to eq(ticket_state.id) expect(ticket_state_exists.name).to eq("#{name}-2") @@ -122,9 +123,9 @@ expect(ticket_state_exists.state_type_id).to eq(2) expect(ticket_state_exists.next_state).to eq('closed') expect(ticket_state_exists.next_state_id).to eq(4) - expect(ticket_state_exists.ignore_escalation).to eq(true) + expect(ticket_state_exists.ignore_escalation).to be(true) expect(ticket_state_exists.note).to eq('some note') - expect(ticket_state_exists.active).to eq(false) + expect(ticket_state_exists.active).to be(false) expect(ticket_state_exists.created_by).to eq('admin@example.com') expect(ticket_state_exists.updated_by).to eq('admin@example.com') @@ -140,10 +141,9 @@ expect(ticket_state_lookup.next_state).to eq('closed') expect(ticket_state_lookup.next_state_id).to eq(4) expect(ticket_state_lookup.note).to eq('some note') - expect(ticket_state_lookup.active).to eq(true) + expect(ticket_state_lookup.active).to be(true) expect(ticket_state_lookup.created_by).to eq('admin@example.com') expect(ticket_state_lookup.updated_by).to eq('admin@example.com') - end it 'pagination with all' do @@ -152,35 +152,34 @@ expect(ticket_states[0].class).to eq(ZammadAPI::Resources::TicketState) count = 0 - ticket_states.each { |local_ticket_state| + ticket_states.each do |local_ticket_state| expect(local_ticket_state.class).to eq(ZammadAPI::Resources::TicketState) count += 1 - } + end expect(count).to be >= 7 count = 0 ticket_states = client.ticket_state.all - ticket_states.page(1, 3) { |local_ticket_state| + ticket_states.page(1, 3) do |local_ticket_state| expect(local_ticket_state.class).to eq(ZammadAPI::Resources::TicketState) count += 1 - } + end expect(count).to eq(3) - ticket_states.page(2, 3) { |local_ticket_state| + ticket_states.page(2, 3) do |local_ticket_state| expect(local_ticket_state.class).to eq(ZammadAPI::Resources::TicketState) count += 1 - } + end expect(count).to eq(6) - ticket_states.page(3, 3) { |local_ticket_state| + ticket_states.page(3, 3) do |local_ticket_state| expect(local_ticket_state.class).to eq(ZammadAPI::Resources::TicketState) count += 1 - } + end expect(count).to be >= 7 end it 'destroy' do result = ticket_state.destroy - expect(result).to eq(true) + expect(result).to be(true) end - end diff --git a/spec/zammad_api/resources/user_spec.rb b/spec/zammad_api/resources/user_spec.rb index 8f26f44..ddbd6a0 100644 --- a/spec/zammad_api/resources/user_spec.rb +++ b/spec/zammad_api/resources/user_spec.rb @@ -1,53 +1,53 @@ require 'spec_helper' describe ZammadAPI, 'user object basics' do - client = Helper.client() + client = Helper.client - random = Helper.random() + random = Helper.random firstname = "firstname#{random}" lastname = "lastname#{random}" email = "some_user#{random}@example.com" user = nil it 'new with invalid attributes' do - user_invalid = client.user.new() + user_invalid = client.user.new expect(user_invalid.class).to eq(ZammadAPI::Resources::User) - expect(user_invalid.new_record?).to eq(true) + expect(user_invalid.new_record?).to be(true) expect { user_invalid.save }.to raise_error(RuntimeError) end it 'new with valid attributes' do user = client.user.new( - firstname: firstname, - lastname: lastname, - email: email, - groups: { - :Users => ['full'] + firstname: firstname, + lastname: lastname, + email: email, + groups: { + Users: ['full'] }, - roles: ['Customer'], + roles: ['Customer'], preferences: { key1: 123, key2: 'abc' }, - note: '', - active: true, + note: '', + active: true, ) expect(user.class).to eq(ZammadAPI::Resources::User) - expect(user.new_record?).to eq(true) - expect(user.id).to eq(nil) + expect(user.new_record?).to be(true) + expect(user.id).to be_nil expect(user.firstname).to eq(firstname) expect(user.lastname).to eq(lastname) expect(user.email).to eq(email) expect(user.preferences).to eq({ key1: 123, key2: 'abc' }) expect(user.note).to eq('') - expect(user.active).to eq(true) + expect(user.active).to be(true) end it 'save' do result = user.save - expect(result).to eq(true) - expect(user.id).not_to eq(nil) + expect(result).to be(true) + expect(user.id).not_to be_nil expect(user.firstname).to eq(firstname) expect(user.lastname).to eq(lastname) expect(user.email).to eq(email) @@ -57,7 +57,7 @@ expect(user.roles).to eq(['Customer']) expect(user.preferences).to eq({ key1: 123, key2: 'abc' }) expect(user.note).to eq('') - expect(user.active).to eq(true) + expect(user.active).to be(true) expect(user.created_by).to eq('admin@example.com') expect(user.updated_by).to eq('admin@example.com') @@ -66,20 +66,20 @@ user.note = 'some note' changes = user.changes - expect(changes.key?(:lastname)).to eq(false) + expect(changes.key?(:lastname)).to be(false) expect(changes[:firstname][0]).to eq(firstname) expect(changes[:firstname][1]).to eq("#{firstname}-2") expect(changes[:note][0]).to eq('') expect(changes[:note][1]).to eq('some note') result = user.save - expect(result).to eq(true) - expect(user.id).to eq(user.id) + expect(result).to be(true) + expect(user.id).to be_present expect(user.firstname).to eq("#{firstname}-2") expect(user.lastname).to eq(lastname) expect(user.email).to eq(email) - expect(user.group_ids).to eq({:'1' => ['full']}) - expect(user.groups).to eq({:Users => ['full']}) + expect(user.group_ids).to eq({ '1': ['full'] }) + expect(user.groups).to eq({ Users: ['full'] }) expect(user.role_ids).to eq([2]) expect(user.roles).to eq(['Agent']) expect(user.note).to eq('some note') @@ -95,32 +95,32 @@ expect(user_lookup.firstname).to eq("#{firstname}-2") expect(user_lookup.lastname).to eq(lastname) expect(user_lookup.email).to eq(email) - expect(user_lookup.group_ids).to eq({:'1' => ['full']}) - expect(user_lookup.groups).to eq({:Users => ['full']}) + expect(user_lookup.group_ids).to eq({ '1': ['full'] }) + expect(user_lookup.groups).to eq({ Users: ['full'] }) expect(user_lookup.role_ids).to eq([2]) expect(user_lookup.roles).to eq(['Agent']) expect(user_lookup.note).to eq('some note') expect(user_lookup.created_by).to eq('admin@example.com') expect(user_lookup.updated_by).to eq('admin@example.com') - end it 'all' do users = client.user.all user_exists = nil - users.each { |local_user| + users.each do |local_user| next if local_user.id != user.id + user_exists = local_user - } + end expect(user_exists.class).to eq(ZammadAPI::Resources::User) expect(user_exists.id).to eq(user.id) expect(user_exists.id).to eq(user.id) expect(user_exists.firstname).to eq("#{firstname}-2") expect(user_exists.lastname).to eq(lastname) expect(user_exists.email).to eq(email) - expect(user_exists.group_ids).to eq({:'1' => ['full']}) - expect(user_exists.groups).to eq({:Users => ['full']}) + expect(user_exists.group_ids).to eq({ '1': ['full'] }) + expect(user_exists.groups).to eq({ Users: ['full'] }) expect(user_exists.role_ids).to eq([2]) expect(user_exists.roles).to eq(['Agent']) expect(user_exists.note).to eq('some note') @@ -134,57 +134,56 @@ expect(user_lookup.firstname).to eq("#{firstname}-2") expect(user_lookup.lastname).to eq(lastname) expect(user_lookup.email).to eq(email) - expect(user_lookup.group_ids).to eq({:'1' => ['full']}) - expect(user_lookup.groups).to eq({:Users => ['full']}) + expect(user_lookup.group_ids).to eq({ '1': ['full'] }) + expect(user_lookup.groups).to eq({ Users: ['full'] }) expect(user_lookup.role_ids).to eq([2]) expect(user_lookup.roles).to eq(['Agent']) expect(user_lookup.note).to eq('some note') - expect(user_lookup.active).to eq(true) + expect(user_lookup.active).to be(true) expect(user_lookup.created_by).to eq('admin@example.com') expect(user_lookup.updated_by).to eq('admin@example.com') - end it 'pagination with all' do - (1..10).each { |local_count| + (1..10).each do |local_count| client.user.create( firstname: "firstname#{local_count}", - lastname: "lastname#{local_count}", - email: "customer_email#{local_count}@example.com", - groups: {:Users => ['full']}, - roles: ['Customer'], - note: '', - active: true, + lastname: "lastname#{local_count}", + email: "customer_email#{local_count}@example.com", + groups: { Users: ['full'] }, + roles: ['Customer'], + note: '', + active: true, ) - } + end users = client.user.all expect(users[0].class).to eq(ZammadAPI::Resources::User) count = 0 - users.each { |local_user| + users.each do |local_user| expect(local_user.class).to eq(ZammadAPI::Resources::User) count += 1 - } + end expect(count).to eq(15) count = 0 users = client.user.all - users.page(1, 4) { |local_user| + users.page(1, 4) do |local_user| expect(local_user.class).to eq(ZammadAPI::Resources::User) count += 1 - } + end expect(count).to eq(4) - users.page(2, 5) { |local_user| + users.page(2, 5) do |local_user| expect(local_user.class).to eq(ZammadAPI::Resources::User) count += 1 - } + end expect(count).to eq(9) count = 0 - users.page(1, 200) { |local_user| + users.page(1, 200) do |local_user| expect(local_user.class).to eq(ZammadAPI::Resources::User) count += 1 - } + end expect(count).to eq(15) end @@ -192,18 +191,19 @@ users = client.user.search(query: firstname) user_exists = nil - users.each { |local_user| + users.each do |local_user| next if local_user.id != user.id + user_exists = local_user - } + end expect(user_exists.class).to eq(ZammadAPI::Resources::User) expect(user_exists.id).to eq(user.id) expect(user_exists.firstname).to eq("#{firstname}-2") - expect(user_exists.group_ids).to eq({:'1' => ['full']}) - expect(user_exists.groups).to eq({:Users => ['full']}) + expect(user_exists.group_ids).to eq({ '1': ['full'] }) + expect(user_exists.groups).to eq({ Users: ['full'] }) expect(user_exists.role_ids).to eq([2]) expect(user_exists.roles).to eq(['Agent']) - expect(user_exists.active).to eq(true) + expect(user_exists.active).to be(true) expect(user_exists.created_by).to eq('admin@example.com') expect(user_exists.updated_by).to eq('admin@example.com') @@ -218,10 +218,9 @@ expect(user_lookup.groups).to be_empty expect(user_lookup.role_ids).to eq([2]) expect(user_lookup.roles).to eq(['Agent']) - expect(user_lookup.active).to eq(false) + expect(user_lookup.active).to be(false) expect(user_lookup.created_by).to eq('admin@example.com') expect(user_lookup.updated_by).to eq('admin@example.com') - end it 'pagination with search' do @@ -231,12 +230,13 @@ count = 0 user_exists = nil - users.each { |local_user| + users.each do |local_user| expect(local_user.class).to eq(ZammadAPI::Resources::User) count += 1 next if local_user.id != user.id + user_exists = local_user - } + end expect(count).to eq(1) expect(user_exists.class).to eq(ZammadAPI::Resources::User) expect(user_exists.id).to eq(user.id) @@ -245,26 +245,25 @@ expect(user_exists.groups).to be_empty expect(user_exists.role_ids).to eq([2]) expect(user_exists.roles).to eq(['Agent']) - expect(user_exists.active).to eq(false) + expect(user_exists.active).to be(false) expect(user_exists.created_by).to eq('admin@example.com') expect(user_exists.updated_by).to eq('admin@example.com') count = 0 users = client.user.search(query: firstname) - users.page(1, 3) { |local_user| + users.page(1, 3) do |local_user| expect(local_user.class).to eq(ZammadAPI::Resources::User) count += 1 - } + end expect(count).to eq(1) - users.page(2, 3) { |local_user| + users.page(2, 3) do |local_user| expect(local_user.class).to eq(ZammadAPI::Resources::User) count += 1 - } + end expect(count).to eq(1) end it 'destroy' do - # wait until zammad scheduler wrote some entries to activity stream # to have some references and not allow users to delete sleep 12 @@ -273,5 +272,4 @@ #result = user.destroy #expect(result).to eq(true) end - end diff --git a/spec/zammad_api/transport_spec.rb b/spec/zammad_api/transport_spec.rb index 68a7f8d..38f1934 100644 --- a/spec/zammad_api/transport_spec.rb +++ b/spec/zammad_api/transport_spec.rb @@ -2,7 +2,6 @@ require 'logger' describe ZammadAPI::Transport do - before(:all) do WebMock.enable! end @@ -11,7 +10,7 @@ WebMock.disable! end - after(:each) do + after do WebMock.reset! end @@ -24,49 +23,45 @@ let(:instance) { described_class.new(config, logger) } context 'GET' do - it 'performs GET requests' do - stub_request(:get, "#{config[:url]}some/path"). - to_return(status: 200, body: "", headers: {}) + stub_request(:get, "#{config[:url]}some/path") + .to_return(status: 200, body: '', headers: {}) instance.get(url: '/some/path') end end context 'on behalf of' do - it 'responds to #on_behalf_of' do expect(instance).to respond_to(:on_behalf_of) end + it 'responds to #on_behalf_of=' do expect(instance).to respond_to(:on_behalf_of=) end it 'sets X-On-Behalf-Of header' do - on_behalf_of_identifier = 'some_login' instance.on_behalf_of = on_behalf_of_identifier - stub_request(:get, "#{config[:url]}some/path"). - with( headers: { + stub_request(:get, "#{config[:url]}some/path") + .with(headers: { 'X-On-Behalf-Of' => on_behalf_of_identifier - }). - to_return(status: 200, body: "", headers: {}) + }) + .to_return(status: 200, body: '', headers: {}) instance.get(url: '/some/path') end it 'unsets X-On-Behalf-Of header' do - on_behalf_of_identifier = 'some_login' instance.on_behalf_of = on_behalf_of_identifier instance.on_behalf_of = nil - stub = stub_request(:get, "#{config[:url]}some/path"). - to_return(status: 200, body: "", headers: {}) - + stub = stub_request(:get, "#{config[:url]}some/path") + .to_return(status: 200, body: '', headers: {}) # this is kind of a hack/workaround to check if the # header was not set/send since webmock doesn't support @@ -75,6 +70,7 @@ def request_pattern.matches?(request_signature) return false if !super return true if request_signature.headers.empty? + !request_signature.headers.key?('X-On-Behalf-Of') end diff --git a/spec/zammad_api_spec.rb b/spec/zammad_api_spec.rb index 8d2ac2c..07aee5f 100644 --- a/spec/zammad_api_spec.rb +++ b/spec/zammad_api_spec.rb @@ -2,11 +2,10 @@ describe ZammadAPI do it 'has a version number' do - expect(ZammadAPI::VERSION).not_to be nil + expect(ZammadAPI::VERSION).not_to be_nil end context 'failing authentication' do - Helper.auto_wizard client = Helper.client(user: 'not_existing', password: 'not_existing') diff --git a/zammad_api.gemspec b/zammad_api.gemspec index 7bb6339..263de4a 100644 --- a/zammad_api.gemspec +++ b/zammad_api.gemspec @@ -1,5 +1,4 @@ -# coding: utf-8 -lib = File.expand_path('../lib', __FILE__) +lib = File.expand_path('lib', __dir__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require 'zammad_api/version' @@ -12,21 +11,25 @@ Gem::Specification.new do |spec| spec.summary = 'Zammad API v1.0 client.' spec.description = 'Ruby wrapper for the Zammad API v1.0.' spec.homepage = 'https://github.com/zammad/zammad-api-client-ruby' - spec.licenses = ['AGPL-3.0-only', 'MIT'] + spec.licenses = ['AGPL-3.0-only', 'MIT'] - spec.metadata["allowed_push_host"] = "https://rubygems.org" + spec.metadata['allowed_push_host'] = 'https://rubygems.org' - spec.metadata["homepage_uri"] = spec.homepage - spec.metadata["source_code_uri"] = "https://github.com/zammad/zammad-api-client-ruby" - spec.metadata["changelog_uri"] = "https://github.com/zammad/zammad-api-client-ruby/blob/master/CHANGELOG.md" + spec.metadata['homepage_uri'] = spec.homepage + spec.metadata['source_code_uri'] = 'https://github.com/zammad/zammad-api-client-ruby' + spec.metadata['changelog_uri'] = 'https://github.com/zammad/zammad-api-client-ruby/blob/master/CHANGELOG.md' + spec.metadata['rubygems_mfa_required'] = 'true' spec.files = Dir['{lib}/**/*'] spec.require_paths = ['lib'] - spec.add_runtime_dependency 'faraday', '~> 2' + spec.add_dependency 'faraday', '~> 2' spec.add_development_dependency 'bundler', '>= 2.2.10' spec.add_development_dependency 'rake' spec.add_development_dependency 'rspec' + spec.add_development_dependency 'rubocop' + spec.add_development_dependency 'rubocop-performance' + spec.add_development_dependency 'rubocop-rspec' spec.add_development_dependency 'webmock' end From 4023c6ce61243882603784e368db2ea8ddc5f2ff Mon Sep 17 00:00:00 2001 From: Martin Gruner Date: Mon, 27 Apr 2026 14:10:37 +0200 Subject: [PATCH 2/3] Fix tests --- spec/zammad_api/resources/group_spec.rb | 2 +- spec/zammad_api/resources/organization_spec.rb | 2 +- spec/zammad_api/resources/ticket_priority_spec.rb | 2 +- spec/zammad_api/resources/ticket_spec.rb | 2 +- spec/zammad_api/resources/ticket_state_spec.rb | 2 +- spec/zammad_api/resources/user_spec.rb | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/spec/zammad_api/resources/group_spec.rb b/spec/zammad_api/resources/group_spec.rb index 9c1d2d9..48c62aa 100644 --- a/spec/zammad_api/resources/group_spec.rb +++ b/spec/zammad_api/resources/group_spec.rb @@ -66,7 +66,7 @@ result = group.save expect(result).to be(true) - expect(group.id).to be_present + expect(group.id).to be_a_kind_of(Integer) expect(group.name).to eq("#{name}-2") expect(group.assignment_timeout).to eq(4711) expect(group.follow_up_assignment).to be(false) diff --git a/spec/zammad_api/resources/organization_spec.rb b/spec/zammad_api/resources/organization_spec.rb index d63718f..277459a 100644 --- a/spec/zammad_api/resources/organization_spec.rb +++ b/spec/zammad_api/resources/organization_spec.rb @@ -62,7 +62,7 @@ result = organization.save expect(result).to be(true) - expect(organization.id).to be_present + expect(organization.id).to be_a_kind_of(Integer) expect(organization.name).to eq("#{name}-2") expect(organization.shared).to be(true) expect(organization.note).to eq('some note') diff --git a/spec/zammad_api/resources/ticket_priority_spec.rb b/spec/zammad_api/resources/ticket_priority_spec.rb index 1a2868c..0908c4f 100644 --- a/spec/zammad_api/resources/ticket_priority_spec.rb +++ b/spec/zammad_api/resources/ticket_priority_spec.rb @@ -54,7 +54,7 @@ result = ticket_priority.save expect(result).to be(true) - expect(ticket_priority.id).to be_present + expect(ticket_priority.id).to be_a_kind_of(Integer) expect(ticket_priority.name).to eq("#{name}-2") expect(ticket_priority.note).to eq('some note') expect(ticket_priority.active).to be(false) diff --git a/spec/zammad_api/resources/ticket_spec.rb b/spec/zammad_api/resources/ticket_spec.rb index 3098e8c..ce1e9eb 100644 --- a/spec/zammad_api/resources/ticket_spec.rb +++ b/spec/zammad_api/resources/ticket_spec.rb @@ -69,7 +69,7 @@ result = ticket.save expect(result).to be(true) expect(ticket.new_record?).to be(false) - expect(ticket.id).to be_present + expect(ticket.id).to be_a_kind_of(Integer) expect(ticket.title).to eq("#{title}-2") expect(ticket.state).to eq('open') expect(ticket.state_id).to eq(2) diff --git a/spec/zammad_api/resources/ticket_state_spec.rb b/spec/zammad_api/resources/ticket_state_spec.rb index 6a8d90b..7225a16 100644 --- a/spec/zammad_api/resources/ticket_state_spec.rb +++ b/spec/zammad_api/resources/ticket_state_spec.rb @@ -77,7 +77,7 @@ result = ticket_state.save expect(result).to be(true) - expect(ticket_state.id).to be_present + expect(ticket_state.id).to be_a_kind_of(Integer) expect(ticket_state.name).to eq("#{name}-2") expect(ticket_state.state_type).to eq('open') expect(ticket_state.state_type_id).to eq(2) diff --git a/spec/zammad_api/resources/user_spec.rb b/spec/zammad_api/resources/user_spec.rb index ddbd6a0..b45d803 100644 --- a/spec/zammad_api/resources/user_spec.rb +++ b/spec/zammad_api/resources/user_spec.rb @@ -74,7 +74,7 @@ result = user.save expect(result).to be(true) - expect(user.id).to be_present + expect(user.id).to be_a_kind_of(Integer) expect(user.firstname).to eq("#{firstname}-2") expect(user.lastname).to eq(lastname) expect(user.email).to eq(email) From 4d76d4976658f3234d540ebe2c301685122a84b0 Mon Sep 17 00:00:00 2001 From: Martin Gruner Date: Mon, 27 Apr 2026 14:15:33 +0200 Subject: [PATCH 3/3] Fix rubocop --- .rubocop.yml | 1 + Gemfile.lock | 4 ++++ spec/zammad_api/resources/group_spec.rb | 2 +- spec/zammad_api/resources/organization_spec.rb | 2 +- spec/zammad_api/resources/ticket_priority_spec.rb | 2 +- spec/zammad_api/resources/ticket_spec.rb | 2 +- spec/zammad_api/resources/ticket_state_spec.rb | 2 +- spec/zammad_api/resources/user_spec.rb | 2 +- zammad_api.gemspec | 1 + 9 files changed, 12 insertions(+), 6 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 618ce33..0c24cc6 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -3,6 +3,7 @@ plugins: - rubocop-performance + - rubocop-rake - rubocop-rspec inherit_from: diff --git a/Gemfile.lock b/Gemfile.lock index fac704d..7d64579 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -70,6 +70,9 @@ GEM lint_roller (~> 1.1) rubocop (>= 1.75.0, < 2.0) rubocop-ast (>= 1.47.1, < 2.0) + rubocop-rake (0.7.1) + lint_roller (~> 1.1) + rubocop (>= 1.72.1) rubocop-rspec (3.9.0) lint_roller (~> 1.1) rubocop (~> 1.81) @@ -92,6 +95,7 @@ DEPENDENCIES rspec rubocop rubocop-performance + rubocop-rake rubocop-rspec webmock zammad_api! diff --git a/spec/zammad_api/resources/group_spec.rb b/spec/zammad_api/resources/group_spec.rb index 48c62aa..0b96426 100644 --- a/spec/zammad_api/resources/group_spec.rb +++ b/spec/zammad_api/resources/group_spec.rb @@ -66,7 +66,7 @@ result = group.save expect(result).to be(true) - expect(group.id).to be_a_kind_of(Integer) + expect(group.id).to be_a(Integer) expect(group.name).to eq("#{name}-2") expect(group.assignment_timeout).to eq(4711) expect(group.follow_up_assignment).to be(false) diff --git a/spec/zammad_api/resources/organization_spec.rb b/spec/zammad_api/resources/organization_spec.rb index 277459a..85af4e9 100644 --- a/spec/zammad_api/resources/organization_spec.rb +++ b/spec/zammad_api/resources/organization_spec.rb @@ -62,7 +62,7 @@ result = organization.save expect(result).to be(true) - expect(organization.id).to be_a_kind_of(Integer) + expect(organization.id).to be_a(Integer) expect(organization.name).to eq("#{name}-2") expect(organization.shared).to be(true) expect(organization.note).to eq('some note') diff --git a/spec/zammad_api/resources/ticket_priority_spec.rb b/spec/zammad_api/resources/ticket_priority_spec.rb index 0908c4f..d84a717 100644 --- a/spec/zammad_api/resources/ticket_priority_spec.rb +++ b/spec/zammad_api/resources/ticket_priority_spec.rb @@ -54,7 +54,7 @@ result = ticket_priority.save expect(result).to be(true) - expect(ticket_priority.id).to be_a_kind_of(Integer) + expect(ticket_priority.id).to be_a(Integer) expect(ticket_priority.name).to eq("#{name}-2") expect(ticket_priority.note).to eq('some note') expect(ticket_priority.active).to be(false) diff --git a/spec/zammad_api/resources/ticket_spec.rb b/spec/zammad_api/resources/ticket_spec.rb index ce1e9eb..d0fbb59 100644 --- a/spec/zammad_api/resources/ticket_spec.rb +++ b/spec/zammad_api/resources/ticket_spec.rb @@ -69,7 +69,7 @@ result = ticket.save expect(result).to be(true) expect(ticket.new_record?).to be(false) - expect(ticket.id).to be_a_kind_of(Integer) + expect(ticket.id).to be_a(Integer) expect(ticket.title).to eq("#{title}-2") expect(ticket.state).to eq('open') expect(ticket.state_id).to eq(2) diff --git a/spec/zammad_api/resources/ticket_state_spec.rb b/spec/zammad_api/resources/ticket_state_spec.rb index 7225a16..f605b35 100644 --- a/spec/zammad_api/resources/ticket_state_spec.rb +++ b/spec/zammad_api/resources/ticket_state_spec.rb @@ -77,7 +77,7 @@ result = ticket_state.save expect(result).to be(true) - expect(ticket_state.id).to be_a_kind_of(Integer) + expect(ticket_state.id).to be_a(Integer) expect(ticket_state.name).to eq("#{name}-2") expect(ticket_state.state_type).to eq('open') expect(ticket_state.state_type_id).to eq(2) diff --git a/spec/zammad_api/resources/user_spec.rb b/spec/zammad_api/resources/user_spec.rb index b45d803..b96f154 100644 --- a/spec/zammad_api/resources/user_spec.rb +++ b/spec/zammad_api/resources/user_spec.rb @@ -74,7 +74,7 @@ result = user.save expect(result).to be(true) - expect(user.id).to be_a_kind_of(Integer) + expect(user.id).to be_a(Integer) expect(user.firstname).to eq("#{firstname}-2") expect(user.lastname).to eq(lastname) expect(user.email).to eq(email) diff --git a/zammad_api.gemspec b/zammad_api.gemspec index 263de4a..b04a37a 100644 --- a/zammad_api.gemspec +++ b/zammad_api.gemspec @@ -30,6 +30,7 @@ Gem::Specification.new do |spec| spec.add_development_dependency 'rspec' spec.add_development_dependency 'rubocop' spec.add_development_dependency 'rubocop-performance' + spec.add_development_dependency 'rubocop-rake' spec.add_development_dependency 'rubocop-rspec' spec.add_development_dependency 'webmock' end