harpy 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -43,11 +43,15 @@ module Harpy
43
43
  end
44
44
  end
45
45
 
46
- def from_id(id)
47
- url = Harpy.entry_point.urn urn(id)
46
+ def from_urn(urn)
47
+ url = Harpy.entry_point.urn urn
48
48
  from_url url if url
49
49
  end
50
50
 
51
+ def from_id(id)
52
+ from_urn urn id
53
+ end
54
+
51
55
  def urn(id)
52
56
  raise NotImplementedError
53
57
  end
data/lib/harpy/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Harpy
2
- VERSION = "0.1.5"
2
+ VERSION = "0.1.6"
3
3
  end
@@ -117,22 +117,54 @@ describe "class including Harpy::Resource" do
117
117
  end
118
118
  end
119
119
  end
120
- describe ".from_id(id)" do
121
- context "when entry point is configured" do
120
+ describe ".from_urn(urn)" do
121
+ context "when entry point is not set" do
122
122
  it "raises Harpy::EntryPointRequired" do
123
123
  lambda{
124
- Harpy::Spec::Company.from_id(1)
124
+ Harpy::Spec::Company.from_urn("urn:harpy:company:1")
125
125
  }.should raise_error Harpy::EntryPointRequired
126
126
  end
127
127
  end
128
- context "when entry point is set but urn has not been overriden" do
128
+ context "when entry point is set" do
129
+ let(:urn) { "urn:harpy:company:1" }
130
+ let(:url) { "http://localhost/company/1" }
131
+ it "asks Harpy.entry_point to convert urn to url then call .from_url" do
132
+ # urn:harpy:company:1 -> http://localhost/company/1
133
+ Harpy.entry_point = mock
134
+ Harpy.entry_point.should_receive(:urn).with(urn).and_return url
135
+
136
+ # http://localhost/company/1 -> Harpy::Spec::Company instance
137
+ Harpy::Spec::Company.should_receive(:from_url).with(url).and_return(expected = mock)
138
+ Harpy::Spec::Company.from_urn(urn).should be expected
139
+ end
140
+ it "is nil if urn is not found" do
141
+ # urn:harpy:company:1 -> nil
142
+ Harpy.entry_point = mock
143
+ Harpy.entry_point.should_receive(:urn).with(urn)
144
+
145
+ Harpy::Spec::Company.from_urn(urn).should be_nil
146
+ end
147
+ end
148
+ end
149
+ describe ".from_id(id)" do
150
+ context "when urn has not been overriden" do
129
151
  it "raises NotImplementedError" do
130
- Harpy.entry_point_url = "http://localhost"
131
152
  lambda{
132
153
  Harpy::Spec::Company.from_id(1)
133
154
  }.should raise_error NotImplementedError
134
155
  end
135
156
  end
157
+ context "when urn has been overriden but entry point is not set" do
158
+ let(:urn) { "urn:harpy:company:1" }
159
+ it "raises Harpy::EntryPointRequired" do
160
+ # 1 -> urn:harpy:company:1
161
+ Harpy::Spec::Company.should_receive(:urn).with(1).and_return urn
162
+
163
+ lambda{
164
+ Harpy::Spec::Company.from_id(1)
165
+ }.should raise_error Harpy::EntryPointRequired
166
+ end
167
+ end
136
168
  context "when entry point is set and urn has been overriden" do
137
169
  let(:urn) { "urn:harpy:company:1" }
138
170
  let(:url) { "http://localhost/company/1" }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: harpy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,12 +10,12 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2011-07-20 00:00:00.000000000 +02:00
13
+ date: 2011-08-02 00:00:00.000000000 +02:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: typhoeus
18
- requirement: &2164769540 !ruby/object:Gem::Requirement
18
+ requirement: &2164624240 !ruby/object:Gem::Requirement
19
19
  none: false
20
20
  requirements:
21
21
  - - ~>
@@ -23,10 +23,10 @@ dependencies:
23
23
  version: 0.2.4
24
24
  type: :runtime
25
25
  prerelease: false
26
- version_requirements: *2164769540
26
+ version_requirements: *2164624240
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: activesupport
29
- requirement: &2164769020 !ruby/object:Gem::Requirement
29
+ requirement: &2164623720 !ruby/object:Gem::Requirement
30
30
  none: false
31
31
  requirements:
32
32
  - - ! '>='
@@ -34,10 +34,10 @@ dependencies:
34
34
  version: 3.0.0
35
35
  type: :runtime
36
36
  prerelease: false
37
- version_requirements: *2164769020
37
+ version_requirements: *2164623720
38
38
  - !ruby/object:Gem::Dependency
39
39
  name: activemodel
40
- requirement: &2164768540 !ruby/object:Gem::Requirement
40
+ requirement: &2164623240 !ruby/object:Gem::Requirement
41
41
  none: false
42
42
  requirements:
43
43
  - - ! '>='
@@ -45,10 +45,10 @@ dependencies:
45
45
  version: 3.0.0
46
46
  type: :runtime
47
47
  prerelease: false
48
- version_requirements: *2164768540
48
+ version_requirements: *2164623240
49
49
  - !ruby/object:Gem::Dependency
50
50
  name: hash-deep-merge
51
- requirement: &2155977780 !ruby/object:Gem::Requirement
51
+ requirement: &2156256400 !ruby/object:Gem::Requirement
52
52
  none: false
53
53
  requirements:
54
54
  - - ~>
@@ -56,10 +56,10 @@ dependencies:
56
56
  version: 0.1.1
57
57
  type: :runtime
58
58
  prerelease: false
59
- version_requirements: *2155977780
59
+ version_requirements: *2156256400
60
60
  - !ruby/object:Gem::Dependency
61
61
  name: yajl-ruby
62
- requirement: &2155977300 !ruby/object:Gem::Requirement
62
+ requirement: &2156255920 !ruby/object:Gem::Requirement
63
63
  none: false
64
64
  requirements:
65
65
  - - ~>
@@ -67,10 +67,10 @@ dependencies:
67
67
  version: 0.8.2
68
68
  type: :runtime
69
69
  prerelease: false
70
- version_requirements: *2155977300
70
+ version_requirements: *2156255920
71
71
  - !ruby/object:Gem::Dependency
72
72
  name: rake
73
- requirement: &2155976820 !ruby/object:Gem::Requirement
73
+ requirement: &2156255440 !ruby/object:Gem::Requirement
74
74
  none: false
75
75
  requirements:
76
76
  - - ~>
@@ -78,10 +78,10 @@ dependencies:
78
78
  version: 0.8.7
79
79
  type: :development
80
80
  prerelease: false
81
- version_requirements: *2155976820
81
+ version_requirements: *2156255440
82
82
  - !ruby/object:Gem::Dependency
83
83
  name: rspec
84
- requirement: &2155976340 !ruby/object:Gem::Requirement
84
+ requirement: &2156254960 !ruby/object:Gem::Requirement
85
85
  none: false
86
86
  requirements:
87
87
  - - ~>
@@ -89,10 +89,10 @@ dependencies:
89
89
  version: 2.6.0
90
90
  type: :development
91
91
  prerelease: false
92
- version_requirements: *2155976340
92
+ version_requirements: *2156254960
93
93
  - !ruby/object:Gem::Dependency
94
94
  name: rocco
95
- requirement: &2155975860 !ruby/object:Gem::Requirement
95
+ requirement: &2156254480 !ruby/object:Gem::Requirement
96
96
  none: false
97
97
  requirements:
98
98
  - - ~>
@@ -100,7 +100,7 @@ dependencies:
100
100
  version: '0.7'
101
101
  type: :development
102
102
  prerelease: false
103
- version_requirements: *2155975860
103
+ version_requirements: *2156254480
104
104
  description: Client for REST API with HATEOAS
105
105
  email:
106
106
  - joseph.halter@thetalentbox.com