restpack_serializer 0.6.7 → 0.6.8

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: ec99f158a9e7825b3134792a1ea5ba5efb2a961f
4
- data.tar.gz: a33b39771c550f179826c344af688f5d9e84392b
3
+ metadata.gz: 7af1bc27d7c8835c4661909c30fc9dd85db99379
4
+ data.tar.gz: cdd08668865b3200810f2f296a6729b5aa29a1e1
5
5
  SHA512:
6
- metadata.gz: 6412ccee09177e52299f3b8bfbfcdefc5f541f18bb3e5ab95ef126ecb178fd8a7f8304e3ceda94c838d30904056727b9e9413b3175e7cfc437a8eb33214aacf7
7
- data.tar.gz: 8c2f759aa5ca1fcf1fa4d927e4fb6c156fdabb0a66a1fbc4bce6f9683d944a861d1b2b79107ae9ca8a23e633a6953dc72f25a67cc7c3dbe35f23f7042262a44b
6
+ metadata.gz: a9186bacc0ef4f585bd8e053e2ba678f980ce263f026fb6623812076bc22f3dc0d10490ac29f4bf31fa0c397dd205e86e96a59825c5cda097516a01914612fd5
7
+ data.tar.gz: e7e1ab1b5d90c07c5868a106888a0079f8fa3e4ad638ec97ba2d7d5b2114f75cd9d63e6f4898563fe208625d8bac8f02496c60b2633c5582ee55dac0349784cc
data/.gitignore CHANGED
@@ -3,3 +3,4 @@
3
3
  tmp
4
4
  /coverage
5
5
  Gemfile.lock
6
+ /.idea
@@ -1,5 +1,5 @@
1
1
  module RestPack
2
2
  module Serializer
3
- VERSION = '0.6.7'
3
+ VERSION = '0.6.8'
4
4
  end
5
5
  end
@@ -17,17 +17,18 @@ Gem::Specification.new do |gem|
17
17
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
18
  gem.require_paths = ["lib"]
19
19
 
20
- gem.add_dependency 'activesupport', ['>= 4.0.3', '< 5.0']
21
- gem.add_dependency 'activerecord', ['>= 4.0.3', '< 5.0']
22
- gem.add_dependency 'kaminari', '~> 0.16.1'
20
+ gem.add_dependency 'activesupport', ['>= 4.0.3', '< 6.0']
21
+ gem.add_dependency 'activerecord', ['>= 4.0.3', '< 6.0']
22
+ gem.add_dependency 'kaminari', '~> 0.17.0'
23
+ gem.add_dependency 'kaminari-mongoid', '~> 0.1'
23
24
 
24
25
  gem.add_development_dependency 'restpack_gem', '~> 0.0.9'
25
- gem.add_development_dependency 'rake', '~> 11.1.2'
26
- gem.add_development_dependency 'guard-rspec', '~> 4.6.4'
27
- gem.add_development_dependency 'factory_girl', '~> 4.7.0'
28
- gem.add_development_dependency 'sqlite3', '~> 1.3.7'
29
- gem.add_development_dependency 'database_cleaner', '~> 1.5.3'
26
+ gem.add_development_dependency 'rake', '~> 11.3'
27
+ gem.add_development_dependency 'guard-rspec', '~> 4.7'
28
+ gem.add_development_dependency 'factory_girl', '~> 4.7'
29
+ gem.add_development_dependency 'sqlite3', '~> 1.3'
30
+ gem.add_development_dependency 'database_cleaner', '~> 1.5'
30
31
  gem.add_development_dependency 'rspec'
31
32
  gem.add_development_dependency 'bump'
32
- gem.add_development_dependency 'protected_attributes', '~> 1.1.3'
33
+ gem.add_development_dependency 'protected_attributes_continued', '~> 1.2'
33
34
  end
@@ -5,45 +5,52 @@ describe RestPack::Serializer::Factory do
5
5
 
6
6
  describe "single-word" do
7
7
  it "creates by string" do
8
- factory.create("Song").should be_an_instance_of(MyApp::SongSerializer)
8
+ expect(factory.create("Song")).to be_an_instance_of(MyApp::SongSerializer)
9
9
  end
10
+
10
11
  it "creates by lowercase string" do
11
- factory.create("song").should be_an_instance_of(MyApp::SongSerializer)
12
+ expect(factory.create("song")).to be_an_instance_of(MyApp::SongSerializer)
12
13
  end
14
+
13
15
  it "creates by lowercase plural string" do
14
- factory.create("songs").should be_an_instance_of(MyApp::SongSerializer)
16
+ expect(factory.create("songs")).to be_an_instance_of(MyApp::SongSerializer)
15
17
  end
18
+
16
19
  it "creates by symbol" do
17
- factory.create(:song).should be_an_instance_of(MyApp::SongSerializer)
20
+ expect(factory.create(:song)).to be_an_instance_of(MyApp::SongSerializer)
18
21
  end
22
+
19
23
  it "creates by class" do
20
- factory.create(MyApp::Song).should be_an_instance_of(MyApp::SongSerializer)
24
+ expect(factory.create(MyApp::Song)).to be_an_instance_of(MyApp::SongSerializer)
21
25
  end
22
26
 
23
27
  it "creates multiple with Array" do
24
28
  serializers = factory.create("Song", "artists", :album)
25
- serializers[0].should be_an_instance_of(MyApp::SongSerializer)
26
- serializers[1].should be_an_instance_of(MyApp::ArtistSerializer)
27
- serializers[2].should be_an_instance_of(MyApp::AlbumSerializer)
29
+ expect(serializers[0]).to be_an_instance_of(MyApp::SongSerializer)
30
+ expect(serializers[1]).to be_an_instance_of(MyApp::ArtistSerializer)
31
+ expect(serializers[2]).to be_an_instance_of(MyApp::AlbumSerializer)
28
32
  end
29
33
  end
30
34
 
31
35
  describe "multi-word" do
32
36
  it "creates multi-word string" do
33
- factory.create("AlbumReview").should be_an_instance_of(MyApp::AlbumReviewSerializer)
37
+ expect(factory.create("AlbumReview")).to be_an_instance_of(MyApp::AlbumReviewSerializer)
34
38
  end
39
+
35
40
  it "creates multi-word lowercase string" do
36
- factory.create("album_review").should be_an_instance_of(MyApp::AlbumReviewSerializer)
41
+ expect(factory.create("album_review")).to be_an_instance_of(MyApp::AlbumReviewSerializer)
37
42
  end
43
+
38
44
  it "creates multi-word lowercase plural string" do
39
- factory.create("album_reviews").should be_an_instance_of(MyApp::AlbumReviewSerializer)
45
+ expect(factory.create("album_reviews")).to be_an_instance_of(MyApp::AlbumReviewSerializer)
40
46
  end
47
+
41
48
  it "creates multi-word symbol" do
42
- factory.create(:album_review).should be_an_instance_of(MyApp::AlbumReviewSerializer)
49
+ expect(factory.create(:album_review)).to be_an_instance_of(MyApp::AlbumReviewSerializer)
43
50
  end
51
+
44
52
  it "creates multi-word class" do
45
- factory.create(MyApp::AlbumReview).should be_an_instance_of(MyApp::AlbumReviewSerializer)
53
+ expect(factory.create(MyApp::AlbumReview)).to be_an_instance_of(MyApp::AlbumReviewSerializer)
46
54
  end
47
55
  end
48
-
49
56
  end
@@ -1,6 +1,6 @@
1
1
  require 'sqlite3'
2
2
  require 'active_record'
3
- require 'protected_attributes'
3
+ require 'protected_attributes_continued'
4
4
 
5
5
  ActiveRecord::Base.establish_connection(
6
6
  :adapter => 'sqlite3',
@@ -6,8 +6,8 @@ describe RestPack::Serializer do
6
6
 
7
7
  context "#setup" do
8
8
  it "has defaults" do
9
- subject.config.href_prefix.should == ''
10
- subject.config.page_size.should == 10
9
+ expect(subject.config.href_prefix).to eq('')
10
+ expect(subject.config.page_size).to eq(10)
11
11
  end
12
12
 
13
13
  it "can be configured" do
@@ -16,8 +16,8 @@ describe RestPack::Serializer do
16
16
  config.page_size = 50
17
17
  end
18
18
 
19
- subject.config.href_prefix.should == '/api/v1'
20
- subject.config.page_size.should == 50
19
+ expect(subject.config.href_prefix).to eq('/api/v1')
20
+ expect(subject.config.page_size).to eq(50)
21
21
  end
22
22
  end
23
23
  end
@@ -3,18 +3,19 @@ require 'spec_helper'
3
3
  describe RestPack::Serializer::Result do
4
4
  context 'a new instance' do
5
5
  it 'has defaults' do
6
- subject.resources.should == {}
7
- subject.meta.should == {}
8
- subject.links.should == {}
6
+ expect(subject.resources).to eq({})
7
+ expect(subject.meta).to eq({})
8
+ expect(subject.links).to eq({})
9
9
  end
10
10
  end
11
11
 
12
12
  context 'when serializing' do
13
13
  let(:result) { subject.serialize }
14
+
14
15
  context 'in jsonapi.org format' do
15
16
  context 'an empty result' do
16
17
  it 'returns an empty result' do
17
- result.should == {}
18
+ expect(result).to eq({})
18
19
  end
19
20
  end
20
21
 
@@ -26,9 +27,9 @@ describe RestPack::Serializer::Result do
26
27
  end
27
28
 
28
29
  it 'returns correct jsonapi.org format' do
29
- result[:albums].should == subject.resources[:albums]
30
- result[:meta].should == subject.meta
31
- result[:links].should == subject.links
30
+ expect(result[:albums]).to eq(subject.resources[:albums])
31
+ expect(result[:meta]).to eq(subject.meta)
32
+ expect(result[:links]).to eq(subject.links)
32
33
  end
33
34
  end
34
35
 
@@ -43,16 +44,16 @@ describe RestPack::Serializer::Result do
43
44
  end
44
45
 
45
46
  it 'returns correct jsonapi.org format, including injected has_many links' do
46
- result[:albums].should == [{ id: '1', name: 'AMOK', links: { songs: ['91'] } }]
47
- result[:links].should == subject.links
48
- result[:linked][:songs].should == subject.resources[:songs]
47
+ expect(result[:albums]).to eq([{ id: '1', name: 'AMOK', links: { songs: ['91'] } }])
48
+ expect(result[:links]).to eq(subject.links)
49
+ expect(result[:linked][:songs]).to eq(subject.resources[:songs])
49
50
  end
50
51
 
51
52
  it 'includes resources in correct order' do
52
- result.keys[0].should == :albums
53
- result.keys[1].should == :linked
54
- result.keys[2].should == :links
55
- result.keys[3].should == :meta
53
+ expect(result.keys[0]).to eq(:albums)
54
+ expect(result.keys[1]).to eq(:linked)
55
+ expect(result.keys[2]).to eq(:links)
56
+ expect(result.keys[3]).to eq(:meta)
56
57
  end
57
58
 
58
59
  context 'with multiple calls to serialize' do
@@ -62,7 +63,7 @@ describe RestPack::Serializer::Result do
62
63
  end
63
64
 
64
65
  it 'does not create duplicate has_many links' do
65
- result[:albums].first[:links][:songs].count.should == 1
66
+ expect(result[:albums].first[:links][:songs].count).to eq(1)
66
67
  end
67
68
  end
68
69
  end
@@ -9,6 +9,6 @@ describe RestPack::Serializer::Filterable do
9
9
  end
10
10
 
11
11
  it "captures the specified filters" do
12
- CustomSerializer.serializable_filters.should == [:a, :c]
12
+ expect(CustomSerializer.serializable_filters).to eq([:a, :c])
13
13
  end
14
14
  end
@@ -6,94 +6,99 @@ describe RestPack::Serializer::Options do
6
6
  let(:scope) { nil }
7
7
 
8
8
  describe 'default values' do
9
- it { subject.model_class.should == MyApp::Song }
10
- it { subject.include.should == [] }
11
- it { subject.page.should == 1 }
12
- it { subject.page_size.should == 10 }
13
- it { subject.filters.should == {} }
14
- it { subject.scope.should == MyApp::Song.all }
15
- it { subject.default_page_size?.should == true }
16
- it { subject.filters_as_url_params.should == '' }
9
+ it { expect(subject.model_class).to eq(MyApp::Song) }
10
+ it { expect(subject.include).to eq([]) }
11
+ it { expect(subject.page).to eq(1) }
12
+ it { expect(subject.page_size).to eq(10) }
13
+ it { expect(subject.filters).to eq({}) }
14
+ it { expect(subject.scope).to eq(MyApp::Song.all) }
15
+ it { expect(subject.default_page_size?).to eq(true) }
16
+ it { expect(subject.filters_as_url_params).to eq('') }
17
17
  end
18
18
 
19
19
  describe 'with paging params' do
20
20
  let(:params) { { 'page' => '2', 'page_size' => '8' } }
21
- it { subject.page.should == 2 }
22
- it { subject.page_size.should == 8 }
21
+ it { expect(subject.page).to eq(2) }
22
+ it { expect(subject.page_size).to eq(8) }
23
23
  end
24
24
 
25
25
  describe 'with include' do
26
26
  let(:params) { { 'include' => 'model1,model2' } }
27
- it { subject.include.should == ["model1", "model2"] }
27
+ it { expect(subject.include).to eq(%w(model1 model2)) }
28
28
  end
29
29
 
30
30
  context 'with filters' do
31
31
  describe 'with no filter params' do
32
- let(:params) { { } }
33
- it { subject.filters.should == {} }
32
+ let(:params) { {} }
33
+ it { expect(subject.filters).to eq({}) }
34
34
  end
35
+
35
36
  describe 'with a primary key with a single value' do
36
37
  let(:params) { { 'id' => '142857' } }
37
- it { subject.filters.should == { id: ['142857'] } }
38
- it { subject.filters_as_url_params.should == 'id=142857' }
38
+ it { expect(subject.filters).to eq(id: %w(142857)) }
39
+ it { expect(subject.filters_as_url_params).to eq('id=142857') }
39
40
  end
41
+
40
42
  describe 'with a primary key with multiple values' do
41
43
  let(:params) { { 'ids' => '42,142857' } }
42
- it { subject.filters.should == { id: ['42', '142857'] } }
43
- it { subject.filters_as_url_params.should == 'id=42,142857' }
44
+ it { expect(subject.filters).to eq(id: %w(42 142857)) }
45
+ it { expect(subject.filters_as_url_params).to eq('id=42,142857') }
44
46
  end
47
+
45
48
  describe 'with a foreign key with a single value' do
46
49
  let(:params) { { 'album_id' => '789' } }
47
- it { subject.filters.should == { album_id: ['789'] } }
48
- it { subject.filters_as_url_params.should == 'album_id=789' }
50
+ it { expect(subject.filters).to eq(album_id: %w(789)) }
51
+ it { expect(subject.filters_as_url_params).to eq('album_id=789') }
49
52
  end
53
+
50
54
  describe 'with a foreign key with multiple values' do
51
55
  let(:params) { { 'album_id' => '789,678,567' } }
52
- it { subject.filters.should == { album_id: ['789', '678', '567'] } }
53
- it { subject.filters_as_url_params.should == 'album_id=789,678,567' }
56
+ it { expect(subject.filters).to eq(album_id: %w(789 678 567)) }
57
+ it { expect(subject.filters_as_url_params).to eq('album_id=789,678,567') }
54
58
  end
59
+
55
60
  describe 'with multiple foreign keys' do
56
61
  let(:params) { { 'album_id' => '111,222', 'artist_id' => '888,999' } }
57
- it { subject.filters.should == { album_id: ['111', '222'], artist_id: ['888', '999'] } }
58
- it { subject.filters_as_url_params.should == 'album_id=111,222&artist_id=888,999' }
62
+ it { expect(subject.filters).to eq(album_id: %w(111 222), artist_id: %w(888 999)) }
63
+ it { expect(subject.filters_as_url_params).to eq('album_id=111,222&artist_id=888,999') }
59
64
  end
60
65
  end
61
66
 
62
67
  context 'with sorting parameters' do
63
68
  describe 'with no params' do
64
- let(:params) { { } }
65
- it { subject.sorting.should == {} }
69
+ let(:params) { {} }
70
+ it { expect(subject.sorting).to eq({}) }
66
71
  end
67
72
  describe 'with a sorting value' do
68
73
  let(:params) { { 'sort' => 'Title' } }
69
- it { subject.sorting.should == { title: :asc } }
70
- it { subject.sorting_as_url_params.should == 'sort=title' }
74
+ it { expect(subject.sorting).to eq(title: :asc) }
75
+ it { expect(subject.sorting_as_url_params).to eq('sort=title') }
71
76
  end
72
77
  describe 'with a descending sorting value' do
73
78
  let(:params) { { 'sort' => '-title' } }
74
- it { subject.sorting.should == { title: :desc } }
75
- it { subject.sorting_as_url_params.should == 'sort=-title' }
79
+ it { expect(subject.sorting).to eq(title: :desc) }
80
+ it { expect(subject.sorting_as_url_params).to eq('sort=-title') }
76
81
  end
77
82
  describe 'with multiple sorting values' do
78
83
  let(:params) { { 'sort' => '-Title,ID' } }
79
- it { subject.sorting.should == { title: :desc, id: :asc } }
80
- it { subject.sorting_as_url_params.should == 'sort=-title,id' }
84
+ it { expect(subject.sorting).to eq(title: :desc, id: :asc) }
85
+ it { expect(subject.sorting_as_url_params).to eq('sort=-title,id') }
81
86
  end
82
87
  describe 'with a not allowed sorting value' do
83
88
  let(:params) { { 'sort' => '-title,album_id,id' } }
84
- it { subject.sorting.should == { title: :desc, id: :asc } }
85
- it { subject.sorting_as_url_params.should == 'sort=-title,id' }
89
+ it { expect(subject.sorting).to eq(title: :desc, id: :asc) }
90
+ it { expect(subject.sorting_as_url_params).to eq('sort=-title,id') }
86
91
  end
87
92
  end
88
93
 
89
94
  context 'scopes' do
90
95
  describe 'with default scope' do
91
- it { subject.scope.should == MyApp::Song.all }
96
+ it { expect(subject.scope).to eq(MyApp::Song.all) }
92
97
  end
93
98
 
94
99
  describe 'with custom scope' do
95
100
  let(:scope) { MyApp::Song.where("id >= 100") }
96
- it { subject.scope.should == scope }
101
+ it { expect(subject.scope).to eq(scope) }
97
102
  end
98
103
  end
99
104
  end
@@ -8,32 +8,35 @@ describe RestPack::Serializer::Paging do
8
8
 
9
9
  context "#page" do
10
10
  let(:page) { MyApp::SongSerializer.page(params, scope, context) }
11
- let(:params) { { } }
11
+ let(:params) { {} }
12
12
  let(:scope) { nil }
13
- let(:context) { { } }
13
+ let(:context) { {} }
14
14
 
15
15
  context "with defaults" do
16
16
  it "page defaults to 1" do
17
- page[:meta][:songs][:page].should == 1
17
+ expect(page[:meta][:songs][:page]).to eq(1)
18
18
  end
19
+
19
20
  it "page_size defaults to 10" do
20
- page[:meta][:songs][:page_size].should == 10
21
+ expect(page[:meta][:songs][:page_size]).to eq(10)
21
22
  end
23
+
22
24
  it "includes valid paging meta data" do
23
- page[:meta][:songs][:count].should == 18
24
- page[:meta][:songs][:page_count].should == 2
25
- page[:meta][:songs][:first_href].should == '/songs'
26
- page[:meta][:songs][:previous_page].should == nil
27
- page[:meta][:songs][:previous_href].should == nil
28
- page[:meta][:songs][:next_page].should == 2
29
- page[:meta][:songs][:next_href].should == '/songs?page=2'
30
- page[:meta][:songs][:last_href].should == '/songs?page=2'
25
+ expect(page[:meta][:songs][:count]).to eq(18)
26
+ expect(page[:meta][:songs][:page_count]).to eq(2)
27
+ expect(page[:meta][:songs][:first_href]).to eq('/songs')
28
+ expect(page[:meta][:songs][:previous_page]).to eq(nil)
29
+ expect(page[:meta][:songs][:previous_href]).to eq(nil)
30
+ expect(page[:meta][:songs][:next_page]).to eq(2)
31
+ expect(page[:meta][:songs][:next_href]).to eq('/songs?page=2')
32
+ expect(page[:meta][:songs][:last_href]).to eq('/songs?page=2')
31
33
  end
34
+
32
35
  it "includes links" do
33
- page[:links].should == {
34
- 'songs.album' => { :href => "/albums/{songs.album}", :type => :albums },
35
- 'songs.artist' => { :href => "/artists/{songs.artist}", :type => :artists }
36
- }
36
+ expect(page[:links]).to eq(
37
+ 'songs.album' => { href: "/albums/{songs.album}", type: :albums },
38
+ 'songs.artist' => { href: "/artists/{songs.artist}", type: :artists }
39
+ )
37
40
  end
38
41
  end
39
42
 
@@ -42,42 +45,44 @@ describe RestPack::Serializer::Paging do
42
45
  @original_prefix = MyApp::SongSerializer.href_prefix
43
46
  MyApp::SongSerializer.href_prefix = '/api/v3'
44
47
  end
45
- after do
46
- MyApp::SongSerializer.href_prefix = @original_prefix
47
- end
48
- let(:page) do
49
- MyApp::SongSerializer.page(params, scope, context)
50
- end
48
+ after { MyApp::SongSerializer.href_prefix = @original_prefix }
49
+
50
+ let(:page) { MyApp::SongSerializer.page(params, scope, context) }
51
+
51
52
  it 'should use prefixed links' do
52
- page[:meta][:songs][:next_href].should == '/api/v3/songs?page=2'
53
+ expect(page[:meta][:songs][:next_href]).to eq('/api/v3/songs?page=2')
53
54
  end
54
55
  end
55
56
 
56
57
  context "with custom page size" do
57
58
  let(:params) { { page_size: '3' } }
59
+
58
60
  it "returns custom page sizes" do
59
- page[:meta][:songs][:page_size].should == 3
60
- page[:meta][:songs][:page_count].should == 6
61
+ expect(page[:meta][:songs][:page_size]).to eq(3)
62
+ expect(page[:meta][:songs][:page_count]).to eq(6)
61
63
  end
64
+
62
65
  it "includes the custom page size in the page hrefs" do
63
- page[:meta][:songs][:next_page].should == 2
64
- page[:meta][:songs][:next_href].should == '/songs?page=2&page_size=3'
65
- page[:meta][:songs][:last_href].should == '/songs?page=6&page_size=3'
66
+ expect(page[:meta][:songs][:next_page]).to eq(2)
67
+ expect(page[:meta][:songs][:next_href]).to eq('/songs?page=2&page_size=3')
68
+ expect(page[:meta][:songs][:last_href]).to eq('/songs?page=6&page_size=3')
66
69
  end
67
70
  end
68
71
 
69
72
  context "with custom filter" do
70
73
  context "valid :title" do
71
74
  let(:params) { { title: @album1.songs[0].title } }
75
+
72
76
  it "returns the album" do
73
- page[:meta][:songs][:count].should == 1
77
+ expect(page[:meta][:songs][:count]).to eq(1)
74
78
  end
75
79
  end
76
80
 
77
81
  context "invalid :title" do
78
82
  let(:params) { { title: "this doesn't exist" } }
83
+
79
84
  it "returns the album" do
80
- page[:meta][:songs][:count].should == 0
85
+ expect(page[:meta][:songs][:count]).to eq(0)
81
86
  end
82
87
  end
83
88
  end
@@ -87,13 +92,13 @@ describe RestPack::Serializer::Paging do
87
92
 
88
93
  it "returns reversed titles" do
89
94
  first = MyApp::Song.first
90
- page[:songs].first[:title].should == first.title.reverse
95
+ expect(page[:songs].first[:title]).to eq(first.title.reverse)
91
96
  end
92
97
  end
93
98
 
94
99
  it "serializes results" do
95
100
  first = MyApp::Song.first
96
- page[:songs].first.should == {
101
+ expect(page[:songs].first).to eq(
97
102
  id: first.id.to_s,
98
103
  title: first.title,
99
104
  album_id: first.album_id,
@@ -101,17 +106,17 @@ describe RestPack::Serializer::Paging do
101
106
  album: first.album_id.to_s,
102
107
  artist: first.artist_id.to_s
103
108
  }
104
- }
109
+ )
105
110
  end
106
111
 
107
112
  context "first page" do
108
113
  let(:params) { { page: '1' } }
109
114
 
110
115
  it "returns first page" do
111
- page[:meta][:songs][:page].should == 1
112
- page[:meta][:songs][:page_size].should == 10
113
- page[:meta][:songs][:previous_page].should == nil
114
- page[:meta][:songs][:next_page].should == 2
116
+ expect(page[:meta][:songs][:page]).to eq(1)
117
+ expect(page[:meta][:songs][:page_size]).to eq(10)
118
+ expect(page[:meta][:songs][:previous_page]).to eq(nil)
119
+ expect(page[:meta][:songs][:next_page]).to eq(2)
115
120
  end
116
121
  end
117
122
 
@@ -119,11 +124,11 @@ describe RestPack::Serializer::Paging do
119
124
  let(:params) { { page: '2' } }
120
125
 
121
126
  it "returns second page" do
122
- page[:songs].length.should == 8
123
- page[:meta][:songs][:page].should == 2
124
- page[:meta][:songs][:previous_page].should == 1
125
- page[:meta][:songs][:next_page].should == nil
126
- page[:meta][:songs][:previous_href].should == '/songs'
127
+ expect(page[:songs].length).to eq(8)
128
+ expect(page[:meta][:songs][:page]).to eq(2)
129
+ expect(page[:meta][:songs][:previous_page]).to eq(1)
130
+ expect(page[:meta][:songs][:next_page]).to eq(nil)
131
+ expect(page[:meta][:songs][:previous_href]).to eq('/songs')
127
132
  end
128
133
  end
129
134
 
@@ -131,48 +136,49 @@ describe RestPack::Serializer::Paging do
131
136
  let(:params) { { include: 'albums' } }
132
137
 
133
138
  it "includes side-loaded models" do
134
- page[:linked][:albums].should_not == nil
139
+ expect(page[:linked][:albums]).not_to eq(nil)
135
140
  end
136
141
 
137
142
  it "includes the side-loads in the main meta data" do
138
- page[:meta][:songs][:include].should == ["albums"]
143
+ expect(page[:meta][:songs][:include]).to eq(%w(albums))
139
144
  end
140
145
 
141
146
  it "includes the side-loads in page hrefs" do
142
- page[:meta][:songs][:next_href].should == '/songs?page=2&include=albums'
147
+ expect(page[:meta][:songs][:next_href]).to eq('/songs?page=2&include=albums')
143
148
  end
144
149
 
145
150
  it "includes links between documents" do
146
151
  song = page[:songs].first
147
152
  song_model = MyApp::Song.find(song[:id])
148
- song[:links][:album].should == song_model.album_id.to_s
149
- song[:links][:artist].should == song_model.artist_id.to_s
153
+ expect(song[:links][:album]).to eq(song_model.album_id.to_s)
154
+ expect(song[:links][:artist]).to eq(song_model.artist_id.to_s)
150
155
 
151
156
  album = page[:linked][:albums].first
152
157
  album_model = MyApp::Album.find(album[:id])
153
158
 
154
- album[:links][:artist].should == album_model.artist_id.to_s
155
- (page[:songs].map { |song| song[:id] } - album[:links][:songs]).empty?.should be_truthy
159
+ expect(album[:links][:artist]).to eq(album_model.artist_id.to_s)
160
+ expect((page[:songs].map { |song| song[:id] } - album[:links][:songs]).empty?).to eq(true)
156
161
  end
157
162
 
158
163
  context "with includes as comma delimited string" do
159
164
  let(:params) { { include: "albums,artists" } }
165
+
160
166
  it "includes side-loaded models" do
161
- page[:linked][:albums].should_not == nil
162
- page[:linked][:artists].should_not == nil
167
+ expect(page[:linked][:albums]).not_to eq(nil)
168
+ expect(page[:linked][:artists]).not_to eq(nil)
163
169
  end
164
170
 
165
171
  it "includes the side-loads in page hrefs" do
166
- page[:meta][:songs][:next_href].should == '/songs?page=2&include=albums,artists'
172
+ expect(page[:meta][:songs][:next_href]).to eq('/songs?page=2&include=albums,artists')
167
173
  end
168
174
 
169
175
  it "includes links" do
170
- page[:links]['songs.album'].should_not == nil
171
- page[:links]['songs.artist'].should_not == nil
172
- page[:links]['albums.songs'].should_not == nil
173
- page[:links]['albums.artist'].should_not == nil
174
- page[:links]['artists.songs'].should_not == nil
175
- page[:links]['artists.albums'].should_not == nil
176
+ expect(page[:links]['songs.album']).not_to eq(nil)
177
+ expect(page[:links]['songs.artist']).not_to eq(nil)
178
+ expect(page[:links]['albums.songs']).not_to eq(nil)
179
+ expect(page[:links]['albums.artist']).not_to eq(nil)
180
+ expect(page[:links]['artists.songs']).not_to eq(nil)
181
+ expect(page[:links]['artists.albums']).not_to eq(nil)
176
182
  end
177
183
  end
178
184
  end
@@ -182,7 +188,7 @@ describe RestPack::Serializer::Paging do
182
188
  let(:params) { {} }
183
189
 
184
190
  it "returns a page of all data" do
185
- page[:meta][:songs][:count].should == 18
191
+ expect(page[:meta][:songs][:count]).to eq(18)
186
192
  end
187
193
  end
188
194
 
@@ -190,11 +196,11 @@ describe RestPack::Serializer::Paging do
190
196
  let(:params) { { album_id: @album1.id.to_s } }
191
197
 
192
198
  it "returns a page with songs from album1" do
193
- page[:meta][:songs][:count].should == @album1.songs.length
199
+ expect(page[:meta][:songs][:count]).to eq(@album1.songs.length)
194
200
  end
195
201
 
196
202
  it "includes the filter in page hrefs" do
197
- page[:meta][:songs][:next_href].should == "/songs?page=2&album_id=#{@album1.id}"
203
+ expect(page[:meta][:songs][:next_href]).to eq("/songs?page=2&album_id=#{@album1.id}")
198
204
  end
199
205
  end
200
206
  end
@@ -204,7 +210,7 @@ describe RestPack::Serializer::Paging do
204
210
  let(:params) { {} }
205
211
 
206
212
  it "uses the model's sorting" do
207
- page[:songs].first[:id].to_i.should < page[:songs].last[:id].to_i
213
+ expect(page[:songs].first[:id].to_i < page[:songs].last[:id].to_i).to eq(true)
208
214
  end
209
215
  end
210
216
 
@@ -212,11 +218,11 @@ describe RestPack::Serializer::Paging do
212
218
  let(:params) { { sort: '-title' } }
213
219
 
214
220
  it 'returns a page with sorted songs' do
215
- page[:songs].first[:title].should > page[:songs].last[:title]
221
+ expect(page[:songs].first[:title] > page[:songs].last[:title]).to eq(true)
216
222
  end
217
223
 
218
224
  it 'includes the sorting in page hrefs' do
219
- page[:meta][:songs][:next_href].should == '/songs?page=2&sort=-title'
225
+ expect(page[:meta][:songs][:next_href]).to eq('/songs?page=2&sort=-title')
220
226
  end
221
227
  end
222
228
  end
@@ -230,7 +236,7 @@ describe RestPack::Serializer::Paging do
230
236
  let(:scope) { MyApp::Album.classic }
231
237
 
232
238
  it "returns a page of scoped data" do
233
- page[:meta][:albums][:count].should == 2
239
+ expect(page[:meta][:albums][:count]).to eq(2)
234
240
  end
235
241
  end
236
242
  end
@@ -242,43 +248,44 @@ describe RestPack::Serializer::Paging do
242
248
 
243
249
  context "with defaults" do
244
250
  it "includes valid paging meta data" do
245
- page[:meta][:songs][:count].should == 18
246
- page[:meta][:songs][:page_count].should == 2
247
- page[:meta][:songs][:previous_page].should == nil
248
- page[:meta][:songs][:next_page].should == 2
251
+ expect(page[:meta][:songs][:count]).to eq(18)
252
+ expect(page[:meta][:songs][:page_count]).to eq(2)
253
+ expect(page[:meta][:songs][:previous_page]).to eq(nil)
254
+ expect(page[:meta][:songs][:next_page]).to eq(2)
249
255
  end
250
256
  end
251
257
 
252
258
  context "with custom page size" do
253
259
  let(:params) { { page_size: '3' } }
260
+
254
261
  it "returns custom page sizes" do
255
- page[:meta][:songs][:page_size].should == 3
256
- page[:meta][:songs][:page_count].should == 6
262
+ expect(page[:meta][:songs][:page_size]).to eq(3)
263
+ expect(page[:meta][:songs][:page_count]).to eq(6)
257
264
  end
258
265
  end
259
266
  end
260
267
 
261
268
  context "paging with paged side-load" do
262
269
  let(:page) { MyApp::AlbumSerializer.page_with_options(options) }
263
- let(:options) { RestPack::Serializer::Options.new(MyApp::AlbumSerializer, { include: 'songs' }) }
270
+ let(:options) { RestPack::Serializer::Options.new(MyApp::AlbumSerializer, include: 'songs') }
264
271
 
265
272
  it "includes side-loaded paging data in meta data" do
266
- page[:meta][:albums].should_not == nil
267
- page[:meta][:albums][:page].should == 1
268
- page[:meta][:songs].should_not == nil
269
- page[:meta][:songs][:page].should == 1
273
+ expect(page[:meta][:albums]).not_to eq(nil)
274
+ expect(page[:meta][:albums][:page]).to eq(1)
275
+ expect(page[:meta][:songs]).not_to eq(nil)
276
+ expect(page[:meta][:songs][:page]).to eq(1)
270
277
  end
271
278
  end
272
279
 
273
280
  context "paging with two paged side-loads" do
274
281
  let(:page) { MyApp::ArtistSerializer.page_with_options(options) }
275
- let(:options) { RestPack::Serializer::Options.new(MyApp::ArtistSerializer, { include: 'albums,songs' }) }
282
+ let(:options) { RestPack::Serializer::Options.new(MyApp::ArtistSerializer, include: 'albums,songs') }
276
283
 
277
284
  it "includes side-loaded paging data in meta data" do
278
- page[:meta][:albums].should_not == nil
279
- page[:meta][:albums][:page].should == 1
280
- page[:meta][:songs].should_not == nil
281
- page[:meta][:songs][:page].should == 1
285
+ expect(page[:meta][:albums]).not_to eq(nil)
286
+ expect(page[:meta][:albums][:page]).to eq(1)
287
+ expect(page[:meta][:songs]).not_to eq(nil)
288
+ expect(page[:meta][:songs][:page]).to eq(1)
282
289
  end
283
290
  end
284
291
  end