session_countdown 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -5,13 +5,18 @@
5
5
  A Ruby on Rails plugin that puts a countdown timer on the session
6
6
  object.
7
7
 
8
- session.countdown_start(30.minutes)
8
+ session.countdown_start(1.hour)
9
+ session.countdown_count #=> 3600
9
10
  session.countdown_running? # => true
10
- session.countdown_expire
11
+ # 60 minutes pass
12
+ session.countdown_count #=> 0
11
13
  session.countdown_running? # => false
12
14
  session.countdown_expired? # => true
13
15
  session.countdown_restart
14
16
  session.countdown_running? # => true
17
+ session.countdown_abort
18
+ session.countdown_running? # => false
19
+ session.countdown_expired? # => false
15
20
 
16
21
  === But why?!?
17
22
 
@@ -26,7 +31,7 @@ authentication stuff, so why not combine the two?
26
31
  == API
27
32
 
28
33
 
29
- <i>Note that countdown_expire(), countdown_restart() and
34
+ <i>Note that countdown_abort(), countdown_restart() and
30
35
  countdown_count() will throw a NoCountdown exception if called on a
31
36
  non-existent countdown timer.</i>
32
37
 
@@ -43,7 +48,7 @@ Check if a countdown timer exists and is currently running
43
48
 
44
49
  Expire early (i.e. logout)
45
50
 
46
- session.countdown_expire(name = :default)
51
+ session.countdown_abort(name = :default)
47
52
 
48
53
  Restart, using the duration supplied to countdown_start
49
54
 
@@ -101,7 +106,7 @@ Understanding timer running, expired, and never started
101
106
  end
102
107
 
103
108
  def logout
104
- session.countdown_expire
109
+ session.countdown_abort
105
110
  flash[:notice] = "You are now logged out"
106
111
  redirect_to :index
107
112
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.0
1
+ 0.5.0
data/created.rid CHANGED
@@ -1 +1 @@
1
- Fri, 06 Aug 2010 09:30:21 -0400
1
+ Fri, 06 Aug 2010 10:45:22 -0400
@@ -39,8 +39,8 @@ module SessionCountdown
39
39
 
40
40
  ## these methods all require a sanity check for existing countdown
41
41
 
42
- def _countdown_expire(name = @@default_name)
43
- self[get_zero_key(name)] = Time.now
42
+ def _countdown_abort(name = @@default_name)
43
+ self[get_zero_key(name)] = nil
44
44
  end
45
45
 
46
46
  def _countdown_restart(name = @@default_name)
@@ -65,7 +65,9 @@ module SessionCountdown
65
65
  end
66
66
 
67
67
  def insist_countdown_exists(name = @@default_name)
68
- unless self[get_zero_key(name)]
68
+ # We use delta_key here because timer might have been nil'd by
69
+ # aborting, but it still should be restartable.
70
+ unless self[get_zero_delta_key(name)]
69
71
  raise NoCountdown, "no session countdown named '#{name}'"
70
72
  end
71
73
  end
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{session_countdown}
8
- s.version = "0.4.0"
8
+ s.version = "0.5.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Kevin Swope"]
@@ -21,10 +21,10 @@ class TestControllerTest < ActionController::TestCase
21
21
  assert session.countdown_running?
22
22
  assert ! session.countdown_expired?
23
23
 
24
- session.countdown_expire
24
+ session.countdown_abort
25
25
 
26
26
  assert ! session.countdown_running?
27
- assert session.countdown_expired?
27
+ assert ! session.countdown_expired?
28
28
 
29
29
  session.countdown_restart
30
30
  assert ! session.countdown_expired?
@@ -45,9 +45,9 @@ class TestControllerTest < ActionController::TestCase
45
45
  assert ! session.countdown_expired?
46
46
 
47
47
  # with countdown expired
48
- session.countdown_expire
48
+ session.countdown_abort
49
49
  assert ! session.countdown_running?
50
- assert session.countdown_expired?
50
+ assert ! session.countdown_expired?
51
51
 
52
52
  end
53
53
 
@@ -59,27 +59,27 @@ class TestControllerTest < ActionController::TestCase
59
59
  session.countdown_start(1.minute)
60
60
  session.countdown_start(1.minute, :admin)
61
61
 
62
- ## expire default counter
62
+ ## abort default counter
63
63
 
64
64
  assert session.countdown_running?
65
- session.countdown_expire
65
+ session.countdown_abort
66
66
  assert ! session.countdown_running?
67
- assert session.countdown_expired?
67
+ assert ! session.countdown_expired?
68
68
 
69
- ## expire admin counter
69
+ ## abort admin counter
70
70
 
71
71
  assert session.countdown_running?(:admin)
72
- session.countdown_expire(:admin)
72
+ session.countdown_abort(:admin)
73
73
  assert ! session.countdown_running?(:admin)
74
- assert session.countdown_expired?(:admin)
74
+ assert ! session.countdown_expired?(:admin)
75
75
 
76
76
  ## mixing calls to both timers
77
77
 
78
78
  session.countdown_start(1.minute)
79
79
  assert session.countdown_running?()
80
80
  assert ! session.countdown_running?(:admin)
81
- session.countdown_expire
82
- assert session.countdown_expired?(:admin)
81
+ session.countdown_abort
82
+ assert ! session.countdown_expired?(:admin)
83
83
  session.countdown_restart(:admin)
84
84
  assert session.countdown_running?(:admin)
85
85
  assert ! session.countdown_expired?(:admin)
@@ -129,13 +129,13 @@ class TestControllerTest < ActionController::TestCase
129
129
  # restart, expire and count require an existing countdown, should
130
130
  # throw exception if there isn't one
131
131
 
132
- assert_raise(NoCountdown) { session.countdown_expire }
132
+ assert_raise(NoCountdown) { session.countdown_abort }
133
133
  assert_raise(NoCountdown) { session.countdown_restart }
134
134
  assert_raise(NoCountdown) { session.countdown_count }
135
135
 
136
136
  ## try with named countdown
137
137
 
138
- assert_raise(NoCountdown) { session.countdown_expire(:admin) }
138
+ assert_raise(NoCountdown) { session.countdown_abort(:admin) }
139
139
  assert_raise(NoCountdown) { session.countdown_restart(:admin) }
140
140
  assert_raise(NoCountdown) { session.countdown_count(:admin) }
141
141
 
@@ -163,13 +163,18 @@ class TestControllerTest < ActionController::TestCase
163
163
  # copied from README, mostly checking spelling
164
164
  test "rdoc example" do
165
165
 
166
- session.countdown_start(30.minutes)
167
- session.countdown_running? # => true
168
- session.countdown_expire
169
- session.countdown_running? # => false
170
- session.countdown_expired? # => true
166
+ session.countdown_start(1.hour)
167
+ assert (3599 < session.countdown_count)
168
+ assert session.countdown_running?
169
+ Timecop.travel(60.minute)
170
+ assert_equal 0, session.countdown_count
171
+ assert ! session.countdown_running?
172
+ assert session.countdown_expired?
171
173
  session.countdown_restart
172
- session.countdown_running? # => true
174
+ assert session.countdown_running?
175
+ session.countdown_abort
176
+ assert ! session.countdown_running?
177
+ assert ! session.countdown_expired?
173
178
 
174
179
  end
175
180
 
@@ -21,10 +21,10 @@ class TestControllerTest < ActionController::TestCase
21
21
  assert session.countdown_running?
22
22
  assert ! session.countdown_expired?
23
23
 
24
- session.countdown_expire
24
+ session.countdown_abort
25
25
 
26
26
  assert ! session.countdown_running?
27
- assert session.countdown_expired?
27
+ assert ! session.countdown_expired?
28
28
 
29
29
  session.countdown_restart
30
30
  assert ! session.countdown_expired?
@@ -45,9 +45,9 @@ class TestControllerTest < ActionController::TestCase
45
45
  assert ! session.countdown_expired?
46
46
 
47
47
  # with countdown expired
48
- session.countdown_expire
48
+ session.countdown_abort
49
49
  assert ! session.countdown_running?
50
- assert session.countdown_expired?
50
+ assert ! session.countdown_expired?
51
51
 
52
52
  end
53
53
 
@@ -59,27 +59,27 @@ class TestControllerTest < ActionController::TestCase
59
59
  session.countdown_start(1.minute)
60
60
  session.countdown_start(1.minute, :admin)
61
61
 
62
- ## expire default counter
62
+ ## abort default counter
63
63
 
64
64
  assert session.countdown_running?
65
- session.countdown_expire
65
+ session.countdown_abort
66
66
  assert ! session.countdown_running?
67
- assert session.countdown_expired?
67
+ assert ! session.countdown_expired?
68
68
 
69
- ## expire admin counter
69
+ ## abort admin counter
70
70
 
71
71
  assert session.countdown_running?(:admin)
72
- session.countdown_expire(:admin)
72
+ session.countdown_abort(:admin)
73
73
  assert ! session.countdown_running?(:admin)
74
- assert session.countdown_expired?(:admin)
74
+ assert ! session.countdown_expired?(:admin)
75
75
 
76
76
  ## mixing calls to both timers
77
77
 
78
78
  session.countdown_start(1.minute)
79
79
  assert session.countdown_running?()
80
80
  assert ! session.countdown_running?(:admin)
81
- session.countdown_expire
82
- assert session.countdown_expired?(:admin)
81
+ session.countdown_abort
82
+ assert ! session.countdown_expired?(:admin)
83
83
  session.countdown_restart(:admin)
84
84
  assert session.countdown_running?(:admin)
85
85
  assert ! session.countdown_expired?(:admin)
@@ -129,13 +129,13 @@ class TestControllerTest < ActionController::TestCase
129
129
  # restart, expire and count require an existing countdown, should
130
130
  # throw exception if there isn't one
131
131
 
132
- assert_raise(NoCountdown) { session.countdown_expire }
132
+ assert_raise(NoCountdown) { session.countdown_abort }
133
133
  assert_raise(NoCountdown) { session.countdown_restart }
134
134
  assert_raise(NoCountdown) { session.countdown_count }
135
135
 
136
136
  ## try with named countdown
137
137
 
138
- assert_raise(NoCountdown) { session.countdown_expire(:admin) }
138
+ assert_raise(NoCountdown) { session.countdown_abort(:admin) }
139
139
  assert_raise(NoCountdown) { session.countdown_restart(:admin) }
140
140
  assert_raise(NoCountdown) { session.countdown_count(:admin) }
141
141
 
@@ -163,13 +163,18 @@ class TestControllerTest < ActionController::TestCase
163
163
  # copied from README, mostly checking spelling
164
164
  test "rdoc example" do
165
165
 
166
- session.countdown_start(30.minutes)
167
- session.countdown_running? # => true
168
- session.countdown_expire
169
- session.countdown_running? # => false
170
- session.countdown_expired? # => true
166
+ session.countdown_start(1.hour)
167
+ assert (3599 < session.countdown_count)
168
+ assert session.countdown_running?
169
+ Timecop.travel(60.minute)
170
+ assert_equal 0, session.countdown_count
171
+ assert ! session.countdown_running?
172
+ assert session.countdown_expired?
171
173
  session.countdown_restart
172
- session.countdown_running? # => true
174
+ assert session.countdown_running?
175
+ session.countdown_abort
176
+ assert ! session.countdown_running?
177
+ assert ! session.countdown_expired?
173
178
 
174
179
  end
175
180
 
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: /Users/kevin/Development/session_countdown
3
3
  specs:
4
- session_countdown (0.3.0)
4
+ session_countdown (0.4.0)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
@@ -21,10 +21,10 @@ class TestControllerTest < ActionController::TestCase
21
21
  assert session.countdown_running?
22
22
  assert ! session.countdown_expired?
23
23
 
24
- session.countdown_expire
24
+ session.countdown_abort
25
25
 
26
26
  assert ! session.countdown_running?
27
- assert session.countdown_expired?
27
+ assert ! session.countdown_expired?
28
28
 
29
29
  session.countdown_restart
30
30
  assert ! session.countdown_expired?
@@ -45,9 +45,9 @@ class TestControllerTest < ActionController::TestCase
45
45
  assert ! session.countdown_expired?
46
46
 
47
47
  # with countdown expired
48
- session.countdown_expire
48
+ session.countdown_abort
49
49
  assert ! session.countdown_running?
50
- assert session.countdown_expired?
50
+ assert ! session.countdown_expired?
51
51
 
52
52
  end
53
53
 
@@ -59,27 +59,27 @@ class TestControllerTest < ActionController::TestCase
59
59
  session.countdown_start(1.minute)
60
60
  session.countdown_start(1.minute, :admin)
61
61
 
62
- ## expire default counter
62
+ ## abort default counter
63
63
 
64
64
  assert session.countdown_running?
65
- session.countdown_expire
65
+ session.countdown_abort
66
66
  assert ! session.countdown_running?
67
- assert session.countdown_expired?
67
+ assert ! session.countdown_expired?
68
68
 
69
- ## expire admin counter
69
+ ## abort admin counter
70
70
 
71
71
  assert session.countdown_running?(:admin)
72
- session.countdown_expire(:admin)
72
+ session.countdown_abort(:admin)
73
73
  assert ! session.countdown_running?(:admin)
74
- assert session.countdown_expired?(:admin)
74
+ assert ! session.countdown_expired?(:admin)
75
75
 
76
76
  ## mixing calls to both timers
77
77
 
78
78
  session.countdown_start(1.minute)
79
79
  assert session.countdown_running?()
80
80
  assert ! session.countdown_running?(:admin)
81
- session.countdown_expire
82
- assert session.countdown_expired?(:admin)
81
+ session.countdown_abort
82
+ assert ! session.countdown_expired?(:admin)
83
83
  session.countdown_restart(:admin)
84
84
  assert session.countdown_running?(:admin)
85
85
  assert ! session.countdown_expired?(:admin)
@@ -129,13 +129,13 @@ class TestControllerTest < ActionController::TestCase
129
129
  # restart, expire and count require an existing countdown, should
130
130
  # throw exception if there isn't one
131
131
 
132
- assert_raise(NoCountdown) { session.countdown_expire }
132
+ assert_raise(NoCountdown) { session.countdown_abort }
133
133
  assert_raise(NoCountdown) { session.countdown_restart }
134
134
  assert_raise(NoCountdown) { session.countdown_count }
135
135
 
136
136
  ## try with named countdown
137
137
 
138
- assert_raise(NoCountdown) { session.countdown_expire(:admin) }
138
+ assert_raise(NoCountdown) { session.countdown_abort(:admin) }
139
139
  assert_raise(NoCountdown) { session.countdown_restart(:admin) }
140
140
  assert_raise(NoCountdown) { session.countdown_count(:admin) }
141
141
 
@@ -163,13 +163,18 @@ class TestControllerTest < ActionController::TestCase
163
163
  # copied from README, mostly checking spelling
164
164
  test "rdoc example" do
165
165
 
166
- session.countdown_start(30.minutes)
167
- session.countdown_running? # => true
168
- session.countdown_expire
169
- session.countdown_running? # => false
170
- session.countdown_expired? # => true
166
+ session.countdown_start(1.hour)
167
+ assert (3599 < session.countdown_count)
168
+ assert session.countdown_running?
169
+ Timecop.travel(60.minute)
170
+ assert_equal 0, session.countdown_count
171
+ assert ! session.countdown_running?
172
+ assert session.countdown_expired?
171
173
  session.countdown_restart
172
- session.countdown_running? # => true
174
+ assert session.countdown_running?
175
+ session.countdown_abort
176
+ assert ! session.countdown_running?
177
+ assert ! session.countdown_expired?
173
178
 
174
179
  end
175
180
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: session_countdown
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
4
+ hash: 11
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 4
8
+ - 5
9
9
  - 0
10
- version: 0.4.0
10
+ version: 0.5.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Kevin Swope