rest_resource 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -10,7 +10,7 @@ The gem provides a basic CRUD operation to the resources. It is basically rest-c
10
10
  The goal of this gem is to provide a minimum CRUD client interface for the RESTful web services. It doesn't make the API to be ActiveRecord like. Rather, it lets the users have the full control on the resources, especially on the error handling.
11
11
 
12
12
  ## USAGE
13
- Given you need to fetch user from a web service. You can write:
13
+ Given that you need to fetch user from a web service. You can write:
14
14
 
15
15
  class User < RestResource::Resource
16
16
  class << self
@@ -19,7 +19,7 @@ Given you need to fetch user from a web service. You can write:
19
19
  end
20
20
 
21
21
  def resource_name
22
- "resources"
22
+ "users"
23
23
  end
24
24
  end
25
25
  end
@@ -30,7 +30,7 @@ To use it, you can just do:
30
30
 
31
31
  user = User.create :name => "Leslie Cheung", :login => "singer"
32
32
 
33
- Both operation assume your web service controller returns a json string which can be initialized into an object.
33
+ Both operations assume your web service controller returns a json string which can be initialized into an object.
34
34
 
35
35
  ##Contributors
36
36
  * Yi Wen
@@ -24,7 +24,7 @@ module RestResource
24
24
  end
25
25
 
26
26
  def initialize(params={})
27
- params_hash = ActiveSupport::JSON.decode params
27
+ params_hash = (params.is_a?(String)) ? ActiveSupport::JSON.decode(params) : params
28
28
  @attributes = params_hash
29
29
  (class << self; self; end).class_eval do
30
30
  params_hash.each_pair do |method_name, value|
@@ -1,3 +1,3 @@
1
1
  module RestResource
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -44,11 +44,23 @@ module RestResource
44
44
  end
45
45
 
46
46
  describe ".new" do
47
- let(:params) { ActiveSupport::JSON.encode( {"attr1" => "val1", "attr2" => "val2"} ) }
48
- let(:resource) {klass.new(params)}
49
- {"attr1" => "val1", "attr2" => "val2"}.each_pair do |attr, val|
50
- it "should generate '#{attr}' method and return '#{val}'" do
51
- resource.send(attr).should == val
47
+ context "when the params is a string" do
48
+ let(:params) { ActiveSupport::JSON.encode( {"attr1" => "val1", "attr2" => "val2"} ) }
49
+ let(:resource) {klass.new(params)}
50
+ {"attr1" => "val1", "attr2" => "val2"}.each_pair do |attr, val|
51
+ it "should generate '#{attr}' method and return '#{val}'" do
52
+ resource.send(attr).should == val
53
+ end
54
+ end
55
+ end
56
+
57
+ context "when the params is a hash" do
58
+ let(:params) { {"attr1" => "val1", "attr2" => "val2"} }
59
+ let(:resource) {klass.new(params)}
60
+ {"attr1" => "val1", "attr2" => "val2"}.each_pair do |attr, val|
61
+ it "should generate '#{attr}' method and return '#{val}'" do
62
+ resource.send(attr).should == val
63
+ end
52
64
  end
53
65
  end
54
66
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rest_resource
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 21
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 4
10
- version: 0.0.4
9
+ - 5
10
+ version: 0.0.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - Yi Wen