Sha256: bb23ef6767ee451a940e4a1cb348c3b714b270908052eaffbaf0bf07c9a6a874

Contents?: true

Size: 1.29 KB

Versions: 9

Compression:

Stored size: 1.29 KB

Contents

require 'spec_helper'

describe 'with action class finder' do
  include_context 'form builder'

  before {
    allow(Formtastic::FormBuilder)
      .to receive(:action_class_finder).and_return(Formtastic::ActionClassFinder)
  }

  it_behaves_like 'Action Helper'

  describe 'instantiating an action class' do
    it "should delegate to ActionClassFinder" do
      concat(semantic_form_for(@new_post) do |builder|
        Formtastic::ActionClassFinder.any_instance.should_receive(:find).
            with(:button).and_call_original

        builder.action(:submit, :as => :button)
      end)
    end

    describe 'when instantiated multiple times with the same action type' do
      it "should be cached" do
        concat(semantic_form_for(@new_post) do |builder|
          Formtastic::ActionClassFinder.should_receive(:new).once.and_call_original
          builder.action(:submit, :as => :button)
          builder.action(:submit, :as => :button)
        end)
      end
    end

    context 'of unknown action' do
      it "should try to load class named as the action" do
        expect {
          semantic_form_for(@new_post) do |builder|
            builder.action(:destroy)
          end
        }.to raise_error(Formtastic::UnknownActionError, 'Unable to find action class DestroyAction')
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 2 rubygems

Version Path
formtastic-3.1.5 spec/helpers/namespaced_action_helper_spec.rb
ish_lib_manager-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/formtastic-3.1.4/spec/helpers/namespaced_action_helper_spec.rb
formtastic-3.1.4 spec/helpers/namespaced_action_helper_spec.rb
formtastic-3.1.3 spec/helpers/namespaced_action_helper_spec.rb
formtastic-3.1.2 spec/helpers/namespaced_action_helper_spec.rb
formtastic-3.1.1 spec/helpers/namespaced_action_helper_spec.rb
formtastic-3.1.0 spec/helpers/namespaced_action_helper_spec.rb
formtastic-3.1.0.rc2 spec/helpers/namespaced_action_helper_spec.rb
formtastic-3.1.0.rc1 spec/helpers/namespaced_action_helper_spec.rb