session_countdown 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +23 -0
- data/LICENSE +20 -0
- data/README.rdoc +149 -0
- data/Rakefile +40 -0
- data/VERSION +1 -0
- data/lib/session_countdown.rb +80 -0
- data/session_countdown.gemspec +141 -0
- data/test/common/test_controller_test.rb +150 -0
- data/test/rails2x_root/Rakefile +10 -0
- data/test/rails2x_root/app/controllers/application_controller.rb +10 -0
- data/test/rails2x_root/app/controllers/test_controller.rb +2 -0
- data/test/rails2x_root/app/helpers/application_helper.rb +3 -0
- data/test/rails2x_root/app/helpers/test_helper.rb +2 -0
- data/test/rails2x_root/config/boot.rb +110 -0
- data/test/rails2x_root/config/database.yml +22 -0
- data/test/rails2x_root/config/environment.rb +29 -0
- data/test/rails2x_root/config/environments/development.rb +17 -0
- data/test/rails2x_root/config/environments/production.rb +28 -0
- data/test/rails2x_root/config/environments/test.rb +28 -0
- data/test/rails2x_root/config/initializers/backtrace_silencers.rb +7 -0
- data/test/rails2x_root/config/initializers/cookie_verification_secret.rb +7 -0
- data/test/rails2x_root/config/initializers/inflections.rb +10 -0
- data/test/rails2x_root/config/initializers/mime_types.rb +5 -0
- data/test/rails2x_root/config/initializers/new_rails_defaults.rb +21 -0
- data/test/rails2x_root/config/initializers/session_store.rb +15 -0
- data/test/rails2x_root/config/locales/en.yml +5 -0
- data/test/rails2x_root/config/routes.rb +43 -0
- data/test/rails2x_root/script/about +4 -0
- data/test/rails2x_root/script/console +3 -0
- data/test/rails2x_root/script/dbconsole +3 -0
- data/test/rails2x_root/script/destroy +3 -0
- data/test/rails2x_root/script/generate +3 -0
- data/test/rails2x_root/script/performance/benchmarker +3 -0
- data/test/rails2x_root/script/performance/profiler +3 -0
- data/test/rails2x_root/script/plugin +3 -0
- data/test/rails2x_root/script/runner +3 -0
- data/test/rails2x_root/script/server +3 -0
- data/test/rails2x_root/test/functional/test_controller_test.rb +150 -0
- data/test/rails2x_root/test/test_helper.rb +45 -0
- data/test/rails3x_root/Gemfile +34 -0
- data/test/rails3x_root/Gemfile.lock +83 -0
- data/test/rails3x_root/Rakefile +7 -0
- data/test/rails3x_root/app/controllers/application_controller.rb +3 -0
- data/test/rails3x_root/app/controllers/test_controller.rb +2 -0
- data/test/rails3x_root/app/helpers/application_helper.rb +2 -0
- data/test/rails3x_root/app/helpers/test_helper.rb +2 -0
- data/test/rails3x_root/app/views/layouts/application.html.erb +14 -0
- data/test/rails3x_root/config/application.rb +47 -0
- data/test/rails3x_root/config/boot.rb +13 -0
- data/test/rails3x_root/config/environment.rb +5 -0
- data/test/rails3x_root/config/environments/development.rb +22 -0
- data/test/rails3x_root/config/environments/production.rb +49 -0
- data/test/rails3x_root/config/environments/test.rb +35 -0
- data/test/rails3x_root/config/initializers/backtrace_silencers.rb +7 -0
- data/test/rails3x_root/config/initializers/inflections.rb +10 -0
- data/test/rails3x_root/config/initializers/mime_types.rb +5 -0
- data/test/rails3x_root/config/initializers/secret_token.rb +7 -0
- data/test/rails3x_root/config/initializers/session_store.rb +8 -0
- data/test/rails3x_root/config/locales/en.yml +5 -0
- data/test/rails3x_root/config/routes.rb +58 -0
- data/test/rails3x_root/config.ru +4 -0
- data/test/rails3x_root/script/rails +6 -0
- data/test/rails3x_root/test/functional/test_controller_test.rb +150 -0
- data/test/rails3x_root/test/test_helper.rb +8 -0
- metadata +168 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Kevin Swope
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,149 @@
|
|
1
|
+
|
2
|
+
= session_countdown
|
3
|
+
|
4
|
+
|
5
|
+
A Ruby on Rails plugin that puts a countdown timer on the session
|
6
|
+
object.
|
7
|
+
|
8
|
+
session.countdown_run(30.minutes)
|
9
|
+
session.countdown_running? # => true
|
10
|
+
session.countdown_expire
|
11
|
+
session.countdown_running? # => false
|
12
|
+
session.countdown_expired? # => true
|
13
|
+
session.countdown_restart
|
14
|
+
session.countdown_running? # => true
|
15
|
+
|
16
|
+
=== But why?!?
|
17
|
+
|
18
|
+
Sometimes I need to build my own custom rails authentication systems
|
19
|
+
rather than use plugins such as Authlogic, Devise or
|
20
|
+
restful_authentication.
|
21
|
+
|
22
|
+
There is always a "timer" in my custom authentication contraptions,
|
23
|
+
and there is always a session object lurking when I'm dealing with
|
24
|
+
authentication stuff, so why not combine the two?
|
25
|
+
|
26
|
+
== API
|
27
|
+
|
28
|
+
|
29
|
+
<i>Note that except for countdown_run() and countdown_running?() all
|
30
|
+
the public methods will throw a NoCountdown exception if called on a
|
31
|
+
non-existent countdown timer.</i>
|
32
|
+
|
33
|
+
|
34
|
+
Start a countdown timer
|
35
|
+
|
36
|
+
session.countdown_run(seconds, name = :default)
|
37
|
+
|
38
|
+
<i>You can have multiple countdown timers if you name them. The
|
39
|
+
default countdown timer is named "default".</i>
|
40
|
+
|
41
|
+
Check if a countdown timer exists and is currently running
|
42
|
+
|
43
|
+
session.countdown_running?(name = :default)
|
44
|
+
|
45
|
+
Expire early
|
46
|
+
|
47
|
+
session.countdown_expire(name = :default)
|
48
|
+
|
49
|
+
Restart, using the duration supplied to countdown_run
|
50
|
+
|
51
|
+
session.countdown_restart(name = :default)
|
52
|
+
|
53
|
+
Check if expired
|
54
|
+
|
55
|
+
session.countdown_expired?(name = :default)
|
56
|
+
|
57
|
+
<i>countdown_expired? is not the reverse of countdown_running?
|
58
|
+
because only works on an existing countdown, otherwise it will throw a
|
59
|
+
NoCountdown exception. Its use will reveal only if an existing
|
60
|
+
countdown is expired. The statement !countdown_running? can't tell
|
61
|
+
you if the countdown has expired because it will return true if there
|
62
|
+
was no countdown in the first place.</i>
|
63
|
+
|
64
|
+
Remaining time in seconds
|
65
|
+
|
66
|
+
session.countdown_count(name = :default)
|
67
|
+
|
68
|
+
|
69
|
+
= Synopsis
|
70
|
+
|
71
|
+
=== In application_controller.rb
|
72
|
+
|
73
|
+
before_filter :authorize
|
74
|
+
|
75
|
+
|
76
|
+
def authorize
|
77
|
+
if session.countdown_running?
|
78
|
+
session.countdown_restart # give user more time
|
79
|
+
else
|
80
|
+
session[:original_uri] = request.request_uri
|
81
|
+
flash[:notice] = session.countdown_expired? ? "Login Expired" : "Please login"
|
82
|
+
redirect_to :login
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
|
87
|
+
=== In any controller
|
88
|
+
|
89
|
+
def login
|
90
|
+
user = User.find_by_email(params[:email)
|
91
|
+
if user && user.password_matches?(params[:password])
|
92
|
+
session.countdown_run(1.hour)
|
93
|
+
redirect_to :controller => :private
|
94
|
+
else
|
95
|
+
flash.now[:notice] = "Sorry, email/password wrong"
|
96
|
+
render :index
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
100
|
+
|
101
|
+
def logout
|
102
|
+
session.countdown_expire
|
103
|
+
flash[:notice] = "You are now logged out"
|
104
|
+
redirect_to :index
|
105
|
+
end
|
106
|
+
|
107
|
+
|
108
|
+
=== In user model
|
109
|
+
|
110
|
+
def before_save
|
111
|
+
if self.password_changed?
|
112
|
+
self.salt = SecureRandom.hex(10)
|
113
|
+
self.password = Digest::MD5.hexdigest(self.salt + self.password)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
def password_matches?(password_to_match)
|
118
|
+
self.password == Digest::MD5.hexdigest(self.salt + password_to_match)
|
119
|
+
end
|
120
|
+
|
121
|
+
|
122
|
+
=== Note: Remember me
|
123
|
+
|
124
|
+
If you want an "remember me" feature you need to do two things.
|
125
|
+
|
126
|
+
Set timer for far future when user checks "remember me"
|
127
|
+
|
128
|
+
session.countdown_run(1.year)
|
129
|
+
|
130
|
+
Tell rails to serve up a persistent cookie instead of session cookie,
|
131
|
+
probably in application_controller.rb
|
132
|
+
|
133
|
+
ActionController::Base.session_options[:expire_after] = 1.year
|
134
|
+
|
135
|
+
=== Persistent vs session cookies
|
136
|
+
|
137
|
+
There are two types of browser cookies: ones with expiration dates and
|
138
|
+
ones without. When a cookie doesnt have an expiration date it's a
|
139
|
+
<i>session</i> cookie and will be deleted when the browser quits. If
|
140
|
+
the cookie has an expiration date it's a <i>persistent</i> cookie
|
141
|
+
(a.k.a. domain cookie) and will be valid until that date.
|
142
|
+
|
143
|
+
"Remember me" could work fine with only session cookies, provided the
|
144
|
+
user never quits the browser, but users expect "remember me" to never
|
145
|
+
expire their login <i>and</i> to persist across browser quits. It
|
146
|
+
also makes sense to set a far future expiration date or the cookie
|
147
|
+
will eventually expire before the login does.
|
148
|
+
|
149
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
summary = "A Ruby on Rails plugin that puts a countdown timer on the session object"
|
8
|
+
gem.name = "session_countdown"
|
9
|
+
gem.summary = summary
|
10
|
+
gem.description = summary
|
11
|
+
gem.email = "gems-kevdev@snkmail.com"
|
12
|
+
gem.homepage = "http://github.com/kswope/session_countdown"
|
13
|
+
gem.authors = ["Kevin Swope"]
|
14
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
15
|
+
end
|
16
|
+
Jeweler::GemcutterTasks.new
|
17
|
+
rescue LoadError
|
18
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
19
|
+
end
|
20
|
+
|
21
|
+
desc "build README.html from README.doc (for previewing in browser)"
|
22
|
+
task :readme do
|
23
|
+
system "rdoc README.rdoc --one-file > README.html"
|
24
|
+
end
|
25
|
+
|
26
|
+
task :default => :test
|
27
|
+
task :test => [:test_rails2x, :test_rails3x]
|
28
|
+
|
29
|
+
task :test_rails2x do |t|
|
30
|
+
chdir "test/rails2x_root" do
|
31
|
+
system "rake"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
task :test_rails3x do |t|
|
36
|
+
chdir "test/rails3x_root" do
|
37
|
+
system "rake"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'action_controller'
|
3
|
+
|
4
|
+
|
5
|
+
class NoCountdown < Exception; end
|
6
|
+
|
7
|
+
module SessionCountdown
|
8
|
+
|
9
|
+
@@default_name = "default"
|
10
|
+
|
11
|
+
def countdown_run(delta, name = @@default_name)
|
12
|
+
self[get_zero_key(name)] = Time.now + delta
|
13
|
+
self[get_zero_delta_key(name)] = delta # save for reset
|
14
|
+
end
|
15
|
+
|
16
|
+
def countdown_running?(name = @@default_name)
|
17
|
+
self[get_zero_key(name)] && self[get_zero_key(name)] > Time.now
|
18
|
+
end
|
19
|
+
|
20
|
+
# sanity check for existing countdown for some methods
|
21
|
+
def method_missing(method, *args)
|
22
|
+
check_countdown_exists(*args) # reason for this method_missing()
|
23
|
+
method = "_#{method}"
|
24
|
+
respond_to?(method) ? send(method, *args) : raise(NoMethodError)
|
25
|
+
end
|
26
|
+
|
27
|
+
## these methods all require a sanity check for existing countdown
|
28
|
+
|
29
|
+
def _countdown_expire(name = @@default_name)
|
30
|
+
self[get_zero_key(name)] = Time.now
|
31
|
+
end
|
32
|
+
|
33
|
+
def _countdown_expired?(name = @@default_name)
|
34
|
+
! countdown_running?(name)
|
35
|
+
end
|
36
|
+
|
37
|
+
def _countdown_restart(name = @@default_name)
|
38
|
+
self[get_zero_key(name)] = Time.now + self[get_zero_delta_key(name)]
|
39
|
+
end
|
40
|
+
|
41
|
+
def _countdown_count(name = @@default_name)
|
42
|
+
remaining = (self[get_zero_key(name)] - Time.now)
|
43
|
+
(remaining > 0) ? remaining : 0
|
44
|
+
end
|
45
|
+
|
46
|
+
|
47
|
+
private #~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*
|
48
|
+
|
49
|
+
|
50
|
+
def get_zero_key(name)
|
51
|
+
"session_countdown:#{name}"
|
52
|
+
end
|
53
|
+
|
54
|
+
def get_zero_delta_key(name)
|
55
|
+
"session_countdown:#{name}_delta"
|
56
|
+
end
|
57
|
+
|
58
|
+
def check_countdown_exists(name = @@default_name)
|
59
|
+
unless self[get_zero_key(name)]
|
60
|
+
raise NoCountdown, "no session countdown named '#{name}'"
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
|
66
|
+
|
67
|
+
if Rails::VERSION::MAJOR == 2
|
68
|
+
|
69
|
+
class ActionController::Session::AbstractStore::SessionHash
|
70
|
+
include SessionCountdown
|
71
|
+
end
|
72
|
+
|
73
|
+
else
|
74
|
+
|
75
|
+
class ActionDispatch::Session::AbstractStore::SessionHash
|
76
|
+
include SessionCountdown
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
|
@@ -0,0 +1,141 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{session_countdown}
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Kevin Swope"]
|
12
|
+
s.date = %q{2010-08-05}
|
13
|
+
s.description = %q{A Ruby on Rails plugin that puts a countdown timer on the session object}
|
14
|
+
s.email = %q{gems-kevdev@snkmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".gitignore",
|
22
|
+
"LICENSE",
|
23
|
+
"README.rdoc",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"lib/session_countdown.rb",
|
27
|
+
"session_countdown.gemspec",
|
28
|
+
"test/common/test_controller_test.rb",
|
29
|
+
"test/rails2x_root/Rakefile",
|
30
|
+
"test/rails2x_root/app/controllers/application_controller.rb",
|
31
|
+
"test/rails2x_root/app/controllers/test_controller.rb",
|
32
|
+
"test/rails2x_root/app/helpers/application_helper.rb",
|
33
|
+
"test/rails2x_root/app/helpers/test_helper.rb",
|
34
|
+
"test/rails2x_root/config/boot.rb",
|
35
|
+
"test/rails2x_root/config/database.yml",
|
36
|
+
"test/rails2x_root/config/environment.rb",
|
37
|
+
"test/rails2x_root/config/environments/development.rb",
|
38
|
+
"test/rails2x_root/config/environments/production.rb",
|
39
|
+
"test/rails2x_root/config/environments/test.rb",
|
40
|
+
"test/rails2x_root/config/initializers/backtrace_silencers.rb",
|
41
|
+
"test/rails2x_root/config/initializers/cookie_verification_secret.rb",
|
42
|
+
"test/rails2x_root/config/initializers/inflections.rb",
|
43
|
+
"test/rails2x_root/config/initializers/mime_types.rb",
|
44
|
+
"test/rails2x_root/config/initializers/new_rails_defaults.rb",
|
45
|
+
"test/rails2x_root/config/initializers/session_store.rb",
|
46
|
+
"test/rails2x_root/config/locales/en.yml",
|
47
|
+
"test/rails2x_root/config/routes.rb",
|
48
|
+
"test/rails2x_root/script/about",
|
49
|
+
"test/rails2x_root/script/console",
|
50
|
+
"test/rails2x_root/script/dbconsole",
|
51
|
+
"test/rails2x_root/script/destroy",
|
52
|
+
"test/rails2x_root/script/generate",
|
53
|
+
"test/rails2x_root/script/performance/benchmarker",
|
54
|
+
"test/rails2x_root/script/performance/profiler",
|
55
|
+
"test/rails2x_root/script/plugin",
|
56
|
+
"test/rails2x_root/script/runner",
|
57
|
+
"test/rails2x_root/script/server",
|
58
|
+
"test/rails2x_root/test/functional/test_controller_test.rb",
|
59
|
+
"test/rails2x_root/test/test_helper.rb",
|
60
|
+
"test/rails3x_root/Gemfile",
|
61
|
+
"test/rails3x_root/Gemfile.lock",
|
62
|
+
"test/rails3x_root/Rakefile",
|
63
|
+
"test/rails3x_root/app/controllers/application_controller.rb",
|
64
|
+
"test/rails3x_root/app/controllers/test_controller.rb",
|
65
|
+
"test/rails3x_root/app/helpers/application_helper.rb",
|
66
|
+
"test/rails3x_root/app/helpers/test_helper.rb",
|
67
|
+
"test/rails3x_root/app/views/layouts/application.html.erb",
|
68
|
+
"test/rails3x_root/config.ru",
|
69
|
+
"test/rails3x_root/config/application.rb",
|
70
|
+
"test/rails3x_root/config/boot.rb",
|
71
|
+
"test/rails3x_root/config/environment.rb",
|
72
|
+
"test/rails3x_root/config/environments/development.rb",
|
73
|
+
"test/rails3x_root/config/environments/production.rb",
|
74
|
+
"test/rails3x_root/config/environments/test.rb",
|
75
|
+
"test/rails3x_root/config/initializers/backtrace_silencers.rb",
|
76
|
+
"test/rails3x_root/config/initializers/inflections.rb",
|
77
|
+
"test/rails3x_root/config/initializers/mime_types.rb",
|
78
|
+
"test/rails3x_root/config/initializers/secret_token.rb",
|
79
|
+
"test/rails3x_root/config/initializers/session_store.rb",
|
80
|
+
"test/rails3x_root/config/locales/en.yml",
|
81
|
+
"test/rails3x_root/config/routes.rb",
|
82
|
+
"test/rails3x_root/script/rails",
|
83
|
+
"test/rails3x_root/test/functional/test_controller_test.rb",
|
84
|
+
"test/rails3x_root/test/test_helper.rb"
|
85
|
+
]
|
86
|
+
s.homepage = %q{http://github.com/kswope/session_countdown}
|
87
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
88
|
+
s.require_paths = ["lib"]
|
89
|
+
s.rubygems_version = %q{1.3.7}
|
90
|
+
s.summary = %q{A Ruby on Rails plugin that puts a countdown timer on the session object}
|
91
|
+
s.test_files = [
|
92
|
+
"test/common/test_controller_test.rb",
|
93
|
+
"test/rails2x_root/app/controllers/application_controller.rb",
|
94
|
+
"test/rails2x_root/app/controllers/test_controller.rb",
|
95
|
+
"test/rails2x_root/app/helpers/application_helper.rb",
|
96
|
+
"test/rails2x_root/app/helpers/test_helper.rb",
|
97
|
+
"test/rails2x_root/config/boot.rb",
|
98
|
+
"test/rails2x_root/config/environment.rb",
|
99
|
+
"test/rails2x_root/config/environments/development.rb",
|
100
|
+
"test/rails2x_root/config/environments/production.rb",
|
101
|
+
"test/rails2x_root/config/environments/test.rb",
|
102
|
+
"test/rails2x_root/config/initializers/backtrace_silencers.rb",
|
103
|
+
"test/rails2x_root/config/initializers/cookie_verification_secret.rb",
|
104
|
+
"test/rails2x_root/config/initializers/inflections.rb",
|
105
|
+
"test/rails2x_root/config/initializers/mime_types.rb",
|
106
|
+
"test/rails2x_root/config/initializers/new_rails_defaults.rb",
|
107
|
+
"test/rails2x_root/config/initializers/session_store.rb",
|
108
|
+
"test/rails2x_root/config/routes.rb",
|
109
|
+
"test/rails2x_root/test/functional/test_controller_test.rb",
|
110
|
+
"test/rails2x_root/test/test_helper.rb",
|
111
|
+
"test/rails3x_root/app/controllers/application_controller.rb",
|
112
|
+
"test/rails3x_root/app/controllers/test_controller.rb",
|
113
|
+
"test/rails3x_root/app/helpers/application_helper.rb",
|
114
|
+
"test/rails3x_root/app/helpers/test_helper.rb",
|
115
|
+
"test/rails3x_root/config/application.rb",
|
116
|
+
"test/rails3x_root/config/boot.rb",
|
117
|
+
"test/rails3x_root/config/environment.rb",
|
118
|
+
"test/rails3x_root/config/environments/development.rb",
|
119
|
+
"test/rails3x_root/config/environments/production.rb",
|
120
|
+
"test/rails3x_root/config/environments/test.rb",
|
121
|
+
"test/rails3x_root/config/initializers/backtrace_silencers.rb",
|
122
|
+
"test/rails3x_root/config/initializers/inflections.rb",
|
123
|
+
"test/rails3x_root/config/initializers/mime_types.rb",
|
124
|
+
"test/rails3x_root/config/initializers/secret_token.rb",
|
125
|
+
"test/rails3x_root/config/initializers/session_store.rb",
|
126
|
+
"test/rails3x_root/config/routes.rb",
|
127
|
+
"test/rails3x_root/test/functional/test_controller_test.rb",
|
128
|
+
"test/rails3x_root/test/test_helper.rb"
|
129
|
+
]
|
130
|
+
|
131
|
+
if s.respond_to? :specification_version then
|
132
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
133
|
+
s.specification_version = 3
|
134
|
+
|
135
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
136
|
+
else
|
137
|
+
end
|
138
|
+
else
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
@@ -0,0 +1,150 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'timecop'
|
3
|
+
|
4
|
+
class TestControllerTest < ActionController::TestCase
|
5
|
+
|
6
|
+
|
7
|
+
test "single default" do
|
8
|
+
|
9
|
+
assert ! session.countdown_running?
|
10
|
+
|
11
|
+
session.countdown_run(1.minute)
|
12
|
+
assert session.countdown_running?
|
13
|
+
assert ! session.countdown_expired?
|
14
|
+
|
15
|
+
session.countdown_expire
|
16
|
+
|
17
|
+
assert ! session.countdown_running?
|
18
|
+
assert session.countdown_expired?
|
19
|
+
|
20
|
+
session.countdown_restart
|
21
|
+
assert ! session.countdown_expired?
|
22
|
+
assert session.countdown_running?
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
test "mixed names" do
|
28
|
+
|
29
|
+
## start up two counters
|
30
|
+
|
31
|
+
session.countdown_run(1.minute)
|
32
|
+
session.countdown_run(1.minute, :admin)
|
33
|
+
|
34
|
+
## expire default counter
|
35
|
+
|
36
|
+
assert session.countdown_running?
|
37
|
+
session.countdown_expire
|
38
|
+
assert ! session.countdown_running?
|
39
|
+
assert session.countdown_expired?
|
40
|
+
|
41
|
+
## expire admin counter
|
42
|
+
|
43
|
+
assert session.countdown_running?(:admin)
|
44
|
+
session.countdown_expire(:admin)
|
45
|
+
assert ! session.countdown_running?(:admin)
|
46
|
+
assert session.countdown_expired?(:admin)
|
47
|
+
|
48
|
+
## mixing calls to both timers
|
49
|
+
|
50
|
+
session.countdown_run(1.minute)
|
51
|
+
assert session.countdown_running?()
|
52
|
+
assert ! session.countdown_running?(:admin)
|
53
|
+
session.countdown_expire
|
54
|
+
assert session.countdown_expired?(:admin)
|
55
|
+
session.countdown_restart(:admin)
|
56
|
+
assert session.countdown_running?(:admin)
|
57
|
+
assert ! session.countdown_expired?(:admin)
|
58
|
+
assert ! session.countdown_running?()
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
|
63
|
+
test "expiring and resetting" do
|
64
|
+
|
65
|
+
session.countdown_run(1.minute)
|
66
|
+
assert session.countdown_running?
|
67
|
+
assert ! session.countdown_expired?
|
68
|
+
|
69
|
+
Timecop.travel(1.minute)
|
70
|
+
assert ! session.countdown_running?
|
71
|
+
assert session.countdown_expired?
|
72
|
+
|
73
|
+
session.countdown_restart
|
74
|
+
assert session.countdown_running?
|
75
|
+
|
76
|
+
Timecop.return
|
77
|
+
|
78
|
+
end
|
79
|
+
|
80
|
+
|
81
|
+
test "named expiring and resetting" do
|
82
|
+
|
83
|
+
session.countdown_run(1.minute, :admin)
|
84
|
+
assert session.countdown_running?(:admin)
|
85
|
+
assert ! session.countdown_expired?(:admin)
|
86
|
+
|
87
|
+
Timecop.travel(1.minute)
|
88
|
+
assert ! session.countdown_running?(:admin)
|
89
|
+
assert session.countdown_expired?(:admin)
|
90
|
+
|
91
|
+
session.countdown_restart(:admin)
|
92
|
+
assert session.countdown_running?(:admin)
|
93
|
+
|
94
|
+
Timecop.return
|
95
|
+
|
96
|
+
end
|
97
|
+
|
98
|
+
|
99
|
+
test "unstable state" do
|
100
|
+
|
101
|
+
## all public methods except countdown_run and countdown_running?
|
102
|
+
## require an existing countdown
|
103
|
+
|
104
|
+
assert_raise(NoCountdown) { session.countdown_expire }
|
105
|
+
assert_raise(NoCountdown) { session.countdown_restart }
|
106
|
+
assert_raise(NoCountdown) { session.countdown_expired? }
|
107
|
+
assert_raise(NoCountdown) { session.countdown_count }
|
108
|
+
|
109
|
+
## try with named countdown
|
110
|
+
|
111
|
+
assert_raise(NoCountdown) { session.countdown_expire(:admin) }
|
112
|
+
assert_raise(NoCountdown) { session.countdown_restart(:admin) }
|
113
|
+
assert_raise(NoCountdown) { session.countdown_expired?(:admin) }
|
114
|
+
assert_raise(NoCountdown) { session.countdown_count(:admin) }
|
115
|
+
|
116
|
+
end
|
117
|
+
|
118
|
+
|
119
|
+
test "countdown_count" do
|
120
|
+
|
121
|
+
session.countdown_run(1.minute)
|
122
|
+
assert session.countdown_count < 1.minute
|
123
|
+
assert session.countdown_count > (1.minute - 1)
|
124
|
+
Timecop.travel(30.seconds)
|
125
|
+
assert session.countdown_count < 30
|
126
|
+
Timecop.travel(1.minute)
|
127
|
+
assert session.countdown_count == 0
|
128
|
+
|
129
|
+
session.countdown_restart
|
130
|
+
assert session.countdown_count > (1.minute - 1)
|
131
|
+
|
132
|
+
Timecop.return
|
133
|
+
|
134
|
+
end
|
135
|
+
|
136
|
+
|
137
|
+
# copied from README, mostly checking spelling
|
138
|
+
test "rdoc example" do
|
139
|
+
|
140
|
+
session.countdown_run(30.minutes)
|
141
|
+
session.countdown_running? # => true
|
142
|
+
session.countdown_expire
|
143
|
+
session.countdown_running? # => false
|
144
|
+
session.countdown_expired? # => true
|
145
|
+
session.countdown_restart
|
146
|
+
session.countdown_running? # => true
|
147
|
+
|
148
|
+
end
|
149
|
+
|
150
|
+
end
|
@@ -0,0 +1,10 @@
|
|
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.join(File.dirname(__FILE__), 'config', 'boot'))
|
5
|
+
|
6
|
+
require 'rake'
|
7
|
+
require 'rake/testtask'
|
8
|
+
require 'rake/rdoctask'
|
9
|
+
|
10
|
+
require 'tasks/rails'
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# Filters added to this controller apply to all controllers in the application.
|
2
|
+
# Likewise, all the methods added will be available for all controllers.
|
3
|
+
|
4
|
+
class ApplicationController < ActionController::Base
|
5
|
+
helper :all # include all helpers, all the time
|
6
|
+
protect_from_forgery # See ActionController::RequestForgeryProtection for details
|
7
|
+
|
8
|
+
# Scrub sensitive parameters from your log
|
9
|
+
# filter_parameter_logging :password
|
10
|
+
end
|