rspeckled 0.0.51 → 0.0.52

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: 145c053a261f643418d067a8ed08911418c5180a89b4e92a87d50d6372433dee
4
- data.tar.gz: d9cee2b150b4ba9cebfee7ff87c5e367e49be512681e504ac41dd20399a22330
3
+ metadata.gz: 3c7c4c3a8c27c061df89836be60d67bc39bc6a4649081abd77d20716468d4305
4
+ data.tar.gz: 6acb4108f10f6927ea5cd464940e934e7afc928ad80adabeb2c61a86dc9a2403
5
5
  SHA512:
6
- metadata.gz: 02eb91705dc2dd4466a2e03e844c24bbbc011975b9c3049e385eeaa6a759d03d3d6495d7044e0910b3a58fa015436376a0f2cd51266cea9f92a0a8c22343bc1a
7
- data.tar.gz: 83b41741e95b88da06163d6a925b3350336901b241074006650ed65c752bf7d52307c5ef5866c04f2d30f2d587d1e401efea372d912567eaa0016893e4bcf863
6
+ metadata.gz: ea06ffceb8fd2440c658f9283c43014d6a431efb3665cb33d95168757b8fb06437c782f68e124fa6a6da3a2d71f403b9a945b1c99999762796f1cda0c3eb4c1f
7
+ data.tar.gz: 8a12e63b970c674a218a94202bcf09f98e40fce93a0cb441f7a2f60dc29ab26498a2cbd50f5aacd7bd0fef5d4cf4c993977d7efb7a0558abd97a25f2cf3c7c32
checksums.yaml.gz.sig CHANGED
Binary file
@@ -1,128 +1,100 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # rubocop:disable Layout/IndentHash
3
4
  RSpec.configure do |config|
4
5
  config.around(:each, :mock_auth => lambda { |v| !!v }) do |example|
5
- options = example.metadata[:mock_auth]
6
-
7
- authentication_type = if options.is_a?(Hash) && options[:type]
8
- options[:type]
6
+ options = if example.metadata[:mock_auth].is_a?(Hash)
7
+ example.metadata[:mock_auth]
9
8
  else
10
- :json_web_token
9
+ {
10
+ :token => {
11
+ :roles => example.metadata[:mock_auth],
12
+ },
13
+ }
11
14
  end
12
15
 
13
- klass = case options
14
- when TrueClass
15
- User
16
- when Hash
17
- options[:class] || described_class
18
- .name[/(.*?)::/, 1]
19
- .concat('::User')
20
- .constantize
21
- else
22
- options
23
- end
16
+ options[:class] ||= described_class
17
+ .name[/\A([^:]+)::/, 1]
18
+ .concat('::User')
19
+ .constantize
24
20
 
25
- underscored_class_name = klass
21
+ class_name_underscored = options[:class]
26
22
  .name[/(?:.*::)?(\w+)\z/, 1]
27
23
  .gsub(/([a-z])([A-Z])/, '\1_\2')
28
24
  .downcase
29
25
 
30
- current_class_method = if options.is_a?(Hash) && options[:method]
31
- options[:method] || :current_user
32
- else
33
- :"current_#{underscored_class_name}"
34
- end
35
-
36
- class_instance_overrides = if options.is_a?(Hash) && options[:class_instance_overrides]
37
- options[:class_instance_overrides]
38
- else
39
- {}
40
- end
41
-
42
- class_instance_traits = if options.is_a?(Hash) && options[:class_instance_traits]
43
- options[:class_instance_traits]
44
- else
45
- {}
26
+ defaults = {
27
+ :type => :json_web_token,
28
+ :authentication_method => :"authenticate_#{class_name_underscored}!",
29
+ :class_instance_overrides => {},
30
+ :class_instance_traits => {},
31
+ :method => :"current_#{class_name_underscored}",
32
+ :strategy => :factory,
33
+ :successful? => true,
34
+ :token => {
35
+ :roles => 'standard',
36
+ },
37
+ }
38
+
39
+ options = defaults.deep_merge(options)
40
+
41
+ instance = case options[:strategy]
42
+ when :factory
43
+ FactoryBot.create(class_name_underscored.to_sym, *options[:class_instance_traits], options[:class_instance_overrides])
44
+ when :instance
45
+ options[:class].new(options[:class_instance_overrides])
46
46
  end
47
47
 
48
- instance = if options.is_a?(Hash) && options[:strategy] == :instance
49
- klass.new(class_instance_overrides)
50
- else
51
- FactoryBot.create(underscored_class_name.to_sym, *class_instance_traits, class_instance_overrides)
52
- end
48
+ authentication_result = options[:successful?] ? instance : nil
53
49
 
54
- inferred_auth_method = if options.is_a?(Hash) && options[:authentication_method]
50
+ case options[:type]
51
+ when :standard
52
+ authentication_controller_class = (example.metadata[:type] == :controller) ? described_class : ApplicationController
53
+ authentication_controller_instance = authentication_controller_class.new
54
+ authentication_method = if authentication_controller_instance.respond_to?(options[:authentication_method], true)
55
55
  options[:authentication_method]
56
- else
57
- :"authenticate_#{underscored_class_name}!"
58
- end
59
-
60
- authentication_controller_class = if example.metadata[:type] == :controller
61
- described_class
62
- else
63
- ApplicationController
56
+ elsif authentication_controller_instance.respond_to?(:authenticate, true)
57
+ :authenticate
64
58
  end
65
59
 
66
- authentication_controller_instance = authentication_controller_class.new
67
-
68
- authentication_successful = if options.is_a?(Hash) && options.has_key?(:status)
69
- options[:status] == :authorized
70
- else
71
- true
72
- end
73
-
74
- authentication_result = authentication_successful ? instance : nil
75
-
76
- if authentication_type == :standard
77
- authentication_method = if authentication_controller_instance.respond_to?(inferred_auth_method, true)
78
- inferred_auth_method
79
- elsif authentication_controller_instance.respond_to?(:authenticate, true)
80
- :authenticate
81
- end
82
-
83
- authentication_controller_class.__send__(:define_method, authentication_method) { authentication_successful }
84
- authentication_controller_class.__send__(:define_method, current_class_method) { authentication_result }
85
- authentication_controller_class.__send__(:helper_method, current_class_method)
86
- example.example_group_instance.class.let(current_class_method) { authentication_result }
60
+ authentication_controller_class.__send__(:define_method, authentication_method) { options[:successful?] }
61
+ authentication_controller_class.__send__(:define_method, options[:method]) { authentication_result }
62
+ authentication_controller_class.__send__(:helper_method, options[:method])
63
+ example.example_group_instance.class.let(options[:method]) { authentication_result }
87
64
 
88
65
  example.run
89
66
 
90
- authentication_controller_class.__send__(:remove_method, current_class_method)
91
- elsif authentication_type == :json_web_token
92
- @token_data = if options.is_a?(Hash) && options[:data]
93
- options[:data]
94
- else
95
- [
96
- {
97
- 'aid' => options[:audience_id] || instance['account_id'] || instance['id'],
98
- 'aud' => options[:audience] || instance.class.name,
99
- 'exp' => options[:expired_at] || 1.day.from_now.utc.to_i,
100
- 'iat' => Time.now.utc.to_i,
101
- 'iss' => options[:issuer] || 'rspeckled',
102
- 'jti' => SecureRandom.uuid,
103
- 'nbf' => 1.day.ago.utc.to_i,
104
- 'rol' => options[:roles] || 'standard',
105
- 'sid' => options[:subject_id],
106
- 'sub' => options[:subject],
107
- },
108
- {
109
- 'typ' => 'JWT',
110
- 'cty' => 'application/json-web-token',
111
- },
112
- ]
113
- end
114
-
115
- example.example_group_instance.class.let(current_class_method) { authentication_result }
67
+ authentication_controller_class.__send__(:remove_method, options[:method])
68
+ when :json_web_token
69
+ @token_data = [
70
+ {
71
+ 'aid' => options[:token][:audience_id] || instance['account_id'] || instance['id'],
72
+ 'aud' => options[:token][:audience] || instance.class.name,
73
+ 'exp' => options[:token][:expired_at] || 1.day.from_now.utc.to_i,
74
+ 'iat' => options[:token][:issued_at] || Time.now.utc.to_i,
75
+ 'iss' => options[:token][:issuer] || 'rspeckled',
76
+ 'jti' => options[:token][:token_id] || SecureRandom.uuid,
77
+ 'nbf' => options[:token][:not_before] || 1.day.ago.utc.to_i,
78
+ 'rol' => options[:token][:roles] || 'standard',
79
+ 'sid' => options[:token][:subject_id],
80
+ 'sub' => options[:token][:subject],
81
+ },
82
+ {
83
+ 'typ' => 'JWT',
84
+ 'cty' => 'application/json-web-token',
85
+ },
86
+ ]
87
+
88
+ example.example_group_instance.class.let(options[:method]) { authentication_result }
116
89
 
117
90
  example.run
118
- else
119
- fail ArgumentError, 'You must specify a valid type for the :mock_auth metadata'
120
91
  end
121
92
 
122
- instance.delete unless options.is_a?(Hash) && options[:strategy] == :instance
93
+ instance.delete unless options[:strategy] == :instance
123
94
  end
124
95
 
125
96
  config.before(:each, :mock_auth => lambda { |v| !!v }) do |_example|
126
97
  request.env['X_JSON_WEB_TOKEN'] = @token_data
127
98
  end
128
99
  end
100
+ # rubocop:enable Layout/IndentHash
@@ -0,0 +1,58 @@
1
+ # frozen_string_literal: true
2
+
3
+ ##############################################################################
4
+ # Dox Plugin
5
+ ##############################################################################
6
+
7
+ begin
8
+ require 'dox'
9
+ require 'pathname'
10
+
11
+ RSpec.configure do |config|
12
+ config.after(:each, :dox) do |example|
13
+ example.metadata[:request] = request
14
+ example.metadata[:response] = response
15
+ end
16
+ end
17
+
18
+ api_docs_folder = Pathname.pwd.join('docs', 'api')
19
+ api_docs_header = api_docs_folder.join('header.md')
20
+
21
+ api_docs_folder.mkpath
22
+
23
+ api_docs_folder.glob('**/*.rb').each { |f| require f }
24
+
25
+ titleized_application_name = Rails
26
+ .application
27
+ .class
28
+ .name
29
+ .split('::')[0]
30
+ .titleize
31
+
32
+ http_settings_file = Pathname.pwd.join('config', 'settings', 'http.yml')
33
+
34
+ host = if http_settings_file.exist?
35
+ http_settings = YAML.load(http_settings_file.read) # rubocop:disable Security/YAMLLoad
36
+
37
+ http_settings['production']['http']['base_url']
38
+ else
39
+ 'http://api.lvh.me:5000'
40
+ end
41
+
42
+ unless api_docs_header.exist?
43
+ api_docs_header.write(<<~HEREDOC, :mode => 'w')
44
+ FORMAT: 1A
45
+ HOST: #{host}
46
+
47
+ # #{titleized_application_name}
48
+
49
+ HEREDOC
50
+ end
51
+
52
+ Dox.configure do |config|
53
+ config.header_file_path = api_docs_header
54
+ config.desc_folder_path = api_docs_folder
55
+ # config.headers_whitelist = ['Accept', 'X-Auth-Token']
56
+ end
57
+ rescue LoadError
58
+ end
@@ -8,6 +8,7 @@ require 'rspeckled/plugins/carrier_wave'
8
8
  require 'rspeckled/plugins/capybara'
9
9
  require 'rspeckled/plugins/database_cleaner'
10
10
  require 'rspeckled/plugins/devise'
11
+ require 'rspeckled/plugins/dox'
11
12
  require 'rspeckled/plugins/elasticsearch'
12
13
  require 'rspeckled/plugins/email'
13
14
  require 'rspeckled/plugins/factory_bot'
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rspeckled
4
+ class Railtie < Rails::Railtie
5
+ rake_tasks do
6
+ load 'rspeckled/tasks/documentation.rake'
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ ##############################################################################
4
+ # Documentation
5
+ ##############################################################################
6
+
7
+ namespace :documentation do
8
+ namespace :api do
9
+ desc 'Generate API documentation markdown'
10
+ task :blueprint do
11
+ require 'rspec/core/rake_task'
12
+
13
+ RSpec::Core::RakeTask.new(:api_docs) do |t|
14
+ t.pattern = 'spec/controllers/**/v1/**/*_spec.rb'
15
+ t.rspec_opts = '--format="Dox::Formatter" --out="./docs/api/index.apib" --order="defined" --tag="dox"'
16
+ end
17
+
18
+ Rake::Task['api_docs'].invoke
19
+ end
20
+
21
+ task :json => :blueprint do
22
+ `apib2swagger --input='./docs/api/index.apib' --output='./docs/api/index.json'`
23
+ end
24
+
25
+ task :yaml => :blueprint do
26
+ `apib2swagger --yaml --input='./docs/api/index.apib' --output='./docs/api/index.yaml'`
27
+ end
28
+
29
+ task :html => :json do
30
+ `redoc-cli bundle --output='./docs/api/index.html' './docs/api/index.json'`
31
+ end
32
+
33
+ task :preview => :html do
34
+ `open './docs/api/index.html'`
35
+ end
36
+
37
+ task :publish => :blueprint do
38
+ `apiary publish --path='./docs/api/apispec.apib' --api-name='#{Rails.application.name}'`
39
+ end
40
+ end
41
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Rspeckled
4
- VERSION = '0.0.51'
4
+ VERSION = '0.0.52'
5
5
  end
data/lib/rspeckled.rb CHANGED
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rspeckled/rails/railtie' if defined?(Rails)
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspeckled
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.51
4
+ version: 0.0.52
5
5
  platform: ruby
6
6
  authors:
7
7
  - thegranddesign
@@ -31,7 +31,7 @@ cert_chain:
31
31
  Y2GAoHKstmfIVhc4XHOPpmTd2o/C29O9oaRgjrkfQEhF/KvJ/PhoV5hvokzsCyI5
32
32
  iUeXPfvrGD/itYIBCgk+fnzyQQ4QtE5hTQaWQ3o2
33
33
  -----END CERTIFICATE-----
34
- date: 2018-05-25 00:00:00.000000000 Z
34
+ date: 2018-05-30 00:00:00.000000000 Z
35
35
  dependencies:
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rspec
@@ -119,6 +119,7 @@ files:
119
119
  - lib/rspeckled/plugins/code_climate.rb
120
120
  - lib/rspeckled/plugins/database_cleaner.rb
121
121
  - lib/rspeckled/plugins/devise.rb
122
+ - lib/rspeckled/plugins/dox.rb
122
123
  - lib/rspeckled/plugins/elasticsearch.rb
123
124
  - lib/rspeckled/plugins/email.rb
124
125
  - lib/rspeckled/plugins/factory_bot.rb
@@ -145,6 +146,7 @@ files:
145
146
  - lib/rspeckled/plugins/vcr.rb
146
147
  - lib/rspeckled/plugins/webmock.rb
147
148
  - lib/rspeckled/plugins/wisper.rb
149
+ - lib/rspeckled/rails/railtie.rb
148
150
  - lib/rspeckled/reporting.rb
149
151
  - lib/rspeckled/reporting/example.rb
150
152
  - lib/rspeckled/reporting/outputs/csv.rb
@@ -156,6 +158,7 @@ files:
156
158
  - lib/rspeckled/spec_helpers/rails_engine.rb
157
159
  - lib/rspeckled/spec_helpers/rspeckled.rb
158
160
  - lib/rspeckled/support.rb
161
+ - lib/rspeckled/tasks/documentation.rake
159
162
  - lib/rspeckled/vcr_matchers/uri_without_trailing_id.rb
160
163
  - lib/rspeckled/version.rb
161
164
  homepage: https://github.com/thekompanee/rspeckled
metadata.gz.sig CHANGED
Binary file