Skip to content

Commit 2ae4de3

Browse files
author
Lee Richmond
committed
Switch to render_jsonapi
This makes more sense as we are moving off of AMS
1 parent 3410475 commit 2ae4de3

14 files changed

+23
-26
lines changed

Gemfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@ source "https://rubygems.org"
22

33
# Specify your gem's dependencies in jsonapi_compliable.gemspec
44
gemspec
5+
gem 'jsonapi-parser', path: '../jsonapi-parser'
6+
gem 'jsonapi-rb', path: '../jsonapi-rb'
7+
gem 'jsonapi-rails', path: '../jsonapi-rails', require: 'jsonapi/rails'
58
gem 'jsonapi-serializable', path: '../serializable'
9+
gem 'jsonapi-deserializable', path: '../jsonapi-deserializable'
610

711
group :test do
812
gem 'appraisal'

jsonapi_compliable.gemspec

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ Gem::Specification.new do |spec|
1818
spec.require_paths = ["lib"]
1919

2020
spec.add_dependency "rails", ['>= 4.1', '< 6']
21-
spec.add_dependency "jsonapi", '~> 0.1.1.beta2'
2221

2322
spec.add_dependency 'jsonapi-rails'
2423

lib/jsonapi_compliable/base.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def parse_fieldsets!
5151
Util::FieldParams.parse!(params, :extra_fields)
5252
end
5353

54-
def render_ams(scope, opts = {})
54+
def render_jsonapi(scope, opts = {})
5555
scoped = Util::Scoping.apply?(self, scope, opts.delete(:scope)) ? jsonapi_scope(scope) : scope
5656
options = default_ams_options
5757
options[:include] = forced_includes || Util::IncludeParams.scrub(self)
@@ -67,7 +67,7 @@ def render_ams(scope, opts = {})
6767
render(options)
6868
end
6969

70-
# render_ams(foo) equivalent to
70+
# render_jsonapi(foo) equivalent to
7171
# render json: foo, ams_default_options
7272
def default_ams_options
7373
{}.tap do |options|

lib/jsonapi_compliable/extensions/boolean_attribute.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
require 'jsonapi/serializable/conditional_fields'
2-
31
module JsonapiCompliable
42
module Extensions
53
module BooleanAttribute

lib/jsonapi_compliable/extensions/extra_attribute.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
require 'jsonapi/serializable/conditional_fields'
1+
require 'jsonapi/serializable/resource/conditional_fields'
22

33
module JsonapiCompliable
44
module Extensions
@@ -29,6 +29,6 @@ def extra_attribute(name, options = {}, &blk)
2929
end
3030

3131
JSONAPI::Serializable::Resource.class_eval do
32-
prepend JSONAPI::Serializable::ConditionalFields
32+
prepend JSONAPI::Serializable::Resource::ConditionalFields
3333
include JsonapiCompliable::Extensions::ExtraAttribute
3434
end

spec/create_update_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def create
1010
author = Author.new(author_params.except(:state_attributes))
1111
author.state = State.find_or_initialize_by(author_params[:state_attributes])
1212
author.save!(validate: false)
13-
render_ams(author, scope: false)
13+
render_jsonapi(author, scope: false)
1414
end
1515

1616
def update
@@ -21,7 +21,7 @@ def update
2121
end
2222
author.association(:books).loaded!
2323
author.save!
24-
render_ams(author, scope: false)
24+
render_jsonapi(author, scope: false)
2525
end
2626

2727
private

spec/extra_fields_spec.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
require 'spec_helper'
2-
require 'jsonapi/serializable/conditional_fields'
32

43
RSpec.describe 'extra_fields', type: :controller do
54
class SerializableTestExtraFields < JSONAPI::Serializable::Resource
6-
prepend JSONAPI::Serializable::ConditionalFields
75
type 'authors'
86
attributes :first_name, :last_name
97
extra_attribute :net_worth, if: proc { @context.allow_net_worth? } do
@@ -23,7 +21,7 @@ def allow_net_worth?
2321
end
2422

2523
def index
26-
render_ams(Author.all, class: SerializableTestExtraFields)
24+
render_jsonapi(Author.all, class: SerializableTestExtraFields)
2725
end
2826
end
2927

spec/fields_spec.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
require 'spec_helper'
2-
require 'jsonapi/serializable/conditional_fields'
32

43
RSpec.describe 'fields', type: :controller do
54
controller(ApplicationController) do
65
jsonapi {}
76

87
class SerializableTestFields < JSONAPI::Serializable::Resource
9-
prepend JSONAPI::Serializable::ConditionalFields
108
type 'authors'
119

1210
attribute :first_name
@@ -24,7 +22,7 @@ def admin?
2422
end
2523

2624
def index
27-
render_ams(Author.all, class: SerializableTestFields)
25+
render_jsonapi(Author.all, class: SerializableTestFields)
2826
end
2927

3028
def current_user

spec/filtering_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
end
1313

1414
def index
15-
render_ams(Author.all)
15+
render_jsonapi(Author.all)
1616
end
1717

1818
def can_filter_first_name?

spec/jsonapi_compliable_spec.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
def index
88
scope = Author.all
9-
render_ams(scope)
9+
render_jsonapi(scope)
1010
end
1111
end
1212

@@ -46,15 +46,15 @@ def index
4646
end
4747
end
4848

49-
describe '#render_ams' do
49+
describe '#render_jsonapi' do
5050
it 'is able to override options' do
5151
author = Author.create!(first_name: 'Stephen', last_name: 'King')
5252
author.books.create(title: "The Shining", genre: Genre.new(name: 'horror'))
5353

5454
controller.class_eval do
5555
def index
5656
scope = Author.all
57-
render_ams(scope, include: { books: :genre })
57+
render_jsonapi(scope, include: { books: :genre })
5858
end
5959
end
6060

@@ -67,7 +67,7 @@ def index
6767
controller.class_eval do
6868
def index
6969
people = jsonapi_scope(Author.all).to_a
70-
render_ams(people)
70+
render_jsonapi(people)
7171
end
7272
end
7373
end
@@ -97,7 +97,7 @@ def index
9797
controller.class_eval do
9898
def index
9999
people = Author.all
100-
render_ams(people, scope: false)
100+
render_jsonapi(people, scope: false)
101101
end
102102
end
103103
end

0 commit comments

Comments
 (0)