diff --git a/.rspec b/.rspec
new file mode 100644
index 0000000..4e1e0d2
--- /dev/null
+++ b/.rspec
@@ -0,0 +1 @@
+--color
diff --git a/Gemfile b/Gemfile
index 4f01d2f..a8563ef 100644
--- a/Gemfile
+++ b/Gemfile
@@ -6,9 +6,8 @@ gem 'rails', '3.2.12'
# gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'sqlite3'
-
# bundle --without mysql if using sqlite
-gem 'mysql2', "~> 0.3.11", :group => :mysql
+gem 'mysql2', "~> 0.3.11", :group => :mysql
#Authentication Gems
gem 'devise'
@@ -50,7 +49,14 @@ gem 'thin', :group => :development
#testing
group :test, :development do
- gem 'minitest-rails'
+ gem "rspec-rails"
+ gem "factory_girl_rails"
+ gem "capybara"
+ gem "poltergeist"
+end
+
+group :test do
+ gem "sinatra"
end
#debug
diff --git a/Gemfile.lock b/Gemfile.lock
index 18efc5b..c23f8f2 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -29,68 +29,89 @@ GEM
i18n (~> 0.6)
multi_json (~> 1.0)
arel (3.0.2)
- bcrypt-ruby (3.0.1)
+ bcrypt-ruby (3.1.1)
bootstrap-sass (2.1.1.0)
bootstrap-will_paginate (0.0.9)
will_paginate
builder (3.0.4)
- cancan (1.6.8)
- chronic (0.6.7)
+ cancan (1.6.10)
+ capybara (2.1.0)
+ mime-types (>= 1.16)
+ nokogiri (>= 1.3.3)
+ rack (>= 1.0.0)
+ rack-test (>= 0.5.4)
+ xpath (~> 2.0)
+ chronic (0.9.1)
coffee-rails (3.2.2)
coffee-script (>= 2.2.0)
railties (~> 3.2.0)
coffee-script (2.2.0)
coffee-script-source
execjs
- coffee-script-source (1.4.0)
+ coffee-script-source (1.6.3)
daemons (1.1.9)
- devise (2.1.2)
+ devise (3.0.0)
bcrypt-ruby (~> 3.0)
orm_adapter (~> 0.1)
- railties (~> 3.1)
- warden (~> 1.2.1)
+ railties (>= 3.2.6, < 5)
+ warden (~> 1.2.3)
+ diff-lcs (1.2.4)
erubis (2.7.0)
- eventmachine (1.0.0)
+ eventmachine (1.0.3)
execjs (1.4.0)
multi_json (~> 1.0)
- font-awesome-sass-rails (2.0.0.0)
+ factory_girl (4.2.0)
+ activesupport (>= 3.0.0)
+ factory_girl_rails (4.2.1)
+ factory_girl (~> 4.2.0)
+ railties (>= 3.0.0)
+ faye-websocket (0.4.7)
+ eventmachine (>= 0.12.0)
+ font-awesome-sass-rails (3.0.2.2)
railties (>= 3.1.1)
sass-rails (>= 3.1.1)
formtastic (2.2.1)
actionpack (>= 3.0)
- haml (3.1.7)
- haml-rails (0.3.5)
+ haml (4.0.3)
+ tilt
+ haml-rails (0.4)
actionpack (>= 3.1, < 4.1)
activesupport (>= 3.1, < 4.1)
- haml (~> 3.1)
+ haml (>= 3.1, < 4.1)
railties (>= 3.1, < 4.1)
- hike (1.2.1)
+ hike (1.2.3)
+ http_parser.rb (0.5.3)
i18n (0.6.4)
journey (1.0.4)
- jquery-datatables-rails (1.11.1)
+ jquery-datatables-rails (1.11.2)
jquery-rails
- jquery-rails (2.1.3)
- railties (>= 3.1.0, < 5.0)
- thor (~> 0.14)
- json (1.7.7)
- kgio (2.7.4)
- libv8 (3.3.10.4)
+ jquery-rails (3.0.4)
+ railties (>= 3.0, < 5.0)
+ thor (>= 0.14, < 2.0)
+ json (1.8.0)
+ kgio (2.8.0)
+ libv8 (3.11.8.17)
mail (2.4.4)
i18n (>= 0.4.0)
mime-types (~> 1.16)
treetop (~> 1.4.8)
- mime-types (1.21)
- minitest (4.3.3)
- minitest-rails (0.3)
- minitest (~> 4.0)
- rails (~> 3.0)
- multi_json (1.6.1)
+ mime-types (1.23)
+ mini_portile (0.5.1)
+ multi_json (1.7.7)
mysql2 (0.3.11)
+ nokogiri (1.6.0)
+ mini_portile (~> 0.5.0)
orm_adapter (0.4.0)
+ poltergeist (1.3.0)
+ capybara (~> 2.1.0)
+ faye-websocket (>= 0.4.4, < 0.5.0)
+ http_parser.rb (~> 0.5.3)
polyglot (0.3.3)
rack (1.4.5)
rack-cache (1.2)
rack (>= 0.4)
+ rack-protection (1.5.0)
+ rack
rack-ssl (1.3.3)
rack
rack-test (0.6.2)
@@ -110,49 +131,68 @@ GEM
rake (>= 0.8.7)
rdoc (~> 3.4)
thor (>= 0.14.6, < 2.0)
- raindrops (0.10.0)
- rake (10.0.3)
+ raindrops (0.11.0)
+ rake (10.1.0)
rdoc (3.12.2)
json (~> 1.4)
+ ref (1.0.5)
rest-client (1.6.7)
mime-types (>= 1.16)
rolify (3.1.0)
- sass (3.2.1)
- sass-rails (3.2.5)
+ rspec-core (2.14.3)
+ rspec-expectations (2.14.0)
+ diff-lcs (>= 1.1.3, < 2.0)
+ rspec-mocks (2.14.1)
+ rspec-rails (2.14.0)
+ actionpack (>= 3.0)
+ activesupport (>= 3.0)
+ railties (>= 3.0)
+ rspec-core (~> 2.14.0)
+ rspec-expectations (~> 2.14.0)
+ rspec-mocks (~> 2.14.0)
+ sass (3.2.9)
+ sass-rails (3.2.6)
railties (~> 3.2.0)
sass (>= 3.1.10)
tilt (~> 1.3)
+ sinatra (1.4.3)
+ rack (~> 1.4)
+ rack-protection (~> 1.4)
+ tilt (~> 1.3, >= 1.3.4)
sprockets (2.2.2)
hike (~> 1.2)
multi_json (~> 1.0)
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
- sqlite3 (1.3.6)
- therubyracer (0.10.2)
- libv8 (~> 3.3.10)
- thin (1.5.0)
+ sqlite3 (1.3.7)
+ therubyracer (0.11.4)
+ libv8 (~> 3.11.8.12)
+ ref
+ thin (1.5.1)
daemons (>= 1.0.9)
eventmachine (>= 0.12.6)
rack (>= 1.0.0)
- thor (0.17.0)
- tilt (1.3.5)
- treetop (1.4.12)
+ thor (0.18.1)
+ tilt (1.4.1)
+ treetop (1.4.14)
polyglot
polyglot (>= 0.3.1)
tzinfo (0.3.37)
- uglifier (1.3.0)
+ uglifier (2.1.2)
execjs (>= 0.3.0)
multi_json (~> 1.0, >= 1.0.2)
- unicorn (4.4.0)
+ unicorn (4.6.3)
kgio (~> 2.6)
rack
raindrops (~> 0.7)
- warden (1.2.1)
+ warden (1.2.3)
rack (>= 1.0)
- whenever (0.7.3)
+ whenever (0.8.3)
activesupport (>= 2.3.4)
- chronic (~> 0.6.3)
- will_paginate (3.0.3)
+ chronic (>= 0.6.3)
+ will_paginate (3.0.4)
+ xpath (2.0.0)
+ nokogiri (~> 1.3)
PLATFORMS
ruby
@@ -161,20 +201,24 @@ DEPENDENCIES
bootstrap-sass (= 2.1.1.0)
bootstrap-will_paginate
cancan
+ capybara
coffee-rails (~> 3.2.1)
devise
+ factory_girl_rails
font-awesome-sass-rails
formtastic
haml-rails
jquery-datatables-rails
jquery-rails
json
- minitest-rails
mysql2 (~> 0.3.11)
+ poltergeist
rails (= 3.2.12)
rest-client
rolify (= 3.1)
+ rspec-rails
sass-rails (~> 3.2.3)
+ sinatra
sqlite3
therubyracer
thin
diff --git a/app/assets/javascripts/clients.js.coffee b/app/assets/javascripts/clients.js.coffee
index 0a6bb91..d3be359 100644
--- a/app/assets/javascripts/clients.js.coffee
+++ b/app/assets/javascripts/clients.js.coffee
@@ -3,21 +3,35 @@
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
$ ->
$('.subpopover').popover({'placement': 'bottom'})
+
$('td.moreinfo').click ->
- $($(this).closest('tr').attr("rel")).modal("show")
+ $(this).closest('tr').attr("rel")
+ $.get "/clients/modal_data", { 'client_query': $(this).closest('tr').attr("rel") },
+ (data) ->
+ if data.code == 0
+ $('#client-data-modal').html(data['data'])
+ $('#client-data-modal').modal("show")
+ else
+ alert(data.msg)
+
$('a.delete-client').click ->
self = $(this)
if (confirm('Are you sure?'))
- $.ajax $(this).attr("rel"),
- type: 'DELETE'
- success: (data) ->
+ $.post "/clients/delete_client", { 'key': $(this).attr('key') },
+ (data) ->
if data
$("#client_row_" + $(self).attr('key')).hide()
else
alert("Could not delete client")
+ use_environments = $("#use_environments").attr("rel")
+ if use_environments == "true"
+ aocolumns = [null, null, null, null, null, null, {bSortable: false}, {bSortable: false}]
+ else
+ aocolumns = [null, null, null, null, null, {bSortable: false}, {bSortable: false}]
+
dtable = $('#clients_table').dataTable
- bAutoWidth: false
- bSort: true
- aoColumns: [null, null, null, null, null, null, {bSortable: false}, {bSortable: false}]
- bPaginate: false
+ bAutoWidth: false
+ bSort: true
+ aoColumns: aocolumns
+ bPaginate: false
diff --git a/app/assets/javascripts/events.js.coffee b/app/assets/javascripts/events.js.coffee
index 5514be5..0d24f3a 100644
--- a/app/assets/javascripts/events.js.coffee
+++ b/app/assets/javascripts/events.js.coffee
@@ -12,23 +12,18 @@ $ ->
$('#primary_events_table').dataTable().fnReloadAjax()
setTimeout (() -> $('#updating_event_list').hide()), 2500
- runPermanentHooks = ()->
+ setPickers = ()->
$('.timepicker').timepicker({ 'step': 15, 'showDuration': true, 'timeFormat': 'g:ia', 'scrollDefaultNow': true })
$('.datepicker').datepicker({ 'autoclose': true, 'dateFormat': 'm/d/yy', 'format': 'mm/dd/yyyy' })
+ runPermanentHooks = ()->
$(document).on 'keydown', '.silence-input', ->
- self = $(this)
- misc = $(self).attr("misc")
- $('#no_input_' + $(self).attr("misc")).hide()
- if $(self).val().length > 12
- $('[control="silence_grey_submit_' + misc + '"]').hide()
- $('[control="silence_submit_' + misc + '"]').show()
+ misc = $(this).attr("misc")
+ $('#no_input_' + $(this).attr("misc")).hide()
+ if $(this).val().length >= $(this).data("min")
+ $('[control="silence_submit_' + misc + '"]').addClass('btn-success').removeClass('btn-inverse')
else
- $('[control="silence_grey_submit_' + misc + '"]').show()
- $('[control="silence_submit_' + misc + '"]').hide()
-
- $(document).on 'click', '[control^=silence_grey_submit_]', ->
- $('#no_input_' + $(this).attr("misc")).show()
+ $('[control="silence_submit_' + misc + '"]').addClass('btn-inverse').removeClass('btn-success')
$(document).on 'click', 'div.moreinfo', ->
$.get "/events/modal_data", { 'event_query': $(this).attr('misc'), 'i': $(this).attr('index_id') },
@@ -52,51 +47,67 @@ $ ->
$(self).text("Failed to resolve")
$(self).css("color", "red")
- $(document).on 'click', '.silence-event', ->
- self = $(this)
+ $(document).on 'click', '.silence-client', ->
+ $("#event-data-modal").modal("hide")
+ $.get "/events/modal_silence", { 'event_query': $(this).attr('misc'), 'i': $(this).attr('index_id'), 't':'client' },
+ (data) ->
+ if data
+ $('#event-data-modal').html(data['data'])
+ $('#event-data-modal').modal("show")
+ setPickers()
+ else
+ alert("Could not get modal info")
+
+ $(document).on 'click', '.silence-check', ->
$("#event-data-modal").modal("hide")
- $("#modal_" + $(self).attr("misc")).modal("show")
+ $.get "/events/modal_silence", { 'event_query': $(this).attr('misc'), 'i': $(this).attr('index_id'), 't':'check' },
+ (data) ->
+ if data
+ $('#event-data-modal').html(data['data'])
+ $('#event-data-modal').modal("show")
+ setPickers()
+ else
+ alert("Could not get modal info")
$(document).on 'click', '.silence-submit-event', ->
- self = $(this)
- misc = $(self).attr("misc")
+ misc = $(this).attr("misc")
+ if $('#text_input_' + misc).val().length < $('#text_input_' + misc).data("min")
+ alert('Comment must be at least ' + $('#text_input_' + misc).data("min") + ' characters long')
+ return false
$.post $(this).attr("rel"), { 'expire_at_time': $('#silence_expire_at_time_' + misc).val(), 'expire_at_date': $('#silence_expire_at_date_' + misc).val(), 'description': $('#text_input_' + misc).val()},
(data) ->
- if data
- $("#modal_" + misc).modal("hide")
+ if data.code == 0
+ $("#event-data-modal").modal("hide")
+ $('i[event="' + misc + '"]').removeClass("icon-volume-up").addClass("icon-volume-off")
updateEventTable()
else
- alert("Failed to silence...")
+ alert(data)
$(document).on 'click', '.unsilence-submit-event', ->
- self = $(this)
- misc = $(self).attr("misc")
+ misc = $(this).attr("misc")
$.post $(this).attr("rel"),
(data) ->
if data
- $('[control="unsilence_' + misc + '"]').hide()
- $('[control="silence_' + misc + '"]').show()
$('td[rel="' + misc + '_popup_info"]').attr('data-content', "No")
$('td[rel="' + misc + '_column_silenced"]').text("No")
+ $('i[event="' + misc + '"]').removeClass("icon-volume-off").addClass("icon-volume-up")
else
alert("Failed to unsilence...")
- $(document).on 'click', '.delete-client', ->
- self = $(this)
- if (confirm('Are you sure?'))
- $.ajax $(this).attr("rel"),
- type: 'DELETE'
- success: (data) ->
- if data
- updateEventTable()
- else
- alert("Could not delete client")
+ $(document).on 'click', 'a.delete-client', ->
+ if (confirm('Are you sure?'))
+ $.post "/clients/delete_client", { 'key': $(this).attr('key') },
+ (data) ->
+ if data
+ $("td:contains('" + this.data.split("=")[1] + "')").parent().hide()
+ else
+ alert("Could not delete client")
use_environments = $("#use_environments").attr("rel")
if use_environments == "true"
- aocolumns = [{bVisible: false}, null, null, null, null, null, null, null, null]
+ aocolumns = [{bVisible: false}, null, null, null, null, null, null, null, {bSortable: false}]
else
- aocolumns = [{bVisible: false}, null, null, null, null, null, null, null]
+ aocolumns = [{bVisible: false}, null, null, null, null, null, null, {bSortable: false}]
dtable = $('#primary_events_table').dataTable
bAutoWidth: false
diff --git a/app/assets/stylesheets/bootstrap_and_overrides.css.scss b/app/assets/stylesheets/bootstrap_and_overrides.css.scss
index 8e5d94c..e71d03d 100644
--- a/app/assets/stylesheets/bootstrap_and_overrides.css.scss
+++ b/app/assets/stylesheets/bootstrap_and_overrides.css.scss
@@ -18,32 +18,42 @@ body {
top: 3%;
right: 3%;
left: 3%;
- bottom: 3%;
width: auto;
- margin: 0;
+ margin: 0 auto;
}
.small-modal {
- height: 60%;
- width: 60%;
+ width: 30%;
left: 8%;
- top: 5%;
+ top: 20%;
}
.large-modal {
- height: 65%;
- width: 75%;
- left: 8%;
- top: 5%;
+ width: 50%;
+ left: 8%;
+ top: 5%;
+}
+
+.silence-reason {
+ float: left;
+}
+
+.silence-time {
+ float: left;
+ padding-left: 50px;
}
div.modal-body {
- max-height: 60%;
+ padding-bottom: 80px;
+ max-height: 500px;
max-width: 95%;
}
div.modal-footer {
- min-height: 20%;
+ position: absolute;
+ bottom: 0px;
+ right: 0px;
+ width: 100%;
}
table.events_table {
@@ -86,7 +96,8 @@ only screen and (max-width: 480px) {
.modal-footer {
min-height: 45px;
}
-
+
+
/* Force table to not be like tables anymore */
.events_table thead,.events_table tbody,.events_table th,.events_table td,.events_table tr {
display: block;
diff --git a/app/controllers/api_controller.rb b/app/controllers/api_controller.rb
index 8998060..d028f3d 100644
--- a/app/controllers/api_controller.rb
+++ b/app/controllers/api_controller.rb
@@ -1,4 +1,4 @@
-class Api::ApiController < ApplicationController
+class Api::ApiController < ApplicationController
def status
render :json => { :data => render_to_string(:action => '_apistatus', :layout => false) }
end
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index bd06b8a..5580b7f 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -17,7 +17,7 @@ def check_for_api
def check_for_settings
REQUIRED_SETTINGS.each do |setting|
unless Setting.find_by_name(setting)
- redirect_to(settings_missing_path, :notice => "Settings missing #{setting}") and return
+ redirect_to(settings_missing_path, :notice => "Settings missing #{setting}") and return
end
end
end
diff --git a/app/controllers/clients_controller.rb b/app/controllers/clients_controller.rb
index 078ef8d..efc80f2 100644
--- a/app/controllers/clients_controller.rb
+++ b/app/controllers/clients_controller.rb
@@ -5,12 +5,22 @@ def index
@clients = Client.all_with_cache
end
- def destroy
- resp = Client.destroy(params[:id])
+ def modal_data
+ client = Client.find(params[:client_query])
+ if client
+ render :json => {:code => 0, :data => render_to_string(:action => "_modal", :layout => false, :locals => {:client => client})}
+ else
+ render :json => {:code => 1, :msg => "Could not find client #{params[:client_query]}"}
+ end
+ end
+
+ def delete_client
+ resp = Client.destroy(params[:key])
Client.refresh_cache
+ Event.refresh_cache
respond_to do |format|
- format.json { render :json => {:data => (resp == 202).to_s}.to_json }
- format.mobile { render :json => {:data => (resp == 202).to_s}.to_json }
+ format.json { render :json => {:data => (resp.code == 202).to_s}.to_json }
+ format.mobile { render :json => {:data => (resp.code == 202).to_s}.to_json }
end
end
end
diff --git a/app/controllers/events_controller.rb b/app/controllers/events_controller.rb
index 8ab897c..d6d48ad 100644
--- a/app/controllers/events_controller.rb
+++ b/app/controllers/events_controller.rb
@@ -8,6 +8,8 @@ def index
def events_table
events_datatable = []
@events.each_with_index do |event, i|
+ client_silenced = event.client_silenced
+ check_silenced = event.check_silenced
if Setting.use_environments?
events_datatable << [
event.sort_val,
@@ -16,7 +18,7 @@ def events_table
event.client,
event.check,
render_to_string(:action => "_output", :formats => [:html], :layout => false, :locals => { :event => event }),
- render_to_string(:action => "_actions", :formats => [:html], :layout => false, :locals => { :event => event, :i => i}),
+ render_to_string(:action => "_actions", :formats => [:html], :layout => false, :locals => { :event => event, :i => i, :client_silenced => client_silenced, :check_silenced => check_silenced}),
render_to_string(:action => "_issued", :formats => [:html], :layout => false, :locals => { :event => event }),
"
"
]
@@ -27,7 +29,7 @@ def events_table
event.client,
event.check,
render_to_string(:action => "_output", :formats => [:html], :layout => false, :locals => { :event => event }),
- render_to_string(:action => "_actions", :formats => [:html], :layout => false, :locals => { :event => event, :i => i}),
+ render_to_string(:action => "_actions", :formats => [:html], :layout => false, :locals => { :event => event, :i => i, :client_silenced => client_silenced, :check_silenced => check_silenced}),
render_to_string(:action => "_issued", :formats => [:html], :layout => false, :locals => { :event => event }),
"
"
]
@@ -42,7 +44,16 @@ def events_table
def modal_data
event = Event.single(params[:event_query])
- render :json => {:data => render_to_string(:action => "_modal_data", :layout => false, :locals => {:event => event, :i => params[:i]})}
+ if event
+ render :json => {:data => render_to_string(:action => "_modal_data", :layout => false, :locals => {:event => event, :i => params[:i]})}
+ else
+ render :json => {:data => false }
+ end
+ end
+
+ def modal_silence
+ event = Event.single(params[:event_query])
+ render :json => {:data => render_to_string(:action => "_modal_silence", :layout => false, :locals => {:event => event, :i => params[:i], :type => params[:t]})}
end
def resolve
@@ -54,7 +65,22 @@ def resolve
end
end
+ def check_min_desc(description)
+ min_length = Setting.min_desc_length.to_i || 0
+ if description.length < min_length
+ respond_to do |format|
+ format.json { render :json => {:code => 1, :msg => "Your comment must be at least #{min_length} characters long"} }
+ format.mobile { render :json => {:code => 1, :msg => "Your comment must be at least #{min_length} characters long"} }
+ end
+ return false
+ end
+ return true
+ end
+
def silence_client
+ unless check_min_desc(params[:description])
+ return
+ end
expire_at = nil
if !params[:expire_at_time].blank? && !params[:expire_at_date].blank?
expire_at = Time.parse("#{params[:expire_at_date]} #{params[:expire_at_time]}")
@@ -62,13 +88,17 @@ def silence_client
params[:description] = "No reason given" if params[:description].empty?
resp = Event.silence_client(params[:client], params[:description], current_user, expire_at)
Stash.refresh_cache
+
respond_to do |format|
- format.json { render :json => (resp.code == 201).to_s }
+ format.json { render :json => (resp.code == 201) ? {'code' => 0} : {'code' => resp.code, 'msg' => 'Error silencing client'} }
format.mobile { render :json => (resp.code == 201).to_s }
end
end
def silence_check
+ unless check_min_desc(params[:description])
+ return
+ end
expire_at = nil
if !params[:expire_at_time].blank? && !params[:expire_at_date].blank?
expire_at = Time.parse("#{params[:expire_at_date]} #{params[:expire_at_time]}")
@@ -77,6 +107,7 @@ def silence_check
resp = Event.silence_check(params[:client], params[:check], params[:description], current_user, expire_at)
Stash.refresh_cache
respond_to do |format|
+ format.json { render :json => (resp.code == 201) ? {'code' => 0} : {'code' => resp.code, 'msg' => 'Error silencing check'} }
format.json { render :json => (resp.code == 201).to_s }
format.mobile { render :json => (resp.code == 201).to_s }
end
@@ -86,8 +117,8 @@ def unsilence_client
resp = Event.unsilence_client(params[:client], current_user)
Stash.refresh_cache
respond_to do |format|
- format.json { render :json => (resp.code == 202).to_s }
- format.mobile { render :json => (resp.code == 202).to_s }
+ format.json { render :json => (resp.code == 204).to_s }
+ format.mobile { render :json => (resp.code == 204).to_s }
end
end
@@ -95,8 +126,8 @@ def unsilence_check
resp = Event.unsilence_check(params[:client], params[:check], current_user)
Stash.refresh_cache
respond_to do |format|
- format.json { render :json => (resp.code == 202).to_s }
- format.mobile { render :json => (resp.code == 202).to_s }
+ format.json { render :json => (resp.code == 204).to_s }
+ format.mobile { render :json => (resp.code == 204).to_s }
end
end
diff --git a/app/controllers/settings_controller.rb b/app/controllers/settings_controller.rb
index 16edbbc..c45052b 100644
--- a/app/controllers/settings_controller.rb
+++ b/app/controllers/settings_controller.rb
@@ -12,7 +12,6 @@ def missing
end
def create
- puts params.inspect
@setting = Setting.new(:name => params[:name], :value => params[:value])
if @setting.save!
redirect_to(settings_path, :notice => "Successfully created")
diff --git a/app/helpers/events_helper.rb b/app/helpers/events_helper.rb
index 9f94dba..e348fc6 100644
--- a/app/helpers/events_helper.rb
+++ b/app/helpers/events_helper.rb
@@ -4,17 +4,17 @@ def silenced_output(check, client)
# TODO: This should be all haml_tag's
output = ""
output << "Check silenced by:
" unless check.nil?
- output << "#{check['description']} - #{check['owner']} - #{check['timestamp']}
" unless check.nil?
+ output << "#{check['content']['description']} - #{check['content']['owner']} - #{check['content']['timestamp']}
" unless check.nil?
output << "Client silenced by:
" unless client.nil?
- output << "#{client['description']} - #{client['owner']} - #{client['timestamp']}
" unless client.nil?
+ output << "#{client['content']['description']} - #{client['content']['owner']} - #{client['content']['timestamp']}
" unless client.nil?
output << "Not Silenced" if client.nil? && check.nil?
output
end
- def display_silenced(event, i)
+ def display_silenced(event, i, client_silenced, check_silenced)
# If client_silenced is nil, that means its not silenced
- voldisp = ((event.client_silenced.nil? && event.check_silenced.nil?) ? "up" : "off")
- haml_tag(:i, {:class => "icon-volume-#{voldisp}", :rel => "icon_silenced_#{i}", :style => "color: #2c2c2c; text-shadow: none;"})
+ voldisp = ((client_silenced.nil? && check_silenced.nil?) ? "up" : "off")
+ haml_tag(:i, {:class => "icon-volume-#{voldisp}", :event => "#{event.client}_#{event.check}", :rel => "icon_silenced_#{i}"})
end
def is_nil?(obj)
diff --git a/app/models/api.rb b/app/models/api.rb
index fe6ed6e..621725c 100644
--- a/app/models/api.rb
+++ b/app/models/api.rb
@@ -9,10 +9,10 @@ def self.version
end
def self.redis_health
- self.status.health['redis']
+ self.status.redis['connected']
end
def self.rabbitmq_health
- self.status.health['rabbitmq']
+ self.status.rabbitmq['connected']
end
end
diff --git a/app/models/downtime b/app/models/downtime
deleted file mode 100644
index e69de29..0000000
diff --git a/app/models/downtime.rb b/app/models/downtime.rb
index e3edaba..627c106 100644
--- a/app/models/downtime.rb
+++ b/app/models/downtime.rb
@@ -8,7 +8,7 @@ class Downtime < ActiveRecord::Base
validates_presence_of :name
validates_presence_of :user_id
- validates_presence_of :downtime_clients
+ # validates_presence_of :downtime_clients
validate :validates_stop_time_of, :on => :create
@@ -56,11 +56,11 @@ def self.process_downtimes
def self.force_complete(id)
downtime = Downtime.find(id)
- Stash.stashes.each do |k,v|
+ Stash.stashes.each do |v|
unless v['downtime_id'].nil?
if v['downtime_id'].to_i == id.to_i
- puts "Force completing downtime (#{downtime.name}, #{downtime.id}) - Deleting stash #{k}"
- Stash.delete_stash(k)
+ puts "Force completing downtime (#{downtime.name}, #{downtime.id}) - Deleting stash #{v['path']}"
+ Stash.delete_stash(v['path'])
end
end
end
diff --git a/app/models/event.rb b/app/models/event.rb
index a6c08a8..4114309 100644
--- a/app/models/event.rb
+++ b/app/models/event.rb
@@ -12,7 +12,7 @@ def self.refresh_cache
end
def resolve
- self.delete("#{self.client}/#{self.check}")
+ self.delete("#{self.class.to_s.downcase}/#{self.client}/#{self.check}")
end
def self.single(query)
@@ -21,20 +21,12 @@ def self.single(query)
def client_silenced
stashes = Stash.stashes
- if stashes.include?("silence/#{self.client}")
- stashes["silence/#{self.client}"]
- else
- nil
- end
+ stashes.detect {|stash| stash['path'] == "silence/#{self.client}"}
end
def check_silenced
stashes = Stash.stashes
- if stashes.include?("silence/#{self.client}/#{self.check}")
- stashes["silence/#{self.client}/#{self.check}"]
- else
- nil
- end
+ stashes.detect {|stash| stash['path'] == "silence/#{self.client}/#{self.check}"}
end
def self.manual_resolve(client, check, user)
diff --git a/app/models/setting.rb b/app/models/setting.rb
index fb3a18e..215bab9 100644
--- a/app/models/setting.rb
+++ b/app/models/setting.rb
@@ -13,6 +13,12 @@ def self.use_environments?
find_by_name("use_environments").value == "true"
end
end
+
+ def self.min_desc_length
+ Rails.cache.fetch("min_desc_length", :expires_in => 15.minutes, :race_condition_ttl => 10) do
+ find_by_name("min_desc_length").value
+ end
+ end
def self.configure_server?
Rails.cache.fetch("configure_server", :expires_in => 15.minutes, :race_condition_ttl => 10) do
diff --git a/app/models/stash.rb b/app/models/stash.rb
index 8bde839..97c965d 100644
--- a/app/models/stash.rb
+++ b/app/models/stash.rb
@@ -61,18 +61,18 @@ def self.delete_stash(key)
end
def self.delete_all_stashes
- Stash.all.each do |key|
- destroy(key)
+ Stash.all.each do |v|
+ destroy(v['path'])
end
true
end
def self.clear_expired_stashes
- Stash.stashes.each do |k,v|
+ Stash.stashes.each do |v|
unless v['expire_at'].nil?
if Time.parse(v['expire_at']) < Time.now
- puts "Clearing stash #{k} due to expiration."
- destroy(k)
+ puts "Clearing stash #{v['path']} due to expiration."
+ destroy(v['path'])
end
end
end and true
diff --git a/app/views/clients/_modal.html.haml b/app/views/clients/_modal.html.haml
new file mode 100644
index 0000000..a39ef1f
--- /dev/null
+++ b/app/views/clients/_modal.html.haml
@@ -0,0 +1,9 @@
+%div.modal-header
+ %h3== Client: #{client.name}
+%div.modal-body
+ %table.table.table-striped.table-bordered
+ %tbody
+ - client.attributes.each do |k,v|
+ %tr
+ %td= k
+ %td= v
diff --git a/app/views/clients/index.html.haml b/app/views/clients/index.html.haml
index 541deaf..85a9fcf 100644
--- a/app/views/clients/index.html.haml
+++ b/app/views/clients/index.html.haml
@@ -1,14 +1,5 @@
-- @clients.each do |client|
- %div{:class => "modal hide", :id => "client_modal_#{client.name}"}
- %div.modal-header
- %h3== Client: #{client.name}
- %div.modal-body
- %table.table.table-striped.table-bordered
- %tbody
- - client.attributes.each do |k,v|
- %tr
- %td= k
- %td= v
+%div{:class => "modal small-modal hide", :id => "client-data-modal"}
+%div{:style => "display: none;", :id => "use_environments", :rel => "#{use_environments?}"}
%table.table-striped.dataTable.clients_table.table{:id => "clients_table"}
%thead
@@ -17,13 +8,13 @@
%th Name
%th Address
%th Subscriptions
- %th Last checkin
- %th
+ %th Role
+ %th Last Checkin
%th
%tbody
- @clients.each do |client|
- %tr{:id => "client_row_#{client.name}", :rel => "#client_modal_#{client.name}"}
+ %tr{:id => "client_row_#{client.name}", :rel => client.name}
- if use_environments?
%td.moreinfo= client.environment
%td.moreinfo= client.name
diff --git a/app/views/events/_actions.html.haml b/app/views/events/_actions.html.haml
index 8e5eded..e6d9f17 100644
--- a/app/views/events/_actions.html.haml
+++ b/app/views/events/_actions.html.haml
@@ -1,25 +1,25 @@
-%td{:rel => "#{event.client}_popup_info", :title => "Check Silence", 'data-content' => silenced_output(event.check_silenced, event.client_silenced)}
+%td{:rel => "#{event.client}_popup_info", :title => "Check Silence", 'data-content' => silenced_output(check_silenced, client_silenced)}
%div.btn-group
%button.btn.btn-info.dropdown-toggle{'data-toggle' => 'dropdown'}
%div{:style => "width: 25px"}
%div{:style => "float: left;"}
- - display_silenced(event, i)
+ - display_silenced(event, i, client_silenced, check_silenced)
%div{:style => "float: right;"}
%span.caret
%ul.dropdown-menu
- - if event.client_silenced.nil?
+ - if client_silenced.nil?
%li
- %a.silence-event{:index_id => "#{i}", :misc => "#{event.client}", :href => "#"} Silence Client
+ %a.silence-client{:index_id => "#{i}", :misc => "#{event.client}_#{event.check}", :href => "#"} Silence Client
- else
%li
- %a.unsilence-submit-event{:index_id => "#{i}", :misc => "#{event.client}", :rel => "/events/#{event.client}/unsilence", :href => "#"} UnSilence Client
- - if event.check_silenced.nil?
+ %a.unsilence-submit-event{:index_id => "#{i}", :misc => "#{event.client}_#{event.check}", :rel => "/events/#{event.client}/unsilence", :href => "#"} UnSilence Client
+ - if check_silenced.nil?
%li
- %a.silence-event{:index_id => "#{i}", :misc => "#{event.client}_#{event.check}", :href => "#"} Silence Check
+ %a.silence-check{:index_id => "#{i}", :misc => "#{event.client}_#{event.check}", :href => "#"} Silence Check
- else
%li
%a.unsilence-submit-event{:index_id => "#{i}", :misc => "#{event.client}_#{event.check}", :rel => "/events/#{event.client}/#{event.check}/unsilence", :href => "#"} UnSilence Check
%li
%a.resolve-event{:misc => "#row-event-#{i}", :index_id => "#{i}", :rel => "/events/#{event.client}/#{event.check}/resolve"} Resolve
%li
- %a.delete-client{:misc => "#row-event-#{i}", :index_id => "#{i}", :rel => "/clients/#{event.client}"} Delete Client
+ %a.delete-client{:misc => "#row-event-#{i}", :index_id => "#{i}", :key => "#{event.client}"} Delete Client
diff --git a/app/views/events/_modal_data.html.haml b/app/views/events/_modal_data.html.haml
index 8fcc905..05db433 100644
--- a/app/views/events/_modal_data.html.haml
+++ b/app/views/events/_modal_data.html.haml
@@ -25,10 +25,10 @@
%td= event.flapping
%tr
%td Check Silenced
- %td{:rel => "#{event.client}_#{event.check}_column_silenced"}= ((event.check_silenced.nil?) ? "No" : Time.at(event.check_silenced["timestamp"]))
+ %td{:rel => "#{event.client}_#{event.check}_column_silenced"}= ((event.check_silenced.nil?) ? "No" : Time.at(event.check_silenced["content"]["timestamp"]))
%tr
%td Client Silenced
- %td{:rel => "#{event.client}_column_silenced"}= ((event.client_silenced.nil?) ? "No" : Time.at(event.client_silenced["timestamp"]))
+ %td{:rel => "#{event.client}_column_silenced"}= ((event.client_silenced.nil?) ? "No" : Time.at(event.client_silenced["content"]["timestamp"]))
%br
%br
%h3 Check Attributes
@@ -52,11 +52,11 @@
/ TODO: This needs to be moved into partials probably and remove a disturbing number of attribs
/
- if event.check_silenced.nil?
- %a.silence-event.btn.btn-primary{:control => "silence_#{event.client}_#{event.check}", :index_id => "#{i}", :misc => "#{event.client}_#{event.check}"} Silence Check
+ %a.silence-check.btn.btn-primary{:control => "silence_#{event.client}_#{event.check}", :index_id => "#{i}", :misc => "#{event.client}_#{event.check}"} Silence Check
- else
%a.unsilence-submit-event.btn.btn-primary{:control => "unsilence_#{event.client}_#{event.check}", :index_id => "#{i}", :misc => "#{event.client}_#{event.check}", :rel => "/events/#{event.client}/#{event.check}/unsilence"} Unsilence Check
- if event.client_silenced.nil?
- %a.silence-event.btn.btn-primary{:control => "silence_#{event.client}", :index_id => "#{i}", :misc => "#{event.client}"} Silence Client
+ %a.silence-client.btn.btn-primary{:control => "silence_#{event.client}", :index_id => "#{i}", :misc => "#{event.client}_#{event.check}"} Silence Client
- else
%a.unsilence-submit-event.btn.btn-primary{:control => "unsilence_#{event.client}", :index_id => "#{i}", :misc => "#{event.client}", :rel => "/events/#{event.client}/unsilence"} Unsilence Client
%a.resolve-event.btn.btn-success{:rel => "/events/#{event.client}/#{event.check}/resolve"} Resolve
diff --git a/app/views/events/_modal_silence.html.haml b/app/views/events/_modal_silence.html.haml
new file mode 100644
index 0000000..b954f51
--- /dev/null
+++ b/app/views/events/_modal_silence.html.haml
@@ -0,0 +1,25 @@
+- len = Setting.min_desc_length.to_i
+- if type.match("client")
+ - header_title = "Silence client #{event.client}"
+ - suffix = "#{event.client}"
+- else
+ - header_title = "Silence check #{event.check} on client #{event.client}"
+ - suffix = "#{event.client}_#{event.check}"
+%div.modal-header
+ %h3= header_title
+%div.modal-body
+ %div.pull-left Note: Your event handler must use sensu-plugin or hit the API to make use of silencing.
+ %div.silence-reason
+ %h4 Enter reason
+ %textarea.input-xlarge.silence-input{:id => "text_input_#{suffix}", :index_id => i, :data => {:min => len}, :misc => suffix, :rel => "Silence #{type}", :rows => "3", :type => "text", :placeholder => "Silence #{type} reason"}
+ %div.silence-time
+ %h4 Expire at (Optional):
+ %p Date:
+ %input.datepicker{:id => "silence_expire_at_date_#{suffix}"}
+ %p Time:
+ %input.timepicker{:id => "silence_expire_at_time_#{suffix}"}
+%div.modal-footer
+ - if len > 0
+ %a.silence-submit-event.btn.btn-inverse{:control => "silence_submit_#{suffix}", :index_id => i, :misc => suffix, :rel => "/events/#{suffix.sub("_","/")}/silence"} Submit
+ - else
+ %a.silence-submit-event.btn.btn-success{:control => "silence_submit_#{suffix}", :index_id => i, :misc => "#{suffix}", :rel => "/events/#{suffix.sub("_","/")}/silence"} Submit
diff --git a/app/views/events/_modals.html.haml b/app/views/events/_modals.html.haml
index dc50c17..dbfbb1e 100644
--- a/app/views/events/_modals.html.haml
+++ b/app/views/events/_modals.html.haml
@@ -2,6 +2,7 @@
- @events.each_with_index do |event,i|
- processed_clients = []
+ - len = Setting.min_desc_length.to_i
%div{:class => "modal small-modal hide", :id => "modal_#{event.client}_#{event.check}"}
%div.modal-header
%h3== Silence check #{event.check} on client #{event.client}
@@ -9,7 +10,7 @@
%p.pull-left Note: Your event handler must use sensu-plugin or hit the API to make use of silencing.
%br
%h3 Enter reason
- %textarea.input-xlarge.silence-input{:id => "text_input_#{event.client}_#{event.check}", :index_id => "#{i}", :misc => "#{event.client}_#{event.check}", :rel => "Silence Check", :rows => "3", :type => "text", :placeholder => "Silence Check Reason"}
+ %textarea.input-xlarge.silence-input{:id => "text_input_#{event.client}_#{event.check}", :index_id => "#{i}", :data => {:min => len}, :misc => "#{event.client}_#{event.check}", :rel => "Silence Check", :rows => "3", :type => "text", :placeholder => "Silence Check Reason"}
%br
%h3 Expire at (Optional):
%div
@@ -19,10 +20,11 @@
%p Time:
%input.timepicker{:id => "silence_expire_at_time_#{event.client}_#{event.check}"}
%div.modal-footer
- %div.alert.alert-error{:id => "no_input_#{event.client}_#{event.check}", :style => "display: none; float: left;" }
- %p You need to enter a reason over 12 chars before you can submit!
- %a.silence-submit-event.btn.btn-success{:control => "silence_submit_#{event.client}_#{event.check}", :index_id => "#{i}", :misc => "#{event.client}_#{event.check}", :rel => "/events/#{event.client}/#{event.check}/silence", :style => "display: none;"} Submit
- %a.silence-submit-event.btn.btn-inverse{:control => "silence_grey_submit_#{event.client}_#{event.check}", :index_id => "#{i}", :misc => "#{event.client}_#{event.check}"} Submit
+ - if len > 0
+ %a.silence-submit-event.btn.btn-inverse{:control => "silence_submit_#{event.client}_#{event.check}", :index_id => "#{i}", :misc => "#{event.client}_#{event.check}", :rel => "/events/#{event.client}/#{event.check}/silence"} Submit
+ - else
+ %a.silence-submit-event.btn.btn-success{:control => "silence_submit_#{event.client}_#{event.check}", :index_id => "#{i}", :misc => "#{event.client}_#{event.check}", :rel => "/events/#{event.client}/#{event.check}/silence"} Submit
+
- unless processed_clients.include?(event.client)
- processed_clients << event.client
%div{:class => "small-modal modal hide", :id => "modal_#{event.client}"}
@@ -32,7 +34,7 @@
%p.pull-left Note: Your event handler must use sensu-plugin or hit the API to make use of silencing.
%br
%h3 Enter reason
- %textarea.input-xlarge.silence-input{:id => "text_input_#{event.client}", :index_id => "#{i}", :misc => "#{event.client}", :rel => "Silence Check", :rows => "3", :type => "text", :placeholder => "Silence Client Reason"}
+ %textarea.input-xlarge.silence-input{:id => "text_input_#{event.client}", :index_id => "#{i}", :data => {:min => len}, :misc => "#{event.client}", :rel => "Silence Check", :rows => "3", :type => "text", :placeholder => "Silence Client Reason"}
%br
%h3 Expire at (Optional):
%div
@@ -42,7 +44,6 @@
%p Time:
%input.timepicker{:id => "silence_expire_at_time_#{event.client}"}
%div.modal-footer
- %div.alert.alert-error{:id => "no_input_#{event.client}", :style => "float: left;"}
- %p You need to enter a reason over 12 chars before you can submit!
- %a.silence-submit-event.btn.btn-success{:control => "silence_submit_#{event.client}", :index_id => "#{i}", :style => "display: none;", :misc => "#{event.client}", :rel => "/events/#{event.client}/silence"} Submit
- %a.silence-submit-event.btn.btn-inverse{:control => "silence_grey_submit_#{event.client}", :index_id => "#{i}", :misc => "#{event.client}"} Submit
+ %a.silence-submit-event.btn.btn-success{:control => "silence_submit_#{event.client}", :index_id => "#{i}", :misc => "#{event.client}", :rel => "/events/#{event.client}/silence"} Submit
+ - if len > 0
+ %a.silence-submit-event.btn.btn-inverse{:control => "silence_grey_submit_#{event.client}", :index_id => "#{i}", :misc => "#{event.client}"} Submit
diff --git a/app/views/events/_output.html.haml b/app/views/events/_output.html.haml
index f4b8d95..3fbe71d 100644
--- a/app/views/events/_output.html.haml
+++ b/app/views/events/_output.html.haml
@@ -1 +1 @@
-= format_output(event.output, 240)
+= event.output
diff --git a/app/views/events/_table.html.haml b/app/views/events/_table.html.haml
index 3ddde53..7b16b81 100644
--- a/app/views/events/_table.html.haml
+++ b/app/views/events/_table.html.haml
@@ -1,5 +1,4 @@
-= render 'modals'
-
+%div{:class => "modal large-modal hide", :id => "event-data-modal"}
%div{:style => "display: none;", :id => "use_environments", :rel => "#{use_environments?}"}
%table.span12.dataTable.events_table.table{'data-source' => '/events/events_table', :border => "0", :cellpadding => "0", :cellspacing => "0", :id => "primary_events_table", :style => "width: 100%;"}
%thead
diff --git a/app/views/settings/index.html.haml b/app/views/settings/index.html.haml
index caa6a9e..d3f4510 100644
--- a/app/views/settings/index.html.haml
+++ b/app/views/settings/index.html.haml
@@ -1,7 +1,7 @@
%div
= semantic_form_for @sensu_api_server do |f|
.row
- %div.span8
+ %div.span8#api_url
= f.input :value, :label => "Sensu API Server url"
= f.actions
%div.span4
diff --git a/app/views/stashes/_stash_row.html.haml b/app/views/stashes/_stash_row.html.haml
index 81fe093..53ffe8c 100644
--- a/app/views/stashes/_stash_row.html.haml
+++ b/app/views/stashes/_stash_row.html.haml
@@ -1,15 +1,15 @@
-%tr{:id => "stash-#{i}"}
+%tr{:id => "#{path}"}
%td.span5= path
- %td.span4= content_item['description'] || ''
- %td= content_item['owner'] || ''
- - if content_item['expire_at']
- %td= distance_of_time_in_words(Time.now, Time.parse(content_item['expire_at']))
+ %td.span4= content['description'] || ''
+ %td= content['owner'] || ''
+ - if content['expire_at']
+ %td= distance_of_time_in_words(Time.now, Time.parse(content['expire_at']))
- else
%td Never
%td
- - if content_item['timestamp'].to_i
- = time_ago_in_words(Time.at(content_item['timestamp'].to_i)) + " ago"
+ - if content['timestamp'].to_i
+ = time_ago_in_words(Time.at(content['timestamp'].to_i)) + " ago"
- else
= 'Not set'
- %td
- %a.delete-stash{:key => path, :misc => "#stash-#{i}", :rel => "/stashes/delete_stash"} Delete
+ %td{:id => "delete-#{path}"}
+ %a.delete-stash{:id => path.gsub(/\//, "-"), :misc => "#stash-#{path}", :rel => "/stashes/delete_stash", :key => "#{path}"} Delete
diff --git a/app/views/stashes/_stash_row.mobile.haml b/app/views/stashes/_stash_row.mobile.haml
new file mode 100644
index 0000000..d200e01
--- /dev/null
+++ b/app/views/stashes/_stash_row.mobile.haml
@@ -0,0 +1,20 @@
+%li{'data-theme' => 'a', :id => "stash_#{i}"}
+ %h2= k
+ %p== Description: #{v['description']}
+ %p== Owner: #{v['owner']}
+ - if v['expire_at']
+ %p== Expires at: #{distance_of_time_in_words(Time.now, Time.parse(v['expire_at']))}
+ - else
+ %p Expires at: Never
+ %p== Set at: #{time_ago_in_words(Time.at(v['timestamp'].to_i))} ago
+ %ul
+ %li
+ %h2= k
+ %p== Attributes:
+ - v.each do |k,v|
+ %p== #{k} -> #{v}
+ %li{'data-theme' => 'b'}
+ %div{:id => "delete_#{i}"}
+ %button.delete-stash{:index => i, 'data-theme' => 'b', :key => k, :rel => "/stashes/delete_stash"} Delete Stash
+ %div{:id => "deleted_#{i}", :style => "display: none;"}
+ %button{'data-theme' => 'c'} Deleted!
diff --git a/app/views/stashes/_stash_row_legacy.html.haml b/app/views/stashes/_stash_row_legacy.html.haml
index 76a1bd3..12a7f6f 100644
--- a/app/views/stashes/_stash_row_legacy.html.haml
+++ b/app/views/stashes/_stash_row_legacy.html.haml
@@ -2,7 +2,7 @@
%td.span5= k
%td.span4= v['description'] unless v['description'].nil?
%td= v['owner']
- - if v['expire_at']
+ - if v['expire_at']
%td= distance_of_time_in_words(Time.now, Time.parse(v['expire_at']))
- else
%td Never
diff --git a/app/views/stashes/index.html.haml b/app/views/stashes/index.html.haml
index 63ba99d..8a68e79 100644
--- a/app/views/stashes/index.html.haml
+++ b/app/views/stashes/index.html.haml
@@ -62,8 +62,7 @@
%tbody
- if Gem::Version.new(@sensu_version) <= Gem::Version.new("0.9.11")
- @stashes.each_with_index do |(k,v), i|
- = render "stash_row_legacy"
+ = render "stash_row_legacy", :k => k, :v => v, :i => i
- else
- @stashes.each do |stash|
- - stash['content'].each_with_index do |content_item, i|
- = render "stash_row", :path => stash['path'], :content_item => Hash[*content_item], :i => i
+ = render "stash_row", :path => stash['path'], :content => stash['content']
diff --git a/app/views/stashes/index.mobile.haml b/app/views/stashes/index.mobile.haml
index 10a9d50..dd2b09b 100644
--- a/app/views/stashes/index.mobile.haml
+++ b/app/views/stashes/index.mobile.haml
@@ -6,24 +6,9 @@
%ul{'data-theme' => 'a', 'data-count-theme' => 'a', 'data-role' => 'listview', 'data-inset' => 'true'}
- if @stashes.empty?
%button{'data-theme' => 'c'} No Stashes
- - @stashes.each_with_index do |(k,v), i|
- %li{'data-theme' => 'a', :id => "stash_#{i}"}
- %h2= k
- %p== Description: #{v['description']}
- %p== Owner: #{v['owner']}
- - if v['expire_at']
- %p== Expires at: #{distance_of_time_in_words(Time.now, Time.parse(v['expire_at']))}
- - else
- %p Expires at: Never
- %p== Set at: #{time_ago_in_words(Time.at(v['timestamp'].to_i))} ago
- %ul
- %li
- %h2= k
- %p== Attributes:
- - v.each do |k,v|
- %p== #{k} -> #{v}
- %li{'data-theme' => 'b'}
- %div{:id => "delete_#{i}"}
- %button.delete-stash{:index => i, 'data-theme' => 'b', :key => k, :rel => "/stashes/delete_stash"} Delete Stash
- %div{:id => "deleted_#{i}", :style => "display: none;"}
- %button{'data-theme' => 'c'} Deleted!
+ - if Gem::Version.new(@sensu_version) <= Gem::Version.new("0.9.11")
+ - @stashes.each_with_index do |(k,v), i|
+ = render "stash_row", :k => k, :v => v, :i => i
+ - else
+ - @stashes.each_with_index do |stash, i|
+ = render "stash_row", :k => stash['path'], :v => stash['content'], :i => i
diff --git a/app/views/stats/index.html.haml b/app/views/stats/index.html.haml
index 368fb77..3376e47 100644
--- a/app/views/stats/index.html.haml
+++ b/app/views/stats/index.html.haml
@@ -5,7 +5,7 @@
.row
.span3
%p By Subscriptions:
- %table.table.table-striped.table-bordered
+ %table.table.table-striped.table-bordered#clients-by-subscriptions
%thead
%th Name
%th Count
@@ -16,7 +16,7 @@
%td= v
.span3
%p By Environment:
- %table.table.table-striped.table-bordered
+ %table.table.table-striped.table-bordered#clients-by-environment
%thead
%th Name
%th Count
@@ -32,7 +32,7 @@
%td= value_total
.span5
%p Misc stats
- %table.table.table-striped.table-bordered
+ %table.table.table-striped.table-bordered#clients-misc
%thead
%th Name
%th Count
@@ -54,7 +54,7 @@
.row
.span3
%p By Check:
- %table.table.table-striped.table-bordered
+ %table.table.table-striped.table-bordered#events-by-check
%thead
%th Name
%th Count
@@ -65,7 +65,7 @@
%td= v
.span2
%p By Environment:
- %table.table.table-striped.table-bordered
+ %table.table.table-striped.table-bordered#events-by-environment
%thead
%th Name
%th Count
@@ -81,7 +81,7 @@
%td= total_events
.span4
%p Events per client
- %table.table.table-striped.table-bordered
+ %table.table.table-striped.table-bordered#events-per-client
%thead
%th Client
%th Count
@@ -92,7 +92,7 @@
%td= v
.span3
%p Misc stats
- %table.table.table-striped.table-bordered
+ %table.table.table-striped.table-bordered#events-misc
%thead
%th Name
%th Count
diff --git a/config/database.yml b/config/database.yml
index 51a4dd4..62be10b 100644
--- a/config/database.yml
+++ b/config/database.yml
@@ -5,7 +5,7 @@
# gem 'sqlite3'
development:
adapter: sqlite3
- database: db/development.sqlite3
+ database: db/development.sqlite3
pool: 5
timeout: 5000
@@ -20,6 +20,6 @@ test:
production:
adapter: sqlite3
- database: db/production.sqlite3
+ database: db/production.sqlite3
pool: 5
timeout: 5000
diff --git a/config/routes.rb b/config/routes.rb
index a1d0ea9..e998b10 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -11,7 +11,8 @@
scope 'events' do
match 'events_table' => 'events#events_table', :via => :get
match 'modal_data' => 'events#modal_data', :via => :get
- scope '/:client', :constraints => { :client => /[\w.\-]+/ } do
+ match 'modal_silence' => 'events#modal_silence', :via => :get
+ scope '/:client', :constraints => { :client => /[\w.-]+/ } do
match '/silence' => 'events#silence_client', :via => :post
match '/unsilence' => 'events#unsilence_client', :via => :post
scope '/:check' do
@@ -34,6 +35,11 @@
end
match 'checks/:check/submit' => 'checks#submit_check', :via => :post
+
+ scope 'clients' do
+ match '/delete_client' => 'clients#delete_client', :via => :post
+ match '/modal_data' => 'clients#modal_data', :via => :get
+ end
namespace :api do
match '/status' => 'api#status', :via => :get
diff --git a/db/seeds.rb b/db/seeds.rb
index 667b1ea..d182b14 100644
--- a/db/seeds.rb
+++ b/db/seeds.rb
@@ -24,3 +24,7 @@
unless Setting.find_by_name("configure_server")
Setting.create(:name => "configure_server", :value => "true")
end
+
+unless Setting.find_by_name("min_desc_length")
+ Setting.create(:name => "min_desc_length", :value => "0")
+end
diff --git a/spec/controllers/aggregates_controller_spec.rb b/spec/controllers/aggregates_controller_spec.rb
new file mode 100644
index 0000000..ae75e83
--- /dev/null
+++ b/spec/controllers/aggregates_controller_spec.rb
@@ -0,0 +1,13 @@
+require 'spec_helper'
+
+describe AggregatesController do
+ login_user
+
+ describe "GET 'index'" do
+ it "returns http success" do
+ get 'index'
+ response.code.should eq "200"
+ end
+ end
+
+end
diff --git a/spec/controllers/api_controller_spec.rb b/spec/controllers/api_controller_spec.rb
new file mode 100644
index 0000000..a342642
--- /dev/null
+++ b/spec/controllers/api_controller_spec.rb
@@ -0,0 +1,34 @@
+require 'spec_helper'
+
+describe Api::ApiController do
+ login_user
+
+ describe "GET 'status'" do
+ it "returns http success" do
+ get 'status'
+ response.code.should eq "200"
+ end
+ end
+
+ describe "GET 'time'" do
+ it "returns http success" do
+ get 'time'
+ response.code.should eq "200"
+ end
+ end
+
+ describe "GET 'setup'" do
+ it "returns http success" do
+ get 'setup'
+ response.code.should eq "200"
+ end
+ end
+
+ describe "GET 'test_api'" do
+ it "returns http success" do
+ get 'test_api'
+ response.code.should eq "200"
+ end
+ end
+
+end
diff --git a/spec/controllers/checks_controller_spec.rb b/spec/controllers/checks_controller_spec.rb
new file mode 100644
index 0000000..4a7d9aa
--- /dev/null
+++ b/spec/controllers/checks_controller_spec.rb
@@ -0,0 +1,21 @@
+require 'spec_helper'
+
+describe ChecksController do
+ login_user
+
+ describe "GET 'index'" do
+ it "returns http success" do
+ get 'index'
+ response.code.should eq "200"
+ end
+ end
+
+ describe "GET 'submit_check'" do
+ it "returns http success" do
+ # todo
+ # get 'submit_check', {:check => 1}
+ # response.code.should eq "200"
+ end
+ end
+
+end
diff --git a/spec/controllers/clients_controller_spec.rb b/spec/controllers/clients_controller_spec.rb
new file mode 100644
index 0000000..c14bcba
--- /dev/null
+++ b/spec/controllers/clients_controller_spec.rb
@@ -0,0 +1,21 @@
+require 'spec_helper'
+
+describe ClientsController do
+ login_user
+
+ describe "GET 'index'" do
+ it "returns http success" do
+ get 'index'
+ response.code.should eq "200"
+ end
+ end
+
+ describe "DELETE 'destroy'" do
+ it "returns http success" do
+ # todo: no template
+ # delete 'destroy', {:id => 1}
+ # response.code.should eq "202"
+ end
+ end
+
+end
diff --git a/spec/controllers/downtimes_controller_spec.rb b/spec/controllers/downtimes_controller_spec.rb
new file mode 100644
index 0000000..a95fe2e
--- /dev/null
+++ b/spec/controllers/downtimes_controller_spec.rb
@@ -0,0 +1,82 @@
+require 'spec_helper'
+
+describe DowntimesController do
+ login_user
+
+ before :all do
+ @downtime = Downtime.create(:name => "test_downtime", :user_id => 1, :start_time => Time.now, :stop_time => Time.now + 1.hour)
+ end
+
+ describe "GET 'index'" do
+ it "returns http success" do
+ get 'index'
+ response.code.should eq "200"
+ end
+ end
+
+ describe "GET 'new'" do
+ it "returns http success" do
+ # get 'new'
+ # response.code.should eq "200"
+ end
+ end
+
+ describe "GET 'create'" do
+ it "returns http success" do
+ # get 'create'
+ # response.code.should eq "200"
+ end
+ end
+
+ describe "GET 'old_downtimes'" do
+ it "returns http success" do
+ get 'old_downtimes'
+ response.code.should eq "200"
+ end
+ end
+
+ describe "GET 'show'" do
+ it "returns http success" do
+ # get 'show'
+ # response.code.should eq "200"
+ end
+ end
+
+ describe "GET 'edit'" do
+ it "returns http success" do
+ get 'edit', {:id => 1}
+ response.code.should eq "200"
+ end
+ end
+
+ describe "GET 'update'" do
+ it "returns http success" do
+ downtime = FactoryGirl.create(:downtime)
+ downtime_client = FactoryGirl.build(:downtime_client)
+ downtime_client.downtime_id = downtime.id
+ downtime_client.save
+ setting = FactoryGirl.create(:setting)
+ # get 'update', {:id => downtime.id}
+ # response.code.should eq "200"
+ end
+ end
+
+ describe "GET 'force_complete'" do
+ it "returns http success" do
+ # todo
+ # get 'force_complete', {:id => 1, :downtime_id => 1}
+ # response.code.should eq "200"
+ end
+ end
+
+ describe "GET 'destroy'" do
+ context "when admin is not logged in" do
+ it "returns http success" do
+
+ get 'destroy', {:id => 1, :downtime_id => 1}
+ response.code.should eq "302"
+ end
+ end
+ end
+
+end
diff --git a/spec/controllers/events_controller_spec.rb b/spec/controllers/events_controller_spec.rb
new file mode 100644
index 0000000..123d701
--- /dev/null
+++ b/spec/controllers/events_controller_spec.rb
@@ -0,0 +1,67 @@
+require 'spec_helper'
+
+describe EventsController do
+ login_user
+
+ describe "GET 'index'" do
+ it "returns http success" do
+ get 'index'
+ response.code.should eq "200"
+ end
+ end
+
+ describe "GET 'events_table'" do
+ it "returns http success" do
+ get 'events_table', {:client => 1}
+ response.code.should eq "406"
+ end
+ end
+
+ describe "GET 'modal_data'" do
+ it "returns http success" do
+ get 'modal_data', {:client => 1}
+ response.code.should eq "200"
+ end
+ end
+
+ describe "GET 'resolve'" do
+ it "returns http success" do
+ # todo
+ # get 'resolve', {:client => 1, :check => 1}
+ # response.code.should eq "200"
+ end
+ end
+
+ describe "GET 'silence_client'" do
+ it "returns http success" do
+ # todo
+ # get 'silence_client', {:client =>1}
+ # response.code.should eq "200"
+ end
+ end
+
+ describe "GET 'silence_check'" do
+ it "returns http success" do
+ # todo
+ # get 'silence_check', {:client => 1, :check => 1, :description => "this is a test description", :user => User.first}
+ # response.code.should eq "200"
+ end
+ end
+
+ describe "GET 'unsilence_check'" do
+ it "returns http success" do
+ # todo
+ # get 'unsilence_check', {:client => 1, :check => 1}
+ # response.code.should eq "200"
+ end
+ end
+
+ describe "GET 'unslience_client'" do
+ it "returns http success" do
+ # todo
+ # get 'unslience_client', {:client => 1}
+ # response.code.should eq "200"
+ end
+ end
+
+end
diff --git a/spec/controllers/logs_controller_spec.rb b/spec/controllers/logs_controller_spec.rb
new file mode 100644
index 0000000..8d8870b
--- /dev/null
+++ b/spec/controllers/logs_controller_spec.rb
@@ -0,0 +1,13 @@
+require 'spec_helper'
+
+describe LogsController do
+ login_user
+
+ describe "GET 'index'" do
+ it "returns http success" do
+ get 'index'
+ response.code.should eq "200"
+ end
+ end
+
+end
diff --git a/spec/controllers/settings_controller_spec.rb b/spec/controllers/settings_controller_spec.rb
new file mode 100644
index 0000000..dd86664
--- /dev/null
+++ b/spec/controllers/settings_controller_spec.rb
@@ -0,0 +1,35 @@
+require 'spec_helper'
+
+describe SettingsController do
+ login_user
+
+ describe "GET 'index'" do
+ it "returns http success" do
+ get 'index'
+ response.code.should eq "200"
+ end
+ end
+
+ describe "GET 'missing'" do
+ it "returns http success" do
+ get 'missing'
+ response.code.should eq "200"
+ end
+ end
+
+ describe "GET 'create'" do
+ it "returns http success" do
+ get 'create'
+ response.code.should eq "302"
+ end
+ end
+
+ describe "PUT 'update'" do
+ it "returns http success" do
+ setting = FactoryGirl.create(:setting)
+ put 'update', {:id => 1, :setting => {:name => setting.name}}
+ response.code.should eq "302"
+ end
+ end
+
+end
diff --git a/spec/controllers/stashes_controller_spec.rb b/spec/controllers/stashes_controller_spec.rb
new file mode 100644
index 0000000..e60792b
--- /dev/null
+++ b/spec/controllers/stashes_controller_spec.rb
@@ -0,0 +1,14 @@
+require 'spec_helper'
+
+describe StashesController do
+ login_user
+
+ describe "GET 'index'" do
+ it "returns http success" do
+ # todo
+ # get 'index'
+ # response.code.should eq "200"
+ end
+ end
+
+end
diff --git a/spec/controllers/stats_controller_spec.rb b/spec/controllers/stats_controller_spec.rb
new file mode 100644
index 0000000..54a6f42
--- /dev/null
+++ b/spec/controllers/stats_controller_spec.rb
@@ -0,0 +1,13 @@
+require 'spec_helper'
+
+describe StatsController do
+ login_user
+
+ describe "GET 'index'" do
+ it "returns http success" do
+ get 'index'
+ response.code.should eq "200"
+ end
+ end
+
+end
diff --git a/spec/controllers/users_controller_spec.rb b/spec/controllers/users_controller_spec.rb
new file mode 100644
index 0000000..cb2314d
--- /dev/null
+++ b/spec/controllers/users_controller_spec.rb
@@ -0,0 +1,75 @@
+require 'spec_helper'
+
+describe UsersController do
+ login_user
+
+ before :each do
+ @user = FactoryGirl.create(:user)
+ end
+
+ describe "GET 'index'" do
+ it "returns http success" do
+ get 'index'
+ response.code.should eq "200"
+ end
+ end
+
+ describe "GET 'new'" do
+ it "returns http success" do
+ get 'new'
+ response.code.should eq "200"
+ end
+ end
+
+ describe "GET 'create'" do
+ it "returns http success" do
+ get 'create'
+ response.code.should eq "200"
+ end
+ end
+
+ describe "GET 'edit'" do
+ it "returns http success" do
+ get 'edit', :id => @user.id
+ response.code.should eq "200"
+ end
+ end
+
+ describe "GET 'update_password'" do
+ it "returns http success" do
+ # todo
+ # get 'update_password', {:id => @user.id, :password => "123456", :password_confirmation => "123456"}
+ # response.code.should eq "302"
+ end
+ end
+
+ describe "GET 'show'" do
+ it "returns http success" do
+ get 'show', {:id => @user.id}
+ response.code.should eq "200"
+ end
+ end
+
+ describe "GET 'update'" do
+ it "returns http success" do
+ put 'update', {:id => @user.id, :user => {:role_ids => 1}}
+ response.code.should eq "302"
+ end
+ end
+
+ describe "GET 'destroy'" do
+ it "returns http success" do
+ # TODO
+ # get 'destroy'
+ # response.code.should eq "200"
+ end
+ end
+
+ describe "GET 'activate'" do
+ it "returns http success" do
+ get 'activate', :id => 1
+ response.code.should eq "302"
+ end
+ end
+
+end
diff --git a/spec/factories.rb b/spec/factories.rb
new file mode 100644
index 0000000..2c51633
--- /dev/null
+++ b/spec/factories.rb
@@ -0,0 +1,56 @@
+require 'factory_girl'
+
+FactoryGirl.define do
+
+ ## Users/Roles
+ factory :user do
+ sequence :email do |n|
+ "test_user#{n}@example.com"
+ end
+ password '123456'
+ password_confirmation '123456'
+
+ factory :roles do
+ name "admin"
+ user
+ end
+ end
+
+ factory :role do
+ end
+
+ ## Downtimes
+ factory :downtime do
+ name "maintenance"
+ description "shutting it down for maintenance"
+ start_time { Time.now + 1.hour }
+ stop_time { Time.now + 2.hours }
+ user_id 1
+ end
+
+ factory :downtime_client do
+ name "test_downtime_client"
+ downtime
+
+ factory :downtime_in_past do
+ end
+ end
+
+ factory :downtime_check do
+ # belongs_to :downtime
+ sequence :name do |n|
+ "test_downtime_check_#{n}"
+ end
+ end
+
+ factory :client do
+ name "test_client"
+ end
+
+ ## Setting
+ factory :setting do
+ name "test_configure_server"
+ value true
+ end
+
+end
diff --git a/spec/fake_sensu/config.ru b/spec/fake_sensu/config.ru
new file mode 100644
index 0000000..b62fe55
--- /dev/null
+++ b/spec/fake_sensu/config.ru
@@ -0,0 +1,2 @@
+require File.expand_path 'spec/fake_sensu/fake_sensu'
+run FakeSensu
diff --git a/spec/fake_sensu/fake_sensu.rb b/spec/fake_sensu/fake_sensu.rb
new file mode 100644
index 0000000..17aa756
--- /dev/null
+++ b/spec/fake_sensu/fake_sensu.rb
@@ -0,0 +1,168 @@
+require 'sinatra'
+require 'json'
+
+class FakeSensu < Sinatra::Base
+
+ configure do
+ set :info, "{\"sensu\":{\"version\":\"0.9.12.beta.6\"},\"rabbitmq\":{\"keepalives\":{\"messages\":null,\"consumers\":null},\"results\":{\"messages\":null,\"consumers\":null},\"connected\":false},\"redis\":{\"connected\":true}}"
+ set :clients, "[{\"name\":\"i-424242\",\"address\":\"127.0.0.1\",\"subscriptions\":[\"test\"],\"nested\":{\"attribute\":true},\"timestamp\":1364343737}]"
+ set :checks, "[{\"command\":\"echo -n OK\",\"subscribers\":[\"test\"],\"interval\":60,\"name\":\"test\"},{\"command\":\"echo -n OK\",\"subscribers\":[\"tokens\"],\"interval\":60,\"name\":\"tokens\"}]"
+ set :events, "[{\"output\":\"i-424242 true\",\"status\":2,\"issued\":1364343741,\"handlers\":[\"default\"],\"flapping\":false,\"occurrences\":11828,\"client\":\"i-424242\",\"check\":\"tokens\"},{\"output\":\"foobar\",\"status\":1,\"issued\":1364343741,\"handlers\":[\"default\"],\"flapping\":false,\"occurrences\":11828,\"client\":\"i-424242\",\"check\":\"standalone\"}]"
+ set :stashes, "[{\"path\":\"silence/i-424242/tokens\",\"content\":{\"timestamp\":1364332102}},{\"path\":\"silence/i-424242/standalone\",\"content\":{\"timestamp\":1364332111}}]"
+ set :immutable_info, info.freeze
+ set :immutable_clients, clients.freeze
+ set :immutable_checks, checks.freeze
+ set :immutable_events, events.freeze
+ set :immutable_stashes, stashes.freeze
+ end
+
+ get '/info' do
+ content_type :json
+ body settings.info
+ end
+
+ get '/clients' do
+ content_type :json
+ settings.clients
+ end
+
+ get %r{/clients/([\w\.-]+)$} do |client_name|
+ content_type :json
+ clients = JSON.parse(settings.clients)
+ clients.each do |client|
+ clients.each do |client|
+ if client.has_value? client_name
+ @body = client.reject! {|k| k == "name"}.to_json
+ end
+ end
+ end
+ @body ? "#{@body}" : ""
+ end
+
+ get '/checks' do
+ content_type :json
+ settings.checks
+ end
+
+ get %r{/checks?/([\w\.-]+)$} do |check_name|
+ content_type :json
+ checks = JSON.parse(settings.checks)
+ checks.each do |check|
+ if check.has_value? check_name
+ @body = check.to_json
+ end
+ end
+ @body ? "#{@body}" : ""
+ end
+
+ post %r{/(?:check/)?request$} do
+ post_body = JSON.parse(request.body.read)
+ check_name = post_body["check"]
+ check = post_body["check"]
+ subscribers = check["subscribers"].to_a
+ command = check["command"]
+ payload = {
+ :name => check_name,
+ :command => command,
+ :issued => Time.now.to_i
+ }
+ body payload
+ end
+
+ get '/events' do
+ content_type :json
+ body settings.events
+ end
+
+ get %r{/events/([\w\.-]+)$} do |client_name|
+ content_type :json
+ events = JSON.parse(settings.events)
+ events.each do |event|
+ if event.has_value? client_name
+ @body = event.to_json
+ end
+ end
+ @body ? "#{@body}" : ""
+ end
+
+ get %r{/events?/([\w\.-]+)/([\w\.-]+)$} do |client_name, check_name|
+ content_type :json
+ event_json = settings.events[client_name]
+ unless event_json.nil?
+ event_json[:client_name] = check
+ event_json[:check_name] = check_name
+ @body = event_json
+ end
+ end
+
+ delete %r{/events?/([\w\.-]+)/([\w\.-]+)$} do |client_name, check_name|
+ content_type :json
+ events = JSON.parse(settings.events)
+ events.each do |event|
+ if event["client"] == client_name && event["check"] == check_name
+ events.delete_if {|e| e.has_value? check_name}
+ # settings.events = events.to_s
+ end
+ end
+ body ''
+ end
+
+ get '/stashes' do
+ content_type :json
+ body settings.stashes
+ end
+
+ get %r{/stash(?:es)?/(.*)} do |path|
+ content_type :json
+ stashes = JSON.parse(settings.stashes)
+ stashes.each do |stash|
+ if stash.has_value? path
+ @body = stash["content"]
+ end
+ end
+ @body ? "#{@body}" : ""
+ end
+
+ post %r{/stash(?:es)?/(.*)} do |path|
+ content_type :json
+ stashes = JSON.parse(settings.stashes)
+ stashes = stashes + [{"path" => path, "content" => {"timestamp" => Time.now.to_i}}]
+ settings.stashes = stashes.to_json
+ body ''
+ end
+
+ post '/stashes' do
+ content_type :json
+ post_body = JSON.parse(request.body.read)
+ path = post_body["path"]
+ content = post_body["content"]
+ stashes = JSON.parse(settings.stashes)
+ stashes = stashes + [{"path" => path, "content" => content}]
+ settings.stashes = stashes.to_json
+ end
+
+ delete %r{/stash(?:es)?/(.*)} do |path|
+ content_type :json
+ stashes = JSON.parse(settings.stashes)
+ stashes.each do |stash|
+ if stash.has_value? path
+ stashes.delete_if {|stash| stash.has_value? path}
+ settings.stashes = stashes.to_json
+ body = ''
+ else
+ body = 'not found'
+ end
+ end
+ body
+ end
+
+ get '/reset' do
+ settings.info = settings.immutable_info
+ settings.clients = settings.immutable_clients
+ settings.checks = settings.immutable_checks
+ settings.events = settings.immutable_events
+ settings.stashes = settings.immutable_stashes
+ body ''
+ end
+
+end
diff --git a/test/fixtures/.gitkeep b/spec/features/.gitkeep
similarity index 100%
rename from test/fixtures/.gitkeep
rename to spec/features/.gitkeep
diff --git a/spec/features/aggregates_features_spec.rb b/spec/features/aggregates_features_spec.rb
new file mode 100644
index 0000000..ae7ff06
--- /dev/null
+++ b/spec/features/aggregates_features_spec.rb
@@ -0,0 +1,19 @@
+require 'spec_helper'
+
+describe "Aggregates" do
+ before :all do
+ load "#{Rails.root}/db/seeds.rb"
+ end
+
+ before :each do
+ user = FactoryGirl.create(:user)
+ user.add_role :admin
+ sign_in_user(user)
+ visit '/aggregates'
+ end
+
+ it "should show the aggregates page" do
+ page.should have_content "Aggregates"
+ end
+
+end
diff --git a/spec/features/application_features_spec.rb b/spec/features/application_features_spec.rb
new file mode 100644
index 0000000..09b9040
--- /dev/null
+++ b/spec/features/application_features_spec.rb
@@ -0,0 +1,24 @@
+require 'spec_helper'
+
+describe "Applicaiton" do
+
+ before :all do
+ load "#{Rails.root}/db/seeds.rb"
+ end
+
+ before :each do
+ user = FactoryGirl.create(:user)
+ user.add_role :admin
+ sign_in_user(user)
+ end
+
+ pending "should redirect to the settings page if the api does not connect" do
+ visit '/settings'
+ fill_in "setting_value", :with => "::55467"
+ within("#api_url") do
+ click_on("Update Setting")
+ end
+ page.body.should include "Please enter in your api server"
+ end
+
+end
diff --git a/spec/features/checks_features_spec.rb b/spec/features/checks_features_spec.rb
new file mode 100644
index 0000000..c5da9f9
--- /dev/null
+++ b/spec/features/checks_features_spec.rb
@@ -0,0 +1,24 @@
+require 'spec_helper'
+
+describe "Checks" do
+ before :all do
+ load "#{Rails.root}/db/seeds.rb"
+ end
+
+ before :each do
+ user = FactoryGirl.create(:user)
+ user.add_role :admin
+ sign_in_user(user)
+ visit '/checks'
+ end
+
+ it "should show the checks page" do
+ page.should have_content "Checks"
+ end
+
+ it "should show a list of checks" do
+ page.should have_content "test"
+ end
+
+end
+
diff --git a/spec/features/client_features_spec.rb b/spec/features/client_features_spec.rb
new file mode 100644
index 0000000..08d0f1f
--- /dev/null
+++ b/spec/features/client_features_spec.rb
@@ -0,0 +1,35 @@
+require 'spec_helper'
+
+describe "Clients" do
+ before :all do
+ load "#{Rails.root}/db/seeds.rb"
+ end
+
+ before :each do
+ user = FactoryGirl.create(:user)
+ user.add_role :admin
+ sign_in_user(user)
+ visit '/clients'
+ end
+
+ it "should show the clients page" do
+ page.should have_content "Clients"
+ end
+
+ it "should a client name" do
+ page.should have_content "i-424242"
+ end
+
+ it "should show a client address" do
+ page.should have_content "127.0.0.1"
+ end
+
+ it "should show subscriptions" do
+ page.should have_content "test"
+ end
+
+ it "should show a client time" do
+ page.should have_content time_ago_in_words(Time.at(1364343737))
+ end
+
+end
diff --git a/spec/features/downtimes_features_spec.rb b/spec/features/downtimes_features_spec.rb
new file mode 100644
index 0000000..dc28cec
--- /dev/null
+++ b/spec/features/downtimes_features_spec.rb
@@ -0,0 +1,19 @@
+require 'spec_helper'
+
+describe "Downtimes" do
+ before :all do
+ load "#{Rails.root}/db/seeds.rb"
+ end
+
+ before :each do
+ user = FactoryGirl.create(:user)
+ user.add_role :admin
+ sign_in_user(user)
+ visit '/downtimes'
+ end
+
+ it "should show the downtimes page" do
+ page.should have_content "Active downtimes"
+ end
+
+end
diff --git a/spec/features/events_features_spec.rb b/spec/features/events_features_spec.rb
new file mode 100644
index 0000000..a4c0f88
--- /dev/null
+++ b/spec/features/events_features_spec.rb
@@ -0,0 +1,44 @@
+require 'spec_helper'
+
+describe "Events" do
+
+ context "When API fully functional" do
+ before :all do
+ load "#{Rails.root}/db/seeds.rb"
+ end
+
+ before :each do
+ user = FactoryGirl.create(:user)
+ user.add_role :admin
+ sign_in_user(user)
+ visit '/events'
+ end
+
+ it "should show the events page" do
+ page.should have_content "Events"
+ end
+
+ it "should show multiple events", :js => true do
+ page.should have_content "standalone"
+ page.should have_content "tokens"
+ end
+
+ it "should show the client for an event", :js => true do
+ page.should have_content "i-424242"
+ end
+
+ it "should show the check for an event", :js => true do
+ page.should have_content "standalone"
+ end
+
+ it "should show the output for an event", :js => true do
+ page.body.should have_content "i-424242 true"
+ end
+
+ it "should show time since issued for an event", :js => true do
+ page.should have_content time_ago_in_words(Time.at(1364343741))
+ end
+
+ end
+
+end
diff --git a/spec/features/logs_features_spec.rb b/spec/features/logs_features_spec.rb
new file mode 100644
index 0000000..ee9e85e
--- /dev/null
+++ b/spec/features/logs_features_spec.rb
@@ -0,0 +1,19 @@
+require 'spec_helper'
+
+describe "Logs" do
+ before :all do
+ load "#{Rails.root}/db/seeds.rb"
+ end
+
+ before :each do
+ user = FactoryGirl.create(:user)
+ user.add_role :admin
+ sign_in_user(user)
+ visit '/logs'
+ end
+
+ it "should show the logs page" do
+ page.should have_content "Logs"
+ end
+
+end
diff --git a/spec/features/stashes_features_spec.rb b/spec/features/stashes_features_spec.rb
new file mode 100644
index 0000000..bdd1429
--- /dev/null
+++ b/spec/features/stashes_features_spec.rb
@@ -0,0 +1,39 @@
+require 'spec_helper'
+
+describe "Stashes" do
+ before :all do
+ load "#{Rails.root}/db/seeds.rb"
+ end
+
+ before :each do
+ user = FactoryGirl.create(:user)
+ user.add_role :admin
+ sign_in_user(user)
+ visit '/stashes'
+ end
+
+ it "should show the stashes page" do
+ page.should have_content "Stashes"
+ end
+
+ it "should show the correct stash count" do
+ page.should have_content "Stashes (#{Stash.all.count})"
+ end
+
+ it "should show stashes and correct data" do
+ page.should have_content "silence/i-424242/tokens"
+ page.should have_content "Never"
+ page.should have_content time_ago_in_words(Time.at(1364332102))
+ end
+
+ it "should have a delete link" do
+ page.should have_button "Delete"
+ end
+
+ pending "should allow deletion of a stash", :js => true do
+ page.should have_selector("#silence-i-424242-tokens", :text => "Delete")
+ find("#silence-i-424242-tokens", :text => "Delete").click
+ page.should_not have_selector("#silence-i-424242-tokens", :text => "Delete")
+ end
+
+end
diff --git a/spec/features/stats_features_spec.rb b/spec/features/stats_features_spec.rb
new file mode 100644
index 0000000..eebcac5
--- /dev/null
+++ b/spec/features/stats_features_spec.rb
@@ -0,0 +1,58 @@
+require 'spec_helper'
+
+describe "Stats" do
+ before :all do
+ load "#{Rails.root}/db/seeds.rb"
+ end
+
+ before :each do
+ user = FactoryGirl.create(:user)
+ user.add_role :admin
+ sign_in_user(user)
+ visit '/stats'
+ end
+
+ it "should show the stats page" do
+ page.should have_content "Stats"
+ end
+
+ it "should show clients by subscriptions" do
+ within("#clients-by-subscriptions") { find("td", :text => "test") }
+ end
+
+ it "should show clients by environment" do
+ within("#clients-by-environment") { find("td", :text => "None") }
+ end
+
+ it "should show miscellaneous client stats" do
+ within("#clients-misc tbody") do
+ find("td", :text => "Total Clients")
+ page.should have_content Client.all.count
+ end
+ end
+
+ it "should show events by check" do
+ within("#events-by-check") do
+ page.should have_content "tokens"
+ end
+ end
+
+ it "should show events by environment" do
+ within("#events-by-environment") do
+ page.should have_content "2"
+ end
+ end
+
+ it "should show events per client" do
+ within("#events-per-client") do
+ page.should have_content "i-424242"
+ end
+ end
+
+ it "should show miscellaneous event stats" do
+ within("#events-misc") do
+ page.should have_content "Total Events"
+ end
+ end
+
+end
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
new file mode 100644
index 0000000..97c5302
--- /dev/null
+++ b/spec/spec_helper.rb
@@ -0,0 +1,70 @@
+# This file is copied to spec/ when you run 'rails generate rspec:install'
+ENV["RAILS_ENV"] ||= 'test'
+require File.expand_path("../../config/environment", __FILE__)
+require 'rspec/rails'
+require 'rspec/autorun'
+require 'capybara/rspec'
+require 'capybara/poltergeist'
+include ActionView::Helpers::DateHelper
+
+Capybara.configure do |config|
+ config.ignore_hidden_elements = true
+end
+Capybara.javascript_driver = :poltergeist
+
+# Requires supporting ruby files with custom matchers and macros, etc,
+# in spec/support/ and its subdirectories.
+Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
+
+# seed database
+
+RSpec.configure do |config|
+ # ## Mock Framework
+ #
+ # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
+ #
+ # config.mock_with :mocha
+ # config.mock_with :flexmock
+ # config.mock_with :rr
+
+ config.before :suite do
+ puts "starting fake sensu api!"
+ setting = Setting.find_or_create_by_name("api_server")
+ setting.value = "localhost:9292"
+ setting.save
+ $fake_sensu_pid = Process.spawn("rackup --env production #{Rails.root}/spec/fake_sensu/config.ru", :out => "/dev/stdout")
+ sleep 1
+ end
+
+ config.after :suite do
+ puts "\nstopping fake sensu api @ #{$fake_sensu_pid}!"
+ Process.kill 9, $fake_sensu_pid
+ end
+
+
+ # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
+ config.fixture_path = "#{::Rails.root}/spec/fixtures"
+
+ # If you're not using ActiveRecord, or you'd prefer not to run each of your
+ # examples within a transaction, remove the following line or assign false
+ # instead of true.
+ config.use_transactional_fixtures = true
+
+ # If true, the base class of anonymous controllers will be inferred
+ # automatically. This will be the default behavior in future versions of
+ # rspec-rails.
+ config.infer_base_class_for_anonymous_controllers = false
+
+ # Run specs in random order to surface order dependencies. If you find an
+ # order dependency and want to debug it, you can fix the order by providing
+ # the seed, which is printed after each run.
+ # --seed 1234
+ config.order = "random"
+
+ # include controller test helpers
+ config.include FakeSensuMacros
+ config.include Devise::TestHelpers, :type => :controller
+ config.include DeviseMacros, :type => :feature
+ config.extend ControllerMacros, :type => :controller
+
+end
diff --git a/spec/support/api_stubs.rb b/spec/support/api_stubs.rb
new file mode 100644
index 0000000..1a456da
--- /dev/null
+++ b/spec/support/api_stubs.rb
@@ -0,0 +1,15 @@
+module ApiStubs
+ def mock_api(opts={})
+ # Continuning this when spies are added to rspec-mocks: https://github.com/rspec/rspec-mocks/pull/241
+ redis_status = opts['redis_status'] || true
+ rabbitmq_status = opts['rabbitmq_status'] || true
+ status = JSON.parse("{\"sensu\":{\"version\":\"0.9.12.beta.6\"},\"rabbitmq\":{\"keepalives\":{\"messages\":null,\"consumers\":null},\"results\":{\"messages\":null,\"consumers\":null},\"connected\":#{rabbitmq_status}},\"redis\":{\"connected\":#{redis_status}}}")
+
+ @api = double('Api')
+ @api.stub(:status).with(status)
+ @api.stub(:version).with(status['sensu']['version'])
+ @api.stub(:redis_health).with(status['redis']['connected'])
+ @api.stub(:rabbitmq_health).with(status['rabbitmq']['connected'])
+ end
+
+end
diff --git a/spec/support/controller_macros.rb b/spec/support/controller_macros.rb
new file mode 100644
index 0000000..219b415
--- /dev/null
+++ b/spec/support/controller_macros.rb
@@ -0,0 +1,21 @@
+module ControllerMacros
+ def login_admin
+ before(:each) do
+ @request.env["devise.mapping"] = Devise.mappings[:admin]
+ sign_in FactoryGirl.create(:admin)
+ end
+ end
+
+ def login_user
+ before :all do
+ load "#{Rails.root}/db/seeds.rb"
+ end
+
+ before :each do
+ @request.env["devise.mapping"] = Devise.mappings[:user]
+ user = FactoryGirl.create(:user)
+ user.add_role :admin
+ sign_in user
+ end
+ end
+end
diff --git a/spec/support/devise.rb b/spec/support/devise.rb
new file mode 100644
index 0000000..5958be8
--- /dev/null
+++ b/spec/support/devise.rb
@@ -0,0 +1,14 @@
+module DeviseMacros
+ def sign_in_user(user)
+ visit '/users/sign_in'
+ fill_in "Email", :with => user.email
+ fill_in "Password", :with => user.password
+ click_button "Sign in"
+ end
+
+ def set_api
+ visit '/api/setup'
+ fill_in "Sensu API Server url", :with => "http://foo:bar@33.33.33.11:4567"
+ click_link_or_button "save_api_server"
+ end
+end
diff --git a/spec/support/fake_sensu_macros.rb b/spec/support/fake_sensu_macros.rb
new file mode 100644
index 0000000..78dfdd7
--- /dev/null
+++ b/spec/support/fake_sensu_macros.rb
@@ -0,0 +1,9 @@
+module FakeSensuMacros
+
+ def reset_fake_sensu!
+ api_setting = Setting.find_by_name("api_server")
+ api_path = api_setting.value
+ RestClient.get("#{api_path}/reset")
+ end
+
+end
diff --git a/spec/support/shared_db_connection.rb b/spec/support/shared_db_connection.rb
new file mode 100644
index 0000000..f813ba4
--- /dev/null
+++ b/spec/support/shared_db_connection.rb
@@ -0,0 +1,12 @@
+class ActiveRecord::Base
+ mattr_accessor :shared_connection
+ @@shared_connection = nil
+
+ def self.connection
+ @@shared_connection || retrieve_connection
+ end
+end
+
+# Forces all threads to share the same connection. This works on
+# Capybara because it starts the web server in a thread.
+ActiveRecord::Base.shared_connection = ActiveRecord::Base.connection
diff --git a/test/functional/.gitkeep b/spec/unit/.gitkeep
similarity index 100%
rename from test/functional/.gitkeep
rename to spec/unit/.gitkeep
diff --git a/spec/unit/aggregate_spec.rb b/spec/unit/aggregate_spec.rb
new file mode 100644
index 0000000..bc14a73
--- /dev/null
+++ b/spec/unit/aggregate_spec.rb
@@ -0,0 +1,10 @@
+require 'spec_helper'
+
+describe Aggregate do
+
+ it "should return a hash of all aggregates" do
+ aggregates = Aggregate.all
+ aggregates.should be_false
+ end
+
+end
diff --git a/spec/unit/api_spec.rb b/spec/unit/api_spec.rb
new file mode 100644
index 0000000..aa52921
--- /dev/null
+++ b/spec/unit/api_spec.rb
@@ -0,0 +1,33 @@
+require 'spec_helper'
+
+describe Api do
+
+ before :each do
+ load "#{Rails.root}/db/seeds.rb"
+ end
+
+ it "should return a status" do
+ status = Api.status
+ status.should be_a Api
+ status.should_not be_nil
+ status.should_not be_false
+ end
+
+ it "should return a version" do
+ version = Api.version
+ version.should_not be_false
+ version.should_not be_nil
+ end
+
+ it "should return redis health" do
+ redis_health = Api.redis_health
+ redis_health.should_not be_false
+ redis_health.should_not be_nil
+ end
+
+ it "should return rabbit health" do
+ rabbit_health = Api.rabbitmq_health
+ rabbit_health.should_not be_nil
+ end
+
+end
diff --git a/spec/unit/check_spec.rb b/spec/unit/check_spec.rb
new file mode 100644
index 0000000..2fab30c
--- /dev/null
+++ b/spec/unit/check_spec.rb
@@ -0,0 +1,15 @@
+require 'spec_helper'
+
+describe Check do
+
+ before :each do
+ load "#{Rails.root}/db/seeds.rb"
+ end
+
+ it "should submit a check" do
+ check = Check.all.first
+ check_name = check.name
+ subscribers = check.subscribers
+ end
+
+end
diff --git a/spec/unit/client_spec.rb b/spec/unit/client_spec.rb
new file mode 100644
index 0000000..18eba1d
--- /dev/null
+++ b/spec/unit/client_spec.rb
@@ -0,0 +1,17 @@
+require 'spec_helper'
+
+describe Client do
+
+ it "should return all clients through cache" do
+ clients = Client.all_with_cache
+ clients.count.should eq 1
+ end
+
+ it "should return all clients as a hash" do
+ clients_hash = Client.full_hash
+ clients_hash.should be_a Hash
+ clients_hash.should_not be_empty
+ clients_hash.count.should eq 1
+ end
+
+end
diff --git a/spec/unit/downtime_check_spec.rb b/spec/unit/downtime_check_spec.rb
new file mode 100644
index 0000000..b072a1c
--- /dev/null
+++ b/spec/unit/downtime_check_spec.rb
@@ -0,0 +1,10 @@
+require 'spec_helper'
+
+describe DowntimeCheck do
+
+ it "has a valid factory" do
+ downtime_check = FactoryGirl.create(:downtime_check)
+ downtime_check.should be_valid
+ end
+
+end
diff --git a/test/unit/downtime_client_test.rb b/spec/unit/downtime_client_spec.rb
similarity index 82%
rename from test/unit/downtime_client_test.rb
rename to spec/unit/downtime_client_spec.rb
index d23901f..a69e666 100644
--- a/test/unit/downtime_client_test.rb
+++ b/spec/unit/downtime_client_spec.rb
@@ -1,4 +1,4 @@
-require 'test_helper'
+require 'spec_helper'
class DowntimeClientTest < ActiveSupport::TestCase
# test "the truth" do
diff --git a/spec/unit/downtime_spec.rb b/spec/unit/downtime_spec.rb
new file mode 100644
index 0000000..aeff951
--- /dev/null
+++ b/spec/unit/downtime_spec.rb
@@ -0,0 +1,12 @@
+require 'spec_helper'
+
+describe Downtime do
+
+ before :each do
+ load "#{Rails.root}/db/seeds.rb"
+ end
+
+ it "should process downtimes" do
+ end
+
+end
diff --git a/spec/unit/event_spec.rb b/spec/unit/event_spec.rb
new file mode 100644
index 0000000..393cb61
--- /dev/null
+++ b/spec/unit/event_spec.rb
@@ -0,0 +1,103 @@
+require 'spec_helper'
+
+describe Event do
+
+ before :each do
+ load "#{Rails.root}/db/seeds.rb"
+ # user = FactoryGirl.create(:user)
+ # user.add_role :admin
+ # sign_in_user(user)
+ end
+
+ it "should return all checks through cache" do
+ events = Event.all_with_cache
+ events.count.should eq 2
+ end
+
+ it "should resolve an event" do
+ events = Event.all
+ events.count.should eq 2
+ event = events[rand(events.length)]
+ event.resolve.should be_true
+ # TODO: would be nice if fake_sensu would delete, then switch back after one
+ # GET /events
+ end
+
+ it "should return a single event" do
+ event = Event.all.first
+ client = event.client
+ check = event.check
+ single_event = Event.single("#{client}_#{check}")
+ single_event.should be_a Event
+ end
+
+ it "should identify when an event's client is silenced" do
+ event = Event.all.last
+ client = event.client
+ check = event.check
+ description = "This is a test description, it is long enough"
+ event.check_silenced.should_not eq nil
+ # Event.silence_check(client, check, description, User.first, nil, false, nil)
+ # event.check_silenced.should eq
+ end
+
+ it "should allow manual resolution of an event" do
+ event = Event.all.last
+ client = event.client
+ check = event.check
+ user = User.last
+ Event.manual_resolve(client, check, user).should be_a String
+ end
+
+ it "should allow a client to be silenced" do
+ event = Event.all.last
+ client = event.client
+ description = "This is a test description, it is long enough"
+ user = User.first
+ silenced_client = Event.silence_client(client, description, user, nil, false, nil)
+ silenced_client.should be_a String
+ reset_fake_sensu!
+ end
+
+ it "should allow a check to be silenced" do
+ event = Event.all.last
+ client = event.client
+ check = event.check
+ description = "This is a test description, it is long enough"
+ user = User.last
+ silenced_check = Event.silence_check(client, check, description, user)
+ silenced_check.should be_a String
+ reset_fake_sensu!
+ end
+
+ it "should allow a client to be unsilenced" do
+ client = Event.all.last.client
+ user = User.last
+ unsilenced_client = Event.unsilence_client(client, user)
+ unsilenced_client.should be_a String
+ end
+
+ it "should return client attributes" do
+ event = Event.all.first
+ client_attributes = event.client_attributes
+ client_attributes.should be_a Hash
+ client_attributes.should_not be_empty
+ end
+
+ it "should return check attributes" do
+ event = Event.all.first
+ check_attributes = event.check_attributes
+ check_attributes.should be_a Hash
+ check_attributes.should_not be_empty
+ end
+
+ it "should get a client name" do
+ event = Event.all.first
+ event.client.should eq "i-424242"
+ end
+
+ it "should return an environment" do
+ event = Event.all.first
+ end
+
+end
diff --git a/spec/unit/role_spec.rb b/spec/unit/role_spec.rb
new file mode 100644
index 0000000..a6de61f
--- /dev/null
+++ b/spec/unit/role_spec.rb
@@ -0,0 +1,10 @@
+require 'spec_helper'
+
+describe Role do
+
+ it "has a valid factory" do
+ role = FactoryGirl.create(:role)
+ role.should be_valid
+ end
+
+end
diff --git a/spec/unit/setting_spec.rb b/spec/unit/setting_spec.rb
new file mode 100644
index 0000000..1796372
--- /dev/null
+++ b/spec/unit/setting_spec.rb
@@ -0,0 +1,21 @@
+require 'spec_helper'
+
+describe Setting do
+
+ before :each do
+ load "#{Rails.root}/db/seeds.rb"
+ end
+
+ it "should return the api server" do
+ api_server = Setting.api_server
+ api_server.should_not be_nil
+ api_server.should_not be_false
+ Setting.api_server.should_not be_nil
+ end
+
+ it "should return true if environments are in use" do
+ env_setting = Setting.find_by_name("use_environments")
+ Setting.use_environments?.should be_false
+ end
+
+end
diff --git a/spec/unit/stash_spec.rb b/spec/unit/stash_spec.rb
new file mode 100644
index 0000000..e8c0d4c
--- /dev/null
+++ b/spec/unit/stash_spec.rb
@@ -0,0 +1,70 @@
+require 'spec_helper'
+
+describe Stash do
+
+ before :each do
+ load "#{Rails.root}/db/seeds.rb"
+ # user = FactoryGirl.create(:user)
+ # user.add_role :admin
+ # sign_in_user(user)
+ end
+
+ it "should return all stashes raw" do
+ stashes = Stash.all
+ stashes.should be_a Array
+ stashes.count.should eq 2
+ end
+
+ it "should return all stashes through cache" do
+ stashes = Stash.all_with_cache
+ stashes.should be_a Array
+ stashes.count.should eq 2
+ end
+
+ it "should return a list of stashes when self.stashes is called" do
+ stashes = Stash.stashes
+ stashes.should be_a Array
+ stashes.count.should eq 2
+ end
+
+ it "should create a stash" do
+ stashes = Stash.stashes
+ stashes.count.should eq 2
+ user = User.first
+ stash_key = "silence/test_stash/test"
+ attributes = {
+ :description => "This is a test description",
+ :owner => user.email,
+ :timestamp => Time.now.to_i
+ }
+ stash = Stash.create_stash(stash_key, attributes)
+ stash.should_not be_false
+ stashes = Stash.all
+ stashes.count.should eq 3
+ reset_fake_sensu!
+ end
+
+ it "should delete a stash" do
+ stashes = Stash.all
+ stashes.count.should eq 2
+ stash = stashes.last
+ key = stash["path"]
+ Stash.delete_stash(key).should_not be_false
+ stashes = Stash.all
+ stashes.count.should eq 1
+ reset_fake_sensu!
+ end
+
+ it "should delete all stashes" do
+ stashes = Stash.all
+ stashes.count.should eq 2
+ Stash.delete_all_stashes
+ stashes = Stash.all
+ stashes.count.should eq 0
+ reset_fake_sensu!
+ end
+
+ pending "should paginate stashes (see Stash.stashes)" do
+ end
+
+end
diff --git a/test/unit/user_test.rb b/spec/unit/user_spec.rb
similarity index 81%
rename from test/unit/user_test.rb
rename to spec/unit/user_spec.rb
index 82f61e0..880de24 100644
--- a/test/unit/user_test.rb
+++ b/spec/unit/user_spec.rb
@@ -1,4 +1,4 @@
-require 'test_helper'
+require 'spec_helper'
class UserTest < ActiveSupport::TestCase
# test "the truth" do
diff --git a/test/fixtures/downtime_checks.yml b/test/fixtures/downtime_checks.yml
deleted file mode 100644
index b530ac8..0000000
--- a/test/fixtures/downtime_checks.yml
+++ /dev/null
@@ -1,9 +0,0 @@
-# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
-
-one:
- name: MyString
- downtime_id: 1
-
-two:
- name: MyString
- downtime_id: 1
diff --git a/test/fixtures/downtime_clients.yml b/test/fixtures/downtime_clients.yml
deleted file mode 100644
index b530ac8..0000000
--- a/test/fixtures/downtime_clients.yml
+++ /dev/null
@@ -1,9 +0,0 @@
-# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
-
-one:
- name: MyString
- downtime_id: 1
-
-two:
- name: MyString
- downtime_id: 1
diff --git a/test/fixtures/downtimes.yml b/test/fixtures/downtimes.yml
deleted file mode 100644
index 3e7dc7c..0000000
--- a/test/fixtures/downtimes.yml
+++ /dev/null
@@ -1,15 +0,0 @@
-# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
-
-one:
- name: MyString
- description: MyText
- start_time: 2012-08-14 14:28:46
- stop_time: 2012-08-14 14:28:46
- user_id: 1
-
-two:
- name: MyString
- description: MyText
- start_time: 2012-08-14 14:28:46
- stop_time: 2012-08-14 14:28:46
- user_id: 1
diff --git a/test/fixtures/logs.yml b/test/fixtures/logs.yml
deleted file mode 100644
index f8eda28..0000000
--- a/test/fixtures/logs.yml
+++ /dev/null
@@ -1,19 +0,0 @@
-# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
-
-one:
- client: MyString
- check: MyString
- silence_type: MyString
- environment: MyString
- output: MyText
- status: MyString
- user_id: 1
-
-two:
- client: MyString
- check: MyString
- silence_type: MyString
- environment: MyString
- output: MyText
- status: MyString
- user_id: 1
diff --git a/test/fixtures/settings.yml b/test/fixtures/settings.yml
deleted file mode 100644
index c63aac0..0000000
--- a/test/fixtures/settings.yml
+++ /dev/null
@@ -1,11 +0,0 @@
-# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
-
-# This model initially had no columns defined. If you add columns to the
-# model remove the '{}' from the fixture names and add the columns immediately
-# below each fixture, per the syntax in the comments below
-#
-one: {}
-# column: value
-#
-two: {}
-# column: value
diff --git a/test/fixtures/users.yml b/test/fixtures/users.yml
deleted file mode 100644
index c63aac0..0000000
--- a/test/fixtures/users.yml
+++ /dev/null
@@ -1,11 +0,0 @@
-# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
-
-# This model initially had no columns defined. If you add columns to the
-# model remove the '{}' from the fixture names and add the columns immediately
-# below each fixture, per the syntax in the comments below
-#
-one: {}
-# column: value
-#
-two: {}
-# column: value
diff --git a/test/functional/aggregates_controller_test.rb b/test/functional/aggregates_controller_test.rb
deleted file mode 100644
index 4ede4d8..0000000
--- a/test/functional/aggregates_controller_test.rb
+++ /dev/null
@@ -1,7 +0,0 @@
-require 'test_helper'
-
-class AggregatesControllerTest < ActionController::TestCase
- # test "the truth" do
- # assert true
- # end
-end
diff --git a/test/functional/api_controller_test.rb b/test/functional/api_controller_test.rb
deleted file mode 100644
index 5ba1ef0..0000000
--- a/test/functional/api_controller_test.rb
+++ /dev/null
@@ -1,7 +0,0 @@
-require 'test_helper'
-
-class ApiControllerTest < ActionController::TestCase
- # test "the truth" do
- # assert true
- # end
-end
diff --git a/test/functional/checks_controller_test.rb b/test/functional/checks_controller_test.rb
deleted file mode 100644
index 7141381..0000000
--- a/test/functional/checks_controller_test.rb
+++ /dev/null
@@ -1,7 +0,0 @@
-require 'test_helper'
-
-class ChecksControllerTest < ActionController::TestCase
- # test "the truth" do
- # assert true
- # end
-end
diff --git a/test/functional/clients_controller_test.rb b/test/functional/clients_controller_test.rb
deleted file mode 100644
index 001566e..0000000
--- a/test/functional/clients_controller_test.rb
+++ /dev/null
@@ -1,7 +0,0 @@
-require 'test_helper'
-
-class ClientsControllerTest < ActionController::TestCase
- # test "the truth" do
- # assert true
- # end
-end
diff --git a/test/functional/downtimes_controller_test.rb b/test/functional/downtimes_controller_test.rb
deleted file mode 100644
index 0a094f0..0000000
--- a/test/functional/downtimes_controller_test.rb
+++ /dev/null
@@ -1,7 +0,0 @@
-require 'test_helper'
-
-class DowntimesControllerTest < ActionController::TestCase
- # test "the truth" do
- # assert true
- # end
-end
diff --git a/test/functional/events_controller_test.rb b/test/functional/events_controller_test.rb
deleted file mode 100644
index 65ff8bb..0000000
--- a/test/functional/events_controller_test.rb
+++ /dev/null
@@ -1,7 +0,0 @@
-require 'test_helper'
-
-class EventsControllerTest < ActionController::TestCase
- # test "the truth" do
- # assert true
- # end
-end
diff --git a/test/functional/logs_controller_test.rb b/test/functional/logs_controller_test.rb
deleted file mode 100644
index bab4469..0000000
--- a/test/functional/logs_controller_test.rb
+++ /dev/null
@@ -1,7 +0,0 @@
-require 'test_helper'
-
-class LogsControllerTest < ActionController::TestCase
- # test "the truth" do
- # assert true
- # end
-end
diff --git a/test/functional/settings_controller_test.rb b/test/functional/settings_controller_test.rb
deleted file mode 100644
index 265a09b..0000000
--- a/test/functional/settings_controller_test.rb
+++ /dev/null
@@ -1,7 +0,0 @@
-require 'test_helper'
-
-class SettingsControllerTest < ActionController::TestCase
- # test "the truth" do
- # assert true
- # end
-end
diff --git a/test/functional/stashes_controller_test.rb b/test/functional/stashes_controller_test.rb
deleted file mode 100644
index 007fa83..0000000
--- a/test/functional/stashes_controller_test.rb
+++ /dev/null
@@ -1,7 +0,0 @@
-require 'test_helper'
-
-class StashesControllerTest < ActionController::TestCase
- # test "the truth" do
- # assert true
- # end
-end
diff --git a/test/functional/stats_controller_test.rb b/test/functional/stats_controller_test.rb
deleted file mode 100644
index 055d91d..0000000
--- a/test/functional/stats_controller_test.rb
+++ /dev/null
@@ -1,7 +0,0 @@
-require 'test_helper'
-
-class StatsControllerTest < ActionController::TestCase
- # test "the truth" do
- # assert true
- # end
-end
diff --git a/test/integration/.gitkeep b/test/integration/.gitkeep
deleted file mode 100644
index e69de29..0000000
diff --git a/test/minitest_helper.rb b/test/minitest_helper.rb
deleted file mode 100644
index ad5c741..0000000
--- a/test/minitest_helper.rb
+++ /dev/null
@@ -1,25 +0,0 @@
-ENV["RAILS_ENV"] = "test"
-require File.expand_path('../../config/environment', __FILE__)
-
-require "minitest/autorun"
-require "minitest/rails"
-
-# Uncomment if you want Capybara in accceptance/integration tests
-# require "minitest/rails/capybara"
-
-# Uncomment if you want awesome colorful output
-# require "minitest/pride"
-
-class MiniTest::Rails::ActiveSupport::TestCase
- # Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
- fixtures :all
-
- # Add more helper methods to be used by all tests here...
-end
-
-# Do you want all existing Rails tests to use MiniTest::Rails?
-# Comment out the following and either:
-# A) Change the require on the existing tests to `require "minitest_helper"`
-# B) Require this file's code in test_helper.rb
-
-# MiniTest::Rails.override_testunit!
diff --git a/test/performance/browsing_test.rb b/test/performance/browsing_test.rb
deleted file mode 100644
index 3fea27b..0000000
--- a/test/performance/browsing_test.rb
+++ /dev/null
@@ -1,12 +0,0 @@
-require 'test_helper'
-require 'rails/performance_test_help'
-
-class BrowsingTest < ActionDispatch::PerformanceTest
- # Refer to the documentation for all available options
- # self.profile_options = { :runs => 5, :metrics => [:wall_time, :memory]
- # :output => 'tmp/performance', :formats => [:flat] }
-
- def test_homepage
- get '/'
- end
-end
diff --git a/test/test_helper.rb b/test/test_helper.rb
deleted file mode 100644
index 8bf1192..0000000
--- a/test/test_helper.rb
+++ /dev/null
@@ -1,13 +0,0 @@
-ENV["RAILS_ENV"] = "test"
-require File.expand_path('../../config/environment', __FILE__)
-require 'rails/test_help'
-
-class ActiveSupport::TestCase
- # Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
- #
- # Note: You'll currently still have to declare fixtures explicitly in integration tests
- # -- they do not yet inherit this setting
- fixtures :all
-
- # Add more helper methods to be used by all tests here...
-end
diff --git a/test/unit/.gitkeep b/test/unit/.gitkeep
deleted file mode 100644
index e69de29..0000000
diff --git a/test/unit/downtime_check_test.rb b/test/unit/downtime_check_test.rb
deleted file mode 100644
index 2239b06..0000000
--- a/test/unit/downtime_check_test.rb
+++ /dev/null
@@ -1,7 +0,0 @@
-require 'test_helper'
-
-class DowntimeCheckTest < ActiveSupport::TestCase
- # test "the truth" do
- # assert true
- # end
-end
diff --git a/test/unit/downtime_test.rb b/test/unit/downtime_test.rb
deleted file mode 100644
index dba4d6d..0000000
--- a/test/unit/downtime_test.rb
+++ /dev/null
@@ -1,7 +0,0 @@
-require 'test_helper'
-
-class DowntimeTest < ActiveSupport::TestCase
- # test "the truth" do
- # assert true
- # end
-end
diff --git a/test/unit/helpers/aggregates_helper_test.rb b/test/unit/helpers/aggregates_helper_test.rb
deleted file mode 100644
index b627adf..0000000
--- a/test/unit/helpers/aggregates_helper_test.rb
+++ /dev/null
@@ -1,4 +0,0 @@
-require 'test_helper'
-
-class AggregatesHelperTest < ActionView::TestCase
-end
diff --git a/test/unit/helpers/api_helper_test.rb b/test/unit/helpers/api_helper_test.rb
deleted file mode 100644
index 7d6a6d7..0000000
--- a/test/unit/helpers/api_helper_test.rb
+++ /dev/null
@@ -1,4 +0,0 @@
-require 'test_helper'
-
-class ApiHelperTest < ActionView::TestCase
-end
diff --git a/test/unit/helpers/checks_helper_test.rb b/test/unit/helpers/checks_helper_test.rb
deleted file mode 100644
index a138c5b..0000000
--- a/test/unit/helpers/checks_helper_test.rb
+++ /dev/null
@@ -1,4 +0,0 @@
-require 'test_helper'
-
-class ChecksHelperTest < ActionView::TestCase
-end
diff --git a/test/unit/helpers/clients_helper_test.rb b/test/unit/helpers/clients_helper_test.rb
deleted file mode 100644
index 21f2d9b..0000000
--- a/test/unit/helpers/clients_helper_test.rb
+++ /dev/null
@@ -1,4 +0,0 @@
-require 'test_helper'
-
-class ClientsHelperTest < ActionView::TestCase
-end
diff --git a/test/unit/helpers/downtimes_helper_test.rb b/test/unit/helpers/downtimes_helper_test.rb
deleted file mode 100644
index b98c4f7..0000000
--- a/test/unit/helpers/downtimes_helper_test.rb
+++ /dev/null
@@ -1,4 +0,0 @@
-require 'test_helper'
-
-class DowntimesHelperTest < ActionView::TestCase
-end
diff --git a/test/unit/helpers/events_helper_test.rb b/test/unit/helpers/events_helper_test.rb
deleted file mode 100644
index 2e7567e..0000000
--- a/test/unit/helpers/events_helper_test.rb
+++ /dev/null
@@ -1,4 +0,0 @@
-require 'test_helper'
-
-class EventsHelperTest < ActionView::TestCase
-end
diff --git a/test/unit/helpers/logs_helper_test.rb b/test/unit/helpers/logs_helper_test.rb
deleted file mode 100644
index c165554..0000000
--- a/test/unit/helpers/logs_helper_test.rb
+++ /dev/null
@@ -1,4 +0,0 @@
-require 'test_helper'
-
-class LogsHelperTest < ActionView::TestCase
-end
diff --git a/test/unit/helpers/settings_helper_test.rb b/test/unit/helpers/settings_helper_test.rb
deleted file mode 100644
index d5c1375..0000000
--- a/test/unit/helpers/settings_helper_test.rb
+++ /dev/null
@@ -1,4 +0,0 @@
-require 'test_helper'
-
-class SettingsHelperTest < ActionView::TestCase
-end
diff --git a/test/unit/helpers/stashes_helper_test.rb b/test/unit/helpers/stashes_helper_test.rb
deleted file mode 100644
index 6a231fc..0000000
--- a/test/unit/helpers/stashes_helper_test.rb
+++ /dev/null
@@ -1,4 +0,0 @@
-require 'test_helper'
-
-class StashesHelperTest < ActionView::TestCase
-end
diff --git a/test/unit/helpers/stats_helper_test.rb b/test/unit/helpers/stats_helper_test.rb
deleted file mode 100644
index 3f0b9aa..0000000
--- a/test/unit/helpers/stats_helper_test.rb
+++ /dev/null
@@ -1,4 +0,0 @@
-require 'test_helper'
-
-class StatsHelperTest < ActionView::TestCase
-end
diff --git a/test/unit/log_test.rb b/test/unit/log_test.rb
deleted file mode 100644
index f2afee2..0000000
--- a/test/unit/log_test.rb
+++ /dev/null
@@ -1,7 +0,0 @@
-require 'test_helper'
-
-class LogTest < ActiveSupport::TestCase
- # test "the truth" do
- # assert true
- # end
-end
diff --git a/test/unit/setting_test.rb b/test/unit/setting_test.rb
deleted file mode 100644
index 2d91c71..0000000
--- a/test/unit/setting_test.rb
+++ /dev/null
@@ -1,7 +0,0 @@
-require 'test_helper'
-
-class SettingTest < ActiveSupport::TestCase
- # test "the truth" do
- # assert true
- # end
-end