form_configurable_agent_presenter_spec.rb 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. require 'spec_helper'
  2. describe FormConfigurableAgentPresenter do
  3. class FormConfigurableAgentPresenterAgent < Agent
  4. include FormConfigurable
  5. form_configurable :string, roles: :validatable
  6. form_configurable :text, type: :text, roles: :completable
  7. form_configurable :boolean, type: :boolean
  8. form_configurable :array, type: :array, values: [1, 2, 3]
  9. end
  10. before(:all) do
  11. @presenter = FormConfigurableAgentPresenter.new(FormConfigurableAgentPresenterAgent.new, ActionController::Base.new.view_context)
  12. end
  13. it "works for the type :string" do
  14. expect(@presenter.option_field_for(:string)).to(
  15. have_tag('input', with: {:'data-attribute' => 'string', role: 'validatable form-configurable', type: 'text', name: 'agent[options][string]'})
  16. )
  17. end
  18. it "works for the type :text" do
  19. expect(@presenter.option_field_for(:text)).to(
  20. have_tag('textarea', with: {:'data-attribute' => 'text', role: 'completable form-configurable', name: 'agent[options][text]'})
  21. )
  22. end
  23. it "works for the type :boolean" do
  24. expect(@presenter.option_field_for(:boolean)).to(
  25. have_tag('input', with: {:'data-attribute' => 'boolean', role: 'form-configurable', name: 'agent[options][boolean_radio]', type: 'radio'})
  26. )
  27. end
  28. it "works for the type :array" do
  29. expect(@presenter.option_field_for(:array)).to(
  30. have_tag('input', with: {:'data-attribute' => 'array', role: 'completable form-configurable', type: 'text', name: 'agent[options][array]'})
  31. )
  32. end
  33. end