rspectacular 0.44.0 → 0.45.0

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: 16290f005d85c1b14f8b364276c5eff983449a49
4
- data.tar.gz: 3d8faceafa6d96441ce907d2669fd294122afa8d
3
+ metadata.gz: b46bb75a27b3e57faa420401cfe19266d008341c
4
+ data.tar.gz: 5a183e749aefb7beda610d16f700749c520ac94d
5
5
  SHA512:
6
- metadata.gz: f3c57d8ce4854d0a9d92b11d248a11c1d95be407cb16260f8d13b9e74ad3b71baaa23c835191d0a5ea97b165d90a36e11bf85f74d8a43fd25788adb65a718188
7
- data.tar.gz: eb06ec87a8b7cb1ca3940ea1e64b6fec354e9e3708d7c3e1038cf2e7cfbcfa1a02d8310460ab9b1438937c07da6743e80b850646b8d5db53e9e0de7251e10f46
6
+ metadata.gz: 83c157792a0da5a854e637a2541002ddd7881c2b4f12160d7f50e7c993b3d4c4effbad4174c589e71fc5e359045eccc695f1a9cdc7e622d958bb98a663b8ceab
7
+ data.tar.gz: 3c9d62b91f2177644602fa48ac6b761812baeb8d5ccea6fbb612d99a7813c3c4c8cc2563e2fd547b642cfe22867da3446dbf7fdd06b3f403023a438a0f81dd92
@@ -1,73 +1,69 @@
1
1
  RSpec.configure do |config|
2
2
  config.around(:each, mock_auth: lambda { |v| !!v }) do |example|
3
- options = example.metadata[:mock_auth]
3
+ options = example.metadata[:mock_auth]
4
4
 
5
- klass = case options
6
- when TrueClass
7
- User
8
- when Hash
9
- options[:class] || User
10
- else
11
- options
12
- end
5
+ klass = case options
6
+ when TrueClass
7
+ User
8
+ when Hash
9
+ options[:class] || User
10
+ else
11
+ options
12
+ end
13
13
 
14
- underscored_class_name = klass.
15
- name[/.*::(\w+)\z/, 1].
16
- gsub(/([a-z])([A-Z])/, '\1_\2').
17
- downcase
14
+ underscored_class_name = klass.
15
+ name[/(?:.*::)?(\w+)\z/, 1].
16
+ gsub(/([a-z])([A-Z])/, '\1_\2').
17
+ downcase
18
18
 
19
- current_class_method = if options.is_a?(Hash) && options[:method]
20
- options[:method]
21
- else
22
- :"current_#{underscored_class_name}"
23
- end
19
+ current_class_method = if options.is_a?(Hash) && options[:method]
20
+ options[:method]
21
+ else
22
+ :"current_#{underscored_class_name}"
23
+ end
24
24
 
25
- instance = if options.is_a?(Hash) && options[:strategy] == :instance
26
- klass.new
27
- else
28
- FactoryGirl.create(underscored_class_name.to_sym)
29
- end
25
+ instance = if options.is_a?(Hash) && options[:strategy] == :instance
26
+ klass.new
27
+ else
28
+ FactoryGirl.create(underscored_class_name.to_sym)
29
+ end
30
30
 
31
- inferred_auth_method = if options.is_a?(Hash) && options[:authentication_method]
32
- options[:authentication_method]
33
- else
34
- :"authenticate_#{underscored_class_name}!"
35
- end
31
+ inferred_auth_method = if options.is_a?(Hash) && options[:authentication_method]
32
+ options[:authentication_method]
33
+ else
34
+ :"authenticate_#{underscored_class_name}!"
35
+ end
36
36
 
37
- described_class_instance = described_class.new
37
+ authentication_controller_class = if example.metadata[:type] == :controller
38
+ described_class
39
+ else
40
+ ApplicationController
41
+ end
38
42
 
39
- authentication_method = if described_class_instance.respond_to?(inferred_auth_method, true)
40
- inferred_auth_method
41
- elsif described_class_instance.respond_to?(:authenticate, true)
42
- :authenticate
43
- end
43
+ authentication_controller_instance = authentication_controller_class.new
44
44
 
45
- if options[:status] == :unauthorized
46
- described_class.send(:define_method, authentication_method) { false }
47
- else
48
- described_class.send(:define_method, authentication_method) { true }
49
- end
45
+ authentication_method = if authentication_controller_instance.respond_to?(inferred_auth_method, true)
46
+ inferred_auth_method
47
+ elsif authentication_controller_instance.respond_to?(:authenticate, true)
48
+ :authenticate
49
+ end
50
50
 
51
- example.example_group_instance.class.let(current_class_method) do
52
- if options[:status] == :unauthorized
53
- nil
54
- else
55
- instance
56
- end
57
- end
51
+ authentication_successful = if options.is_a?(Hash) && options.has_key?(:status)
52
+ options[:status] == :authorized
53
+ else
54
+ true
55
+ end
58
56
 
59
- described_class.send(:define_method, current_class_method) do
60
- if options[:status] == :unauthorized
61
- nil
62
- else
63
- instance
64
- end
65
- end
57
+ authentication_result = authentication_successful ? instance : nil
58
+
59
+ authentication_controller_class.send(:define_method, authentication_method) { authentication_successful }
60
+ authentication_controller_class.send(:define_method, current_class_method) { authentication_result }
61
+ authentication_controller_class.send(:helper_method, current_class_method)
62
+ example.example_group_instance.class.let(current_class_method) { authentication_result }
66
63
 
67
64
  example.run
68
65
 
69
- described_class.send(:remove_method, current_class_method)
70
- described_class.send(:remove_method, authentication_method)
66
+ authentication_controller_class.send(:remove_method, current_class_method)
71
67
 
72
68
  unless options.is_a?(Hash) && options[:strategy] == :instance
73
69
  instance.delete
@@ -1,3 +1,3 @@
1
1
  module RSpectacular
2
- VERSION = '0.44.0'
2
+ VERSION = '0.45.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspectacular
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.44.0
4
+ version: 0.45.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - jfelchner
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-15 00:00:00.000000000 Z
11
+ date: 2014-06-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec