spec/lib/param_description_spec.rb in apipie-rails-0.7.0 vs spec/lib/param_description_spec.rb in apipie-rails-0.7.1
- old
+ new
@@ -111,9 +111,77 @@
expect(param.validator).to eq(:validator_instance)
end
end
+ describe 'validate' do
+ context 'when allow_blank is ignored, as it was before 0.7.0' do
+ before do
+ Apipie.configuration.ignore_allow_blank_false = true
+ end
+
+ context 'when the parameter is a boolean' do
+ it "should not throw an exception when passed false" do
+ expect { Apipie::ParamDescription.new(method_desc, :param, :boolean).validate(false) }.to_not raise_error
+ end
+
+ it "should throw an exception when passed an empty value" do
+ expect { Apipie::ParamDescription.new(method_desc, :param, :boolean).validate('') }.to raise_error(Apipie::ParamInvalid)
+ end
+ end
+
+ context 'when the parameter is a string' do
+ context 'when allow_blank is specified as true' do
+ it "should throw an exception when passed an empty value" do
+ expect { Apipie::ParamDescription.new(method_desc, :param, String, allow_blank: true).validate('') }.to_not raise_error
+ end
+ end
+ context 'when allow_blank is specified as false' do
+ it "should throw an exception when passed an empty value" do
+ expect { Apipie::ParamDescription.new(method_desc, :param, String, allow_blank: false).validate('') }.to_not raise_error
+ end
+ end
+ context 'when allow_blank is not specified' do
+ it "should throw an exception when passed an empty value" do
+ expect { Apipie::ParamDescription.new(method_desc, :param, String).validate('') }.to_not raise_error
+ end
+ end
+ end
+
+ after do
+ Apipie.configuration.ignore_allow_blank_false = false
+ end
+ end
+
+ context 'when the parameter is a boolean' do
+ it "should not throw an exception when passed false" do
+ expect { Apipie::ParamDescription.new(method_desc, :param, :boolean).validate(false) }.to_not raise_error
+ end
+
+ it "should throw an exception when passed an empty value" do
+ expect { Apipie::ParamDescription.new(method_desc, :param, :boolean).validate('') }.to raise_error(Apipie::ParamInvalid)
+ end
+ end
+
+ context 'when the parameter is a string' do
+ context 'when allow_blank is specified as true' do
+ it "should throw an exception when passed an empty value" do
+ expect { Apipie::ParamDescription.new(method_desc, :param, String, allow_blank: true).validate('') }.to_not raise_error
+ end
+ end
+ context 'when allow_blank is specified as false' do
+ it "should throw an exception when passed an empty value" do
+ expect { Apipie::ParamDescription.new(method_desc, :param, String, allow_blank: false).validate('') }.to raise_error(Apipie::ParamInvalid)
+ end
+ end
+ context 'when allow_blank is not specified' do
+ it "should throw an exception when passed an empty value" do
+ expect { Apipie::ParamDescription.new(method_desc, :param, String).validate('') }.to raise_error(Apipie::ParamInvalid)
+ end
+ end
+ end
+ end
+
describe "concern substitution" do
let(:concern_dsl_data) { dsl_data.merge(:from_concern => true) }
let(:concern_resource_desc) do