yoon-view_trail 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -47,3 +47,9 @@ Rake::RDocTask.new do |rdoc|
47
47
  rdoc.rdoc_files.include('lib/**/*.rb')
48
48
  end
49
49
 
50
+ # $:.unshift(File.dirname(__FILE__) + '/../../lib')
51
+ require 'cucumber/rake/task'
52
+ Cucumber::Rake::Task.new do |t|
53
+ t.cucumber_opts = %w{--format pretty}
54
+ end
55
+
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.2.1
@@ -0,0 +1,20 @@
1
+ Given /^I current user is (\d*)$/ do |id|
2
+ ApplicationController.cu = id
3
+ end
4
+
5
+ Given /^I have 0 activities$/ do
6
+ Activity.destroy_all
7
+ end
8
+
9
+ Given /^I ([^ ]*) the ([^ ]*) page$/ do |method, page|
10
+ visit page, method.to_sym
11
+ end
12
+
13
+ Then /^I should have (\d*) activities$/ do |number|
14
+ Activity.count.should == number.to_i
15
+ end
16
+
17
+ Then /^the last activity should have "([^\"]*)" ([^ ]*)$/ do |value, key|
18
+ Activity.last.send(key.to_sym).to_s.should == value
19
+ end
20
+
@@ -0,0 +1,119 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "paths"))
2
+
3
+ # Commonly used webrat steps
4
+ # http://github.com/brynary/webrat
5
+
6
+ Given /^I am on (.+)$/ do |page_name|
7
+ visit path_to(page_name)
8
+ end
9
+
10
+ When /^I go to (.+)$/ do |page_name|
11
+ visit path_to(page_name)
12
+ end
13
+
14
+ When /^I press "([^\"]*)"$/ do |button|
15
+ click_button(button)
16
+ end
17
+
18
+ When /^I follow "([^\"]*)"$/ do |link|
19
+ click_link(link)
20
+ end
21
+
22
+ When /^I fill in "([^\"]*)" with "([^\"]*)"$/ do |field, value|
23
+ fill_in(field, :with => value)
24
+ end
25
+
26
+ When /^I select "([^\"]*)" from "([^\"]*)"$/ do |value, field|
27
+ select(value, :from => field)
28
+ end
29
+
30
+ # Use this step in conjunction with Rail's datetime_select helper. For example:
31
+ # When I select "December 25, 2008 10:00" as the date and time
32
+ When /^I select "([^\"]*)" as the date and time$/ do |time|
33
+ select_datetime(time)
34
+ end
35
+
36
+ # Use this step when using multiple datetime_select helpers on a page or
37
+ # you want to specify which datetime to select. Given the following view:
38
+ # <%= f.label :preferred %><br />
39
+ # <%= f.datetime_select :preferred %>
40
+ # <%= f.label :alternative %><br />
41
+ # <%= f.datetime_select :alternative %>
42
+ # The following steps would fill out the form:
43
+ # When I select "November 23, 2004 11:20" as the "Preferred" date and time
44
+ # And I select "November 25, 2004 10:30" as the "Alternative" date and time
45
+ When /^I select "([^\"]*)" as the "([^\"]*)" date and time$/ do |datetime, datetime_label|
46
+ select_datetime(datetime, :from => datetime_label)
47
+ end
48
+
49
+ # Use this step in conjunction with Rail's time_select helper. For example:
50
+ # When I select "2:20PM" as the time
51
+ # Note: Rail's default time helper provides 24-hour time-- not 12 hour time. Webrat
52
+ # will convert the 2:20PM to 14:20 and then select it.
53
+ When /^I select "([^\"]*)" as the time$/ do |time|
54
+ select_time(time)
55
+ end
56
+
57
+ # Use this step when using multiple time_select helpers on a page or you want to
58
+ # specify the name of the time on the form. For example:
59
+ # When I select "7:30AM" as the "Gym" time
60
+ When /^I select "([^\"]*)" as the "([^\"]*)" time$/ do |time, time_label|
61
+ select_time(time, :from => time_label)
62
+ end
63
+
64
+ # Use this step in conjunction with Rail's date_select helper. For example:
65
+ # When I select "February 20, 1981" as the date
66
+ When /^I select "([^\"]*)" as the date$/ do |date|
67
+ select_date(date)
68
+ end
69
+
70
+ # Use this step when using multiple date_select helpers on one page or
71
+ # you want to specify the name of the date on the form. For example:
72
+ # When I select "April 26, 1982" as the "Date of Birth" date
73
+ When /^I select "([^\"]*)" as the "([^\"]*)" date$/ do |date, date_label|
74
+ select_date(date, :from => date_label)
75
+ end
76
+
77
+ When /^I check "([^\"]*)"$/ do |field|
78
+ check(field)
79
+ end
80
+
81
+ When /^I uncheck "([^\"]*)"$/ do |field|
82
+ uncheck(field)
83
+ end
84
+
85
+ When /^I choose "([^\"]*)"$/ do |field|
86
+ choose(field)
87
+ end
88
+
89
+ When /^I attach the file at "([^\"]*)" to "([^\"]*)"$/ do |path, field|
90
+ attach_file(field, path)
91
+ end
92
+
93
+ Then /^I should see "([^\"]*)"$/ do |text|
94
+ response.should contain(text)
95
+ end
96
+
97
+ Then /^I should not see "([^\"]*)"$/ do |text|
98
+ response.should_not contain(text)
99
+ end
100
+
101
+ Then /^the "([^\"]*)" field should contain "([^\"]*)"$/ do |field, value|
102
+ field_labeled(field).value.should =~ /#{value}/
103
+ end
104
+
105
+ Then /^the "([^\"]*)" field should not contain "([^\"]*)"$/ do |field, value|
106
+ field_labeled(field).value.should_not =~ /#{value}/
107
+ end
108
+
109
+ Then /^the "([^\"]*)" checkbox should be checked$/ do |label|
110
+ field_labeled(label).should be_checked
111
+ end
112
+
113
+ Then /^the "([^\"]*)" checkbox should not be checked$/ do |label|
114
+ field_labeled(label).should_not be_checked
115
+ end
116
+
117
+ Then /^I should be on (.+)$/ do |page_name|
118
+ URI.parse(current_url).path.should == path_to(page_name)
119
+ end
@@ -0,0 +1,46 @@
1
+ # Sets up the Rails environment for Cucumber
2
+ ENV['RAILS_ENV'] = 'test'
3
+ ENV['RAILS_ROOT'] ||= File.dirname(__FILE__) + '/../../../../..'
4
+ require File.expand_path(File.join(ENV['RAILS_ROOT'], 'config/environment.rb'))
5
+ require 'cucumber/rails/world'
6
+
7
+ # Sets up webrat
8
+ require 'webrat'
9
+
10
+ Webrat.configure do |config|
11
+ config.mode = :rails
12
+ end
13
+
14
+ require 'cucumber/rails/rspec'
15
+ require 'webrat/core/matchers'
16
+
17
+ # Sets up controllers
18
+ require 'application_controller'
19
+ require 'view_trail'
20
+
21
+ class ApplicationController
22
+ def rescue_action(e)
23
+ raise e
24
+ end
25
+ cattr_accessor :cu
26
+ # Returns id of hypothetical current user
27
+ def current_user
28
+ self.cu
29
+ end
30
+ end
31
+
32
+ class FooController < ApplicationController
33
+ has_view_trail :except => :bar
34
+ def foo
35
+ head :ok
36
+ end
37
+ def bar
38
+ head :ok
39
+ end
40
+ end
41
+
42
+ # Sets up routes
43
+ ActionController::Routing::Routes.draw do |map|
44
+ map.foo "/foo", :controller => "foo", :action => "foo"
45
+ map.foo "/bar", :controller => "foo", :action => "bar"
46
+ end
@@ -0,0 +1,45 @@
1
+ module NavigationHelpers
2
+ # Maps a name to a path. Used by the
3
+ #
4
+ # When /^I go to (.+)$/ do |page_name|
5
+ #
6
+ # step definition in webrat_steps.rb
7
+ #
8
+ def path_to(page_name)
9
+ case page_name
10
+
11
+ when /the homepage/
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
+
32
+ # Add more mappings here.
33
+ # Here is a more fancy example:
34
+ #
35
+ # when /^(.*)'s profile page$/i
36
+ # user_profile_path(User.find_by_login($1))
37
+
38
+ else
39
+ raise "Can't find mapping from \"#{page_name}\" to a path.\n" +
40
+ "Now, go and add a mapping in #{__FILE__}"
41
+ end
42
+ end
43
+ end
44
+
45
+ World(NavigationHelpers)
@@ -0,0 +1,38 @@
1
+ Feature: ViewTrail
2
+ In order to audit requests made to my app
3
+ I want to record the controller, action, params, and method
4
+
5
+ Background:
6
+ Given I current user is 312
7
+
8
+ Scenario: GET request
9
+ Given I have 0 activities
10
+ When I get the foo page
11
+ Then I should have 1 activities
12
+ And the last activity should have "312" whodunnit
13
+ And the last activity should have "foo" action
14
+ And the last activity should have "foo" controller
15
+ And the last activity should have "{}" params
16
+
17
+ Scenario: POST request
18
+ When I post the foo page
19
+ Then I should have 2 activities
20
+ And the last activity should have "312" whodunnit
21
+ And the last activity should have "foo" action
22
+
23
+ Scenario: PUT request
24
+ Given I put the foo page
25
+ Then I should have 3 activities
26
+ And the last activity should have "312" whodunnit
27
+ And the last activity should have "foo" action
28
+
29
+ Scenario: DELETE request
30
+ Given I delete the foo page
31
+ Then I should have 4 activities
32
+ And the last activity should have "312" whodunnit
33
+ And the last activity should have "foo" action
34
+
35
+ Scenario: GET request on excepted path
36
+ Given I have 0 activities
37
+ When I get the bar page
38
+ Then I should have 0 activities
data/lib/view_trail.rb CHANGED
@@ -25,9 +25,9 @@ module ViewTrail
25
25
  end
26
26
 
27
27
  module ClassMethods
28
- def has_view_trail(&block)
28
+ def has_view_trail(*conditions)
29
29
  before_filter :set_whodunnit
30
- after_filter(:record_activity, &block)
30
+ after_filter(:record_activity, conditions)
31
31
  cattr_accessor :view_trail_active
32
32
  self.view_trail_active = true
33
33
  send :include, InstanceMethods
data/spec/spec_helper.rb CHANGED
@@ -1,9 +1,14 @@
1
1
  require 'spec'
2
2
 
3
- $LOAD_PATH.unshift(File.dirname(__FILE__))
4
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
5
- require 'view_trail'
3
+ # load rails
4
+ ENV['RAILS_ENV'] = 'test'
5
+ ENV['RAILS_ROOT'] ||= File.dirname(__FILE__) + '/../../../..'
6
+ require File.expand_path(File.join(ENV['RAILS_ROOT'], 'config/environment.rb'))
7
+
8
+ # load view_trail
9
+ # $LOAD_PATH.unshift(File.dirname(__FILE__))
10
+ # $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
11
+ # require 'view_trail'
6
12
 
7
13
  Spec::Runner.configure do |config|
8
-
9
- end
14
+ end
data/view_trail.gemspec CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{view_trail}
5
- s.version = "0.2.0"
5
+ s.version = "0.2.1"
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"]
9
- s.date = %q{2009-07-15}
9
+ s.date = %q{2009-07-16}
10
10
  s.description = %q{View trail tracks controller actions in Rails.}
11
11
  s.email = %q{yoon@northwestern.edu}
12
12
  s.extra_rdoc_files = [
@@ -20,6 +20,11 @@ Gem::Specification.new do |s|
20
20
  "README.md",
21
21
  "Rakefile",
22
22
  "VERSION",
23
+ "features/step_definitions/view_trail_steps.rb",
24
+ "features/step_definitions/webrat_steps.rb",
25
+ "features/support/env.rb",
26
+ "features/support/paths.rb",
27
+ "features/view_trail.feature",
23
28
  "generators/view_trail/templates/create_activities.rb",
24
29
  "generators/view_trail/view_trail_generator.rb",
25
30
  "lib/view_trail.rb",
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.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark Yoon
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-07-15 00:00:00 -07:00
12
+ date: 2009-07-16 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -29,6 +29,11 @@ files:
29
29
  - README.md
30
30
  - Rakefile
31
31
  - VERSION
32
+ - features/step_definitions/view_trail_steps.rb
33
+ - features/step_definitions/webrat_steps.rb
34
+ - features/support/env.rb
35
+ - features/support/paths.rb
36
+ - features/view_trail.feature
32
37
  - generators/view_trail/templates/create_activities.rb
33
38
  - generators/view_trail/view_trail_generator.rb
34
39
  - lib/view_trail.rb