monban 0.0.9 → 0.0.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +0 -1
- data/Gemfile.lock +4 -4
- data/README.md +37 -3
- data/lib/monban/controller_helpers.rb +2 -2
- data/lib/monban/test/controller_helpers.rb +32 -0
- data/lib/monban/version.rb +1 -1
- data/lib/monban.rb +1 -0
- data/monban.gemspec +1 -1
- data/spec/monban/controller_helpers_spec.rb +8 -1
- data/spec/monban/test_controller_helpers_spec.rb +63 -0
- metadata +28 -26
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e29be6de04544dc568a87d8d2c8d192d80c7eaf4
|
4
|
+
data.tar.gz: b8b31096244cdb5314c42b18fcf03e8e2a2e5821
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 645d7342a7f7c3d87fe8657a0c0b28f109338d7dd50fd86874d452adaa5ab0ed77652e511015f8a7b8a9d31460e8016dbc8bf3f78f3d4e7f0d9db7cd65720e21
|
7
|
+
data.tar.gz: f15e3f355a53edd45e24f98cf2a71f8e2a360888fd0165690d0f4a13e2427c82ac30e3475f2e390b7b86972513fb517cf92c59317e1e487c64302f9e2309ed9d
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
monban (0.0.
|
5
|
-
bcrypt
|
4
|
+
monban (0.0.9)
|
5
|
+
bcrypt
|
6
6
|
rails
|
7
7
|
warden
|
8
8
|
|
@@ -39,7 +39,7 @@ GEM
|
|
39
39
|
i18n (~> 0.6)
|
40
40
|
multi_json (~> 1.0)
|
41
41
|
arel (3.0.3)
|
42
|
-
bcrypt
|
42
|
+
bcrypt (3.1.6)
|
43
43
|
builder (3.0.4)
|
44
44
|
capybara (2.0.2)
|
45
45
|
mime-types (>= 1.16)
|
@@ -64,7 +64,7 @@ GEM
|
|
64
64
|
mime-types (1.20.1)
|
65
65
|
multi_json (1.5.0)
|
66
66
|
nokogiri (1.5.6)
|
67
|
-
polyglot (0.3.
|
67
|
+
polyglot (0.3.4)
|
68
68
|
rack (1.4.4)
|
69
69
|
rack-cache (1.2)
|
70
70
|
rack (>= 0.4)
|
data/README.md
CHANGED
@@ -81,7 +81,7 @@ And this filter:
|
|
81
81
|
|
82
82
|
### Test mode
|
83
83
|
|
84
|
-
Monban provides the
|
84
|
+
Monban provides the following:
|
85
85
|
|
86
86
|
```ruby
|
87
87
|
Monban.test_mode!
|
@@ -103,8 +103,6 @@ end
|
|
103
103
|
A couple of convenience methods are available in your tests.
|
104
104
|
|
105
105
|
```ruby
|
106
|
-
require 'monban/test/helpers'
|
107
|
-
|
108
106
|
Monban.test_mode!
|
109
107
|
|
110
108
|
RSpec.configure do |config|
|
@@ -127,6 +125,42 @@ feature "A feature spec" do
|
|
127
125
|
end
|
128
126
|
```
|
129
127
|
|
128
|
+
## Controller Specs
|
129
|
+
|
130
|
+
If you are going to write controller tests, helpers are provided for those as well:
|
131
|
+
|
132
|
+
```ruby
|
133
|
+
Monban.test_mode!
|
134
|
+
|
135
|
+
RSpec.configure do |config|
|
136
|
+
config.include Monban::Test::ControllerHelpers, type: :controller
|
137
|
+
config.after :each do
|
138
|
+
Monban.test_reset!
|
139
|
+
end
|
140
|
+
end
|
141
|
+
```
|
142
|
+
|
143
|
+
```ruby
|
144
|
+
require 'spec_helper'
|
145
|
+
|
146
|
+
describe ProtectedController do
|
147
|
+
|
148
|
+
describe "GET 'index'" do
|
149
|
+
it "returns http success when signed in" do
|
150
|
+
user = create(:user)
|
151
|
+
sign_in(user)
|
152
|
+
get 'index'
|
153
|
+
response.should be_success
|
154
|
+
end
|
155
|
+
|
156
|
+
it "redirects when not signed in" do
|
157
|
+
get 'index'
|
158
|
+
response.should be_redirect
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
162
|
+
```
|
163
|
+
|
130
164
|
## Advanced Functionality
|
131
165
|
|
132
166
|
You may perform a look up on a user using multiple fields by doing something like the following:
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Monban
|
2
|
+
module Test
|
3
|
+
module ControllerHelpers
|
4
|
+
def self.included(base)
|
5
|
+
base.class_eval do
|
6
|
+
setup :store_controller_for_warden, :warden if respond_to?(:setup)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def store_controller_for_warden
|
11
|
+
@request.env['action_controller.instance'] = @controller
|
12
|
+
end
|
13
|
+
|
14
|
+
def sign_in(user)
|
15
|
+
@controller.sign_in(user)
|
16
|
+
end
|
17
|
+
|
18
|
+
def sign_out
|
19
|
+
@controller.sign_out
|
20
|
+
end
|
21
|
+
|
22
|
+
def warden
|
23
|
+
@warden ||= begin
|
24
|
+
manager = Warden::Manager.new(nil) do |config|
|
25
|
+
config.merge! Monban.warden_config
|
26
|
+
end
|
27
|
+
@request.env['warden'] = Warden::Proxy.new(@request.env, manager)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/lib/monban/version.rb
CHANGED
data/lib/monban.rb
CHANGED
data/monban.gemspec
CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |gem|
|
|
18
18
|
gem.require_paths = ["lib"]
|
19
19
|
|
20
20
|
gem.add_dependency 'rails'
|
21
|
-
gem.add_dependency 'bcrypt
|
21
|
+
gem.add_dependency 'bcrypt'
|
22
22
|
gem.add_dependency 'warden'
|
23
23
|
gem.add_development_dependency 'rake'
|
24
24
|
gem.add_development_dependency 'rspec'
|
@@ -7,13 +7,20 @@ module Monban
|
|
7
7
|
end
|
8
8
|
class Flash < Struct.new(:notice)
|
9
9
|
end
|
10
|
+
class FakeRequest
|
11
|
+
attr_reader :env
|
12
|
+
def initialize(env)
|
13
|
+
@env = env
|
14
|
+
end
|
15
|
+
end
|
10
16
|
|
11
17
|
class Dummy
|
12
|
-
attr_reader :redirected, :flash
|
18
|
+
attr_reader :redirected, :flash, :request
|
13
19
|
def initialize warden
|
14
20
|
@warden = warden
|
15
21
|
@flash = Flash.new
|
16
22
|
@redirected = false
|
23
|
+
@request = FakeRequest.new(env)
|
17
24
|
end
|
18
25
|
def redirect_to path
|
19
26
|
@redirected = true
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class FakeRequest
|
4
|
+
attr_reader :env
|
5
|
+
def initialize
|
6
|
+
@env = {}
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
class FakeController
|
11
|
+
attr_reader :user
|
12
|
+
def sign_in(user)
|
13
|
+
@user = user
|
14
|
+
end
|
15
|
+
|
16
|
+
def sign_out
|
17
|
+
@user = nil
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
class FakeSpec
|
22
|
+
cattr_reader :setup_methods
|
23
|
+
attr_reader :request, :controller
|
24
|
+
def initialize(controller = FakeController.new)
|
25
|
+
@request = FakeRequest.new
|
26
|
+
@controller = controller
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.setup(*methods)
|
30
|
+
@@setup_methods = methods
|
31
|
+
end
|
32
|
+
include Monban::Test::ControllerHelpers
|
33
|
+
end
|
34
|
+
|
35
|
+
module Monban
|
36
|
+
module Test
|
37
|
+
describe ControllerHelpers do
|
38
|
+
it 'sets up warden' do
|
39
|
+
expect(FakeSpec.setup_methods).to eq([:store_controller_for_warden, :warden])
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'creates a warden manager' do
|
43
|
+
fake_spec = FakeSpec.new
|
44
|
+
expect(fake_spec.warden).to be_a(Warden::Proxy)
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'calls the sign in method on the controller' do
|
48
|
+
controller = FakeController.new
|
49
|
+
fake_spec = FakeSpec.new(controller)
|
50
|
+
fake_spec.sign_in("user")
|
51
|
+
expect(controller.user).to eq("user")
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'calls the sign out method on the controller' do
|
55
|
+
controller = FakeController.new
|
56
|
+
fake_spec = FakeSpec.new(controller)
|
57
|
+
fake_spec.sign_in("user")
|
58
|
+
fake_spec.sign_out
|
59
|
+
expect(controller.user).to eq(nil)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: monban
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- halogenandtoast
|
@@ -9,132 +9,132 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-03-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
requirements:
|
18
|
-
- -
|
18
|
+
- - ">="
|
19
19
|
- !ruby/object:Gem::Version
|
20
20
|
version: '0'
|
21
21
|
type: :runtime
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
|
-
- -
|
25
|
+
- - ">="
|
26
26
|
- !ruby/object:Gem::Version
|
27
27
|
version: '0'
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
|
-
name: bcrypt
|
29
|
+
name: bcrypt
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
31
31
|
requirements:
|
32
|
-
- -
|
32
|
+
- - ">="
|
33
33
|
- !ruby/object:Gem::Version
|
34
34
|
version: '0'
|
35
35
|
type: :runtime
|
36
36
|
prerelease: false
|
37
37
|
version_requirements: !ruby/object:Gem::Requirement
|
38
38
|
requirements:
|
39
|
-
- -
|
39
|
+
- - ">="
|
40
40
|
- !ruby/object:Gem::Version
|
41
41
|
version: '0'
|
42
42
|
- !ruby/object:Gem::Dependency
|
43
43
|
name: warden
|
44
44
|
requirement: !ruby/object:Gem::Requirement
|
45
45
|
requirements:
|
46
|
-
- -
|
46
|
+
- - ">="
|
47
47
|
- !ruby/object:Gem::Version
|
48
48
|
version: '0'
|
49
49
|
type: :runtime
|
50
50
|
prerelease: false
|
51
51
|
version_requirements: !ruby/object:Gem::Requirement
|
52
52
|
requirements:
|
53
|
-
- -
|
53
|
+
- - ">="
|
54
54
|
- !ruby/object:Gem::Version
|
55
55
|
version: '0'
|
56
56
|
- !ruby/object:Gem::Dependency
|
57
57
|
name: rake
|
58
58
|
requirement: !ruby/object:Gem::Requirement
|
59
59
|
requirements:
|
60
|
-
- -
|
60
|
+
- - ">="
|
61
61
|
- !ruby/object:Gem::Version
|
62
62
|
version: '0'
|
63
63
|
type: :development
|
64
64
|
prerelease: false
|
65
65
|
version_requirements: !ruby/object:Gem::Requirement
|
66
66
|
requirements:
|
67
|
-
- -
|
67
|
+
- - ">="
|
68
68
|
- !ruby/object:Gem::Version
|
69
69
|
version: '0'
|
70
70
|
- !ruby/object:Gem::Dependency
|
71
71
|
name: rspec
|
72
72
|
requirement: !ruby/object:Gem::Requirement
|
73
73
|
requirements:
|
74
|
-
- -
|
74
|
+
- - ">="
|
75
75
|
- !ruby/object:Gem::Version
|
76
76
|
version: '0'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
79
|
version_requirements: !ruby/object:Gem::Requirement
|
80
80
|
requirements:
|
81
|
-
- -
|
81
|
+
- - ">="
|
82
82
|
- !ruby/object:Gem::Version
|
83
83
|
version: '0'
|
84
84
|
- !ruby/object:Gem::Dependency
|
85
85
|
name: rspec-rails
|
86
86
|
requirement: !ruby/object:Gem::Requirement
|
87
87
|
requirements:
|
88
|
-
- -
|
88
|
+
- - ">="
|
89
89
|
- !ruby/object:Gem::Version
|
90
90
|
version: '0'
|
91
91
|
type: :development
|
92
92
|
prerelease: false
|
93
93
|
version_requirements: !ruby/object:Gem::Requirement
|
94
94
|
requirements:
|
95
|
-
- -
|
95
|
+
- - ">="
|
96
96
|
- !ruby/object:Gem::Version
|
97
97
|
version: '0'
|
98
98
|
- !ruby/object:Gem::Dependency
|
99
99
|
name: capybara
|
100
100
|
requirement: !ruby/object:Gem::Requirement
|
101
101
|
requirements:
|
102
|
-
- -
|
102
|
+
- - ">="
|
103
103
|
- !ruby/object:Gem::Version
|
104
104
|
version: '0'
|
105
105
|
type: :development
|
106
106
|
prerelease: false
|
107
107
|
version_requirements: !ruby/object:Gem::Requirement
|
108
108
|
requirements:
|
109
|
-
- -
|
109
|
+
- - ">="
|
110
110
|
- !ruby/object:Gem::Version
|
111
111
|
version: '0'
|
112
112
|
- !ruby/object:Gem::Dependency
|
113
113
|
name: sqlite3
|
114
114
|
requirement: !ruby/object:Gem::Requirement
|
115
115
|
requirements:
|
116
|
-
- -
|
116
|
+
- - ">="
|
117
117
|
- !ruby/object:Gem::Version
|
118
118
|
version: '0'
|
119
119
|
type: :development
|
120
120
|
prerelease: false
|
121
121
|
version_requirements: !ruby/object:Gem::Requirement
|
122
122
|
requirements:
|
123
|
-
- -
|
123
|
+
- - ">="
|
124
124
|
- !ruby/object:Gem::Version
|
125
125
|
version: '0'
|
126
126
|
- !ruby/object:Gem::Dependency
|
127
127
|
name: active_hash
|
128
128
|
requirement: !ruby/object:Gem::Requirement
|
129
129
|
requirements:
|
130
|
-
- -
|
130
|
+
- - ">="
|
131
131
|
- !ruby/object:Gem::Version
|
132
132
|
version: '0'
|
133
133
|
type: :development
|
134
134
|
prerelease: false
|
135
135
|
version_requirements: !ruby/object:Gem::Requirement
|
136
136
|
requirements:
|
137
|
-
- -
|
137
|
+
- - ">="
|
138
138
|
- !ruby/object:Gem::Version
|
139
139
|
version: '0'
|
140
140
|
description: simple rails authentication
|
@@ -144,7 +144,7 @@ executables: []
|
|
144
144
|
extensions: []
|
145
145
|
extra_rdoc_files: []
|
146
146
|
files:
|
147
|
-
- .gitignore
|
147
|
+
- ".gitignore"
|
148
148
|
- CHANGELOG.rdoc
|
149
149
|
- Gemfile
|
150
150
|
- Gemfile.lock
|
@@ -170,6 +170,7 @@ files:
|
|
170
170
|
- lib/monban/services/sign_out.rb
|
171
171
|
- lib/monban/services/sign_up.rb
|
172
172
|
- lib/monban/strategies/password_strategy.rb
|
173
|
+
- lib/monban/test/controller_helpers.rb
|
173
174
|
- lib/monban/test/helpers.rb
|
174
175
|
- lib/monban/version.rb
|
175
176
|
- lib/monban/warden_setup.rb
|
@@ -184,6 +185,7 @@ files:
|
|
184
185
|
- spec/monban/services/sign_in_spec.rb
|
185
186
|
- spec/monban/services/sign_out_spec.rb
|
186
187
|
- spec/monban/services/sign_up_spec.rb
|
188
|
+
- spec/monban/test_controller_helpers_spec.rb
|
187
189
|
- spec/monban/test_helpers_spec.rb
|
188
190
|
- spec/monban_spec.rb
|
189
191
|
- spec/rails_app/Rakefile
|
@@ -230,17 +232,17 @@ require_paths:
|
|
230
232
|
- lib
|
231
233
|
required_ruby_version: !ruby/object:Gem::Requirement
|
232
234
|
requirements:
|
233
|
-
- -
|
235
|
+
- - ">="
|
234
236
|
- !ruby/object:Gem::Version
|
235
237
|
version: '0'
|
236
238
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
237
239
|
requirements:
|
238
|
-
- -
|
240
|
+
- - ">="
|
239
241
|
- !ruby/object:Gem::Version
|
240
242
|
version: '0'
|
241
243
|
requirements: []
|
242
244
|
rubyforge_project:
|
243
|
-
rubygems_version: 2.
|
245
|
+
rubygems_version: 2.2.2
|
244
246
|
signing_key:
|
245
247
|
specification_version: 4
|
246
248
|
summary: Making rails authentication as simple as possible
|
@@ -255,6 +257,7 @@ test_files:
|
|
255
257
|
- spec/monban/services/sign_in_spec.rb
|
256
258
|
- spec/monban/services/sign_out_spec.rb
|
257
259
|
- spec/monban/services/sign_up_spec.rb
|
260
|
+
- spec/monban/test_controller_helpers_spec.rb
|
258
261
|
- spec/monban/test_helpers_spec.rb
|
259
262
|
- spec/monban_spec.rb
|
260
263
|
- spec/rails_app/Rakefile
|
@@ -292,4 +295,3 @@ test_files:
|
|
292
295
|
- spec/rails_app/public/favicon.ico
|
293
296
|
- spec/rails_app/script/rails
|
294
297
|
- spec/spec_helper.rb
|
295
|
-
has_rdoc:
|