Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

given? does not recognize multi-part date inputs #499

Closed
solebared opened this issue Mar 25, 2021 · 0 comments
Closed

given? does not recognize multi-part date inputs #499

solebared opened this issue Mar 25, 2021 · 0 comments
Labels

Comments

@solebared
Copy link

I was pleasantly surprised to find that AI already supports multi-part params such as those generated by the date_select helper.

However it appears that given? does not correctly recognize such inputs.

Easiest way to demonstrate the issue was with this failing test.

diff --git a/spec/active_interaction/base_spec.rb b/spec/active_interaction/base_spec.rb
index ff35e8f..8bfdd8b 100644
--- a/spec/active_interaction/base_spec.rb
+++ b/spec/active_interaction/base_spec.rb
@@ -589,6 +589,32 @@ describe ActiveInteraction::Base do
         expect(result).to be false
       end
     end
+
+    context 'multi-part date values' do
+      let(:described_class) do
+        Class.new(TestInteraction) do
+          date :thing,
+            default: nil
+
+          def execute
+            given?(:thing)
+          end
+        end
+      end
+
+      it 'is true when the input is given' do
+        inputs.merge!(
+          'thing(1i)' => '2020',
+          'thing(2i)' => '12',
+          'thing(3i)' => '31'
+        )
+        expect(result).to be true
+      end
+    end
   end
 
   context 'inheritance' do

Happy to work up a PR if you like, though i may have some questions around how to deal with partial inputs (eg, if just the year param is missing).

Much appreciation for this gem!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants