conglomerate 0.11.0 → 0.11.1

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: 299095559c8ba18987524ef7e2702c2f2ad341b6
4
- data.tar.gz: 65a914ac9c9c2a31086c39d1577685347339b568
3
+ metadata.gz: 62beba0ffa576fd7850b3956e291803ab65df121
4
+ data.tar.gz: e23e631bacf3d357ad45e3e883a9418560a273ae
5
5
  SHA512:
6
- metadata.gz: 2374f028927ee394aabeb148a0513c9dd2b1a59e9cd3c68a926c98c9bd1b12391ad13d19c39eccabdc7cf9e56dd446c9c0f1a31dbe2451bd2d430a348f0efa1d
7
- data.tar.gz: 9a7c73782ab8de2f30131cc60f5449941159b3168b5c228e1af4810f12a49372cd18265e7a3170712c592bd0b288f6324bb0eb45c8fb3d76cdb180f482c57a18
6
+ metadata.gz: fbd8143ba303ec112d94cdd5a108f9a066b6d869677e1516bea0ba308a43f82c6b68398252163c61bc34091a25526974f1b0dec833e38067872cbb67a32059e4
7
+ data.tar.gz: 0fe8a51f3556c1c865825c3f575a2a0506e991b66d6fd3de889b60181469a08c5775a0472471e971a8a9cda9e4a2f42a9ae88702ab874e80e106a89f9f028018
data/README.md CHANGED
@@ -1,7 +1,8 @@
1
1
  # Conglomerate
2
2
 
3
- [![Gem Version](https://badge.fury.io/rb/conglomerate.png)](http://badge.fury.io/rb/conglomerate)
4
3
  [ ![Codeship Status for teamsnap/conglomerate](https://www.codeship.io/projects/7210a3f0-de00-0131-af05-5236ebb52643/status)](https://www.codeship.io/projects/24758)
4
+
5
+ [![Gem Version](https://badge.fury.io/rb/conglomerate.png)](http://badge.fury.io/rb/conglomerate)
5
6
  [![Code Climate](https://codeclimate.com/github/teamsnap/conglomerate.png)](https://codeclimate.com/github/teamsnap/conglomerate)
6
7
  [![Coverage Status](https://coveralls.io/repos/teamsnap/conglomerate/badge.png?branch=master)](https://coveralls.io/r/teamsnap/conglomerate?branch=master)
7
8
  [![Dependency Status](https://gemnasium.com/teamsnap/conglomerate.png)](https://gemnasium.com/teamsnap/conglomerate)
@@ -35,28 +36,30 @@ Or install it yourself as:
35
36
  ```ruby
36
37
  # Step 1: Create a serializer
37
38
  class TeamSerializer
38
- include Conglomerate::RootBuilder
39
+ include Conglomerate::RootBuilder.serializer
39
40
 
40
- href { teams_url }
41
+ collection do
42
+ href { teams_url }
41
43
 
42
- item "Team" do |item|
43
- href { team_url(item.id) }
44
+ item "Team" do |item|
45
+ href { team_url(item.id) }
44
46
 
45
- datum :id
46
- datum :name
47
- datum :event_ids
47
+ datum :id
48
+ datum :name
49
+ datum :event_ids
48
50
 
49
- link :events, :href => Proc.new { event_url(item.event_ids.join(",")) }
50
- end
51
+ link :events, :href => Proc.new { event_url(item.event_ids.join(",")) }
52
+ end
51
53
 
52
- link :root, :href => Proc.new { root_url }
54
+ link :root, :href => Proc.new { root_url }
53
55
 
54
- query :search, :href => Proc.new { search_items_url } do
55
- datum :id
56
- end
56
+ query :search, :href => Proc.new { search_items_url } do
57
+ datum :id
58
+ end
57
59
 
58
- template do
59
- datum :name
60
+ template do
61
+ datum :name
62
+ end
60
63
  end
61
64
  end
62
65
 
@@ -193,17 +193,13 @@ module Conglomerate
193
193
  end
194
194
 
195
195
  def sanitize_value(object, name:, type: :value, default_value: nil)
196
- if blank?(object) || blank?(object.send(name))
196
+ if object.nil? || object.send(name).nil?
197
197
  if type == :array
198
198
  []
199
199
  elsif type == :object
200
200
  {}
201
201
  else
202
- if present?(object) && object.send(name) == false
203
- false
204
- else
205
- default_value
206
- end
202
+ default_value
207
203
  end
208
204
  else
209
205
  object.send(name)
@@ -1,3 +1,3 @@
1
1
  module Conglomerate
2
- VERSION = "0.11.0"
2
+ VERSION = "0.11.1"
3
3
  end
@@ -58,7 +58,7 @@ class ConglomerateNullParticleSerializer
58
58
  end
59
59
 
60
60
  describe Conglomerate do
61
- let(:object) do
61
+ let(:object1) do
62
62
  double(
63
63
  "Object",
64
64
  :id => 1,
@@ -74,6 +74,22 @@ describe Conglomerate do
74
74
  )
75
75
  end
76
76
 
77
+ let(:object2) do
78
+ double(
79
+ "Object",
80
+ :id => 2,
81
+ :description => "Tasty Pizza",
82
+ :event_date_time => DateTime.parse("1982-01-22T10:00:00+00:00"),
83
+ :event_date => Date.parse("1981-01-22"),
84
+ :event_time => Time.parse("1981-01-22T10:00:00+00:00"),
85
+ :event_id => 3,
86
+ :roster_id => nil,
87
+ :team_ids => [3,4],
88
+ :user_ids => [],
89
+ :is_available => true
90
+ )
91
+ end
92
+
77
93
  let(:context) do
78
94
  request = double("Request", :original_url => "https://example.com/items")
79
95
  double(
@@ -85,32 +101,48 @@ describe Conglomerate do
85
101
  allow(context).to receive(:item_url).with(1) {
86
102
  "https://example.com/items/1"
87
103
  }
104
+ allow(context).to receive(:item_url).with(2) {
105
+ "https://example.com/items/2"
106
+ }
88
107
  allow(context).to receive(:event_url).with(2) {
89
108
  "https://example.com/events/2"
90
109
  }
110
+ allow(context).to receive(:event_url).with(3) {
111
+ "https://example.com/events/3"
112
+ }
91
113
  allow(context).to receive(:events_url) {
92
114
  "https://example.com/events"
93
115
  }
94
116
  allow(context).to receive(:team_url).with("1,2") {
95
117
  "https://example.com/teams/1,2"
96
118
  }
119
+ allow(context).to receive(:team_url).with("3,4") {
120
+ "https://example.com/teams/3,4"
121
+ }
97
122
  allow(context).to receive(:test_url) { "abc" }
98
123
  allow(context).to receive(:users_search_url).with(:object_id => 1) {
99
124
  "def"
100
125
  }
126
+ allow(context).to receive(:users_search_url).with(:object_id => 2) {
127
+ "ghi"
128
+ }
101
129
  end
102
130
  end
103
131
 
104
132
  let(:test_serializer) do
105
- ConglomerateTestParticleSerializer.new(object, :context => context).serialize
133
+ ConglomerateTestParticleSerializer.new(object1, :context => context).serialize
106
134
  end
107
135
 
108
136
  let(:extra_test_serializer) do
109
- ConglomerateExtraTestParticleSerializer.new(object, :context => context).serialize
137
+ ConglomerateExtraTestParticleSerializer.new(object1, :context => context).serialize
110
138
  end
111
139
 
112
140
  let(:null_serializer) do
113
- ConglomerateNullParticleSerializer.new(object, :context => context).serialize
141
+ ConglomerateNullParticleSerializer.new(object1, :context => context).serialize
142
+ end
143
+
144
+ let(:multi_test_serializer) do
145
+ ConglomerateTestParticleSerializer.new([object1, object2], :context => context).serialize
114
146
  end
115
147
 
116
148
  let(:test_collection) { test_serializer["collection"] }
@@ -119,6 +151,8 @@ describe Conglomerate do
119
151
 
120
152
  let(:null_collection) { null_serializer["collection"] }
121
153
 
154
+ let(:multi_test_collection) { multi_test_serializer["collection"] }
155
+
122
156
  describe "#version" do
123
157
  it "sets version to 1.0" do
124
158
  expect(null_collection["version"]).to eq("1.0")
@@ -164,8 +198,8 @@ describe Conglomerate do
164
198
 
165
199
  it "doesn't have an items array if items is empty" do
166
200
  test_serializer = ConglomerateTestParticleSerializer
167
- .new(nil, :context => context)
168
- .serialize
201
+ .new(nil, :context => context)
202
+ .serialize
169
203
  test_collection = test_serializer["collection"]
170
204
  expect(test_collection.keys).to_not include("items")
171
205
  end
@@ -207,6 +241,51 @@ describe Conglomerate do
207
241
  ]
208
242
  )
209
243
  end
244
+
245
+ it "correctly handles multiple items" do
246
+ expect(multi_test_collection["items"]).to eq(
247
+ [
248
+ {
249
+ "href" => "https://example.com/items/1",
250
+ "data" => [
251
+ {"name" => "description", "value" => "Tasty Burgers", "prompt" => "awesome"},
252
+ {"name" => "id", "value" => 1},
253
+ {"name" => "event_id", "value" => 2},
254
+ {"name" => "roster_id", "value" => nil},
255
+ {"name" => "team_ids", "value" => [1,2]},
256
+ {"name" => "event_date_time", "value" => "1981-11-28T10:00:00Z"},
257
+ {"name" => "event_date", "value" => "1981-11-28"},
258
+ {"name" => "event_time", "value" => "1981-11-28T10:00:00Z"},
259
+ {"name" => "is_available", "value" => false}
260
+ ],
261
+ "links" => [
262
+ {"href" => "https://example.com/events/2", "rel" => "event"},
263
+ {"href" => "https://example.com/teams/1,2", "rel" => "teams"},
264
+ {"href" => "def", "rel" => "users"}
265
+ ]
266
+ },
267
+ {
268
+ "href" => "https://example.com/items/2",
269
+ "data" => [
270
+ {"name" => "description", "value" => "Tasty Pizza", "prompt" => "awesome"},
271
+ {"name" => "id", "value" => 2},
272
+ {"name" => "event_id", "value" => 3},
273
+ {"name" => "roster_id", "value" => nil},
274
+ {"name" => "team_ids", "value" => [3,4]},
275
+ {"name" => "event_date_time", "value" => "1981-01-22T10:00:00Z"},
276
+ {"name" => "event_date", "value" => "1981-01-22"},
277
+ {"name" => "event_time", "value" => "1981-01-22T10:00:00Z"},
278
+ {"name" => "is_available", "value" => true}
279
+ ],
280
+ "links" => [
281
+ {"href" => "https://example.com/events/3", "rel" => "event"},
282
+ {"href" => "https://example.com/teams/3,4", "rel" => "teams"},
283
+ {"href" => "ghi", "rel" => "users"}
284
+ ]
285
+ }
286
+ ]
287
+ )
288
+ end
210
289
  end
211
290
 
212
291
  context "template" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: conglomerate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.0
4
+ version: 0.11.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shane Emmons
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-06-28 00:00:00.000000000 Z
12
+ date: 2014-07-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler