yoon-view_trail 0.2.2 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +22 -8
- data/VERSION +1 -1
- data/features/step_definitions/view_trail_steps.rb +9 -1
- data/features/support/env.rb +6 -1
- data/features/support/paths.rb +0 -18
- data/features/view_trail.feature +7 -1
- data/generators/view_trail/templates/{create_activities.rb → create_activities_and_items.rb} +8 -4
- data/generators/view_trail/view_trail_generator.rb +2 -1
- data/lib/view_trail/activity.rb +1 -0
- data/lib/view_trail/activity_item.rb +3 -0
- data/lib/view_trail.rb +9 -1
- data/view_trail.gemspec +3 -2
- metadata +3 -2
data/README.md
CHANGED
@@ -10,15 +10,29 @@ Works with Rails 2.3.
|
|
10
10
|
|
11
11
|
class FooController < ActionController::Base
|
12
12
|
has_view_trail :except => :index
|
13
|
+
|
14
|
+
def index
|
15
|
+
end
|
16
|
+
|
17
|
+
def search
|
18
|
+
@results = Model.search(params[:query])
|
19
|
+
|
20
|
+
audit({:results => @results.map(&:id), :flag => "blue"})
|
21
|
+
end
|
13
22
|
end
|
14
23
|
|
15
|
-
Takes :except and :only conditions like other controller filters
|
24
|
+
Takes :except and :only conditions like other controller filters
|
16
25
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
>> Activities.last.
|
26
|
+
Also allows you to audit an arbitrary key/value hash
|
27
|
+
|
28
|
+
For example: when you visit /foo/search?query=pie
|
29
|
+
|
30
|
+
>> Activities.last.whodunnit #=> (@controller.current_user)
|
31
|
+
>> Activities.last.created_at #=> (date/time of activity)
|
32
|
+
>> Activities.last.controller #=> FooController
|
33
|
+
>> Activities.last.action #=> "search"
|
34
|
+
>> Activities.last.params #=> {:query => "pie"}
|
35
|
+
>> Activities.last.activity_items #=> [{:key => :results, :value => [2, 12, 14]}], [{:key => :flag, :value => "blue"}]
|
22
36
|
|
23
37
|
## Installation
|
24
38
|
|
@@ -36,9 +50,9 @@ Takes :except and :only conditions like other controller filters
|
|
36
50
|
|
37
51
|
4. Add `has view_trail` to the controllers you want to track
|
38
52
|
|
39
|
-
##
|
53
|
+
## Issues
|
40
54
|
|
41
|
-
|
55
|
+
Please submit issues via GitHub's [Issue Tracker](http://github.com/yoon/view_trail/issues)
|
42
56
|
|
43
57
|
## Inspiration
|
44
58
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.0
|
@@ -23,7 +23,15 @@ Given /^I ([^ ]*) the ([^ ]*) page with params$/ do |method, page|
|
|
23
23
|
end
|
24
24
|
|
25
25
|
Then /^the last activity should have params$/ do
|
26
|
-
Activity.last.params.should == HashWithIndifferentAccess.new({:check => "yourself"})
|
26
|
+
HashWithIndifferentAccess.new(Activity.last.params).should == HashWithIndifferentAccess.new({:check => "yourself"})
|
27
|
+
end
|
28
|
+
|
29
|
+
Then /^the last activity should have data$/ do
|
30
|
+
Activity.last.activity_items.should have(2).activity_items
|
31
|
+
Activity.last.activity_items.first.key.should == "pi"
|
32
|
+
Activity.last.activity_items.first.value.should == [3,1,4,1,5,9]
|
33
|
+
Activity.last.activity_items.last.key.should == "pie"
|
34
|
+
Activity.last.activity_items.last.value.should == ["apple", "blueberry", "pecan", "strawberry"]
|
27
35
|
end
|
28
36
|
|
29
37
|
|
data/features/support/env.rb
CHANGED
@@ -37,10 +37,15 @@ class FooController < ApplicationController
|
|
37
37
|
def bar
|
38
38
|
head :ok
|
39
39
|
end
|
40
|
+
def baz
|
41
|
+
audit({:pi => [3,1,4,1,5,9], :pie => ["apple", "blueberry", "pecan", "strawberry"]})
|
42
|
+
head :ok
|
43
|
+
end
|
40
44
|
end
|
41
45
|
|
42
46
|
# Sets up routes
|
43
47
|
ActionController::Routing::Routes.draw do |map|
|
44
48
|
map.foo "/foo", :controller => "foo", :action => "foo"
|
45
|
-
map.
|
49
|
+
map.bar "/bar", :controller => "foo", :action => "bar"
|
50
|
+
map.baz "/baz", :controller => "foo", :action => "baz"
|
46
51
|
end
|
data/features/support/paths.rb
CHANGED
@@ -10,24 +10,6 @@ module NavigationHelpers
|
|
10
10
|
|
11
11
|
when /the homepage/
|
12
12
|
default_path
|
13
|
-
|
14
|
-
when /the login page/
|
15
|
-
authentication_index_path
|
16
|
-
|
17
|
-
when /the dashboard/
|
18
|
-
dashboard_path
|
19
|
-
|
20
|
-
when /the all studies page/
|
21
|
-
studies_path
|
22
|
-
|
23
|
-
when /my subjects/
|
24
|
-
subjects_path
|
25
|
-
|
26
|
-
when /the study page for id "([^\"]*)"/
|
27
|
-
"/studies/#{$1}"
|
28
|
-
|
29
|
-
when /the search page/
|
30
|
-
search_path
|
31
13
|
|
32
14
|
# Add more mappings here.
|
33
15
|
# Here is a more fancy example:
|
data/features/view_trail.feature
CHANGED
@@ -32,11 +32,17 @@ Feature: ViewTrail
|
|
32
32
|
And the last activity should have "312" whodunnit
|
33
33
|
And the last activity should have "foo" action
|
34
34
|
|
35
|
-
Scenario: GET request
|
35
|
+
Scenario: GET request with params
|
36
36
|
Given I get the foo page with params
|
37
37
|
Then I should have 5 activities
|
38
38
|
And the last activity should have params
|
39
39
|
|
40
|
+
Scenario: GET request with params and arbitrary data
|
41
|
+
Given I get the baz page with params
|
42
|
+
Then I should have 6 activities
|
43
|
+
And the last activity should have data
|
44
|
+
And the last activity should have params
|
45
|
+
|
40
46
|
Scenario: GET request on excepted path
|
41
47
|
Given I have 0 activities
|
42
48
|
When I get the bar page
|
data/generators/view_trail/templates/{create_activities.rb → create_activities_and_items.rb}
RENAMED
@@ -1,4 +1,4 @@
|
|
1
|
-
class
|
1
|
+
class CreateActivitiesAndItems < ActiveRecord::Migration
|
2
2
|
def self.up
|
3
3
|
create_table :activities do |t|
|
4
4
|
t.string :controller
|
@@ -6,12 +6,16 @@ class CreateActivities < ActiveRecord::Migration
|
|
6
6
|
t.text :params
|
7
7
|
t.string :whodunnit
|
8
8
|
t.datetime :created_at
|
9
|
+
end
|
10
|
+
create_table :activity_items do |t|
|
11
|
+
t.integer :activity_id
|
12
|
+
t.string :key
|
13
|
+
t.text :value
|
9
14
|
end
|
10
|
-
# add_index :activities, [:item_type, :item_id]
|
11
15
|
end
|
12
16
|
|
13
17
|
def self.down
|
14
|
-
# remove_index :activities, [:item_type, :item_id]
|
15
18
|
drop_table :activities
|
19
|
+
drop_table :activity_items
|
16
20
|
end
|
17
|
-
end
|
21
|
+
end
|
@@ -2,8 +2,9 @@ class ViewTrailGenerator < Rails::Generator::Base
|
|
2
2
|
|
3
3
|
def manifest
|
4
4
|
record do |m|
|
5
|
-
m.migration_template '
|
5
|
+
m.migration_template 'create_activities_and_items.rb', 'db/migrate', :migration_file_name => 'create_activities_and_items'
|
6
6
|
end
|
7
|
+
|
7
8
|
end
|
8
9
|
|
9
10
|
end
|
data/lib/view_trail/activity.rb
CHANGED
data/lib/view_trail.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'view_trail/activity'
|
2
|
+
require 'view_trail/activity_item'
|
2
3
|
|
3
4
|
module ViewTrail
|
4
5
|
@@whodunnit = nil
|
@@ -42,9 +43,16 @@ module ViewTrail
|
|
42
43
|
end
|
43
44
|
|
44
45
|
module InstanceMethods
|
46
|
+
def audit(items)
|
47
|
+
@activity_items = items
|
48
|
+
end
|
45
49
|
def record_activity
|
46
50
|
if self.class.view_trail_active
|
47
|
-
Activity.create(:whodunnit => ViewTrail.whodunnit, :controller => params.delete(:controller), :action => params.delete(:action), :params => params)
|
51
|
+
a = Activity.create(:whodunnit => ViewTrail.whodunnit, :controller => params.delete(:controller), :action => params.delete(:action), :params => params)
|
52
|
+
(@activity_items || {}).each do |k,v|
|
53
|
+
a.activity_items.create(:key => k.to_s, :value => v)
|
54
|
+
end
|
55
|
+
@activity_items = nil
|
48
56
|
end
|
49
57
|
end
|
50
58
|
end
|
data/view_trail.gemspec
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{view_trail}
|
5
|
-
s.version = "0.
|
5
|
+
s.version = "0.3.0"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Mark Yoon"]
|
@@ -25,10 +25,11 @@ Gem::Specification.new do |s|
|
|
25
25
|
"features/support/env.rb",
|
26
26
|
"features/support/paths.rb",
|
27
27
|
"features/view_trail.feature",
|
28
|
-
"generators/view_trail/templates/
|
28
|
+
"generators/view_trail/templates/create_activities_and_items.rb",
|
29
29
|
"generators/view_trail/view_trail_generator.rb",
|
30
30
|
"lib/view_trail.rb",
|
31
31
|
"lib/view_trail/activity.rb",
|
32
|
+
"lib/view_trail/activity_item.rb",
|
32
33
|
"spec/spec_helper.rb",
|
33
34
|
"spec/view_trail_spec.rb",
|
34
35
|
"view_trail.gemspec"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yoon-view_trail
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mark Yoon
|
@@ -34,10 +34,11 @@ files:
|
|
34
34
|
- features/support/env.rb
|
35
35
|
- features/support/paths.rb
|
36
36
|
- features/view_trail.feature
|
37
|
-
- generators/view_trail/templates/
|
37
|
+
- generators/view_trail/templates/create_activities_and_items.rb
|
38
38
|
- generators/view_trail/view_trail_generator.rb
|
39
39
|
- lib/view_trail.rb
|
40
40
|
- lib/view_trail/activity.rb
|
41
|
+
- lib/view_trail/activity_item.rb
|
41
42
|
- spec/spec_helper.rb
|
42
43
|
- spec/view_trail_spec.rb
|
43
44
|
- view_trail.gemspec
|