Skip to content

Commit

Permalink
Added more specific plugin error reporting.
Browse files Browse the repository at this point in the history
  • Loading branch information
nbibler committed Apr 12, 2008
1 parent f35dba2 commit 5d01367
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
18 changes: 17 additions & 1 deletion lib/find_by_param.rb
@@ -1,4 +1,20 @@
module FindByParam

##
# Catch-all error for any issue arrising within the FindByParam plugin.
#
class Error < RuntimeError; end

##
# Raised when the param requested is not in the model's table definition.
# For example:
#
# class WillRaiseError < ActiveRecord::Base
# define_find_param :undefined_column
# end
#
class ColumnNotFoundError < Error; end

module ClassMethods
def define_find_param(param, options={})
param = param.to_s
Expand All @@ -13,7 +29,7 @@ def define_find_param(param, options={})
end
self.class.send(:define_method, 'find_by_param', &bl)
else
raise StandardError
raise ColumnNotFoundError
end
self.send(:include, FindByParam::InstanceMethods)
end
Expand Down
8 changes: 8 additions & 0 deletions test/find_by_param_test.rb
Expand Up @@ -38,4 +38,12 @@ def test_raises_on_not_found_if_specified
BlogPost.find_by_param('in ur tests, failing')
end
end

def test_raises_column_not_found_error_when_given_undefined_column
assert_raise(FindByParam::ColumnNotFoundError) do
BlogPost.send(:define_find_param, 'bad_column_name')
end
assert_kind_of FindByParam::Error, FindByParam::ColumnNotFoundError.new
end

end

0 comments on commit 5d01367

Please sign in to comment.