version-one 0.0.7 → 0.0.8

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.
@@ -1 +1 @@
1
- 1.9.2-p484
1
+ 1.9.3-p0
@@ -273,45 +273,37 @@ module VersionOne
273
273
  def init_attribute_value(el)
274
274
  attr_name = el.attributes['name']
275
275
 
276
- children = el.children
277
- child_count = children.size
278
- first = children[0]
279
-
280
- if true #child_count > 0
281
-
282
- case el.name
283
- when 'Attribute'
284
- val = case
285
- when child_count == 0
286
- nil
287
- when first.name == 'Value'
288
- children.map(&:content)
289
- else
290
- el.content
291
- end
292
-
293
- #DEBUG puts "Setting #{attr_name} to #{val.inspect}"
294
-
295
- if @setters[attr_name]
296
- send(@setters[attr_name], val)
297
- else
298
- add_simple_attribute(attr_name, String, readonly: true)
299
- @attributes[attr_name] = val
300
- end
301
-
302
- when 'Relation'
303
- val = children.map{|v| (v.name == 'Asset') ? AssetRef.new(v) : nil}.compact
304
- unless @setters[attr_name]
305
- add_relation_attribute(attr_name, readonly: true)
306
- end
276
+ # If no children (text or elements) then treat as nil value
277
+ # If has Value or Asset children then default to multivalue array
278
+ is_nil = el.children.size == 0
279
+ val = nil if is_nil
280
+ children = is_nil ? [] : el.find('Value|Asset').to_a
281
+ is_multivalue = children.size > 0
282
+
283
+ case el.name
284
+ when 'Attribute'
285
+ val = is_multivalue ? children.map(&:content) : el.content unless is_nil
286
+
287
+ if @setters[attr_name]
307
288
  send(@setters[attr_name], val)
308
- @attributes[attr_name].unchanged! if @attributes[attr_name].respond_to?(:unchanged!)
309
-
310
289
  else
311
- # Ignore
312
- end
290
+ add_simple_attribute(attr_name, String, readonly: true, multivalue: is_multivalue)
291
+ @attributes[attr_name] = val
292
+ end
313
293
 
294
+ when 'Relation'
295
+ val = children.map{|v| AssetRef.new(v)} unless is_nil
296
+
297
+ unless @setters[attr_name]
298
+ add_relation_attribute(attr_name, readonly: true, multivalue: is_multivalue)
299
+ end
300
+ send(@setters[attr_name], val)
301
+ @attributes[attr_name].unchanged! if @attributes[attr_name].respond_to?(:unchanged!)
302
+
303
+ else
304
+ # Ignore
314
305
  end
306
+
315
307
  end
316
308
 
317
309
  def add_generic_attribute(attr_name, options={})
@@ -359,9 +351,9 @@ end
359
351
  @setters[attr_name] = "#{ruby_name}="
360
352
  end
361
353
 
362
- def add_simple_attribute(attr_name, native_type, options={})
354
+ def add_simple_attribute(_attr_name, native_type, _options={})
363
355
 
364
- add_generic_attribute(attr_name, options) do |attr_name, options|
356
+ add_generic_attribute(_attr_name, _options) do |attr_name, options|
365
357
  convert = "convert_to_#{native_type}"
366
358
  if options[:multivalue]
367
359
  setter = %{
@@ -435,6 +427,10 @@ end
435
427
  VersionOne.s_to_time(val, utc: !!(name.match(/utc$/i)))
436
428
  end
437
429
 
430
+ def convert_to_Float(name, val)
431
+ Float(val)
432
+ end
433
+
438
434
  def save_url
439
435
  if @href
440
436
  @href
@@ -120,7 +120,7 @@ module VersionOne
120
120
  request_path = uri.path
121
121
  request_path += '?' + uri.query if uri.query
122
122
 
123
- result = http.start do
123
+ http.start do
124
124
  klass = case type
125
125
  when :get
126
126
  Net::HTTP::Get
@@ -26,7 +26,7 @@ module VersionOne
26
26
  end
27
27
  end
28
28
 
29
- q.instance_eval &block
29
+ q.instance_eval(&block)
30
30
  q
31
31
  end
32
32
 
@@ -4,6 +4,8 @@ module VersionOne
4
4
  class RelationMultiValue
5
5
 
6
6
  def initialize(val = nil)
7
+ @assets = {}
8
+ @original_assets = {}
7
9
  set(val)
8
10
  end
9
11
 
@@ -15,7 +17,11 @@ module VersionOne
15
17
  def set(val)
16
18
  val ||= []
17
19
  val = [val] unless val.is_a?(Array)
18
- @assets = val.map{|v| AssetRef.for(v) }.index_by(&:id)
20
+ @assets = {}
21
+ val.each do |v|
22
+ v = AssetRef.for(v)
23
+ @assets[v.id] = v
24
+ end
19
25
  @original_assets ||= @assets.dup
20
26
  self
21
27
  end
@@ -1,3 +1,3 @@
1
1
  module VersionOne
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8"
3
3
  end
@@ -0,0 +1,54 @@
1
+ <Assets total="2" pageSize="2147483647" pageStart="0">
2
+ <Asset href="/Bogus/rest-1.v1/Data/Expression/74458" id="Expression:74458">
3
+ <Attribute name="AssetType">Expression</Attribute>
4
+ <Relation name="Mentions">
5
+ <Asset href="/Bogus/rest-1.v1/Data/Member/1008" idref="Member:1008"/>
6
+ <Asset href="/Bogus/rest-1.v1/Data/Member/1010" idref="Member:1010"/>
7
+ <Asset href="/Bogus/rest-1.v1/Data/Member/1120" idref="Member:1120"/>
8
+ </Relation>
9
+ <Attribute name="Mentions.Name">
10
+ <Value>Bob One</Value>
11
+ <Value>Bob Two</Value>
12
+ <Value>Bob Three</Value>
13
+ </Attribute>
14
+ <Relation name="InReplyTo.Mentions">
15
+ <Asset href="/Bogus/rest-1.v1/Data/Member/1008" idref="Member:1008"/>
16
+ <Asset href="/Bogus/rest-1.v1/Data/Member/1120" idref="Member:1120"/>
17
+ <Asset href="/Bogus/rest-1.v1/Data/Member/8050" idref="Member:8050"/>
18
+ <Asset href="/Bogus/rest-1.v1/Data/Member/14494" idref="Member:14494"/>
19
+ <Asset href="/Bogus/rest-1.v1/Data/Defect/72081" idref="Defect:72081"/>
20
+ </Relation>
21
+ <Attribute name="InReplyTo.Mentions.Name">
22
+ <Value>Bob One</Value>
23
+ <Value>Bob Two</Value>
24
+ <Value>Bob Three</Value>
25
+ <Value>Bob Four</Value>
26
+ <Value>Some bug in the product</Value>
27
+ </Attribute>
28
+ <Attribute name="SomeThing.SingleValue">Expected Value</Attribute>
29
+ <Relation name="SomeThing.SingleRelation"><Asset href="/Bogus/rest-1.v1/Data/Member/14494" idref="Member:14494"/></Relation>
30
+ </Asset>
31
+ <Asset href="/Bogus/rest-1.v1/Data/Expression/74463" id="Expression:74463">
32
+ <Attribute name="AssetType">Expression</Attribute>
33
+ <Relation name="Mentions">
34
+ <Asset href="/Bogus/rest-1.v1/Data/Member/51082" idref="Member:51082"/>
35
+ <Asset href="/Bogus/rest-1.v1/Data/Member/1008" idref="Member:1008"/>
36
+ <Asset href="/Bogus/rest-1.v1/Data/Member/1010" idref="Member:1010"/>
37
+ <Asset href="/Bogus/rest-1.v1/Data/Member/1120" idref="Member:1120"/>
38
+ </Relation>
39
+ <Attribute name="Mentions.Name">
40
+ <Value>Bob One</Value>
41
+ <Value>Bob Two</Value>
42
+ <Value>Bob Three</Value>
43
+ <Value>Bob Four</Value>
44
+ </Attribute>
45
+ <Relation name="InReplyTo.Mentions">
46
+ <Asset href="/Bogus/rest-1.v1/Data/Defect/45128" idref="Defect:45128"/>
47
+ </Relation>
48
+ <Attribute name="InReplyTo.Mentions.Name">
49
+ <Value>
50
+ Some other problem with the product
51
+ </Value>
52
+ </Attribute>
53
+ </Asset>
54
+ </Assets>
@@ -1,16 +1,16 @@
1
1
  <?xml version="1.0" encoding="UTF-8"?>
2
- <Asset href="/Ooyala/rest-1.v1/Data/Story/1816" id="Story:1816">
2
+ <Asset href="/Bogus/rest-1.v1/Data/Story/1816" id="Story:1816">
3
3
  <Attribute name="AssetType">Story</Attribute>
4
4
  <Attribute name="Benefits"/>
5
5
  <Relation name="SplitFrom"/>
6
6
  <Relation name="SecurityScope">
7
- <Asset href="/Ooyala/rest-1.v1/Data/Scope/4322" idref="Scope:4322"/>
7
+ <Asset href="/Bogus/rest-1.v1/Data/Scope/4322" idref="Scope:4322"/>
8
8
  </Relation>
9
9
  <Relation name="Super"/>
10
10
  <Relation name="Team"/>
11
11
  <Relation name="IdentifiedIn"/>
12
12
  <Relation name="Parent">
13
- <Asset href="/Ooyala/rest-1.v1/Data/Theme/4853" idref="Theme:4853"/>
13
+ <Asset href="/Bogus/rest-1.v1/Data/Theme/4853" idref="Theme:4853"/>
14
14
  </Relation>
15
15
  <Relation name="Category"/>
16
16
  <Relation name="Risk"/>
@@ -41,21 +41,56 @@ describe VersionOne::Asset do
41
41
  end
42
42
 
43
43
  describe 'new from xml' do
44
- subject { described_class.from_xml(load_xml('story')) }
44
+ context 'with a single result' do
45
+ subject { described_class.from_xml(load_xml('story')) }
45
46
 
46
- include_examples 'new'
47
+ include_examples 'new'
47
48
 
48
- it 'should set attribute values from xml' do
49
- expect(subject.number).to eq 'B-01027'
50
- expect(subject.order).to eq -1071957351
51
- end
49
+ it 'should set attribute values from xml' do
50
+ expect(subject.number).to eq 'B-01027'
51
+ expect(subject.order).to eq -1071957351
52
+ end
52
53
 
53
- it 'should provide attribute readers for queried attributes' do
54
- expect(subject).to respond_to :security_scope_name
54
+ it 'should provide attribute readers for queried attributes' do
55
+ expect(subject).to respond_to :security_scope_name
56
+ end
55
57
  end
56
58
 
59
+ context 'with multiple results' do
60
+ subject { described_class.from_xml(load_xml('expression_results')) }
61
+
62
+ it 'should return an array of assets' do
63
+ expect(subject).to be_a Array
64
+ expect(subject.size).to eq 2
65
+ end
66
+
67
+ describe 'should populate indirectly' do
68
+
69
+ it 'single values' do
70
+ expect(subject[0].some_thing_single_value).to eq 'Expected Value'
71
+ end
72
+
73
+ it 'multiple values' do
74
+ expect(subject[0].in_reply_to_mentions_name).to eq ['Bob One', 'Bob Two', 'Bob Three', 'Bob Four', 'Some bug in the product']
75
+ end
76
+
77
+ it 'single relations' do
78
+ expect(subject[0].some_thing_single_relation.size).to be > 0
79
+ expect(subject[0].some_thing_single_relation.map(&:id)).to eq ['Member:14494']
80
+ end
81
+
82
+ it 'multiple relations' do
83
+ expect(subject[0].in_reply_to_mentions.size).to be > 0
84
+ expect(subject[0].in_reply_to_mentions.map(&:id)).to eq %w{Member:1008 Member:1120 Member:8050 Member:14494 Defect:72081}
85
+ end
86
+
87
+ end
88
+
89
+ end
57
90
  end
58
91
 
92
+
93
+
59
94
  describe 'new' do
60
95
  subject { described_class.new(type: 'Story') }
61
96
 
@@ -4,5 +4,5 @@ require 'lib/common'
4
4
  describe VersionOne::Query do
5
5
  include_context 'configured'
6
6
 
7
-
7
+ it 'should test something'
8
8
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: version-one
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  prerelease:
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: 2014-10-14 00:00:00.000000000 Z
12
+ date: 2014-11-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: libxml-ruby
@@ -85,6 +85,7 @@ files:
85
85
  - lib/version-one/time.rb
86
86
  - lib/version-one/version.rb
87
87
  - lib/version-one/version.rb~
88
+ - spec/fixtures/expression_results.xml
88
89
  - spec/fixtures/story.xml
89
90
  - spec/fixtures/story_meta.xml
90
91
  - spec/lib/asset_spec.rb
@@ -120,6 +121,7 @@ signing_key:
120
121
  specification_version: 3
121
122
  summary: VersionOne integration gem.
122
123
  test_files:
124
+ - spec/fixtures/expression_results.xml
123
125
  - spec/fixtures/story.xml
124
126
  - spec/fixtures/story_meta.xml
125
127
  - spec/lib/asset_spec.rb