Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,17 @@ matrix:
rvm: 2.5.3
env: DB=postgresql DB_USERNAME=postgres DB_PASSWORD=""
services: postgresql
- gemfile: spec/gemfiles/rails_6_1.gemfile
rvm: 2.5.3
env: DB=sqlite3
- gemfile: spec/gemfiles/rails_6_1.gemfile
rvm: 2.5.3
env: DB=mysql2 DB_USERNAME=root DB_PASSWORD=""
services: mysql
- gemfile: spec/gemfiles/rails_6_1.gemfile
rvm: 2.5.3
env: DB=postgresql DB_USERNAME=postgres DB_PASSWORD=""
services: postgresql
env:
global:
- TRAVIS=1
Expand Down
18 changes: 17 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
## 0.5.4

* Rails 7.2 now supported

## 0.5.3

* Rails 7.1 now supported.

## 0.5.2

* Ruby 3.0 now supported.
* Rails 7.0 now supported.

## 0.5.1

* Rails 6.1 now supported.
## 0.5.0

* Rails 6 now supported.
Expand All @@ -20,7 +36,7 @@

## 0.3.4

* The `before` and `after` methods now accept a boolean argument that indicates
* The `before` and `after` methods now accept a boolean argument that indicates
whether the relation should exclude the given point or not.
By default the given point is excluded, if you want to include it,
use `before(false)` / `after(false)`.
Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

source 'https://rubygems.org'

eval_gemfile 'spec/gemfiles/rails_6_0.gemfile'
eval_gemfile 'spec/gemfiles/rails_7_2.gemfile'
eval_gemfile 'rubocop.gemfile'
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ This gem finds the next or previous record(s) relative to the current one effici
Add to Gemfile:

```ruby
gem 'order_query', '~> 0.5.0'
gem 'order_query', '~> 0.5.4'
```

## Usage
Expand Down
10 changes: 8 additions & 2 deletions lib/order_query/point.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,14 @@ def value(column)
v = record.send(column.name)
if v.nil? && !column.nullable?
fail Errors::NonNullableColumnIsNullError,
"Column #{column.inspect} is NULL on record #{@record.inspect}. "\
"Column #{column.inspect} is NULL on record #{@record.send(inspect_method)}. "\
Copy link
Copy Markdown

@evgeniy-trebin evgeniy-trebin Nov 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Calling a private method using send feels a bit fishy; perhaps it makes sense to make the method protected and use as usual?

'Set the `nulls` option to :first or :last.'
end
v
end

def inspect
"#<OrderQuery::Point @record=#{@record.inspect} @space=#{@space.inspect}>"
"#<OrderQuery::Point @record=#{@record.send(inspect_method)} @space=#{@space.inspect}>"
end

protected
Expand All @@ -85,5 +85,11 @@ def inspect
def unless_record_eq(rec)
rec unless rec == @record
end

private
def inspect_method
Gem::Version.new(ActiveRecord::VERSION::STRING) >= Gem::Version.new("7.2.0") ? :full_inspect
: :inspect
end
end
end
15 changes: 11 additions & 4 deletions lib/order_query/space.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@ class Space
# @see Column#initialize for the order_spec element format.
def initialize(base_scope, order_spec)
@base_scope = base_scope
@columns = order_spec.map do |cond_spec|
kwargs, args = cond_spec.partition { |x| x.is_a?(Hash) }
kwargs = kwargs.reduce({}, :merge)
Column.new(base_scope, *args, **kwargs)
@columns = order_spec.map(&:clone)
@columns.map! do |cond_spec|
build_column(base_scope, cond_spec)
end
# add primary key if columns are not unique
unless @columns.last.unique?
Expand Down Expand Up @@ -60,5 +59,13 @@ def inspect
"#<OrderQuery::Space @columns=#{@columns.inspect} "\
"@base_scope=#{@base_scope.inspect}>"
end

private

def build_column(base_scope, cond_spec)
column_spec = cond_spec.last.is_a?(Hash) ? cond_spec : cond_spec.push({})
attr_name, *vals_and_or_dir, options = column_spec
Column.new(base_scope, attr_name, *vals_and_or_dir, **options)
end
end
end
2 changes: 1 addition & 1 deletion lib/order_query/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module OrderQuery
VERSION = '0.5.0'
VERSION = '0.5.4'
end
6 changes: 3 additions & 3 deletions order_query.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ Gem::Specification.new do |s|

s.required_ruby_version = '>= 2.3.0'

s.add_dependency 'activerecord', '>= 5.0', '< 7.0'
s.add_dependency 'activesupport', '>= 5.0', '< 7.0'
s.add_development_dependency 'rake', '~> 10.2'
s.add_dependency 'activerecord', '>= 5.0', '< 7.3'
s.add_dependency 'activesupport', '>= 5.0', '< 7.3'
s.add_development_dependency 'rake', '~> 13.0'
s.add_development_dependency 'rspec', '~> 3.4'
s.add_development_dependency 'simplecov'
end
4 changes: 2 additions & 2 deletions spec/gemfiles/rails_6_0.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ source 'https://rubygems.org'

gemspec path: '../../'

gem 'activerecord', '~> 5.2.3'
gem 'activesupport', '~> 5.2.3'
gem 'activerecord', '~> 6.0.3'
gem 'activesupport', '~> 6.0.3'

platforms :mri, :rbx do
# https://github.com/rails/rails/blob/v6.0.0/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb#L13
Expand Down
21 changes: 21 additions & 0 deletions spec/gemfiles/rails_6_1.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# frozen_string_literal: true

source 'https://rubygems.org'

gemspec path: '../../'

gem 'activerecord', '~> 6.1.1'
gem 'activesupport', '~> 6.1.1'

platforms :mri, :rbx do
# https://github.com/rails/rails/blob/v6.0.0/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb#L13
gem 'sqlite3', '~> 1.4'

# https://github.com/rails/rails/blob/v6.0.0/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb#L4
gem 'pg', '>= 0.18', '< 2.0'

# https://github.com/rails/rails/blob/v6.0.0/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb#L6
gem 'mysql2', '>= 0.4.4'
end

eval_gemfile '../../shared.gemfile'
21 changes: 21 additions & 0 deletions spec/gemfiles/rails_7_0.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# frozen_string_literal: true

source 'https://rubygems.org'

gemspec path: '../../'

gem 'activerecord', '~> 7.0.0'
gem 'activesupport', '~> 7.0.0'

platforms :mri, :rbx do
# https://github.com/rails/rails/blob/v6.0.0/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb#L13
gem 'sqlite3', '~> 1.4'

# https://github.com/rails/rails/blob/v6.0.0/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb#L4
gem 'pg', '>= 0.18', '< 2.0'

# https://github.com/rails/rails/blob/v6.0.0/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb#L6
gem 'mysql2', '>= 0.4.4'
end

eval_gemfile '../../shared.gemfile'
16 changes: 16 additions & 0 deletions spec/gemfiles/rails_7_1.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# frozen_string_literal: true

source 'https://rubygems.org'

gemspec path: '../../'

gem 'activerecord', '~> 7.1.0'
gem 'activesupport', '~> 7.1.0'

platforms :mri, :rbx do
gem 'sqlite3', '~> 1.4'
gem 'pg', '>= 0.18', '< 2.0'
gem 'mysql2', '>= 0.4.4'
end

eval_gemfile '../../shared.gemfile'
16 changes: 16 additions & 0 deletions spec/gemfiles/rails_7_2.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# frozen_string_literal: true

source 'https://rubygems.org'

gemspec path: '../../'

gem 'activerecord', '~> 7.2.0'
gem 'activesupport', '~> 7.2.0'

platforms :mri, :rbx do
gem 'sqlite3', '~> 1.4'
gem 'pg', '>= 0.18', '< 2.0'
gem 'mysql2', '>= 0.4.4'
end

eval_gemfile '../../shared.gemfile'
6 changes: 6 additions & 0 deletions spec/order_query_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,12 @@ def wrap_top_level_or(value)
)
end

it '.seek does not mutate the given order arguments' do
order = [[:priority, :desc], [:id, :asc]]
Issue.seek(order)
expect(order).to eq [[:priority, :desc], [:id, :asc]]
end

context 'partitioned on a boolean flag' do
before do
create_issue(active: true)
Expand Down