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 CHANGED
@@ -5,3 +5,4 @@ pkg/*
5
5
  coverage/*
6
6
  doc/*
7
7
  *~
8
+ pkg/*
data/History.md ADDED
@@ -0,0 +1,15 @@
1
+ Placid History
2
+ ==============
3
+
4
+ 0.0.2
5
+ -----
6
+
7
+ - Fix bug with Model#list so it returns model instances, not Mashes
8
+
9
+
10
+ 0.0.1
11
+ -----
12
+
13
+ - Initial release
14
+ - Basic models and CRUD methods
15
+
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
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "placid"
3
- s.version = "0.0.1"
3
+ s.version = "0.0.2"
4
4
  s.summary = "Models from REST"
5
5
  s.description = <<-EOS
6
6
  EOS
@@ -243,13 +243,17 @@ describe Placid::Model do
243
243
  end
244
244
 
245
245
  describe "#list" do
246
- it "returns a Mash list of all model instances" do
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.should == data
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).should == data
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).should == {'name' => 'Foo'}
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).should == {'uri' => 'foo'}
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).should == {'name' => 'Foo', 'uri' => 'foo'}
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().errors.should == ['name is required']
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).should == {'name' => 'Foo'}
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).should == {'uri' => 'foo'}
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).should == {'name' => 'Foo', 'uri' => 'foo'}
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, {}).errors.should == ['name is required']
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: 29
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
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-17 00:00:00 Z
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