action_controller_tweaks 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +4 -3
- data/Appraisals +4 -2
- data/CHANGELOG.md +6 -0
- data/README.md +19 -6
- data/action_controller_tweaks.gemspec +1 -1
- data/gemfiles/rails3_2.gemfile +3 -2
- data/gemfiles/rails4_0.gemfile +3 -2
- data/lib/action_controller_tweaks/caching.rb +2 -2
- data/lib/action_controller_tweaks/session.rb +44 -14
- data/lib/action_controller_tweaks/version.rb +5 -1
- data/spec/action_controller_tweaks_spec.rb +269 -90
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d18d5ac685043630bc71743acdbdfa01954ca26d
|
4
|
+
data.tar.gz: decb6e92a43ee69c13b753d1fe7ba350011aea9b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 218dc267dee725e8084a96c09ed05403ea2b6591a9b3ad438349f3584fe5499a635e6d46c204cd5f1731d3e01015bfc95fd639b41c04ce856b7d28acac7e404e
|
7
|
+
data.tar.gz: ffae98b515dd4d3ac1068c87e484e5b32b9cd47e8abbccfb5a780bf28e108879849c37a842ce654592d5ee52416b0fa33a7ec1b8a3140a1fbc6e3fdc87f02c1e
|
data/.travis.yml
CHANGED
data/Appraisals
CHANGED
@@ -1,12 +1,14 @@
|
|
1
1
|
|
2
2
|
appraise "rails3-2" do
|
3
|
-
version = "3.2.
|
3
|
+
version = "3.2.17"
|
4
4
|
gem 'activesupport', version
|
5
5
|
gem 'actionpack', version
|
6
|
+
gem 'activerecord', version
|
6
7
|
end
|
7
8
|
|
8
9
|
appraise "rails4-0" do
|
9
|
-
version = "4.0.
|
10
|
+
version = "4.0.3"
|
10
11
|
gem 'activesupport', version
|
11
12
|
gem 'actionpack', version
|
13
|
+
gem 'activerecord', version
|
12
14
|
end
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,12 @@
|
|
1
1
|
### Changelog
|
2
2
|
|
3
3
|
|
4
|
+
- **0.3.0**
|
5
|
+
- Add method `#set_session_with_expiry`
|
6
|
+
- Add option `expires_in` and `expires_at` to #set_session
|
7
|
+
- Fix invalid header when using `#set_no_cache` for HTTP 1.0
|
8
|
+
- Raise error when reserved session key(s) is set through the provided method
|
9
|
+
|
4
10
|
- **0.2.0**
|
5
11
|
- Add option `expire_at` to #set_session
|
6
12
|
- Use semantic versioning
|
data/README.md
CHANGED
@@ -9,11 +9,11 @@ Tested against:
|
|
9
9
|
- Action Controller of version `3.2` and `4.0` (`3.1` and below got problem with buggy `rspec-rails`)
|
10
10
|
- Ruby `1.9.2`, `1.9.3`, `2.0.0` (except Rails 4 with `1.9.2`)
|
11
11
|
|
12
|
-
[](https://travis-ci.org/PikachuEXE/action_controller_tweaks)
|
13
|
+
[](http://badge.fury.io/rb/action_controller_tweaks)
|
14
|
+
[](https://gemnasium.com/PikachuEXE/action_controller_tweaks)
|
15
|
+
[](https://coveralls.io/r/PikachuEXE/action_controller_tweaks)
|
16
|
+
[](https://codeclimate.com/github/PikachuEXE/action_controller_tweaks)
|
17
17
|
|
18
18
|
Install
|
19
19
|
=======
|
@@ -41,11 +41,24 @@ Usage:
|
|
41
41
|
set_no_cache
|
42
42
|
```
|
43
43
|
|
44
|
-
### `#set_session`
|
44
|
+
### `#set_session` & `#set_session_with_expiry`
|
45
45
|
I write this on my own, it's ok to blame me if it's buggy :P
|
46
46
|
This method let's you set session, with expiry time!
|
47
|
+
It depends on `before_filter`/`before_action` to remove expired session keys
|
48
|
+
Valid options: `expire_in`, `expires_in`, `expire_at`, `expires_at`
|
47
49
|
Example:
|
48
50
|
```ruby
|
51
|
+
# Option keys are NOT checked
|
52
|
+
set_session(:key, 'value') # => Just like session[:key] = 'value'
|
53
|
+
|
49
54
|
set_session(:key, 'value', expire_in: 1.day)
|
55
|
+
set_session(:key, 'value', expires_in: 1.day)
|
56
|
+
|
57
|
+
set_session(:key, 'value', expire_at: 1.day.from_now)
|
58
|
+
set_session(:key, 'value', expires_at: 1.day.from_now)
|
59
|
+
|
60
|
+
# Option keys are checked
|
61
|
+
# You must pass valid options or error will be raised
|
62
|
+
set_session_with_expiry(:key, 'value', expires_in: 1.day)
|
50
63
|
```
|
51
64
|
Note: Please don't use the session key `session_keys_to_expire`, it's reserved for internal processing
|
@@ -9,7 +9,7 @@ require "#{gem_name}/version"
|
|
9
9
|
Gem::Specification.new do |s|
|
10
10
|
s.platform = Gem::Platform::RUBY
|
11
11
|
s.name = gem_name
|
12
|
-
s.version = ActionControllerTweaks
|
12
|
+
s.version = ActionControllerTweaks.version
|
13
13
|
s.summary = "Some Tweaks for ActionController"
|
14
14
|
s.description = "ActionController is great, but could be better. Here are some tweaks for it."
|
15
15
|
|
data/gemfiles/rails3_2.gemfile
CHANGED
data/gemfiles/rails4_0.gemfile
CHANGED
@@ -6,8 +6,8 @@ module ActionControllerTweaks
|
|
6
6
|
|
7
7
|
HEADERS = {
|
8
8
|
"Cache-Control" => "no-cache, no-store, max-age=0, must-revalidate, pre-check=0, post-check=0", # HTTP 1.1
|
9
|
-
"
|
10
|
-
"Expires" => "Fri, 01 Jan 1990 00:00:00 GMT", #
|
9
|
+
"Pragma" => "no-cache", # HTTP 1.0
|
10
|
+
"Expires" => "Fri, 01 Jan 1990 00:00:00 GMT", # HTTP 1.0
|
11
11
|
}.freeze
|
12
12
|
|
13
13
|
included do
|
@@ -5,7 +5,18 @@ module ActionControllerTweaks
|
|
5
5
|
module Session
|
6
6
|
extend ActiveSupport::Concern
|
7
7
|
|
8
|
-
|
8
|
+
module Errors
|
9
|
+
InvalidOptionKeys = Class.new(ArgumentError)
|
10
|
+
ReservedSessionKeyConflict = Class.new(ArgumentError)
|
11
|
+
end
|
12
|
+
|
13
|
+
RESERVED_SESSION_KEYS = %w( session_keys_to_expire )
|
14
|
+
VALID_OPTION_KEYS = [
|
15
|
+
:expires_in,
|
16
|
+
:expires_at,
|
17
|
+
:expire_in,
|
18
|
+
:expire_at,
|
19
|
+
].freeze
|
9
20
|
|
10
21
|
class InvalidOptionValue < ArgumentError
|
11
22
|
def self.new(option_key, options_value, expected_types)
|
@@ -19,13 +30,17 @@ module ActionControllerTweaks
|
|
19
30
|
|
20
31
|
private
|
21
32
|
|
33
|
+
# Set session just like `session[key] = value` but accept some options about expiry
|
34
|
+
#
|
35
|
+
# @option expires_in [Integer] How long from now should the session value be expired
|
36
|
+
# @option expire_in [Integer] same as `expires_in`
|
37
|
+
# @option expires_at [Integer] What time should the session value be expired (using a time in the past would expire at next request)
|
38
|
+
# @option expire_at [Integer] same as `expires_at`
|
22
39
|
def set_session(key, value, options = {})
|
23
40
|
options.symbolize_keys!
|
24
41
|
|
25
|
-
|
26
|
-
|
27
|
-
if SPECIAL_KEYS.include?(key.to_s)
|
28
|
-
return
|
42
|
+
if RESERVED_SESSION_KEYS.include?(key.to_s)
|
43
|
+
raise Errors::ReservedSessionKeyConflict.new, "you are trying to set #{value} to #{key}, but reserved by ActionControllerTweaks::Session"
|
29
44
|
end
|
30
45
|
|
31
46
|
session[key] = value
|
@@ -33,24 +48,39 @@ module ActionControllerTweaks
|
|
33
48
|
# Set special session
|
34
49
|
new_session_keys_to_expire = session_keys_to_expire
|
35
50
|
|
36
|
-
|
51
|
+
expires_in = options.delete(:expires_in) || options.delete(:expire_in)
|
52
|
+
expires_at = options.delete(:expires_at) || options.delete(:expire_at)
|
37
53
|
|
38
|
-
if
|
39
|
-
|
54
|
+
if expires_at && expires_at.respond_to?(:to_time)
|
55
|
+
expires_at = expires_at.to_time
|
40
56
|
end
|
41
57
|
|
42
|
-
raise InvalidOptionValue.new(:
|
43
|
-
raise InvalidOptionValue.new(:
|
58
|
+
raise InvalidOptionValue.new(:expires_in, expires_in, Numeric) if expires_in && !expires_in.is_a?(Numeric)
|
59
|
+
raise InvalidOptionValue.new(:expires_at, expires_at, Time) if expires_at && !expires_at.is_a?(Time)
|
44
60
|
|
45
|
-
new_session_keys_to_expire[key] = if
|
46
|
-
|
47
|
-
elsif
|
48
|
-
|
61
|
+
new_session_keys_to_expire[key] = if expires_in
|
62
|
+
expires_in.from_now
|
63
|
+
elsif expires_at
|
64
|
+
expires_at
|
49
65
|
end
|
50
66
|
|
51
67
|
session[:session_keys_to_expire] = new_session_keys_to_expire
|
52
68
|
end
|
53
69
|
|
70
|
+
# set value in session just like `set_session`, but checked option keys
|
71
|
+
#
|
72
|
+
# @raise [ActionControllerTweaks::Session::Errors::InvalidOptionKeys]
|
73
|
+
def set_session_with_expiry(key, value, options = {})
|
74
|
+
option_keys = options.symbolize_keys.keys
|
75
|
+
required_option_key_present = option_keys.any? do |key|
|
76
|
+
VALID_OPTION_KEYS.include?(key)
|
77
|
+
end
|
78
|
+
invalid_option_key_absent = (option_keys - VALID_OPTION_KEYS.dup).empty?
|
79
|
+
(required_option_key_present && invalid_option_key_absent) or raise ActionControllerTweaks::Session::Errors::InvalidOptionKeys
|
80
|
+
|
81
|
+
set_session(key, value, options = {})
|
82
|
+
end
|
83
|
+
|
54
84
|
def delete_expired_session_keys
|
55
85
|
# Remove keys that are expired
|
56
86
|
session_keys_to_expire.each do |key, expire_at_str|
|
@@ -20,154 +20,294 @@ describe PostsController, type: :controller do
|
|
20
20
|
end
|
21
21
|
|
22
22
|
describe '::Session' do
|
23
|
+
let(:session_key) { :key }
|
24
|
+
let(:session_value) { 'value' }
|
25
|
+
|
23
26
|
describe '#set_session' do
|
24
|
-
let(:session_key) { :key }
|
25
|
-
let(:session_value) { 'value' }
|
26
27
|
let(:expire_in) { 60 * 60 } # 1 hour
|
27
28
|
let(:expire_at) { Time.new(2014, 1, 1).in_time_zone }
|
28
29
|
let(:time_now) { Time.new(2013, 1, 1).in_time_zone }
|
30
|
+
# Corrected option keys
|
31
|
+
let(:expires_in) { expire_in }
|
32
|
+
let(:expires_at) { expire_at }
|
29
33
|
|
30
34
|
context 'when calling it without option' do
|
31
|
-
|
35
|
+
let :set_session do
|
32
36
|
controller.send(:set_session, session_key, session_value)
|
33
37
|
end
|
34
38
|
|
35
|
-
|
36
|
-
|
39
|
+
context 'with normal key' do
|
40
|
+
before do
|
41
|
+
set_session
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'set the session' do
|
45
|
+
session[session_key].should eq session_value
|
46
|
+
end
|
37
47
|
end
|
38
48
|
|
39
|
-
context 'with a
|
40
|
-
let(:session_key) { ActionControllerTweaks::Session::
|
49
|
+
context 'with a reserved key' do
|
50
|
+
let(:session_key) { ActionControllerTweaks::Session::RESERVED_SESSION_KEYS.first }
|
41
51
|
|
42
|
-
it '
|
43
|
-
|
52
|
+
it 'raise error' do
|
53
|
+
expect { set_session }.to raise_error(ActionControllerTweaks::Session::Errors::ReservedSessionKeyConflict)
|
44
54
|
end
|
45
55
|
end
|
46
56
|
end
|
47
57
|
|
48
|
-
context '
|
49
|
-
|
50
|
-
|
58
|
+
context 'for old option keys' do
|
59
|
+
context 'when calling it with option expire_in' do
|
60
|
+
let!(:time_before_expire) { time_now + (expire_in / 2) }
|
61
|
+
let!(:time_after_expire) { time_now + (expire_in * 2) }
|
51
62
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
63
|
+
before do
|
64
|
+
Timecop.freeze(time_now)
|
65
|
+
controller.send(:set_session, session_key, session_value, expire_in: expire_in)
|
66
|
+
end
|
56
67
|
|
57
|
-
|
58
|
-
|
59
|
-
|
68
|
+
after do
|
69
|
+
Timecop.return
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'set the session' do
|
73
|
+
session[session_key].should eq session_value
|
74
|
+
end
|
60
75
|
|
61
|
-
|
62
|
-
|
76
|
+
context 'before expire time' do
|
77
|
+
before do
|
78
|
+
Timecop.travel(time_before_expire)
|
79
|
+
# Runs before_filter
|
80
|
+
get :index
|
81
|
+
end
|
82
|
+
|
83
|
+
it 'keeps the session key' do
|
84
|
+
session[session_key].should eq session_value
|
85
|
+
end
|
86
|
+
end
|
87
|
+
context 'after expire time' do
|
88
|
+
before do
|
89
|
+
Timecop.travel(time_after_expire)
|
90
|
+
# Runs before_filter
|
91
|
+
get :index
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'keeps the session key' do
|
95
|
+
session.key?(session_key).should be_false
|
96
|
+
end
|
97
|
+
end
|
63
98
|
end
|
64
99
|
|
65
|
-
context '
|
100
|
+
context 'when calling it with option expire_at' do
|
101
|
+
let!(:time_before_expire) { expire_at - 1 }
|
102
|
+
let!(:time_after_expire) { expire_at + 1 }
|
103
|
+
|
66
104
|
before do
|
67
|
-
Timecop.
|
68
|
-
|
69
|
-
|
105
|
+
Timecop.freeze(time_now)
|
106
|
+
controller.send(:set_session, session_key, session_value, expire_at: expire_at)
|
107
|
+
end
|
108
|
+
|
109
|
+
after do
|
110
|
+
Timecop.return
|
70
111
|
end
|
71
112
|
|
72
|
-
it '
|
113
|
+
it 'set the session' do
|
73
114
|
session[session_key].should eq session_value
|
74
115
|
end
|
116
|
+
|
117
|
+
context 'before expire time' do
|
118
|
+
before do
|
119
|
+
Timecop.travel(time_before_expire)
|
120
|
+
# Runs before_filter
|
121
|
+
get :index
|
122
|
+
end
|
123
|
+
|
124
|
+
it 'keeps the session key' do
|
125
|
+
session[session_key].should eq session_value
|
126
|
+
end
|
127
|
+
end
|
128
|
+
context 'after expire time' do
|
129
|
+
before do
|
130
|
+
Timecop.travel(time_after_expire)
|
131
|
+
# Runs before_filter
|
132
|
+
get :index
|
133
|
+
end
|
134
|
+
|
135
|
+
it 'keeps the session key' do
|
136
|
+
session.key?(session_key).should be_false
|
137
|
+
end
|
138
|
+
end
|
75
139
|
end
|
76
|
-
|
140
|
+
end
|
141
|
+
context 'for new option keys' do
|
142
|
+
context 'when calling it with option expires_in' do
|
143
|
+
let!(:time_before_expire) { time_now + (expires_in / 2) }
|
144
|
+
let!(:time_after_expire) { time_now + (expires_in * 2) }
|
145
|
+
|
77
146
|
before do
|
78
|
-
Timecop.
|
79
|
-
|
80
|
-
get :index
|
147
|
+
Timecop.freeze(time_now)
|
148
|
+
controller.send(:set_session, session_key, session_value, expires_in: expires_in)
|
81
149
|
end
|
82
150
|
|
83
|
-
|
84
|
-
|
151
|
+
after do
|
152
|
+
Timecop.return
|
85
153
|
end
|
86
|
-
end
|
87
|
-
end
|
88
154
|
|
89
|
-
|
90
|
-
|
91
|
-
|
155
|
+
it 'set the session' do
|
156
|
+
session[session_key].should eq session_value
|
157
|
+
end
|
92
158
|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
159
|
+
context 'before expire time' do
|
160
|
+
before do
|
161
|
+
Timecop.travel(time_before_expire)
|
162
|
+
# Runs before_filter
|
163
|
+
get :index
|
164
|
+
end
|
97
165
|
|
98
|
-
|
99
|
-
|
166
|
+
it 'keeps the session key' do
|
167
|
+
session[session_key].should eq session_value
|
168
|
+
end
|
169
|
+
end
|
170
|
+
context 'after expire time' do
|
171
|
+
before do
|
172
|
+
Timecop.travel(time_after_expire)
|
173
|
+
# Runs before_filter
|
174
|
+
get :index
|
175
|
+
end
|
176
|
+
|
177
|
+
it 'keeps the session key' do
|
178
|
+
session.key?(session_key).should be_false
|
179
|
+
end
|
180
|
+
end
|
100
181
|
end
|
101
182
|
|
102
|
-
|
103
|
-
|
104
|
-
|
183
|
+
context 'when calling it with option expires_at' do
|
184
|
+
let!(:time_before_expire) { expires_at - 1 }
|
185
|
+
let!(:time_after_expire) { expires_at + 1 }
|
105
186
|
|
106
|
-
context 'before expire time' do
|
107
187
|
before do
|
108
|
-
Timecop.
|
109
|
-
|
110
|
-
get :index
|
188
|
+
Timecop.freeze(time_now)
|
189
|
+
controller.send(:set_session, session_key, session_value, expire_at: expires_at)
|
111
190
|
end
|
112
191
|
|
113
|
-
|
114
|
-
|
192
|
+
after do
|
193
|
+
Timecop.return
|
115
194
|
end
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
Timecop.travel(time_after_expire)
|
120
|
-
# Runs before_filter
|
121
|
-
get :index
|
195
|
+
|
196
|
+
it 'set the session' do
|
197
|
+
session[session_key].should eq session_value
|
122
198
|
end
|
123
199
|
|
124
|
-
|
125
|
-
|
200
|
+
context 'before expire time' do
|
201
|
+
before do
|
202
|
+
Timecop.travel(time_before_expire)
|
203
|
+
# Runs before_filter
|
204
|
+
get :index
|
205
|
+
end
|
206
|
+
|
207
|
+
it 'keeps the session key' do
|
208
|
+
session[session_key].should eq session_value
|
209
|
+
end
|
210
|
+
end
|
211
|
+
context 'after expire time' do
|
212
|
+
before do
|
213
|
+
Timecop.travel(time_after_expire)
|
214
|
+
# Runs before_filter
|
215
|
+
get :index
|
216
|
+
end
|
217
|
+
|
218
|
+
it 'keeps the session key' do
|
219
|
+
session.key?(session_key).should be_false
|
220
|
+
end
|
126
221
|
end
|
127
222
|
end
|
128
223
|
end
|
129
224
|
|
225
|
+
|
130
226
|
context 'when option value with different types is passed into options' do
|
131
227
|
let(:method_call) do
|
132
228
|
controller.send(:set_session, session_key, session_value, options)
|
133
229
|
end
|
134
|
-
context 'for expire_in' do
|
135
|
-
let(:options) { {expire_in: expire_in.to_s} }
|
136
230
|
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
context 'with a Hash' do
|
141
|
-
# String#to_time would be nil if format invalid
|
142
|
-
let(:options) { {expire_at: {}} }
|
231
|
+
context 'for old option keys' do
|
232
|
+
context 'for expire_in' do
|
233
|
+
let(:options) { {expire_in: expire_in.to_s} }
|
143
234
|
|
144
235
|
specify { expect{ method_call }.to raise_error(ActionControllerTweaks::Session::InvalidOptionValue) }
|
145
236
|
end
|
146
|
-
context '
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
237
|
+
context 'for expire_at' do
|
238
|
+
context 'with a Hash' do
|
239
|
+
# String#to_time would be nil if format invalid
|
240
|
+
let(:options) { {expire_at: {}} }
|
241
|
+
|
242
|
+
specify { expect{ method_call }.to raise_error(ActionControllerTweaks::Session::InvalidOptionValue) }
|
243
|
+
end
|
244
|
+
context 'with a blank String' do
|
245
|
+
# String#to_time would be nil if format invalid
|
246
|
+
let(:options) { {expire_at: ''} }
|
247
|
+
|
248
|
+
specify { expect{ method_call }.to_not raise_error }
|
249
|
+
end
|
250
|
+
context 'with a time String' do
|
251
|
+
let(:options) { {expire_at: expire_at.to_s} }
|
252
|
+
|
253
|
+
specify { expect{ method_call }.to_not raise_error }
|
254
|
+
end
|
255
|
+
context 'with a Time' do
|
256
|
+
let(:options) { {expire_at: expire_at.to_time} }
|
257
|
+
|
258
|
+
specify { expect{ method_call }.to_not raise_error }
|
259
|
+
end
|
260
|
+
context 'with a Date' do
|
261
|
+
let(:options) { {expire_at: expire_at.to_date} }
|
262
|
+
|
263
|
+
specify { expect{ method_call }.to_not raise_error }
|
264
|
+
end
|
265
|
+
context 'with a DateTime' do
|
266
|
+
let(:options) { {expire_at: expire_at.in_time_zone} }
|
267
|
+
|
268
|
+
specify { expect{ method_call }.to_not raise_error }
|
269
|
+
end
|
161
270
|
end
|
162
|
-
|
163
|
-
|
271
|
+
end
|
272
|
+
context 'for new option keys' do
|
273
|
+
context 'for expires_in' do
|
274
|
+
let(:options) { {expires_in: expires_in.to_s} }
|
164
275
|
|
165
|
-
specify { expect{ method_call }.
|
276
|
+
specify { expect{ method_call }.to raise_error(ActionControllerTweaks::Session::InvalidOptionValue) }
|
166
277
|
end
|
167
|
-
context '
|
168
|
-
|
169
|
-
|
170
|
-
|
278
|
+
context 'for expires_at' do
|
279
|
+
context 'with a Hash' do
|
280
|
+
# String#to_time would be nil if format invalid
|
281
|
+
let(:options) { {expires_at: {}} }
|
282
|
+
|
283
|
+
specify { expect{ method_call }.to raise_error(ActionControllerTweaks::Session::InvalidOptionValue) }
|
284
|
+
end
|
285
|
+
context 'with a blank String' do
|
286
|
+
# String#to_time would be nil if format invalid
|
287
|
+
let(:options) { {expires_at: ''} }
|
288
|
+
|
289
|
+
specify { expect{ method_call }.to_not raise_error }
|
290
|
+
end
|
291
|
+
context 'with a time String' do
|
292
|
+
let(:options) { {expires_at: expire_at.to_s} }
|
293
|
+
|
294
|
+
specify { expect{ method_call }.to_not raise_error }
|
295
|
+
end
|
296
|
+
context 'with a Time' do
|
297
|
+
let(:options) { {expires_at: expire_at.to_time} }
|
298
|
+
|
299
|
+
specify { expect{ method_call }.to_not raise_error }
|
300
|
+
end
|
301
|
+
context 'with a Date' do
|
302
|
+
let(:options) { {expires_at: expire_at.to_date} }
|
303
|
+
|
304
|
+
specify { expect{ method_call }.to_not raise_error }
|
305
|
+
end
|
306
|
+
context 'with a DateTime' do
|
307
|
+
let(:options) { {expires_at: expire_at.in_time_zone} }
|
308
|
+
|
309
|
+
specify { expect{ method_call }.to_not raise_error }
|
310
|
+
end
|
171
311
|
end
|
172
312
|
end
|
173
313
|
end
|
@@ -201,5 +341,44 @@ describe PostsController, type: :controller do
|
|
201
341
|
end
|
202
342
|
end
|
203
343
|
end
|
344
|
+
|
345
|
+
describe '#set_session_with_expiry' do
|
346
|
+
let(:method_call) do
|
347
|
+
controller.send(:set_session_with_expiry, session_key, session_value, options)
|
348
|
+
end
|
349
|
+
|
350
|
+
context 'when call with no options' do
|
351
|
+
let!(:options) { {} }
|
352
|
+
|
353
|
+
specify { expect{method_call}.to raise_error(ActionControllerTweaks::Session::Errors::InvalidOptionKeys) }
|
354
|
+
end
|
355
|
+
context 'when call with invalid option keys' do
|
356
|
+
let!(:options) { {key: :value} }
|
357
|
+
|
358
|
+
specify { expect{method_call}.to raise_error(ActionControllerTweaks::Session::Errors::InvalidOptionKeys) }
|
359
|
+
end
|
360
|
+
context 'when call with valid option keys' do
|
361
|
+
context 'like expire_in' do
|
362
|
+
let!(:options) { {expire_in: 1.day} }
|
363
|
+
|
364
|
+
specify { expect{method_call}.to_not raise_error }
|
365
|
+
end
|
366
|
+
context 'like expire_at' do
|
367
|
+
let!(:options) { {expire_at: 1.day.from_now} }
|
368
|
+
|
369
|
+
specify { expect{method_call}.to_not raise_error }
|
370
|
+
end
|
371
|
+
context 'like expires_in' do
|
372
|
+
let!(:options) { {expires_in: 1.day} }
|
373
|
+
|
374
|
+
specify { expect{method_call}.to_not raise_error }
|
375
|
+
end
|
376
|
+
context 'like expires_at' do
|
377
|
+
let!(:options) { {expires_at: 1.day.from_now} }
|
378
|
+
|
379
|
+
specify { expect{method_call}.to_not raise_error }
|
380
|
+
end
|
381
|
+
end
|
382
|
+
end
|
204
383
|
end
|
205
384
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: action_controller_tweaks
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- PikachuEXE
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-03-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -244,7 +244,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
244
244
|
version: 1.4.0
|
245
245
|
requirements: []
|
246
246
|
rubyforge_project:
|
247
|
-
rubygems_version: 2.2.
|
247
|
+
rubygems_version: 2.2.2
|
248
248
|
signing_key:
|
249
249
|
specification_version: 4
|
250
250
|
summary: Some Tweaks for ActionController
|