Skip to content

Commit

Permalink
Merge branch 'support-7-2'
Browse files Browse the repository at this point in the history
  • Loading branch information
amckinnell committed Oct 26, 2024
2 parents fe80da9 + 3f91f25 commit a9560cc
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 76 deletions.
5 changes: 5 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
require:
- rubocop-performance
- rubocop-rails
- rubocop-rake
- rubocop-rspec
- rubocop-rspec_rails

inherit_from:
- .rubocop.directories.yml
Expand Down Expand Up @@ -114,6 +116,9 @@ Lint/UnmodifiedReduceAccumulator:
Metrics:
Enabled: false

Rails/Output:
Enabled: false

RSpec/AnyInstance:
Enabled: false

Expand Down
9 changes: 5 additions & 4 deletions Appraisals
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion gemfiles/rails_6_1.gemfile → gemfiles/rails_7_2.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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: "../"
83 changes: 27 additions & 56 deletions lib/nulogy_graphql_api/rspec/graphql_matchers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion lib/nulogy_graphql_api/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module NulogyGraphqlApi
VERSION = "4.1.0"
VERSION = "4.2.0"
end
20 changes: 11 additions & 9 deletions nulogy_graphql_api.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion spec/helpers/db_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# rubocop:disable RSpec/FilePath
# rubocop:disable RSpec/SpecFilePathFormat
RSpec.describe DummyApiController, :graphql, type: :request do
it "returns graphql response" do
Expand Down Expand Up @@ -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
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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

0 comments on commit a9560cc

Please sign in to comment.