Skip to content

Commit 388368e

Browse files
committed
Convert controller's action_name to a string to get AbstractController::Callbacks (before_action) working properly [fixes websocket-rails#150]
1 parent 1c1eaec commit 388368e

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# WebsocketRails Change Log
22

3+
## UNRELEASED
4+
5+
* Convert controller's `action_name` to a string to get AbstractController::Callbacks (`before_action`) working properly [fixes #150]
6+
37
## Version 0.6.2
48

59
September 8 2013

lib/websocket_rails/controller_factory.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def set_controller_store(controller)
4747
end
4848

4949
def set_action_name(controller, method)
50-
set_ivar :@_action_name, controller, method
50+
set_ivar :@_action_name, controller, method.to_s
5151
end
5252

5353
def set_ivar(ivar, object, value)

spec/unit/base_controller_spec.rb

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,46 @@ class TestClass; end;
2929
end
3030
end
3131

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
3273
end
3374
end

0 commit comments

Comments
 (0)