Skip to content

Rails 6 support #151

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
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
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ install: bundle install --retry=3 --jobs=3
gemfile:
- gemfiles/rails_4.gemfile
- gemfiles/rails_5.gemfile
- gemfiles/rails_6.gemfile

deploy:
provider: rubygems
Expand Down
8 changes: 7 additions & 1 deletion Appraisals
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
appraise "rails-4" do
gem "rails", "~> 4.1"
gem "rails", "~> 4.2"
gem 'jsonapi-rails', '~> 0.3.1', require: 'jsonapi/rails'
gem 'rspec-rails'
end
Expand All @@ -9,3 +9,9 @@ appraise "rails-5" do
gem 'jsonapi-rails', '~> 0.3.1', require: 'jsonapi/rails'
gem 'rspec-rails'
end

appraise "rails-6" do
gem "rails", "~> 6.1.4"
gem 'jsonapi-rails', '~> 0.3.1', require: 'jsonapi/rails'
gem 'rspec-rails'
end
4 changes: 3 additions & 1 deletion gemfiles/rails_4.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

source "https://rubygems.org"

gem "rails", "~> 4.1"
gem "rails", "~> 4.2"
gem "jsonapi-rails", "~> 0.3.1", :require => "jsonapi/rails"
gem "rspec-rails"
gem "sqlite3", "~> 1.3"
gem "bundler", "~> 1.17"

group :test do
gem "pry"
Expand Down
2 changes: 2 additions & 0 deletions gemfiles/rails_5.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ source "https://rubygems.org"
gem "rails", "~> 5.2"
gem "jsonapi-rails", "~> 0.3.1", :require => "jsonapi/rails"
gem "rspec-rails"
gem "sqlite3", "~> 1.3"
gem "bundler", "~> 2"

group :test do
gem "pry"
Expand Down
19 changes: 19 additions & 0 deletions gemfiles/rails_6.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "rails", "~> 6.1.4"
gem "jsonapi-rails", "~> 0.4.0", :require => "jsonapi/rails"
gem "rspec-rails"
gem "sqlite3", "~> 1.4"
gem "bundler", "~> 2"

group :test do
gem "pry"
gem "pry-byebug", :platform => [:mri]
gem "appraisal"
gem "guard"
gem "guard-rspec"
end

gemspec :path => "../"
4 changes: 2 additions & 2 deletions jsonapi_compliable.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ Gem::Specification.new do |spec|
# Pinning this version until backwards-incompatibility is addressed
spec.add_dependency 'jsonapi-serializable', '~> 0.3.0'

spec.add_development_dependency "activerecord", ['>= 4.1', '< 6']
spec.add_development_dependency "activerecord", ['>= 4.1', '< 7']
spec.add_development_dependency "kaminari", '~> 0.17'
spec.add_development_dependency "bundler", "~> 2.1.4"
spec.add_development_dependency "rake", "~> 10.0"
spec.add_development_dependency "sqlite3"
spec.add_development_dependency "sqlite3", ['~> 1.3', '< 1.5']
spec.add_development_dependency "database_cleaner"
end
4 changes: 2 additions & 2 deletions lib/jsonapi_compliable/adapters/active_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def create(model_class, create_params)
# (see Adapters::Abstract#update)
def update(model_class, update_params)
instance = model_class.find(update_params.delete(:id))
instance.update_attributes(update_params)
instance.update(update_params)
instance
end

Expand All @@ -123,7 +123,7 @@ def destroy(model_class, id)

def associate_many(parent, child, association_name)
parent.association(association_name).loaded!
parent.association(association_name).add_to_target(child, :skip_callbacks)
parent.association(association_name).add_to_target(child, skip_callbacks: true)
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/jsonapi_compliable/adapters/active_record_sideloading.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def has_many(association_name, scope: nil, resource:, foreign_key:, primary_key:
parent.association(association_name).loaded!
relevant_children = children_hash[parent.send(primary_key)] || []
relevant_children.each do |c|
parent.association(association_name).add_to_target(c, :skip_callbacks)
parent.association(association_name).add_to_target(c, skip_callbacks: true)
end
end
end
Expand Down Expand Up @@ -111,7 +111,7 @@ def has_and_belongs_to_many(association_name, scope: nil, resource:, foreign_key
parent.association(association_name).loaded!
relevant_children = children.select { |c| c.send(through).any? { |ct| ct.send(fk) == parent.send(primary_key) } }
relevant_children.each do |c|
parent.association(association_name).add_to_target(c, :skip_callbacks)
parent.association(association_name).add_to_target(c, skip_callbacks: true)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/jsonapi_compliable/extensions/temp_id.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module JsonapiCompliable
# reference it directly.
module SerializableTempId
# Common interface for jsonapi-rb extensions
def as_jsonapi(*)
def as_jsonapi(**)
super.tap do |hash|
if temp_id = @object.instance_variable_get(:'@_jsonapi_temp_id')
hash[:'temp-id'] = temp_id
Expand Down
4 changes: 2 additions & 2 deletions lib/jsonapi_compliable/query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ def parse_sort(hash)
sorts.each do |s|
if s.include?('.')
type, attr = s.split('.')
if type.starts_with?('-')
if type.start_with?('-')
type = type.sub('-', '')
attr = "-#{attr}"
end
Expand Down Expand Up @@ -254,7 +254,7 @@ def parse_pagination(hash)
end

def sort_attr(attr)
value = attr.starts_with?('-') ? :desc : :asc
value = attr.start_with?('-') ? :desc : :asc
key = attr.sub('-', '').to_sym

{ key => value }
Expand Down
2 changes: 1 addition & 1 deletion lib/jsonapi_compliable/sideload.rb
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ def resolve(parents, query, namespace)
# @see #scope
# @return void
def allow_sideload(name, opts = {}, &blk)
sideload = Sideload.new(name, opts)
sideload = Sideload.new(name, **opts)
sideload.instance_eval(&blk) if blk

if polymorphic?
Expand Down
2 changes: 1 addition & 1 deletion lib/jsonapi_compliable/util/persistence.rb
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def iterate(only: [], except: [])
relationships: @relationships,
}.merge(only: only, except: except)

JsonapiCompliable::Util::RelationshipPayload.iterate(opts) do |x|
JsonapiCompliable::Util::RelationshipPayload.iterate(**opts) do |x|
yield x
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/jsonapi_compliable/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module JsonapiCompliable
VERSION = "0.11.34"
VERSION = "0.11.35"
end
16 changes: 16 additions & 0 deletions spec/rails_spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,19 @@ def fix_params!
end

require 'rspec/rails'

# https://github.com/rails/rails/issues/34790#issuecomment-450502805
if RUBY_VERSION>='2.6.0'
if Rails.version < '5'
class ActionController::TestResponse < ActionDispatch::TestResponse
def recycle!
# hack to avoid MonitorMixin double-initialize error:
@mon_mutex_owner_object_id = nil
@mon_mutex = nil
initialize
end
end
else
puts "Monkeypatch for ActionController::TestResponse no longer needed"
end
end
2 changes: 1 addition & 1 deletion spec/sideload_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

RSpec.describe JsonapiCompliable::Sideload do
let(:opts) { {} }
let(:instance) { described_class.new(:foo, opts) }
let(:instance) { described_class.new(:foo, **opts) }

describe '.new' do
it 'assigns a resource class' do
Expand Down