braque 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7e576d0ca74ea35d912a52c67e9971a7740a0dfa
4
- data.tar.gz: 5d52452de3a6ed8611a2b127ed002d5ebee8c3e9
3
+ metadata.gz: 7877495074bf14604179991d76599e5bfc508716
4
+ data.tar.gz: c08da9d09ed4e53b9179b5c3188073dd025e2b95
5
5
  SHA512:
6
- metadata.gz: 60fbbb04472b235c26ceb02490013f7b68b046478e461889a5ccaac88728aa5b51671c022dc4fcb3f74827f8f7cb85f3b37c5f0af4239f5ce53ad8bf5c14abcd
7
- data.tar.gz: 0076fe9afecb8bded09adf25806d9afc920be19de40b2de2bcad5d33e3e8e13765676f793b01f96c681751e6ee1dacbb5fe96f0310d9cd0b2fabf7afbddb14f3
6
+ metadata.gz: f9df5a71dc0428f62e763b14dd3b68e5c363ef7a1d6118b407878cd6e0627ef54dfc1c13d54544e81fc73c93ec6d3e5c027bd986ee738f18d74644c29d4ac45a
7
+ data.tar.gz: 02fcb2222b97b54c8216b5024f12b8fb57f55e9ec4901fd2d7e81dd2b82c1451065fb62e340318aae7546299d9b2434636e3379e9fb8c2146a6bc746f51cf1cd
@@ -10,7 +10,7 @@ module Braque
10
10
  previous_link = response._links.try(:prev)
11
11
  total_count = response.try(:total_count)
12
12
  retrieved_items = []
13
- response.each do |item|
13
+ response_items(response, klass).each do |item|
14
14
  retrieved_items << klass.new(item)
15
15
  end
16
16
  @retrieved_items = retrieved_items
@@ -19,6 +19,11 @@ module Braque
19
19
  @total_count = total_count
20
20
  super retrieved_items
21
21
  end
22
+
23
+ def response_items(response, klass)
24
+ return response unless response.respond_to? :_embedded
25
+ response._embedded.send klass.collection_method_name
26
+ end
22
27
  end
23
28
  end
24
29
  end
@@ -1,3 +1,3 @@
1
1
  module Braque
2
- VERSION = '0.1.2'
2
+ VERSION = '0.1.3'
3
3
  end
@@ -1,24 +1,32 @@
1
1
  require 'spec_helper'
2
2
 
3
+ require 'spec_helper'
4
+
3
5
  RSpec.describe Braque::Collection do
4
- context 'paginate_and_sort in a GravityModel class' do
5
- before(:all) do
6
- class BraqueClass
7
- include ::ActiveAttr::Model
8
- include Braque::Collection
9
- attribute :id
10
- attribute :title
6
+ before(:all) do
7
+ class BraqueClass
8
+ include ::ActiveAttr::Model
9
+ include Braque::Collection
10
+ attribute :id
11
+ attribute :title
12
+
13
+ def self.collection_method_name
14
+ name.tableize
11
15
  end
16
+ end
12
17
 
13
- class ResponseLinks
14
- attr_reader :next
15
- attr_reader :prev
16
- def initialize(next_str, previous_str)
17
- @next = next_str
18
- @prev = previous_str
19
- end
18
+ class ResponseLinks
19
+ attr_reader :next
20
+ attr_reader :prev
21
+ def initialize(next_str, previous_str)
22
+ @next = next_str
23
+ @prev = previous_str
20
24
  end
25
+ end
26
+ end
21
27
 
28
+ context 'when collection is an array' do
29
+ before(:all) do
22
30
  class ResponseCollection < Array
23
31
  attr_reader :total_count
24
32
  attr_reader :_links
@@ -37,25 +45,91 @@ RSpec.describe Braque::Collection do
37
45
  @response = ResponseCollection.new @array, true, false
38
46
  @linked_array = BraqueClass::LinkedArray.new(@response, BraqueClass)
39
47
  end
48
+
40
49
  it 'returns an array of the correct number of items' do
41
50
  expect(@linked_array.count).to eq 2
42
51
  end
52
+
43
53
  it 'returns the correct total_count' do
44
54
  expect(@linked_array.total_count).to eq 3
45
55
  end
56
+
46
57
  it 'returns an array of new items based on the calling class' do
47
58
  expect(@linked_array.first.id).to eq 1
48
59
  expect(@linked_array.first.title).to eq @array.first[:title]
49
60
  expect(@linked_array.first.class.name).to eq 'BraqueClass'
61
+ expect(@linked_array[1].id).to eq 2
62
+ expect(@linked_array[1].title).to eq @array[1][:title]
63
+ expect(@linked_array[1].class.name).to eq 'BraqueClass'
64
+ end
65
+
66
+ it 'responds to previous_link with the correct value' do
67
+ expect(@linked_array).to respond_to(:previous_link)
68
+ expect(@linked_array.previous_link).to eq false
69
+ end
70
+
71
+ it 'responds to next_link with the correct value' do
72
+ expect(@linked_array).to respond_to(:next_link)
73
+ expect(@linked_array.next_link).to eq true
74
+ end
75
+ end
76
+ end
77
+ end
78
+
79
+ context 'when collection responds to _embedded' do
80
+ before(:all) do
81
+ class ResponseEmbedded
82
+ attr_reader :braque_classes
83
+
84
+ def initialize(results)
85
+ @braque_classes = results
86
+ end
87
+ end
50
88
 
89
+ class ResponseCollection < Array
90
+ attr_reader :total_count
91
+ attr_reader :_links
92
+ attr_reader :_embedded
93
+
94
+ def initialize(array, next_str, previous_str)
95
+ @total_count = 3
96
+ @_links = ResponseLinks.new next_str, previous_str
97
+ @_embedded = ResponseEmbedded.new array
98
+ super array
99
+ end
100
+ end
101
+ end
102
+
103
+ context 'LinkedArray' do
104
+ context '#initialize' do
105
+ before(:all) do
106
+ @array = [{ id: 1, title: 'hello' }, { id: 2, title: 'goodbye' }]
107
+ @response = ResponseCollection.new @array, true, false
108
+ @linked_array = BraqueClass::LinkedArray.new(@response, BraqueClass)
109
+ end
110
+
111
+ it 'returns an array of the correct number of items' do
112
+ expect(@linked_array.count).to eq 2
113
+ end
114
+
115
+ it 'returns the correct total_count' do
116
+ expect(@linked_array.total_count).to eq 3
117
+ end
118
+
119
+ it 'returns an array of new items based on the calling class' do
120
+ expect(@linked_array.first.id).to eq 1
121
+ expect(@linked_array.first.title).to eq @array.first[:title]
122
+ expect(@linked_array.first.class.name).to eq 'BraqueClass'
51
123
  expect(@linked_array[1].id).to eq 2
52
124
  expect(@linked_array[1].title).to eq @array[1][:title]
53
125
  expect(@linked_array[1].class.name).to eq 'BraqueClass'
54
126
  end
127
+
55
128
  it 'responds to previous_link with the correct value' do
56
129
  expect(@linked_array).to respond_to(:previous_link)
57
130
  expect(@linked_array.previous_link).to eq false
58
131
  end
132
+
59
133
  it 'responds to next_link with the correct value' do
60
134
  expect(@linked_array).to respond_to(:next_link)
61
135
  expect(@linked_array.next_link).to eq true
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: braque
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dylan Fareed
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-15 00:00:00.000000000 Z
11
+ date: 2015-08-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hyperclient
@@ -98,7 +98,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
98
98
  version: '0'
99
99
  requirements: []
100
100
  rubyforge_project:
101
- rubygems_version: 2.4.3
101
+ rubygems_version: 2.2.2
102
102
  signing_key:
103
103
  specification_version: 4
104
104
  summary: Braque provides a simple interface for interacting with Hypermedia API services