rails-session_cookie 0.2.1 → 0.2.2
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/.rubocop.yml +1 -0
- data/.travis.yml +0 -3
- data/README.md +67 -18
- data/Rakefile +27 -1
- data/gemfiles/rails_4.2.gemfile.lock +3 -1
- data/gemfiles/rails_4.2_warden.gemfile.lock +3 -1
- data/gemfiles/rails_5.0.gemfile.lock +3 -1
- data/gemfiles/rails_5.0_warden.gemfile.lock +3 -1
- data/gemfiles/rails_5.1.gemfile.lock +3 -1
- data/gemfiles/rails_5.1_warden.gemfile.lock +3 -1
- data/lib/rails-session_cookie.rb +1 -0
- data/lib/rails/session_cookie/version.rb +1 -1
- data/rails-session_cookie.gemspec +1 -0
- metadata +16 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cf883bbe0ecd2fa1007bd3dcaf93dea8fd30df30
|
4
|
+
data.tar.gz: 432aa9b0e2b4d44f9f114447faf6d244b7353db0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a74cf4563775b1751910d431a5fcbc4eee47f6d3ce6d405c986691317d6cc98701f00614a3b4f56589ca44bf6b080990bda869df4213824080c05dc7554168d1
|
7
|
+
data.tar.gz: b5d743ce4a4559657223dfed66c44eaa50f599750921b50102597fd2ab2445497cf8dc95466e31a4e7c58ba778dfe02ac3c0d96a67bd3ba5c2d179662e1f3383
|
data/.rubocop.yml
CHANGED
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -14,7 +14,7 @@ Probably, you might have seen a lot code like this:
|
|
14
14
|
# config/initializers/session_store.rb
|
15
15
|
Rails.application.config.session_store :cookie_store
|
16
16
|
|
17
|
-
#
|
17
|
+
# authenticating method (maybe Devise or whatever)
|
18
18
|
session[:current_user_id] = current_user.id
|
19
19
|
|
20
20
|
# somewhere in helper for request specs
|
@@ -23,7 +23,7 @@ def login(current_user)
|
|
23
23
|
end
|
24
24
|
|
25
25
|
# now every request spec is calling login request
|
26
|
-
RSpec.describe 'User
|
26
|
+
RSpec.describe 'User interface', type: :request do
|
27
27
|
let(:user) { create :user }
|
28
28
|
|
29
29
|
before do
|
@@ -37,13 +37,18 @@ end
|
|
37
37
|
```
|
38
38
|
|
39
39
|
In a usual user-driven application this tightly couples *all* request specs, which require authentication, to the login process.
|
40
|
-
If it fails - everything fails. If it's not
|
40
|
+
If it fails - everything fails. If it's not blazing fast - it slows the whole suite down.
|
41
41
|
|
42
|
-
One may move to token-based
|
43
|
-
But we
|
42
|
+
One may move to token-based authentication, especially when having API. That's reasonable and nice.
|
43
|
+
But HTTP is stateless, really we don't need to do several requests, we can think about a session cookie
|
44
|
+
as a token passed in a special header!
|
44
45
|
|
45
|
-
|
46
|
-
Rails is
|
46
|
+
You can easily pass headers in tests, the only hard thing is getting the cookie value.
|
47
|
+
Rails may change how a state is serialized into the session cookie. It can be encrypted or not, marshalled
|
48
|
+
(an old story for rails-3 legacy) or JSONed. Long story short: only rails knows how to generate cookie from data.
|
49
|
+
|
50
|
+
This gem replaces your usual process of getting session cookie with the simplest rack app utilizing
|
51
|
+
2 rails middlewares. Rails is modular, that's cool :)
|
47
52
|
|
48
53
|
## Installation
|
49
54
|
|
@@ -85,13 +90,12 @@ However, never saw this in practice, and consider caching of requests in before-
|
|
85
90
|
If you need more sophisticated logic:
|
86
91
|
|
87
92
|
```ruby
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
end
|
93
|
+
auth_app = proc { |env|
|
94
|
+
# do your magic
|
95
|
+
env[Rails::SessionCookie::RACK_SESSION].merge!(context)
|
96
|
+
[200, {}, []]
|
97
|
+
}
|
98
|
+
raw_session_cookie = Rails::SessionCookie::App.new(auth_app).session_cookie
|
95
99
|
```
|
96
100
|
|
97
101
|
Of course, you can just make use (and reuse!) of as many procs as you wish.
|
@@ -119,7 +123,7 @@ Capybara.current_session.driver.browser.set_cookie raw_session_cookie
|
|
119
123
|
|
120
124
|
## Benchmarks
|
121
125
|
|
122
|
-
*NOTE:* Sometimes devise's `
|
126
|
+
*NOTE:* Sometimes devise's `sign_in` is still faster than `SessionCookie` (a little though),
|
123
127
|
because Warden uses an [ugly hack, in my opinion,](https://github.com/hassox/warden/blob/master/lib/warden/test/helpers.rb#L18L23)
|
124
128
|
to support test-mode authentication.
|
125
129
|
|
@@ -128,7 +132,7 @@ Besides, authentication becomes as transparent as possible and should increase r
|
|
128
132
|
if you understand HTTP session cookies principles.
|
129
133
|
|
130
134
|
```sh
|
131
|
-
$ appraisal rails-5.1-warden rspec -t performance spec/benchmarks
|
135
|
+
$ appraisal rails-5.1-warden rspec -t performance spec/benchmarks/feature_spec.rb
|
132
136
|
|
133
137
|
Speed using capybara in feature test
|
134
138
|
correctness of
|
@@ -140,6 +144,34 @@ Speed using capybara in feature test
|
|
140
144
|
is obviously slower separately
|
141
145
|
is not slower than devise helpers if using cache and executing multiple specs in a suite
|
142
146
|
|
147
|
+
Warming up --------------------------------------
|
148
|
+
devise sign_in
|
149
|
+
70.000 i/100ms
|
150
|
+
session cookie
|
151
|
+
70.000 i/100ms
|
152
|
+
session cookie (no cache)
|
153
|
+
62.000 i/100ms
|
154
|
+
Calculating -------------------------------------
|
155
|
+
devise sign_in
|
156
|
+
700.554 (± 5.3%) i/s - 3.500k in 5.011356s
|
157
|
+
session cookie
|
158
|
+
686.868 (± 4.7%) i/s - 3.430k in 5.005542s
|
159
|
+
session cookie (no cache)
|
160
|
+
611.439 (± 4.9%) i/s - 3.100k in 5.083986s
|
161
|
+
|
162
|
+
Comparison:
|
163
|
+
devise sign_in : 700.6 i/s
|
164
|
+
session cookie : 686.9 i/s - same-ish: difference falls within error
|
165
|
+
session cookie (no cache): 611.4 i/s - 1.15x slower
|
166
|
+
|
167
|
+
```
|
168
|
+
|
169
|
+
But when it comes with comparison to a simple custom authentication (see `spec/support/rails_app.rb`),
|
170
|
+
this gem is several times faster! (custom action checks password, hits database, request touches the whole rails middleware stack)
|
171
|
+
|
172
|
+
```sh
|
173
|
+
$ appraisal rails-5.1-warden rspec -t performance spec/benchmarks/request_spec.rb
|
174
|
+
|
143
175
|
Speed using custom sign-in in request test
|
144
176
|
correctness of
|
145
177
|
SessionCookie
|
@@ -149,8 +181,25 @@ Speed using custom sign-in in request test
|
|
149
181
|
against custom sign in route
|
150
182
|
is faster separately without cache
|
151
183
|
|
152
|
-
|
153
|
-
|
184
|
+
Warming up --------------------------------------
|
185
|
+
custom sign in
|
186
|
+
1.000 i/100ms
|
187
|
+
session cookie
|
188
|
+
1.759k i/100ms
|
189
|
+
session cookie (no cache)
|
190
|
+
482.000 i/100ms
|
191
|
+
Calculating -------------------------------------
|
192
|
+
custom sign in
|
193
|
+
11.219 (± 0.0%) i/s - 57.000 in 5.082143s
|
194
|
+
session cookie
|
195
|
+
17.573k (± 2.0%) i/s - 87.950k in 5.006754s
|
196
|
+
session cookie (no cache)
|
197
|
+
4.714k (± 5.0%) i/s - 23.618k in 5.023448s
|
198
|
+
|
199
|
+
Comparison:
|
200
|
+
session cookie : 17573.4 i/s
|
201
|
+
session cookie (no cache): 4714.3 i/s - 3.73x slower
|
202
|
+
custom sign in : 11.2 i/s - 1566.44x slower
|
154
203
|
```
|
155
204
|
|
156
205
|
## Contributing
|
data/Rakefile
CHANGED
@@ -1,8 +1,34 @@
|
|
1
1
|
require 'bundler/gem_tasks'
|
2
2
|
require 'rspec/core/rake_task'
|
3
3
|
require 'rubocop/rake_task'
|
4
|
+
require 'codeclimate-test-reporter'
|
4
5
|
|
5
6
|
RSpec::Core::RakeTask.new(:spec)
|
6
7
|
RuboCop::RakeTask.new(:rubocop)
|
7
8
|
|
8
|
-
|
9
|
+
# Same as bin/codeclimate-test-reporter, but don't complain if no coverage found
|
10
|
+
task :coverage do
|
11
|
+
exit unless ENV['CI']
|
12
|
+
|
13
|
+
repo_token = ENV['CODECLIMATE_REPO_TOKEN']
|
14
|
+
if repo_token.nil? || repo_token.empty?
|
15
|
+
STDERR.puts 'Cannot post results: environment variable CODECLIMATE_REPO_TOKEN must be set.'
|
16
|
+
exit
|
17
|
+
end
|
18
|
+
|
19
|
+
COVERAGE_FILE = ARGV.first || 'coverage/.resultset.json'
|
20
|
+
unless File.exist?(COVERAGE_FILE)
|
21
|
+
STDERR.puts 'Coverage results not found'
|
22
|
+
exit
|
23
|
+
end
|
24
|
+
|
25
|
+
begin
|
26
|
+
results = JSON.parse(File.read(COVERAGE_FILE))
|
27
|
+
rescue JSON::ParserError => e
|
28
|
+
abort "Error encountered while parsing #{COVERAGE_FILE}: #{e}"
|
29
|
+
end
|
30
|
+
|
31
|
+
CodeClimate::TestReporter.run(results)
|
32
|
+
end
|
33
|
+
|
34
|
+
task default: %i[rubocop spec coverage]
|
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: ..
|
3
3
|
specs:
|
4
|
-
rails-session_cookie (0.2.
|
4
|
+
rails-session_cookie (0.2.2)
|
5
5
|
rails (>= 4.0)
|
6
6
|
|
7
7
|
GEM
|
@@ -49,6 +49,7 @@ GEM
|
|
49
49
|
thor (>= 0.14.0)
|
50
50
|
arel (6.0.4)
|
51
51
|
ast (2.3.0)
|
52
|
+
benchmark-ips (2.7.2)
|
52
53
|
benchmark-perf (0.2.1)
|
53
54
|
builder (3.2.3)
|
54
55
|
byebug (9.0.6)
|
@@ -184,6 +185,7 @@ PLATFORMS
|
|
184
185
|
|
185
186
|
DEPENDENCIES
|
186
187
|
appraisal (~> 2.2)
|
188
|
+
benchmark-ips (~> 2.7.2)
|
187
189
|
bundler (~> 1.15)
|
188
190
|
capybara (~> 2.15)
|
189
191
|
codeclimate-test-reporter (= 1.0.8)
|
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: ..
|
3
3
|
specs:
|
4
|
-
rails-session_cookie (0.2.
|
4
|
+
rails-session_cookie (0.2.2)
|
5
5
|
rails (>= 4.0)
|
6
6
|
|
7
7
|
GEM
|
@@ -50,6 +50,7 @@ GEM
|
|
50
50
|
arel (6.0.4)
|
51
51
|
ast (2.3.0)
|
52
52
|
bcrypt (3.1.11)
|
53
|
+
benchmark-ips (2.7.2)
|
53
54
|
benchmark-perf (0.2.1)
|
54
55
|
builder (3.2.3)
|
55
56
|
byebug (9.1.0)
|
@@ -197,6 +198,7 @@ PLATFORMS
|
|
197
198
|
|
198
199
|
DEPENDENCIES
|
199
200
|
appraisal (~> 2.2)
|
201
|
+
benchmark-ips (~> 2.7.2)
|
200
202
|
bundler (~> 1.15)
|
201
203
|
capybara (~> 2.15)
|
202
204
|
codeclimate-test-reporter (= 1.0.8)
|
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: ..
|
3
3
|
specs:
|
4
|
-
rails-session_cookie (0.2.
|
4
|
+
rails-session_cookie (0.2.2)
|
5
5
|
rails (>= 4.0)
|
6
6
|
|
7
7
|
GEM
|
@@ -52,6 +52,7 @@ GEM
|
|
52
52
|
thor (>= 0.14.0)
|
53
53
|
arel (7.1.4)
|
54
54
|
ast (2.3.0)
|
55
|
+
benchmark-ips (2.7.2)
|
55
56
|
benchmark-perf (0.2.1)
|
56
57
|
builder (3.2.3)
|
57
58
|
byebug (9.0.6)
|
@@ -190,6 +191,7 @@ PLATFORMS
|
|
190
191
|
|
191
192
|
DEPENDENCIES
|
192
193
|
appraisal (~> 2.2)
|
194
|
+
benchmark-ips (~> 2.7.2)
|
193
195
|
bundler (~> 1.15)
|
194
196
|
capybara (~> 2.15)
|
195
197
|
codeclimate-test-reporter (= 1.0.8)
|
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: ..
|
3
3
|
specs:
|
4
|
-
rails-session_cookie (0.2.
|
4
|
+
rails-session_cookie (0.2.2)
|
5
5
|
rails (>= 4.0)
|
6
6
|
|
7
7
|
GEM
|
@@ -53,6 +53,7 @@ GEM
|
|
53
53
|
arel (7.1.4)
|
54
54
|
ast (2.3.0)
|
55
55
|
bcrypt (3.1.11)
|
56
|
+
benchmark-ips (2.7.2)
|
56
57
|
benchmark-perf (0.2.1)
|
57
58
|
builder (3.2.3)
|
58
59
|
byebug (9.1.0)
|
@@ -203,6 +204,7 @@ PLATFORMS
|
|
203
204
|
|
204
205
|
DEPENDENCIES
|
205
206
|
appraisal (~> 2.2)
|
207
|
+
benchmark-ips (~> 2.7.2)
|
206
208
|
bundler (~> 1.15)
|
207
209
|
capybara (~> 2.15)
|
208
210
|
codeclimate-test-reporter (= 1.0.8)
|
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: ..
|
3
3
|
specs:
|
4
|
-
rails-session_cookie (0.2.
|
4
|
+
rails-session_cookie (0.2.2)
|
5
5
|
rails (>= 4.0)
|
6
6
|
|
7
7
|
GEM
|
@@ -52,6 +52,7 @@ GEM
|
|
52
52
|
thor (>= 0.14.0)
|
53
53
|
arel (8.0.0)
|
54
54
|
ast (2.3.0)
|
55
|
+
benchmark-ips (2.7.2)
|
55
56
|
benchmark-perf (0.2.1)
|
56
57
|
builder (3.2.3)
|
57
58
|
byebug (9.0.6)
|
@@ -190,6 +191,7 @@ PLATFORMS
|
|
190
191
|
|
191
192
|
DEPENDENCIES
|
192
193
|
appraisal (~> 2.2)
|
194
|
+
benchmark-ips (~> 2.7.2)
|
193
195
|
bundler (~> 1.15)
|
194
196
|
capybara (~> 2.15)
|
195
197
|
codeclimate-test-reporter (= 1.0.8)
|
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: ..
|
3
3
|
specs:
|
4
|
-
rails-session_cookie (0.2.
|
4
|
+
rails-session_cookie (0.2.2)
|
5
5
|
rails (>= 4.0)
|
6
6
|
|
7
7
|
GEM
|
@@ -53,6 +53,7 @@ GEM
|
|
53
53
|
arel (8.0.0)
|
54
54
|
ast (2.3.0)
|
55
55
|
bcrypt (3.1.11)
|
56
|
+
benchmark-ips (2.7.2)
|
56
57
|
benchmark-perf (0.2.1)
|
57
58
|
builder (3.2.3)
|
58
59
|
byebug (9.1.0)
|
@@ -203,6 +204,7 @@ PLATFORMS
|
|
203
204
|
|
204
205
|
DEPENDENCIES
|
205
206
|
appraisal (~> 2.2)
|
207
|
+
benchmark-ips (~> 2.7.2)
|
206
208
|
bundler (~> 1.15)
|
207
209
|
capybara (~> 2.15)
|
208
210
|
codeclimate-test-reporter (= 1.0.8)
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'rails/session_cookie'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails-session_cookie
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vlad Bokov
|
@@ -178,6 +178,20 @@ dependencies:
|
|
178
178
|
- - "~>"
|
179
179
|
- !ruby/object:Gem::Version
|
180
180
|
version: '2.15'
|
181
|
+
- !ruby/object:Gem::Dependency
|
182
|
+
name: benchmark-ips
|
183
|
+
requirement: !ruby/object:Gem::Requirement
|
184
|
+
requirements:
|
185
|
+
- - "~>"
|
186
|
+
- !ruby/object:Gem::Version
|
187
|
+
version: 2.7.2
|
188
|
+
type: :development
|
189
|
+
prerelease: false
|
190
|
+
version_requirements: !ruby/object:Gem::Requirement
|
191
|
+
requirements:
|
192
|
+
- - "~>"
|
193
|
+
- !ruby/object:Gem::Version
|
194
|
+
version: 2.7.2
|
181
195
|
description: Helps to get proper integration tests run faster
|
182
196
|
email:
|
183
197
|
- razum2um@mail.ru
|
@@ -209,6 +223,7 @@ files:
|
|
209
223
|
- gemfiles/rails_5.1.gemfile.lock
|
210
224
|
- gemfiles/rails_5.1_warden.gemfile
|
211
225
|
- gemfiles/rails_5.1_warden.gemfile.lock
|
226
|
+
- lib/rails-session_cookie.rb
|
212
227
|
- lib/rails/session_cookie.rb
|
213
228
|
- lib/rails/session_cookie/app.rb
|
214
229
|
- lib/rails/session_cookie/version.rb
|