freshy_filter_chain 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/LICENSE +19 -0
- data/README.markdown +34 -0
- data/Rakefile +28 -0
- data/VERSION +1 -0
- data/freshy_filter_chain.gemspec +66 -0
- data/init.rb +1 -0
- data/lib/freshy_filter_chain.rb +57 -0
- data/tests/append_after_test.rb +42 -0
- data/tests/append_around_test.rb +42 -0
- data/tests/append_before_test.rb +53 -0
- data/tests/deep_class_hierarchy_test.rb +61 -0
- data/tests/normal_filter_chain_test.rb +56 -0
- data/tests/prepend_after_test.rb +42 -0
- data/tests/prepend_around_test.rb +42 -0
- data/tests/prepend_before_test.rb +42 -0
- data/tests/skip_after_test.rb +43 -0
- data/tests/skip_before_test.rb +43 -0
- data/tests/skip_test.rb +43 -0
- data/tests/test_helper.rb +42 -0
- metadata +104 -0
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
pkg
|
data/LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2009 Ryan L. Bell
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
THE SOFTWARE.
|
data/README.markdown
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# Freshy Filter Chains: Get yourself a freshy!
|
2
|
+
|
3
|
+
Freshy gives your ActionController filter chains more consistent inheritence behavior, regardless of the order the code is loaded.
|
4
|
+
|
5
|
+
## Install
|
6
|
+
|
7
|
+
As a plugin:
|
8
|
+
|
9
|
+
./script/plugin instal git://github.com/kofno/freshy_filter_chain.git
|
10
|
+
|
11
|
+
As a gem:
|
12
|
+
|
13
|
+
gem install freshy_filter_chain
|
14
|
+
|
15
|
+
And don't forget to add the gem to your rails config
|
16
|
+
|
17
|
+
config.gem "freshy_filter_chain"
|
18
|
+
|
19
|
+
## Links
|
20
|
+
|
21
|
+
* [Wiki](http://wiki.github.com/kofno/freshy_filter_chain)
|
22
|
+
* [Issues](http://github.com/kofno/freshy_filter_chain/issues)
|
23
|
+
|
24
|
+
## Why would I need this?
|
25
|
+
|
26
|
+
You may not. In general, the Rails community tends to treat plugins a extensions to Rails, and application code builds on Rails and the plugins. For this scenario, the default filter chain inheritence is fine.
|
27
|
+
|
28
|
+
Of course, the other use of plugins is to extend the application's functionality. When writing an extension, its quite common to re-open the application controller and update the filters. In this scenario, depending on how the code loads, extension filters may not be inherited by subclasses. This is exactly the scenario freshy was created to fix.
|
29
|
+
|
30
|
+
[More information on inheritable attributes and filter chains](http://wiki.github.com/kofno/freshy_filter_chain/rails-inheritable-attributes)
|
31
|
+
|
32
|
+
|
33
|
+
|
34
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'rake/testtask'
|
2
|
+
|
3
|
+
task :default => :test
|
4
|
+
|
5
|
+
Rake::TestTask.new do |t|
|
6
|
+
t.libs << "test"
|
7
|
+
t.test_files = FileList['tests/*_test.rb']
|
8
|
+
end
|
9
|
+
|
10
|
+
begin
|
11
|
+
require 'jeweler'
|
12
|
+
Jeweler::Tasks.new do |gemspec|
|
13
|
+
gemspec.name = "freshy_filter_chain"
|
14
|
+
gemspec.summary = "'get a freshy' filter chain"
|
15
|
+
gemspec.description = "Enhances Rails filter chains so they refresh should a superclass change impact a subclass"
|
16
|
+
gemspec.email = "ryan.l.bell@gmail.com"
|
17
|
+
gemspec.homepage = "http://github.com/kofno/freshy_filter_chain"
|
18
|
+
gemspec.authors = ["Ryan L. Bell"]
|
19
|
+
|
20
|
+
gemspec.add_development_dependency "shoulda", "= 2.10.2"
|
21
|
+
gemspec.add_development_dependency "redgreen", "= 1.2.2"
|
22
|
+
|
23
|
+
gemspec.add_dependency "actionpack", ">= 2.3.0"
|
24
|
+
end
|
25
|
+
Jeweler::GemcutterTasks.new
|
26
|
+
rescue LoadError
|
27
|
+
puts "Jeweler not available. Install with: gem install jeweler"
|
28
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
@@ -0,0 +1,66 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{freshy_filter_chain}
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Ryan L. Bell"]
|
12
|
+
s.date = %q{2009-12-13}
|
13
|
+
s.description = %q{Enhances Rails filter chains so they refresh should a superclass change impact a subclass}
|
14
|
+
s.email = %q{ryan.l.bell@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.markdown"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".gitignore",
|
21
|
+
"LICENSE",
|
22
|
+
"README.markdown",
|
23
|
+
"Rakefile",
|
24
|
+
"VERSION",
|
25
|
+
"freshy_filter_chain.gemspec",
|
26
|
+
"init.rb",
|
27
|
+
"lib/freshy_filter_chain.rb",
|
28
|
+
"tests/append_after_test.rb",
|
29
|
+
"tests/append_around_test.rb",
|
30
|
+
"tests/append_before_test.rb",
|
31
|
+
"tests/deep_class_hierarchy_test.rb",
|
32
|
+
"tests/normal_filter_chain_test.rb",
|
33
|
+
"tests/prepend_after_test.rb",
|
34
|
+
"tests/prepend_around_test.rb",
|
35
|
+
"tests/prepend_before_test.rb",
|
36
|
+
"tests/skip_after_test.rb",
|
37
|
+
"tests/skip_before_test.rb",
|
38
|
+
"tests/skip_test.rb",
|
39
|
+
"tests/test_helper.rb"
|
40
|
+
]
|
41
|
+
s.homepage = %q{http://github.com/kofno/freshy_filter_chain}
|
42
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
43
|
+
s.require_paths = ["lib"]
|
44
|
+
s.rubygems_version = %q{1.3.5}
|
45
|
+
s.summary = %q{'get a freshy' filter chain}
|
46
|
+
|
47
|
+
if s.respond_to? :specification_version then
|
48
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
49
|
+
s.specification_version = 3
|
50
|
+
|
51
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
52
|
+
s.add_development_dependency(%q<shoulda>, ["= 2.10.2"])
|
53
|
+
s.add_development_dependency(%q<redgreen>, ["= 1.2.2"])
|
54
|
+
s.add_runtime_dependency(%q<actionpack>, [">= 2.3.0"])
|
55
|
+
else
|
56
|
+
s.add_dependency(%q<shoulda>, ["= 2.10.2"])
|
57
|
+
s.add_dependency(%q<redgreen>, ["= 1.2.2"])
|
58
|
+
s.add_dependency(%q<actionpack>, [">= 2.3.0"])
|
59
|
+
end
|
60
|
+
else
|
61
|
+
s.add_dependency(%q<shoulda>, ["= 2.10.2"])
|
62
|
+
s.add_dependency(%q<redgreen>, ["= 1.2.2"])
|
63
|
+
s.add_dependency(%q<actionpack>, [">= 2.3.0"])
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'freshy_filter_chain'
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'action_controller'
|
2
|
+
|
3
|
+
module ActionController
|
4
|
+
|
5
|
+
class Base
|
6
|
+
class << self
|
7
|
+
def self.record_filter_chain_ops_for(*filter_methods)
|
8
|
+
filter_methods.each do |meth|
|
9
|
+
class_eval <<-CODE
|
10
|
+
def #{meth}_with_recording(*filters, &block)
|
11
|
+
filter_operation = lambda { #{meth}_without_recording(*filters, &block) }
|
12
|
+
filter_operation.call
|
13
|
+
recorded_filter_chain_ops << filter_operation
|
14
|
+
refresh_subclass_filter_chains
|
15
|
+
end
|
16
|
+
alias_method_chain meth, :recording
|
17
|
+
CODE
|
18
|
+
end
|
19
|
+
end
|
20
|
+
record_filter_chain_ops_for :append_before_filter, :before_filter
|
21
|
+
record_filter_chain_ops_for :append_after_filter, :after_filter
|
22
|
+
record_filter_chain_ops_for :append_around_filter, :around_filter
|
23
|
+
record_filter_chain_ops_for :prepend_before_filter, :prepend_after_filter, :prepend_around_filter
|
24
|
+
record_filter_chain_ops_for :skip_before_filter, :skip_after_filter, :skip_filter
|
25
|
+
|
26
|
+
def refresh_subclass_filter_chains
|
27
|
+
immediate_subclasses.each do |child|
|
28
|
+
child.write_inheritable_attribute('filter_chain', filter_chain.dup)
|
29
|
+
child.replay_filter_chain_ops
|
30
|
+
child.refresh_subclass_filter_chains
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def replay_filter_chain_ops
|
35
|
+
recorded_filter_chain_ops.each { |filter_chain_op| filter_chain_op.call }
|
36
|
+
end
|
37
|
+
|
38
|
+
def immediate_subclasses
|
39
|
+
@immediate_subclasses ||= []
|
40
|
+
end
|
41
|
+
|
42
|
+
def inherited_with_subclass_recording(child)
|
43
|
+
immediate_subclasses << child
|
44
|
+
inherited_without_subclass_recording(child)
|
45
|
+
end
|
46
|
+
alias_method_chain :inherited, :subclass_recording
|
47
|
+
|
48
|
+
def recorded_filter_chain_ops
|
49
|
+
@recorded_filter_chain_ops ||= []
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'test_helper')
|
2
|
+
|
3
|
+
class AfterFiltersTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
class ApplicationController < ::ActionController::Base
|
6
|
+
after_filter :application_filter
|
7
|
+
end
|
8
|
+
|
9
|
+
class ChildController < ApplicationController
|
10
|
+
after_filter :child_filter
|
11
|
+
end
|
12
|
+
|
13
|
+
ApplicationController.class_eval do
|
14
|
+
after_filter :after_thought
|
15
|
+
end
|
16
|
+
|
17
|
+
context "The ApplicationController" do
|
18
|
+
setup do
|
19
|
+
@app_filter_chain = ApplicationController.filter_chain
|
20
|
+
end
|
21
|
+
|
22
|
+
should "have only its own filters" do
|
23
|
+
assert_contains_filter @app_filter_chain, :application_filter
|
24
|
+
assert_contains_filter @app_filter_chain, :after_thought
|
25
|
+
assert_equal 2, @app_filter_chain.size
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
context "The ChildController" do
|
31
|
+
setup do
|
32
|
+
@child_filter_chain = ChildController.filter_chain
|
33
|
+
end
|
34
|
+
|
35
|
+
should "should have its own filter, plus the inherited ones" do
|
36
|
+
assert_contains_filter @child_filter_chain, :application_filter
|
37
|
+
assert_contains_filter @child_filter_chain, :after_thought
|
38
|
+
assert_contains_filter @child_filter_chain, :child_filter
|
39
|
+
assert_equal 3, @child_filter_chain.size
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'test_helper')
|
2
|
+
|
3
|
+
class AppendAroundTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
class ApplicationController < ::ActionController::Base
|
6
|
+
around_filter :application_filter
|
7
|
+
end
|
8
|
+
|
9
|
+
class ChildController < ApplicationController
|
10
|
+
around_filter :child_filter
|
11
|
+
end
|
12
|
+
|
13
|
+
ApplicationController.class_eval do
|
14
|
+
around_filter :after_thought
|
15
|
+
end
|
16
|
+
|
17
|
+
context "The ApplicationController" do
|
18
|
+
setup do
|
19
|
+
@app_filter_chain = ApplicationController.filter_chain
|
20
|
+
end
|
21
|
+
|
22
|
+
should "have only its own filters" do
|
23
|
+
assert_contains_filter @app_filter_chain, :application_filter
|
24
|
+
assert_contains_filter @app_filter_chain, :after_thought
|
25
|
+
assert_equal 2, @app_filter_chain.size
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
context "The ChildController" do
|
31
|
+
setup do
|
32
|
+
@child_filter_chain = ChildController.filter_chain
|
33
|
+
end
|
34
|
+
|
35
|
+
should "should have its own filter, plus the inherited ones" do
|
36
|
+
assert_contains_filter @child_filter_chain, :application_filter
|
37
|
+
assert_contains_filter @child_filter_chain, :after_thought
|
38
|
+
assert_contains_filter @child_filter_chain, :child_filter
|
39
|
+
assert_equal 3, @child_filter_chain.size
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'test_helper')
|
2
|
+
|
3
|
+
class ReopenParentControllerFilterChainTest < Test::Unit::TestCase
|
4
|
+
# build our test classes
|
5
|
+
class ApplicationController < ::ActionController::Base
|
6
|
+
before_filter :application_filter
|
7
|
+
def application_filter; puts "something"; end
|
8
|
+
end
|
9
|
+
|
10
|
+
class ChildController < ApplicationController
|
11
|
+
before_filter :child_filter
|
12
|
+
def child_filter; puts "from the mouths of babes";end
|
13
|
+
end
|
14
|
+
|
15
|
+
# now we reload
|
16
|
+
ApplicationController.class_eval do
|
17
|
+
before_filter :new_stuff_baby
|
18
|
+
def new_stuff_baby; puts "yeah!"; end
|
19
|
+
end
|
20
|
+
|
21
|
+
def app_filter_chain
|
22
|
+
ApplicationController.filter_chain
|
23
|
+
end
|
24
|
+
|
25
|
+
def child_filter_chain
|
26
|
+
ChildController.filter_chain
|
27
|
+
end
|
28
|
+
|
29
|
+
context "The ApplicationController" do
|
30
|
+
|
31
|
+
should "have a two filters" do
|
32
|
+
assert_equal 2, app_filter_chain.size
|
33
|
+
end
|
34
|
+
|
35
|
+
should "have a filter named :new_stuff_baby" do
|
36
|
+
assert_contains_filter app_filter_chain, :new_stuff_baby
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
context "The ChildController" do
|
42
|
+
|
43
|
+
should "have a three filters" do
|
44
|
+
assert_equal 3, child_filter_chain.size
|
45
|
+
end
|
46
|
+
|
47
|
+
should "have a filter named :new_stuff_baby" do
|
48
|
+
assert_contains_filter child_filter_chain, :new_stuff_baby
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'test_helper')
|
2
|
+
|
3
|
+
class DeepClassHierarchyTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
class ApplicationController < ::ActionController::Base
|
6
|
+
after_filter :application_filter
|
7
|
+
end
|
8
|
+
|
9
|
+
class ChildController < ApplicationController
|
10
|
+
before_filter :child_filter
|
11
|
+
skip_filter :after_thought
|
12
|
+
end
|
13
|
+
|
14
|
+
ApplicationController.class_eval do
|
15
|
+
around_filter :after_thought
|
16
|
+
before_filter { puts "poo" }
|
17
|
+
end
|
18
|
+
|
19
|
+
class SubChildController < ChildController
|
20
|
+
append_before_filter :sub_filter
|
21
|
+
skip_after_filter :application_filter
|
22
|
+
end
|
23
|
+
|
24
|
+
ChildController.class_eval do
|
25
|
+
append_after_filter :late_arrival
|
26
|
+
append_around_filter :gets_around
|
27
|
+
prepend_before_filter :line_cutter
|
28
|
+
end
|
29
|
+
|
30
|
+
context "The ApplicationController" do
|
31
|
+
setup do
|
32
|
+
@app_filter_chain = ApplicationController.filter_chain
|
33
|
+
end
|
34
|
+
|
35
|
+
should "have only its own filters" do
|
36
|
+
assert_chain_order [:after_thought, :a_proc, :application_filter], @app_filter_chain
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
context "The ChildController" do
|
42
|
+
setup do
|
43
|
+
@child_filter_chain = ChildController.filter_chain
|
44
|
+
end
|
45
|
+
|
46
|
+
should "should have its own filter, plus the inherited ones" do
|
47
|
+
assert_chain_order [:line_cutter, :a_proc, :child_filter, :gets_around, :application_filter, :late_arrival], @child_filter_chain
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
context "The SubChildController" do
|
52
|
+
setup do
|
53
|
+
@sub_child_filter_chain = SubChildController.filter_chain
|
54
|
+
end
|
55
|
+
|
56
|
+
should "should have its own filter, plus the inherited ones" do
|
57
|
+
assert_chain_order [:line_cutter, :a_proc, :child_filter, :gets_around, :sub_filter, :late_arrival], @sub_child_filter_chain
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'test_helper')
|
2
|
+
|
3
|
+
# captures normal, healthy filter_chain behavior
|
4
|
+
class NormalFilterChainTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
# build our test classes
|
7
|
+
class ApplicationController < ::ActionController::Base
|
8
|
+
before_filter :application_filter
|
9
|
+
def application_filter; puts "something"; end
|
10
|
+
end
|
11
|
+
|
12
|
+
class ChildController < ApplicationController
|
13
|
+
before_filter :child_filter
|
14
|
+
def child_filter; puts "from the mouths of babes";end
|
15
|
+
end
|
16
|
+
|
17
|
+
def app_filter_chain
|
18
|
+
ApplicationController.filter_chain
|
19
|
+
end
|
20
|
+
|
21
|
+
def child_filter_chain
|
22
|
+
ChildController.filter_chain
|
23
|
+
end
|
24
|
+
|
25
|
+
context "The ApplicationController" do
|
26
|
+
|
27
|
+
should "inherited filters be the same" do
|
28
|
+
assert_equal app_filter_chain.first, child_filter_chain.first
|
29
|
+
end
|
30
|
+
|
31
|
+
should 'have one filter' do
|
32
|
+
assert_equal 1, app_filter_chain.size
|
33
|
+
end
|
34
|
+
|
35
|
+
should 'have a filter named :application_filter' do
|
36
|
+
assert_contains_filter app_filter_chain, :application_filter
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context "The ChildController" do
|
41
|
+
|
42
|
+
should 'have two filters' do
|
43
|
+
assert_equal 2, child_filter_chain.size
|
44
|
+
end
|
45
|
+
|
46
|
+
should 'have a filter named :application_filter' do
|
47
|
+
assert_contains_filter child_filter_chain, :application_filter
|
48
|
+
end
|
49
|
+
|
50
|
+
should 'have a filter named :child_filter' do
|
51
|
+
assert_contains_filter child_filter_chain, :child_filter
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'test_helper')
|
2
|
+
|
3
|
+
class PrependAfterTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
class ApplicationController < ::ActionController::Base
|
6
|
+
prepend_after_filter :application_filter
|
7
|
+
end
|
8
|
+
|
9
|
+
class ChildController < ApplicationController
|
10
|
+
prepend_after_filter :child_filter
|
11
|
+
end
|
12
|
+
|
13
|
+
ApplicationController.class_eval do
|
14
|
+
prepend_after_filter :after_thought
|
15
|
+
end
|
16
|
+
|
17
|
+
context "The ApplicationController" do
|
18
|
+
setup do
|
19
|
+
@app_filter_chain = ApplicationController.filter_chain
|
20
|
+
end
|
21
|
+
|
22
|
+
should "have only its own filters" do
|
23
|
+
assert_contains_filter @app_filter_chain, :application_filter
|
24
|
+
assert_contains_filter @app_filter_chain, :after_thought
|
25
|
+
assert_equal 2, @app_filter_chain.size
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
context "The ChildController" do
|
31
|
+
setup do
|
32
|
+
@child_filter_chain = ChildController.filter_chain
|
33
|
+
end
|
34
|
+
|
35
|
+
should "should have its own filter, plus the inherited ones" do
|
36
|
+
assert_contains_filter @child_filter_chain, :application_filter
|
37
|
+
assert_contains_filter @child_filter_chain, :after_thought
|
38
|
+
assert_contains_filter @child_filter_chain, :child_filter
|
39
|
+
assert_equal 3, @child_filter_chain.size
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'test_helper')
|
2
|
+
|
3
|
+
class PrependAroundTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
class ApplicationController < ::ActionController::Base
|
6
|
+
prepend_around_filter :application_filter
|
7
|
+
end
|
8
|
+
|
9
|
+
class ChildController < ApplicationController
|
10
|
+
prepend_around_filter :child_filter
|
11
|
+
end
|
12
|
+
|
13
|
+
ApplicationController.class_eval do
|
14
|
+
prepend_around_filter :after_thought
|
15
|
+
end
|
16
|
+
|
17
|
+
context "The ApplicationController" do
|
18
|
+
setup do
|
19
|
+
@app_filter_chain = ApplicationController.filter_chain
|
20
|
+
end
|
21
|
+
|
22
|
+
should "have only its own filters" do
|
23
|
+
assert_contains_filter @app_filter_chain, :application_filter
|
24
|
+
assert_contains_filter @app_filter_chain, :after_thought
|
25
|
+
assert_equal 2, @app_filter_chain.size
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
context "The ChildController" do
|
31
|
+
setup do
|
32
|
+
@child_filter_chain = ChildController.filter_chain
|
33
|
+
end
|
34
|
+
|
35
|
+
should "should have its own filter, plus the inherited ones" do
|
36
|
+
assert_contains_filter @child_filter_chain, :application_filter
|
37
|
+
assert_contains_filter @child_filter_chain, :after_thought
|
38
|
+
assert_contains_filter @child_filter_chain, :child_filter
|
39
|
+
assert_equal 3, @child_filter_chain.size
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'test_helper')
|
2
|
+
|
3
|
+
class PrependBeforeTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
class ApplicationController < ::ActionController::Base
|
6
|
+
prepend_before_filter :application_filter
|
7
|
+
end
|
8
|
+
|
9
|
+
class ChildController < ApplicationController
|
10
|
+
prepend_before_filter :child_filter
|
11
|
+
end
|
12
|
+
|
13
|
+
ApplicationController.class_eval do
|
14
|
+
prepend_before_filter :after_thought
|
15
|
+
end
|
16
|
+
|
17
|
+
context "The ApplicationController" do
|
18
|
+
setup do
|
19
|
+
@app_filter_chain = ApplicationController.filter_chain
|
20
|
+
end
|
21
|
+
|
22
|
+
should "have only its own filters" do
|
23
|
+
assert_contains_filter @app_filter_chain, :application_filter
|
24
|
+
assert_contains_filter @app_filter_chain, :after_thought
|
25
|
+
assert_equal 2, @app_filter_chain.size
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
context "The ChildController" do
|
31
|
+
setup do
|
32
|
+
@child_filter_chain = ChildController.filter_chain
|
33
|
+
end
|
34
|
+
|
35
|
+
should "should have its own filter, plus the inherited ones" do
|
36
|
+
assert_contains_filter @child_filter_chain, :application_filter
|
37
|
+
assert_contains_filter @child_filter_chain, :after_thought
|
38
|
+
assert_contains_filter @child_filter_chain, :child_filter
|
39
|
+
assert_equal 3, @child_filter_chain.size
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'test_helper')
|
2
|
+
|
3
|
+
class SkipAfterTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
class ApplicationController < ::ActionController::Base
|
6
|
+
after_filter :application_filter
|
7
|
+
end
|
8
|
+
|
9
|
+
class ChildController < ApplicationController
|
10
|
+
after_filter :child_filter
|
11
|
+
skip_after_filter :after_thought
|
12
|
+
end
|
13
|
+
|
14
|
+
ApplicationController.class_eval do
|
15
|
+
after_filter :after_thought
|
16
|
+
end
|
17
|
+
|
18
|
+
context "The ApplicationController" do
|
19
|
+
setup do
|
20
|
+
@app_filter_chain = ApplicationController.filter_chain
|
21
|
+
end
|
22
|
+
|
23
|
+
should "have only its own filters" do
|
24
|
+
assert_contains_filter @app_filter_chain, :application_filter
|
25
|
+
assert_contains_filter @app_filter_chain, :after_thought
|
26
|
+
assert_equal 2, @app_filter_chain.size
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
context "The ChildController" do
|
32
|
+
setup do
|
33
|
+
@child_filter_chain = ChildController.filter_chain
|
34
|
+
end
|
35
|
+
|
36
|
+
should "should have its own filter, plus the inherited ones" do
|
37
|
+
assert_contains_filter @child_filter_chain, :application_filter
|
38
|
+
assert_filter_absent @child_filter_chain, :after_thought
|
39
|
+
assert_contains_filter @child_filter_chain, :child_filter
|
40
|
+
assert_equal 2, @child_filter_chain.size
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'test_helper')
|
2
|
+
|
3
|
+
class SkipBeforeTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
class ApplicationController < ::ActionController::Base
|
6
|
+
before_filter :application_filter
|
7
|
+
end
|
8
|
+
|
9
|
+
class ChildController < ApplicationController
|
10
|
+
before_filter :child_filter
|
11
|
+
skip_before_filter :after_thought
|
12
|
+
end
|
13
|
+
|
14
|
+
ApplicationController.class_eval do
|
15
|
+
before_filter :after_thought
|
16
|
+
end
|
17
|
+
|
18
|
+
context "The ApplicationController" do
|
19
|
+
setup do
|
20
|
+
@app_filter_chain = ApplicationController.filter_chain
|
21
|
+
end
|
22
|
+
|
23
|
+
should "have only its own filters" do
|
24
|
+
assert_contains_filter @app_filter_chain, :application_filter
|
25
|
+
assert_contains_filter @app_filter_chain, :after_thought
|
26
|
+
assert_equal 2, @app_filter_chain.size
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
context "The ChildController" do
|
32
|
+
setup do
|
33
|
+
@child_filter_chain = ChildController.filter_chain
|
34
|
+
end
|
35
|
+
|
36
|
+
should "should have its own filter, plus the inherited ones" do
|
37
|
+
assert_contains_filter @child_filter_chain, :application_filter
|
38
|
+
assert_filter_absent @child_filter_chain, :after_thought
|
39
|
+
assert_contains_filter @child_filter_chain, :child_filter
|
40
|
+
assert_equal 2, @child_filter_chain.size
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/tests/skip_test.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'test_helper')
|
2
|
+
|
3
|
+
class SkipTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
class ApplicationController < ::ActionController::Base
|
6
|
+
after_filter :application_filter
|
7
|
+
end
|
8
|
+
|
9
|
+
class ChildController < ApplicationController
|
10
|
+
before_filter :child_filter
|
11
|
+
skip_filter :after_thought
|
12
|
+
end
|
13
|
+
|
14
|
+
ApplicationController.class_eval do
|
15
|
+
around_filter :after_thought
|
16
|
+
end
|
17
|
+
|
18
|
+
context "The ApplicationController" do
|
19
|
+
setup do
|
20
|
+
@app_filter_chain = ApplicationController.filter_chain
|
21
|
+
end
|
22
|
+
|
23
|
+
should "have only its own filters" do
|
24
|
+
assert_contains_filter @app_filter_chain, :application_filter
|
25
|
+
assert_contains_filter @app_filter_chain, :after_thought
|
26
|
+
assert_equal 2, @app_filter_chain.size
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
context "The ChildController" do
|
32
|
+
setup do
|
33
|
+
@child_filter_chain = ChildController.filter_chain
|
34
|
+
end
|
35
|
+
|
36
|
+
should "should have its own filter, plus the inherited ones" do
|
37
|
+
assert_contains_filter @child_filter_chain, :application_filter
|
38
|
+
assert_filter_absent @child_filter_chain, :after_thought
|
39
|
+
assert_contains_filter @child_filter_chain, :child_filter
|
40
|
+
assert_equal 2, @child_filter_chain.size
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'test/unit'
|
3
|
+
|
4
|
+
# tests are now awesome
|
5
|
+
gem 'shoulda'
|
6
|
+
require 'shoulda'
|
7
|
+
|
8
|
+
# pretty colors
|
9
|
+
gem 'redgreen'
|
10
|
+
require 'redgreen'
|
11
|
+
|
12
|
+
# need some rails bits
|
13
|
+
gem 'actionpack'
|
14
|
+
require 'action_controller'
|
15
|
+
|
16
|
+
#my bits
|
17
|
+
require 'freshy_filter_chain'
|
18
|
+
|
19
|
+
# some useful assertions
|
20
|
+
|
21
|
+
def assert_contains_filter(collection, filter_name)
|
22
|
+
if collection.any? {|filter| filter.method == filter_name}
|
23
|
+
assert_block { true }
|
24
|
+
else
|
25
|
+
failure_msg = "#{filter_name.inspect} could not be found in #{collection.inspect}"
|
26
|
+
assert_block(failure_msg) { false }
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def assert_filter_absent(collection, filter_name)
|
31
|
+
if collection.any? {|filter| filter.method == filter_name}
|
32
|
+
failure_msg = "#{filter_name.inspect} was unexpectedly found in #{collection.inspect}"
|
33
|
+
assert_block(failure_msg) { false }
|
34
|
+
else
|
35
|
+
assert_block { true }
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def assert_chain_order(expected, chain)
|
40
|
+
chain_symbols = chain.map(&:method).map{ |f| f.is_a?(Proc) ? :a_proc : f.to_sym }
|
41
|
+
assert_equal expected, chain_symbols
|
42
|
+
end
|
metadata
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: freshy_filter_chain
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ryan L. Bell
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-12-13 00:00:00 -05:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: shoulda
|
17
|
+
type: :development
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - "="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 2.10.2
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: redgreen
|
27
|
+
type: :development
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.2.2
|
34
|
+
version:
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: actionpack
|
37
|
+
type: :runtime
|
38
|
+
version_requirement:
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 2.3.0
|
44
|
+
version:
|
45
|
+
description: Enhances Rails filter chains so they refresh should a superclass change impact a subclass
|
46
|
+
email: ryan.l.bell@gmail.com
|
47
|
+
executables: []
|
48
|
+
|
49
|
+
extensions: []
|
50
|
+
|
51
|
+
extra_rdoc_files:
|
52
|
+
- LICENSE
|
53
|
+
- README.markdown
|
54
|
+
files:
|
55
|
+
- .gitignore
|
56
|
+
- LICENSE
|
57
|
+
- README.markdown
|
58
|
+
- Rakefile
|
59
|
+
- VERSION
|
60
|
+
- freshy_filter_chain.gemspec
|
61
|
+
- init.rb
|
62
|
+
- lib/freshy_filter_chain.rb
|
63
|
+
- tests/append_after_test.rb
|
64
|
+
- tests/append_around_test.rb
|
65
|
+
- tests/append_before_test.rb
|
66
|
+
- tests/deep_class_hierarchy_test.rb
|
67
|
+
- tests/normal_filter_chain_test.rb
|
68
|
+
- tests/prepend_after_test.rb
|
69
|
+
- tests/prepend_around_test.rb
|
70
|
+
- tests/prepend_before_test.rb
|
71
|
+
- tests/skip_after_test.rb
|
72
|
+
- tests/skip_before_test.rb
|
73
|
+
- tests/skip_test.rb
|
74
|
+
- tests/test_helper.rb
|
75
|
+
has_rdoc: true
|
76
|
+
homepage: http://github.com/kofno/freshy_filter_chain
|
77
|
+
licenses: []
|
78
|
+
|
79
|
+
post_install_message:
|
80
|
+
rdoc_options:
|
81
|
+
- --charset=UTF-8
|
82
|
+
require_paths:
|
83
|
+
- lib
|
84
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: "0"
|
89
|
+
version:
|
90
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: "0"
|
95
|
+
version:
|
96
|
+
requirements: []
|
97
|
+
|
98
|
+
rubyforge_project:
|
99
|
+
rubygems_version: 1.3.5
|
100
|
+
signing_key:
|
101
|
+
specification_version: 3
|
102
|
+
summary: "'get a freshy' filter chain"
|
103
|
+
test_files: []
|
104
|
+
|