From 30d349c1220ded2b89674d9874a7b1ac00c04d2d Mon Sep 17 00:00:00 2001 From: Alistair McKinnell Date: Fri, 25 Oct 2024 20:52:03 -0400 Subject: [PATCH 1/3] Revert the change to the :have_graphql_data matcher --- .../rspec/graphql_matchers.rb | 83 ++++++------------- 1 file changed, 27 insertions(+), 56 deletions(-) diff --git a/lib/nulogy_graphql_api/rspec/graphql_matchers.rb b/lib/nulogy_graphql_api/rspec/graphql_matchers.rb index 1a63e5e..dc6c030 100644 --- a/lib/nulogy_graphql_api/rspec/graphql_matchers.rb +++ b/lib/nulogy_graphql_api/rspec/graphql_matchers.rb @@ -4,72 +4,43 @@ module NulogyGraphqlApi module GraphqlMatchers RSpec::Matchers.define :have_graphql_data do |expected_data| - match do |actual_data| - # Allow the expected data to be passed without the root :data key. - @actual = actual_data[:data] - @expected = expected_data - - deep_match(@expected, @actual) + match do |graphql_response| + @expected_response = { data: expected_data } + expect(graphql_response).to match(@expected_response) end - diffable - - failure_message do - "Expected GraphQL data to match (ignoring array ordering) but found differences." - end - - failure_message_when_negated do - "Expected GraphQL data not to match (ignoring array ordering) but found no differences." - end + failure_message do |actual_response| + <<~MSG + expected: #{@expected_response.pretty_inspect} - def actual - @actual - end - - def expected - @expected - end - - def deep_match(expected, actual) - case expected - when Hash - return false unless actual.is_a?(Hash) && expected.keys.sort == actual.keys.sort - - expected.all? { |key, value| deep_match(value, actual[key]) } - when Array - return false unless actual.is_a?(Array) && expected.size == actual.size - - # Sort both arrays before comparing them element by element. - expected.sort_by(&:to_s) == actual.sort_by(&:to_s) - else - expected == actual - end + got: #{actual_response.pretty_inspect} + MSG end end - end - RSpec::Matchers.define :have_graphql_error do |message| - match do |actual_response| - expect(actual_response.fetch(:errors, nil)).to contain_exactly(a_hash_including( - message: include(message) - )) + RSpec::Matchers.define :have_graphql_error do |message| + match do |actual_response| + expect(actual_response.fetch(:errors, nil)).to contain_exactly(a_hash_including( + message: include(message) + )) + end end - end - RSpec::Matchers.define :have_network_error do |message, error_extensions = {}| - match do |actual_response| - expect(actual_response).to match({ - data: {}, - errors: [{ message: message }.merge(error_extensions)] - }) + RSpec::Matchers.define :have_network_error do |message, error_extensions = {}| + match do |actual_response| + expect(actual_response).to match({ + data: {}, + errors: [{ message: message }.merge(error_extensions)] + }) + end end - end - RSpec::Matchers.define :include_graphql_error do |message| - match do |actual_response| - expect(actual_response.fetch(:errors, nil)).to include(a_hash_including( - message: include(message) - )) + RSpec::Matchers.define :include_graphql_error do |message| + match do |actual_response| + expect(actual_response.fetch(:errors, nil)).to include(a_hash_including( + message: include(message) + )) + end end end end From 84619d3e5fd5c07d105ab5c53bded07d37fc690f Mon Sep 17 00:00:00 2001 From: Alistair McKinnell Date: Fri, 25 Oct 2024 21:29:52 -0400 Subject: [PATCH 2/3] Drop support for Rails 6.1 - Update development dependencies - Address rubocop violations --- .rubocop.yml | 5 +++++ Appraisals | 9 +++++---- .../{rails_6_1.gemfile => rails_7_2.gemfile} | 3 ++- nulogy_graphql_api.gemspec | 20 ++++++++++--------- spec/helpers/db_helpers.rb | 2 +- .../graphql_api_controller_spec.rb | 2 -- .../graphql_base_controller_spec.rb | 2 -- 7 files changed, 24 insertions(+), 19 deletions(-) rename gemfiles/{rails_6_1.gemfile => rails_7_2.gemfile} (63%) diff --git a/.rubocop.yml b/.rubocop.yml index 336033b..a8390b7 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,7 +1,9 @@ require: - rubocop-performance + - rubocop-rails - rubocop-rake - rubocop-rspec + - rubocop-rspec_rails inherit_from: - .rubocop.directories.yml @@ -114,6 +116,9 @@ Lint/UnmodifiedReduceAccumulator: Metrics: Enabled: false +Rails/Output: + Enabled: false + RSpec/AnyInstance: Enabled: false diff --git a/Appraisals b/Appraisals index 807df72..6ad004f 100644 --- a/Appraisals +++ b/Appraisals @@ -1,7 +1,3 @@ -appraise "rails-6-1" do - gem "rails", "6.1.4" -end - appraise "rails-7-0" do gem "rails", "7.0.8.6" gem "sprockets-rails", "3.5.2" @@ -11,3 +7,8 @@ appraise "rails-7-1" do gem "rails", "7.1.4.2" gem "sprockets-rails", "3.5.2" end + +appraise "rails-7-2" do + gem "rails", "7.2.1.2" + gem "sprockets-rails", "3.5.2" +end diff --git a/gemfiles/rails_6_1.gemfile b/gemfiles/rails_7_2.gemfile similarity index 63% rename from gemfiles/rails_6_1.gemfile rename to gemfiles/rails_7_2.gemfile index 2c17297..c3da363 100644 --- a/gemfiles/rails_6_1.gemfile +++ b/gemfiles/rails_7_2.gemfile @@ -2,6 +2,7 @@ source "https://rubygems.org" -gem "rails", "6.1.4" +gem "rails", "7.2.1.2" +gem "sprockets-rails", "3.5.2" gemspec path: "../" diff --git a/nulogy_graphql_api.gemspec b/nulogy_graphql_api.gemspec index 1c7df0e..e539df5 100644 --- a/nulogy_graphql_api.gemspec +++ b/nulogy_graphql_api.gemspec @@ -29,18 +29,20 @@ Gem::Specification.new do |spec| spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } spec.require_paths = ["lib"] - spec.add_dependency "graphql", "~> 2" + spec.add_dependency "graphql", "~> 2.3" spec.add_dependency "graphql-schema_comparator", "~> 1.2" - spec.add_dependency "rails", ">= 6.1", "< 8.0" - spec.add_dependency "rainbow", "~> 3.0" + spec.add_dependency "rails", ">= 7.0", "< 8.0" + spec.add_dependency "rainbow", "~> 3.1" spec.add_development_dependency "appraisal", "~> 2.5" - spec.add_development_dependency "rake", "~> 13.1" - spec.add_development_dependency "rspec", "~> 3.12" - spec.add_development_dependency "rspec-rails", "~> 5.1" - spec.add_development_dependency "rubocop", "~> 1.25" - spec.add_development_dependency "rubocop-performance", "~> 1.13" + spec.add_development_dependency "rake", "~> 13.2" + spec.add_development_dependency "rspec", "~> 3.13" + spec.add_development_dependency "rspec-rails", ">= 6.1" + spec.add_development_dependency "rubocop", "~> 1.67" + spec.add_development_dependency "rubocop-performance", "~> 1.22" + spec.add_development_dependency "rubocop-rails", "~> 2.26" spec.add_development_dependency "rubocop-rake", "~> 0.6" - spec.add_development_dependency "rubocop-rspec", "~> 2.8" + spec.add_development_dependency "rubocop-rspec", "~> 3.1" + spec.add_development_dependency "rubocop-rspec_rails", "~> 2.3" spec.add_development_dependency "sqlite3", "~> 1.4" end diff --git a/spec/helpers/db_helpers.rb b/spec/helpers/db_helpers.rb index 0364395..9eed41c 100644 --- a/spec/helpers/db_helpers.rb +++ b/spec/helpers/db_helpers.rb @@ -17,7 +17,7 @@ def define_table(table_name, columns, force) end def define_ar(table_name) - Class.new(ActiveRecord::Base) do + Class.new(ApplicationRecord) do self.table_name = table_name end end diff --git a/spec/requests/lib/nulogy_graphql_api/graphql_api_controller_spec.rb b/spec/requests/lib/nulogy_graphql_api/graphql_api_controller_spec.rb index 424abaa..0991595 100644 --- a/spec/requests/lib/nulogy_graphql_api/graphql_api_controller_spec.rb +++ b/spec/requests/lib/nulogy_graphql_api/graphql_api_controller_spec.rb @@ -1,4 +1,3 @@ -# rubocop:disable RSpec/FilePath # rubocop:disable RSpec/SpecFilePathFormat RSpec.describe DummyApiController, :graphql, type: :request do it "returns graphql response" do @@ -87,5 +86,4 @@ def consider_all_requests_non_local Rails.application.config.consider_all_requests_local = old_val end end -# rubocop:enable RSpec/FilePath # rubocop:enable RSpec/SpecFilePathFormat diff --git a/spec/requests/lib/nulogy_graphql_api/graphql_base_controller_spec.rb b/spec/requests/lib/nulogy_graphql_api/graphql_base_controller_spec.rb index 9a62039..d01b0a7 100644 --- a/spec/requests/lib/nulogy_graphql_api/graphql_base_controller_spec.rb +++ b/spec/requests/lib/nulogy_graphql_api/graphql_base_controller_spec.rb @@ -1,4 +1,3 @@ -# rubocop:disable RSpec/FilePath # rubocop:disable RSpec/SpecFilePathFormat RSpec.describe DummyBaseController, type: :request do it "returns Not Found when requesting an entity that does not exist" do @@ -65,5 +64,4 @@ def consider_all_requests_non_local Rails.application.config.consider_all_requests_local = old_val end end -# rubocop:enable RSpec/FilePath # rubocop:enable RSpec/SpecFilePathFormat From 3f91f258555bca0ab677ae1eb1f2f86a36037c3e Mon Sep 17 00:00:00 2001 From: Alistair McKinnell Date: Fri, 25 Oct 2024 21:30:00 -0400 Subject: [PATCH 3/3] Update version and CHANGELOG --- CHANGELOG.md | 5 +++++ lib/nulogy_graphql_api/version.rb | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 607566e..0e83115 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,11 @@ _none_ +## 4.2.0 (2024-10-28) + +* Drop support for Rails 6.1 +* Revert change to `have_graphql_data` RSpec matcher + ## 4.1.0 (2024-10-25) * Add support for Rails 7.1 diff --git a/lib/nulogy_graphql_api/version.rb b/lib/nulogy_graphql_api/version.rb index d1f4fa2..97953c1 100644 --- a/lib/nulogy_graphql_api/version.rb +++ b/lib/nulogy_graphql_api/version.rb @@ -1,3 +1,3 @@ module NulogyGraphqlApi - VERSION = "4.1.0" + VERSION = "4.2.0" end