Commit 988f4a83baa35e706fd423895e0106b0d99fc428
1 parent
5a2e9ad1
Exists in
theme-brasil-digital-from-staging
and in
9 other branches
#community dashboard - add unit test
Showing
1 changed file
with
31 additions
and
0 deletions
Show diff stats
plugins/community_hub/test/unit/community_hub_plugin/listener_test.rb
0 → 100644
| ... | ... | @@ -0,0 +1,31 @@ |
| 1 | +require File.dirname(__FILE__) + '/../../test_helper' | |
| 2 | + | |
| 3 | +class ListenerTest < ActiveSupport::TestCase | |
| 4 | + | |
| 5 | + should 'initialize logger' do | |
| 6 | + logger = CommunityHubPlugin::Listener.initialize_logger | |
| 7 | + logfile = logger.instance_variable_get(:@logdev).instance_variable_get(:@filename) | |
| 8 | + assert_instance_of(Logger, logger) | |
| 9 | + assert File.exists?(logfile) | |
| 10 | + end | |
| 11 | + | |
| 12 | + should 'log message' do | |
| 13 | + logdir = File.join(RAILS_ROOT, 'log', CommunityHubPlugin::Listener.name.underscore) | |
| 14 | + | |
| 15 | + if File.exists?(logdir) | |
| 16 | + Dir.foreach(logdir) { |f| | |
| 17 | + fn = File.join(logdir, f); | |
| 18 | + File.delete(fn) if f != '.' && f != '..' | |
| 19 | + } | |
| 20 | + end | |
| 21 | + | |
| 22 | + logger = CommunityHubPlugin::Listener.initialize_logger | |
| 23 | + CommunityHubPlugin::Listener.log('testmessage') | |
| 24 | + | |
| 25 | + logfile = logger.instance_variable_get(:@logdev).instance_variable_get(:@filename) | |
| 26 | + text = File.open(logfile).read | |
| 27 | + | |
| 28 | + assert_match /testmessage/, text | |
| 29 | + end | |
| 30 | + | |
| 31 | +end | ... | ... |