frenetic 0.0.20.alpha.5 → 0.0.20.alpha.6

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.
@@ -27,6 +27,12 @@ class Frenetic
27
27
  {}
28
28
  end
29
29
 
30
+ module ClassMethods
31
+ def api_client
32
+ superclass.api_client
33
+ end
34
+ end
35
+
30
36
  private
31
37
 
32
38
  def build_params( p )
@@ -12,14 +12,6 @@ class Frenetic
12
12
  include HalLinked
13
13
  include MemberRestMethods
14
14
 
15
- def api
16
- self.class.api
17
- end
18
-
19
- def self.api
20
- api_client
21
- end
22
-
23
15
  def self.api_client( client = nil )
24
16
  if client
25
17
  @api_client = client
@@ -31,6 +23,8 @@ class Frenetic
31
23
  @api_client
32
24
  end
33
25
  end
26
+ # Alias class method hack
27
+ def self.api; api_client; end
34
28
 
35
29
  def self.namespace( namespace = nil )
36
30
  if namespace
@@ -46,12 +40,15 @@ class Frenetic
46
40
  (api.schema[namespace]||{})['properties'] or raise HypermediaError, %Q{Could not find schema definition for the resource "#{namespace}"}
47
41
  end
48
42
 
49
- def self.as_mock( params = {} )
50
- raise Frenetic::ClientError, "Mock resource not defined for #{namespace}." \
51
- " Subclass #{self} and mixin Frenetic::ResourceMockery" \
52
- " to define a mock" unless @mock_class
43
+ def self.mock_class
44
+ @mock_class or raise Frenetic::ClientError,
45
+ "Mock resource not defined for #{namespace}." \
46
+ " Subclass #{self} and mixin Frenetic::ResourceMockery" \
47
+ " to define a mock"
48
+ end
53
49
 
54
- @mock_class.new params
50
+ def self.as_mock( params = {} )
51
+ mock_class.new params
55
52
  end
56
53
 
57
54
  def initialize( p = {} )
@@ -65,6 +62,11 @@ class Frenetic
65
62
  build_structure
66
63
  end
67
64
 
65
+ def api_client
66
+ self.class.api_client
67
+ end
68
+ alias :api :api_client
69
+
68
70
  def attributes
69
71
  @attributes ||= begin
70
72
  @structure.each_pair.each_with_object({}) do |(k,v), attrs|
@@ -123,6 +125,5 @@ class Frenetic
123
125
  def self.test_mode?
124
126
  api_client.config.test_mode
125
127
  end
126
-
127
128
  end
128
129
  end
@@ -1,3 +1,3 @@
1
1
  class Frenetic
2
- VERSION = '0.0.20.alpha.5'
2
+ VERSION = '0.0.20.alpha.6'
3
3
  end
@@ -155,6 +155,20 @@ describe Frenetic::Resource do
155
155
  describe '.as_mock' do
156
156
  subject { MyNamespace::MyTempResource.as_mock id:99 }
157
157
 
158
+ before do
159
+ stub_const 'MyNamespace::MyMockResource', Class.new(MyNamespace::MyTempResource)
160
+
161
+ MyNamespace::MyMockResource.send :include, Frenetic::ResourceMockery
162
+ end
163
+
164
+ it 'should initialize the mock with the provided values' do
165
+ expect(subject.id).to eq 99
166
+ end
167
+ end
168
+
169
+ describe '.mock_class' do
170
+ subject { MyNamespace::MyTempResource.mock_class }
171
+
158
172
  context 'without a defined Mock-class' do
159
173
  it 'should raise an error' do
160
174
  expect{subject}.to raise_error Frenetic::ClientError
@@ -169,11 +183,7 @@ describe Frenetic::Resource do
169
183
  end
170
184
 
171
185
  it 'should return a mock instance of the resource' do
172
- expect(subject).to be_an_instance_of MyNamespace::MyMockResource
173
- end
174
-
175
- it 'should initialize the mock with the provided values' do
176
- expect(subject.id).to eq 99
186
+ expect(subject).to eq MyNamespace::MyMockResource
177
187
  end
178
188
  end
179
189
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: frenetic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.20.alpha.5
4
+ version: 0.0.20.alpha.6
5
5
  prerelease: 7
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-05-16 00:00:00.000000000 Z
12
+ date: 2013-05-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: faraday
@@ -215,7 +215,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
215
215
  version: '0'
216
216
  segments:
217
217
  - 0
218
- hash: -3382151532624258123
218
+ hash: -828936829114139905
219
219
  required_rubygems_version: !ruby/object:Gem::Requirement
220
220
  none: false
221
221
  requirements: