diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml index 215eb90..123fa73 100644 --- a/.github/workflows/ruby.yml +++ b/.github/workflows/ruby.yml @@ -12,12 +12,12 @@ jobs: strategy: fail-fast: false matrix: - ruby: [ '2.6', '2.7', '3.0' ] + ruby: [ '3.0', '3.1', '3.2' ] env: RUBY_IMAGE: ${{ matrix.ruby }} name: Ruby ${{ matrix.ruby }} steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Set up Ruby uses: ruby/setup-ruby@v1 with: diff --git a/.gitignore b/.gitignore index 1714084..cd8b423 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ /gemfiles/ /pkg/ /spec/reports/ +/spec/internal/tmp/ /tmp/ .pry_history .rspec_status diff --git a/.standard.yml b/.standard.yml index 3af9da5..c19ce03 100644 --- a/.standard.yml +++ b/.standard.yml @@ -1 +1 @@ -ruby_version: 2.6 +ruby_version: 2.7 diff --git a/docker-compose.yml b/docker-compose.yml index 5810de2..53de4a0 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,6 +1,6 @@ services: ruby: - image: ruby:${RUBY_IMAGE:-3.0}-buster + image: ruby:${RUBY_IMAGE:-2.7}-bullseye environment: HISTFILE: /app/.bash_history BUNDLE_PATH: /bundle diff --git a/graphql-connections.gemspec b/graphql-connections.gemspec index ff89077..d3bc385 100644 --- a/graphql-connections.gemspec +++ b/graphql-connections.gemspec @@ -28,7 +28,7 @@ Gem::Specification.new do |spec| spec.bindir = "exe" spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } spec.require_paths = ["lib"] - spec.required_ruby_version = "> 2.5" + spec.required_ruby_version = "> 2.6" spec.add_runtime_dependency "activerecord", ">= 5" spec.add_runtime_dependency "graphql", [">= 1.10", "< 3.0"] @@ -41,8 +41,8 @@ Gem::Specification.new do |spec| spec.add_development_dependency "pg", "~> 1.2" spec.add_development_dependency "pry-byebug", "~> 3" spec.add_development_dependency "rake", "~> 13.0" - spec.add_development_dependency "rspec-rails", "~> 5.0" + spec.add_development_dependency "rspec-rails", "~> 6.0" spec.add_development_dependency "standard", "~> 1.1" - spec.add_development_dependency "test-prof", "~> 1.0" + spec.add_development_dependency "test-prof", "~> 1.0.0" end # rubocop:enable Metrics/BlockLength diff --git a/lefthook-local.dip_example.yml b/lefthook-local.dip_example.yml index e8928f6..2b1f70e 100644 --- a/lefthook-local.dip_example.yml +++ b/lefthook-local.dip_example.yml @@ -1,4 +1,4 @@ pre-commit: commands: rubocop: - runner: dip {cmd} + run: dip {cmd} diff --git a/lefthook.yml b/lefthook.yml index ed48839..5207494 100644 --- a/lefthook.yml +++ b/lefthook.yml @@ -3,4 +3,4 @@ pre-commit: rubocop: tags: backend glob: "**/*.rb" - runner: bundle exec standardrb --fix {staged_files} && git add {staged_files} + run: bundle exec standardrb --fix {staged_files} && git add {staged_files} diff --git a/lib/graphql/connections/keyset/asc.rb b/lib/graphql/connections/keyset/asc.rb index 0df5dfb..fb9be0b 100644 --- a/lib/graphql/connections/keyset/asc.rb +++ b/lib/graphql/connections/keyset/asc.rb @@ -42,10 +42,10 @@ def has_next_page false end end - # rubocop:enable Naming/PredicateName, Metrics/AbcSize, Metrics/MethodLength private + # standard:disable Metrics/AbcSize, Metrics/MethodLength def limited_relation scope = sliced_relation nodes = [] @@ -78,6 +78,7 @@ def sliced_relation_before(relation) .where(arel_table[primary_key].lt(before_cursor_primary_key)) .or(relation.where(arel_table[field_key].lt(before_cursor_date))) end + # standard:enable Metrics/AbcSize, Metrics/MethodLength end end end diff --git a/lib/graphql/connections/keyset/desc.rb b/lib/graphql/connections/keyset/desc.rb index 82ee390..3a6d4cd 100644 --- a/lib/graphql/connections/keyset/desc.rb +++ b/lib/graphql/connections/keyset/desc.rb @@ -42,8 +42,8 @@ def has_next_page false end end - # rubocop:enable Naming/PredicateName, Metrics/AbcSize, Metrics/MethodLength + # standard:disable Metrics/AbcSize, Metrics/MethodLength def cursor_for(item) cursor = [item[field_key], item[primary_key]].map { |value| serialize(value) }.join(@separator) cursor = encode(cursor) if opaque_cursor @@ -85,6 +85,7 @@ def sliced_relation_before(relation) .where(arel_table[primary_key].gt(before_cursor_primary_key)) .or(relation.where(arel_table[field_key].gt(before_cursor_date))) end + # standard:disable Metrics/AbcSize, Metrics/MethodLength end end end diff --git a/lib/graphql/connections/primary_key/base.rb b/lib/graphql/connections/primary_key/base.rb index 9f590f3..6dec149 100644 --- a/lib/graphql/connections/primary_key/base.rb +++ b/lib/graphql/connections/primary_key/base.rb @@ -16,8 +16,10 @@ def initialize(*args, primary_key: nil, **kwargs) end def has_previous_page + return false if nodes.empty? + if last - nodes.any? && items_exist?(type: :query, search: nodes.first[primary_key], page_type: :previous) + items_exist?(type: :query, search: nodes.first[primary_key], page_type: :previous) elsif after items_exist?(type: :cursor, search: after_cursor, page_type: :previous) else @@ -26,6 +28,8 @@ def has_previous_page end def has_next_page + return false if nodes.empty? + if first items_exist?(type: :query, search: nodes.last[primary_key], page_type: :next) elsif before diff --git a/spec/lib/keyset/desc_spec.rb b/spec/lib/keyset/desc_spec.rb index cb196f3..ea877d1 100644 --- a/spec/lib/keyset/desc_spec.rb +++ b/spec/lib/keyset/desc_spec.rb @@ -26,6 +26,16 @@ expect(connection.has_previous_page).to be false expect(connection.has_next_page).to be true end + + context "with empty relation" do + let(:relation) { Message.none } + + it "returns no nodes and has_previous_page and has_next_page are false" do + expect(nodes.size).to eq 0 + expect(connection.has_previous_page).to be false + expect(connection.has_next_page).to be false + end + end end describe ":first param" do diff --git a/spec/lib/primary_key/asc_spec.rb b/spec/lib/primary_key/asc_spec.rb index e528e73..5f0c2a4 100644 --- a/spec/lib/primary_key/asc_spec.rb +++ b/spec/lib/primary_key/asc_spec.rb @@ -26,6 +26,16 @@ expect(connection.has_previous_page).to be false expect(connection.has_next_page).to be true end + + context "with empty relation" do + let(:relation) { Message.none } + + it "returns no nodes and has_previous_page and has_next_page are false" do + expect(nodes.size).to eq 0 + expect(connection.has_previous_page).to be false + expect(connection.has_next_page).to be false + end + end end describe ":first param" do