form_configurable_spec.rb 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. require 'rails_helper'
  2. describe FormConfigurable do
  3. class Agent1
  4. include FormConfigurable
  5. def validate_test
  6. true
  7. end
  8. def complete_test
  9. [{name: 'test', value: 1234}]
  10. end
  11. end
  12. class Agent2 < Agent
  13. end
  14. before(:all) do
  15. @agent1 = Agent1.new
  16. @agent2 = Agent2.new
  17. end
  18. it "#is_form_configurable" do
  19. expect(@agent1.is_form_configurable?).to be true
  20. expect(@agent2.is_form_configurable?).to be false
  21. end
  22. describe "#validete_option" do
  23. it "should call the validation method if it is defined" do
  24. expect(@agent1.validate_option('test')).to be true
  25. end
  26. it "should return false of the method is undefined" do
  27. expect(@agent1.validate_option('undefined')).to be false
  28. end
  29. end
  30. it "#complete_option" do
  31. expect(@agent1.complete_option('test')).to eq [{name: 'test', value: 1234}]
  32. end
  33. describe "#form_configurable" do
  34. it "should raise an ArgumentError for invalid options" do
  35. expect { Agent1.form_configurable(:test, invalid: true) }.to raise_error(ArgumentError)
  36. end
  37. it "should raise an ArgumentError when not providing an array with type: array" do
  38. expect { Agent1.form_configurable(:test, type: :array, values: 1) }.to raise_error(ArgumentError)
  39. end
  40. it "should not require any options for the default values" do
  41. expect { Agent1.form_configurable(:test) }.to change(Agent1, :form_configurable_attributes).by(['test'])
  42. end
  43. end
  44. end