restpack_serializer 0.4.2 → 0.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/LICENSE +2 -2
- data/lib/restpack_serializer/factory.rb +6 -4
- data/lib/restpack_serializer/serializable.rb +8 -0
- data/lib/restpack_serializer/version.rb +1 -1
- data/spec/factory/factory_spec.rb +8 -8
- data/spec/fixtures/db.rb +22 -20
- data/spec/fixtures/serializers.rb +16 -14
- data/spec/serializable/options_spec.rb +5 -5
- data/spec/serializable/paging_spec.rb +10 -10
- data/spec/serializable/resource_spec.rb +2 -2
- data/spec/serializable/serializer_spec.rb +1 -1
- data/spec/serializable/side_loading/belongs_to_spec.rb +11 -11
- data/spec/serializable/side_loading/has_many_spec.rb +3 -3
- data/spec/serializable/side_loading/side_loading_spec.rb +9 -9
- data/spec/support/factory.rb +5 -5
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d39e57d828f7ab0187a771d4ab43da44a92da1d1
|
4
|
+
data.tar.gz: c119977625b408dfd76a740b3e5cb8d87b9be867
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e271bc108f3d4596c46a8c4e59e724b55936861fa9f7ba0d6e2557c68e955e3b426bfd38e95f4bb30fe27f3d65907bdef31bacc0a93528d6208eb810cfa0acf0
|
7
|
+
data.tar.gz: 11861d3dd864bb37279d4a5afd410ed6b7a6758ebb5824e578964c9b75f40dac400fd2a0a0fb09be6ee298b849ece4fa2a8791ac76746e7090b32c75165b33f1
|
data/LICENSE
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
Copyright (c) 2013 Gavin Joyce
|
1
|
+
Copyright (c) 2013 Gavin Joyce
|
2
2
|
Copyright (c) 2011-2012 José Valim & Yehuda Katz (https://github.com/rails-api/active_model_serializers/blob/master/MIT-LICENSE.txt)
|
3
3
|
|
4
4
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
@@ -17,4 +17,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
17
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
18
18
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
19
19
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
20
|
-
SOFTWARE.
|
20
|
+
SOFTWARE.
|
@@ -7,10 +7,12 @@ class RestPack::Serializer::Factory
|
|
7
7
|
private
|
8
8
|
|
9
9
|
def self.classify(identifier)
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
normalised_identifier = identifier.to_s.downcase
|
11
|
+
[normalised_identifier, normalised_identifier.singularize].each do |format|
|
12
|
+
klass = RestPack::Serializer.class_map[format]
|
13
|
+
return klass.new if klass
|
14
14
|
end
|
15
|
+
|
16
|
+
raise "Invalid RestPack::Serializer : #{identifier}"
|
15
17
|
end
|
16
18
|
end
|
@@ -8,6 +8,14 @@ require_relative "serializable/side_loading"
|
|
8
8
|
module RestPack
|
9
9
|
module Serializer
|
10
10
|
extend ActiveSupport::Concern
|
11
|
+
mattr_accessor :class_map
|
12
|
+
@@class_map ||= {}
|
13
|
+
|
14
|
+
included do
|
15
|
+
identifier = self.to_s.downcase.chomp('serializer')
|
16
|
+
@@class_map[identifier] = self
|
17
|
+
@@class_map[identifier.split('::').last] = self
|
18
|
+
end
|
11
19
|
|
12
20
|
include RestPack::Serializer::Paging
|
13
21
|
include RestPack::Serializer::Resource
|
@@ -4,25 +4,25 @@ describe RestPack::Serializer::Factory do
|
|
4
4
|
let(:factory) { RestPack::Serializer::Factory }
|
5
5
|
|
6
6
|
it "creates by string" do
|
7
|
-
factory.create("Song").should be_an_instance_of(SongSerializer)
|
7
|
+
factory.create("Song").should be_an_instance_of(MyApp::SongSerializer)
|
8
8
|
end
|
9
9
|
it "creates by lowercase string" do
|
10
|
-
factory.create("song").should be_an_instance_of(SongSerializer)
|
10
|
+
factory.create("song").should be_an_instance_of(MyApp::SongSerializer)
|
11
11
|
end
|
12
12
|
it "creates by lowercase plural string" do
|
13
|
-
factory.create("songs").should be_an_instance_of(SongSerializer)
|
13
|
+
factory.create("songs").should be_an_instance_of(MyApp::SongSerializer)
|
14
14
|
end
|
15
15
|
it "creates by symbol" do
|
16
|
-
factory.create(:song).should be_an_instance_of(SongSerializer)
|
16
|
+
factory.create(:song).should be_an_instance_of(MyApp::SongSerializer)
|
17
17
|
end
|
18
18
|
it "creates by class" do
|
19
|
-
factory.create(Song).should be_an_instance_of(SongSerializer)
|
19
|
+
factory.create(MyApp::Song).should be_an_instance_of(MyApp::SongSerializer)
|
20
20
|
end
|
21
21
|
|
22
22
|
it "creates multiple with Array" do
|
23
23
|
serializers = factory.create("Song", "artists", :album)
|
24
|
-
serializers[0].should be_an_instance_of(SongSerializer)
|
25
|
-
serializers[1].should be_an_instance_of(ArtistSerializer)
|
26
|
-
serializers[2].should be_an_instance_of(AlbumSerializer)
|
24
|
+
serializers[0].should be_an_instance_of(MyApp::SongSerializer)
|
25
|
+
serializers[1].should be_an_instance_of(MyApp::ArtistSerializer)
|
26
|
+
serializers[2].should be_an_instance_of(MyApp::AlbumSerializer)
|
27
27
|
end
|
28
28
|
end
|
data/spec/fixtures/db.rb
CHANGED
@@ -39,31 +39,33 @@ ActiveRecord::Schema.define(:version => 1) do
|
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
42
|
-
|
43
|
-
|
42
|
+
module MyApp
|
43
|
+
class Artist < ActiveRecord::Base
|
44
|
+
attr_accessible :name, :website
|
44
45
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
end
|
46
|
+
has_many :albums
|
47
|
+
has_many :songs
|
48
|
+
has_many :payments
|
49
|
+
end
|
49
50
|
|
50
|
-
class Album < ActiveRecord::Base
|
51
|
-
|
52
|
-
|
51
|
+
class Album < ActiveRecord::Base
|
52
|
+
attr_accessible :title, :year, :artist
|
53
|
+
scope :classic, where("year < 1950")
|
53
54
|
|
54
|
-
|
55
|
-
|
56
|
-
end
|
55
|
+
belongs_to :artist
|
56
|
+
has_many :songs
|
57
|
+
end
|
57
58
|
|
58
|
-
class Song < ActiveRecord::Base
|
59
|
-
|
59
|
+
class Song < ActiveRecord::Base
|
60
|
+
attr_accessible :title, :artist, :album
|
60
61
|
|
61
|
-
|
62
|
-
|
63
|
-
end
|
62
|
+
belongs_to :artist
|
63
|
+
belongs_to :album
|
64
|
+
end
|
64
65
|
|
65
|
-
class Payment < ActiveRecord::Base
|
66
|
-
|
66
|
+
class Payment < ActiveRecord::Base
|
67
|
+
attr_accessible :amount, :artist
|
67
68
|
|
68
|
-
|
69
|
+
belongs_to :artist
|
70
|
+
end
|
69
71
|
end
|
@@ -1,17 +1,19 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
module MyApp
|
2
|
+
class SongSerializer
|
3
|
+
include RestPack::Serializer
|
4
|
+
attributes :id, :title, :album_id
|
5
|
+
can_include :albums, :artists
|
6
|
+
end
|
6
7
|
|
7
|
-
class AlbumSerializer
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
end
|
8
|
+
class AlbumSerializer
|
9
|
+
include RestPack::Serializer
|
10
|
+
attributes :id, :title, :year, :artist_id
|
11
|
+
can_include :artists, :songs
|
12
|
+
end
|
12
13
|
|
13
|
-
class ArtistSerializer
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
class ArtistSerializer
|
15
|
+
include RestPack::Serializer
|
16
|
+
attributes :id, :name, :website
|
17
|
+
can_include :albums, :songs
|
18
|
+
end
|
17
19
|
end
|
@@ -1,17 +1,17 @@
|
|
1
1
|
require './spec/spec_helper'
|
2
2
|
|
3
3
|
describe RestPack::Serializer::Options do
|
4
|
-
let(:subject) { RestPack::Serializer::Options.new(SongSerializer, params, scope) }
|
4
|
+
let(:subject) { RestPack::Serializer::Options.new(MyApp::SongSerializer, params, scope) }
|
5
5
|
let(:params) { {} }
|
6
6
|
let(:scope) { nil }
|
7
7
|
|
8
8
|
describe 'default values' do
|
9
|
-
it { subject.model_class.should == Song }
|
9
|
+
it { subject.model_class.should == MyApp::Song }
|
10
10
|
it { subject.includes.should == [] }
|
11
11
|
it { subject.page.should == 1 }
|
12
12
|
it { subject.page_size.should == 10 }
|
13
13
|
it { subject.filters.should == {} }
|
14
|
-
it { subject.scope.should == Song.all }
|
14
|
+
it { subject.scope.should == MyApp::Song.all }
|
15
15
|
it { subject.default_page_size?.should == true }
|
16
16
|
it { subject.filters_as_url_params.should == '' }
|
17
17
|
end
|
@@ -61,11 +61,11 @@ describe RestPack::Serializer::Options do
|
|
61
61
|
|
62
62
|
context 'scopes' do
|
63
63
|
describe 'with default scope' do
|
64
|
-
it { subject.scope.should == Song.all }
|
64
|
+
it { subject.scope.should == MyApp::Song.all }
|
65
65
|
end
|
66
66
|
|
67
67
|
describe 'with custom scope' do
|
68
|
-
let(:scope) { Song.where("id >= 100") }
|
68
|
+
let(:scope) { MyApp::Song.where("id >= 100") }
|
69
69
|
it { subject.scope.should == scope }
|
70
70
|
end
|
71
71
|
end
|
@@ -7,7 +7,7 @@ describe RestPack::Serializer::Paging do
|
|
7
7
|
end
|
8
8
|
|
9
9
|
context "#page" do
|
10
|
-
let(:page) { SongSerializer.page(params) }
|
10
|
+
let(:page) { MyApp::SongSerializer.page(params) }
|
11
11
|
let(:params) { { } }
|
12
12
|
|
13
13
|
context "with defaults" do
|
@@ -46,7 +46,7 @@ describe RestPack::Serializer::Paging do
|
|
46
46
|
end
|
47
47
|
|
48
48
|
it "serializes results" do
|
49
|
-
first = Song.first
|
49
|
+
first = MyApp::Song.first
|
50
50
|
page[:songs].first.should == {
|
51
51
|
id: first.id.to_s,
|
52
52
|
title: first.title,
|
@@ -145,8 +145,8 @@ describe RestPack::Serializer::Paging do
|
|
145
145
|
FactoryGirl.create(:album, year: 1930)
|
146
146
|
FactoryGirl.create(:album, year: 1948)
|
147
147
|
end
|
148
|
-
let(:page) { AlbumSerializer.page(params, scope) }
|
149
|
-
let(:scope) { Album.classic }
|
148
|
+
let(:page) { MyApp::AlbumSerializer.page(params, scope) }
|
149
|
+
let(:scope) { MyApp::Album.classic }
|
150
150
|
|
151
151
|
it "returns a page of scoped data" do
|
152
152
|
page[:meta][:albums][:count].should == 2
|
@@ -155,9 +155,9 @@ describe RestPack::Serializer::Paging do
|
|
155
155
|
end
|
156
156
|
|
157
157
|
context "#page_with_options" do
|
158
|
-
let(:page) { SongSerializer.page_with_options(options) }
|
158
|
+
let(:page) { MyApp::SongSerializer.page_with_options(options) }
|
159
159
|
let(:params) { {} }
|
160
|
-
let(:options) { RestPack::Serializer::Options.new(SongSerializer, params) }
|
160
|
+
let(:options) { RestPack::Serializer::Options.new(MyApp::SongSerializer, params) }
|
161
161
|
|
162
162
|
context "with defaults" do
|
163
163
|
it "includes valid paging meta data" do
|
@@ -178,8 +178,8 @@ describe RestPack::Serializer::Paging do
|
|
178
178
|
end
|
179
179
|
|
180
180
|
context "paging with paged side-load" do
|
181
|
-
let(:page) { AlbumSerializer.page_with_options(options) }
|
182
|
-
let(:options) { RestPack::Serializer::Options.new(AlbumSerializer, { includes: 'songs' }) }
|
181
|
+
let(:page) { MyApp::AlbumSerializer.page_with_options(options) }
|
182
|
+
let(:options) { RestPack::Serializer::Options.new(MyApp::AlbumSerializer, { includes: 'songs' }) }
|
183
183
|
|
184
184
|
it "includes side-loaded paging data in meta data" do
|
185
185
|
page[:meta][:albums].should_not == nil
|
@@ -190,8 +190,8 @@ describe RestPack::Serializer::Paging do
|
|
190
190
|
end
|
191
191
|
|
192
192
|
context "paging with two paged side-loads" do
|
193
|
-
let(:page) { ArtistSerializer.page_with_options(options) }
|
194
|
-
let(:options) { RestPack::Serializer::Options.new(ArtistSerializer, { includes: 'albums,songs' }) }
|
193
|
+
let(:page) { MyApp::ArtistSerializer.page_with_options(options) }
|
194
|
+
let(:options) { RestPack::Serializer::Options.new(MyApp::ArtistSerializer, { includes: 'albums,songs' }) }
|
195
195
|
|
196
196
|
it "includes side-loaded paging data in meta data" do
|
197
197
|
page[:meta][:albums].should_not == nil
|
@@ -6,7 +6,7 @@ describe RestPack::Serializer::Resource do
|
|
6
6
|
@song = @album.songs.first
|
7
7
|
end
|
8
8
|
|
9
|
-
let(:resource) { SongSerializer.resource(params) }
|
9
|
+
let(:resource) { MyApp::SongSerializer.resource(params) }
|
10
10
|
let(:params) { { id: @song.id.to_s } }
|
11
11
|
|
12
12
|
it "returns a resource by id" do
|
@@ -40,7 +40,7 @@ describe RestPack::Serializer::Resource do
|
|
40
40
|
|
41
41
|
describe "song with no artist" do
|
42
42
|
let(:song) { FactoryGirl.create(:song, :artist => nil) }
|
43
|
-
let(:resource) { SongSerializer.resource(id: song.id.to_s) }
|
43
|
+
let(:resource) { MyApp::SongSerializer.resource(id: song.id.to_s) }
|
44
44
|
|
45
45
|
it "should not have an artist link" do
|
46
46
|
resource[:songs][0][:links].keys.should_not include(:artist)
|
@@ -78,7 +78,7 @@ describe RestPack::Serializer do
|
|
78
78
|
end
|
79
79
|
|
80
80
|
context "links" do
|
81
|
-
let(:serializer) { SongSerializer.new }
|
81
|
+
let(:serializer) { MyApp::SongSerializer.new }
|
82
82
|
it "includes 'links' data" do
|
83
83
|
@album1 = FactoryGirl.create(:album_with_songs, song_count: 11)
|
84
84
|
json = serializer.as_json(@album1.songs.first)
|
@@ -8,13 +8,13 @@ describe RestPack::Serializer::SideLoading do
|
|
8
8
|
FactoryGirl.create(:artist_with_albums, album_count: 2)
|
9
9
|
FactoryGirl.create(:artist_with_albums, album_count: 1)
|
10
10
|
end
|
11
|
-
let(:side_loads) { SongSerializer.side_loads(models, options) }
|
11
|
+
let(:side_loads) { MyApp::SongSerializer.side_loads(models, options) }
|
12
12
|
|
13
13
|
context "with no models" do
|
14
14
|
let(:models) { [] }
|
15
15
|
|
16
16
|
context "no side-loads" do
|
17
|
-
let(:options) { RestPack::Serializer::Options.new(SongSerializer) }
|
17
|
+
let(:options) { RestPack::Serializer::Options.new(MyApp::SongSerializer) }
|
18
18
|
|
19
19
|
it "returns a hash with no data" do
|
20
20
|
side_loads.should == { :meta => {} }
|
@@ -22,7 +22,7 @@ describe RestPack::Serializer::SideLoading do
|
|
22
22
|
end
|
23
23
|
|
24
24
|
context "when including :albums" do
|
25
|
-
let(:options) { RestPack::Serializer::Options.new(SongSerializer, { "includes" => "albums" }) }
|
25
|
+
let(:options) { RestPack::Serializer::Options.new(MyApp::SongSerializer, { "includes" => "albums" }) }
|
26
26
|
|
27
27
|
it "returns a hash with no data" do
|
28
28
|
side_loads.should == { :meta => {} }
|
@@ -31,14 +31,14 @@ describe RestPack::Serializer::SideLoading do
|
|
31
31
|
end
|
32
32
|
|
33
33
|
context "with a single model" do
|
34
|
-
let(:models) { [Song.first] }
|
34
|
+
let(:models) { [MyApp::Song.first] }
|
35
35
|
|
36
36
|
context "when including :albums" do
|
37
|
-
let(:options) { RestPack::Serializer::Options.new(SongSerializer, { "includes" => "albums" }) }
|
37
|
+
let(:options) { RestPack::Serializer::Options.new(MyApp::SongSerializer, { "includes" => "albums" }) }
|
38
38
|
|
39
39
|
it "returns side-loaded albums" do
|
40
40
|
side_loads.should == {
|
41
|
-
albums: [AlbumSerializer.as_json(Song.first.album)],
|
41
|
+
albums: [MyApp::AlbumSerializer.as_json(MyApp::Song.first.album)],
|
42
42
|
meta: { }
|
43
43
|
}
|
44
44
|
end
|
@@ -46,20 +46,20 @@ describe RestPack::Serializer::SideLoading do
|
|
46
46
|
end
|
47
47
|
|
48
48
|
context "with multiple models" do
|
49
|
-
let(:artist1) { Artist.find(1) }
|
50
|
-
let(:artist2) { Artist.find(2) }
|
49
|
+
let(:artist1) { MyApp::Artist.find(1) }
|
50
|
+
let(:artist2) { MyApp::Artist.find(2) }
|
51
51
|
let(:song1) { artist1.songs.first }
|
52
52
|
let(:song2) { artist2.songs.first }
|
53
53
|
let(:models) { [song1, song2] }
|
54
54
|
|
55
55
|
context "when including :albums" do
|
56
|
-
let(:options) { RestPack::Serializer::Options.new(SongSerializer, { "includes" => "albums" }) }
|
56
|
+
let(:options) { RestPack::Serializer::Options.new(MyApp::SongSerializer, { "includes" => "albums" }) }
|
57
57
|
|
58
58
|
it "returns side-loaded albums" do
|
59
59
|
side_loads.should == {
|
60
60
|
albums: [
|
61
|
-
AlbumSerializer.as_json(song1.album),
|
62
|
-
AlbumSerializer.as_json(song2.album)
|
61
|
+
MyApp::AlbumSerializer.as_json(song1.album),
|
62
|
+
MyApp::AlbumSerializer.as_json(song2.album)
|
63
63
|
],
|
64
64
|
:meta => { }
|
65
65
|
}
|
@@ -8,13 +8,13 @@ describe RestPack::Serializer::SideLoading do
|
|
8
8
|
@artist1 = FactoryGirl.create(:artist_with_albums, album_count: 2)
|
9
9
|
@artist2 = FactoryGirl.create(:artist_with_albums, album_count: 1)
|
10
10
|
end
|
11
|
-
let(:side_loads) { ArtistSerializer.side_loads(models, options) }
|
11
|
+
let(:side_loads) { MyApp::ArtistSerializer.side_loads(models, options) }
|
12
12
|
|
13
13
|
context "with a single model" do
|
14
14
|
let(:models) { [@artist1] }
|
15
15
|
|
16
16
|
context "when including :albums" do
|
17
|
-
let(:options) { RestPack::Serializer::Options.new(ArtistSerializer, { "includes" => "albums" }) }
|
17
|
+
let(:options) { RestPack::Serializer::Options.new(MyApp::ArtistSerializer, { "includes" => "albums" }) }
|
18
18
|
|
19
19
|
it "returns side-loaded albums" do
|
20
20
|
side_loads[:albums].count.should == @artist1.albums.count
|
@@ -28,7 +28,7 @@ describe RestPack::Serializer::SideLoading do
|
|
28
28
|
let(:models) { [@artist1, @artist2] }
|
29
29
|
|
30
30
|
context "when including :albums" do
|
31
|
-
let(:options) { RestPack::Serializer::Options.new(ArtistSerializer, { "includes" => "albums" }) }
|
31
|
+
let(:options) { RestPack::Serializer::Options.new(MyApp::ArtistSerializer, { "includes" => "albums" }) }
|
32
32
|
|
33
33
|
it "returns side-loaded albums" do
|
34
34
|
expected_count = @artist1.albums.count + @artist2.albums.count
|
@@ -9,10 +9,10 @@ describe RestPack::Serializer::SideLoading do
|
|
9
9
|
context "an include to an inexistent model" do
|
10
10
|
it "raises an exception" do
|
11
11
|
exception = RestPack::Serializer::InvalidInclude
|
12
|
-
message = ":wrong is not a valid include for Song"
|
12
|
+
message = ":wrong is not a valid include for MyApp::Song"
|
13
13
|
|
14
14
|
expect do
|
15
|
-
SongSerializer.side_loads([Song.first], RestPack::Serializer::Options.new(SongSerializer, { "includes" => "wrong" }))
|
15
|
+
MyApp::SongSerializer.side_loads([MyApp::Song.first], RestPack::Serializer::Options.new(MyApp::SongSerializer, { "includes" => "wrong" }))
|
16
16
|
end.to raise_error(exception, message)
|
17
17
|
end
|
18
18
|
end
|
@@ -21,10 +21,10 @@ describe RestPack::Serializer::SideLoading do
|
|
21
21
|
it "raises an exception" do
|
22
22
|
payment = FactoryGirl.create(:payment)
|
23
23
|
exception = RestPack::Serializer::InvalidInclude
|
24
|
-
message = ":payments is not a valid include for Artist"
|
24
|
+
message = ":payments is not a valid include for MyApp::Artist"
|
25
25
|
|
26
26
|
expect do
|
27
|
-
ArtistSerializer.side_loads([payment.artist], RestPack::Serializer::Options.new(ArtistSerializer, { "includes" => "payments" }))
|
27
|
+
MyApp::ArtistSerializer.side_loads([payment.artist], RestPack::Serializer::Options.new(MyApp::ArtistSerializer, { "includes" => "payments" }))
|
28
28
|
end.to raise_error(exception, message)
|
29
29
|
end
|
30
30
|
end
|
@@ -50,7 +50,7 @@ describe RestPack::Serializer::SideLoading do
|
|
50
50
|
end
|
51
51
|
|
52
52
|
describe "#links" do
|
53
|
-
AlbumSerializer.links.should == {
|
53
|
+
MyApp::AlbumSerializer.links.should == {
|
54
54
|
"albums.artist" => {
|
55
55
|
:href => "/artists/{albums.artist}.json",
|
56
56
|
:type => :artists
|
@@ -64,7 +64,7 @@ describe RestPack::Serializer::SideLoading do
|
|
64
64
|
it "applies custom RestPack::Serializer.config.href_prefix" do
|
65
65
|
original = RestPack::Serializer.config.href_prefix
|
66
66
|
RestPack::Serializer.config.href_prefix = "/api/v1"
|
67
|
-
AlbumSerializer.links["albums.artist"][:href].should == "/api/v1/artists/{albums.artist}.json"
|
67
|
+
MyApp::AlbumSerializer.links["albums.artist"][:href].should == "/api/v1/artists/{albums.artist}.json"
|
68
68
|
RestPack::Serializer.config.href_prefix = original
|
69
69
|
end
|
70
70
|
end
|
@@ -72,17 +72,17 @@ describe RestPack::Serializer::SideLoading do
|
|
72
72
|
describe "#filterable_by" do
|
73
73
|
context "a model with no :belongs_to relations" do
|
74
74
|
it "is filterable by :id only" do
|
75
|
-
ArtistSerializer.filterable_by.should == [:id]
|
75
|
+
MyApp::ArtistSerializer.filterable_by.should == [:id]
|
76
76
|
end
|
77
77
|
end
|
78
78
|
context "a model with a single :belongs_torelations" do
|
79
79
|
it "is filterable by primary key and foreign keys" do
|
80
|
-
AlbumSerializer.filterable_by.should =~ [:id, :artist_id]
|
80
|
+
MyApp::AlbumSerializer.filterable_by.should =~ [:id, :artist_id]
|
81
81
|
end
|
82
82
|
end
|
83
83
|
context "a model with multiple :belongs_to relations" do
|
84
84
|
it "is filterable by primary key and foreign keys" do
|
85
|
-
SongSerializer.filterable_by.should =~ [:id, :artist_id, :album_id]
|
85
|
+
MyApp::SongSerializer.filterable_by.should =~ [:id, :artist_id, :album_id]
|
86
86
|
end
|
87
87
|
end
|
88
88
|
end
|
data/spec/support/factory.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'factory_girl'
|
2
2
|
|
3
3
|
FactoryGirl.define do
|
4
|
-
factory :artist do
|
4
|
+
factory :artist, :class => MyApp::Artist do
|
5
5
|
sequence(:name) {|n| "Artist ##{n}" }
|
6
6
|
sequence(:website) {|n| "http://website#{n}.com/" }
|
7
7
|
|
@@ -16,7 +16,7 @@ FactoryGirl.define do
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
-
factory :album do
|
19
|
+
factory :album, :class => MyApp::Album do
|
20
20
|
sequence(:title) {|n| "Album ##{n}" }
|
21
21
|
sequence(:year) {|n| 1960 + n }
|
22
22
|
artist
|
@@ -32,14 +32,14 @@ FactoryGirl.define do
|
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
-
factory :song do
|
35
|
+
factory :song, :class => MyApp::Song do
|
36
36
|
sequence(:title) {|n| "Song ##{n}" }
|
37
37
|
artist
|
38
38
|
album
|
39
39
|
end
|
40
40
|
|
41
|
-
factory :payment do
|
41
|
+
factory :payment, :class => MyApp::Payment do
|
42
42
|
amount 999
|
43
43
|
artist
|
44
44
|
end
|
45
|
-
end
|
45
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: restpack_serializer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gavin Joyce
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-09-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -265,7 +265,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
265
265
|
version: '0'
|
266
266
|
requirements: []
|
267
267
|
rubyforge_project:
|
268
|
-
rubygems_version: 2.0.
|
268
|
+
rubygems_version: 2.0.7
|
269
269
|
signing_key:
|
270
270
|
specification_version: 4
|
271
271
|
summary: Model serialization, paging, side-loading and filtering
|