jsonapi-resources 0.5.6 → 0.5.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e9dfa52ac05f532050b9740a884e624b27f40dcc
4
- data.tar.gz: 515bc38bde0559a474dcfbc7ec9891a9cc79d1eb
3
+ metadata.gz: ab4c4a0d0d8f176e2085aee265a0d0678876c8bd
4
+ data.tar.gz: 04ea25473f89a0bf77df0778b2ebaa7d4dd3aa8d
5
5
  SHA512:
6
- metadata.gz: c47e723f53c1b0d30ef1ab99f19841b5c1bb6ed808a441739d3d065e3e7ef57513881f7644a579766eb652df57d280a98eaa6c44f3d57c53f7158a5a045e50e5
7
- data.tar.gz: 2644748a35a9e4de7554be0627068a044611600f43195ddf41fd28be1f33cd5df4d047605d74f950efccd9df3b48a968f2e42dd3c6846195fb5916cf126a182a
6
+ metadata.gz: b19b8f700405d1caf6d676a1d984d8d2e0a82aa3d0df31b140d26484f318e74fc94311b4744e40d16ca7bf900a64a27a86351fe588bdee413569da5bbc299c63
7
+ data.tar.gz: 09b9a7ac8901f2b3c6ff218b8680c8cc313d806cfbd472989623f94871d95466375b6929cbfb2d48105799598a2fdeeee67fd27915fc054e1f53ea191a469d55
@@ -158,7 +158,7 @@ module JSONAPI
158
158
  end
159
159
 
160
160
  def records
161
- related_resource_records = source_resource.records_for(@relationship_type)
161
+ related_resource_records = source_resource.public_send(@relationship_type)
162
162
  @resource_klass.filter_records(@filters, @options, related_resource_records)
163
163
  end
164
164
 
@@ -111,8 +111,8 @@ module JSONAPI
111
111
 
112
112
  # Override this on a resource to customize how the associated records
113
113
  # are fetched for a model. Particularly helpful for authorization.
114
- def records_for(relationship_name, _options = {})
115
- model.public_send relationship_name
114
+ def records_for(relation_name, _options = {})
115
+ model.public_send relation_name
116
116
  end
117
117
 
118
118
  private
@@ -1,5 +1,5 @@
1
1
  module JSONAPI
2
2
  module Resources
3
- VERSION = '0.5.6'
3
+ VERSION = '0.5.7'
4
4
  end
5
5
  end
@@ -1026,6 +1026,8 @@ module Api
1026
1026
  end
1027
1027
  }
1028
1028
 
1029
+ has_many :aliased_comments, class_name: 'BookComments', relation_name: :approved_book_comments
1030
+
1029
1031
  filters :banned, :book_comments
1030
1032
 
1031
1033
  class << self
@@ -410,7 +410,7 @@ class RequestTest < ActionDispatch::IntegrationTest
410
410
  get '/api/v2/books/1/book_comments?page[limit]=10'
411
411
  assert_equal 'http://www.example.com/api/v2/books/1/book_comments?page%5Blimit%5D=10&page%5Boffset%5D=0', json_response['links']['first']
412
412
  assert_equal 'http://www.example.com/api/v2/books/1/book_comments?page%5Blimit%5D=10&page%5Boffset%5D=10', json_response['links']['next']
413
- assert_equal 'http://www.example.com/api/v2/books/1/book_comments?page%5Blimit%5D=10&page%5Boffset%5D=41', json_response['links']['last']
413
+ assert_equal 'http://www.example.com/api/v2/books/1/book_comments?page%5Blimit%5D=10&page%5Boffset%5D=16', json_response['links']['last']
414
414
  end
415
415
 
416
416
  def test_pagination_related_resources_links_meta
@@ -418,10 +418,10 @@ class RequestTest < ActionDispatch::IntegrationTest
418
418
  Api::V2::BookCommentResource.paginator :offset
419
419
  JSONAPI.configuration.top_level_meta_include_record_count = true
420
420
  get '/api/v2/books/1/book_comments?page[limit]=10'
421
- assert_equal 51, json_response['meta']['record_count']
421
+ assert_equal 26, json_response['meta']['record_count']
422
422
  assert_equal 'http://www.example.com/api/v2/books/1/book_comments?page%5Blimit%5D=10&page%5Boffset%5D=0', json_response['links']['first']
423
423
  assert_equal 'http://www.example.com/api/v2/books/1/book_comments?page%5Blimit%5D=10&page%5Boffset%5D=10', json_response['links']['next']
424
- assert_equal 'http://www.example.com/api/v2/books/1/book_comments?page%5Blimit%5D=10&page%5Boffset%5D=41', json_response['links']['last']
424
+ assert_equal 'http://www.example.com/api/v2/books/1/book_comments?page%5Blimit%5D=10&page%5Boffset%5D=16', json_response['links']['last']
425
425
  ensure
426
426
  JSONAPI.configuration.top_level_meta_include_record_count = false
427
427
  end
@@ -436,6 +436,18 @@ class RequestTest < ActionDispatch::IntegrationTest
436
436
  assert_equal 'http://www.example.com/api/v2/books/10/book_comments?page%5Blimit%5D=10&page%5Boffset%5D=0', json_response['links']['last']
437
437
  end
438
438
 
439
+ def test_related_resource_alternate_relation_name_record_count
440
+ original_config = JSONAPI.configuration.dup
441
+ JSONAPI.configuration.default_paginator = :paged
442
+ JSONAPI.configuration.top_level_meta_include_record_count = true
443
+
444
+ get '/api/v2/books/1/aliased_comments'
445
+ assert_equal 200, status
446
+ assert_equal 26, json_response['meta']['record_count']
447
+ ensure
448
+ JSONAPI.configuration = original_config
449
+ end
450
+
439
451
  def test_pagination_related_resources_data_includes
440
452
  Api::V2::BookResource.paginator :offset
441
453
  Api::V2::BookCommentResource.paginator :offset
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jsonapi-resources
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.6
4
+ version: 0.5.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dan Gebhardt
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-08-11 00:00:00.000000000 Z
12
+ date: 2015-08-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler