Skip to content

Commit

Permalink
Add tests for Filter#default
Browse files Browse the repository at this point in the history
  • Loading branch information
tfausak committed Nov 11, 2013
1 parent 9976288 commit 877c2be
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions spec/active_interaction/filter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,37 @@ class ActiveInteraction::TestKlassFilter < described_class; end
expect(klass.type).to eql :test_klass
end
end

describe '#default' do
let(:name) { SecureRandom.hex }
let(:options) { {} }

subject(:filter) { ActiveInteraction::TestKlassFilter.new(name, options) }

context 'without a default' do
it 'returns nil' do
expect(filter.default).to be_nil
end
end

context 'with a default' do
let(:default) { SecureRandom.hex }
let(:factory) { double }

before do
options.merge!(default: default)
allow(ActiveInteraction::Caster).to receive(:cast).and_return(default)
end

it 'returns the default' do
expect(filter.default).to eq default
end

it 'calls cast' do
expect(ActiveInteraction::Caster).to receive(:cast).
once.with(filter, default)
filter.default
end
end
end
end

0 comments on commit 877c2be

Please sign in to comment.