minitest-anonymous_controller 0.1.0 → 0.1.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 +4 -4
- data/README.md +12 -12
- data/lib/minitest/anonymous_controller.rb +2 -2
- data/lib/minitest/anonymous_controller/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8051af49d53786c3cb4193556ca542cccdb0ce46
|
4
|
+
data.tar.gz: e6ac577d4df019196889f1becd706a7f8bbc01d9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a29c7736c64197e1734fe5f659b6921f52111a782c7bc0b58e4515c84c0a604d5cd6e17266d7609cdf1d02362b34a74e08cea790637814f17858be1dce13d04d
|
7
|
+
data.tar.gz: db59536bdddc11e4171f039ba4d26ee2a32ba705cda6d3516ec2c08f7c04b877f56125a5226209eabf48dbd18c9363408b06a6f96bfe467b2644fb4c7065217d
|
data/README.md
CHANGED
@@ -12,19 +12,20 @@ gem 'minitest-anonymous_controller'
|
|
12
12
|
|
13
13
|
## Usage
|
14
14
|
|
15
|
-
The typical use-cases for anonymous controllers are to test filters defined in a base controller.
|
15
|
+
The typical use-cases for anonymous controllers are to test filters defined in a base (sort of abstract) controller.
|
16
16
|
|
17
17
|
__ApplicationController__
|
18
18
|
|
19
19
|
```ruby
|
20
20
|
class ApplicationController < ActionController::Base
|
21
|
+
before_action :require_login
|
21
22
|
|
22
23
|
...
|
23
24
|
|
24
25
|
private
|
25
26
|
|
26
|
-
def
|
27
|
-
redirect_to
|
27
|
+
def require_login # <= Assume if you want to test this filter
|
28
|
+
redirect_to login_url, alert: 'Please login first' unless logged_in?
|
28
29
|
end
|
29
30
|
|
30
31
|
...
|
@@ -32,23 +33,22 @@ class ApplicationController < ActionController::Base
|
|
32
33
|
end
|
33
34
|
```
|
34
35
|
|
35
|
-
|
36
|
+
__ApplicationControllerTest__
|
36
37
|
|
37
38
|
```ruby
|
38
39
|
require 'test_helper'
|
39
40
|
|
40
41
|
class ApplicationControllerTest < ActionDispatch::IntegrationTest
|
41
|
-
|
42
|
-
|
43
|
-
ApplicationController.insert_dummy_action
|
42
|
+
ApplicationController.insert_dummy_action # <= Insert dummy action to the controller
|
44
43
|
|
45
44
|
test 'should redirect someone without logging in to login page' do
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
assert_redirected_to login_url
|
50
|
-
end
|
45
|
+
get dummy_action_url # <= Now you can test the filter via the dummy action
|
46
|
+
assert_equal 'Please login first', flash[:alert]
|
47
|
+
assert_redirected_to root_url
|
51
48
|
end
|
49
|
+
|
50
|
+
...
|
51
|
+
|
52
52
|
end
|
53
53
|
```
|
54
54
|
|
@@ -6,7 +6,7 @@ module Minitest
|
|
6
6
|
# Define dummy action for testing in ApplicationController class context
|
7
7
|
self.class_eval do
|
8
8
|
def dummy_action
|
9
|
-
|
9
|
+
head :ok
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
@@ -21,4 +21,4 @@ module Minitest
|
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
-
ActionController::Base.extend Minitest::AnonymousController
|
24
|
+
ActionController::Base.send(:extend, Minitest::AnonymousController)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: minitest-anonymous_controller
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hirofumi Wakasugi
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-05-
|
11
|
+
date: 2016-05-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|