summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAzul <azul@leap.se>2013-01-22 13:07:03 +0100
committerAzul <azul@leap.se>2013-01-22 13:07:03 +0100
commit0d1da13914675790daaf8def26f27017bf2d2a44 (patch)
tree09b679110cc54b8b4a9c3d7777b6baf1f250dd1a
parentde48efcf2a6b5fb096fd209b1efea482f743c19c (diff)
render 404 if needed
-rw-r--r--app/controllers/application_controller.rb4
-rw-r--r--core/lib/extensions/couchrest.rb37
-rw-r--r--users/app/controllers/webfinger_controller.rb4
3 files changed, 29 insertions, 16 deletions
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index be7aa1f..a1ea008 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -2,4 +2,8 @@ class ApplicationController < ActionController::Base
protect_from_forgery
ActiveSupport.run_load_hooks(:application_controller, self)
+
+ def not_found
+ raise RECORD_NOT_FOUND.new('Not Found')
+ end
end
diff --git a/core/lib/extensions/couchrest.rb b/core/lib/extensions/couchrest.rb
index 5938df4..ca4b608 100644
--- a/core/lib/extensions/couchrest.rb
+++ b/core/lib/extensions/couchrest.rb
@@ -1,23 +1,32 @@
-module CouchRest::Model::Designs
+module CouchRest
+ module Model::Designs
- class View
+ class View
- # so we can called Ticket.method.descending or Ticket.method.ascending
- def ascending
- self
+ # so we can called Ticket.method.descending or Ticket.method.ascending
+ def ascending
+ self
+ end
end
- end
- class DesignMapper
- def load_views(dir)
- Dir.glob("#{dir}/*.js") do |js|
- name = File.basename(js, '.js')
- file = File.open(js, 'r')
- view name.to_sym,
- :map => file.read,
- :reduce => "function(key, values, rereduce) { return sum(values); }"
+ class DesignMapper
+ def load_views(dir)
+ Dir.glob("#{dir}/*.js") do |js|
+ name = File.basename(js, '.js')
+ file = File.open(js, 'r')
+ view name.to_sym,
+ :map => file.read,
+ :reduce => "function(key, values, rereduce) { return sum(values); }"
+ end
end
end
+
end
+ class ModelRailtie
+ config.action_dispatch.rescue_responses.merge!(
+ 'CouchRest::Model::DocumentNotFound' => :not_found,
+ 'RestClient::ResourceNotFound' => :not_found
+ )
+ end
end
diff --git a/users/app/controllers/webfinger_controller.rb b/users/app/controllers/webfinger_controller.rb
index e86cd2d..ac05934 100644
--- a/users/app/controllers/webfinger_controller.rb
+++ b/users/app/controllers/webfinger_controller.rb
@@ -8,8 +8,8 @@ class WebfingerController < ApplicationController
def search
username = params[:q].split('@')[0].to_s.downcase
-
- user = User.find_by_login(username)
+ user = User.find_by_login(username) || not_found
@subject = Webfinger::UserPresenter.new(user, request)
end
+
end