public
Fork of markbates/mack
Description: A Ruby web application framework
Homepage: http://www.mackframework.com
Clone URL: git://github.com/juretta/mack.git
Search Repo:
Release 0.4.2

Conflicts:

  CHANGELOG
  tasks/gem_helper.rb
markbates (author)
Wed Apr 02 10:40:35 -0700 2008
commit  e3adf0dbeaf13d8262de77fc91a0fb3458a0b085
tree    ebc22911dd6993258bdf96b3142f499d20bd339e
parent  49227d9242910362140937683d1a46d7c14c8293 parent  a8be6adae7f5c0fd3850630ffad5204049898cf3
...
 
1
2
3
 
 
4
5
6
...
1
2
3
4
5
6
7
8
9
0
@@ -1,6 +1,9 @@
0
+===0.4.2
0
 * Added config/initializers directory. All files in this directory will be required at start up time.
0
 * Gems can now be required simply using the initializers/gems.rb file and the require_gems method.
0
 * Added gems:list and gems:install rake tasks. The gems:list task will list any gems being required for the application. The gems:install task will install all the gems being required for the application.
0
+* Filters in controllers can now be inherited from parent controller classes.
0
+* gem: mack_ruby_core_extensions 0.1.5
0
 * gem: thing 0.7.1
0
 
0
 ===0.4.1
...
320
321
322
323
 
324
325
326
327
 
 
 
 
 
 
 
 
 
 
 
 
 
328
329
330
...
320
321
322
 
323
324
325
326
 
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
0
@@ -320,11 +320,23 @@
0
         end
0
         
0
         def add_filter(type, meth, options) # :nodoc:
0
- controller_filters[type.to_sym] << Mack::Controller::Filter.new(meth, , options)
0
+ controller_filters[type.to_sym] << Mack::Controller::Filter.new(meth, self, options)
0
         end
0
         
0
         def controller_filters # :nodoc:
0
- @controller_filters = {:before => [], :after => [], :after_render => []} unless @controller_filters
0
+ unless @controller_filters
0
+ @controller_filters = {:before => [], :after => [], :after_render => []}
0
+ # inherit filters from the superclass, if any, to this parent
0
+ sc = self.superclass
0
+ if sc.class_is_a?(Mack::Controller::Base)
0
+ ch = sc.controller_filters
0
+ [:before, :after, :after_render].each do |v|
0
+ @controller_filters[v] << ch[v]
0
+ @controller_filters[v].flatten!
0
+ @controller_filters[v].uniq!
0
+ end
0
+ end
0
+ end
0
           @controller_filters
0
         end
0
         
...
33
34
35
36
 
37
38
 
39
40
41
...
46
47
48
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49
50
51
...
33
34
35
 
36
37
38
39
40
41
42
...
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
0
@@ -33,9 +33,10 @@
0
       attr_reader :filter_method
0
       attr_reader :action_list
0
   
0
- def initialize(filter_method, , action_list = {})
0
+ def initialize(filter_method, klass, action_list = {})
0
         @filter_method = filter_method
0
         clean_action_list(action_list)
0
+ @klass = klass
0
       end
0
   
0
       def run?(action)
0
@@ -46,6 +47,22 @@
0
           return !action_list[:except].include?(action)
0
         end
0
         return false
0
+ end
0
+
0
+ def to_s
0
+ "#{@klass}.#{filter_method}"
0
+ end
0
+
0
+ def ==(other)
0
+ self.to_s == other.to_s
0
+ end
0
+
0
+ def eql?(other)
0
+ self.to_s == other.to_s
0
+ end
0
+
0
+ def hash
0
+ self.to_s.hash
0
       end
0
     
0
       private
...
10
11
12
13
 
14
15
16
...
10
11
12
 
13
14
15
16
0
@@ -10,7 +10,7 @@
0
     self.project = "magrathea"
0
     self.package = "mack"
0
     self.gem_name = "mack"
0
- self.version = "0.4.1.112"
0
+ self.version = "0.4.2"
0
   end
0
   
0
   def gem_name_with_version
...
47
48
49
50
 
51
52
53
...
47
48
49
 
50
51
52
53
0
@@ -47,7 +47,7 @@
0
         s.rdoc_options << '--title' << 'Mack' << '--main' << 'README' << '--line-numbers' << "--inline-source"
0
         
0
         s.add_dependency("rack", "0.3.0")
0
- s.add_dependency("mack_ruby_core_extensions", "0.1.4")
0
+ s.add_dependency("mack_ruby_core_extensions", "0.1.5")
0
         s.add_dependency("application_configuration", "1.2.1")
0
         s.add_dependency("cachetastic", "1.4.2")
0
         s.add_dependency("log4r", "1.0.5")
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
0
@@ -1 +1,62 @@
0
+require File.dirname(__FILE__) + '/../test_helper.rb'
0
+
0
+class FilterInheritanceTest < Test::Unit::TestCase
0
+
0
+ class TopController < Mack::Controller::Base
0
+ before_filter :say_hi
0
+ protected
0
+ def say_hi
0
+ @hello = "hi from TopController"
0
+ end
0
+ end
0
+
0
+ class MiddleController < TopController
0
+ before_filter :say_something
0
+ protected
0
+ def say_something
0
+ @something = "something from MiddleController"
0
+ end
0
+ end
0
+
0
+ class BottomController < MiddleController
0
+ before_filter :say_bye
0
+ def bf_index
0
+ render(:text => "i'm in the bottom controller")
0
+ end
0
+ protected
0
+ def say_bye
0
+ @bye = "bye from BottomController"
0
+ end
0
+ end
0
+
0
+ Mack::Routes.build do |r|
0
+ r.bottom_bf_index "/bottom_bf_index", :controller => "filter_inheritance_test/bottom", :action => :bf_index
0
+ end
0
+
0
+ def test_inheritance
0
+ filters = []
0
+ filters << Mack::Controller::Filter.new(:say_hi, FilterInheritanceTest::TopController, {})
0
+ filters << Mack::Controller::Filter.new(:say_something, FilterInheritanceTest::MiddleController, {})
0
+ filters << Mack::Controller::Filter.new(:say_bye, FilterInheritanceTest::BottomController, {})
0
+ assert_equal filters, BottomController.controller_filters[:before]
0
+ end
0
+
0
+ def test_before_filter_inheritance
0
+ get bottom_bf_index_url
0
+ assert_match "i'm in the bottom controller", response.body
0
+
0
+ hello = assigns(:hello)
0
+ assert_not_nil hello
0
+ assert_equal "hi from TopController", hello
0
+
0
+ something = assigns(:something)
0
+ assert_not_nil something
0
+ assert_equal "something from MiddleController", something
0
+
0
+ bye = assigns(:bye)
0
+ assert_not_nil bye
0
+ assert_equal "bye from BottomController", bye
0
+ end
0
+
0
+end
...
3
4
5
6
 
7
8
9
 
10
11
12
13
 
14
15
16
17
 
18
19
20
21
22
 
23
24
25
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
27
28
...
3
4
5
 
6
7
8
 
9
10
11
12
 
13
14
15
16
 
17
18
19
20
21
 
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
0
@@ -3,26 +3,42 @@
0
 class FilterTest < Test::Unit::TestCase
0
   
0
   def test_run
0
- f = Mack::Controller::Filter.new(:log_action)
0
+ f = Mack::Controller::Filter.new(:log_action, self)
0
     assert f.run?(:my_action)
0
     
0
- f = Mack::Controller::Filter.new(:log_action, , :only => :my_action)
0
+ f = Mack::Controller::Filter.new(:log_action, self, :only => :my_action)
0
     assert f.run?(:my_action)
0
     assert !f.run?(:my_other_action)
0
     
0
- f = Mack::Controller::Filter.new(:log_action, , :except => :my_action)
0
+ f = Mack::Controller::Filter.new(:log_action, self, :except => :my_action)
0
     assert !f.run?(:my_action)
0
     assert f.run?(:my_other_action)
0
     
0
- f = Mack::Controller::Filter.new(:log_action, , :only => [:my_action, :my_other_action])
0
+ f = Mack::Controller::Filter.new(:log_action, self, :only => [:my_action, :my_other_action])
0
     assert f.run?(:my_action)
0
     assert f.run?(:my_other_action)
0
     assert !f.run?(:some_other_action)
0
     
0
- f = Mack::Controller::Filter.new(:log_action, , :except => [:my_action, :my_other_action])
0
+ f = Mack::Controller::Filter.new(:log_action, self, :except => [:my_action, :my_other_action])
0
     assert !f.run?(:my_action)
0
     assert !f.run?(:my_other_action)
0
     assert f.run?(:some_other_action)
0
+ end
0
+
0
+ def test_to_s
0
+ f = Mack::Controller::Filter.new(:log_action, FilterTest)
0
+ puts f
0
+ assert_equal "FilterTest.log_action", f.to_s
0
+ end
0
+
0
+ def test_equals
0
+ assert_equal Mack::Controller::Filter.new(:log_action, FilterTest), Mack::Controller::Filter.new(:log_action, FilterTest)
0
+ end
0
+
0
+ def test_array_uniq
0
+ fs = [Mack::Controller::Filter.new(:log_action, FilterTest), Mack::Controller::Filter.new(:log_action, FilterTest)]
0
+ fs.uniq!
0
+ assert_equal [Mack::Controller::Filter.new(:log_action, FilterTest)], fs
0
   end
0
   
0
   def test_before_all_actions

Comments

    No one has commented yet.