monban 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cd09aa083126137a0de785ca3c26497485606236
4
- data.tar.gz: c5280f21c291872564c4785f29951baa4292f541
3
+ metadata.gz: acd6663ce53c6af5ad43f138da55020b087cea3e
4
+ data.tar.gz: 048b50dc5d4f0fc2bec708a5d25c50123cb865e6
5
5
  SHA512:
6
- metadata.gz: c49cea5a7cef423381cd17dae58d410ce93d3ab919b27cd25d7256a0a19e662464ed80a97ddb9fec4fc33e2e161f07478981368234c3340b94b7458fbffbc693
7
- data.tar.gz: 3e6ca5fd876a5c8af8ead41c791eb2a57a342003a9ef6404860ef14950edd1598fb2fc7f8d1b43f9615d0a457b39d6301017de2d50661fd9c601724e339ed892
6
+ metadata.gz: 9c9a8140dfa2b6c5c04aa3d4513885d8b319b30edc2852d5ca68b3d87c8d5c6d580b422650ba2b3ae1508280690ecc5100eb7f767c3316386bb118a399b844f8
7
+ data.tar.gz: 75e929873ffa7175559ffc0779a5366f992d157353d1ce735f3db32a6b9f03802707951ed1c0203e56ce6f50b4885d87659fd07ba42fbd9eaaadaa362be0a0ca
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- monban (0.2.0)
4
+ monban (0.2.1)
5
5
  bcrypt
6
6
  rails
7
7
  warden
@@ -9,98 +9,130 @@ PATH
9
9
  GEM
10
10
  remote: https://rubygems.org/
11
11
  specs:
12
- actionmailer (0.6.1)
13
- actionpack (>= 0.9.5)
14
- actionpack (4.1.0)
15
- actionview (= 4.1.0)
16
- activesupport (= 4.1.0)
17
- rack (~> 1.5.2)
12
+ actionmailer (4.2.2)
13
+ actionpack (= 4.2.2)
14
+ actionview (= 4.2.2)
15
+ activejob (= 4.2.2)
16
+ mail (~> 2.5, >= 2.5.4)
17
+ rails-dom-testing (~> 1.0, >= 1.0.5)
18
+ actionpack (4.2.2)
19
+ actionview (= 4.2.2)
20
+ activesupport (= 4.2.2)
21
+ rack (~> 1.6)
18
22
  rack-test (~> 0.6.2)
19
- actionview (4.1.0)
20
- activesupport (= 4.1.0)
23
+ rails-dom-testing (~> 1.0, >= 1.0.5)
24
+ rails-html-sanitizer (~> 1.0, >= 1.0.1)
25
+ actionview (4.2.2)
26
+ activesupport (= 4.2.2)
21
27
  builder (~> 3.1)
22
28
  erubis (~> 2.7.0)
23
- active_hash (0.9.13)
29
+ rails-dom-testing (~> 1.0, >= 1.0.5)
30
+ rails-html-sanitizer (~> 1.0, >= 1.0.1)
31
+ active_hash (1.4.0)
24
32
  activesupport (>= 2.2.2)
25
- activemodel (4.1.0)
26
- activesupport (= 4.1.0)
33
+ activejob (4.2.2)
34
+ activesupport (= 4.2.2)
35
+ globalid (>= 0.3.0)
36
+ activemodel (4.2.2)
37
+ activesupport (= 4.2.2)
27
38
  builder (~> 3.1)
28
- activerecord (4.1.0)
29
- activemodel (= 4.1.0)
30
- activesupport (= 4.1.0)
31
- arel (~> 5.0.0)
32
- activesupport (4.1.0)
33
- i18n (~> 0.6, >= 0.6.9)
39
+ activerecord (4.2.2)
40
+ activemodel (= 4.2.2)
41
+ activesupport (= 4.2.2)
42
+ arel (~> 6.0)
43
+ activesupport (4.2.2)
44
+ i18n (~> 0.7)
34
45
  json (~> 1.7, >= 1.7.7)
35
46
  minitest (~> 5.1)
36
- thread_safe (~> 0.1)
47
+ thread_safe (~> 0.3, >= 0.3.4)
37
48
  tzinfo (~> 1.1)
38
- arel (5.0.1.20140414130214)
49
+ arel (6.0.0)
39
50
  bcrypt (3.1.10)
40
51
  builder (3.2.2)
41
- capybara (2.0.2)
52
+ capybara (2.4.4)
42
53
  mime-types (>= 1.16)
43
54
  nokogiri (>= 1.3.3)
44
55
  rack (>= 1.0.0)
45
56
  rack-test (>= 0.5.4)
46
- selenium-webdriver (~> 2.0)
47
- xpath (~> 1.0.0)
48
- childprocess (0.3.7)
49
- ffi (~> 1.0, >= 1.0.6)
57
+ xpath (~> 2.0)
50
58
  diff-lcs (1.2.5)
51
59
  erubis (2.7.0)
52
- ffi (1.3.1)
53
- i18n (0.6.9)
54
- json (1.8.1)
55
- mime-types (2.2)
56
- minitest (5.3.3)
57
- multi_json (1.9.3)
58
- nokogiri (1.5.6)
59
- rack (1.5.2)
60
- rack-test (0.6.2)
60
+ globalid (0.3.5)
61
+ activesupport (>= 4.1.0)
62
+ i18n (0.7.0)
63
+ json (1.8.3)
64
+ loofah (2.0.2)
65
+ nokogiri (>= 1.5.9)
66
+ mail (2.6.3)
67
+ mime-types (>= 1.16, < 3)
68
+ mime-types (2.6.1)
69
+ mini_portile (0.6.2)
70
+ minitest (5.7.0)
71
+ nokogiri (1.6.6.2)
72
+ mini_portile (~> 0.6.0)
73
+ rack (1.6.4)
74
+ rack-test (0.6.3)
61
75
  rack (>= 1.0)
62
- rails (0.9.5)
63
- actionmailer (>= 0.6.1)
64
- actionpack (>= 1.4.0)
65
- activerecord (>= 1.6.0)
66
- rake (>= 0.4.15)
67
- railties (4.1.0)
68
- actionpack (= 4.1.0)
69
- activesupport (= 4.1.0)
76
+ rails (4.2.2)
77
+ actionmailer (= 4.2.2)
78
+ actionpack (= 4.2.2)
79
+ actionview (= 4.2.2)
80
+ activejob (= 4.2.2)
81
+ activemodel (= 4.2.2)
82
+ activerecord (= 4.2.2)
83
+ activesupport (= 4.2.2)
84
+ bundler (>= 1.3.0, < 2.0)
85
+ railties (= 4.2.2)
86
+ sprockets-rails
87
+ rails-deprecated_sanitizer (1.0.3)
88
+ activesupport (>= 4.2.0.alpha)
89
+ rails-dom-testing (1.0.6)
90
+ activesupport (>= 4.2.0.beta, < 5.0)
91
+ nokogiri (~> 1.6.0)
92
+ rails-deprecated_sanitizer (>= 1.0.1)
93
+ rails-html-sanitizer (1.0.2)
94
+ loofah (~> 2.0)
95
+ railties (4.2.2)
96
+ actionpack (= 4.2.2)
97
+ activesupport (= 4.2.2)
70
98
  rake (>= 0.8.7)
71
99
  thor (>= 0.18.1, < 2.0)
72
- rake (10.3.1)
73
- rspec (2.14.1)
74
- rspec-core (~> 2.14.0)
75
- rspec-expectations (~> 2.14.0)
76
- rspec-mocks (~> 2.14.0)
77
- rspec-core (2.14.8)
78
- rspec-expectations (2.14.5)
79
- diff-lcs (>= 1.1.3, < 2.0)
80
- rspec-mocks (2.14.6)
81
- rspec-rails (2.14.2)
100
+ rake (10.4.2)
101
+ rspec (3.3.0)
102
+ rspec-core (~> 3.3.0)
103
+ rspec-expectations (~> 3.3.0)
104
+ rspec-mocks (~> 3.3.0)
105
+ rspec-core (3.3.1)
106
+ rspec-support (~> 3.3.0)
107
+ rspec-expectations (3.3.0)
108
+ diff-lcs (>= 1.2.0, < 2.0)
109
+ rspec-support (~> 3.3.0)
110
+ rspec-mocks (3.3.0)
111
+ diff-lcs (>= 1.2.0, < 2.0)
112
+ rspec-support (~> 3.3.0)
113
+ rspec-rails (3.3.2)
114
+ actionpack (>= 3.0, < 4.3)
115
+ activesupport (>= 3.0, < 4.3)
116
+ railties (>= 3.0, < 4.3)
117
+ rspec-core (~> 3.3.0)
118
+ rspec-expectations (~> 3.3.0)
119
+ rspec-mocks (~> 3.3.0)
120
+ rspec-support (~> 3.3.0)
121
+ rspec-support (3.3.0)
122
+ sprockets (3.2.0)
123
+ rack (~> 1.0)
124
+ sprockets-rails (2.3.1)
82
125
  actionpack (>= 3.0)
83
- activemodel (>= 3.0)
84
126
  activesupport (>= 3.0)
85
- railties (>= 3.0)
86
- rspec-core (~> 2.14.0)
87
- rspec-expectations (~> 2.14.0)
88
- rspec-mocks (~> 2.14.0)
89
- rubyzip (0.9.9)
90
- selenium-webdriver (2.29.0)
91
- childprocess (>= 0.2.5)
92
- multi_json (~> 1.0)
93
- rubyzip
94
- websocket (~> 1.0.4)
95
- sqlite3 (1.3.7)
127
+ sprockets (>= 2.8, < 4.0)
128
+ sqlite3 (1.3.10)
96
129
  thor (0.19.1)
97
- thread_safe (0.3.3)
98
- tzinfo (1.1.0)
130
+ thread_safe (0.3.5)
131
+ tzinfo (1.2.2)
99
132
  thread_safe (~> 0.1)
100
133
  warden (1.2.3)
101
134
  rack (>= 1.0)
102
- websocket (1.0.7)
103
- xpath (1.0.0)
135
+ xpath (2.0.0)
104
136
  nokogiri (~> 1.3)
105
137
 
106
138
  PLATFORMS
data/NEWS.rdoc CHANGED
@@ -1,3 +1,8 @@
1
+ == 0.2.1
2
+ * Updated documentation for test helpers
3
+ * Updated documentation for using monban in console
4
+ * Fixed bug with failure app now allowing actual http auth to occur
5
+
1
6
  == 0.2.0
2
7
  * `sign_in` test helper now returns the user
3
8
  * `authenticate_session` arguments are coerced to Hash
data/README.md CHANGED
@@ -57,6 +57,15 @@ configure and change any of these:
57
57
 
58
58
  ### Suggestions
59
59
 
60
+ #### Console Usage
61
+
62
+ If you're trying to sign up a User in a console you won't be able to call User#new or User#create because the User model does not know how to encrypt passwords.
63
+ You should instead use the sign up service in order to create the user:
64
+
65
+ ```ruby
66
+ Monban.config.sign_up_service.new(email: "foo@example.com", password: "password").perform
67
+ ```
68
+
60
69
  #### Validations
61
70
 
62
71
  Monban doesn't add validations to your user model unless you're using [monban generators] so it's suggested to add the following validations:
@@ -175,7 +184,7 @@ end
175
184
 
176
185
  ### Spec helpers
177
186
 
178
- A couple of convenience methods are available in your tests.
187
+ A couple of convenience methods are available in your tests. In order to set this up you'll want to add the following to `rails_helper.rb` or if that doesn't exist `spec_helper.rb`
179
188
 
180
189
  ```ruby
181
190
  Monban.test_mode!
@@ -188,6 +197,8 @@ RSpec.configure do |config|
188
197
  end
189
198
  ```
190
199
 
200
+ Then you can use any of the [test helpers] in your scenarios
201
+
191
202
  ```ruby
192
203
  feature "A feature spec" do
193
204
  scenario "that requires login" do
@@ -359,3 +370,4 @@ Here are a few of the current limitations of monban:
359
370
  5. Create new Pull Request
360
371
 
361
372
  [monban generators]: https://github.com/halogenandtoast/monban-generators
373
+ [test helpers]: https://github.com/halogenandtoast/monban/blob/master/lib/monban/test/helpers.rb
@@ -4,6 +4,7 @@ require "monban/configuration"
4
4
  require "monban/services"
5
5
  require "monban/controller_helpers"
6
6
  require "monban/railtie"
7
+ require "monban/failure_app"
7
8
  require "monban/back_door"
8
9
  require "monban/warden_setup"
9
10
  require "monban/field_map"
@@ -109,7 +109,7 @@ module Monban
109
109
  end
110
110
 
111
111
  def setup_warden_requirements
112
- @failure_app = lambda{|e|[401, {"Content-Type" => "text/plain"}, ["Authorization Failed"]] }
112
+ @failure_app = Monban::FailureApp
113
113
  @authentication_strategy = Monban::Strategies::PasswordStrategy
114
114
  end
115
115
  end
@@ -0,0 +1,48 @@
1
+ module Monban
2
+ class FailureApp
3
+ def self.call(env)
4
+ request = Rack::Request.new(env)
5
+ new(request).response
6
+ end
7
+
8
+ def initialize(request)
9
+ @request = request
10
+ end
11
+
12
+ def response
13
+ [401, headers, body]
14
+ end
15
+
16
+ private
17
+
18
+ attr_reader :request
19
+
20
+ def headers
21
+ if http_auth_header?
22
+ basic_headers.merge(auth_headers)
23
+ else
24
+ basic_headers
25
+ end
26
+ end
27
+
28
+ def basic_headers
29
+ {
30
+ "Content-Type" => request.content_type.to_s
31
+ }
32
+ end
33
+
34
+ def auth_headers
35
+ {
36
+ "WWW-Authenticate" => 'Basic realm="Application"'
37
+ }
38
+ end
39
+
40
+ def body
41
+ ["Authorization Failed"]
42
+ end
43
+
44
+ def http_auth_header?
45
+ !request.xhr?
46
+ end
47
+ end
48
+ end
@@ -1,4 +1,4 @@
1
1
  module Monban
2
- # 0.2.0
3
- VERSION = "0.2.0"
2
+ # 0.2.1
3
+ VERSION = "0.2.1"
4
4
  end
@@ -0,0 +1,9 @@
1
+ require 'spec_helper'
2
+
3
+ feature 'User tries to access constrained routes' do
4
+ scenario 'they can access a route constrained to users' do
5
+ page.driver.browser.basic_authorize("admin", "password")
6
+ visit basic_auth_path
7
+ expect(page.status_code).to eq(200)
8
+ end
9
+ end
@@ -5,6 +5,6 @@ feature 'Visitor signs up' do
5
5
  visit sign_up_path
6
6
  click_on 'go'
7
7
 
8
- page.should_not have_content("Sign out")
8
+ expect(page).not_to have_content("Sign out")
9
9
  end
10
10
  end
@@ -7,7 +7,7 @@ feature 'Visitor signs up' do
7
7
  fill_in 'user_password', with: 'password'
8
8
  click_on 'go'
9
9
 
10
- page.current_path.should eq(posts_path)
10
+ expect(page.current_path).to eq(posts_path)
11
11
  end
12
12
 
13
13
  scenario 'multiple users' do
@@ -26,6 +26,6 @@ feature 'Visitor signs up' do
26
26
  fill_in 'session_password', with: 'password'
27
27
  click_on 'go'
28
28
 
29
- page.current_path.should eq(posts_path)
29
+ expect(page.current_path).to eq(posts_path)
30
30
  end
31
31
  end
@@ -46,22 +46,25 @@ module Monban
46
46
  it 'runs the block when user is signed in' do
47
47
  user = stub_sign_in
48
48
  expectation = double()
49
- expectation.should_receive(:success)
49
+ allow(expectation).to receive(:success)
50
50
  @dummy.sign_in(user) { expectation.success }
51
+ expect(expectation).to have_received(:success)
51
52
  end
52
53
 
53
54
  it 'does not run the block when user can not be signed in' do
54
55
  user = stub_sign_in(false)
55
56
  expectation = double()
56
- expectation.should_not_receive(:failure)
57
+ allow(expectation).to receive(:failure)
57
58
  @dummy.sign_in(user) { expectation.failure }
59
+ expect(expectation).not_to have_received(:failure)
58
60
  end
59
61
 
60
62
  it 'performs a sign out' do
61
63
  sign_out = double()
62
- sign_out.should_receive(:perform)
63
- Services::SignOut.should_receive(:new).with(@warden).and_return(sign_out)
64
+ allow(sign_out).to receive(:perform)
65
+ allow(Services::SignOut).to receive(:new).with(@warden).and_return(sign_out)
64
66
  @dummy.sign_out
67
+ expect(sign_out).to have_received(:perform)
65
68
  end
66
69
 
67
70
  it 'performs a sign_up' do
@@ -72,25 +75,27 @@ module Monban
72
75
  it 'runs the block when user is signed up' do
73
76
  user_params = stub_sign_up
74
77
  expectation = double()
75
- expectation.should_receive(:success)
78
+ allow(expectation).to receive(:success)
76
79
  @dummy.sign_up(user_params) { expectation.success }
80
+ expect(expectation).to have_received(:success)
77
81
  end
78
82
 
79
83
  it 'does not run the block when user can not be signed up' do
80
84
  user_params = stub_sign_up(false)
81
85
  expectation = double()
82
- expectation.should_not_receive(:failure)
83
- @dummy.sign_up(user_params) { expecation.failure }
86
+ allow(expectation).to receive(:failure)
87
+ @dummy.sign_up(user_params) { expectation.failure }
88
+ expect(expectation).not_to have_received(:failure)
84
89
  end
85
90
 
86
91
  it 'authenticates a session' do
87
92
  session_params = { password: 'password', email: 'a@b.com' }
88
93
  user = double()
89
94
  authentication = double()
90
- authentication.should_receive(:perform).and_return(user)
91
- Monban.should_receive(:lookup).with({email: 'a@b.com'}, nil).and_return(user)
92
- Services::Authentication.should_receive(:new).with(user, 'password').and_return(authentication)
93
- @dummy.authenticate_session(session_params).should == user
95
+ allow(authentication).to receive(:perform).and_return(user)
96
+ allow(Monban).to receive(:lookup).with({email: 'a@b.com'}, nil).and_return(user)
97
+ allow(Services::Authentication).to receive(:new).with(user, 'password').and_return(authentication)
98
+ expect(@dummy.authenticate_session(session_params)).to eq user
94
99
  end
95
100
 
96
101
  it 'authenticates a session against multiple fields' do
@@ -98,44 +103,48 @@ module Monban
98
103
  field_map = { email_or_username: [:email, :username] }
99
104
  user = double()
100
105
  authentication = double()
101
- authentication.should_receive(:perform).and_return(user)
102
- Monban.should_receive(:lookup).with(session_params.except(:password), field_map).and_return(user)
103
- Services::Authentication.should_receive(:new).with(user, 'password').and_return(authentication)
104
- @dummy.authenticate_session(session_params, field_map).should == user
106
+ allow(authentication).to receive(:perform).and_return(user)
107
+ allow(Monban).to receive(:lookup).with(session_params.except(:password), field_map).and_return(user)
108
+ allow(Services::Authentication).to receive(:new).with(user, 'password').and_return(authentication)
109
+ expect(@dummy.authenticate_session(session_params, field_map)).to eq user
105
110
  end
106
111
 
107
112
  it 'returns false when it could not authenticate the user' do
108
113
  session_params = { password: "password", lookup_key: "lookup_key" }
109
114
  user = double()
110
115
  authentication = double()
111
- authentication.should_receive(:perform).and_return(false)
112
- Monban.should_receive(:lookup).with({ lookup_key: "lookup_key" }, nil).and_return(user)
113
- Services::Authentication.should_receive(:new).with(user, 'password').and_return(authentication)
114
- @dummy.authenticate_session(session_params).should == false
116
+ allow(authentication).to receive(:perform).and_return(false)
117
+ allow(Monban).to receive(:lookup).with({ lookup_key: "lookup_key" }, nil).and_return(user)
118
+ allow(Services::Authentication).to receive(:new).with(user, 'password').and_return(authentication)
119
+ expect(@dummy.authenticate_session(session_params)).to be_falsey
115
120
  end
116
121
 
117
122
  it 'performs an authenticate' do
118
123
  user = double()
119
124
  password = double()
120
125
  authentication = double()
121
- authentication.should_receive(:perform)
122
- Services::Authentication.should_receive(:new).with(user, password).and_return(authentication)
126
+ allow(authentication).to receive(:perform)
127
+ allow(Services::Authentication).to receive(:new).with(user, password).and_return(authentication)
123
128
  @dummy.authenticate user, password
129
+ expect(authentication).to have_received(:perform)
124
130
  end
125
131
 
126
132
  it 'returns the current user' do
127
- @warden.should_receive(:user)
128
- @dummy.current_user
133
+ current_user = double()
134
+ allow(@warden).to receive(:user).and_return(current_user)
135
+ expect(@dummy.current_user).to eq current_user
129
136
  end
130
137
 
131
138
  it 'returns signed_in?' do
132
- @warden.should_receive(:user)
133
- @dummy.should_not_receive(:current_user)
139
+ allow(@warden).to receive(:user)
140
+ allow(@dummy).to receive(:current_user)
134
141
  @dummy.signed_in?
142
+ expect(@warden).to have_received(:user)
143
+ expect(@dummy).not_to have_received(:current_user)
135
144
  end
136
145
 
137
146
  it 'redirects when not signed_in' do
138
- @warden.should_receive(:user).and_return(false)
147
+ allow(@warden).to receive(:user).and_return(false)
139
148
  @dummy.require_login
140
149
  expect(@dummy.redirected).to eq(true)
141
150
  expect(@dummy.redirected_to).to eq(Monban.config.no_login_redirect)
@@ -143,28 +152,28 @@ module Monban
143
152
  end
144
153
 
145
154
  it 'does not redirect when signed_in' do
146
- @warden.should_receive(:user).and_return(true)
155
+ allow(@warden).to receive(:user).and_return(true)
147
156
  @dummy.require_login
148
157
  expect(@dummy.redirected).to eq(false)
149
158
  end
150
159
 
151
160
  it 'returns warden' do
152
- @dummy.warden.should == @warden
161
+ expect(@dummy.warden).to eq @warden
153
162
  end
154
163
 
155
164
  def stub_sign_in(success = true)
156
165
  user = double()
157
166
  sign_in = double()
158
- sign_in.should_receive(:perform).and_return(success)
159
- Services::SignIn.should_receive(:new).with(user, @warden).and_return(sign_in)
167
+ allow(sign_in).to receive(:perform).and_return(success)
168
+ allow(Services::SignIn).to receive(:new).with(user, @warden).and_return(sign_in)
160
169
  user
161
170
  end
162
171
 
163
172
  def stub_sign_up(success = true)
164
173
  user_params = double()
165
174
  sign_up = double()
166
- sign_up.should_receive(:perform).and_return(success)
167
- Services::SignUp.should_receive(:new).with(user_params).and_return(sign_up)
175
+ allow(sign_up).to receive(:perform).and_return(success)
176
+ allow(Services::SignUp).to receive(:new).with(user_params).and_return(sign_up)
168
177
  user_params
169
178
  end
170
179
  end
@@ -11,10 +11,11 @@ describe Monban::Services::PasswordReset do
11
11
  password_digest = Monban.hash_token('password')
12
12
  user = double()
13
13
  field = Monban.config.user_token_store_field
14
- user.should_receive(:[]=).with(field, 'passwordsecret')
14
+ allow(user).to receive(:[]=)
15
15
  password_reset = Monban::Services::PasswordReset.new(user, 'password')
16
16
 
17
17
  password_reset.perform
18
+ expect(user).to have_received(:[]=).with(field, 'passwordsecret')
18
19
  end
19
20
 
20
21
  after do
@@ -5,8 +5,9 @@ describe Monban::Services::SignIn, '#perform' do
5
5
  it 'signs the user in' do
6
6
  user = double()
7
7
  warden = double()
8
- warden.should_receive(:set_user).with(user)
8
+ allow(warden).to receive(:set_user)
9
9
 
10
10
  Monban::Services::SignIn.new(user, warden).perform
11
+ expect(warden).to have_received(:set_user).with(user)
11
12
  end
12
13
  end
@@ -4,8 +4,9 @@ require 'monban/services/sign_out'
4
4
  describe Monban::Services::SignOut, '#perform' do
5
5
  it 'signs out the user' do
6
6
  warden = double()
7
- warden.should_receive(:logout)
7
+ allow(warden).to receive(:logout)
8
8
 
9
9
  Monban::Services::SignOut.new(warden).perform
10
+ expect(warden).to have_received(:logout)
10
11
  end
11
12
  end
@@ -9,7 +9,7 @@ describe Monban::Services::SignUp, '#perform' do
9
9
  Monban::Services::SignUp.new(user_params).perform
10
10
  expect(User).to have_received(:create) do |args|
11
11
  expect(args[:email]).to eq(user_params[:email])
12
- expect(Monban.compare_token(args[:password_digest], 'password')).to be_true
12
+ expect(Monban.compare_token(args[:password_digest], 'password')).to be_truthy
13
13
  end
14
14
  end
15
15
 
@@ -23,7 +23,7 @@ describe Monban::Services::SignUp, '#perform' do
23
23
  end
24
24
 
25
25
  expect(user_create_double).to have_received(:call) do |args|
26
- expect(Monban.compare_token(args[:password_digest], 'password')).to be_true
26
+ expect(Monban.compare_token(args[:password_digest], 'password')).to be_truthy
27
27
  end
28
28
  end
29
29
 
@@ -67,14 +67,14 @@ module Monban
67
67
  return_value = sign_in(user)
68
68
  app = lambda do |env|
69
69
  $captures << :run
70
- env['warden'].should be_authenticated
71
- env['warden'].user.should eq(user)
70
+ expect(env['warden']).to be_authenticated
71
+ expect(env['warden'].user).to eq(user)
72
72
  valid_response
73
73
  end
74
74
  setup_rack(app).call(env_with_params)
75
75
 
76
- return_value.should eq(user)
77
- $captures.should eq([:run])
76
+ expect(return_value).to eq(user)
77
+ expect($captures).to eq([:run])
78
78
  end
79
79
 
80
80
  it 'performs a sign out' do
@@ -85,12 +85,12 @@ module Monban
85
85
  app = lambda do |env|
86
86
  $captures << :run
87
87
  warden = env['warden']
88
- warden.user.should be_nil
89
- warden.should_not be_authenticated
88
+ expect(warden.user).to be_nil
89
+ expect(warden).not_to be_authenticated
90
90
  end
91
91
 
92
92
  setup_rack(app).call(env_with_params)
93
- $captures.should eq([:run])
93
+ expect($captures).to eq([:run])
94
94
  end
95
95
  end
96
96
  end
@@ -9,7 +9,7 @@ describe 'Monban' do
9
9
  it "provides a .test_mode!" do
10
10
  Monban.test_mode!
11
11
  expect(Monban.hash_token('password')).to eql('password')
12
- expect(Monban.compare_token('password', 'password')).to be_true
12
+ expect(Monban.compare_token('password', 'password')).to be_truthy
13
13
  end
14
14
 
15
15
  it "allows lookup with a field_map" do
@@ -0,0 +1,7 @@
1
+ class BasicAuthController < ApplicationController
2
+ http_basic_authenticate_with name: "admin", password: "password"
3
+
4
+ def show
5
+ render plain: "Hello"
6
+ end
7
+ end
@@ -1,6 +1,4 @@
1
1
  class SessionsController < ApplicationController
2
- respond_to :html
3
-
4
2
  def new
5
3
  end
6
4
 
@@ -22,7 +20,7 @@ class SessionsController < ApplicationController
22
20
  private
23
21
 
24
22
  def session_params
25
- params[:session]
23
+ params.require(:session).permit(:email, :password)
26
24
  end
27
25
  end
28
26
 
@@ -1,6 +1,4 @@
1
1
  class UsersController < ApplicationController
2
- respond_to :html
3
-
4
2
  def new
5
3
  @user = User.new
6
4
  end
@@ -19,7 +17,7 @@ class UsersController < ApplicationController
19
17
  private
20
18
 
21
19
  def user_params
22
- params[:user]
20
+ params.require(:user).permit(:email, :password)
23
21
  end
24
22
  end
25
23
 
@@ -20,4 +20,5 @@ RailsApp::Application.routes.draw do
20
20
  get "sign_up" => "users#new"
21
21
  get "invalid_sign_in" => "invalid_sessions#new"
22
22
  post "invalid_sign_in" => "invalid_sessions#create"
23
+ get "basic_auth" => "basic_auth#show"
23
24
  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.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - halogenandtoast
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-02-24 00:00:00.000000000 Z
12
+ date: 2015-06-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -145,6 +145,7 @@ extensions: []
145
145
  extra_rdoc_files: []
146
146
  files:
147
147
  - ".gitignore"
148
+ - ".rspec"
148
149
  - ".travis.yml"
149
150
  - Gemfile
150
151
  - Gemfile.lock
@@ -158,6 +159,7 @@ files:
158
159
  - lib/monban/constraints/signed_in.rb
159
160
  - lib/monban/constraints/signed_out.rb
160
161
  - lib/monban/controller_helpers.rb
162
+ - lib/monban/failure_app.rb
161
163
  - lib/monban/field_map.rb
162
164
  - lib/monban/railtie.rb
163
165
  - lib/monban/services.rb
@@ -174,6 +176,7 @@ files:
174
176
  - monban.gemspec
175
177
  - spec/features/user/user_signs_in_through_back_door_spec.rb
176
178
  - spec/features/user/user_tries_to_access_constrained_routes_spec.rb
179
+ - spec/features/user/user_tries_to_access_http_auth_page_spec.rb
177
180
  - spec/features/visitor/visitor_fails_to_sign_up_spec.rb
178
181
  - spec/features/visitor/visitor_is_unauthorized_spec.rb
179
182
  - spec/features/visitor/visitor_signs_in_via_invalid_form_spec.rb
@@ -197,6 +200,7 @@ files:
197
200
  - spec/rails_app/app/assets/javascripts/application.js
198
201
  - spec/rails_app/app/assets/stylesheets/application.css
199
202
  - spec/rails_app/app/controllers/application_controller.rb
203
+ - spec/rails_app/app/controllers/basic_auth_controller.rb
200
204
  - spec/rails_app/app/controllers/constrained_to_users_controller.rb
201
205
  - spec/rails_app/app/controllers/constrained_to_visitors_controller.rb
202
206
  - spec/rails_app/app/controllers/failures_controller.rb
@@ -250,13 +254,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
250
254
  version: '0'
251
255
  requirements: []
252
256
  rubyforge_project:
253
- rubygems_version: 2.2.2
257
+ rubygems_version: 2.4.5
254
258
  signing_key:
255
259
  specification_version: 4
256
260
  summary: Making rails authentication as simple as possible
257
261
  test_files:
258
262
  - spec/features/user/user_signs_in_through_back_door_spec.rb
259
263
  - spec/features/user/user_tries_to_access_constrained_routes_spec.rb
264
+ - spec/features/user/user_tries_to_access_http_auth_page_spec.rb
260
265
  - spec/features/visitor/visitor_fails_to_sign_up_spec.rb
261
266
  - spec/features/visitor/visitor_is_unauthorized_spec.rb
262
267
  - spec/features/visitor/visitor_signs_in_via_invalid_form_spec.rb
@@ -280,6 +285,7 @@ test_files:
280
285
  - spec/rails_app/app/assets/javascripts/application.js
281
286
  - spec/rails_app/app/assets/stylesheets/application.css
282
287
  - spec/rails_app/app/controllers/application_controller.rb
288
+ - spec/rails_app/app/controllers/basic_auth_controller.rb
283
289
  - spec/rails_app/app/controllers/constrained_to_users_controller.rb
284
290
  - spec/rails_app/app/controllers/constrained_to_visitors_controller.rb
285
291
  - spec/rails_app/app/controllers/failures_controller.rb