mole 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -17,19 +17,28 @@ class MoleFeature < ActiveRecord::Base
17
17
  def find_exception_feature( app_name )
18
18
  find_or_create_feature( exception, app_name )
19
19
  end
20
-
20
+
21
+ # Find the all feature ( wildcard feature for given app )
21
22
  def find_all_feature( app_name )
22
23
  find_or_create_feature( all, app_name )
23
24
  end
24
-
25
+
26
+ # Find all the MOled applications
27
+ def find_moled_application_names
28
+ res = find( :all,
29
+ :select => "distinct( app_name )",
30
+ :order => "name asc" )
31
+ res.map(&:app_name)
32
+ end
33
+
25
34
  # Finds all the features available for a given application
26
35
  def find_features( app_name )
27
36
  # Creates the all feature if necessary
28
37
  find_all_feature( app_name )
29
- MoleFeature.find( :all,
30
- :conditions => ["app_name = ?", app_name],
31
- :select => "id, name, context",
32
- :order => "name asc" )
38
+ find( :all,
39
+ :conditions => ["app_name = ?", app_name],
40
+ :select => "id, name, context",
41
+ :order => "name asc" )
33
42
  end
34
43
 
35
44
  # locates an existing feature or create a new one if it does not exist.
@@ -37,9 +46,13 @@ class MoleFeature < ActiveRecord::Base
37
46
  if name.nil? or name.empty?
38
47
  ::Mole.logger.error( "--- MOLE ERROR - Invalid feature. Empty or nil" )
39
48
  return nil
40
- end
41
- find_by_name_and_context_and_app_name( name, ctx_name, app_name ) ||
42
- create(:name => name,:context => ctx_name, :app_name => app_name )
49
+ end
50
+ if ctx_name
51
+ res = find_by_name_and_context_and_app_name( name, ctx_name, app_name )
52
+ else
53
+ res = find_by_name_and_app_name( name, app_name )
54
+ end
55
+ res || create(:name => name,:context => ctx_name, :app_name => app_name )
43
56
  end
44
57
  end
45
58
  end
@@ -4,7 +4,7 @@
4
4
  class MoleLog < ActiveRecord::Base
5
5
  belongs_to :mole_feature
6
6
 
7
- class << self
7
+ class << self
8
8
  # mole the bastard - create db entry into mole logs
9
9
  def log_it( context, feature, user_id, args )
10
10
  args ||= "no args"
@@ -16,8 +16,8 @@ class MoleLog < ActiveRecord::Base
16
16
  :params => args.to_yaml,
17
17
  :ip_address => ip_addr,
18
18
  :browser_type => browser_type )
19
- end
20
-
19
+ end
20
+
21
21
  # extract orginating ip address and browser type
22
22
  def log_details( context ) #:nodoc:
23
23
  ip_addr, browser_type = nil
@@ -25,6 +25,7 @@ class MoleLog < ActiveRecord::Base
25
25
  ip_addr, browser_type = context.request.env['REMOTE_ADDR'], context.request.env['HTTP_USER_AGENT']
26
26
  end
27
27
  return ip_addr, browser_type
28
- end
29
- end
28
+ end
29
+ end
30
+
30
31
  end
data/lib/mole/version.rb CHANGED
@@ -2,7 +2,7 @@ module Mole
2
2
  module Version
3
3
  MAJOR = 1
4
4
  MINOR = 0
5
- TINY = 1
5
+ TINY = 2
6
6
 
7
7
  # Returns the version string for the library.
8
8
  #
@@ -3,7 +3,10 @@ require File.join(File.dirname(__FILE__), "..", "spec_helper" )
3
3
  describe MoleFeature do
4
4
  before( :each ) do
5
5
  ::Mole.reset_configuration!
6
- ::Mole.initialize( :mode => :persistent, :log_level => :debug, :moleable => true )
6
+ ::Mole.initialize( :application => "Test",
7
+ :mode => :persistent,
8
+ :log_level => :debug,
9
+ :moleable => true )
7
10
  end
8
11
 
9
12
  it "should find or create known features correctly" do
@@ -33,5 +36,13 @@ describe MoleFeature do
33
36
  MoleFeature.find_or_create_feature( "Fred", ::Mole.application, self.class.name )
34
37
  features = MoleFeature.find_features( ::Mole.application )
35
38
  features.should have(4).mole_features
39
+ end
40
+
41
+ it "should find moled application names correctly" do
42
+ MoleFeature.find_moled_application_names.should be_empty
43
+ %w[ all performance exception].each do |f|
44
+ feature = MoleFeature.send( "find_#{f}_feature".to_sym, ::Mole.application )
45
+ end
46
+ MoleFeature.find_moled_application_names.should == ["Test"]
36
47
  end
37
48
  end
@@ -1,4 +1,5 @@
1
1
  require File.join(File.dirname(__FILE__), "..", "spec_helper" )
2
+ require 'ostruct'
2
3
 
3
4
  describe MoleLog do
4
5
  before( :each ) do
@@ -42,8 +43,8 @@ describe MoleLog do
42
43
  log = check_it( feature, 400, @args )
43
44
  log.ip_address.should == "1.1.1.1"
44
45
  log.browser_type.should == "GodZilla"
45
- end
46
-
46
+ end
47
+
47
48
  module Moled
48
49
  class Controller
49
50
  class Request
metadata CHANGED
@@ -3,7 +3,7 @@ rubygems_version: 0.9.4
3
3
  specification_version: 1
4
4
  name: mole
5
5
  version: !ruby/object:Gem::Version
6
- version: 1.0.1
6
+ version: 1.0.2
7
7
  date: 2008-03-02 00:00:00 -07:00
8
8
  summary: A flexible way to track user's interactions within your ruby web applications
9
9
  require_paths: