restpack_serializer 0.5.4 → 0.5.5
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/.ruby-version +1 -0
- data/lib/restpack_serializer/serializable.rb +5 -1
- data/lib/restpack_serializer/version.rb +1 -1
- data/spec/serializable/serializer_spec.rb +12 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1ab97075ec26119008cee6b11195794a748b17af
|
4
|
+
data.tar.gz: 155498c6a186c00f7fe37b4a8a2af3a02556a888
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2e1eee7a4d17308778a0a76a3efa839ec9c0add561e7eb1817ae2709653cbfd5c407cc9cb50538abb1e37410099b3dbe8e1e8d6e9794cb6ff4a92dc88614c0e4
|
7
|
+
data.tar.gz: e959700701297dc69ebc1289a80b3c76519a2ca20950bd08c8c5609300e4a710da6ba1741f28c07fc3c997c50e5070246f7dc6bf7a94cb3dbc32de59d67ed2a7
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.0.0-p353
|
@@ -71,7 +71,11 @@ module RestPack
|
|
71
71
|
when association.macro == :belongs_to
|
72
72
|
model.send(association.foreign_key).try(:to_s)
|
73
73
|
when association.macro.to_s.match(/has_/)
|
74
|
-
model.send(association.name).
|
74
|
+
if model.send(association.name).loaded?
|
75
|
+
model.send(association.name).collect { |associated| associated.id.to_s }
|
76
|
+
else
|
77
|
+
model.send(association.name).pluck(:id).map(&:to_s)
|
78
|
+
end
|
75
79
|
end
|
76
80
|
unless links_value.blank?
|
77
81
|
data[:links][association.name.to_sym] = links_value
|
@@ -153,12 +153,23 @@ describe RestPack::Serializer do
|
|
153
153
|
end
|
154
154
|
|
155
155
|
context "with a serializer with has_* associations" do
|
156
|
+
let(:artist_factory) { FactoryGirl.create :artist_with_fans }
|
156
157
|
let(:artist_serializer) { MyApp::ArtistSerializer.new }
|
157
158
|
let(:json) { artist_serializer.as_json(artist_factory) }
|
158
159
|
let(:side_load_ids) { artist_has_association.map {|obj| obj.id.to_s } }
|
159
160
|
|
161
|
+
context "when the association has been eager loaded" do
|
162
|
+
before do
|
163
|
+
artist_factory.fans.stub(:loaded?) { true }
|
164
|
+
end
|
165
|
+
it "does not make a query to retrieve id values" do
|
166
|
+
expect(artist_factory.fans).not_to receive(:pluck)
|
167
|
+
json
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
|
160
172
|
describe "'has_many, through' associations" do
|
161
|
-
let(:artist_factory) { FactoryGirl.create :artist_with_fans }
|
162
173
|
let(:artist_has_association) { artist_factory.fans }
|
163
174
|
|
164
175
|
it "includes 'links' data when there are associated records" do
|
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.5.
|
4
|
+
version: 0.5.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gavin Joyce
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-10-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -213,6 +213,7 @@ extra_rdoc_files: []
|
|
213
213
|
files:
|
214
214
|
- ".gitignore"
|
215
215
|
- ".rspec"
|
216
|
+
- ".ruby-version"
|
216
217
|
- ".travis.yml"
|
217
218
|
- Gemfile
|
218
219
|
- Guardfile
|
@@ -274,7 +275,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
274
275
|
version: '0'
|
275
276
|
requirements: []
|
276
277
|
rubyforge_project:
|
277
|
-
rubygems_version: 2.
|
278
|
+
rubygems_version: 2.0.14
|
278
279
|
signing_key:
|
279
280
|
specification_version: 4
|
280
281
|
summary: Model serialization, paging, side-loading and filtering
|