Sha256: e381fa177a3a97a9053bf434bd6009f0878c5708689256a4fa8f759692ff7340

Contents?: true

Size: 1.76 KB

Versions: 8

Compression:

Stored size: 1.76 KB

Contents

require "spec_helper"

describe TableCloth::Extensions::Actions::Jury do
  let(:action) { FactoryGirl.build(:action, options: action_options) }
  subject { described_class.new(action) }
  let(:model) { double("model") }

  context "Proc" do
    context "if .available?" do
      let(:action_options) { {if: Proc.new{|o| o.state == "valid" }} }

      it "returns true for valid models" do
        model.stub state: "valid"
        expect(subject).to be_available(model)
      end

      it "returns false for invalid models" do
        model.stub state: "invalid"
        expect(subject).not_to be_available(model)
      end
    end

    context "unless .available?" do
      let(:action_options) { {unless: Proc.new{|o| o.state == "invalid" }} }
      
      it "returns true for valid models" do
        model.stub state: "valid"
        expect(subject).to be_available(model)
      end

      it "returns false for invalid models" do
        model.stub state: "invalid"
        expect(subject).not_to be_available(model)
      end
    end
  end

  context "Symbol" do
    context "if .available?" do
      let(:action_options) { {if: :valid?} }

      it "returns true for valid?" do
        model.stub valid?: true
        expect(subject).to be_available(model)
      end

      it "returns true for valid?" do
        model.stub valid?: false
        expect(subject).not_to be_available(model)
      end
    end

    context "unless .available?" do
      let(:action_options) { {unless: :valid?} }
      
      it "returns true for valid models" do
        model.stub valid?: false
        expect(subject).to be_available(model)
      end

      it "returns false for invalid models" do
        model.stub valid?: true
        expect(subject).not_to be_available(model)
      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/jury_spec.rb
table_cloth-0.4.1 spec/lib/extensions/actions/jury_spec.rb
table_cloth-0.4.0 spec/lib/extensions/actions/jury_spec.rb
table_cloth-0.3.2 spec/lib/extensions/actions/jury_spec.rb
table_cloth-0.3.1.alpha1 spec/lib/extensions/actions/jury_spec.rb
table_cloth-0.3.0.beta3 spec/lib/extensions/actions/jury_spec.rb
table_cloth-0.3.0.beta2 spec/lib/extensions/actions/jury_spec.rb
table_cloth-0.3.0.beta1 spec/lib/extensions/actions/jury_spec.rb