Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Enforce :values or :example_values for :array type

Form select helper will fail if neither of these are set in the
parameter definition, so raise an error if they are both abesnt
  • Loading branch information...
commit 150cfc1df6788aa37c9b4bdd4a55ea064b701a17 1 parent 4a94c06
Malcolm Locke malclocke authored
3  lib/api_canon/documented_param.rb
View
@@ -22,6 +22,9 @@ def form_values
def to_field(f, doco_prefix)
# TODO: This doco_prefix thing sucks. Get rid of it.
if type == :array
+ if form_values.nil?
+ raise ArgumentError.new(':values or :example_values must be supplied for :array type params')
+ end
f.select name, form_values, {:selected => default, :include_blank => true}, {:multiple => multiple?, :class => 'input-block-level', :id => "#{doco_prefix}_#{name}"}
elsif type == :boolean
f.select name, [true,false], {:selected => default, :include_blank => true}, :class => 'input-block-level', :id => "#{doco_prefix}_#{name}"
6 spec/lib/api_canon/documented_param_spec.rb
View
@@ -26,6 +26,12 @@
fake_form.should_receive(:select).with :format, [:json, :xml], hash_including({:include_blank => true}), hash_including({:id => 'foo_format'})
documented_param.to_field fake_form, doco_prefix
end
+ context 'when form_values returns nil' do
+ it 'raises an ArgumentError' do
+ subject.stub(:form_values => nil)
+ expect { documented_param.to_field fake_form, doco_prefix }.to raise_exception(ArgumentError)
+ end
+ end
end
context "boolean-type params" do
before(:each) {documented_param.type = :boolean}
Please sign in to comment.
Something went wrong with that request. Please try again.