placid 0.0.1 → 0.0.2
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.
- data/.gitignore +1 -0
- data/History.md +15 -0
- data/lib/placid/model.rb +3 -2
- data/placid.gemspec +1 -1
- data/spec/placid_model_spec.rb +33 -11
- metadata +5 -4
data/.gitignore
CHANGED
data/History.md
ADDED
data/lib/placid/model.rb
CHANGED
@@ -99,7 +99,9 @@ module Placid
|
|
99
99
|
# Return a Hashie::Mash with a list of all model instances.
|
100
100
|
#
|
101
101
|
def self.list
|
102
|
-
get_mashes(model.pluralize)
|
102
|
+
return get_mashes(model.pluralize).map do |mash|
|
103
|
+
self.new(mash)
|
104
|
+
end
|
103
105
|
end
|
104
106
|
|
105
107
|
# Return a Model instance matching the given id
|
@@ -141,7 +143,6 @@ module Placid
|
|
141
143
|
obj = self.new(attrs)
|
142
144
|
json = put(model, id, attrs)
|
143
145
|
obj.merge!(json)
|
144
|
-
#obj.errors = json['errors']
|
145
146
|
return obj
|
146
147
|
end
|
147
148
|
|
data/placid.gemspec
CHANGED
data/spec/placid_model_spec.rb
CHANGED
@@ -243,13 +243,17 @@ describe Placid::Model do
|
|
243
243
|
end
|
244
244
|
|
245
245
|
describe "#list" do
|
246
|
-
it "returns a
|
246
|
+
it "returns a list of model instances" do
|
247
247
|
data = [
|
248
248
|
{'name' => 'Foo'},
|
249
249
|
{'name' => 'Bar'},
|
250
250
|
]
|
251
251
|
RestClient.stub(:get => JSON(data))
|
252
|
-
Thing.list
|
252
|
+
things = Thing.list
|
253
|
+
things.should == data
|
254
|
+
things.each do |thing|
|
255
|
+
thing.should be_a(Thing)
|
256
|
+
end
|
253
257
|
end
|
254
258
|
end
|
255
259
|
|
@@ -257,7 +261,9 @@ describe Placid::Model do
|
|
257
261
|
it "returns a Model instance matching the given id" do
|
258
262
|
data = {'name' => 'Foo'}
|
259
263
|
RestClient.stub(:get => JSON(data))
|
260
|
-
Thing.find(1)
|
264
|
+
thing = Thing.find(1)
|
265
|
+
thing.should be_a(Thing)
|
266
|
+
thing.should == data
|
261
267
|
end
|
262
268
|
end
|
263
269
|
|
@@ -266,26 +272,34 @@ describe Placid::Model do
|
|
266
272
|
it "posted attributes if no attributes were returned" do
|
267
273
|
RestClient.stub(:post => '{}')
|
268
274
|
attrs = {'name' => 'Foo'}
|
269
|
-
Thing.create(attrs)
|
275
|
+
thing = Thing.create(attrs)
|
276
|
+
thing.should be_a(Thing)
|
277
|
+
thing.should == {'name' => 'Foo'}
|
270
278
|
end
|
271
279
|
|
272
280
|
it "returned attributes if no attributes were posted" do
|
273
281
|
RestClient.stub(:post => '{"uri": "foo"}')
|
274
282
|
attrs = {}
|
275
|
-
Thing.create(attrs)
|
283
|
+
thing = Thing.create(attrs)
|
284
|
+
thing.should be_a(Thing)
|
285
|
+
thing.should == {'uri' => 'foo'}
|
276
286
|
end
|
277
287
|
|
278
288
|
it "original attributes merged with returned attributes" do
|
279
289
|
RestClient.stub(:post => '{"uri": "foo"}')
|
280
290
|
attrs = {'name' => 'Foo'}
|
281
|
-
Thing.create(attrs)
|
291
|
+
thing = Thing.create(attrs)
|
292
|
+
thing.should be_a(Thing)
|
293
|
+
thing.should == {'name' => 'Foo', 'uri' => 'foo'}
|
282
294
|
end
|
283
295
|
end
|
284
296
|
|
285
297
|
it "sets errors on the Model instance" do
|
286
298
|
data = {'errors' => ['name is required']}
|
287
299
|
RestClient.stub(:post => JSON(data))
|
288
|
-
Thing.create()
|
300
|
+
thing = Thing.create()
|
301
|
+
thing.should be_a(Thing)
|
302
|
+
thing.errors.should == ['name is required']
|
289
303
|
end
|
290
304
|
end
|
291
305
|
|
@@ -295,26 +309,34 @@ describe Placid::Model do
|
|
295
309
|
RestClient.stub(:put => '{}')
|
296
310
|
attrs = {'name' => 'Foo'}
|
297
311
|
result = Thing.update(1, attrs)
|
298
|
-
Thing.update(1, attrs)
|
312
|
+
thing = Thing.update(1, attrs)
|
313
|
+
thing.should be_a(Thing)
|
314
|
+
thing.should == {'name' => 'Foo'}
|
299
315
|
end
|
300
316
|
|
301
317
|
it "returned attributes if no attributes were posted" do
|
302
318
|
RestClient.stub(:put => '{"uri": "foo"}')
|
303
319
|
attrs = {}
|
304
|
-
Thing.update(1, attrs)
|
320
|
+
thing = Thing.update(1, attrs)
|
321
|
+
thing.should be_a(Thing)
|
322
|
+
thing.should == {'uri' => 'foo'}
|
305
323
|
end
|
306
324
|
|
307
325
|
it "original attributes merged with returned attributes" do
|
308
326
|
RestClient.stub(:put => '{"uri": "foo"}')
|
309
327
|
attrs = {'name' => 'Foo'}
|
310
|
-
Thing.update(1, attrs)
|
328
|
+
thing = Thing.update(1, attrs)
|
329
|
+
thing.should be_a(Thing)
|
330
|
+
thing.should == {'name' => 'Foo', 'uri' => 'foo'}
|
311
331
|
end
|
312
332
|
end
|
313
333
|
|
314
334
|
it "sets errors on the Model instance" do
|
315
335
|
data = {'errors' => ['name is required']}
|
316
336
|
RestClient.stub(:put => JSON(data))
|
317
|
-
Thing.update(1, {})
|
337
|
+
thing = Thing.update(1, {})
|
338
|
+
thing.should be_a(Thing)
|
339
|
+
thing.errors.should == ['name is required']
|
318
340
|
end
|
319
341
|
end
|
320
342
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: placid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Eric Pierce
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-05-
|
18
|
+
date: 2012-05-18 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: hashie
|
@@ -141,6 +141,7 @@ files:
|
|
141
141
|
- .gitignore
|
142
142
|
- .yardopts
|
143
143
|
- Gemfile
|
144
|
+
- History.md
|
144
145
|
- MIT-LICENSE
|
145
146
|
- README.md
|
146
147
|
- Rakefile
|