simon_says 0.3.0.alpha.5 → 0.3.0.alpha.6

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
  SHA256:
3
- metadata.gz: 3abfdc67fe4a00391a5a167d425db7cda7e855c316b00a724d1f452114af6c68
4
- data.tar.gz: c14a9de36943db2c6059b8ea6a41063ad99a704a0964c38600a99ebb3687a170
3
+ metadata.gz: 1dd25d86d02036d68ac186879af756e9544030505f5658b3f7be735f124b2138
4
+ data.tar.gz: 46e3848c3c5f0c211bdef99a9debc35bcafe96736c9fb480e231c7d923681a55
5
5
  SHA512:
6
- metadata.gz: ac1930289951138e3bee481d6f09a44b3f5b3878e4b19685167614add7ceff33e1ebb409ec67f382dd3985ba9970373ff3ddac316b97b82443c383d16bc3a7b6
7
- data.tar.gz: 9be3fd968195386735821c2ab17b02ce59de685788ad54cc5ded492368e6c2bc2e92f36f77a4b61c1924a78d052ca7b1d0283770957ed8702651f89968839108
6
+ metadata.gz: fc17c0dfd266893558bfbe1897fee2b475cde52d9a465495e8b4790a0d90f11ed499689e9f0444fc2e2f39b7ff55e7882caf830cccdc91e2073df0dca855be26
7
+ data.tar.gz: d55a0a2cb7f053505dde303d53b700fb63db896bfb085f951eac341daf9eac986fd6b6ca08d4a7bda54b56d53e7dfa2bdbce08c6aad101907b2b93f19f52ff55
data/.travis.yml CHANGED
@@ -6,7 +6,7 @@ before_install:
6
6
  install: bundle install --jobs=3 --retry=3
7
7
  rvm:
8
8
  - "2.6.3"
9
- - "2.5.4"
9
+ - "2.5.5"
10
10
  - "2.4.6"
11
11
  script:
12
12
  - bundle exec rake test
data/bin/console ADDED
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+
6
+ $: << File.expand_path('../lib', __dir__) if ENV['DEBUG'] == 'true'
7
+ require 'simon_says'
8
+
9
+ # You can add fixtures and/or initialization code here to make experimenting
10
+ # with your gem easier. You can also use a different console, if you like.
11
+
12
+ # (If you use this, don't forget to add pry to your Gemfile!)
13
+ # require "pry"
14
+ # Pry.start
15
+
16
+ require 'irb'
17
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,16 @@
1
+ en:
2
+ simon_says:
3
+ denied:
4
+ warning: Access denied;
5
+ array_connector:
6
+ two_words_connector: ' or '
7
+ last_word_connector: ', or '
8
+
9
+ required:
10
+ one: '%{list} is required'
11
+ other: '%{list} are required'
12
+
13
+ explanation:
14
+ zero: '%{warning} %{required}, however you have no %{role_attr} set'
15
+ one: '%{warning} %{required}, however you have %{actual} %{role_attr} set'
16
+ other: '%{warning} %{required}, however you have %{actual} %{role_attr} set'
data/lib/simon_says.rb CHANGED
@@ -1,5 +1,18 @@
1
1
  require 'active_support'
2
+ require 'active_support/core_ext'
2
3
 
3
4
  require "simon_says/version"
4
5
  require "simon_says/roleable"
5
6
  require "simon_says/authorizer"
7
+
8
+ begin
9
+ require 'i18n' unless defined? I18n
10
+
11
+ if defined? I18n
12
+ I18n.load_path += Dir[File.join(
13
+ File.expand_path(File.join('..', 'config', 'locales'), __dir__), '*.yml'
14
+ )]
15
+ end
16
+ rescue LoadError
17
+ # do nothing
18
+ end
@@ -3,12 +3,30 @@ module SimonSays
3
3
  extend ActiveSupport::Concern
4
4
 
5
5
  class Denied < StandardError
6
- # @private
7
- def initialize(as, required, actual)
8
- # TODO i18n for err message (as should be singluarized with 1 flag)
9
- current_access = actual.empty? ? 'empty' : actual.join(', ')
6
+ attr_reader :role_attr
10
7
 
11
- super "Access denied; #{required * ', '} #{as} is required. Current access is #{current_access}"
8
+ # @private
9
+ def initialize(role_attr, required, actual)
10
+ @role_attr = role_attr
11
+
12
+ if defined? I18n
13
+ required_text = I18n.translate(
14
+ 'simon_says.denied.required',
15
+ count: required.size,
16
+ list: required.to_sentence(I18n.translate('simon_says.denied.array_connector'))
17
+ )
18
+
19
+ super I18n.translate(
20
+ 'simon_says.denied.explanation',
21
+ count: actual.size,
22
+ role_attr: @role_attr,
23
+ warning: I18n.translate('simon_says.denied.warning'),
24
+ actual: actual.to_sentence,
25
+ required: required_text
26
+ )
27
+ else
28
+ super "Access denied; required=#{required.inspect} current_access=#{actual.inspect}"
29
+ end
12
30
  end
13
31
  end
14
32
 
@@ -1,3 +1,3 @@
1
1
  module SimonSays
2
- VERSION = '0.3.0.alpha.5'
2
+ VERSION = '0.3.0.alpha.6'
3
3
  end
@@ -0,0 +1,75 @@
1
+ require 'test_helper'
2
+
3
+ class AuthorizerAccessDeniedTest < ActiveSupport::TestCase
4
+ test 'one required and none set' do
5
+ err = SimonSays::Authorizer::Denied.new(:roles, %w(foo), [])
6
+
7
+ assert_equal 'Access denied; foo is required, however you have no roles set', err.message
8
+ end
9
+
10
+ test 'two required and none set' do
11
+ err = SimonSays::Authorizer::Denied.new(:roles, %w(foo bar), [])
12
+
13
+ assert_equal 'Access denied; foo or bar are required, however you have no roles set', err.message
14
+ end
15
+
16
+ test 'three required and none set' do
17
+ err = SimonSays::Authorizer::Denied.new(:roles, %w(foo bar baz), [])
18
+
19
+ assert_equal 'Access denied; foo, bar, or baz are required, however you have no roles set', err.message
20
+ end
21
+
22
+ test 'one required and one set' do
23
+ err = SimonSays::Authorizer::Denied.new(:roles, %w(foo), %w(qux))
24
+
25
+ assert_equal 'Access denied; foo is required, however you have qux roles set', err.message
26
+ end
27
+
28
+ test 'two required and one set' do
29
+ err = SimonSays::Authorizer::Denied.new(:roles, %w(foo bar), %w(qux))
30
+
31
+ assert_equal 'Access denied; foo or bar are required, however you have qux roles set', err.message
32
+ end
33
+
34
+ test 'three required and one set' do
35
+ err = SimonSays::Authorizer::Denied.new(:roles, %w(foo bar baz), %w(qux))
36
+
37
+ assert_equal 'Access denied; foo, bar, or baz are required, however you have qux roles set', err.message
38
+ end
39
+
40
+ test 'one required and two set' do
41
+ err = SimonSays::Authorizer::Denied.new(:roles, %w(foo), %w(qux quux))
42
+
43
+ assert_equal 'Access denied; foo is required, however you have qux and quux roles set', err.message
44
+ end
45
+
46
+ test 'two required and two set' do
47
+ err = SimonSays::Authorizer::Denied.new(:roles, %w(foo bar), %w(qux quux))
48
+
49
+ assert_equal 'Access denied; foo or bar are required, however you have qux and quux roles set', err.message
50
+ end
51
+
52
+ test 'three required and two set' do
53
+ err = SimonSays::Authorizer::Denied.new(:roles, %w(foo bar baz), %w(qux quux))
54
+
55
+ assert_equal 'Access denied; foo, bar, or baz are required, however you have qux and quux roles set', err.message
56
+ end
57
+
58
+ test 'one required and three set' do
59
+ err = SimonSays::Authorizer::Denied.new(:roles, %w(foo), %w(qux quux quuz))
60
+
61
+ assert_equal 'Access denied; foo is required, however you have qux, quux, and quuz roles set', err.message
62
+ end
63
+
64
+ test 'two required and three set' do
65
+ err = SimonSays::Authorizer::Denied.new(:roles, %w(foo bar), %w(qux quux quuz))
66
+
67
+ assert_equal 'Access denied; foo or bar are required, however you have qux, quux, and quuz roles set', err.message
68
+ end
69
+
70
+ test 'three required and three set' do
71
+ err = SimonSays::Authorizer::Denied.new(:roles, %w(foo bar baz), %w(qux quux quuz))
72
+
73
+ assert_equal 'Access denied; foo, bar, or baz are required, however you have qux, quux, and quuz roles set', err.message
74
+ end
75
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simon_says
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0.alpha.5
4
+ version: 0.3.0.alpha.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Coyne
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2019-07-15 00:00:00.000000000 Z
13
+ date: 2019-07-16 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport
@@ -106,7 +106,9 @@ description: This gem is a simple, easy-to-use declarative role-based access con
106
106
  system for Rails
107
107
  email:
108
108
  - mikeycgto@gmail.com
109
- executables: []
109
+ executables:
110
+ - console
111
+ - setup
110
112
  extensions: []
111
113
  extra_rdoc_files: []
112
114
  files:
@@ -120,6 +122,9 @@ files:
120
122
  - README.md
121
123
  - Rakefile
122
124
  - SimonSays.png
125
+ - bin/console
126
+ - bin/setup
127
+ - config/locales/en.yml
123
128
  - lib/generators/active_record/simon_says_generator.rb
124
129
  - lib/generators/active_record/templates/migration.rb
125
130
  - lib/simon_says.rb
@@ -217,6 +222,7 @@ files:
217
222
  - test/rails_app/test/test_helper.rb
218
223
  - test/rails_app/vendor/assets/javascripts/.keep
219
224
  - test/rails_app/vendor/assets/stylesheets/.keep
225
+ - test/simon_says/authorizer_denied_test.rb
220
226
  - test/simon_says/authorizer_test.rb
221
227
  - test/simon_says/roleable_test.rb
222
228
  - test/simon_says_test.rb
@@ -335,6 +341,7 @@ test_files:
335
341
  - test/rails_app/test/test_helper.rb
336
342
  - test/rails_app/vendor/assets/javascripts/.keep
337
343
  - test/rails_app/vendor/assets/stylesheets/.keep
344
+ - test/simon_says/authorizer_denied_test.rb
338
345
  - test/simon_says/authorizer_test.rb
339
346
  - test/simon_says/roleable_test.rb
340
347
  - test/simon_says_test.rb