cosm-rb 0.0.1

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.
Files changed (122) hide show
  1. data/.gitignore +12 -0
  2. data/.rbenv-version +1 -0
  3. data/.rspec +2 -0
  4. data/.rvmrc +1 -0
  5. data/.travis.yml +10 -0
  6. data/CHANGELOG.md +91 -0
  7. data/Gemfile +4 -0
  8. data/MIT-LICENSE +20 -0
  9. data/README.md +195 -0
  10. data/Rakefile +35 -0
  11. data/ci/build_hudson.sh +24 -0
  12. data/cosm-rb.gemspec +40 -0
  13. data/init.rb +2 -0
  14. data/lib/cosm-rb/array_extensions.rb +6 -0
  15. data/lib/cosm-rb/base/instance_methods.rb +28 -0
  16. data/lib/cosm-rb/base.rb +52 -0
  17. data/lib/cosm-rb/client.rb +7 -0
  18. data/lib/cosm-rb/datapoint.rb +71 -0
  19. data/lib/cosm-rb/datastream.rb +136 -0
  20. data/lib/cosm-rb/feed.rb +108 -0
  21. data/lib/cosm-rb/hash_extensions.rb +16 -0
  22. data/lib/cosm-rb/helpers.rb +42 -0
  23. data/lib/cosm-rb/key.rb +98 -0
  24. data/lib/cosm-rb/nil_content.rb +15 -0
  25. data/lib/cosm-rb/object_extensions.rb +6 -0
  26. data/lib/cosm-rb/parsers/csv/datastream_defaults.rb +12 -0
  27. data/lib/cosm-rb/parsers/csv/feed_defaults.rb +38 -0
  28. data/lib/cosm-rb/parsers/defaults.rb +13 -0
  29. data/lib/cosm-rb/parsers/json/datapoint_defaults.rb +12 -0
  30. data/lib/cosm-rb/parsers/json/datastream_defaults.rb +53 -0
  31. data/lib/cosm-rb/parsers/json/feed_defaults.rb +103 -0
  32. data/lib/cosm-rb/parsers/json/key_defaults.rb +15 -0
  33. data/lib/cosm-rb/parsers/json/search_result_defaults.rb +18 -0
  34. data/lib/cosm-rb/parsers/json/trigger_defaults.rb +12 -0
  35. data/lib/cosm-rb/parsers/xml/datapoint_defaults.rb +20 -0
  36. data/lib/cosm-rb/parsers/xml/datastream_defaults.rb +77 -0
  37. data/lib/cosm-rb/parsers/xml/feed_defaults.rb +127 -0
  38. data/lib/cosm-rb/parsers/xml/key_defaults.rb +40 -0
  39. data/lib/cosm-rb/parsers/xml/trigger_defaults.rb +22 -0
  40. data/lib/cosm-rb/permission.rb +67 -0
  41. data/lib/cosm-rb/resource.rb +43 -0
  42. data/lib/cosm-rb/search_result.rb +63 -0
  43. data/lib/cosm-rb/string_extensions.rb +6 -0
  44. data/lib/cosm-rb/template.rb +32 -0
  45. data/lib/cosm-rb/templates/csv/datapoint_defaults.rb +22 -0
  46. data/lib/cosm-rb/templates/csv/datastream_defaults.rb +43 -0
  47. data/lib/cosm-rb/templates/csv/feed_defaults.rb +47 -0
  48. data/lib/cosm-rb/templates/defaults.rb +14 -0
  49. data/lib/cosm-rb/templates/json/datapoint_defaults.rb +15 -0
  50. data/lib/cosm-rb/templates/json/datastream_defaults.rb +66 -0
  51. data/lib/cosm-rb/templates/json/feed_defaults.rb +134 -0
  52. data/lib/cosm-rb/templates/json/key_defaults.rb +41 -0
  53. data/lib/cosm-rb/templates/json/search_result_defaults.rb +47 -0
  54. data/lib/cosm-rb/templates/json/trigger_defaults.rb +21 -0
  55. data/lib/cosm-rb/templates/xml/datapoint_defaults.rb +25 -0
  56. data/lib/cosm-rb/templates/xml/datastream_defaults.rb +66 -0
  57. data/lib/cosm-rb/templates/xml/feed_defaults.rb +110 -0
  58. data/lib/cosm-rb/templates/xml/search_result_defaults.rb +116 -0
  59. data/lib/cosm-rb/templates/xml_headers.rb +17 -0
  60. data/lib/cosm-rb/trigger.rb +65 -0
  61. data/lib/cosm-rb/validations.rb +9 -0
  62. data/lib/cosm-rb/version.rb +3 -0
  63. data/lib/cosm-rb.rb +29 -0
  64. data/spec/cosm-rb/array_extensions_spec.rb +9 -0
  65. data/spec/cosm-rb/base/instance_methods_spec.rb +109 -0
  66. data/spec/cosm-rb/base_spec.rb +56 -0
  67. data/spec/cosm-rb/client_spec.rb +7 -0
  68. data/spec/cosm-rb/datapoint_spec.rb +169 -0
  69. data/spec/cosm-rb/datastream_spec.rb +301 -0
  70. data/spec/cosm-rb/feed_spec.rb +298 -0
  71. data/spec/cosm-rb/hash_extensions_spec.rb +20 -0
  72. data/spec/cosm-rb/helpers_spec.rb +56 -0
  73. data/spec/cosm-rb/key_spec.rb +178 -0
  74. data/spec/cosm-rb/parsers/csv/datastream_defaults_spec.rb +12 -0
  75. data/spec/cosm-rb/parsers/csv/feed_defaults_spec.rb +35 -0
  76. data/spec/cosm-rb/parsers/json/datapoint_defaults_spec.rb +15 -0
  77. data/spec/cosm-rb/parsers/json/datastream_defaults_spec.rb +82 -0
  78. data/spec/cosm-rb/parsers/json/feed_defaults_spec.rb +18 -0
  79. data/spec/cosm-rb/parsers/json/key_defaults_spec.rb +8 -0
  80. data/spec/cosm-rb/parsers/json/search_result_defaults_spec.rb +12 -0
  81. data/spec/cosm-rb/parsers/json/trigger_defaults_spec.rb +16 -0
  82. data/spec/cosm-rb/parsers/xml/datapoint_defaults_spec.rb +19 -0
  83. data/spec/cosm-rb/parsers/xml/datastream_defaults_spec.rb +63 -0
  84. data/spec/cosm-rb/parsers/xml/feed_defaults_spec.rb +65 -0
  85. data/spec/cosm-rb/parsers/xml/key_defaults_spec.rb +16 -0
  86. data/spec/cosm-rb/parsers/xml/trigger_defaults_spec.rb +16 -0
  87. data/spec/cosm-rb/search_result_spec.rb +258 -0
  88. data/spec/cosm-rb/string_extensions_spec.rb +12 -0
  89. data/spec/cosm-rb/template_spec.rb +74 -0
  90. data/spec/cosm-rb/templates/csv/datapoint_defaults_spec.rb +41 -0
  91. data/spec/cosm-rb/templates/csv/datastream_defaults_spec.rb +131 -0
  92. data/spec/cosm-rb/templates/csv/feed_defaults_spec.rb +78 -0
  93. data/spec/cosm-rb/templates/json/datapoint_defaults_spec.rb +14 -0
  94. data/spec/cosm-rb/templates/json/datastream_defaults_spec.rb +170 -0
  95. data/spec/cosm-rb/templates/json/feed_defaults_spec.rb +397 -0
  96. data/spec/cosm-rb/templates/json/key_defaults_spec.rb +29 -0
  97. data/spec/cosm-rb/templates/json/search_result_defaults_spec.rb +37 -0
  98. data/spec/cosm-rb/templates/json/trigger_defaults_spec.rb +19 -0
  99. data/spec/cosm-rb/templates/xml/datapoint_defaults_spec.rb +14 -0
  100. data/spec/cosm-rb/templates/xml/datastream_defaults_spec.rb +113 -0
  101. data/spec/cosm-rb/templates/xml/feed_defaults_spec.rb +131 -0
  102. data/spec/cosm-rb/templates/xml/search_result_defaults_spec.rb +44 -0
  103. data/spec/cosm-rb/trigger_spec.rb +117 -0
  104. data/spec/fixtures/models.rb +81 -0
  105. data/spec/spec_helper.rb +17 -0
  106. data/spec/support/contain_datapoint_eeml_matcher.rb +16 -0
  107. data/spec/support/contain_datastream_eeml_matcher.rb +60 -0
  108. data/spec/support/contain_feed_eeml_matcher.rb +96 -0
  109. data/spec/support/datapoint_helper.rb +53 -0
  110. data/spec/support/datastream_helper.rb +300 -0
  111. data/spec/support/describe_eeml_matcher.rb +23 -0
  112. data/spec/support/feed_helper.rb +771 -0
  113. data/spec/support/fully_represent_datapoint_matcher.rb +30 -0
  114. data/spec/support/fully_represent_datastream_matcher.rb +92 -0
  115. data/spec/support/fully_represent_feed_matcher.rb +226 -0
  116. data/spec/support/fully_represent_key_matcher.rb +74 -0
  117. data/spec/support/fully_represent_search_result_matcher.rb +67 -0
  118. data/spec/support/fully_represent_trigger_matcher.rb +29 -0
  119. data/spec/support/key_helper.rb +74 -0
  120. data/spec/support/search_result_helper.rb +252 -0
  121. data/spec/support/trigger_helper.rb +51 -0
  122. metadata +363 -0
@@ -0,0 +1,178 @@
1
+ require 'spec_helper'
2
+
3
+ describe Cosm::Key do
4
+ it "should have a constant that defines the allowed keys" do
5
+ Cosm::Key::ALLOWED_KEYS.sort.should == %w(expires_at id key label user permissions private_access).sort
6
+ end
7
+
8
+ describe "validation" do
9
+ before(:each) do
10
+ @key = Cosm::Key.new
11
+ end
12
+
13
+ %w(label permissions user).each do |field|
14
+ it "should require a '#{field}'" do
15
+ @key.send("#{field}=".to_sym, nil)
16
+ @key.should_not be_valid
17
+ @key.errors[field.to_sym].should include("can't be blank")
18
+ end
19
+ end
20
+
21
+ it "should not be valid if resource present with no feed_id" do
22
+ @key.attributes = { :user => "bob", :permissions => [ { :access_methods => ["get"], :resources => [{}] } ] }
23
+ @key.should_not be_valid
24
+ end
25
+
26
+ it "should not be valid if we have a datastream_id with no feed_id in a resource" do
27
+ @key.attributes = { :user => "bob", :permissions => [ { :access_methods => ["get"], :resources => [{:datastream_id => "0"}] } ] }
28
+ @key.should_not be_valid
29
+ end
30
+
31
+ it "should always return a boolean from the permission private_access? attribute, even if nil" do
32
+ @key.private_access.should be_nil
33
+ @key.private_access?.should be_false
34
+ @key.private_access = true
35
+ @key.private_access?.should be_true
36
+ end
37
+
38
+ it "should not be valid if a permission object with no methods is added" do
39
+ @key.attributes = { :user => "bob", :permissions => [ { :label => "label" } ] }
40
+ @key.should_not be_valid
41
+ @key.errors[:permissions_access_methods].should include("can't be blank")
42
+ end
43
+
44
+ it "should return the key as the id if no id attribute is specified" do
45
+ hash = key_as_(:hash)
46
+ hash.delete("id")
47
+ @key.attributes = hash
48
+ @key.id.should == "abcdefghasdfaoisdj109usasdf0a9sf"
49
+ end
50
+ end
51
+
52
+ describe "#initialize" do
53
+ it "should create a blank slate when passed no arguments" do
54
+ key = Cosm::Key.new
55
+ Cosm::Key::ALLOWED_KEYS.each do |attr|
56
+ key.attributes[attr.to_sym].should be_nil
57
+ end
58
+ end
59
+
60
+ it "should accept xml" do
61
+ key = Cosm::Key.new(key_as_(:xml))
62
+ key.permissions.first.access_methods.should == ["get", "put", "post", "delete"]
63
+ end
64
+
65
+ it "should accept json" do
66
+ key = Cosm::Key.new(key_as_(:json))
67
+ key.permissions.first.access_methods.should == ["get", "put", "post", "delete"]
68
+ end
69
+
70
+ it "should accept a hash of attributes" do
71
+ key = Cosm::Key.new(key_as_(:hash))
72
+ key.permissions.first.access_methods.should == ["get", "put", "post", "delete"]
73
+ end
74
+ end
75
+
76
+ describe "#attributes" do
77
+ it "should return a hash of key properties" do
78
+ attrs = {}
79
+ Cosm::Key::ALLOWED_KEYS.each do |key|
80
+ attrs[key] = "key #{rand(1000)}"
81
+ end
82
+ attrs["permissions"] = [Cosm::Permission.new(:permissions => [:get])]
83
+ key = Cosm::Key.new(attrs)
84
+
85
+ key.attributes.should == attrs
86
+ end
87
+
88
+ it "should not return nil values" do
89
+ attrs = {}
90
+ Cosm::Key::ALLOWED_KEYS.each do |key|
91
+ attrs[key] = "key #{rand(1000)}"
92
+ end
93
+ attrs["notified_at"] = nil
94
+ key = Cosm::Key.new(attrs)
95
+
96
+ key.attributes.should_not include("notified_at")
97
+ end
98
+ end
99
+
100
+ describe "#attributes=" do
101
+ it "should accept and save a hash of properties" do
102
+ key = Cosm::Key.new({})
103
+
104
+ attrs = {}
105
+ Cosm::Key::ALLOWED_KEYS.each do |attr|
106
+ value = "key #{rand(1000)}"
107
+ attrs[attr] = value
108
+ key.should_receive("#{attr}=").with(value)
109
+ end
110
+ key.attributes=(attrs)
111
+ end
112
+
113
+ it "should accept deep nested attributes for permissions array" do
114
+ key = Cosm::Key.new({})
115
+ key.attributes = { :permissions_attributes => [{:label => "label", :access_methods => [:get, :put], :resources_attributes => [{:feed_id => 123, :datastream_id => "0"}]}] }
116
+ key.permissions.size.should == 1
117
+ key.permissions.first.label.should == "label"
118
+ key.permissions.first.resources.size.should == 1
119
+ key.permissions.first.resources.first.feed_id.should == 123
120
+ end
121
+
122
+ it "should set deep nested attributes using class instances as well (not just hashes of attributes)" do
123
+ resource = Cosm::Resource.new(:feed_id => 123)
124
+ permission = Cosm::Permission.new(:label => "label", :access_methods => [:get], :resources => [resource])
125
+ key = Cosm::Key.new(:permissions => [permission])
126
+ key.permissions.size.should == 1
127
+ key.permissions.first.resources.size.should == 1
128
+ end
129
+ end
130
+
131
+ describe "#as_json" do
132
+ it "should call the json generator" do
133
+ options = {:include_blanks => true}
134
+ key = Cosm::Key.new
135
+ key.should_receive(:generate_json).with(options).and_return({"permissions" => [:get, :put]})
136
+ key.as_json(options).should == {"permissions" => [:get, :put]}
137
+ end
138
+
139
+ it "should accept *very* nil options" do
140
+ key = Cosm::Key.new
141
+ key.should_receive(:generate_json).with({}).and_return({"permissions" => [:get, :put]})
142
+ key.as_json(nil).should == {"permissions" => [:get, :put]}
143
+ end
144
+
145
+ it "should return iso8601 formatted expires_at string if present" do
146
+ time = Time.now
147
+ key = Cosm::Key.new(:expires_at => time)
148
+ key.as_json[:key][:expires_at].should == time.iso8601(6)
149
+ end
150
+ end
151
+
152
+ describe "#to_json" do
153
+ before(:each) do
154
+ @time = Time.now
155
+ @key_hash = { "label" => "label", :expires_at => @time, "permissions" => [{"permissions" => [:get, :put, :post], :resources => [{:feed_id => 504, :datastream_id => "0"}]}] }
156
+ end
157
+
158
+ it "should call #as_json" do
159
+ key = Cosm::Key.new(@key_hash)
160
+ key.should_receive(:as_json).with(nil)
161
+ key.to_json
162
+ end
163
+
164
+ it "should pass options through to #as_json" do
165
+ key = Cosm::Key.new(@key_hash)
166
+ key.should_receive(:as_json).with({:crazy => "options"})
167
+ key.to_json({:crazy => "options"})
168
+ end
169
+
170
+ it "should pass the output of #as_json to yajl" do
171
+ key = Cosm::Key.new(@key_hash)
172
+ key.should_receive(:as_json).and_return({:awesome => "hash"})
173
+ ::JSON.should_receive(:generate).with({:awesome => "hash"})
174
+ key.to_json
175
+ end
176
+ end
177
+
178
+ end
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+
3
+ describe "default datastream csv parser" do
4
+ describe "csv" do
5
+ it "should convert Pachube CSV into attributes hash" do
6
+ csv = datastream_as_(:csv)
7
+ datastream = Cosm::Datastream.new(csv)
8
+ datastream.should fully_represent_datastream(:csv, csv)
9
+ end
10
+ end
11
+ end
12
+
@@ -0,0 +1,35 @@
1
+ require 'spec_helper'
2
+
3
+ describe "default feed csv parser" do
4
+ describe "csv" do
5
+ it "should convert Pachube CSV v2 into attributes hash" do
6
+ csv = feed_as_(:csv, :version => 'v2')
7
+ feed = Cosm::Feed.new(csv)
8
+ feed.should fully_represent_feed(:csv_v2, csv)
9
+ end
10
+
11
+ it "should convert Pachube CSV v1 into attributes hash" do
12
+ csv = feed_as_(:csv, :version => 'v1')
13
+ feed = Cosm::Feed.new(csv)
14
+ feed.should fully_represent_feed(:csv_v1, csv)
15
+ end
16
+
17
+ it "should raise an exception if Pachube CSV cannot be detected" do
18
+ csv = feed_as_(:csv, :version => 'unknown')
19
+ lambda {Cosm::Feed.new(csv)}.should raise_exception(Cosm::Parsers::CSV::UnknownVersionError)
20
+ end
21
+
22
+ it "should accept manually determining csv version to be v2" do
23
+ csv = feed_as_(:csv, :version => 'unknown')
24
+ feed = Cosm::Feed.new(csv, :v2)
25
+ feed.should fully_represent_feed(:csv_v2, csv)
26
+ end
27
+
28
+ it "should accept manually determining csv version to be v1" do
29
+ csv = feed_as_(:csv, :version => 'unknown')
30
+ feed = Cosm::Feed.new(csv, :v1)
31
+ feed.should fully_represent_feed(:csv_v1, csv)
32
+ end
33
+ end
34
+ end
35
+
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ describe "default datapoint json parser" do
4
+ before(:each) do
5
+ @datapoint = Cosm::Datapoint.new(datapoint_as_(:json))
6
+ end
7
+
8
+ it "should convert into attributes hash" do
9
+ @json = datapoint_as_(:json)
10
+ attributes = @datapoint.from_json(@json)
11
+ json = JSON.parse(@json)
12
+ attributes["at"].should == json["at"]
13
+ attributes["value"].should == json["value"]
14
+ end
15
+ end
@@ -0,0 +1,82 @@
1
+ require 'spec_helper'
2
+
3
+ describe "default datastream json parser" do
4
+ before(:each) do
5
+ @datastream = Cosm::Datastream.new(datastream_as_(:json))
6
+ end
7
+
8
+ it "should default to v1 API if no version is sent" do
9
+ @json = datastream_as_(:json, :version => "0.6-alpha", :except => [:version])
10
+ attributes = {}
11
+ lambda {attributes = @datastream.from_json(@json)}.should_not raise_error
12
+ json = JSON.parse(@json)
13
+ attributes["id"].should == json["id"]
14
+ attributes["updated"].should == json["values"].first["recorded_at"]
15
+ attributes["current_value"].should == json["values"].first["value"]
16
+ attributes["max_value"].should == json["values"].first["max_value"]
17
+ attributes["min_value"].should == json["values"].first["min_value"]
18
+ attributes["tags"].should == json["tags"].join(',')
19
+ attributes["unit_type"].should == json["unit"]["type"]
20
+ attributes["unit_label"].should == json["unit"]["label"]
21
+ attributes["unit_symbol"].should == json["unit"]["symbol"]
22
+ end
23
+
24
+ context "1.0.0 (used by API v2)" do
25
+ it "should convert into attributes hash" do
26
+ @json = datastream_as_(:json)
27
+ attributes = @datastream.from_json(@json)
28
+ json = JSON.parse(@json)
29
+ attributes["id"].should == json["id"]
30
+ attributes["updated"].should == json["at"]
31
+ attributes["current_value"].should == json["current_value"]
32
+ attributes["max_value"].should == json["max_value"]
33
+ attributes["min_value"].should == json["min_value"]
34
+ attributes["tags"].should == json["tags"].join(',')
35
+ attributes["unit_type"].should == json["unit"]["type"]
36
+ attributes["unit_label"].should == json["unit"]["label"]
37
+ attributes["unit_symbol"].should == json["unit"]["symbol"]
38
+ at_least_one_datapoint = false
39
+ attributes["datapoints"].each do |point|
40
+ at_least_one_datapoint = true
41
+ dp = json["datapoints"].detect {|dp| dp["at"] == point["at"]}
42
+ point["value"].should == dp["value"]
43
+ point["at"].should == dp["at"]
44
+ end
45
+ at_least_one_datapoint.should be_true
46
+ end
47
+
48
+ it "should handle blank tags" do
49
+ @json = datastream_as_(:json, :except => [:tags])
50
+ lambda {@datastream.from_json(@json)}.should_not raise_error
51
+ end
52
+ end
53
+
54
+ context "0.6-alpha (used by API v1)" do
55
+
56
+ it "should convert into attributes hash" do
57
+ @json = datastream_as_(:json, :version => "0.6-alpha")
58
+ attributes = @datastream.from_json(@json)
59
+ json = JSON.parse(@json)
60
+ attributes["id"].should == json["id"]
61
+ attributes["updated"].should == json["values"].first["recorded_at"]
62
+ attributes["current_value"].should == json["values"].first["value"]
63
+ attributes["max_value"].should == json["values"].first["max_value"]
64
+ attributes["min_value"].should == json["values"].first["min_value"]
65
+ attributes["tags"].should == json["tags"].join(',')
66
+ attributes["unit_type"].should == json["unit"]["type"]
67
+ attributes["unit_label"].should == json["unit"]["label"]
68
+ attributes["unit_symbol"].should == json["unit"]["symbol"]
69
+ end
70
+
71
+ it "should handle blank tags" do
72
+ @json = datastream_as_(:json, :version => "0.6-alpha", :except => [:tags])
73
+ lambda {@datastream.from_json(@json)}.should_not raise_error
74
+ end
75
+
76
+ it "should handle blank values" do
77
+ @json = datastream_as_(:json, :version => "0.6-alpha", :except => [:values])
78
+ lambda {@datastream.from_json(@json)}.should_not raise_error
79
+ end
80
+ end
81
+
82
+ end
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+ describe "default feed json parser" do
4
+ describe "json" do
5
+ it "should convert Pachube JSON 1.0.0 (used by API v2) into attributes hash" do
6
+ json = feed_as_(:json)
7
+ feed = Cosm::Feed.new(json)
8
+ feed.should fully_represent_feed(:json, json)
9
+ end
10
+
11
+ it "should convert Pachube JSON 0.6-alpha (used by API v1) into attributes hash" do
12
+ json = feed_as_(:json, :version => "0.6-alpha")
13
+ feed = Cosm::Feed.new(json)
14
+ feed.should fully_represent_feed(:json, json)
15
+ end
16
+ end
17
+ end
18
+
@@ -0,0 +1,8 @@
1
+ require 'spec_helper'
2
+
3
+ describe "default key json parser" do
4
+ it "should convert into attributes hash" do
5
+ @json = key_as_(:json)
6
+ Cosm::Key.new(@json).should fully_represent_key(:json, @json)
7
+ end
8
+ end
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+
3
+ describe "default search result json parser" do
4
+ describe "json" do
5
+ it "should convert Pachube JSON 1.0.0 (used by API v2) into attributes hash" do
6
+ json = search_result_as_(:json)
7
+ search_result = Cosm::SearchResult.new(json)
8
+ search_result.should fully_represent_search_result(:json, json)
9
+ end
10
+ end
11
+ end
12
+
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+
3
+ describe "default trigger json parser" do
4
+ before(:each) do
5
+ @trigger = Cosm::Trigger.new(trigger_as_(:json))
6
+ end
7
+
8
+ it "should convert into attributes hash" do
9
+ @json = trigger_as_(:json)
10
+ attributes = @trigger.from_json(@json)
11
+ json = JSON.parse(@json)
12
+ Cosm::Trigger::ALLOWED_KEYS.each do |key|
13
+ attributes[key].should == json[key]
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe "default datapoint xml parser" do
4
+ it "should convert into attributes hash" do
5
+ @xml = datapoint_as_(:xml)
6
+ Cosm::Datapoint.new(@xml).should fully_represent_datapoint(:xml, @xml)
7
+ end
8
+
9
+ it "should handle blank at" do
10
+ @xml = datapoint_as_(:xml, :except_node => :at)
11
+ Cosm::Datapoint.new(@xml).should fully_represent_datapoint(:xml, @xml)
12
+ end
13
+
14
+ it "should handle blank value" do
15
+ @xml = datapoint_as_(:xml, :except_node => :value)
16
+ Cosm::Datapoint.new(@xml).should fully_represent_datapoint(:xml, @xml)
17
+ end
18
+ end
19
+
@@ -0,0 +1,63 @@
1
+ require 'spec_helper'
2
+
3
+ describe "default datastream xml parser" do
4
+ context "0.5.1 (used by API v2)" do
5
+ it "should convert into attributes hash" do
6
+ @xml = datastream_as_(:xml)
7
+ Cosm::Datastream.new(@xml).should fully_represent_datastream(:xml, @xml)
8
+ end
9
+
10
+ it "should handle blank tags" do
11
+ @xml = datastream_as_(:xml, :except_node => :tag)
12
+ Cosm::Datastream.new(@xml).should fully_represent_datastream(:xml, @xml)
13
+ end
14
+
15
+ it "should handle blank units" do
16
+ @xml = datastream_as_(:xml, :except_node => :unit)
17
+ Cosm::Datastream.new(@xml).should fully_represent_datastream(:xml, @xml)
18
+ end
19
+
20
+ it "should handle missing unit attributes" do
21
+ @xml = datastream_as_(:xml, :except_node => :unit_attributes)
22
+ Cosm::Datastream.new(@xml).should fully_represent_datastream(:xml, @xml)
23
+ end
24
+
25
+ it "should handle missing timestamps" do
26
+ @xml = datastream_as_(:xml, :except_node => :timestamps)
27
+ Cosm::Datastream.new(@xml).should fully_represent_datastream(:xml, @xml)
28
+ end
29
+ end
30
+
31
+ context "5 (used by API v1)" do
32
+ it "should convert into attributes hash" do
33
+ @xml = datastream_as_(:xml, :version => "5")
34
+ Cosm::Datastream.new(@xml).should fully_represent_datastream(:xml, @xml)
35
+ end
36
+
37
+ it "should handle blank tags" do
38
+ @xml = datastream_as_(:xml, :version => "5", :except_node => :tag)
39
+ Cosm::Datastream.new(@xml).should fully_represent_datastream(:xml, @xml)
40
+ end
41
+
42
+ it "should handle blank units" do
43
+ @xml = datastream_as_(:xml, :version => "5", :except_node => :unit)
44
+ Cosm::Datastream.new(@xml).should fully_represent_datastream(:xml, @xml)
45
+ end
46
+
47
+ it "should handle missing unit attributes" do
48
+ @xml = datastream_as_(:xml, :version => "5", :except_node => :unit_attributes)
49
+ Cosm::Datastream.new(@xml).should fully_represent_datastream(:xml, @xml)
50
+ end
51
+
52
+ it "should handle missing value attributes" do
53
+ @xml = datastream_as_(:xml, :version => "5", :except_node => :value_attributes)
54
+ Cosm::Datastream.new(@xml).should fully_represent_datastream(:xml, @xml)
55
+ end
56
+
57
+ it "should handle missing timestamps" do
58
+ @xml = datastream_as_(:xml, :version => "5", :except_node => :timestamps)
59
+ Cosm::Datastream.new(@xml).should fully_represent_datastream(:xml, @xml)
60
+ end
61
+ end
62
+ end
63
+
@@ -0,0 +1,65 @@
1
+ require 'spec_helper'
2
+
3
+ describe "default feed xml parser" do
4
+ context "0.5.1 (used by API v2)" do
5
+ it "should convert into attributes hash" do
6
+ @xml = feed_as_(:xml)
7
+ Cosm::Feed.new(@xml).should fully_represent_feed(:xml, @xml)
8
+ end
9
+
10
+ it "should handle blank location" do
11
+ @xml = feed_as_(:xml, :except_node => :location)
12
+ Cosm::Feed.new(@xml).should fully_represent_feed(:xml, @xml)
13
+ end
14
+
15
+ it "should handle blank units" do
16
+ @xml = feed_as_(:xml, :except_node => :unit)
17
+ Cosm::Feed.new(@xml).should fully_represent_feed(:xml, @xml)
18
+ end
19
+
20
+ it "should handle missing unit attributes" do
21
+ @xml = feed_as_(:xml, :except_node => :unit_attributes)
22
+ Cosm::Feed.new(@xml).should fully_represent_feed(:xml, @xml)
23
+ end
24
+
25
+ it "should handle blank tags" do
26
+ @xml = feed_as_(:xml, :except_node => :tag)
27
+ Cosm::Feed.new(@xml).should fully_represent_feed(:xml, @xml)
28
+ end
29
+
30
+ end
31
+
32
+ context "5 (used by API v1)" do
33
+ it "should convert into attributes hash" do
34
+ @xml = feed_as_(:xml, :version => "5")
35
+ Cosm::Feed.new(@xml).should fully_represent_feed(:xml, @xml)
36
+ end
37
+
38
+ it "should handle blank tags" do
39
+ @xml = feed_as_(:xml, :version => "5", :except_node => :tag)
40
+ Cosm::Feed.new(@xml).should fully_represent_feed(:xml, @xml)
41
+ end
42
+
43
+ it "should handle blank location" do
44
+ @xml = feed_as_(:xml, :version => "5", :except_node => :location)
45
+ Cosm::Feed.new(@xml).should fully_represent_feed(:xml, @xml)
46
+ end
47
+
48
+ it "should handle blank units" do
49
+ @xml = feed_as_(:xml, :version => "5", :except_node => :unit)
50
+ Cosm::Feed.new(@xml).should fully_represent_feed(:xml, @xml)
51
+ end
52
+
53
+ it "should handle missing unit attributes" do
54
+ @xml = feed_as_(:xml, :version => "5", :except_node => :unit_attributes)
55
+ Cosm::Feed.new(@xml).should fully_represent_feed(:xml, @xml)
56
+ end
57
+
58
+ it "should handle missing value attributes" do
59
+ @xml = feed_as_(:xml, :version => "5", :except_node => :value_attributes)
60
+ Cosm::Feed.new(@xml).should fully_represent_feed(:xml, @xml)
61
+ end
62
+
63
+ end
64
+ end
65
+
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+
3
+ describe "default key xml parser" do
4
+ it "should convert into attributes hash" do
5
+ @xml = key_as_(:xml)
6
+ Cosm::Key.new(@xml).should fully_represent_key(:xml, @xml)
7
+ end
8
+
9
+ Cosm::Key::ALLOWED_KEYS.each do |key|
10
+ it "should handle blank '#{key}'" do
11
+ @xml = key_as_(:xml, :except_node => :referer)
12
+ Cosm::Key.new(@xml).should fully_represent_key(:xml, @xml)
13
+ end
14
+ end
15
+ end
16
+
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+
3
+ describe "default trigger xml parser" do
4
+ it "should convert into attributes hash" do
5
+ @xml = trigger_as_(:xml)
6
+ Cosm::Trigger.new(@xml).should fully_represent_trigger(:xml, @xml)
7
+ end
8
+
9
+ Cosm::Trigger::ALLOWED_KEYS.each do |key|
10
+ it "should handle blank '#{key}'" do
11
+ @xml = trigger_as_(:xml, :except_node => :at)
12
+ Cosm::Trigger.new(@xml).should fully_represent_trigger(:xml, @xml)
13
+ end
14
+ end
15
+ end
16
+