acts_as_monitor 0.0.2 → 0.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. data/CHANGELOG.md +6 -3
  2. data/README.md +22 -0
  3. data/app/controllers/acts_as_monitor/monitors_controller.rb +18 -0
  4. data/app/helpers/acts_as_monitor_helper.rb +25 -0
  5. data/app/views/acts_as_monitor/monitors/show.html.erb +26 -0
  6. data/config/routes.rb +3 -1
  7. data/lib/acts_as_monitor/engine.rb +21 -8
  8. data/lib/acts_as_monitor/monitor.rb +1 -1
  9. data/lib/acts_as_monitor/version.rb +1 -1
  10. data/lib/acts_as_monitor.rb +10 -10
  11. data/lib/generators/acts_as_monitor/install/install_generator.rb +33 -25
  12. data/lib/generators/acts_as_monitor/install/templates/acts_as_monitor.css +48 -0
  13. data/lib/generators/acts_as_monitor/install/templates/acts_as_monitor.it.yml +8 -1
  14. data/lib/generators/acts_as_monitor/install/templates/acts_as_monitor_javascript.js +78 -0
  15. data/lib/generators/acts_as_monitor/install/templates/acts_as_monitor_loading.gif +0 -0
  16. data/test/acts_as_monitor_helper_test.rb +16 -0
  17. data/test/{units/acts_as_monitor_test.rb → acts_as_monitor_test.rb} +3 -20
  18. data/test/dummy/Rakefile +7 -0
  19. data/test/dummy/app/controllers/application_controller.rb +3 -0
  20. data/test/dummy/app/controllers/homes_controller.rb +4 -0
  21. data/test/dummy/app/helpers/application_helper.rb +2 -0
  22. data/test/dummy/app/helpers/homes_helper.rb +2 -0
  23. data/test/dummy/app/models/test_class.rb +33 -0
  24. data/test/dummy/app/models/test_class_no_monitor.rb +2 -0
  25. data/test/dummy/app/views/homes/index.html.erb +8 -0
  26. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  27. data/test/dummy/config/application.rb +45 -0
  28. data/test/dummy/config/boot.rb +10 -0
  29. data/test/dummy/config/database.yml +22 -0
  30. data/test/dummy/config/environment.rb +5 -0
  31. data/test/dummy/config/environments/development.rb +26 -0
  32. data/test/dummy/config/environments/production.rb +49 -0
  33. data/test/dummy/config/environments/test.rb +35 -0
  34. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  35. data/test/dummy/config/initializers/inflections.rb +10 -0
  36. data/test/dummy/config/initializers/mime_types.rb +5 -0
  37. data/test/dummy/config/initializers/secret_token.rb +7 -0
  38. data/test/dummy/config/initializers/session_store.rb +8 -0
  39. data/test/dummy/config/locales/acts_as_monitor.it.yml +14 -0
  40. data/test/dummy/config/locales/en.yml +5 -0
  41. data/test/dummy/config/routes.rb +58 -0
  42. data/test/dummy/config.ru +4 -0
  43. data/test/{acts_as_monitor.sqlite3.db → dummy/db/development.sqlite3} +0 -0
  44. data/test/dummy/db/migrate/20120523110000_add_test_tables.rb +12 -0
  45. data/test/dummy/db/schema.rb +19 -0
  46. data/test/dummy/db/test.sqlite3 +0 -0
  47. data/test/dummy/log/development.log +4537 -0
  48. data/test/dummy/log/production.log +0 -0
  49. data/test/dummy/log/server.log +0 -0
  50. data/test/dummy/log/test.log +188 -0
  51. data/test/dummy/public/404.html +26 -0
  52. data/test/dummy/public/422.html +26 -0
  53. data/test/dummy/public/500.html +26 -0
  54. data/test/dummy/public/favicon.ico +0 -0
  55. data/test/dummy/public/images/acts_as_monitor_green.png +0 -0
  56. data/test/dummy/public/images/acts_as_monitor_red.png +0 -0
  57. data/test/dummy/public/images/acts_as_monitor_yellow.png +0 -0
  58. data/test/dummy/public/javascripts/acts_as_monitor_javascript.js +66 -0
  59. data/test/dummy/public/javascripts/application.js +2 -0
  60. data/test/dummy/public/javascripts/builder.js +136 -0
  61. data/test/dummy/public/javascripts/controls.js +965 -0
  62. data/test/dummy/public/javascripts/dragdrop.js +974 -0
  63. data/test/dummy/public/javascripts/effects.js +1123 -0
  64. data/test/dummy/public/javascripts/prototype.js +6001 -0
  65. data/test/dummy/public/javascripts/rails.js +191 -0
  66. data/test/dummy/public/javascripts/scriptaculous.js +68 -0
  67. data/test/dummy/public/javascripts/slider.js +275 -0
  68. data/test/dummy/public/javascripts/sound.js +59 -0
  69. data/test/dummy/public/javascripts/unittest.js +568 -0
  70. data/test/dummy/public/stylesheets/.gitkeep +0 -0
  71. data/test/dummy/public/stylesheets/acts_as_monitor.css +30 -0
  72. data/test/dummy/script/rails +6 -0
  73. data/test/integration/navigation_test.rb +7 -0
  74. data/test/support/integration_case.rb +5 -0
  75. data/test/test_helper.rb +17 -42
  76. metadata +128 -11
  77. data/app/controllers/acts_as_monitor/monitor_controller.rb +0 -7
  78. data/app/helpers/monitor_helper.rb +0 -11
  79. data/app/views/acts_as_monitor/indext.html.erb +0 -1
data/CHANGELOG.md CHANGED
@@ -1,8 +1,11 @@
1
1
  0.1.0 ToDo
2
+ - BugFixing
3
+
4
+ 0.0.9 (May 28, 2012)
2
5
  - Ajax to have warning and error list clicking on icon
3
6
 
4
- 0.0.2 (May 23, 2011)
5
- - Working copy
7
+ 0.0.2 (May 23, 2012)
8
+ - first working copy
6
9
 
7
- 0.0.1 (May 23, 2011)
10
+ 0.0.1 (May 23, 2012)
8
11
  - First deploy not working
data/README.md CHANGED
@@ -57,8 +57,30 @@ You can now check the status of your model using the following code:
57
57
 
58
58
  You can use the monitor_tag helper to view a red/green/yellow rapresentation:
59
59
  #app/views/users/index.html.erb
60
+ <%= monitor_tag_js %> #Creates hidden div and load css and javascript
60
61
  ...
61
62
  <%= monitor_tag(@user) %>
63
+
64
+ Clicking to Icon you receive via Ajax the full error/warning list
65
+
66
+ ## Internationalization
67
+ You can localize the output modifing the acts_as_monitor.it.yml, or cloning for the language you prefear.
68
+ Name of models is retrived via human_name, so yuo have to localize the ActiveRecord to change names:
69
+ it:
70
+ activerecord:
71
+ models:
72
+ your_model_name: Your Model Name
73
+
74
+ namespace:
75
+ namespaced_model_name: Your Namespaced Model Name
76
+
77
+ ## Personalization
78
+ Feel free to modify the fololwing files to change layouts and text :
79
+ - public/stylesheets/acts_as_monitor.css
80
+ - config/locales/act_as_monitor.it.yml
81
+
82
+ If you need a deeper personalization you can try to overload app/views/acts_as_monitor/monitors/show.html.erb
83
+ conaining the page template for the error/warning list
62
84
 
63
85
  ## Contributing
64
86
 
@@ -0,0 +1,18 @@
1
+ module ActsAsMonitor
2
+ class MonitorsController < ::ApplicationController
3
+
4
+ def show
5
+ @monitor = eval(params[:class_name]).find(params[:id]) if monitor_valid?(params)
6
+ Rails::logger.info("MonitorsController @monitor=#{@monitor.inspect}")
7
+ respond_to do |format|
8
+ format.js do
9
+ view = render_to_string "show"
10
+ #render :json => {"text" => @status.status}
11
+ render :json => {"text" => view}
12
+ end
13
+ format.html
14
+ end
15
+ end
16
+
17
+ end
18
+ end
@@ -0,0 +1,25 @@
1
+ module ActsAsMonitorHelper
2
+ def monitor_tag(object)
3
+ raise ActsAsMonitor::MissingMethod unless object.respond_to?(:status_flag)
4
+ status = object.status_flag
5
+ icon = I18n.t(status, :scope => "acts_as_monitor.icons",
6
+ :default => "acts_as_monitor_#{status.to_s}.png")
7
+ image_tag icon, :alt => I18n.t("alt_image_#{status.to_s}", :scope => "acts_as_monitor.icons",
8
+ :default => status.to_s.capitalize),
9
+ :class => "acts_as_monitor_icon_#{status.to_s}",
10
+ 'data-class' => object.class.name, 'data-id' => object.id
11
+ end
12
+
13
+ def monitor_tag_js()
14
+ content_tag(:div, "/#{Rails.root.to_s.split('/').last}", :id => 'acts_as_monitor_status_window') +
15
+ javascript_include_tag("acts_as_monitor_javascript.js") +
16
+ stylesheet_link_tag('acts_as_monitor.css')
17
+ end
18
+
19
+ def monitor_valid?(params)
20
+ return false if params[:id].blank? || params[:class_name].blank?
21
+ Rails::logger.info eval(params[:class_name]).instance_methods.include?("status")
22
+ return false unless eval(params[:class_name]).instance_methods.include?("status")
23
+ true
24
+ end
25
+ end
@@ -0,0 +1,26 @@
1
+ <% if @monitor %>
2
+ <fieldset class='acts_as_monitor_status_window'>
3
+ <legend class='acts_as_monitor_status_window'><%= @monitor.class.human_name %></legend>
4
+ <% @status = @monitor.status %>
5
+ <% @li_scope = "acts_as_monitor.messages.#{@monitor.class.name.underscore.gsub('/','_')}"%>
6
+ <% unless @status[:error].blank? %>
7
+ <h3 class="acts_as_monitor_errors_title"><%=I18n.t(:errors, :scope => "acts_as_monitor.messages") %></h3>
8
+ <ul class="acts_as_monitor_list_errors">
9
+ <%@status[:error].each do |error| %>
10
+ <li class= "acts_as_monitor_list_errors"><%=I18n.t(error, :scope=> @li_scope, :default => error.to_s) %></li>
11
+ <% end %>
12
+ </ul>
13
+ <% end %>
14
+ <% unless @status[:warn].blank? %>
15
+ <h3 class="acts_as_monitor_warnings_title"><%=I18n.t(:warnings, :scope => "acts_as_monitor.messages") %></h3>
16
+ <ul class="acts_as_monitor_list_warnings">
17
+ <%@status[:warn].each do |warn| %>
18
+ <li class="acts_as_monitor_list_warnings"><%=I18n.t(warn, :scope=> @li_scope, :default => warn.to_s) %></li>
19
+ <% end %>
20
+ </ul>
21
+ <% end %>
22
+ <% else %>
23
+ <p><%= I18n.t(:missing_method, :scope=> "acts_as_monitor.errors", :default => "Add acts_as_monitor to monitored Class") %></p>
24
+ <% end %>
25
+
26
+
data/config/routes.rb CHANGED
@@ -1,4 +1,6 @@
1
1
  # CURRENT FILE :: config/routes.rb
2
2
  Rails.application.routes.draw do
3
- get "monitor" => "acts_as_monitor/monitor#index", :as => :acts_as_monitor
3
+ namespace :acts_as_monitor do
4
+ resources :monitors, :only =>[:show]
5
+ end
4
6
  end
@@ -1,15 +1,28 @@
1
1
  module ActsAsMonitor
2
2
  class Engine < Rails::Engine
3
- initialize "team_page.load_app_instance_data" do |app|
4
- TeamPage.setup do |config|
5
- config.app_root = app.root
3
+ # initialize "acts_as_monitor.load_app_instance_data" do |app|
4
+ # ActsAsMonitor.setup do |config|
5
+ # config.app_root = app.root
6
+ # end
7
+ # end
8
+ #
9
+ # initialize "acts_as_monitor.load_static_assets" do |app|
10
+ # app.middleware.use ::ActionDispatch::Static, "#{root}/public"
11
+ # end
12
+ #
13
+ #Includes models, controllers, helpers, config/routes.rb, config/locales/*, tasks in lib/tasks/*
14
+ engine_name :acts_as_monitor
15
+
16
+ initializer 'acts_as_monitor.helper' do |app|
17
+ #ActionView::Base.send :include, ActsAsMonitorHelper
18
+ ActiveSupport.on_load(:action_controller) do
19
+ include ActsAsMonitorHelper
6
20
  end
21
+ ActiveSupport.on_load(:action_view) do
22
+ include ActsAsMonitorHelper
23
+ end
24
+
7
25
  end
8
-
9
- initialize "team_page.load_static_assets" do |app|
10
- app.middleware.use ::ActionDispatch::Static, "#{root}/public"
11
- end
12
-
13
26
  end
14
27
 
15
28
  end
@@ -47,7 +47,7 @@ module ActsAsMonitor
47
47
  out = {:warn => [], :error => []}
48
48
  methods = self.private_methods.map{|m| m.match(search) }.compact
49
49
  methods.each do |method|
50
- out[method[1].to_sym] << method[0].to_sym if send(method[0])
50
+ out[method[1].to_sym] << method[0].gsub("?","").to_sym if send(method[0])
51
51
  end
52
52
  out
53
53
  end
@@ -1,3 +1,3 @@
1
1
  module ActsAsMonitor
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.9"
3
3
  end
@@ -1,15 +1,15 @@
1
- require "acts_as_monitor/version"
2
- require "acts_as_monitor/monitor"
3
- require File.dirname(__FILE__) + '/../app/helpers/monitor_helper'
1
+ require "active_support/dependencies"
4
2
 
5
3
  module ActsAsMonitor
6
- class MissingMethod < StandardError
7
- def message
8
- I18n.t(:missing_method, :scope => "acts_as_monitor.errors", :default => "Add acts_as_monitor to your class")
9
- end
4
+ mattr_accessor :app_root
5
+
6
+ def self.setup
7
+ yield self
10
8
  end
11
-
12
- #Include my Helper to ActionView (as they where in application_helper)
13
- ActionView::Base.send :include, ActsAsMonitor::Helper
14
9
 
15
10
  end
11
+
12
+ require "acts_as_monitor/engine"
13
+ #require "acts_as_monitor/version"
14
+ require "acts_as_monitor/monitor"
15
+ require "acts_as_monitor/exceptions"
@@ -1,31 +1,39 @@
1
1
  require 'rails/generators'
2
2
  module ActsAsMonitor
3
- class InstallGenerator < Rails::Generators::Base
4
- desc "Install generator for ActsAsMonitor gem"
5
- source_root File.expand_path("../templates", __FILE__)
3
+ class InstallGenerator < Rails::Generators::Base
4
+ desc "Install generator for ActsAsMonitor gem"
5
+ source_root File.expand_path("../templates", __FILE__)
6
6
 
7
- def copy_icons
8
- icons = ["acts_as_monitor_green.png", "acts_as_monitor_red.png", "acts_as_monitor_yellow.png"]
9
- icons.each do |icon|
10
- destination = "public/images/" + icon
11
- copy_file icon, destination
12
- end
13
- end
14
-
15
- def copy_locales
16
- file = "acts_as_monitor.it.yml"
17
- destination = "config/locales/" + file
18
- copy_file file, destination
19
- end
20
- end
21
-
22
- def print_usage
23
- usage = <<-START
24
- Add acts_as_monitor to model to monitor
25
- Add a private method warn_*? and error_*? to define warning and error status
26
- Use monitor_tag(model_instance) in your view
27
- START
28
- puts(usage)
7
+ def copy_icons
8
+ icons = ["acts_as_monitor_green.png", "acts_as_monitor_red.png", "acts_as_monitor_yellow.png", "acts_as_monitor_loading.gif"]
9
+ icons.each do |icon|
10
+ destination = "public/images/" + icon
11
+ copy_file icon, destination
29
12
  end
13
+ end
30
14
 
15
+ def copy_locales
16
+ file = "acts_as_monitor.it.yml"
17
+ destination = "config/locales/" + file
18
+ copy_file file, destination
19
+ end
20
+
21
+ def copy_javascripts
22
+ copy_file "acts_as_monitor_javascript.js", "public/javascripts/acts_as_monitor_javascript.js"
23
+ end
24
+
25
+ def copy_stylesheet
26
+ copy_file "acts_as_monitor.css", "public/stylesheets/acts_as_monitor.css"
27
+ end
28
+
29
+
30
+ def print_usage
31
+ usage = <<-START
32
+ Add acts_as_monitor to model to monitor
33
+ Add a private method warn_*? and error_*? to define warning and error status
34
+ Use monitor_tag(model_instance) in your view
35
+ START
36
+ puts(usage)
37
+ end
38
+ end
31
39
  end
@@ -0,0 +1,48 @@
1
+ .acts_as_monitor_status_window{
2
+ background-color: #F2F2F2;
3
+ border: solid black 1px;
4
+ opacity: 0.9;
5
+ width: 150px;
6
+ }
7
+
8
+ .acts_as_monitor_status_window legend{
9
+ opacity: 1.0;
10
+ background-color: #F2F2F2;
11
+ padding-left: 5px;
12
+ padding-right: 5px;
13
+ margin-left: 5px;
14
+ margin-right: 10px;
15
+
16
+ }
17
+
18
+ .acts_as_monitor_status_window h3.acts_as_monitor_errors_title{
19
+ font-weight: normal;
20
+ background-color: red;
21
+ text-align: center;
22
+ padding-left: 5px;
23
+ padding-right: 5px;
24
+ padding-top: 3px;
25
+ padding-bottom: 3px;
26
+ }
27
+
28
+ .acts_as_monitor_status_window h3.acts_as_monitor_warnings_title{
29
+ font-weight: normal;
30
+ background-color: #FACC2E;
31
+ text-align: center;
32
+ padding-left: 5px;
33
+ padding-right: 5px;
34
+ padding-top: 3px;
35
+ padding-bottom: 3px;
36
+ }
37
+
38
+ .acts_as_monitor_status_window ul{
39
+ margin-left: 10px;
40
+ }
41
+
42
+ li.acts_as_monitor_list_errors{
43
+ list-style-image: url('../images/acts_as_monitor_red.png');
44
+ }
45
+
46
+ li.acts_as_monitor_list_warnings{
47
+ list-style-image: url('../images/acts_as_monitor_yellow.png');
48
+ }
@@ -6,4 +6,11 @@ it:
6
6
  green: acts_as_monitor_green.png
7
7
  alt_image: "Clicca per visualizzare i dettagli"
8
8
  errors:
9
- missing_method: "Aggiungi acts_as_monitor alla classe da monitorare"
9
+ missing_method: "Aggiungi acts_as_monitor alla classe da monitorare"
10
+ messages:
11
+ errors: Errori
12
+ warnings: Avvisi
13
+ #test_clas: #class name (TestClass)
14
+ #warn_test: "Warning Test" #warning method name
15
+ #error_test: "Error Test" #error method name
16
+ #myspace_test_class: #class name (Myspace::TestClass)
@@ -0,0 +1,78 @@
1
+ document.observe('dom:loaded', function()
2
+ {
3
+ var application_root ='';
4
+ create_status_window();
5
+ //alert(application_root);
6
+
7
+ function create_status_window() {
8
+ /*new Insertion.Bottom(
9
+ document.body,
10
+ "<div id='acts_as_monitor_status_window'><%= Rails.root %></div>"
11
+ );*/
12
+ var status_window = $('acts_as_monitor_status_window');
13
+ Position.absolutize(status_window);
14
+ status_window.observe('click', function(ev) {status_window.fade(); });
15
+ status_window.hide();
16
+ //The helper provide the Rails.root inside the created div...
17
+ application_root = status_window.innerHTML;
18
+ }
19
+
20
+ var handle_monitor = function(ev)
21
+ {
22
+ var id = ev.target.getAttribute('data-id');
23
+ var image = ev.target.src;
24
+ new Ajax.Request(application_root + '/acts_as_monitor/monitors/'+ id +'.js',
25
+ {
26
+ method: 'get',
27
+ evalJSON: 'force',
28
+ parameters: {
29
+ class_name: ev.target.getAttribute('data-class')
30
+ },
31
+ onLoading: function(response){
32
+ ev.target.src = application_root + '/images/acts_as_monitor_loading.gif';
33
+ },
34
+ onSuccess: function(response){
35
+ var rsp = response.responseJSON;
36
+ ev.target.src = image;
37
+ create_popup(rsp.text,ev.target);
38
+ },
39
+ onFailure: function(response)
40
+ {
41
+ alert('Failure ' + response.status);
42
+ }
43
+ });
44
+ }
45
+
46
+ //Create popup with information
47
+ function create_popup(text,target)
48
+ {
49
+ //alert(text);
50
+ var status_window = $('acts_as_monitor_status_window');
51
+ status_window.update(text);
52
+ Position.clone(target,
53
+ status_window, {
54
+ offsetLeft: 20
55
+ });
56
+ new Effect.Appear(status_window);
57
+ //alert("Fatto");
58
+ }
59
+
60
+ //$$('.acts_as_monitor_icon_red .acts_as_monitor_icon_yellow .acts_as_monitor_icon_green')
61
+ var pulsate_forever = function(elem) {
62
+ new Effect.Pulsate(elem, {
63
+ //afterFinish: function(o) { new Effect.Pulsate(o.element, o.options); }
64
+ duration: 600,
65
+ pulses: 1500
66
+ });
67
+ }
68
+ $$('.acts_as_monitor_icon_red').each(function(elmt)
69
+ {
70
+ elmt.observe('click', handle_monitor);
71
+ pulsate_forever(elmt);
72
+ });
73
+
74
+ $$('.acts_as_monitor_icon_yellow').each(function(elmt)
75
+ {
76
+ elmt.observe('click', handle_monitor);
77
+ });
78
+ });
@@ -0,0 +1,16 @@
1
+ require 'test_helper'
2
+
3
+ class ActsAsMonitorHelperTest < ActionView::TestCase
4
+ test "monitor_tag return image" do
5
+ @test_class = TestClass.new
6
+ @image = image_tag("acts_as_monitor_#{@test_class.status_flag.to_s}.png" , :alt => "Click to view details")
7
+ assert monitor_tag(@test_class) == @image , "fail monitor tag :#{monitor_tag(TestClass.new)}"
8
+ end
9
+
10
+ test "monitor_tag Rise exception" do
11
+ assert_raise ActsAsMonitor::MissingMethod do
12
+ monitor_tag(TestClassNoMonitor.new)
13
+ end
14
+ end
15
+ end
16
+
@@ -1,9 +1,6 @@
1
1
  require 'test_helper'
2
2
 
3
3
  class ActsAsMonitorTest < ActiveSupport::TestCase
4
- include ActionView::Helpers
5
- include ActsAsMonitor::Helper
6
-
7
4
  test "Methods exists!" do
8
5
  @test_class = TestClass.new
9
6
  assert TestClass.respond_to?(:acts_as_monitor), "acts_as_monitor missing!"
@@ -19,34 +16,20 @@ class ActsAsMonitorTest < ActiveSupport::TestCase
19
16
 
20
17
  test "Status warn" do
21
18
  @test_class = TestClass.new(:warn => true)
22
- assert @test_class.status == {:warn => [:warn_test? ], :error => []} , "Error: #{@test_class.status.inspect}"
19
+ assert @test_class.status == {:warn => [:warn_test ], :error => []} , "Error: #{@test_class.status.inspect}"
23
20
  assert @test_class.status_flag == :yellow , "Error: #{@test_class.status_flag.inspect}"
24
21
  end
25
22
 
26
23
  test "Status error" do
27
24
  @test_class = TestClass.new(:error => true)
28
- assert @test_class.status == {:warn => [], :error => [:error_test? ]}, "Error: #{@test_class.status.inspect}"
25
+ assert @test_class.status == {:warn => [], :error => [:error_test ]}, "Error: #{@test_class.status.inspect}"
29
26
  assert @test_class.status_flag == :red , "Error: #{@test_class.status_flag.inspect}"
30
27
  end
31
28
 
32
29
  test "Status error & warn " do
33
30
  @test_class = TestClass.new(:error => true, :warn => true)
34
- assert @test_class.status == {:warn => [:warn_test? ], :error => [:error_test? ]}, "Error: #{@test_class.status.inspect}"
31
+ assert @test_class.status == {:warn => [:warn_test ], :error => [:error_test ]}, "Error: #{@test_class.status.inspect}"
35
32
  assert @test_class.status_flag == :red , "Error: #{@test_class.status_flag.inspect}"
36
33
  end
37
34
 
38
- test "monitor_tag return image" do
39
- @test_class = TestClass.new
40
- @image = image_tag("acts_as_monitor_#{@test_class.status_flag.to_s}.png" , :alt => "Click to view details")
41
- assert monitor_tag(@test_class) == @image , "fail monitor tag :#{monitor_tag(TestClass.new)}"
42
- end
43
-
44
- test "monitor_tag Rise exception" do
45
- assert_raise ActsAsMonitor::MissingMethod do
46
- monitor_tag(TestClassNoMonitor.new)
47
- end
48
- end
49
-
50
-
51
-
52
35
  end
@@ -0,0 +1,7 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require File.expand_path('../config/application', __FILE__)
5
+ require 'rake'
6
+
7
+ Dummy::Application.load_tasks
@@ -0,0 +1,3 @@
1
+ class ApplicationController < ActionController::Base
2
+ protect_from_forgery
3
+ end
@@ -0,0 +1,4 @@
1
+ class HomesController < ApplicationController
2
+ def index
3
+ end
4
+ end
@@ -0,0 +1,2 @@
1
+ module ApplicationHelper
2
+ end
@@ -0,0 +1,2 @@
1
+ module HomesHelper
2
+ end
@@ -0,0 +1,33 @@
1
+ class TestClass < ActiveRecord::Base
2
+ acts_as_monitor
3
+ attr_accessor :warn, :error
4
+
5
+ after_initialize do
6
+ @warn ||= false
7
+ @error ||= false
8
+ end
9
+
10
+
11
+ private
12
+
13
+ def warn_test?
14
+ @warn
15
+ end
16
+
17
+ def error_test?
18
+ @error
19
+ end
20
+
21
+ def warn_paperino?
22
+ return true if self.name == 'Paperino'
23
+ end
24
+
25
+ def error_pippo?
26
+ return true if self.name == 'Pippo'
27
+ end
28
+
29
+ def error_id?
30
+ return true if self.id == 1
31
+ end
32
+
33
+ end
@@ -0,0 +1,2 @@
1
+ class TestClassNoMonitor
2
+ end
@@ -0,0 +1,8 @@
1
+ <p>Home Page</p>
2
+ <%= javascript_include_tag :defaults %>
3
+ <%= monitor_tag_js %>
4
+ <ul>
5
+ <% TestClass.all.each do |u| %>
6
+ <li><p><%= u.name %></p><p><%= u.status_flag %></p><%=monitor_tag(u) %></li>
7
+ <% end %>
8
+ </ul>
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Dummy</title>
5
+ <%= stylesheet_link_tag :all %>
6
+ <%= javascript_include_tag :defaults %>
7
+ <%= csrf_meta_tag %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
@@ -0,0 +1,45 @@
1
+ require File.expand_path('../boot', __FILE__)
2
+
3
+ require "active_model/railtie"
4
+ require "active_record/railtie"
5
+ require "action_controller/railtie"
6
+ require "action_view/railtie"
7
+ require "action_mailer/railtie"
8
+
9
+ Bundler.require
10
+ require "acts_as_monitor"
11
+
12
+ module Dummy
13
+ class Application < Rails::Application
14
+ # Settings in config/environments/* take precedence over those specified here.
15
+ # Application configuration should go into files in config/initializers
16
+ # -- all .rb files in that directory are automatically loaded.
17
+
18
+ # Custom directories with classes and modules you want to be autoloadable.
19
+ # config.autoload_paths += %W(#{config.root}/extras)
20
+
21
+ # Only load the plugins named here, in the order given (default is alphabetical).
22
+ # :all can be used as a placeholder for all plugins not explicitly named.
23
+ # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
24
+
25
+ # Activate observers that should always be running.
26
+ # config.active_record.observers = :cacher, :garbage_collector, :forum_observer
27
+
28
+ # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
29
+ # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
30
+ # config.time_zone = 'Central Time (US & Canada)'
31
+
32
+ # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
33
+ # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
34
+ # config.i18n.default_locale = :de
35
+
36
+ # JavaScript files you want as :defaults (application.js is always included).
37
+ # config.action_view.javascript_expansions[:defaults] = %w(jquery rails)
38
+
39
+ # Configure the default encoding used in templates for Ruby 1.9.
40
+ config.encoding = "utf-8"
41
+
42
+ # Configure sensitive parameters which will be filtered from the log file.
43
+ config.filter_parameters += [:password]
44
+ end
45
+ end
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ gemfile = File.expand_path('../../../../Gemfile', __FILE__)
3
+
4
+ if File.exist?(gemfile)
5
+ ENV['BUNDLE_GEMFILE'] = gemfile
6
+ require 'bundler'
7
+ Bundler.setup
8
+ end
9
+
10
+ $:.unshift File.expand_path('../../../../lib', __FILE__)
@@ -0,0 +1,22 @@
1
+ # SQLite version 3.x
2
+ # gem install sqlite3
3
+ development:
4
+ adapter: sqlite3
5
+ database: db/development.sqlite3
6
+ pool: 5
7
+ timeout: 5000
8
+
9
+ # Warning: The database defined as "test" will be erased and
10
+ # re-generated from your development database when you run "rake".
11
+ # Do not set this db to the same as development or production.
12
+ test:
13
+ adapter: sqlite3
14
+ database: db/test.sqlite3
15
+ pool: 5
16
+ timeout: 5000
17
+
18
+ production:
19
+ adapter: sqlite3
20
+ database: db/production.sqlite3
21
+ pool: 5
22
+ timeout: 5000
@@ -0,0 +1,5 @@
1
+ # Load the rails application
2
+ require File.expand_path('../application', __FILE__)
3
+
4
+ # Initialize the rails application
5
+ Dummy::Application.initialize!