Skip to content

Commit

Permalink
Initialise :repository and :guest_user attributes
Browse files Browse the repository at this point in the history
These are now initialised in the new `self.included` method, eliminating the previous need to explicitly initialise a value for `config.repository` *every single time.

Want to do it differently? Create your own module that includes or extends `CryptIdent`, and follow this example.

[Closes #29]

86 tests, 113 assertions, 0 failures, 0 errors, 0 skips
Coverage: 1012 / 1012 LOC (100.0%) covered.
RuboCop: 11 files inspected, no offenses detected
Flay: Total score 0
Flog: Total 326.1; method average 4.7; max 8.4 (CryptIdent::SignUp#create_result)
Reek: 0 total warnings
Inch: Nothing to suggest
  • Loading branch information
jdickey committed Feb 27, 2019
1 parent a805568 commit 6201b09
Show file tree
Hide file tree
Showing 21 changed files with 52 additions and 71 deletions.
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.6.0
2.6.1
23 changes: 12 additions & 11 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ GEM
thread_safe (~> 0.3, >= 0.3.1)
bcrypt (3.1.12)
builder (3.2.3)
byebug (10.0.2)
byebug (11.0.0)
codeclimate-engine-rb (0.4.1)
virtus (~> 1.0)
coderay (1.1.2)
Expand All @@ -28,7 +28,7 @@ GEM
descendants_tracker (0.0.4)
thread_safe (~> 0.3, >= 0.3.1)
docile (1.3.1)
dry-configurable (0.8.1)
dry-configurable (0.8.2)
concurrent-ruby (~> 1.0)
dry-core (~> 0.4, >= 0.4.7)
dry-container (0.7.0)
Expand Down Expand Up @@ -115,7 +115,7 @@ GEM
yard (~> 0.9.12)
inflecto (0.0.2)
jaro_winkler (1.5.2)
json (2.1.0)
json (2.2.0)
kwalify (0.7.2)
listen (3.1.5)
rb-fsevent (~> 0.9, >= 0.9.4)
Expand All @@ -133,22 +133,22 @@ GEM
builder
minitest (>= 5.0)
ruby-progressbar
minitest-tagz (1.6.0)
minitest-tagz (1.7.0)
minitest (~> 5)
nenv (0.3.0)
notiffany (0.1.1)
nenv (~> 0.1)
shellany (~> 0.0)
parallel (1.13.0)
parallel (1.14.0)
parser (2.6.0.0)
ast (~> 2.4.0)
path_expander (1.0.3)
powerpack (0.1.2)
pry (0.12.2)
coderay (~> 1.1.0)
method_source (~> 0.9.0)
pry-byebug (3.6.0)
byebug (~> 10.0)
pry-byebug (3.7.0)
byebug (~> 11.0)
pry (~> 0.10)
pry-doc (1.0.0)
pry (~> 0.11)
Expand Down Expand Up @@ -188,11 +188,12 @@ GEM
dry-types (~> 0.11.0)
rom (~> 3.2, >= 3.2.2)
sequel (~> 4.43)
rubocop (0.64.0)
rubocop (0.65.0)
jaro_winkler (~> 1.5.1)
parallel (~> 1.10)
parser (>= 2.5, != 2.5.1.1)
powerpack (~> 0.1)
psych (>= 3.1.0)
rainbow (>= 2.2.2, < 4.0)
ruby-progressbar (~> 1.7)
unicode-display_width (~> 1.4.0)
Expand Down Expand Up @@ -246,13 +247,13 @@ DEPENDENCIES
minitest-hooks (= 1.5.0)
minitest-matchers (= 1.4.1)
minitest-reporters (= 1.3.6)
minitest-tagz (= 1.6.0)
pry-byebug (= 3.6.0)
minitest-tagz (= 1.7.0)
pry-byebug (= 3.7.0)
pry-doc (= 1.0.0)
rake (>= 12.3.2)
redcarpet (= 3.4.0)
reek (= 5.3.1)
rubocop (= 0.64.0)
rubocop (= 0.65.0)
simplecov (= 0.16.1)
sqlite3
timecop (= 0.9.1)
Expand Down
6 changes: 3 additions & 3 deletions crypt_ident.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@ Gem::Specification.new do |spec|
spec.add_development_dependency 'minitest-hooks', '1.5.0'
spec.add_development_dependency 'minitest-matchers', '1.4.1'
spec.add_development_dependency 'minitest-reporters', '1.3.6'
spec.add_development_dependency 'minitest-tagz', '1.6.0'
spec.add_development_dependency 'minitest-tagz', '1.7.0'
# XXX: Great idea; useful; but we've found a way to work around what we were
# looking to use this Gem to help with.
# spec.add_development_dependency 'monotime' #, '0.6.1'
spec.add_development_dependency 'pry-byebug', '3.6.0'
spec.add_development_dependency 'pry-byebug', '3.7.0'
spec.add_development_dependency 'pry-doc', '1.0.0'
spec.add_development_dependency 'reek', '5.3.1'
spec.add_development_dependency 'rubocop', '0.64.0'
spec.add_development_dependency 'rubocop', '0.65.0'
spec.add_development_dependency 'simplecov', '0.16.1'
spec.add_development_dependency 'timecop', '0.9.1'
spec.add_development_dependency 'yard', '0.9.18'
Expand Down
4 changes: 2 additions & 2 deletions docs/CryptIdent.html
Original file line number Diff line number Diff line change
Expand Up @@ -2266,9 +2266,9 @@ <h3 class="signature " id="update_session_expiry-instance_method">
</div>

<div id="footer">
Generated on Thu Feb 21 03:27:41 2019 by
Generated on Wed Feb 27 23:57:21 2019 by
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
0.9.18 (ruby-2.6.0).
0.9.18 (ruby-2.6.1).
</div>

</div>
Expand Down
4 changes: 2 additions & 2 deletions docs/_index.html
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ <h2>Namespace Listing A-Z</h2>
</div>

<div id="footer">
Generated on Thu Feb 21 03:27:40 2019 by
Generated on Wed Feb 27 23:57:21 2019 by
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
0.9.18 (ruby-2.6.0).
0.9.18 (ruby-2.6.1).
</div>

</div>
Expand Down
4 changes: 2 additions & 2 deletions docs/file.CODE_OF_CONDUCT.html
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,9 @@ <h2>Attribution</h2>
</div></div>

<div id="footer">
Generated on Thu Feb 21 03:27:40 2019 by
Generated on Wed Feb 27 23:57:21 2019 by
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
0.9.18 (ruby-2.6.0).
0.9.18 (ruby-2.6.1).
</div>

</div>
Expand Down
4 changes: 2 additions & 2 deletions docs/file.HISTORY.html
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ <h2>0.1.0 (18 December 2018)</h2>
</div></div>

<div id="footer">
Generated on Thu Feb 21 03:27:40 2019 by
Generated on Wed Feb 27 23:57:21 2019 by
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
0.9.18 (ruby-2.6.0).
0.9.18 (ruby-2.6.1).
</div>

</div>
Expand Down
4 changes: 2 additions & 2 deletions docs/file.LICENSE.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@
<div id="content"><div id='filecontents'>The MIT License (MIT)<br/><br/>Copyright (c) 2018 Jeff Dickey<br/><br/>Permission is hereby granted, free of charge, to any person obtaining a copy<br/>of this software and associated documentation files (the &quot;Software&quot;), to deal<br/>in the Software without restriction, including without limitation the rights<br/>to use, copy, modify, merge, publish, distribute, sublicense, and/or sell<br/>copies of the Software, and to permit persons to whom the Software is<br/>furnished to do so, subject to the following conditions:<br/><br/>The above copyright notice and this permission notice shall be included in<br/>all copies or substantial portions of the Software.<br/><br/>THE SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR<br/>IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,<br/>FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE<br/>AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER<br/>LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,<br/>OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN<br/>THE SOFTWARE.</div></div>

<div id="footer">
Generated on Thu Feb 21 03:27:40 2019 by
Generated on Wed Feb 27 23:57:21 2019 by
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
0.9.18 (ruby-2.6.0).
0.9.18 (ruby-2.6.1).
</div>

</div>
Expand Down
4 changes: 2 additions & 2 deletions docs/file.README.html
Original file line number Diff line number Diff line change
Expand Up @@ -682,9 +682,9 @@ <h1>Code of Conduct</h1>
</div></div>

<div id="footer">
Generated on Thu Feb 21 03:27:40 2019 by
Generated on Wed Feb 27 23:57:21 2019 by
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
0.9.18 (ruby-2.6.0).
0.9.18 (ruby-2.6.1).
</div>

</div>
Expand Down
4 changes: 2 additions & 2 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -682,9 +682,9 @@ <h1>Code of Conduct</h1>
</div></div>

<div id="footer">
Generated on Thu Feb 21 03:27:40 2019 by
Generated on Wed Feb 27 23:57:21 2019 by
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
0.9.18 (ruby-2.6.0).
0.9.18 (ruby-2.6.1).
</div>

</div>
Expand Down
4 changes: 2 additions & 2 deletions docs/top-level-namespace.html
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ <h2>Defined Under Namespace</h2>
</div>

<div id="footer">
Generated on Thu Feb 21 03:27:40 2019 by
Generated on Wed Feb 27 23:57:21 2019 by
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
0.9.18 (ruby-2.6.0).
0.9.18 (ruby-2.6.1).
</div>

</div>
Expand Down
17 changes: 11 additions & 6 deletions lib/crypt_ident/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,18 @@ module CryptIdent
#
extend Dry::Configurable

def self.included(base)
super
configure do |conf|
conf.repository = conf.user_repo_class.new
conf.guest_user = conf.repository.guest_user
end
end

# Flash index to use for error messages.
setting :error_key, :error, reader: true
# Class to use for :repository, which is the *User* Repository. Oops on that.
setting :user_repo_class, UserRepository, reader: true
setting :guest_user, reader: true
# Hashing cost for BCrypt. Note that each 1-unit increase *doubles* the
# processing time needed to encode/decode a password.
Expand All @@ -27,12 +37,7 @@ module CryptIdent
# Hanami Repository instance to use for accessing User data.
# NOTE: This *does not* have a default. It is the responsibility of the client
# code to *always* assign this before use.
# NOTE: Also, setting the repository causes the `.guest_user` value to be
# assigned. If anyone knows a better way to accomplish this, PRs welcome.
setting(:repository, reader: true) do |value|
config.guest_user = value.guest_user if value
value
end
setting :repository, reader: true
# Password-reset expiry in seconds; defaults to 24 hours.
setting :reset_expiry, (24 * 60 * 60), reader: true
# Authentication session expiry in seconds; defaults to 15 minutes.
Expand Down
6 changes: 3 additions & 3 deletions scripts/build-gem-list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,17 @@ def gem_strings(list)
'minitest-hooks:1.5.0',
'minitest-matchers:1.4.1',
'minitest-reporters:1.3.6',
'minitest-tagz:1.6.0',
'minitest-tagz:1.7.0',
'minitest:5.11.3',
# XXX: A useful Gem, but not needed for what we were considering using it for
# immediately.
# 'monotime:0.6.1',
'pry-byebug:3.6.0',
'pry-byebug:3.7.0',
'pry-doc:1.0.0',
'rake:12.3.2',
'redcarpet:3.4.0',
'reek:5.3.1',
'rubocop:0.64.0',
'rubocop:0.65.0',
'simplecov:0.16.1',
'timecop:0.9.1',
'yard-classmethods:1.0.0',
Expand Down
11 changes: 3 additions & 8 deletions test/crypt_ident/configure_crypt_ident_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,7 @@
expect(CryptIdent.config.token_bytes).must_equal 24
end

describe '.guest_user that returns' do
it 'a Guest User IF the repository has been set' do
old_repo = CryptIdent.config.repository
CryptIdent.config.repository = CryptIdent.config.repository.class.new
expect(CryptIdent.config.guest_user).must_be :guest?
CryptIdent.config.repository = old_repo
end
end # describe '.guest_user that returns'
it '.guest_user that returns a Guest User' do
expect(CryptIdent.config.guest_user).must_be :guest?
end
end # describe 'CryptIdent.config has a reader for' do
5 changes: 0 additions & 5 deletions test/integration/change_password_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,8 @@
let(:profile) { 'Profile content would go here.' }
let(:user_name) { 'J Random User' }

before do
CryptIdent.config.repository = UserRepository.new
end

after do
CryptIdent.config.repository.clear
CryptIdent.config.repository = nil
end

it 'succeeds along the normal path' do
Expand Down
4 changes: 1 addition & 3 deletions test/integration/demo_generate_reset_token_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
#
# ## Cleanup
#
# 6. The Repository is cleared and the Repository object deleted.
# 6. The Repository is cleared.
#
# For a further discussion of the rationale for these tests, see the commentary
# in `register_and_authenticate_test.rb` in this directory.
Expand Down Expand Up @@ -81,7 +81,6 @@ def set_up_user(name, email, profile = 'Profile')
let(:user_name) { 'J Random User' }

before do
CryptIdent.config.repository = UserRepository.new
@the_user = set_up_user(user_name, email, profile)
# Sign In
CryptIdent.sign_in(@the_user, password) do |result|
Expand All @@ -98,7 +97,6 @@ def set_up_user(name, email, profile = 'Profile')
end
@the_user = nil
CryptIdent.config.repository.clear
CryptIdent.config.repository = nil
end

describe 'a value for the Current User of' do
Expand Down
4 changes: 1 addition & 3 deletions test/integration/demo_update_session_expiry_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
# ## Cleanup
#
# 8. The User is Signed Out and its Entity deleted.
# 9. The Repository is cleared and the Repository object deleted.
# 9. The Repository is cleared.
#
# For a further discussion of the rationale for these tests, see the commentary
# in `register_and_authenticate_test.rb` in this directory.
Expand All @@ -54,7 +54,6 @@
let(:user_name) { 'J Random User' }

before do
CryptIdent.config.repository = UserRepository.new
# Register a New User
sign_up_params = { name: user_name, profile: profile, email: email }
@the_user = :unassigned
Expand Down Expand Up @@ -82,7 +81,6 @@
end
@the_user = nil
CryptIdent.config.repository.clear
CryptIdent.config.repository = nil
end

describe 'with an Authenticated User' do
Expand Down
4 changes: 0 additions & 4 deletions test/integration/prove_an_expired_reset_fails_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@
let(:password) { 'A Suitably Entropic Passphrase Goes Here' }
let(:profile) { 'Profile content would go here.' }

before do
CryptIdent.config.repository = UserRepository.new
end

after do
CryptIdent.config.repository.clear
end
Expand Down
4 changes: 0 additions & 4 deletions test/integration/register_and_authenticate_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,6 @@
let(:password) { 'A Suitably Entropic Passphrase Goes Here' }
let(:profile) { 'Profile content would go here.' }

before do
CryptIdent.config.repository = UserRepository.new
end

after do
CryptIdent.config.repository.clear
end
Expand Down
4 changes: 1 addition & 3 deletions test/integration/session_expiry_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
# ## Cleanup
#
# 7. The User is Signed Out and its Entity deleted.
# 8. The Repository is cleared and the Repository object deleted.
# 8. The Repository is cleared.
#
# For a further discussion of the rationale for these tests, see the commentary
# in `register_and_authenticate_test.rb` in this directory.
Expand All @@ -52,7 +52,6 @@
let(:user_name) { 'J Random User' }

before do
CryptIdent.config.repository = UserRepository.new
# Register a New User
sign_up_params = { name: user_name, profile: profile, email: email }
@the_user = :unassigned
Expand Down Expand Up @@ -80,7 +79,6 @@
end
@the_user = nil
CryptIdent.config.repository.clear
CryptIdent.config.repository = nil
end

describe 'with no Authenticated User' do
Expand Down
1 change: 0 additions & 1 deletion test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,3 @@
require 'crypt_ident'

include CryptIdent
CryptIdent.config.repository = UserRepository.new

0 comments on commit 6201b09

Please sign in to comment.