responder_controller 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.1.2
@@ -3,10 +3,18 @@ require 'active_support/core_ext/string/inflections'
3
3
  require 'active_support/core_ext/module/delegation'
4
4
 
5
5
  module ResponderController
6
+ class BadScope < StandardError
7
+ end
8
+
6
9
  def self.included(mod)
7
10
  mod.extend ClassMethods
8
11
  mod.send :include, InstanceMethods
9
12
  mod.send :include, Actions
13
+
14
+ # Uncaught BadScope exceptions become 422s
15
+ if defined? ActionDispatch
16
+ ActionDispatch::ShowExceptions.rescue_responses[BadScope.name] = :unprocessable_entity
17
+ end
10
18
  end
11
19
 
12
20
  # Configure how the controller finds and serves models of what flavor.
@@ -122,8 +130,6 @@ module ResponderController
122
130
  # examining +params+. If any +params+ key matches a name found in
123
131
  # <tt>ClassMethods#model_class.scopes.keys</tt>, then it is taken to be a scope and is
124
132
  # applied. The values under that +params+ key are passed along as arguments.
125
- #
126
- # TODO: and if the scope taketh arguments not?
127
133
  def scope(query)
128
134
  query = (scopes || []).inject(query) do |query, scope|
129
135
  if Symbol === scope and model_class.scopes.key? scope
@@ -137,7 +143,7 @@ module ResponderController
137
143
 
138
144
  scopes_from_request = (model_class.scopes.keys & params.keys.collect { |k| k.to_sym })
139
145
  query = scopes_from_request.inject(query) do |query, scope|
140
- query.send scope, *params[scope.to_s]
146
+ query.send scope, *params[scope.to_s] rescue raise BadScope.new
141
147
  end
142
148
 
143
149
  query
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{responder_controller}
8
- s.version = "0.1.1"
8
+ s.version = "0.1.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Phil Smith"]
@@ -196,6 +196,13 @@ describe "ResponderController" do
196
196
  class_level_query.should_receive(:commented_on_by).with('you').and_return(class_level_query)
197
197
  @controller.scope(@query).should == class_level_query
198
198
  end
199
+
200
+ it 'throws BadScope for scopes that raise an exception' do
201
+ @query.should_receive(:commented_on_by).and_raise(ArgumentError.new)
202
+ lambda do
203
+ @controller.scope @query
204
+ end.should raise_error(ResponderController::BadScope)
205
+ end
199
206
  end
200
207
 
201
208
  describe '#find_models' do
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 1
9
- version: 0.1.1
8
+ - 2
9
+ version: 0.1.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Phil Smith