@@ -29,5 +29,46 @@ class TestClass; end;
29
29
end
30
30
end
31
31
32
+ describe "before actions" do
33
+ class BeforeActionController < WebsocketRails ::BaseController
34
+ before_action { self . before_array << :all }
35
+ before_action ( :only => :only ) { self . before_array << :only_1 }
36
+ before_action ( :only => :except ) { self . before_array << :only_2 }
37
+ before_action ( :only => [ :main , :only ] ) { self . before_array << :only_3 }
38
+ before_action ( :only => [ :except , :only ] ) { self . before_array << :only_4 }
39
+ before_action ( :except => :except ) { self . before_array << :except_1 }
40
+ before_action ( :except => :only ) { self . before_array << :except_2 }
41
+ before_action ( :except => [ :main , :except ] ) { self . before_array << :except_3 }
42
+ before_action ( :except => [ :only , :except ] ) { self . before_array << :except_4 }
43
+
44
+ attr_accessor :before_array
45
+
46
+ def initialize
47
+ @before_array = [ ]
48
+ end
49
+ def main ; end
50
+ def only ; end
51
+ def except ; end
52
+ end
53
+
54
+ let ( :controller ) { BeforeActionController . new }
55
+ it 'should handle before_action with no args' do
56
+ controller . instance_variable_set :@_action_name , 'main'
57
+ controller . process_action ( :main , nil )
58
+ controller . before_array . should == [ :all , :only_3 , :except_1 , :except_2 , :except_4 ]
59
+ end
60
+
61
+ it 'should handle before_action with :only flag' do
62
+ controller . instance_variable_set :@_action_name , 'only'
63
+ controller . process_action ( :only , nil )
64
+ controller . before_array . should == [ :all , :only_1 , :only_3 , :only_4 , :except_1 , :except_3 ]
65
+ end
66
+
67
+ it 'should handle before_action with :except flag' do
68
+ controller . instance_variable_set :@_action_name , 'except'
69
+ controller . process_action ( :except , nil )
70
+ controller . before_array . should == [ :all , :only_2 , :only_4 , :except_2 ]
71
+ end
72
+ end
32
73
end
33
74
end
0 commit comments