Sha256: 364400341a7c15dc2a4e3c2e416bac5bf684471b309a34e1c87fe07ab79aceda

Contents?: true

Size: 1.47 KB

Versions: 1

Compression:

Stored size: 1.47 KB

Contents

require 'spec_helper'
require 'has_breadcrumb'

class Father
  include HasBreadcrumb

  has_breadcrumb title: "Father"
end

class Son
  include HasBreadcrumb

  attr_accessor :father, :name

  has_breadcrumb parent: :father, title: :name
end

class Daughter
  include HasBreadcrumb

  attr_reader :father

  has_breadcrumb parent: :father
end

describe HasBreadcrumb do
  let(:father){ Father.new }
  let(:son){ Son.new }
  let(:daughter) { Daughter.new }

  describe "#breadcrumb_parent" do
    context "when the parent is nil" do
      it "should return nil" do
        expect(father.breadcrumb_parent).to eq(nil)
      end
    end

    context "when a parent is given" do
      it "should define a breadcrumb parent" do
        father = Object.new
        son.father = father
        expect(son.breadcrumb_parent).to eq(father)
      end
    end
  end

  describe "#breadcrumb_name" do
    context "when no title is given" do
      it "should return an empty string" do
        expect(daughter.breadcrumb_name).to eq("")
      end
    end

    context "when a name is given" do
      it "should return a title when a Symbol is passed" do
        son.name = "Jimmy"
        expect(son.breadcrumb_name).to eq("Jimmy")
      end

      it "should return a title when a string is passed" do
        expect(father.breadcrumb_name).to eq("Father")
      end
    end
  end

  describe ".included" do
    it "should respond to has_breadcrumb" do
      Father.should respond_to(:has_breadcrumb)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
simple_breadcrumbs-0.0.1 spec/has_breadcrumb/has_breadcrumb_spec.rb