Skip to content

Commit

Permalink
Merge pull request #406 from graphiti-api/ruby-3-1-gha
Browse files Browse the repository at this point in the history
Support Ruby 3.1
  • Loading branch information
wagenet authored Feb 4, 2022
2 parents 6dcf894 + a0b5f46 commit 61181e7
Show file tree
Hide file tree
Showing 24 changed files with 110 additions and 124 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ jobs:
- "2.6"
- "2.7"
- "3.0"
- "3.1"
gemfile:
- Gemfile
- gemfiles/rails_5_2.gemfile
Expand Down Expand Up @@ -70,6 +71,10 @@ jobs:
ruby: 3.0
- gemfile: gemfiles/rails_5_2_graphiti_rails.gemfile
ruby: 3.0
- gemfile: gemfiles/rails_5_2.gemfile
ruby: 3.1
- gemfile: gemfiles/rails_5_2_graphiti_rails.gemfile
ruby: 3.1
# Raise 7 can't run on 2.6
- gemfile: gemfiles/rails_7.gemfile
ruby: 2.6
Expand Down
9 changes: 3 additions & 6 deletions Appraisals
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ appraise "rails-5_2-graphiti-rails" do
gem "rspec-rails"
gem "sqlite3", "~> 1.4.0"
gem "database_cleaner"
gem "rescue_registry"
gem "graphiti-rails", git: "https://github.com/graphiti-api/graphiti-rails.git", branch: "master"
gem "graphiti-rails", "~> 0.4.0"
end

appraise "rails-6" do
Expand All @@ -26,8 +25,7 @@ appraise "rails-6-graphiti-rails" do
gem "rspec-rails"
gem "sqlite3", "~> 1.4.0"
gem "database_cleaner"
gem "rescue_registry"
gem "graphiti-rails", git: "https://github.com/graphiti-api/graphiti-rails.git", branch: "master"
gem "graphiti-rails", "~> 0.4.0"
end

appraise "rails-7" do
Expand All @@ -42,6 +40,5 @@ appraise "rails-7-graphiti-rails" do
gem "rspec-rails"
gem "sqlite3", "~> 1.4.0"
gem "database_cleaner"
gem "rescue_registry"
gem "graphiti-rails", git: "https://github.com/graphiti-api/graphiti-rails.git", branch: "master"
gem "graphiti-rails", "~> 0.4.0"
end
3 changes: 1 addition & 2 deletions gemfiles/rails_5_2_graphiti_rails.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ gem "rails", "~> 5.2.0"
gem "rspec-rails"
gem "sqlite3", "~> 1.4.0"
gem "database_cleaner"
gem "rescue_registry"
gem "graphiti-rails", git: "https://github.com/graphiti-api/graphiti-rails.git", branch: "master"
gem "graphiti-rails", "~> 0.4.0"

group :test do
gem "pry"
Expand Down
3 changes: 1 addition & 2 deletions gemfiles/rails_6_graphiti_rails.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ gem "rails", "~> 6.0"
gem "rspec-rails"
gem "sqlite3", "~> 1.4.0"
gem "database_cleaner"
gem "rescue_registry"
gem "graphiti-rails", git: "https://github.com/graphiti-api/graphiti-rails.git", branch: "master"
gem "graphiti-rails", "~> 0.4.0"

group :test do
gem "pry"
Expand Down
3 changes: 1 addition & 2 deletions gemfiles/rails_7_graphiti_rails.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ gem "rails", "~> 7.0"
gem "rspec-rails"
gem "sqlite3", "~> 1.4.0"
gem "database_cleaner"
gem "rescue_registry"
gem "graphiti-rails", git: "https://github.com/graphiti-api/graphiti-rails.git", branch: "master"
gem "graphiti-rails", "~> 0.4.0"

group :test do
gem "pry"
Expand Down
4 changes: 2 additions & 2 deletions graphiti.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,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.6", "< 3.1"]
spec.required_ruby_version = ">= 2.6"

spec.add_dependency "jsonapi-serializable", "~> 0.3.0"
spec.add_dependency "jsonapi-renderer", "~> 0.2", ">= 0.2.2"
Expand All @@ -29,7 +29,7 @@ Gem::Specification.new do |spec|
spec.add_development_dependency "kaminari", "~> 0.17"
spec.add_development_dependency "bundler"
spec.add_development_dependency "rake", ">= 10.0"
spec.add_development_dependency "standard", "~> 1.0.0"
spec.add_development_dependency "standard", "~> 1.4.0"
spec.add_development_dependency "activemodel", ">= 5.2"
spec.add_development_dependency "graphiti_spec_helpers", "1.0.beta.4"
end
2 changes: 1 addition & 1 deletion lib/graphiti/adapters/active_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ def column_for(scope, name)
end

def sanitized_like_for(scope, attribute, value, &block)
escape_char = '\\'
escape_char = "\\"
column = column_for(scope, attribute)
map = value.map { |v|
v = v.downcase
Expand Down
28 changes: 13 additions & 15 deletions lib/graphiti/adapters/persistence/associations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,20 @@ module Associations
def process_belongs_to(persistence, attributes)
parents = [].tap do |processed|
persistence.iterate(only: [:polymorphic_belongs_to, :belongs_to]) do |x|
begin
id = x.dig(:attributes, :id)
x[:object] = x[:resource]
.persist_with_relationships(x[:meta], x[:attributes], x[:relationships])
id = x.dig(:attributes, :id)
x[:object] = x[:resource]
.persist_with_relationships(x[:meta], x[:attributes], x[:relationships])
processed << x
rescue Graphiti::Errors::RecordNotFound
if Graphiti.config.raise_on_missing_sidepost
path = "relationships/#{x.dig(:meta, :jsonapi_type)}"
raise Graphiti::Errors::RecordNotFound.new(x[:sideload].name, id, path)
else
pointer = "data/relationships/#{x.dig(:meta, :jsonapi_type)}"
object = Graphiti::Errors::NullRelation.new(id.to_s, pointer)
object.errors.add(:base, :not_found, message: "could not be found")
x[:object] = object
processed << x
rescue Graphiti::Errors::RecordNotFound
if Graphiti.config.raise_on_missing_sidepost
path = "relationships/#{x.dig(:meta, :jsonapi_type)}"
raise Graphiti::Errors::RecordNotFound.new(x[:sideload].name, id, path)
else
pointer = "data/relationships/#{x.dig(:meta, :jsonapi_type)}"
object = Graphiti::Errors::NullRelation.new(id.to_s, pointer)
object.errors.add(:base, :not_found, message: "could not be found")
x[:object] = object
processed << x
end
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/graphiti/extensions/temp_id.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module SerializableTempId
# Common interface for jsonapi-rb extensions
def as_jsonapi(*)
super.tap do |hash|
if (temp_id = @object.instance_variable_get(:'@_jsonapi_temp_id'))
if (temp_id = @object.instance_variable_get(:@_jsonapi_temp_id))
hash[:'temp-id'] = temp_id
end
end
Expand Down
1 change: 0 additions & 1 deletion lib/graphiti/filter_operators.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ def initialize(resource, type_name, opts)
end
end

# rubocop: disable Style/MethodMissingSuper
def method_missing(name, *args, &blk)
@procs[name] = blk
end
Expand Down
4 changes: 2 additions & 2 deletions lib/graphiti/resource/dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,9 @@ def apply_extra_attributes_to_serializer
def attribute_option(options, name, exclusive = false)
if options[name] != false
default = if (only = options[:only]) && !exclusive
Array(only).include?(name) ? true : false
Array(only).include?(name)
elsif (except = options[:except]) && !exclusive
Array(except).include?(name) ? false : true
!Array(except).include?(name)
else
send(:"attributes_#{name}_by_default")
end
Expand Down
7 changes: 3 additions & 4 deletions lib/graphiti/sideload/polymorphic_belongs_to.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ def initialize(name)
@calls = []
end

# rubocop: disable Style/MethodMissingSuper
def method_missing(name, *args, &blk)
@calls << [name, args, blk]
end
Expand Down Expand Up @@ -56,9 +55,9 @@ def apply(sideload, resource_class)
args = call[1]
opts = args.extract_options!
opts.merge! as: sideload.name,
parent: sideload,
group_name: group.name,
polymorphic_child: true
parent: sideload,
group_name: group.name,
polymorphic_child: true
unless sideload.resource.class.abstract_class?
opts[:foreign_key] ||= sideload.foreign_key
opts[:primary_key] ||= sideload.primary_key
Expand Down
1 change: 0 additions & 1 deletion lib/graphiti/stats/dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ def initialize(adapter, config)
#
# ...will hit +method_missing+ and store the proc for future reference.
# @api private
# rubocop: disable Style/MethodMissingSuper
def method_missing(meth, *args, &blk)
@calculations[meth] = blk
end
Expand Down
4 changes: 2 additions & 2 deletions spec/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

# FIXME: Deprecated
describe "when rails is defined" do
let(:logger) { double('debug?': false) }
let(:logger) { double(debug?: false) }

let(:rails) do
double(root: Pathname.new("/foo/bar"), logger: logger)
Expand All @@ -53,7 +53,7 @@

# FIXME: Deprecated
context "when rails logger is debug level" do
let(:logger) { double('debug?': true) }
let(:logger) { double(debug?: true) }

it { is_expected.to eq(true) }
end
Expand Down
8 changes: 4 additions & 4 deletions spec/filtering_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -433,11 +433,11 @@ def self.name
context "one level" do
let!(:pos1) do
PORO::Position.create title: "foo",
employee_id: employee1.id
employee_id: employee1.id
end
let!(:pos2) do
PORO::Position.create title: "bar",
employee_id: employee1.id
employee_id: employee1.id
end

before do
Expand All @@ -460,11 +460,11 @@ def self.name
let!(:department2) { PORO::Department.create(name: "bar") }
let!(:pos1) do
PORO::Position.create department_id: department1.id,
employee_id: employee1.id
employee_id: employee1.id
end
let!(:pos2) do
PORO::Position.create department_id: department2.id,
employee_id: employee1.id
employee_id: employee1.id
end

before do
Expand Down
56 changes: 28 additions & 28 deletions spec/integration/rails/finders_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,29 +24,29 @@ def resource

let!(:author1) do
Legacy::Author.create! first_name: "Stephen",
age: 70,
active: true,
float_age: 70.03,
decimal_age: 70.033,
state: state,
organization: org1,
dwelling: house,
created_at: one_day_ago,
last_login: one_day_ago,
created_at_date: one_day_ago.to_date,
identifier: SecureRandom.uuid
age: 70,
active: true,
float_age: 70.03,
decimal_age: 70.033,
state: state,
organization: org1,
dwelling: house,
created_at: one_day_ago,
last_login: one_day_ago,
created_at_date: one_day_ago.to_date,
identifier: SecureRandom.uuid
end
let!(:author2) do
Legacy::Author.create! first_name: "George",
age: 65,
active: false,
float_age: 70.01,
decimal_age: 70.011,
dwelling: condo,
created_at: two_days_ago,
last_login: one_day_ago,
created_at_date: two_days_ago.to_date,
identifier: SecureRandom.uuid
age: 65,
active: false,
float_age: 70.01,
decimal_age: 70.011,
dwelling: condo,
created_at: two_days_ago,
last_login: one_day_ago,
created_at_date: two_days_ago.to_date,
identifier: SecureRandom.uuid
end
let!(:book1) { Legacy::Book.create!(author: author1, genre: genre, title: "The Shining") }
let!(:book2) { Legacy::Book.create!(author: author1, genre: genre, title: "The Stand") }
Expand Down Expand Up @@ -208,14 +208,14 @@ def resource

let!(:author3) do
Legacy::Author.create! first_name: "GeOrge",
age: 72,
identifier: "AbC123",
active: true,
float_age: 70.05,
decimal_age: 70.055,
last_login: nil,
created_at: 1.day.from_now,
created_at_date: 1.day.from_now.to_date
age: 72,
identifier: "AbC123",
active: true,
float_age: 70.05,
decimal_age: 70.055,
last_login: nil,
created_at: 1.day.from_now,
created_at_date: 1.day.from_now.to_date
end

context "when multiple operators" do
Expand Down
Loading

0 comments on commit 61181e7

Please sign in to comment.