eldr-sessions 0.0.1
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 +7 -0
- data/.gitignore +13 -0
- data/.rspec +3 -0
- data/.rubocop.yml +7 -0
- data/.rubocop_todo.yml +26 -0
- data/.travis.yml +5 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +112 -0
- data/LICENSE +22 -0
- data/README.md +72 -0
- data/Rakefile +10 -0
- data/eldr-sessions.gemspec +34 -0
- data/examples/app.ru +38 -0
- data/lib/eldr-sessions.rb +1 -0
- data/lib/eldr/sessions.rb +37 -0
- data/lib/eldr/sessions/version.rb +5 -0
- data/spec/app_spec.rb +30 -0
- data/spec/sessions_spec.rb +73 -0
- data/spec/spec_helper.rb +12 -0
- metadata +192 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: f309c5e8248b0c03e552a4a97442a748c84ee83b
|
|
4
|
+
data.tar.gz: de07f1a2c79be4524699032d447a64cc2cf180e7
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 4032a6e45b215186680eef9eedf1a2ebc078dcf37c92b49b489464b8f08c4721b9a059552df53da422d62e3ce33559c0b39188dc2b797dd48ae0e5d8a3d0aaa2
|
|
7
|
+
data.tar.gz: cb2b7c98d4370220233d5bfd9f4bb682ad28ebe1f135f4d78be790a8ac92c33c9c6538f68a029355f426f0c02cc730f7b4a281579dfe37f726a3c647c009e4cf
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/.rubocop_todo.yml
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# This configuration was generated by `rubocop --auto-gen-config`
|
|
2
|
+
# on 2015-01-23 12:16:03 -0800 using RuboCop version 0.28.0.
|
|
3
|
+
# The point is for the user to remove these configuration records
|
|
4
|
+
# one by one as the offenses are removed from the code base.
|
|
5
|
+
# Note that changes in the inspected code, or installation of new
|
|
6
|
+
# versions of RuboCop, may require this file to be generated again.
|
|
7
|
+
|
|
8
|
+
# Offense count: 1
|
|
9
|
+
# Configuration parameters: AllowURI, URISchemes.
|
|
10
|
+
Metrics/LineLength:
|
|
11
|
+
Max: 100
|
|
12
|
+
|
|
13
|
+
# Offense count: 2
|
|
14
|
+
Style/Documentation:
|
|
15
|
+
Enabled: false
|
|
16
|
+
|
|
17
|
+
# Offense count: 1
|
|
18
|
+
# Configuration parameters: Exclude.
|
|
19
|
+
Style/FileName:
|
|
20
|
+
Enabled: false
|
|
21
|
+
|
|
22
|
+
# Offense count: 1
|
|
23
|
+
# Cop supports --auto-correct.
|
|
24
|
+
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
|
25
|
+
Style/SignalException:
|
|
26
|
+
Enabled: false
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
eldr-sessions (0.0.1)
|
|
5
|
+
eldr (~> 0.0)
|
|
6
|
+
|
|
7
|
+
GEM
|
|
8
|
+
remote: https://rubygems.org/
|
|
9
|
+
specs:
|
|
10
|
+
activemodel (4.2.0)
|
|
11
|
+
activesupport (= 4.2.0)
|
|
12
|
+
builder (~> 3.1)
|
|
13
|
+
activesupport (4.2.0)
|
|
14
|
+
i18n (~> 0.7)
|
|
15
|
+
json (~> 1.7, >= 1.7.7)
|
|
16
|
+
minitest (~> 5.1)
|
|
17
|
+
thread_safe (~> 0.3, >= 0.3.4)
|
|
18
|
+
tzinfo (~> 1.1)
|
|
19
|
+
ast (2.0.0)
|
|
20
|
+
astrolabe (1.3.0)
|
|
21
|
+
parser (>= 2.2.0.pre.3, < 3.0)
|
|
22
|
+
bson (1.11.1)
|
|
23
|
+
bson_ext (1.11.1)
|
|
24
|
+
bson (~> 1.11.1)
|
|
25
|
+
builder (3.2.2)
|
|
26
|
+
coveralls (0.7.3)
|
|
27
|
+
multi_json (~> 1.10)
|
|
28
|
+
rest-client (~> 1.7)
|
|
29
|
+
simplecov (~> 0.9.1)
|
|
30
|
+
term-ansicolor (~> 1.3)
|
|
31
|
+
thor (~> 0.19.1)
|
|
32
|
+
diff-lcs (1.2.5)
|
|
33
|
+
docile (1.1.5)
|
|
34
|
+
eldr (0.0.3)
|
|
35
|
+
fast_blank (= 0.0.2)
|
|
36
|
+
mustermann (= 0.4.0)
|
|
37
|
+
rack (~> 1.5)
|
|
38
|
+
fast_blank (0.0.2)
|
|
39
|
+
i18n (0.7.0)
|
|
40
|
+
json (1.8.2)
|
|
41
|
+
mime-types (2.4.3)
|
|
42
|
+
minitest (5.5.1)
|
|
43
|
+
mongo (1.11.1)
|
|
44
|
+
bson (= 1.11.1)
|
|
45
|
+
mongo_mapper (0.13.1)
|
|
46
|
+
activemodel (>= 3.0.0)
|
|
47
|
+
activesupport (>= 3.0)
|
|
48
|
+
mongo (~> 1.8)
|
|
49
|
+
plucky (~> 0.6.5)
|
|
50
|
+
multi_json (1.10.1)
|
|
51
|
+
mustermann (0.4.0)
|
|
52
|
+
tool (~> 0.2)
|
|
53
|
+
netrc (0.10.2)
|
|
54
|
+
parser (2.2.0.2)
|
|
55
|
+
ast (>= 1.1, < 3.0)
|
|
56
|
+
plucky (0.6.6)
|
|
57
|
+
mongo (~> 1.5)
|
|
58
|
+
powerpack (0.0.9)
|
|
59
|
+
rack (1.6.0)
|
|
60
|
+
rack-test (0.6.3)
|
|
61
|
+
rack (>= 1.0)
|
|
62
|
+
rainbow (2.0.0)
|
|
63
|
+
rake (10.4.2)
|
|
64
|
+
rest-client (1.7.2)
|
|
65
|
+
mime-types (>= 1.16, < 3.0)
|
|
66
|
+
netrc (~> 0.7)
|
|
67
|
+
rspec (3.1.0)
|
|
68
|
+
rspec-core (~> 3.1.0)
|
|
69
|
+
rspec-expectations (~> 3.1.0)
|
|
70
|
+
rspec-mocks (~> 3.1.0)
|
|
71
|
+
rspec-core (3.1.7)
|
|
72
|
+
rspec-support (~> 3.1.0)
|
|
73
|
+
rspec-expectations (3.1.2)
|
|
74
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
75
|
+
rspec-support (~> 3.1.0)
|
|
76
|
+
rspec-mocks (3.1.3)
|
|
77
|
+
rspec-support (~> 3.1.0)
|
|
78
|
+
rspec-support (3.1.2)
|
|
79
|
+
rubocop (0.28.0)
|
|
80
|
+
astrolabe (~> 1.3)
|
|
81
|
+
parser (>= 2.2.0.pre.7, < 3.0)
|
|
82
|
+
powerpack (~> 0.0.6)
|
|
83
|
+
rainbow (>= 1.99.1, < 3.0)
|
|
84
|
+
ruby-progressbar (~> 1.4)
|
|
85
|
+
ruby-progressbar (1.7.1)
|
|
86
|
+
simplecov (0.9.1)
|
|
87
|
+
docile (~> 1.1.0)
|
|
88
|
+
multi_json (~> 1.0)
|
|
89
|
+
simplecov-html (~> 0.8.0)
|
|
90
|
+
simplecov-html (0.8.0)
|
|
91
|
+
term-ansicolor (1.3.0)
|
|
92
|
+
tins (~> 1.0)
|
|
93
|
+
thor (0.19.1)
|
|
94
|
+
thread_safe (0.3.4)
|
|
95
|
+
tins (1.3.3)
|
|
96
|
+
tool (0.2.3)
|
|
97
|
+
tzinfo (1.2.2)
|
|
98
|
+
thread_safe (~> 0.1)
|
|
99
|
+
|
|
100
|
+
PLATFORMS
|
|
101
|
+
ruby
|
|
102
|
+
|
|
103
|
+
DEPENDENCIES
|
|
104
|
+
bson_ext (= 1.11.1)
|
|
105
|
+
bundler (~> 1.7)
|
|
106
|
+
coveralls (~> 0.7)
|
|
107
|
+
eldr-sessions!
|
|
108
|
+
mongo_mapper (= 0.13.1)
|
|
109
|
+
rack-test (~> 0.6)
|
|
110
|
+
rake (= 10.4.2)
|
|
111
|
+
rspec (= 3.1.0)
|
|
112
|
+
rubocop (= 0.28.0)
|
data/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Copyright (c) 2015 K-2052
|
|
2
|
+
|
|
3
|
+
MIT License
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
a copy of this software and associated documentation files (the
|
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
+
the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be
|
|
14
|
+
included in all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# Eldr::Sessions [](https://travis-ci.org/eldr-rb/eldr-sessions) [](https://codeclimate.com/github/eldr-rb/eldr-sessions) [](https://coveralls.io/r/eldr-rb/eldr-sessions?branch=master) [](https://gemnasium.com/eldr-rb/eldr-sessions) [](http://inch-ci.org/github/eldr-rb/eldr-sessions) [](https://www.gratipay.com/k2052)
|
|
2
|
+
|
|
3
|
+
Provides session helpers like `signed_in?` and `current_user` for [Eldr](https://github.com/eldr-rb/eldr) apps and Rack apps.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Add this line to your application's Gemfile:
|
|
8
|
+
|
|
9
|
+
```ruby
|
|
10
|
+
gem 'eldr-sessions'
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
And then execute:
|
|
14
|
+
|
|
15
|
+
$ bundle
|
|
16
|
+
|
|
17
|
+
Or install it yourself as:
|
|
18
|
+
|
|
19
|
+
$ gem install eldr-sessions
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
22
|
+
|
|
23
|
+
Eldr::Sessions is designed to be included in a Eldr app or Rack app. It has two dependencies;
|
|
24
|
+
|
|
25
|
+
1. Session access via `env['rack.session']`
|
|
26
|
+
2. A configuration object with a `session_id` and `user_model` accessor.
|
|
27
|
+
|
|
28
|
+
If you use it in a Eldr app these two things are already available and you only need to set a session_id.
|
|
29
|
+
|
|
30
|
+
Use it an Eldr::App like this:
|
|
31
|
+
|
|
32
|
+
```ruby
|
|
33
|
+
class App < Eldr::App
|
|
34
|
+
include Eldr::Sessions
|
|
35
|
+
|
|
36
|
+
use Rack::Session::Cookie, secret: 'sessions_secret'
|
|
37
|
+
set :session_id, 'sessionsRawesome'
|
|
38
|
+
|
|
39
|
+
get '/greeting' do
|
|
40
|
+
if current_user
|
|
41
|
+
Rack::Response.new "Hello #{current_user.name}!"
|
|
42
|
+
else
|
|
43
|
+
Rack::Response.new('Login First!', 401)
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
post '/login' do
|
|
48
|
+
user = User.authenticate(params['email'], params['password'])
|
|
49
|
+
set_current_user user
|
|
50
|
+
Rack::Response.new('Logged In!')
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
See [examples/app.ru](https://github.com/eldr-rb/eldr-sessions/tree/master/examples/app.ru) for an example app.
|
|
56
|
+
|
|
57
|
+
## Contributing
|
|
58
|
+
|
|
59
|
+
1. Fork. it
|
|
60
|
+
2. Create. your feature branch (git checkout -b cat-evolver)
|
|
61
|
+
3. Commit. your changes (git commit -am 'Add Cat Evolution')
|
|
62
|
+
4. Test. your changes (always be testing)
|
|
63
|
+
5. Push. to the branch (git push origin cat-evolver)
|
|
64
|
+
6. Pull. Request. (for extra points include funny gif and or pun in comments)
|
|
65
|
+
|
|
66
|
+
To remember this you can use the easy to remember and totally not tongue-in-check initialism: FCCTPP.
|
|
67
|
+
|
|
68
|
+
I don't want any of these steps to scare you off. If you don't know how to do something or are struggle getting it to work feel free to create a pull request or issue anyway. I'll be happy to help you get your contributions up to code and into the repo!
|
|
69
|
+
|
|
70
|
+
## License
|
|
71
|
+
|
|
72
|
+
Licensed under MIT by K-2052.
|
data/Rakefile
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require 'eldr/sessions/version'
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = 'eldr-sessions'
|
|
8
|
+
spec.version = Eldr::Sessions::VERSION
|
|
9
|
+
spec.authors = ['K-2052']
|
|
10
|
+
spec.email = ['k@2052.me']
|
|
11
|
+
spec.summary = %q{Session helpers for the Eldr ruby framework.}
|
|
12
|
+
spec.description = %q{Session helpers for the Eldr ruby framework}
|
|
13
|
+
spec.homepage = 'https://github.com/eldr-rb/eldr-sessions'
|
|
14
|
+
spec.license = 'MIT'
|
|
15
|
+
|
|
16
|
+
spec.required_rubygems_version = '~> 2.0'
|
|
17
|
+
spec.required_ruby_version = '>= 2.0'
|
|
18
|
+
|
|
19
|
+
spec.files = `git ls-files -z`.split("\x0")
|
|
20
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
|
21
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
|
22
|
+
spec.require_paths = ['lib']
|
|
23
|
+
|
|
24
|
+
spec.add_dependency 'eldr', '~> 0.0'
|
|
25
|
+
|
|
26
|
+
spec.add_development_dependency 'bundler', '~> 1.7'
|
|
27
|
+
spec.add_development_dependency 'rake', '10.4.2'
|
|
28
|
+
spec.add_development_dependency 'rspec', '3.1.0'
|
|
29
|
+
spec.add_development_dependency 'rubocop', '0.28.0'
|
|
30
|
+
spec.add_development_dependency 'rack-test', '~> 0.6'
|
|
31
|
+
spec.add_development_dependency 'coveralls', '~> 0.7'
|
|
32
|
+
spec.add_development_dependency 'bson_ext', '1.11.1'
|
|
33
|
+
spec.add_development_dependency 'mongo_mapper', '0.13.1'
|
|
34
|
+
end
|
data/examples/app.ru
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
require 'eldr'
|
|
2
|
+
require 'mongo_mapper'
|
|
3
|
+
require_relative '../lib/eldr/sessions'
|
|
4
|
+
|
|
5
|
+
MongoMapper.setup({'test' => {'uri' => 'mongodb://localhost:27017/eldr_sessions'}}, 'test')
|
|
6
|
+
|
|
7
|
+
class User
|
|
8
|
+
include MongoMapper::Document
|
|
9
|
+
key :name, String
|
|
10
|
+
key :email, String
|
|
11
|
+
|
|
12
|
+
def self.authenticate(email, password)
|
|
13
|
+
find_by_email(email)
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
class App < Eldr::App
|
|
18
|
+
include Eldr::Sessions
|
|
19
|
+
|
|
20
|
+
use Rack::Session::Cookie, secret: 'sessions_secret'
|
|
21
|
+
set :session_id, 'sessionsRawesome'
|
|
22
|
+
|
|
23
|
+
get '/greeting' do
|
|
24
|
+
if current_user
|
|
25
|
+
Rack::Response.new "Hello #{current_user.name}!"
|
|
26
|
+
else
|
|
27
|
+
Rack::Response.new('Login First!', 401)
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
post '/login' do
|
|
32
|
+
user = User.authenticate(params['email'], params['password'])
|
|
33
|
+
set_current_user user
|
|
34
|
+
Rack::Response.new('Logged In!')
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
run App
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require_relative 'eldr/sessions'
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
module Eldr
|
|
2
|
+
module Sessions
|
|
3
|
+
def session
|
|
4
|
+
env['rack.session']
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
def session_id
|
|
8
|
+
configuration.session_id ||= ENV['SESSION_ID']
|
|
9
|
+
raise StandardError, 'Set a session id!' unless configuration.session_id
|
|
10
|
+
configuration.session_id
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def user_model_obj
|
|
14
|
+
@_user_model_obj ||= configuration.user_model.constantize unless configuration.user_model.nil?
|
|
15
|
+
@_user_model_obj ||= 'User'.constantize if defined?('User')
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def login_from_session
|
|
19
|
+
return nil unless session
|
|
20
|
+
user_model_obj.find_by_id(session[session_id]) if user_model_obj
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def current_user
|
|
24
|
+
@current_user ||= login_from_session
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def current_user=(user)
|
|
28
|
+
session[session_id] = user ? user.id : nil
|
|
29
|
+
@current_user = user
|
|
30
|
+
end
|
|
31
|
+
alias_method :set_current_user, :current_user=
|
|
32
|
+
|
|
33
|
+
def signed_in?
|
|
34
|
+
!current_user.nil?
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
data/spec/app_spec.rb
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
describe 'App' do
|
|
2
|
+
let(:app) do
|
|
3
|
+
path = File.expand_path('../examples/app.ru', File.dirname(__FILE__))
|
|
4
|
+
Rack::Builder.parse_file(path).first
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
let(:rt) do
|
|
8
|
+
Rack::Test::Session.new(app)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
describe 'GET /greeting' do
|
|
12
|
+
context 'when not logged in' do
|
|
13
|
+
it 'askes you to login' do
|
|
14
|
+
response = rt.get '/greeting'
|
|
15
|
+
expect(response.status).to eq(401)
|
|
16
|
+
expect(response.body).to eq('Login First!')
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
context 'POST /login' do
|
|
21
|
+
it 'logins a user' do
|
|
22
|
+
user = User.create(email: 'bob@email.com', name: 'Bob')
|
|
23
|
+
rt.post '/login', {email: user.email}
|
|
24
|
+
response = rt.get '/greeting'
|
|
25
|
+
expect(response.status).to eq(200)
|
|
26
|
+
expect(response.body).to eq("Hello #{user.name}!")
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
class TestApp
|
|
2
|
+
include Eldr::Sessions
|
|
3
|
+
attr_accessor :env, :configuration
|
|
4
|
+
|
|
5
|
+
def initialize
|
|
6
|
+
@configuration = Eldr::Configuration.new
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def call(env)
|
|
10
|
+
@env = env
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
describe Eldr::Sessions do
|
|
15
|
+
let(:app) { TestApp.new }
|
|
16
|
+
|
|
17
|
+
let(:env) do
|
|
18
|
+
Rack::MockRequest.env_for('/', {:method => :get, 'rack.session' => {'cats' => 'bob'}})
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
describe '#session' do
|
|
22
|
+
it 'returns the session data' do
|
|
23
|
+
app.call(env)
|
|
24
|
+
expect(app.session['cats']).to eq('bob')
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
describe '#session_id' do
|
|
29
|
+
context 'when there is a session_id' do
|
|
30
|
+
it 'returns the session_id' do
|
|
31
|
+
app.configuration.session_id = 'sessionsRAwesome'
|
|
32
|
+
expect(app.session_id).to eq('sessionsRAwesome')
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
context 'when there is no set session_id' do
|
|
37
|
+
it 'throws an error' do
|
|
38
|
+
app.configuration.session_id = nil
|
|
39
|
+
expect { app.session_id }.to raise_error
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
describe '#user_model_obj' do
|
|
45
|
+
context 'when there is a user_model set on configuration' do
|
|
46
|
+
it 'returns it' do
|
|
47
|
+
Bob = Class.new()
|
|
48
|
+
app.configuration.user_model = 'Bob'
|
|
49
|
+
expect(app.user_model_obj).to eq Bob
|
|
50
|
+
app.configuration.user_model = nil
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
context 'when there is no user_model set on configuration' do
|
|
55
|
+
it 'returns the default' do
|
|
56
|
+
expect(app.user_model_obj).to eq User
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
describe '#login_from_session' do
|
|
62
|
+
context 'when there is a set user' do
|
|
63
|
+
it 'returns that user' do
|
|
64
|
+
app.configuration.session_id = 'sessionsRAwesome'
|
|
65
|
+
app.call(env)
|
|
66
|
+
|
|
67
|
+
user = User.create(name: 'bob')
|
|
68
|
+
app.set_current_user user
|
|
69
|
+
expect(app.login_from_session).to eq user
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
data/spec/spec_helper.rb
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
if ENV['COVERALLS_REPO_TOKEN']
|
|
2
|
+
require 'coveralls'
|
|
3
|
+
Coveralls.wear!
|
|
4
|
+
end
|
|
5
|
+
|
|
6
|
+
require 'rack/test'
|
|
7
|
+
require 'rack'
|
|
8
|
+
|
|
9
|
+
# Hardcode an instance into a global because rack-test likes to get too clever
|
|
10
|
+
RSpec.configure do |config|
|
|
11
|
+
config.include Rack::Test::Methods
|
|
12
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: eldr-sessions
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- K-2052
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2015-01-25 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: eldr
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '0.0'
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '0.0'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: bundler
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '1.7'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '1.7'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: rake
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - '='
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: 10.4.2
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - '='
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: 10.4.2
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: rspec
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - '='
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: 3.1.0
|
|
62
|
+
type: :development
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - '='
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: 3.1.0
|
|
69
|
+
- !ruby/object:Gem::Dependency
|
|
70
|
+
name: rubocop
|
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - '='
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: 0.28.0
|
|
76
|
+
type: :development
|
|
77
|
+
prerelease: false
|
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - '='
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: 0.28.0
|
|
83
|
+
- !ruby/object:Gem::Dependency
|
|
84
|
+
name: rack-test
|
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
|
86
|
+
requirements:
|
|
87
|
+
- - "~>"
|
|
88
|
+
- !ruby/object:Gem::Version
|
|
89
|
+
version: '0.6'
|
|
90
|
+
type: :development
|
|
91
|
+
prerelease: false
|
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
93
|
+
requirements:
|
|
94
|
+
- - "~>"
|
|
95
|
+
- !ruby/object:Gem::Version
|
|
96
|
+
version: '0.6'
|
|
97
|
+
- !ruby/object:Gem::Dependency
|
|
98
|
+
name: coveralls
|
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
|
100
|
+
requirements:
|
|
101
|
+
- - "~>"
|
|
102
|
+
- !ruby/object:Gem::Version
|
|
103
|
+
version: '0.7'
|
|
104
|
+
type: :development
|
|
105
|
+
prerelease: false
|
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
107
|
+
requirements:
|
|
108
|
+
- - "~>"
|
|
109
|
+
- !ruby/object:Gem::Version
|
|
110
|
+
version: '0.7'
|
|
111
|
+
- !ruby/object:Gem::Dependency
|
|
112
|
+
name: bson_ext
|
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
|
114
|
+
requirements:
|
|
115
|
+
- - '='
|
|
116
|
+
- !ruby/object:Gem::Version
|
|
117
|
+
version: 1.11.1
|
|
118
|
+
type: :development
|
|
119
|
+
prerelease: false
|
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
121
|
+
requirements:
|
|
122
|
+
- - '='
|
|
123
|
+
- !ruby/object:Gem::Version
|
|
124
|
+
version: 1.11.1
|
|
125
|
+
- !ruby/object:Gem::Dependency
|
|
126
|
+
name: mongo_mapper
|
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
|
128
|
+
requirements:
|
|
129
|
+
- - '='
|
|
130
|
+
- !ruby/object:Gem::Version
|
|
131
|
+
version: 0.13.1
|
|
132
|
+
type: :development
|
|
133
|
+
prerelease: false
|
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
135
|
+
requirements:
|
|
136
|
+
- - '='
|
|
137
|
+
- !ruby/object:Gem::Version
|
|
138
|
+
version: 0.13.1
|
|
139
|
+
description: Session helpers for the Eldr ruby framework
|
|
140
|
+
email:
|
|
141
|
+
- k@2052.me
|
|
142
|
+
executables: []
|
|
143
|
+
extensions: []
|
|
144
|
+
extra_rdoc_files: []
|
|
145
|
+
files:
|
|
146
|
+
- ".gitignore"
|
|
147
|
+
- ".rspec"
|
|
148
|
+
- ".rubocop.yml"
|
|
149
|
+
- ".rubocop_todo.yml"
|
|
150
|
+
- ".travis.yml"
|
|
151
|
+
- Gemfile
|
|
152
|
+
- Gemfile.lock
|
|
153
|
+
- LICENSE
|
|
154
|
+
- README.md
|
|
155
|
+
- Rakefile
|
|
156
|
+
- eldr-sessions.gemspec
|
|
157
|
+
- examples/app.ru
|
|
158
|
+
- lib/eldr-sessions.rb
|
|
159
|
+
- lib/eldr/sessions.rb
|
|
160
|
+
- lib/eldr/sessions/version.rb
|
|
161
|
+
- spec/app_spec.rb
|
|
162
|
+
- spec/sessions_spec.rb
|
|
163
|
+
- spec/spec_helper.rb
|
|
164
|
+
homepage: https://github.com/eldr-rb/eldr-sessions
|
|
165
|
+
licenses:
|
|
166
|
+
- MIT
|
|
167
|
+
metadata: {}
|
|
168
|
+
post_install_message:
|
|
169
|
+
rdoc_options: []
|
|
170
|
+
require_paths:
|
|
171
|
+
- lib
|
|
172
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
173
|
+
requirements:
|
|
174
|
+
- - ">="
|
|
175
|
+
- !ruby/object:Gem::Version
|
|
176
|
+
version: '2.0'
|
|
177
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
178
|
+
requirements:
|
|
179
|
+
- - "~>"
|
|
180
|
+
- !ruby/object:Gem::Version
|
|
181
|
+
version: '2.0'
|
|
182
|
+
requirements: []
|
|
183
|
+
rubyforge_project:
|
|
184
|
+
rubygems_version: 2.2.2
|
|
185
|
+
signing_key:
|
|
186
|
+
specification_version: 4
|
|
187
|
+
summary: Session helpers for the Eldr ruby framework.
|
|
188
|
+
test_files:
|
|
189
|
+
- spec/app_spec.rb
|
|
190
|
+
- spec/sessions_spec.rb
|
|
191
|
+
- spec/spec_helper.rb
|
|
192
|
+
has_rdoc:
|