wackamole 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. data/History.txt +5 -1
  2. data/README.rdoc +12 -3
  3. data/bin/wackamole +2 -2
  4. data/data/fixtures.rb +132 -0
  5. data/features/env.rb +29 -0
  6. data/features/mission.feature +10 -0
  7. data/features/step_definitions/mission_steps.rb +5 -0
  8. data/lib/app.rb +23 -7
  9. data/lib/controllers/features.rb +3 -2
  10. data/lib/controllers/logs.rb +1 -0
  11. data/lib/controllers/mission.rb +14 -4
  12. data/lib/controllers/session.rb +32 -0
  13. data/lib/controllers/users.rb +3 -2
  14. data/lib/helpers/flash_helper.rb +4 -1
  15. data/lib/helpers/logs_helper.rb +2 -1
  16. data/lib/helpers/session_helper.rb +29 -0
  17. data/lib/wackamole.rb +1 -1
  18. data/lib/wackamole/models/control.rb +15 -1
  19. data/lib/wackamole/models/feature.rb +11 -2
  20. data/lib/wackamole/models/log.rb +1 -0
  21. data/lib/wackamole/models/mission.rb +9 -7
  22. data/lib/wackamole/models/mole_info.rb +8 -4
  23. data/lib/wackamole/models/search_filter.rb +48 -15
  24. data/lib/wackamole/models/user.rb +12 -1
  25. data/public/stylesheets/wackamole.css +60 -3
  26. data/spec/config/bogus_test.yml +1 -1
  27. data/spec/config/test.yml +1 -1
  28. data/spec/spec_helper.rb +3 -0
  29. data/spec/ui/log_spec.rb +68 -0
  30. data/spec/ui/mission_spec.rb +64 -0
  31. data/spec/ui/session_spec.rb +39 -0
  32. data/spec/ui_utils/mission_util.rb +41 -0
  33. data/spec/{models → wackamole/models}/control_spec.rb +21 -21
  34. data/spec/{models → wackamole/models}/feature_spec.rb +7 -7
  35. data/spec/{models → wackamole/models}/log_spec.rb +5 -5
  36. data/spec/{models → wackamole/models}/mission_spec.rb +11 -7
  37. data/spec/wackamole/models/moled_info_spec.rb +36 -0
  38. data/spec/{models → wackamole/models}/search_filter_spec.rb +12 -16
  39. data/spec/{models → wackamole/models}/user_spec.rb +5 -5
  40. data/spec/{wackamole_spec.rb → wackamole/wackamole_spec.rb} +2 -2
  41. data/tasks/fixtures.rake +3 -1
  42. data/tasks/setup.rb +2 -1
  43. data/tasks/spec.rake +17 -3
  44. data/views/dashboard/_report.erb +3 -3
  45. data/views/layout.erb +44 -11
  46. data/views/logs/show.erb +3 -0
  47. data/views/mission/_report.erb +2 -2
  48. data/views/session/login.erb +28 -0
  49. data/views/shared/_search.erb +1 -1
  50. data/views/users/index.js.erb +1 -1
  51. metadata +22 -10
  52. data/spec/models/moled_info_spec.rb +0 -30
@@ -0,0 +1,39 @@
1
+ require File.join(File.dirname(__FILE__), %w[.. spec_helper])
2
+ require 'capybara'
3
+ require 'capybara/dsl'
4
+ require File.join(File.dirname(__FILE__), %w[.. ui_utils mission_util])
5
+
6
+ include Capybara
7
+ include MissionUtil
8
+
9
+ describe 'Sessions' do
10
+ before( :all ) do
11
+ Capybara.default_driver = :selenium
12
+ @url = "http://localhost:4567/"
13
+ end
14
+
15
+ it "should login correctly" do
16
+ visit( @url )
17
+ login( @url, 'admin', 'admin', @url + 'mission' )
18
+ log_out
19
+ # within( "//form[@id='login']" ) do
20
+ # fill_in 'Login' , :with => 'admin'
21
+ # fill_in 'Password', :with => 'admin'
22
+ # end
23
+ # click_button 'Log In'
24
+ # current_url.should == @url + "mission"
25
+ # click_link 'log out'
26
+ end
27
+
28
+ it "should complain for invalid credentials" do
29
+ visit( @url )
30
+ login( @url, 'fernand', 'oh dear', @url )
31
+ # within( "//form[@id='login']" ) do
32
+ # fill_in 'Login' , :with => 'fernand'
33
+ # fill_in 'Password', :with => 'fuck'
34
+ # end
35
+ # click_button 'Log In'
36
+ # current_url.should == @url
37
+ page.should have_css( 'div.flash_error' )
38
+ end
39
+ end
@@ -0,0 +1,41 @@
1
+ module MissionUtil
2
+
3
+ def check_app( row, app, env, to_date, today, last_tick )
4
+ cells = row.all( :css, 'td' )
5
+
6
+ cells[0].text.should == app
7
+ cells[1].text.should == env
8
+
9
+ to_date_indexes = [4,6,8]
10
+ to_date_indexes.each_index { |i| cells[to_date_indexes[i]].text.should == to_date[i].to_s }
11
+
12
+ today_indexes = [11,13,15]
13
+ today_indexes.each_index { |i| cells[today_indexes[i]].text.should == today[i].to_s }
14
+
15
+ last_tick_indexes = [18,20,22]
16
+ last_tick_indexes.each_index { |i| cells[last_tick_indexes[i]].text.should == last_tick[i].to_s }
17
+ end
18
+
19
+ def show_logs( row, app, env, type )
20
+ row.find( :css, "a##{app}_#{env}_#{type}" ).click
21
+ end
22
+
23
+ def nav_mission
24
+ page.find_link( 'mission control' ).click
25
+ end
26
+
27
+ def login( url, username, password, expected_url )
28
+ visit( url )
29
+ within( "//form[@id='login']" ) do
30
+ fill_in 'Login' , :with => username
31
+ fill_in 'Password', :with => password
32
+ end
33
+ click_button 'Log In'
34
+ current_url.should == expected_url
35
+ end
36
+
37
+ def log_out
38
+ click_link 'log out'
39
+ end
40
+
41
+ end
@@ -1,4 +1,4 @@
1
- require File.join(File.dirname(__FILE__), %w[.. spec_helper])
1
+ require File.join(File.dirname(__FILE__), %w[.. .. spec_helper])
2
2
 
3
3
  describe Wackamole::Control do
4
4
  describe 'errors' do
@@ -11,21 +11,21 @@ describe Wackamole::Control do
11
11
  end
12
12
 
13
13
  it "should raise an error if invalid config file" do
14
- config_file = File.join(File.dirname(__FILE__), %w[.. config blee.yml])
14
+ config_file = File.join(File.dirname(__FILE__), %w[.. .. config blee.yml])
15
15
  lambda {
16
16
  Wackamole::Control.init_config( config_file, 'test' )
17
17
  }.should raise_error( /Hoy! An error occur loading the config file `#{config_file} -- No such file or directory/ )
18
18
  end
19
19
 
20
20
  it "should raise an error if a bogus env is requested" do
21
- config_file = File.join(File.dirname(__FILE__), %w[.. config test.yml])
21
+ config_file = File.join(File.dirname(__FILE__), %w[.. .. config test.yml])
22
22
  lambda {
23
23
  Wackamole::Control.init_config( config_file, 'production' )
24
24
  }.should raise_error( /Hoy! An error occur loading the config file `#{config_file} -- Invalid environment `production/ )
25
25
  end
26
26
 
27
27
  it "should raise an error if invalid config file content" do
28
- config_file = File.join(File.dirname(__FILE__), %w[.. config bogus_test.yml])
28
+ config_file = File.join(File.dirname(__FILE__), %w[.. .. config bogus_test.yml])
29
29
  lambda {
30
30
  Wackamole::Control.init_config( config_file, 'test' )
31
31
  }.should raise_error( /Hoy! An error occur loading the config file `#{config_file} -- Unable to find host in -/ )
@@ -35,19 +35,19 @@ describe Wackamole::Control do
35
35
  describe 'connection' do
36
36
  before :all do
37
37
  Wackamole::Control.reset!
38
- Wackamole::Control.init_config( File.join(File.dirname(__FILE__), %w[.. config test.yml]), 'test' )
38
+ Wackamole::Control.init_config( File.join(File.dirname(__FILE__), %w[.. .. config test.yml]), 'test' )
39
39
  Wackamole::Control.connection.should_not be_nil
40
40
  end
41
41
 
42
42
  describe "#collection" do
43
43
  it "should find a collection correctly" do
44
- cltn = Wackamole::Control.collection( 'features', "mole_fred_development_mdb" )
45
- cltn.count.should == 10
46
- feature = cltn.find_one()
47
- feature['app'].should == "fred"
48
- feature['env'].should == "development"
49
- feature['did'].should == Fixtures.test_time_id.to_s
50
- feature['ctx'].should match( /feature_\d{1}/ )
44
+ cltn = Wackamole::Control.collection( 'features', "mole_app1_test_mdb" )
45
+ cltn.count.should == 6
46
+ feature = cltn.find_one()
47
+ feature['app'].should == "app1"
48
+ feature['env'].should == "test"
49
+ feature['did'].should == Time.now.utc.to_date_id.to_s
50
+ feature['ctx'].should match( /\// )
51
51
  end
52
52
  end
53
53
 
@@ -55,7 +55,7 @@ describe Wackamole::Control do
55
55
  it "should correctly identify mole dbs" do
56
56
  # gen_bogus_dbs
57
57
  mole_dbs = Wackamole::Control.mole_databases
58
- mole_dbs.should have(3).items
58
+ mole_dbs.should have(2).items
59
59
  end
60
60
 
61
61
  it "should extra app/env correctly" do
@@ -69,20 +69,20 @@ describe Wackamole::Control do
69
69
  end
70
70
 
71
71
  it "should connect to a mole databases correctly" do
72
- %w[test production development].each do |env|
73
- Wackamole::Control.db( "mole_fred_#{env}_mdb" )
72
+ %w[app1 app2].each do |app|
73
+ Wackamole::Control.db( "mole_#{app}_test_mdb" )
74
74
  feature = Wackamole::Control.collection( 'features' ).find_one()
75
- feature['app'].should == "fred"
76
- feature['env'].should == env
75
+ feature['app'].should == app
76
+ feature['env'].should == "test"
77
77
  end
78
78
  end
79
79
 
80
80
  it "should switch mole dbs correctly" do
81
- %w[test production development].each do |env|
82
- Wackamole::Control.switch_mole_db!( "fred", env )
81
+ %w[app1 app2].each do |app|
82
+ Wackamole::Control.switch_mole_db!( app, "test" )
83
83
  feature = Wackamole::Control.collection( 'features' ).find_one()
84
- feature['app'].should == "fred"
85
- feature['env'].should == env
84
+ feature['app'].should == app
85
+ feature['env'].should == "test"
86
86
  end
87
87
  end
88
88
 
@@ -1,26 +1,26 @@
1
- require File.join(File.dirname(__FILE__), %w[.. spec_helper])
1
+ require File.join(File.dirname(__FILE__), %w[.. .. spec_helper])
2
2
  require 'chronic'
3
3
 
4
4
  describe Wackamole::Feature do
5
5
  before( :all ) do
6
- Wackamole::Control.init_config( File.join(File.dirname(__FILE__), %w[.. config test.yml]), 'test' )
6
+ Wackamole::Control.init_config( File.join(File.dirname(__FILE__), %w[.. .. config test.yml]), 'test' )
7
7
  Wackamole::Control.connection.should_not be_nil
8
- Wackamole::Control.db( "mole_fred_test_mdb" )
8
+ Wackamole::Control.db( "mole_app1_test_mdb" )
9
9
  end
10
10
 
11
11
  it "retrieve an app info correctly" do
12
12
  app_info = Wackamole::Feature.get_app_info
13
13
  app_info.should_not be_nil
14
14
  app_info.should have(2).items
15
- app_info[:app_name].should == "fred"
15
+ app_info[:app_name].should == "app1"
16
16
  app_info[:stage].should == "test"
17
17
  end
18
18
 
19
19
  it "should paginate features correctly" do
20
20
  cltn = Wackamole::Feature.paginate_tops( {}, 1, 5 )
21
- cltn.total_entries.should == 7
22
- cltn.size.should == 5
23
- cltn.total_pages.should == 2
21
+ cltn.total_entries.should == 6
22
+ cltn.size.should == 5
23
+ cltn.total_pages.should == 2
24
24
  end
25
25
 
26
26
  describe "indexes" do
@@ -1,18 +1,18 @@
1
- require File.join(File.dirname(__FILE__), %w[.. spec_helper])
1
+ require File.join(File.dirname(__FILE__), %w[.. .. spec_helper])
2
2
  require 'chronic'
3
3
 
4
4
  describe Wackamole::Log do
5
5
  before( :all ) do
6
- Wackamole::Control.init_config( File.join(File.dirname(__FILE__), %w[.. config test.yml]), 'test' )
6
+ Wackamole::Control.init_config( File.join(File.dirname(__FILE__), %w[.. .. config test.yml]), 'test' )
7
7
  Wackamole::Control.connection.should_not be_nil
8
- Wackamole::Control.db( "mole_fred_test_mdb" )
8
+ Wackamole::Control.db( "mole_app1_test_mdb" )
9
9
  end
10
10
 
11
11
  it "should paginate logs correctly" do
12
12
  cltn = Wackamole::Log.paginate( {}, 1, 5 )
13
- cltn.total_entries.should == 21
13
+ cltn.total_entries.should == 15
14
14
  cltn.size.should == 5
15
- cltn.total_pages.should == 5
15
+ cltn.total_pages.should == 3
16
16
  end
17
17
 
18
18
  describe "indexes" do
@@ -1,12 +1,14 @@
1
- require File.join(File.dirname(__FILE__), %w[.. spec_helper])
1
+ require File.join(File.dirname(__FILE__), %w[.. .. spec_helper])
2
2
  require 'chronic'
3
3
 
4
4
  describe Wackamole::Mission do
5
5
  before :all do
6
6
  Wackamole::Control.reset!
7
- Wackamole::Control.init_config( File.join(File.dirname(__FILE__), %w[.. config test.yml]), 'test' )
7
+ Wackamole::Control.init_config( File.join(File.dirname(__FILE__), %w[.. .. config test.yml]), 'test' )
8
8
  Wackamole::Control.connection.should_not be_nil
9
- @test_time = Chronic.parse( "2010/01/01 01:00:00" ).utc
9
+ now = Time.now
10
+ @test_time = Chronic.parse( "%d/%2d/%2d 17:00:00" % [now.year,now.month,now.day] )
11
+ # @test_time = Chronic.parse( "2010/01/01 01:00:00" ).utc
10
12
  end
11
13
 
12
14
  describe '#to_type_name' do
@@ -30,16 +32,18 @@ describe Wackamole::Mission do
30
32
  pulse[:to_date].should_not be_nil
31
33
  pulse[:today].should_not be_nil
32
34
  pulse[:last_tick].should_not be_nil
35
+ expected = {'to_date' => [7,5,3], 'today' => [6,4,2] }
33
36
  %w(to_date today).each do |p|
34
- %w(production development test).each do |e|
37
+ %w(app1 app2).each do |app|
35
38
  [0, 1, 2].each do |type|
36
- pulse[p.to_sym]["fred"][e][type].should == 7
39
+ pulse[p.to_sym][app]["test"][type].should == expected[p][type]
37
40
  end
38
41
  end
39
42
  end
40
- %w(production development test).each do |e|
43
+ %w(app1 app2).each do |app|
44
+ expected = [3,2,1]
41
45
  [0, 1, 2].each do |type|
42
- pulse[:last_tick]["fred"][e][type].should == 2
46
+ pulse[:last_tick][app]["test"][type].should == expected[type]
43
47
  end
44
48
  end
45
49
  end
@@ -0,0 +1,36 @@
1
+ require File.join(File.dirname(__FILE__), %w[.. .. spec_helper])
2
+ require 'chronic'
3
+
4
+ describe Wackamole::MoledInfo do
5
+ before( :all ) do
6
+ Wackamole::Control.init_config( File.join(File.dirname(__FILE__), %w[.. .. config test.yml]), 'test' )
7
+ Wackamole::Control.connection.should_not be_nil
8
+ Wackamole::Control.db( "mole_app1_test_mdb" )
9
+ now = Time.now
10
+ @test_time = Chronic.parse( "%d/%2d/%2d 17:00:00" % [now.year,now.month,now.day] )
11
+ end
12
+
13
+ it "should gather dashboard info correctly" do
14
+ info = Wackamole::MoledInfo.collect_dashboard_info( @test_time )
15
+
16
+ info[:total_users].should == 5
17
+ info[:user_load].should == 2
18
+ info[:total_features].should == 6
19
+ info[:feature_load].should == 1
20
+ info[:fault_load].should == 1
21
+ info[:perf_load].should == 2
22
+
23
+ info[:user_series].should == series_for( [[17,2]] )
24
+ info[:feature_series].should == series_for( [[17,2]] )
25
+ info[:fault_series].should == series_for( [[17,1]] )
26
+ info[:perf_series].should == series_for( [[17,2]] )
27
+ end
28
+
29
+ def series_for( slots )
30
+ series = 24.times.collect { |i| 0 }
31
+ slots.each do |pair|
32
+ series[pair.first] = pair.last
33
+ end
34
+ series
35
+ end
36
+ end
@@ -1,8 +1,10 @@
1
- require File.join(File.dirname(__FILE__), %w[.. spec_helper])
1
+ require File.join(File.dirname(__FILE__), %w[.. .. spec_helper])
2
2
 
3
3
  describe Wackamole::SearchFilter do
4
4
  before( :each ) do
5
- @filter = Wackamole::SearchFilter.new
5
+ @filter = Wackamole::SearchFilter.new
6
+ now = Time.now
7
+ @test_time = Chronic.parse( "%d/%2d/%2d 17:00:00" % [now.year,now.month,now.day] )
6
8
  end
7
9
 
8
10
  it "should initialize with the correct defaults" do
@@ -64,8 +66,8 @@ describe Wackamole::SearchFilter do
64
66
  it "should spews default filter query conds correctly" do
65
67
  conds = @filter.to_conds
66
68
  conds.should have(1).item
67
- conds.key?( :did ).should == true
68
- conds[:did].should == { "$gte" => @now.to_date_id.to_s }
69
+ conds.key?( '$where' ).should == true
70
+ conds['$where'].should == "((this.did == '#{@test_time.to_date_id}' && this.tid >= '070001') || ( this.did == '#{(@test_time+24*60*60).to_date_id}' && this.tid <= '065959') )"
69
71
  end
70
72
 
71
73
  it "should include browser if specified correctly" do
@@ -73,8 +75,6 @@ describe Wackamole::SearchFilter do
73
75
  conds = @filter.to_conds
74
76
  time = Chronic.parse( "now" ).utc
75
77
  conds.should have(2).items
76
- conds.key?( :did ).should == true
77
- conds[:did].should == { "$gte" => @now.to_date_id.to_s }
78
78
  conds['bro.name'].should == "Safari"
79
79
  end
80
80
 
@@ -84,8 +84,6 @@ describe Wackamole::SearchFilter do
84
84
  conds = @filter.to_conds
85
85
  time = Chronic.parse( "now" ).utc
86
86
  conds.should have(3).items
87
- conds.key?( :did ).should == true
88
- conds[:did].should == { "$gte" => @now.to_date_id.to_s }
89
87
  conds['bro.name'].should == "Safari"
90
88
  conds[:typ].should == Rackamole.feature
91
89
  end
@@ -95,32 +93,30 @@ describe Wackamole::SearchFilter do
95
93
  conds = @filter.to_conds
96
94
  time = Chronic.parse( "now" ).utc
97
95
  conds.should have(2).items
98
- conds.key?( :did ).should == true
99
- conds[:did].should == { "$gte" => @now.to_date_id.to_s }
100
96
  conds[:fid].should == Mongo::ObjectID.from_string( "4b25b0049983a8a193000010" )
101
97
  end
102
98
 
103
99
  describe "search terms" do
104
100
  before( :all ) do
105
- Wackamole::Control.init_config( File.join(File.dirname(__FILE__), %w[.. config test.yml]), 'test' )
101
+ Wackamole::Control.init_config( File.join(File.dirname(__FILE__), %w[.. .. config test.yml]), 'test' )
106
102
  Wackamole::Control.connection.should_not be_nil
107
- Wackamole::Control.db( "mole_fred_test_mdb" )
103
+ Wackamole::Control.db( "mole_app1_test_mdb" )
108
104
  end
109
105
 
110
106
  it "should retrieve features correctly" do
111
107
  features = @filter.features
112
- features.should have(11).items
108
+ features.should have(7).items
113
109
  count = 0
110
+ expected = %w(All / /error /normal /params/10 /post /slow)
114
111
  features.each do |f|
115
112
  f.should have(2).items
116
- f.first.should == "All" if count == 0
117
- f.first.should == "feature_#{count-1}" if count > 0
113
+ f.first.should == expected[count]
118
114
  count += 1
119
115
  end
120
116
  end
121
117
 
122
118
  it "should include user if specified" do
123
- @filter.search_terms = "user:blee_0@fred.test"
119
+ @filter.search_terms = "user:fernand"
124
120
  conds = @filter.to_conds
125
121
  conds.should have(2).items
126
122
  conds[:uid].should_not be_nil
@@ -1,18 +1,18 @@
1
- require File.join(File.dirname(__FILE__), %w[.. spec_helper])
1
+ require File.join(File.dirname(__FILE__), %w[.. .. spec_helper])
2
2
  require 'chronic'
3
3
 
4
4
  describe Wackamole::User do
5
5
  before( :all ) do
6
- Wackamole::Control.init_config( File.join(File.dirname(__FILE__), %w[.. config test.yml]), 'test' )
6
+ Wackamole::Control.init_config( File.join(File.dirname(__FILE__), %w[.. .. config test.yml]), 'test' )
7
7
  Wackamole::Control.connection.should_not be_nil
8
- Wackamole::Control.db( "mole_fred_test_mdb" )
8
+ Wackamole::Control.db( "mole_app1_test_mdb" )
9
9
  end
10
10
 
11
11
  it "should paginate a user collection correctly" do
12
12
  cltn = Wackamole::User.paginate_tops( {}, 1, 2 )
13
- cltn.total_entries.should == 7
13
+ cltn.total_entries.should == 2
14
14
  cltn.size.should == 2
15
- cltn.total_pages.should == 4
15
+ cltn.total_pages.should == 1
16
16
  end
17
17
 
18
18
  describe "indexes" do
@@ -1,8 +1,8 @@
1
- require File.join(File.dirname(__FILE__), %w[spec_helper])
1
+ require File.join(File.dirname(__FILE__), %w[.. spec_helper])
2
2
 
3
3
  describe Wackamole do
4
4
  before( :all ) do
5
- @root = ::File.expand_path( ::File.join(::File.dirname(__FILE__), ".." ) )
5
+ @root = ::File.expand_path( ::File.join(::File.dirname(__FILE__), %w(.. ..) ) )
6
6
  end
7
7
 
8
8
  it "is versioned" do
@@ -1,3 +1,5 @@
1
+ require 'data/fixtures'
2
+
1
3
  namespace :fixtures do
2
4
 
3
5
  # A prerequisites task that all other tasks depend upon
@@ -5,7 +7,7 @@ namespace :fixtures do
5
7
 
6
8
  desc 'Populate fixture data'
7
9
  task :load do |t|
8
- Fixtures.load_data
10
+ Fixtures.new.populate
9
11
  end
10
12
 
11
13
  # task 'gem:release' => 'svn:create_tag'
@@ -91,7 +91,8 @@ PROJ = OpenStruct.new(
91
91
 
92
92
  # Rspec
93
93
  :spec => OpenStruct.new(
94
- :files => FileList['spec/**/*_spec.rb'],
94
+ :files => FileList['spec/wackamole/**/*_spec.rb'],
95
+ :ui_files => FileList['spec/ui/*_spec.rb'],
95
96
  :opts => []
96
97
  ),
97
98