pulse-meter 0.4.9 → 0.4.11

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 (192) hide show
  1. data/Rakefile +1 -48
  2. data/lib/pulse-meter.rb +1 -68
  3. data/lib/pulse-meter/visualizer.rb +1 -40
  4. data/pulse-meter.gemspec +4 -26
  5. metadata +10 -558
  6. data/Procfile +0 -3
  7. data/bin/pulse +0 -6
  8. data/examples/basic.ru +0 -145
  9. data/examples/basic_sensor_data.rb +0 -96
  10. data/examples/udp_benchmark.rb +0 -29
  11. data/lib/cmd.rb +0 -171
  12. data/lib/pulse-meter/command_aggregator/async.rb +0 -83
  13. data/lib/pulse-meter/command_aggregator/sync.rb +0 -18
  14. data/lib/pulse-meter/command_aggregator/udp.rb +0 -48
  15. data/lib/pulse-meter/extensions/enumerable.rb +0 -24
  16. data/lib/pulse-meter/mixins/cmd.rb +0 -46
  17. data/lib/pulse-meter/mixins/dumper.rb +0 -87
  18. data/lib/pulse-meter/mixins/utils.rb +0 -155
  19. data/lib/pulse-meter/observer.rb +0 -120
  20. data/lib/pulse-meter/observer/extended.rb +0 -34
  21. data/lib/pulse-meter/sensor.rb +0 -61
  22. data/lib/pulse-meter/sensor/base.rb +0 -88
  23. data/lib/pulse-meter/sensor/configuration.rb +0 -106
  24. data/lib/pulse-meter/sensor/counter.rb +0 -39
  25. data/lib/pulse-meter/sensor/hashed_counter.rb +0 -36
  26. data/lib/pulse-meter/sensor/hashed_indicator.rb +0 -24
  27. data/lib/pulse-meter/sensor/indicator.rb +0 -35
  28. data/lib/pulse-meter/sensor/multi.rb +0 -97
  29. data/lib/pulse-meter/sensor/timeline.rb +0 -236
  30. data/lib/pulse-meter/sensor/timeline_reduce.rb +0 -68
  31. data/lib/pulse-meter/sensor/timelined/average.rb +0 -32
  32. data/lib/pulse-meter/sensor/timelined/counter.rb +0 -23
  33. data/lib/pulse-meter/sensor/timelined/hashed_counter.rb +0 -31
  34. data/lib/pulse-meter/sensor/timelined/hashed_indicator.rb +0 -30
  35. data/lib/pulse-meter/sensor/timelined/indicator.rb +0 -23
  36. data/lib/pulse-meter/sensor/timelined/max.rb +0 -19
  37. data/lib/pulse-meter/sensor/timelined/median.rb +0 -14
  38. data/lib/pulse-meter/sensor/timelined/min.rb +0 -19
  39. data/lib/pulse-meter/sensor/timelined/multi_percentile.rb +0 -34
  40. data/lib/pulse-meter/sensor/timelined/percentile.rb +0 -22
  41. data/lib/pulse-meter/sensor/timelined/uniq_counter.rb +0 -22
  42. data/lib/pulse-meter/sensor/timelined/zset_based.rb +0 -38
  43. data/lib/pulse-meter/sensor/uniq_counter.rb +0 -24
  44. data/lib/pulse-meter/server.rb +0 -0
  45. data/lib/pulse-meter/server/command_line_options.rb +0 -0
  46. data/lib/pulse-meter/server/config_options.rb +0 -0
  47. data/lib/pulse-meter/server/sensors.rb +0 -0
  48. data/lib/pulse-meter/udp_server.rb +0 -45
  49. data/lib/pulse-meter/version.rb +0 -3
  50. data/lib/pulse-meter/visualize/app.rb +0 -78
  51. data/lib/pulse-meter/visualize/base.rb +0 -15
  52. data/lib/pulse-meter/visualize/coffee/application.coffee +0 -40
  53. data/lib/pulse-meter/visualize/coffee/collections/page_info_list.coffee +0 -17
  54. data/lib/pulse-meter/visualize/coffee/collections/sensor_info_list.coffee +0 -4
  55. data/lib/pulse-meter/visualize/coffee/collections/widget_list.coffee +0 -14
  56. data/lib/pulse-meter/visualize/coffee/extensions.coffee +0 -26
  57. data/lib/pulse-meter/visualize/coffee/models/dinamic_widget.coffee +0 -34
  58. data/lib/pulse-meter/visualize/coffee/models/page_info.coffee +0 -2
  59. data/lib/pulse-meter/visualize/coffee/models/sensor_info.coffee +0 -2
  60. data/lib/pulse-meter/visualize/coffee/models/widget.coffee +0 -54
  61. data/lib/pulse-meter/visualize/coffee/presenters/area.coffee +0 -2
  62. data/lib/pulse-meter/visualize/coffee/presenters/gauge.coffee +0 -11
  63. data/lib/pulse-meter/visualize/coffee/presenters/line.coffee +0 -2
  64. data/lib/pulse-meter/visualize/coffee/presenters/pie.coffee +0 -20
  65. data/lib/pulse-meter/visualize/coffee/presenters/series.coffee +0 -44
  66. data/lib/pulse-meter/visualize/coffee/presenters/table.coffee +0 -10
  67. data/lib/pulse-meter/visualize/coffee/presenters/timeline.coffee +0 -13
  68. data/lib/pulse-meter/visualize/coffee/presenters/widget.coffee +0 -65
  69. data/lib/pulse-meter/visualize/coffee/router.coffee +0 -21
  70. data/lib/pulse-meter/visualize/coffee/views/dynamic_chart.coffee +0 -91
  71. data/lib/pulse-meter/visualize/coffee/views/dynamic_widget.coffee +0 -58
  72. data/lib/pulse-meter/visualize/coffee/views/page_title.coffee +0 -17
  73. data/lib/pulse-meter/visualize/coffee/views/page_titles.coffee +0 -15
  74. data/lib/pulse-meter/visualize/coffee/views/sensor_info_list.coffee +0 -19
  75. data/lib/pulse-meter/visualize/coffee/views/widget.coffee +0 -99
  76. data/lib/pulse-meter/visualize/coffee/views/widget_chart.coffee +0 -13
  77. data/lib/pulse-meter/visualize/coffee/views/widget_list.coffee +0 -15
  78. data/lib/pulse-meter/visualize/dsl/base.rb +0 -131
  79. data/lib/pulse-meter/visualize/dsl/errors.rb +0 -40
  80. data/lib/pulse-meter/visualize/dsl/layout.rb +0 -27
  81. data/lib/pulse-meter/visualize/dsl/page.rb +0 -33
  82. data/lib/pulse-meter/visualize/dsl/sensor.rb +0 -20
  83. data/lib/pulse-meter/visualize/dsl/widget.rb +0 -37
  84. data/lib/pulse-meter/visualize/dsl/widgets/area.rb +0 -20
  85. data/lib/pulse-meter/visualize/dsl/widgets/gauge.rb +0 -12
  86. data/lib/pulse-meter/visualize/dsl/widgets/line.rb +0 -21
  87. data/lib/pulse-meter/visualize/dsl/widgets/pie.rb +0 -16
  88. data/lib/pulse-meter/visualize/dsl/widgets/table.rb +0 -19
  89. data/lib/pulse-meter/visualize/layout.rb +0 -79
  90. data/lib/pulse-meter/visualize/page.rb +0 -25
  91. data/lib/pulse-meter/visualize/public/css/application.css +0 -56
  92. data/lib/pulse-meter/visualize/public/css/bootstrap.css +0 -4883
  93. data/lib/pulse-meter/visualize/public/css/bootstrap.min.css +0 -729
  94. data/lib/pulse-meter/visualize/public/css/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
  95. data/lib/pulse-meter/visualize/public/css/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
  96. data/lib/pulse-meter/visualize/public/css/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
  97. data/lib/pulse-meter/visualize/public/css/images/ui-bg_glass_75_dadada_1x400.png +0 -0
  98. data/lib/pulse-meter/visualize/public/css/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
  99. data/lib/pulse-meter/visualize/public/css/images/ui-bg_glass_75_ffffff_1x400.png +0 -0
  100. data/lib/pulse-meter/visualize/public/css/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
  101. data/lib/pulse-meter/visualize/public/css/images/ui-bg_inset-soft_95_fef1ec_1x100.png +0 -0
  102. data/lib/pulse-meter/visualize/public/css/images/ui-icons_222222_256x240.png +0 -0
  103. data/lib/pulse-meter/visualize/public/css/images/ui-icons_2e83ff_256x240.png +0 -0
  104. data/lib/pulse-meter/visualize/public/css/images/ui-icons_454545_256x240.png +0 -0
  105. data/lib/pulse-meter/visualize/public/css/images/ui-icons_888888_256x240.png +0 -0
  106. data/lib/pulse-meter/visualize/public/css/images/ui-icons_cd0a0a_256x240.png +0 -0
  107. data/lib/pulse-meter/visualize/public/css/images/ui-icons_f6cf3b_256x240.png +0 -0
  108. data/lib/pulse-meter/visualize/public/css/jquery-ui-1.8.16.bootstrap.css +0 -1320
  109. data/lib/pulse-meter/visualize/public/favicon.ico +0 -208
  110. data/lib/pulse-meter/visualize/public/img/glyphicons-halflings-white.png +0 -0
  111. data/lib/pulse-meter/visualize/public/img/glyphicons-halflings.png +0 -0
  112. data/lib/pulse-meter/visualize/public/js/application.js +0 -973
  113. data/lib/pulse-meter/visualize/public/js/backbone-min.js +0 -38
  114. data/lib/pulse-meter/visualize/public/js/bootstrap.js +0 -1835
  115. data/lib/pulse-meter/visualize/public/js/jquery-1.7.2.min.js +0 -4
  116. data/lib/pulse-meter/visualize/public/js/jquery-ui-1.8.16.bootstrap.min.js +0 -791
  117. data/lib/pulse-meter/visualize/public/js/jquery-ui-1.8.23.custom.min.js +0 -21
  118. data/lib/pulse-meter/visualize/public/js/jquery-ui-timepicker-addon.js +0 -1687
  119. data/lib/pulse-meter/visualize/public/js/json2.js +0 -487
  120. data/lib/pulse-meter/visualize/public/js/underscore-min.js +0 -32
  121. data/lib/pulse-meter/visualize/sensor.rb +0 -63
  122. data/lib/pulse-meter/visualize/series_extractor.rb +0 -107
  123. data/lib/pulse-meter/visualize/views/main.haml +0 -30
  124. data/lib/pulse-meter/visualize/views/sensors.haml +0 -76
  125. data/lib/pulse-meter/visualize/views/widgets/area.haml +0 -53
  126. data/lib/pulse-meter/visualize/views/widgets/extend_options.haml +0 -11
  127. data/lib/pulse-meter/visualize/views/widgets/gauge.haml +0 -13
  128. data/lib/pulse-meter/visualize/views/widgets/line.haml +0 -54
  129. data/lib/pulse-meter/visualize/views/widgets/pie.haml +0 -13
  130. data/lib/pulse-meter/visualize/views/widgets/table.haml +0 -45
  131. data/lib/pulse-meter/visualize/widget.rb +0 -38
  132. data/lib/pulse-meter/visualize/widgets/gauge.rb +0 -47
  133. data/lib/pulse-meter/visualize/widgets/pie.rb +0 -36
  134. data/lib/pulse-meter/visualize/widgets/timeline.rb +0 -114
  135. data/spec/pulse_meter/command_aggregator/async_spec.rb +0 -53
  136. data/spec/pulse_meter/command_aggregator/sync_spec.rb +0 -25
  137. data/spec/pulse_meter/command_aggregator/udp_spec.rb +0 -45
  138. data/spec/pulse_meter/extensions/enumerable_spec.rb +0 -58
  139. data/spec/pulse_meter/mixins/cmd_spec.rb +0 -117
  140. data/spec/pulse_meter/mixins/dumper_spec.rb +0 -162
  141. data/spec/pulse_meter/mixins/utils_spec.rb +0 -212
  142. data/spec/pulse_meter/observer/extended_spec.rb +0 -92
  143. data/spec/pulse_meter/observer_spec.rb +0 -207
  144. data/spec/pulse_meter/sensor/base_spec.rb +0 -106
  145. data/spec/pulse_meter/sensor/configuration_spec.rb +0 -103
  146. data/spec/pulse_meter/sensor/counter_spec.rb +0 -54
  147. data/spec/pulse_meter/sensor/hashed_counter_spec.rb +0 -43
  148. data/spec/pulse_meter/sensor/hashed_indicator_spec.rb +0 -39
  149. data/spec/pulse_meter/sensor/indicator_spec.rb +0 -43
  150. data/spec/pulse_meter/sensor/multi_spec.rb +0 -137
  151. data/spec/pulse_meter/sensor/timeline_spec.rb +0 -88
  152. data/spec/pulse_meter/sensor/timelined/average_spec.rb +0 -6
  153. data/spec/pulse_meter/sensor/timelined/counter_spec.rb +0 -6
  154. data/spec/pulse_meter/sensor/timelined/hashed_counter_spec.rb +0 -8
  155. data/spec/pulse_meter/sensor/timelined/hashed_indicator_spec.rb +0 -8
  156. data/spec/pulse_meter/sensor/timelined/indicator_spec.rb +0 -6
  157. data/spec/pulse_meter/sensor/timelined/max_spec.rb +0 -7
  158. data/spec/pulse_meter/sensor/timelined/median_spec.rb +0 -7
  159. data/spec/pulse_meter/sensor/timelined/min_spec.rb +0 -7
  160. data/spec/pulse_meter/sensor/timelined/multi_percentile_spec.rb +0 -21
  161. data/spec/pulse_meter/sensor/timelined/percentile_spec.rb +0 -17
  162. data/spec/pulse_meter/sensor/timelined/uniq_counter_spec.rb +0 -9
  163. data/spec/pulse_meter/sensor/uniq_counter_spec.rb +0 -28
  164. data/spec/pulse_meter/udp_server_spec.rb +0 -36
  165. data/spec/pulse_meter/visualize/app_spec.rb +0 -27
  166. data/spec/pulse_meter/visualize/dsl/layout_spec.rb +0 -64
  167. data/spec/pulse_meter/visualize/dsl/page_spec.rb +0 -62
  168. data/spec/pulse_meter/visualize/dsl/sensor_spec.rb +0 -30
  169. data/spec/pulse_meter/visualize/dsl/widget_spec.rb +0 -6
  170. data/spec/pulse_meter/visualize/dsl/widgets/area_spec.rb +0 -44
  171. data/spec/pulse_meter/visualize/dsl/widgets/gauge_spec.rb +0 -22
  172. data/spec/pulse_meter/visualize/dsl/widgets/line_spec.rb +0 -44
  173. data/spec/pulse_meter/visualize/dsl/widgets/pie_spec.rb +0 -35
  174. data/spec/pulse_meter/visualize/dsl/widgets/table_spec.rb +0 -36
  175. data/spec/pulse_meter/visualize/layout_spec.rb +0 -54
  176. data/spec/pulse_meter/visualize/page_spec.rb +0 -153
  177. data/spec/pulse_meter/visualize/sensor_spec.rb +0 -120
  178. data/spec/pulse_meter/visualize/series_extractor_spec.rb +0 -80
  179. data/spec/pulse_meter/visualize/widgets/area_spec.rb +0 -6
  180. data/spec/pulse_meter/visualize/widgets/gauge_spec.rb +0 -63
  181. data/spec/pulse_meter/visualize/widgets/line_spec.rb +0 -6
  182. data/spec/pulse_meter/visualize/widgets/pie_spec.rb +0 -73
  183. data/spec/pulse_meter/visualize/widgets/table_spec.rb +0 -6
  184. data/spec/pulse_meter/visualizer_spec.rb +0 -42
  185. data/spec/pulse_meter_spec.rb +0 -73
  186. data/spec/shared_examples/dsl_widget.rb +0 -106
  187. data/spec/shared_examples/timeline_sensor.rb +0 -439
  188. data/spec/shared_examples/timelined_subclass.rb +0 -23
  189. data/spec/shared_examples/widget.rb +0 -97
  190. data/spec/spec_helper.rb +0 -40
  191. data/spec/support/matchers.rb +0 -34
  192. data/spec/support/observered.rb +0 -40
@@ -1,117 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe PulseMeter::Mixins::Cmd do
4
- class CmdDummy
5
- include PulseMeter::Mixins::Cmd
6
-
7
- def initialize(redis)
8
- @redis = redis
9
- end
10
-
11
- def create_redis
12
- @redis
13
- end
14
- end
15
-
16
- let(:redis){ MockRedis.new }
17
- let(:dummy){ CmdDummy.new(redis) }
18
- before{ PulseMeter.redis = redis }
19
-
20
- describe "#fail!" do
21
- it "prints given message and exits" do
22
- STDOUT.should_receive(:puts).with(:msg)
23
- lambda {dummy.fail!(:msg)}.should raise_error(SystemExit)
24
- end
25
- end
26
-
27
- describe '#with_redis' do
28
- it "initializes redies and yields a block" do
29
- PulseMeter.redis = nil
30
- dummy.with_redis do
31
- PulseMeter.redis.should_not be_nil
32
- end
33
- end
34
- end
35
-
36
- describe "#with_safe_restore_of" do
37
- it "restores sensor by name and passes it to block" do
38
- sensor = PulseMeter::Sensor::Counter.new(:foo)
39
- dummy.with_safe_restore_of(:foo) do |s|
40
- s.should be_instance_of(sensor.class)
41
- end
42
- end
43
-
44
- it "prints error and exits if sensor cannot be restored" do
45
- STDOUT.should_receive(:puts).with("Sensor nonexistant is unknown or cannot be restored")
46
- lambda {dummy.with_safe_restore_of(:nonexistant) {|s| s}}.should raise_error(SystemExit)
47
- end
48
- end
49
-
50
- describe "#all_sensors" do
51
- it "is just an alias to PulseMeter::Sensor::Timeline.list_objects" do
52
- PulseMeter::Sensor::Timeline.should_receive(:list_objects)
53
- dummy.all_sensors
54
- end
55
- end
56
-
57
- describe "#all_sensors_table" do
58
- before {PulseMeter.redis.flushall}
59
- let(:init_values){ {:ttl => 1, :raw_data_ttl => 2, :interval => 3, :reduce_delay => 4} }
60
- let!(:s1) {PulseMeter::Sensor::Counter.new(:s1)}
61
- let!(:s2) {PulseMeter::Sensor::Timelined::Counter.new(:s2, init_values)}
62
- let!(:table) {dummy.all_sensors_table}
63
- let!(:csv) {dummy.all_sensors_table(:csv)}
64
- let!(:parsed_csv) {CSV.parse(csv, col_sep: ";")}
65
-
66
- def rows(format)
67
- if "csv" == format.to_s
68
- parsed_csv
69
- else
70
- table.rows.map do |row|
71
- row.cells.map(&:to_s).map(&:strip)
72
- end
73
- end
74
- end
75
-
76
- def sensor_row(name, format)
77
- rows(format).select {|row| row[0] == name}.first
78
- end
79
-
80
- [:csv, :table].each do |format|
81
- context "when format is #{format}" do
82
-
83
- if "csv" == format.to_s
84
- it "returns csv as string" do
85
- csv.should be_instance_of(String)
86
- end
87
- else
88
- it "returns Terminal::Table instance" do
89
- table.should be_instance_of(Terminal::Table)
90
- end
91
- end
92
-
93
- it "has title row" do
94
- rows(format)[0].should == ["Name", "Class", "ttl", "raw data ttl", "interval", "reduce delay"]
95
- end
96
-
97
- it "has one row for each sensor (and a title)" do
98
- rows(format).count.should == 3
99
- end
100
-
101
- it "can display timelined sensors" do
102
- sensor_row("s2", format).should == [
103
- s2.name, s2.class, s2.ttl, s2.raw_data_ttl, s2.interval, s2.reduce_delay
104
- ].map(&:to_s)
105
- end
106
-
107
- it "can display static sensors" do
108
- sensor_row("s1", format).should == [
109
- s1.name, s1.class, "", "", "", ""
110
- ].map(&:to_s)
111
- end
112
-
113
- end
114
- end
115
- end
116
-
117
- end
@@ -1,162 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe PulseMeter::Mixins::Dumper do
4
- class Base
5
- include PulseMeter::Mixins::Dumper
6
- end
7
-
8
- class Bad < Base; end
9
-
10
- class Good < Base
11
- attr_accessor :some_value
12
- attr_accessor :name
13
-
14
- def redis; PulseMeter.redis; end
15
-
16
- def initialize(name)
17
- @name = name.to_s
18
- @some_value = name
19
- end
20
- end
21
-
22
- class GoodButAnother < Good; end
23
-
24
- let(:bad_obj){ Bad.new }
25
- let(:good_obj){ Good.new(:foo) }
26
- let(:another_good_obj){ Good.new(:bar) }
27
- let(:good_obj_of_another_type){ GoodButAnother.new(:quux) }
28
- let(:redis){ PulseMeter.redis }
29
-
30
- describe '#dump' do
31
- context "when class violates dump contract" do
32
- context "when it has no name attribute" do
33
- it "should raise exception" do
34
- def bad_obj.redis; PulseMeter.redis; end
35
- expect{ bad_obj.dump! }.to raise_exception(PulseMeter::DumpError)
36
- end
37
- end
38
-
39
- context "when it has no redis attribute" do
40
- it "should raise exception" do
41
- def bad_obj.name; :foo; end
42
- expect{ bad_obj.dump! }.to raise_exception(PulseMeter::DumpError)
43
- end
44
- end
45
-
46
- context "when redis is not avalable" do
47
- it "should raise exception" do
48
- def bad_obj.name; :foo; end
49
- def bad_obj.redis; nil; end
50
- expect{ bad_obj.dump! }.to raise_exception(PulseMeter::DumpError)
51
- end
52
- end
53
- end
54
-
55
- context "when class follows dump contract" do
56
- it "should not raise dump exception" do
57
- expect {good_obj.dump!}.not_to raise_exception(PulseMeter::DumpError)
58
- end
59
-
60
- it "should save dump to redis" do
61
- expect {good_obj.dump!}.to change {redis.hlen(Good::DUMP_REDIS_KEY)}.by(1)
62
- end
63
- end
64
-
65
- context "when dump is safe" do
66
- it "should not overwrite stored objects of the same type" do
67
- good_obj.some_value = 123
68
- good_obj.dump!
69
- good_obj.some_value = 321
70
- good_obj.dump!
71
- Base.restore(good_obj.name).some_value.should == 123
72
- end
73
-
74
- it "should raise DumpConflictError exception if sensor with the same name but different type already exists" do
75
- good_obj.name = "duplicate_name"
76
- good_obj_of_another_type.name = "duplicate_name"
77
- good_obj.dump!
78
- expect{good_obj_of_another_type.dump!}.to raise_exception(PulseMeter::DumpConflictError)
79
- end
80
- end
81
- end
82
-
83
- describe ".restore" do
84
- context "when object has never been dumped" do
85
- it "should raise exception" do
86
- expect{ Base.restore(:nonexistant) }.to raise_exception(PulseMeter::RestoreError)
87
- end
88
- end
89
-
90
- context "when object was dumped" do
91
- before do
92
- good_obj.dump!
93
- end
94
-
95
- it "should keep object class" do
96
- Base.restore(good_obj.name).should be_instance_of(good_obj.class)
97
- end
98
-
99
- it "should restore object data" do
100
- restored = Base.restore(good_obj.name)
101
- restored.some_value.should == good_obj.some_value
102
- end
103
-
104
- it "should restore last dumped object" do
105
- good_obj.some_value = :bar
106
- good_obj.dump!(false)
107
- restored = Base.restore(good_obj.name)
108
- restored.some_value.should == :bar
109
- end
110
- end
111
- end
112
-
113
- describe ".list_names" do
114
- context "when redis is not available" do
115
- before do
116
- PulseMeter.stub(:redis).and_return(nil)
117
- end
118
-
119
- it "should raise exception" do
120
- expect {Base.list_names}.to raise_exception(PulseMeter::RestoreError)
121
- end
122
- end
123
-
124
- context "when redis if fine" do
125
- it "should return empty list if nothing is registered" do
126
- Base.list_names.should == []
127
- end
128
-
129
- it "should return list of registered objects" do
130
- good_obj.dump!(false)
131
- another_good_obj.dump!(false)
132
- Base.list_names.should =~ [good_obj.name, another_good_obj.name]
133
- end
134
- end
135
- end
136
-
137
- describe ".list_objects" do
138
- before do
139
- good_obj.dump!
140
- another_good_obj.dump!
141
- end
142
-
143
- it "should return restored objects" do
144
- objects = Base.list_objects
145
- objects.map(&:name).should =~ [good_obj.name, another_good_obj.name]
146
- end
147
-
148
- it "should skip unrestorable objects" do
149
- Base.stub(:list_names).and_return([good_obj.name, "scoundrel", another_good_obj.name])
150
- objects = Base.list_objects
151
- objects.map(&:name).should =~ [good_obj.name, another_good_obj.name]
152
- end
153
- end
154
-
155
- describe "#cleanup_dump" do
156
- it "should remove data from redis" do
157
- good_obj.dump!
158
- another_good_obj.dump!
159
- expect {good_obj.cleanup_dump}.to change{good_obj.class.list_names.count}.by(-1)
160
- end
161
- end
162
- end
@@ -1,212 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe PulseMeter::Mixins::Utils do
4
- class Dummy
5
- include PulseMeter::Mixins::Utils
6
- end
7
-
8
- let(:dummy){ Dummy.new }
9
-
10
- describe '#constantize' do
11
- context "when argument is a string with a valid class name" do
12
- it "should return class" do
13
- dummy.constantize("PulseMeter::Mixins::Utils").should == PulseMeter::Mixins::Utils
14
- end
15
- end
16
- context "when argument is a string with invalid class name" do
17
- it "should return nil" do
18
- dummy.constantize("Pumpkin::Eater").should be_nil
19
- end
20
- end
21
- context "when argument is not a string" do
22
- it "should return nil" do
23
- dummy.constantize({}).should be_nil
24
- end
25
- end
26
- end
27
-
28
- describe "#assert_positive_integer!" do
29
- it "should extract integer value from hash by passed key" do
30
- dummy.assert_positive_integer!({:val => 4}, :val).should == 4
31
- end
32
-
33
- context "when no default value given" do
34
- context "when the value by the passed key is not integer" do
35
- it "should convert non-integers to integers" do
36
- dummy.assert_positive_integer!({:val => 4.4}, :val).should == 4
37
- end
38
-
39
- it "should change the original value to the obtained integer" do
40
- h = {:val => 4.4}
41
- dummy.assert_positive_integer!(h, :val).should == 4
42
- h[:val].should == 4
43
- end
44
-
45
- it "should raise exception if the original value cannot be converted to integer"do
46
- expect{ dummy.assert_positive_integer!({:val => :bad_int}, :val) }.to raise_exception(ArgumentError)
47
- end
48
- end
49
-
50
- it "should raise exception if the value is not positive" do
51
- expect{ dummy.assert_positive_integer!({:val => -1}, :val) }.to raise_exception(ArgumentError)
52
- end
53
-
54
- it "should raise exception if the value is not defined" do
55
- expect{ dummy.assert_positive_integer!({}, :val) }.to raise_exception(ArgumentError)
56
- end
57
- end
58
-
59
- context "when default value given" do
60
- it "should prefer value from options to default" do
61
- dummy.assert_positive_integer!({:val => 4}, :val, 22).should == 4
62
- end
63
-
64
- it "should use default value when there is no one in options" do
65
- dummy.assert_positive_integer!({}, :val, 22).should == 22
66
- end
67
-
68
- it "should check default value if it is to be used" do
69
- expect{dummy.assert_positive_integer!({}, :val, :bad)}.to raise_exception(ArgumentError)
70
- expect{dummy.assert_positive_integer!({}, :val, -1)}.to raise_exception(ArgumentError)
71
- end
72
- end
73
- end
74
-
75
- describe "#assert_array!" do
76
- it "should extract value from hash by passed key" do
77
- dummy.assert_array!({:val => [:foo]}, :val).should == [:foo]
78
- end
79
-
80
- context "when no default value given" do
81
- it "should raise exception if th value is not an Array" do
82
- expect{ dummy.assert_array!({:val => :bad}, :val) }.to raise_exception(ArgumentError)
83
- end
84
-
85
- it "should raise exception if the value is not defined" do
86
- expect{ dummy.assert_array!({}, :val) }.to raise_exception(ArgumentError)
87
- end
88
- end
89
-
90
- context "when default value given" do
91
- it "should prefer value from options to default" do
92
- dummy.assert_array!({:val => [:foo]}, :val, []).should == [:foo]
93
- end
94
-
95
- it "should use default value when there is no one in options" do
96
- dummy.assert_array!({}, :val, []).should == []
97
- end
98
-
99
- it "should check default value if it is to be used" do
100
- expect{dummy.assert_array!({}, :val, :bad)}.to raise_exception(ArgumentError)
101
- end
102
- end
103
- end
104
-
105
- describe "#assert_ranged_float!" do
106
-
107
- it "should extract float value from hash by passed key" do
108
- dummy.assert_ranged_float!({:val => 4}, :val, 0, 100).should be_generally_equal(4)
109
- end
110
-
111
- context "when the value by the passed key is not float" do
112
- it "should convert non-floats to floats" do
113
- dummy.assert_ranged_float!({:val => "4.0000"}, :val, 0, 100).should be_generally_equal(4)
114
- end
115
-
116
- it "should change the original value to the obtained float" do
117
- h = {:val => "4.000"}
118
- dummy.assert_ranged_float!(h, :val, 0, 100).should be_generally_equal(4)
119
- h[:val].should be_generally_equal(4)
120
- end
121
-
122
- it "should raise exception if the original value cannot be converted to float" do
123
- expect{ dummy.assert_ranged_float!({:val => :bad_float}, :val, 0, 100) }.to raise_exception(ArgumentError)
124
- end
125
- end
126
-
127
- it "should raise exception if the value is not within range" do
128
- expect{ dummy.assert_ranged_float!({:val => -0.1}, :val, 0, 100) }.to raise_exception(ArgumentError)
129
- expect{ dummy.assert_ranged_float!({:val => 100.1}, :val, 0, 100) }.to raise_exception(ArgumentError)
130
- end
131
-
132
- it "should raise exception if the value is not defined" do
133
- expect{ dummy.assert_ranged_float!({}, :val) }.to raise_exception(ArgumentError)
134
- end
135
- end
136
-
137
- describe "#uniqid" do
138
- it "should return uniq strings" do
139
- uniq_values = (1..1000).map{|_| dummy.uniqid}
140
- uniq_values.uniq.count.should == uniq_values.count
141
- end
142
- end
143
-
144
- describe "#titleize" do
145
- it "should convert identificator to title" do
146
- dummy.titleize("aaa_bbb").should == 'Aaa Bbb'
147
- dummy.titleize(:aaa_bbb).should == 'Aaa Bbb'
148
- dummy.titleize("aaa bbb").should == 'Aaa Bbb'
149
- end
150
- end
151
-
152
- describe "#camelize" do
153
- it "should camelize string" do
154
- dummy.camelize("aa_bb_cc").should == "aaBbCc"
155
- dummy.camelize("aa_bb_cc", true).should == "AaBbCc"
156
- end
157
- end
158
-
159
- describe "#underscore" do
160
- it "should underscore string" do
161
- dummy.underscore("aaBbCc").should == "aa_bb_cc"
162
- dummy.underscore("AaBbCc").should == "aa_bb_cc"
163
- dummy.underscore("aaBb::Cc").should == "aa_bb/cc"
164
- end
165
- end
166
-
167
- describe "#camelize_keys" do
168
- it "should deeply camelize keys in hashes" do
169
- dummy.camelize_keys({ :aa_bb_cc => [ { :dd_ee => 123 }, 456 ] }).should =={ 'aaBbCc' => [ { 'ddEe' => 123 }, 456 ] }
170
- end
171
- end
172
-
173
- describe "#symbolize_keys" do
174
- it "should convert symbolizable keys to symbols" do
175
- dummy.symbolize_keys({"a" => 5, 6 => 7}).should == {a: 5, 6 => 7}
176
- end
177
- end
178
-
179
- describe "#subsets_of" do
180
- it "returns all subsets of given array" do
181
- dummy.subsets_of([1, 2]).sort.should == [[], [1], [2], [1, 2]].sort
182
- end
183
- end
184
-
185
- describe "#each_subset" do
186
- it "iterates over each subset" do
187
- subsets = []
188
- dummy.each_subset([1, 2]) {|s| subsets << s}
189
- subsets.sort.should == [[], [1], [2], [1, 2]].sort
190
- end
191
- end
192
-
193
- describe '#parse_time' do
194
- context "when argument is a valid YYYYmmddHHMMSS string" do
195
- it "should correct Time object" do
196
- t = dummy.parse_time("19700101000000")
197
- t.should be_kind_of(Time)
198
- t.to_i.should == 0
199
- end
200
- end
201
- context "when argument is an invalid YYYYmmddHHMMSS string" do
202
- it "should raise ArgumentError" do
203
- expect{ dummy.parse_time("19709901000000") }.to raise_exception(ArgumentError)
204
- end
205
- end
206
- context "when argument is not a YYYYmmddHHMMSS string" do
207
- it "should raise ArgumentError" do
208
- expect{ dummy.parse_time("197099010000000") }.to raise_exception(ArgumentError)
209
- end
210
- end
211
- end
212
- end