Sha256: db7a7e43e417849f5016cd1862dbe173a7adda81dd9873bbe670ee30a91586c0

Contents?: true

Size: 1.56 KB

Versions: 8

Compression:

Stored size: 1.56 KB

Contents

require "spec_helper"

describe TableCloth::Extensions::Actions::Action do
  let(:action_hash) { {proc: Proc.new{}} }
  subject { described_class.new(action_hash) }

  it "initializes with a hash" do
    expect(subject.options).to eq(action_hash)
  end

  it "defines a delegator to a jury" do
    expect(subject.jury).to be_kind_of TableCloth::Extensions::Actions::Jury
  end

  context "#value" do
    let(:model) { FactoryGirl.build(:dummy_model) }
    let(:view_context) { ActionView::Base.new }

    context "string" do
      let(:action_hash) { {proc: Proc.new{ "something" }} }

      it "returns a string" do
        expect(subject.value(model, view_context)).to match /something/
      end
    end

    context "view helper" do
      let(:action_hash) do
        {proc: Proc.new { link_to "blank", "something" }}
      end

      it "returns a link" do
        expect(subject.value(model, view_context)).to match /href="something"/
        expect(subject.value(model, view_context)).to match />blank</
      end
    end

    context "conditional" do
      let(:action_hash) do
        {
          proc: Proc.new { "something" },
          if: Proc.new {|object| object.admin? }
        }
      end

      it "returns the link when the model condition succeeds" do
        model.stub admin?: true
        expect(subject.value(model, view_context)).to include "something"
      end

      it "does not return the link when the model condition fails" do
        model.stub admin?: false
        expect(subject.value(model, view_context)).not_to include "something"
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
table_cloth-0.4.2 spec/lib/extensions/actions/action_spec.rb
table_cloth-0.4.1 spec/lib/extensions/actions/action_spec.rb
table_cloth-0.4.0 spec/lib/extensions/actions/action_spec.rb
table_cloth-0.3.2 spec/lib/extensions/actions/action_spec.rb
table_cloth-0.3.1.alpha1 spec/lib/extensions/actions/action_spec.rb
table_cloth-0.3.0.beta3 spec/lib/extensions/actions/action_spec.rb
table_cloth-0.3.0.beta2 spec/lib/extensions/actions/action_spec.rb
table_cloth-0.3.0.beta1 spec/lib/extensions/actions/action_spec.rb