Sha256: 3780a0b83d904b0cf5b0bda7602168c2cb9aac15abf93f00a7bedadd78365e8a
Contents?: true
Size: 1.88 KB
Versions: 1
Compression:
Stored size: 1.88 KB
Contents
require 'spec_helper' require 'sweet_params' describe SweetParams do let(:params) { ActionController::Parameters.new(scope: 'recent', filter: { scope: 'recent' }, empty: '') } describe '#has?' do it 'should respond to method' do params.must_respond_to :has? end it 'should be true if parameter is present' do params.has?(:scope, in: [:recent, :new]).must_equal true end it 'should be false if parameter is missing' do params.has?(:empty).must_equal false params.has?(:not_here).must_equal false end it 'should handle multi-dimensional params hash' do params.has?([:filter, :scope]).must_equal true end it 'should handle multi-dimensional params hash' do params.has?([:filter, :not_here]).must_equal false end it 'should use single value as whitelist' do params.has?(:scope, in: :recent).must_equal true end it 'should use array as whitelist' do params.has?(:scope, in: [:recent, :new]).must_equal true end it 'should not allow not whitelisted params' do params.has?(:scope, in: [:hot, :new]).must_equal false end end describe '#validate' do it 'should respond to method' do params.must_respond_to :validate end it 'should allow whitelisted param' do params.validate(:scope, in: [:hot, :recent]).must_equal 'recent' end it 'should return nil for not whitelisted param' do params.validate(:scope, in: [:hot, :new]).must_equal nil end end describe '#validate_to_sym' do it 'should respond to method' do params.must_respond_to :validate_to_sym end it 'should symbolize whitelisted param' do params.validate_to_sym(:scope, in: [:hot, :recent]).must_equal :recent end it 'should return nil for not whitelisted param' do params.validate_to_sym(:scope, in: [:hot, :new]).must_equal nil end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
sweet_params-0.0.1 | spec/sweet_params_spec.rb |