Changeset 648
- Timestamp:
- 09/18/07 07:34:49 (1 year ago)
- Files:
-
- trunk/lib/merb/controller.rb (modified) (2 diffs)
- trunk/lib/merb/core_ext/string.rb (modified) (2 diffs)
- trunk/lib/merb/request.rb (modified) (1 diff)
- trunk/specs/merb/merb_core_ext_spec.rb (modified) (1 diff)
- trunk/specs/merb/merb_dispatch_spec.rb (modified) (1 diff)
- trunk/specs/merb/merb_request_spec.rb (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/lib/merb/controller.rb
r640 r648 8 8 # puts that into params as well. 9 9 class Controller < AbstractController 10 cattr_accessor :_subclasses 11 self._subclasses = [] 10 12 11 13 class_inheritable_accessor :_session_id_key, :_session_expiry … … 18 20 19 21 class << self 22 def inherited(klass) 23 _subclasses << klass.to_s 24 super 25 end 26 20 27 def callable_actions 21 28 @callable_actions ||= Set.new(public_instance_methods - hidden_actions) trunk/lib/merb/core_ext/string.rb
r595 r648 2 2 3 3 class String 4 class InvalidPathConversion < Exception; end 4 5 5 6 def escape_regexp … … 22 23 input = StringScanner.new(self) 23 24 until input.eos? 24 if input.scan(/([a-z][a-zA-Z\d]*)(_|$ )/)25 if input.scan(/([a-z][a-zA-Z\d]*)(_|$|\/)/) 25 26 new_string << input[1].capitalize 26 elsif input.scan(/([a-z][a-zA-Z\d]*)\//) 27 new_string << input[1].capitalize << "::" 27 new_string << "::" if input[2] == '/' 28 else 29 raise InvalidPathConversion, self 28 30 end 29 31 end trunk/lib/merb/request.rb
r640 r648 126 126 127 127 def controller_class 128 path = "#{MERB_ROOT}/app/controllers/#{controller_name}.rb"129 128 cnt = controller_name.to_const_string 130 129 131 if ! File.exist?(path)132 raise ControllerExceptions::NotFound, " Bad controller! #{cnt}"133 end unless $TESTING130 if !Controller._subclasses.include?(cnt) 131 raise ControllerExceptions::NotFound, "Controller '#{cnt}' not found" 132 end 134 133 135 134 begin trunk/specs/merb/merb_core_ext_spec.rb
r517 r648 394 394 "snake_case/path/with_several_parts".to_const_string.should == "SnakeCase::Path::WithSeveralParts" 395 395 end 396 end 396 397 it "should raise an error rather than freeze when trying to convert bad Paths/12Like/-this" do 398 Timeout::timeout(1) do 399 lambda do 400 "Paths/12Like/-this".to_const_string 401 end.should raise_error(String::InvalidPathConversion) 402 end.should_not raise_error(Timeout::Error) 403 end 404 end trunk/specs/merb/merb_dispatch_spec.rb
r640 r648 35 35 it "should handle request: GET /foo/bar and return Foo#bar" do 36 36 controller, action = request(:get, '/foo/bar') 37 e = controller.params[:exception] 37 38 controller.class.should == Foo 38 39 action.should == "bar" trunk/specs/merb/merb_request_spec.rb
r643 r648 2 2 3 3 describe Merb::Request do 4 include Mocha::SetupAndTeardown 5 6 class GoodPosts < Merb::Controller 7 def show() end 8 end 4 9 5 10 before(:all) do 11 setup_stubs 6 12 @in = Merb::Test::FakeRequest.new 13 Merb::Request.any_instance.stubs(:route_params).returns({}) 14 end 15 16 after(:all) do 17 teardown_stubs 7 18 end 8 19 … … 171 182 request.params[:title].should == "hello" 172 183 end 184 185 it "should not raise a NotFound exception when the controller class exists" do 186 @in['REQUEST_URI'] = "/good_posts/show/1" 187 @in['REQUEST_METHOD'] = 'GET' 188 @in['CONTENT_TYPE'] = "application/x-www-form-urlencoded" 189 request = Merb::Request.new(@in) 190 request.expects(:controller_name).returns("good_posts") 191 request.controller_name.should == "good_posts" 192 lambda { request.controller_class }.should_not raise_error(Merb::ControllerExceptions::NotFound) 193 end 194 195 it "should raise a NotFound exception when the controller does not exist" do 196 @in['REQUEST_URI'] = "/bad_posts/show/1" 197 @in['REQUEST_METHOD'] = 'GET' 198 @in['CONTENT_TYPE'] = "application/x-www-form-urlencoded" 199 request = Merb::Request.new(@in) 200 request.expects(:controller_name).returns("bad_posts") 201 request.controller_name.should == "bad_posts" 202 lambda { request.controller_class }.should raise_error(Merb::ControllerExceptions::NotFound) 203 end 173 204 end
