Skip to content

Commit 46ac1a2

Browse files
committed
Raise on non-existent kwargs
1 parent d10f76f commit 46ac1a2

4 files changed

Lines changed: 28 additions & 3 deletions

File tree

lib/active_interaction/base.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,20 @@ class << self
3636
include Hashable
3737
include Missable
3838

39+
ALLOWED_KWARGS = %i[
40+
desc
41+
default
42+
index_errors
43+
strip
44+
format
45+
digits
46+
base
47+
from
48+
methods
49+
class
50+
converter
51+
].freeze
52+
3953
# @!method run(inputs = {})
4054
# @note If the interaction inputs are valid and there are no runtime
4155
# errors and execution completed successfully, {#valid?} will always
@@ -105,6 +119,9 @@ def method_missing(*args, &block)
105119
# @param options [Hash]
106120
def add_filter(klass, name, options, &block)
107121
raise InvalidFilterError, %("#{name}" is a reserved name) if Inputs.reserved?(name)
122+
if (invalid_options = options.keys - ALLOWED_KWARGS).any?
123+
raise InvalidFilterError, "invalid options: #{invalid_options.join(', ')}"
124+
end
108125

109126
initialize_filter(klass.new(name, options, &block))
110127
end

lib/active_interaction/filters/hash_filter.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def convert(value)
7777

7878
# rubocop:disable Style/MissingRespondToMissing
7979
def method_missing(*args, &block)
80-
super(*args) do |klass, names, options|
80+
super do |klass, names, options|
8181
raise InvalidFilterError, 'missing attribute name' if names.empty?
8282

8383
names.each do |name|

spec/active_interaction/base_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,14 @@ def execute
140140
end.to raise_error NoMethodError
141141
end
142142

143+
it 'raises an error for a non-existent kwarg' do
144+
expect do
145+
Class.new(TestInteraction) do
146+
string :beverage, type: :sparkling_wine, bubbles: true
147+
end
148+
end.to raise_error ActiveInteraction::InvalidFilterError, /invalid options: type, bubbles/
149+
end
150+
143151
it do
144152
expect do
145153
Class.new(TestInteraction) do

spec/active_interaction/errors_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111

1212
let(:klass) do
1313
Class.new(ActiveInteraction::Base) do
14-
string :attribute, defualt: nil
15-
array :array, defualt: nil
14+
string :attribute, default: nil
15+
array :array, default: nil
1616

1717
def self.name
1818
@name ||= SecureRandom.hex

0 commit comments

Comments
 (0)