Skip to content

Commit

Permalink
Add extra spec of mixing conditions and defaults.
Browse files Browse the repository at this point in the history
Related to #24
  • Loading branch information
sunny committed May 13, 2020
1 parent bd27c23 commit a0df1f7
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
16 changes: 16 additions & 0 deletions spec/actor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,22 @@
expect(result.value).to eq(3)
end
end

context 'when using type, default, allow_nil and must' do
context 'when not given a value' do
it 'uses the default' do
result = ValidateWeekdays.call
expect(result.weekdays).to eq([0, 1, 2, 3, 4])
end
end

context 'when given a nil value' do
it 'returns nil' do
result = ValidateWeekdays.call(weekdays: nil)
expect(result.weekdays).to be_nil
end
end
end
end

describe '#result' do
Expand Down
15 changes: 15 additions & 0 deletions spec/examples/validate_weekdays.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

class ValidateWeekdays < Actor
DEFAULT_WEEKDAYS = [0, 1, 2, 3, 4].freeze

input :weekdays,
type: Array,
allow_nil: true,
default: DEFAULT_WEEKDAYS,
must: {
be_valid: ->(v) { v.nil? || v.all? { |num| (0..6).include?(num) } }
}

def call; end
end

0 comments on commit a0df1f7

Please sign in to comment.