pulse-meter-rails 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.
- data/.gitignore +17 -0
- data/.rbenv-version +1 -0
- data/.rspec +1 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +93 -0
- data/Rakefile +20 -0
- data/lib/generators/pulse_toolbox/install_generator.rb +20 -0
- data/lib/pulse-meter-rails.rb +38 -0
- data/lib/pulse_toolbox/sensor/initializer.rb +23 -0
- data/lib/pulse_toolbox/sensor/manager.rb +181 -0
- data/lib/pulse_toolbox/sensor/mixins/iterators.rb +54 -0
- data/lib/pulse_toolbox/server/monitoring.rb +48 -0
- data/lib/pulse_toolbox/version.rb +3 -0
- data/pulse-meter-rails.gemspec +31 -0
- data/spec/dummy/.gitignore +15 -0
- data/spec/dummy/app/controllers/application_controller.rb +3 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/mailers/.gitkeep +0 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/config/application.rb +58 -0
- data/spec/dummy/config/boot.rb +9 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +37 -0
- data/spec/dummy/config/environments/production.rb +67 -0
- data/spec/dummy/config/environments/test.rb +34 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/inflections.rb +15 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/pulse.rb +23 -0
- data/spec/dummy/config/initializers/secret_token.rb +7 -0
- data/spec/dummy/config/initializers/session_store.rb +8 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +5 -0
- data/spec/dummy/config/routes.rb +3 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/generators/install_spec.rb +10 -0
- data/spec/pulse_meter_rails_spec.rb +19 -0
- data/spec/pulse_toolbox/sensor/manager_spec.rb +136 -0
- data/spec/pulse_toolbox/sensor/mixins/iterators_spec.rb +65 -0
- data/spec/requests/monitoring_spec.rb +54 -0
- data/spec/spec_helper.rb +28 -0
- data/spec/support/helpers.rb +41 -0
- metadata +256 -0
@@ -0,0 +1,37 @@
|
|
1
|
+
Dummy::Application.configure do
|
2
|
+
# Settings specified here will take precedence over those in config/application.rb
|
3
|
+
|
4
|
+
# In the development environment your application's code is reloaded on
|
5
|
+
# every request. This slows down response time but is perfect for development
|
6
|
+
# since you don't have to restart the web server when you make code changes.
|
7
|
+
config.cache_classes = false
|
8
|
+
|
9
|
+
# Log error messages when you accidentally call methods on nil.
|
10
|
+
config.whiny_nils = true
|
11
|
+
|
12
|
+
# Show full error reports and disable caching
|
13
|
+
config.consider_all_requests_local = true
|
14
|
+
config.action_controller.perform_caching = false
|
15
|
+
|
16
|
+
# Don't care if the mailer can't send
|
17
|
+
config.action_mailer.raise_delivery_errors = false
|
18
|
+
|
19
|
+
# Print deprecation notices to the Rails logger
|
20
|
+
config.active_support.deprecation = :log
|
21
|
+
|
22
|
+
# Only use best-standards-support built into browsers
|
23
|
+
config.action_dispatch.best_standards_support = :builtin
|
24
|
+
|
25
|
+
# Raise exception on mass assignment protection for Active Record models
|
26
|
+
config.active_record.mass_assignment_sanitizer = :strict
|
27
|
+
|
28
|
+
# Log the query plan for queries taking more than this (works
|
29
|
+
# with SQLite, MySQL, and PostgreSQL)
|
30
|
+
config.active_record.auto_explain_threshold_in_seconds = 0.5
|
31
|
+
|
32
|
+
# Do not compress assets
|
33
|
+
config.assets.compress = false
|
34
|
+
|
35
|
+
# Expands the lines which load the assets
|
36
|
+
config.assets.debug = true
|
37
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
Dummy::Application.configure do
|
2
|
+
# Settings specified here will take precedence over those in config/application.rb
|
3
|
+
|
4
|
+
# Code is not reloaded between requests
|
5
|
+
config.cache_classes = true
|
6
|
+
|
7
|
+
# Full error reports are disabled and caching is turned on
|
8
|
+
config.consider_all_requests_local = false
|
9
|
+
config.action_controller.perform_caching = true
|
10
|
+
|
11
|
+
# Disable Rails's static asset server (Apache or nginx will already do this)
|
12
|
+
config.serve_static_assets = false
|
13
|
+
|
14
|
+
# Compress JavaScripts and CSS
|
15
|
+
config.assets.compress = true
|
16
|
+
|
17
|
+
# Don't fallback to assets pipeline if a precompiled asset is missed
|
18
|
+
config.assets.compile = false
|
19
|
+
|
20
|
+
# Generate digests for assets URLs
|
21
|
+
config.assets.digest = true
|
22
|
+
|
23
|
+
# Defaults to Rails.root.join("public/assets")
|
24
|
+
# config.assets.manifest = YOUR_PATH
|
25
|
+
|
26
|
+
# Specifies the header that your server uses for sending files
|
27
|
+
# config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
|
28
|
+
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx
|
29
|
+
|
30
|
+
# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
|
31
|
+
# config.force_ssl = true
|
32
|
+
|
33
|
+
# See everything in the log (default is :info)
|
34
|
+
# config.log_level = :debug
|
35
|
+
|
36
|
+
# Prepend all log lines with the following tags
|
37
|
+
# config.log_tags = [ :subdomain, :uuid ]
|
38
|
+
|
39
|
+
# Use a different logger for distributed setups
|
40
|
+
# config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
|
41
|
+
|
42
|
+
# Use a different cache store in production
|
43
|
+
# config.cache_store = :mem_cache_store
|
44
|
+
|
45
|
+
# Enable serving of images, stylesheets, and JavaScripts from an asset server
|
46
|
+
# config.action_controller.asset_host = "http://assets.example.com"
|
47
|
+
|
48
|
+
# Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
|
49
|
+
# config.assets.precompile += %w( search.js )
|
50
|
+
|
51
|
+
# Disable delivery errors, bad email addresses will be ignored
|
52
|
+
# config.action_mailer.raise_delivery_errors = false
|
53
|
+
|
54
|
+
# Enable threaded mode
|
55
|
+
# config.threadsafe!
|
56
|
+
|
57
|
+
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
|
58
|
+
# the I18n.default_locale when a translation can not be found)
|
59
|
+
config.i18n.fallbacks = true
|
60
|
+
|
61
|
+
# Send deprecation notices to registered listeners
|
62
|
+
config.active_support.deprecation = :notify
|
63
|
+
|
64
|
+
# Log the query plan for queries taking more than this (works
|
65
|
+
# with SQLite, MySQL, and PostgreSQL)
|
66
|
+
# config.active_record.auto_explain_threshold_in_seconds = 0.5
|
67
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
Dummy::Application.configure do
|
2
|
+
# Settings specified here will take precedence over those in config/application.rb
|
3
|
+
|
4
|
+
# The test environment is used exclusively to run your application's
|
5
|
+
# test suite. You never need to work with it otherwise. Remember that
|
6
|
+
# your test database is "scratch space" for the test suite and is wiped
|
7
|
+
# and recreated between test runs. Don't rely on the data there!
|
8
|
+
config.cache_classes = true
|
9
|
+
|
10
|
+
# Configure static asset server for tests with Cache-Control for performance
|
11
|
+
config.serve_static_assets = true
|
12
|
+
config.static_cache_control = "public, max-age=3600"
|
13
|
+
|
14
|
+
# Log error messages when you accidentally call methods on nil
|
15
|
+
config.whiny_nils = true
|
16
|
+
|
17
|
+
# Show full error reports and disable caching
|
18
|
+
config.consider_all_requests_local = true
|
19
|
+
config.action_controller.perform_caching = false
|
20
|
+
|
21
|
+
# Raise exceptions instead of rendering exception templates
|
22
|
+
config.action_dispatch.show_exceptions = false
|
23
|
+
|
24
|
+
# Disable request forgery protection in test environment
|
25
|
+
config.action_controller.allow_forgery_protection = false
|
26
|
+
|
27
|
+
# Tell Action Mailer not to deliver emails to the real world.
|
28
|
+
# The :test delivery method accumulates sent emails in the
|
29
|
+
# ActionMailer::Base.deliveries array.
|
30
|
+
config.action_mailer.delivery_method = :test
|
31
|
+
|
32
|
+
# Print deprecation notices to the stderr
|
33
|
+
config.active_support.deprecation = :stderr
|
34
|
+
end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
|
4
|
+
# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
|
5
|
+
|
6
|
+
# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
|
7
|
+
# Rails.backtrace_cleaner.remove_silencers!
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
# Add new inflection rules using the following format
|
4
|
+
# (all these examples are active by default):
|
5
|
+
# ActiveSupport::Inflector.inflections do |inflect|
|
6
|
+
# inflect.plural /^(ox)$/i, '\1en'
|
7
|
+
# inflect.singular /^(ox)en/i, '\1'
|
8
|
+
# inflect.irregular 'person', 'people'
|
9
|
+
# inflect.uncountable %w( fish sheep )
|
10
|
+
# end
|
11
|
+
#
|
12
|
+
# These inflection rules are supported but not enabled by default:
|
13
|
+
# ActiveSupport::Inflector.inflections do |inflect|
|
14
|
+
# inflect.acronym 'RESTful'
|
15
|
+
# end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
PulseToolbox.redis = Redis.new
|
2
|
+
|
3
|
+
PulseMeter::Sensor::Timelined::Counter.new(:custom_sensor,
|
4
|
+
:ttl => 1.hour,
|
5
|
+
:interval => 1.minute,
|
6
|
+
:raw_data_ttl => 10.minutes,
|
7
|
+
:reduce_delay => 2.minutes
|
8
|
+
)
|
9
|
+
|
10
|
+
PulseToolbox::Sensor::Manager.layout do |l|
|
11
|
+
l.page "Custom" do |p|
|
12
|
+
p.spline "Custom sensor" do |w|
|
13
|
+
w.sensor :custom_sensor, :color => "#0000FF"
|
14
|
+
|
15
|
+
w.timespan 60 * 60 * 3
|
16
|
+
w.redraw_interval 10
|
17
|
+
|
18
|
+
w.show_last_point true
|
19
|
+
w.values_label "Time"
|
20
|
+
w.width 10
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
# Your secret key for verifying the integrity of signed cookies.
|
4
|
+
# If you change this key, all old signed cookies will become invalid!
|
5
|
+
# Make sure the secret is at least 30 characters and all random,
|
6
|
+
# no regular words or you'll be exposed to dictionary attacks.
|
7
|
+
Dummy::Application.config.secret_token = '540600323be4c5ecca3ff2b75d0fb2718d73993ad6250e559cb8eebb9b8d4d2a2c68892600e9a8264b2dda73e176b210accf9b39b8fd3b45e8d51666915a3928'
|
@@ -0,0 +1,8 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
Dummy::Application.config.session_store :cookie_store, :key => '_dummy_session'
|
4
|
+
|
5
|
+
# Use the database for sessions instead of the cookie-based default,
|
6
|
+
# which shouldn't be used to store highly confidential information
|
7
|
+
# (create the session table with "rails generate session_migration")
|
8
|
+
# Dummy::Application.config.session_store :active_record_store
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
#
|
3
|
+
# This file contains settings for ActionController::ParamsWrapper which
|
4
|
+
# is enabled by default.
|
5
|
+
|
6
|
+
# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
|
7
|
+
ActiveSupport.on_load(:action_controller) do
|
8
|
+
wrap_parameters :format => [:json]
|
9
|
+
end
|
10
|
+
|
11
|
+
# Disable root element in JSON by default.
|
12
|
+
ActiveSupport.on_load(:active_record) do
|
13
|
+
self.include_root_in_json = false
|
14
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "install generator" do
|
4
|
+
it "should add route and create an initializer" do
|
5
|
+
when_i_have_rails_app
|
6
|
+
and_run_generator("pulse_toolbox:install")
|
7
|
+
i_should_see_route("mount PulseToolbox::Server::Monitoring, :at => '/monitoring'")
|
8
|
+
i_should_see_file("config/initializers/pulse_toolbox.rb")
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe PulseToolbox do
|
4
|
+
let(:redis) {"redis"}
|
5
|
+
|
6
|
+
describe ".redis=" do
|
7
|
+
it "should set PulseMeter redis" do
|
8
|
+
described_class.redis = redis
|
9
|
+
PulseMeter.redis.should == redis
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe ".redis" do
|
14
|
+
it "should retrieve redis" do
|
15
|
+
described_class.redis = redis
|
16
|
+
described_class.redis.should == redis
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,136 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe PulseToolbox::Sensor::Manager do
|
4
|
+
|
5
|
+
describe ".create_sensors" do
|
6
|
+
it "creates some sensors" do
|
7
|
+
lambda {described_class.create_sensors}.should change {PulseMeter::Sensor::Timeline.list_objects.count}
|
8
|
+
end
|
9
|
+
|
10
|
+
it "adds color property to sensor" do
|
11
|
+
described_class.create_sensors
|
12
|
+
described_class.each_sensor do |s|
|
13
|
+
s.color.should match(/^#[0-9A-F]{6}$/i)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe ".event" do
|
19
|
+
let(:value) {123}
|
20
|
+
it "sends given value to sensor" do
|
21
|
+
described_class.create_sensors
|
22
|
+
sensor = described_class.sensors[0]
|
23
|
+
sensor.class.any_instance.should_receive(:event).with(value)
|
24
|
+
described_class.event(sensor.name, value)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe ".log_request" do
|
29
|
+
it "sends event to all created sensors" do
|
30
|
+
described_class.create_sensors
|
31
|
+
described_class.each_sensor {|s| s.should_receive(:event)}
|
32
|
+
described_class.log_request(3, 2, 1)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe ".add_group" do
|
37
|
+
before do
|
38
|
+
described_class.create_sensors
|
39
|
+
end
|
40
|
+
|
41
|
+
it "adds group to list of groups" do
|
42
|
+
old_groups = groups
|
43
|
+
described_class.add_group(:new_group)
|
44
|
+
new_groups = groups
|
45
|
+
(new_groups - old_groups).should == [:new_group]
|
46
|
+
end
|
47
|
+
|
48
|
+
it "assigns title to group" do
|
49
|
+
old_titles = titles
|
50
|
+
described_class.add_group(:new_group, "New Title")
|
51
|
+
new_titles = titles
|
52
|
+
(new_titles - old_titles).should == ["New Title"]
|
53
|
+
end
|
54
|
+
|
55
|
+
it "overrides existing titles" do
|
56
|
+
described_class.each_group do |g|
|
57
|
+
described_class.add_group(g, "Title")
|
58
|
+
end
|
59
|
+
described_class.each_group_with_title do |g, t|
|
60
|
+
t.should == "Title"
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
it "preserves existing sensors" do
|
65
|
+
sensors_count = {}
|
66
|
+
described_class.each_group do |g|
|
67
|
+
sensors_count[g] = sensors(g).count
|
68
|
+
described_class.add_group(g, "Title")
|
69
|
+
end
|
70
|
+
|
71
|
+
described_class.each_group do |g|
|
72
|
+
sensors(g).count.should == sensors_count[g]
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
it "returns canonical name of created group" do
|
77
|
+
described_class.add_group("new").should == :new
|
78
|
+
described_class.add_group(:new).should == :new
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
describe ".add_sensor" do
|
83
|
+
let(:name) {:new_sensor}
|
84
|
+
let(:options) {
|
85
|
+
{
|
86
|
+
:sensor_type => 'timelined/max',
|
87
|
+
:color => '#0000FF',
|
88
|
+
:args => {
|
89
|
+
:ttl => 10.days,
|
90
|
+
:interval => 10.minutes,
|
91
|
+
:raw_data_ttl => 10.hours,
|
92
|
+
:reduce_delay => 20.minutes,
|
93
|
+
:annotation => "Annotation"
|
94
|
+
}
|
95
|
+
}
|
96
|
+
}
|
97
|
+
|
98
|
+
it "creates group unless it exists" do
|
99
|
+
lambda {
|
100
|
+
described_class.add_sensor(:nonexistant, name, options)
|
101
|
+
described_class.create_sensors
|
102
|
+
}.should change{groups.count}.by(1)
|
103
|
+
end
|
104
|
+
|
105
|
+
it "adds sensors to specified group" do
|
106
|
+
group = groups[0]
|
107
|
+
lambda {
|
108
|
+
described_class.add_sensor(group, name, options)
|
109
|
+
described_class.create_sensors
|
110
|
+
}.should change {sensors(group).count}.by(1)
|
111
|
+
end
|
112
|
+
|
113
|
+
it "returns sensor name in group" do
|
114
|
+
full_name = described_class.add_sensor(:max, name, options)
|
115
|
+
described_class.create_sensors
|
116
|
+
full_name.should == "max_#{name}".to_sym
|
117
|
+
end
|
118
|
+
|
119
|
+
it "assigns sensor's attributes correctly" do
|
120
|
+
full_name = described_class.add_sensor(:max, name, options)
|
121
|
+
described_class.create_sensors
|
122
|
+
sensor = described_class.configurator.sensor(full_name)
|
123
|
+
options[:args].each_pair do |k, v|
|
124
|
+
sensor.send(k).should == v
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
describe ".layout" do
|
130
|
+
it "passes layout instance to block" do
|
131
|
+
described_class.layout do |l|
|
132
|
+
l.should be_instance_of(PulseMeter::Visualize::DSL::Layout)
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe PulseToolbox::Sensor::Mixins::Iterators do
|
4
|
+
class SensorsContainer
|
5
|
+
extend PulseToolbox::Sensor::Mixins::Iterators
|
6
|
+
class_attribute :sensors_config
|
7
|
+
self.sensors_config = {
|
8
|
+
:g1 => {
|
9
|
+
:title => "G1",
|
10
|
+
:sensors => {
|
11
|
+
:s11 => "sensor11",
|
12
|
+
:s12 => "sensor12"
|
13
|
+
}
|
14
|
+
},
|
15
|
+
:g2 => {
|
16
|
+
:title => "G2",
|
17
|
+
:sensors => {
|
18
|
+
:s21 => "sensor21",
|
19
|
+
:s22 => "sensor22"
|
20
|
+
}
|
21
|
+
}
|
22
|
+
}
|
23
|
+
def self.get_sensor(group, name)
|
24
|
+
sensors_config[group][:sensors][name]
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe ".each_group" do
|
29
|
+
it "iterates over groups" do
|
30
|
+
groups = []
|
31
|
+
SensorsContainer.each_group {|g| groups << g}
|
32
|
+
[:g1, :g2].sort.should == groups.sort
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe ".each_group_with_title" do
|
37
|
+
it "iterates over groups and their titles" do
|
38
|
+
data = []
|
39
|
+
SensorsContainer.each_group_with_title {|g, t| data << [g, t]}
|
40
|
+
[[:g1, "G1"], [:g2, "G2"]].sort.should == data.sort
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe ".each_sensor_in_group" do
|
45
|
+
it "iterates over each sensor in specified group" do
|
46
|
+
sensors = []
|
47
|
+
SensorsContainer.each_sensor_in_group(:g1) {|s| sensors << s}
|
48
|
+
["sensor11", "sensor12"].sort.should == sensors.sort
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe ".each_sensor" do
|
53
|
+
it "iterates over each sensor" do
|
54
|
+
sensors = []
|
55
|
+
SensorsContainer.each_sensor {|s| sensors << s}
|
56
|
+
["sensor11", "sensor12", "sensor21", "sensor22"].sort.should == sensors.sort
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe ".sensors" do
|
61
|
+
it "returns all sensor" do
|
62
|
+
["sensor11", "sensor12", "sensor21", "sensor22"].sort.should == SensorsContainer.sensors.sort
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "/monitoring" do
|
4
|
+
it "looks like correct dashboard" do
|
5
|
+
visit "/monitoring"
|
6
|
+
page.body.should match(/Pulse Meter/)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "/monitoring/pages/:id/widgets" do
|
11
|
+
let(:custom_tab) {1}
|
12
|
+
let(:monitoring_tab) {2}
|
13
|
+
def visit_tab(tab_id)
|
14
|
+
PulseToolbox::Sensor::Manager.create_sensors
|
15
|
+
custom = PulseMeter::Sensor::Timelined::Counter.new(:custom_sensor,
|
16
|
+
:ttl => 1.hour,
|
17
|
+
:interval => 1.minute,
|
18
|
+
:raw_data_ttl => 10.minutes,
|
19
|
+
:reduce_delay => 2.minutes,
|
20
|
+
:annotation => "custom_sensor"
|
21
|
+
)
|
22
|
+
visit "/monitoring/pages/#{tab_id}/widgets"
|
23
|
+
@widgets = JSON.parse(page.source)
|
24
|
+
end
|
25
|
+
|
26
|
+
def all_annotations
|
27
|
+
found_annotations = []
|
28
|
+
@widgets.each do |w|
|
29
|
+
w["series"].each do |s|
|
30
|
+
found_annotations << s["name"]
|
31
|
+
end
|
32
|
+
end
|
33
|
+
found_annotations
|
34
|
+
end
|
35
|
+
|
36
|
+
it "returns some groups of widgets" do
|
37
|
+
visit_tab(monitoring_tab)
|
38
|
+
groups = []
|
39
|
+
PulseToolbox::Sensor::Manager.each_group {|g| groups << g}
|
40
|
+
@widgets.count.should == groups.count
|
41
|
+
end
|
42
|
+
|
43
|
+
it "contains all sensors from PulseToolbox::Sensor::Manager config" do
|
44
|
+
visit_tab(monitoring_tab)
|
45
|
+
annotations = PulseToolbox::Sensor::Manager.sensors.map(&:annotation)
|
46
|
+
|
47
|
+
annotations.sort.should == all_annotations.sort
|
48
|
+
end
|
49
|
+
|
50
|
+
it "returns widgets of custom page created in initializer" do
|
51
|
+
visit_tab(custom_tab)
|
52
|
+
all_annotations.should == ["custom_sensor"]
|
53
|
+
end
|
54
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
ENV["RAILS_ENV"] = "test"
|
2
|
+
require 'rubygems'
|
3
|
+
require 'bundler/setup'
|
4
|
+
$:.unshift File.expand_path('../../lib/', __FILE__)
|
5
|
+
|
6
|
+
require File.expand_path("../dummy/config/environment.rb", __FILE__)
|
7
|
+
require "rspec/rails"
|
8
|
+
require 'capybara/rails'
|
9
|
+
|
10
|
+
Bundler.require(:default, :test, :development)
|
11
|
+
|
12
|
+
SimpleCov.start
|
13
|
+
|
14
|
+
require 'rack/test'
|
15
|
+
require 'pulse-meter-rails'
|
16
|
+
|
17
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
18
|
+
|
19
|
+
RSpec.configure do |config|
|
20
|
+
config.include Helpers
|
21
|
+
config.before(:each) do
|
22
|
+
PulseToolbox.redis = Redis.new
|
23
|
+
PulseToolbox.redis.flushdb
|
24
|
+
end
|
25
|
+
config.filter_run :focus => true
|
26
|
+
config.run_all_when_everything_filtered = true
|
27
|
+
end
|
28
|
+
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module Helpers
|
2
|
+
RAILS_APP_PATH = "tmp/rails_app"
|
3
|
+
|
4
|
+
def titles
|
5
|
+
titles = []
|
6
|
+
described_class.each_group_with_title {|g, t| titles << t}
|
7
|
+
titles
|
8
|
+
end
|
9
|
+
|
10
|
+
def groups
|
11
|
+
groups = []
|
12
|
+
described_class.each_group {|g| groups << g}
|
13
|
+
groups
|
14
|
+
end
|
15
|
+
|
16
|
+
def sensors(group)
|
17
|
+
sensors = []
|
18
|
+
described_class.each_sensor_in_group(group) {|s| sensors << s}
|
19
|
+
sensors
|
20
|
+
end
|
21
|
+
|
22
|
+
def when_i_have_rails_app
|
23
|
+
FileUtils.mkdir_p("tmp")
|
24
|
+
FileUtils.remove_dir(RAILS_APP_PATH, true)
|
25
|
+
system("rails new " + RAILS_APP_PATH + " > /dev/null 2>&1").should be_true
|
26
|
+
system("ln -s ../../../lib/generators " + RAILS_APP_PATH + "/lib/generators").should be_true
|
27
|
+
end
|
28
|
+
|
29
|
+
def and_run_generator(name)
|
30
|
+
system("cd " + RAILS_APP_PATH + " && rails g #{name} > /dev/null 2>&1").should be_true
|
31
|
+
end
|
32
|
+
|
33
|
+
def i_should_see_route(route)
|
34
|
+
routes = File.open(RAILS_APP_PATH + "/config/routes.rb").read
|
35
|
+
routes.should include(route)
|
36
|
+
end
|
37
|
+
|
38
|
+
def i_should_see_file(file)
|
39
|
+
File.exists?(RAILS_APP_PATH + "/" + file).should be_true
|
40
|
+
end
|
41
|
+
end
|