acfs 0.43.1 → 0.43.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b273e1b3c19b7b27fdbea33867f442ec33ada319
4
- data.tar.gz: cd853ac93c6276d23cae140d860bf563ba62159b
3
+ metadata.gz: bb6beef716e78e480aedddca7a82b3038c2cdb66
4
+ data.tar.gz: 594fabd1f7d3367a69585b5c57756769543ffbf0
5
5
  SHA512:
6
- metadata.gz: a73b486b0685757f0f5495f9cd358978a6702f78805c5ceeb354aa3e7da086bdae2b4fe0f11a664cb8c1ed753aeb50b7a9bfe4f2cac47b14241f33f883d31ba2
7
- data.tar.gz: 088703ae6692aab3666106c6bd3afcdda44fa37676e4351842e32a1b1777a29fff31daf1b2f0c05c03fe0a6d85d12058aedd87a17710530a28c30b117231c8b6
6
+ metadata.gz: d8e27c7c86a770e016c1ea57f7f1a38b08e8ab77fa2cc3f6b13dcd8c2abb5c2bbcf32e4c85c4ddd5da05a724e736d16a80b554a834fc77e886284e5141c79e6c
7
+ data.tar.gz: 47fc747abc4dcec91a32804c8d6618da3062361ac70bde1ee8f228516e62b3122fd0ee5f930acbe66df7ec06c3a8e9d424cd7df1266b7c2f8ff848496d92663b
@@ -8,7 +8,7 @@ module Acfs::Collections
8
8
  opts[:url]
9
9
  end
10
10
 
11
- attr_reader :total_pages, :current_page
11
+ attr_reader :total_pages, :current_page, :total_count
12
12
  end
13
13
 
14
14
  def process_response(response)
@@ -49,6 +49,10 @@ module Acfs::Collections
49
49
  @total_pages = Integer(headers['X-Total-Pages'])
50
50
  end
51
51
 
52
+ if headers['X-Total-Count']
53
+ @total_count = Integer(headers['X-Total-Count'])
54
+ end
55
+
52
56
  setup_links headers['Link'] if headers['Link']
53
57
  end
54
58
 
data/lib/acfs/errors.rb CHANGED
@@ -46,10 +46,13 @@ module Acfs
46
46
  attr_reader :stubs, :operation
47
47
 
48
48
  def initialize(opts = {})
49
+ require 'pp'
50
+
49
51
  @stubs = opts.delete :stubs
50
52
  @operation = opts.delete :operation
51
53
 
52
- super opts, 'Ambiguous stubs.'
54
+ super opts, "Ambiguous stubs for #{operation.action} on #{operation.resource}.\n" +
55
+ stubs.map {|s| " #{s.opts.pretty_inspect}" }.join
53
56
  end
54
57
  end
55
58
 
@@ -97,7 +100,7 @@ module Acfs
97
100
  def initialize(opts = {})
98
101
  @base_class = opts.delete :base_class
99
102
  @type_name = opts.delete :type_name
100
- opts[:message] = "Recieved ressource type `#{type_name}` is no subclass of #{base_class}"
103
+ opts[:message] = "Received resource type `#{type_name}` is no subclass of #{base_class}"
101
104
  super
102
105
  end
103
106
  end
@@ -17,7 +17,11 @@ module Acfs::Resource::Attributes
17
17
  # @return [Fixnum] Casted object as fixnum.
18
18
  #
19
19
  def cast_type(obj)
20
+ return 0 if obj == ''
21
+
20
22
  Integer obj
23
+ rescue ArgumentError => e
24
+ raise TypeError.new e.message
21
25
  end
22
26
  end
23
27
  end
@@ -137,7 +137,7 @@ class Acfs::Resource
137
137
  def find_by!(params, &block)
138
138
  find_by params do |m|
139
139
  if m.nil?
140
- raise Acfs::ResourceNotFound.new message: 'Recieved erronious ' \
140
+ raise Acfs::ResourceNotFound.new message: 'Received erroneous ' \
141
141
  "response: no `#{name}` with params #{params} found"
142
142
  end
143
143
  block.call m unless block.nil?
data/lib/acfs/version.rb CHANGED
@@ -2,7 +2,7 @@ module Acfs
2
2
  module VERSION
3
3
  MAJOR = 0
4
4
  MINOR = 43
5
- PATCH = 1
5
+ PATCH = 2
6
6
  STAGE = nil
7
7
 
8
8
  STRING = [MAJOR, MINOR, PATCH, STAGE].reject(&:nil?).join('.')
@@ -13,11 +13,15 @@ describe Acfs::Collection do
13
13
  before do
14
14
  stub_request(:get, 'http://users.example.org/users')
15
15
  .to_return response([{id: 1, name: 'Anon', age: 12, born_at: 'Berlin'}],
16
- headers: {'X-Total-Pages' => '2'})
16
+ headers: {
17
+ 'X-Total-Pages' => '2',
18
+ 'X-Total-Count' => '10'
19
+ })
17
20
  end
18
21
 
19
22
  its(:total_pages) { should eq 2 }
20
23
  its(:current_page) { should eq 1 }
24
+ its(:total_count) { should eq 10 }
21
25
  end
22
26
 
23
27
  context 'with page parameter' do
@@ -25,11 +29,15 @@ describe Acfs::Collection do
25
29
  before do
26
30
  stub_request(:get, 'http://users.example.org/users?page=2')
27
31
  .to_return response([{id: 1, name: 'Anon', age: 12, born_at: 'Berlin'}],
28
- headers: {'X-Total-Pages' => '2'})
32
+ headers: {
33
+ 'X-Total-Pages' => '2',
34
+ 'X-Total-Count' => '10'
35
+ })
29
36
  end
30
37
 
31
38
  its(:total_pages) { should eq 2 }
32
39
  its(:current_page) { should eq 2 }
40
+ its(:total_count) { should eq 10 }
33
41
  end
34
42
 
35
43
  context 'with non-numerical page parameter' do
@@ -37,11 +45,15 @@ describe Acfs::Collection do
37
45
  before do
38
46
  stub_request(:get, 'http://users.example.org/users?page=e546f5')
39
47
  .to_return response([{id: 1, name: 'Anon', age: 12, born_at: 'Berlin'}],
40
- headers: {'X-Total-Pages' => '2'})
48
+ headers: {
49
+ 'X-Total-Pages' => '2',
50
+ 'X-Total-Count' => '10'
51
+ })
41
52
  end
42
53
 
43
54
  its(:total_pages) { should eq 2 }
44
55
  its(:current_page) { should eq 'e546f5' }
56
+ its(:total_count) { should eq 10 }
45
57
  end
46
58
 
47
59
  describe '#next_page' do
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe Acfs::Resource::Attributes::Integer do
4
+ subject { Acfs::Resource::Attributes::Integer.new }
5
+
6
+ describe 'cast' do
7
+ it 'should cast integer strings' do
8
+ expect(subject.cast('123')).to eq 123
9
+ end
10
+
11
+ it 'should cast empty string (backward compatibility)' do
12
+ expect(subject.cast('')).to eq 0
13
+ end
14
+
15
+ it 'should not cast invalid integers' do
16
+ expect { subject.cast 'abc' }.to raise_error TypeError
17
+ end
18
+ end
19
+ end
@@ -163,10 +163,16 @@ describe Acfs::Stub do
163
163
  end
164
164
 
165
165
  let!(:comments) { Comment.all }
166
- let(:headers) { {'X-Total-Pages' => '2'} }
166
+ let(:headers) do
167
+ {
168
+ 'X-Total-Pages' => '2',
169
+ 'X-Total-Count' => '10'
170
+ }
171
+ end
167
172
  subject { Acfs.run; comments }
168
173
 
169
174
  its(:total_pages) { should eq 2 }
175
+ its(:total_count) { should eq 10 }
170
176
  end
171
177
  end
172
178
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acfs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.43.1
4
+ version: 0.43.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Graichen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-18 00:00:00.000000000 Z
11
+ date: 2015-12-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -182,6 +182,7 @@ files:
182
182
  - spec/acfs/resource/attributes/date_time_spec.rb
183
183
  - spec/acfs/resource/attributes/dict_spec.rb
184
184
  - spec/acfs/resource/attributes/float_spec.rb
185
+ - spec/acfs/resource/attributes/integer_spec.rb
185
186
  - spec/acfs/resource/attributes/list_spec.rb
186
187
  - spec/acfs/resource/attributes/uuid_spec.rb
187
188
  - spec/acfs/resource/attributes_spec.rb
@@ -226,7 +227,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
226
227
  version: '0'
227
228
  requirements: []
228
229
  rubyforge_project:
229
- rubygems_version: 2.4.6
230
+ rubygems_version: 2.4.8
230
231
  signing_key:
231
232
  specification_version: 4
232
233
  summary: An abstract API base client for service oriented application.
@@ -244,6 +245,7 @@ test_files:
244
245
  - spec/acfs/resource/attributes/date_time_spec.rb
245
246
  - spec/acfs/resource/attributes/dict_spec.rb
246
247
  - spec/acfs/resource/attributes/float_spec.rb
248
+ - spec/acfs/resource/attributes/integer_spec.rb
247
249
  - spec/acfs/resource/attributes/list_spec.rb
248
250
  - spec/acfs/resource/attributes/uuid_spec.rb
249
251
  - spec/acfs/resource/attributes_spec.rb