monban 1.0.0 → 1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c994797ca1338ca8d78bb15bdfeaa5585bdf555a
4
- data.tar.gz: 0ae31c41b9a1b9b08e8888a354d440051ed30eef
3
+ metadata.gz: 61a099fb20745246c9094ac5c9957119180cb452
4
+ data.tar.gz: 4f8aec070188cccfcb27c51692e2942dd67fafe6
5
5
  SHA512:
6
- metadata.gz: 3d4db22086b7359a92202a55cb033f5255434146e214d655974db3ae8d4b039232188bbfc41f715eb6ce040c80c02b55295b51dc2799c6ffe77f76a4ad51ffa7
7
- data.tar.gz: ccd82bf884f619b75f15b0fd4a3d91248f600d0d3aa660964c6a565a20623cf8e868eac62ac91a8bde5caae667d54693f0e11f1e2494fc3c6c49311bc8f92302
6
+ metadata.gz: 809a7eec54aa4327fd7c383088cd2a1a91cc53a4cc96eda43917f070a55c1b41986dce8bd58e7a6f3e0feefb42f25b119f31bf819ce4f07618693e536f0904f6
7
+ data.tar.gz: e7fc64a1393b18b6525962004143c3c82978c41fb4f0712c36186fccccb4da2675ec7db31a289742e33cef7ea1754c747e5ac9b9dcd26753f46dc0a78dbacc3d
data/NEWS.rdoc CHANGED
@@ -1,3 +1,7 @@
1
+ == 1.0.1
2
+ * Wrap helper_method calls in respond_to?(:helper_method)
3
+ * param_transformations now correctly use string keys
4
+
1
5
  == 1.0.0
2
6
  * Do not perform lookup if no params are passed to lookup
3
7
  * Add param transformer for sanitizing and normalizing
@@ -55,6 +55,17 @@ module Monban
55
55
  config.hashing_method.call(token)
56
56
  end
57
57
 
58
+
59
+ # performs transformations on params for signing up and
60
+ # signing in
61
+ #
62
+ # @param params [Hash] hash of parameters to transform
63
+ # @see Monban::Configuration#param_transofmrations
64
+ # @return [Hash] hash with transformed parameters
65
+ def self.transform_params(params)
66
+ ParamTransformer.new(params, config.param_transformations).to_h
67
+ end
68
+
58
69
  # the user class
59
70
  #
60
71
  # @see Monban::Configuration#setup_class_defaults
@@ -30,7 +30,7 @@ module Monban
30
30
  # @see #creation_method=
31
31
  def default_creation_method
32
32
  ->(params) do
33
- updated_params = transform_params(params)
33
+ updated_params = Monban.transform_params(params)
34
34
  Monban.config.user_class.create(updated_params)
35
35
  end
36
36
  end
@@ -54,7 +54,7 @@ module Monban
54
54
  # @see Monban.config.user_class
55
55
  def default_find_method
56
56
  ->(params) do
57
- updated_params = transform_params(params)
57
+ updated_params = Monban.transform_params(params)
58
58
  Monban.config.user_class.find_by(updated_params)
59
59
  end
60
60
  end
@@ -134,12 +134,8 @@ module Monban
134
134
 
135
135
  def setup_param_transformations
136
136
  @param_transformations = {
137
- email: ->(value) { value.downcase }
137
+ "email" => ->(value) { value.downcase }
138
138
  }
139
139
  end
140
-
141
- def transform_params(params)
142
- ParamTransformer.new(params, param_transformations).to_h
143
- end
144
140
  end
145
141
  end
@@ -7,7 +7,9 @@ module Monban
7
7
  module ControllerHelpers
8
8
  extend ActiveSupport::Concern
9
9
  included do
10
- helper_method :current_user, :signed_in?
10
+ if respond_to?(:helper_method)
11
+ helper_method :current_user, :signed_in?
12
+ end
11
13
  end
12
14
 
13
15
  # Sign in a user
@@ -98,9 +100,9 @@ module Monban
98
100
 
99
101
  def authenticate_session session_params, field_map = nil
100
102
  token_field = Monban.config.user_token_field
101
- session_params_hash = session_params.to_h.symbolize_keys
102
- password = session_params_hash.fetch(token_field)
103
- user = Monban.lookup(session_params_hash.except(token_field), field_map)
103
+ params_hash = Monban.transform_params(session_params).symbolize_keys
104
+ password = params_hash.fetch(token_field)
105
+ user = Monban.lookup(params_hash.except(token_field), field_map)
104
106
  authenticate(user, password)
105
107
  end
106
108
 
@@ -1,4 +1,4 @@
1
1
  module Monban
2
- # 1.0.0
3
- VERSION = "1.0.0"
2
+ # 1.0.1
3
+ VERSION = "1.0.1"
4
4
  end
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+
3
+ feature 'User signs in' do
4
+ scenario 'with mismatched email case' do
5
+ user = User.create!(email: "example@example.com", password_digest: "password")
6
+
7
+ visit sign_in_path
8
+ fill_in "session[email]", with: "Example@example.com"
9
+ fill_in "session[password]", with: "password"
10
+ click_button "go"
11
+
12
+ expect(current_path).to eq posts_path
13
+ end
14
+ end
@@ -10,6 +10,15 @@ feature 'Visitor signs up' do
10
10
  expect(page.current_path).to eq(posts_path)
11
11
  end
12
12
 
13
+ scenario 'with uppercase email' do
14
+ visit sign_up_path
15
+ fill_in 'user_email', with: 'Email@example.com'
16
+ fill_in 'user_password', with: 'password'
17
+ click_on 'go'
18
+
19
+ expect(User.last.email).to eq('email@example.com')
20
+ end
21
+
13
22
  scenario 'multiple users' do
14
23
  visit sign_up_path
15
24
  fill_in 'user_email', with: 'email@example.com'
@@ -7,10 +7,16 @@ require 'warden'
7
7
  require 'monban'
8
8
  require 'capybara'
9
9
 
10
+ Monban.test_mode!
11
+ Warden.test_mode!
12
+
10
13
  RSpec.configure do |config|
11
14
  config.include Warden::Test::Helpers
12
15
  config.include Monban::Test::Helpers, type: :feature
13
16
  config.order = "random"
17
+ config.after :each do
18
+ Monban.test_reset!
19
+ end
14
20
  end
15
21
 
16
22
  def with_monban_config(hash, &block)
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: 1.0.0
4
+ version: 1.0.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: 2016-05-02 00:00:00.000000000 Z
12
+ date: 2016-06-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -175,6 +175,7 @@ files:
175
175
  - lib/monban/version.rb
176
176
  - lib/monban/warden_setup.rb
177
177
  - monban.gemspec
178
+ - spec/features/user/user_signs_in_spec.rb
178
179
  - spec/features/user/user_signs_in_through_back_door_spec.rb
179
180
  - spec/features/user/user_tries_to_access_constrained_routes_spec.rb
180
181
  - spec/features/user/user_tries_to_access_http_auth_page_spec.rb
@@ -260,6 +261,7 @@ signing_key:
260
261
  specification_version: 4
261
262
  summary: Making rails authentication as simple as possible
262
263
  test_files:
264
+ - spec/features/user/user_signs_in_spec.rb
263
265
  - spec/features/user/user_signs_in_through_back_door_spec.rb
264
266
  - spec/features/user/user_tries_to_access_constrained_routes_spec.rb
265
267
  - spec/features/user/user_tries_to_access_http_auth_page_spec.rb