Sha256: 64345395bdbc855a9370cc9fd955de6b71fb88f0655abb7ad4b0ddcb8afa5a32

Contents?: true

Size: 1.54 KB

Versions: 2

Compression:

Stored size: 1.54 KB

Contents

# frozen_string_literal: true
require "spec_helper"

module BitCore
  describe Slide do
    fixtures :"bit_core/slideshows", :"bit_core/slides"

    describe "#render_body" do
      it "should render a nil body" do
        expect(subject.render_body).to eq("")
      end

      it "should render markdown as html" do
        subject.body = "# header"

        expect(subject.render_body).to match(%r{<h1>header<\/h1>})
      end

      it "should escape html" do
        subject.body = "<div>my content</div>"

        expect(subject.render_body).to match(%r{<p>my content<\/p>})
      end
    end

    describe "when validated" do
      context "if the options attribute is present" do
        it "normalizes it" do
          hashable = Struct.new("Hashable", :to_h).new("foo": "bar")
          subject.options = hashable
          subject.valid?

          expect(subject.options).to eq("foo": "bar")
        end
      end

      context "if the options attribute isn't present" do
        it "leaves it as nil" do
          subject.options = nil
          subject.valid?

          expect(subject.options).to be_nil
        end
      end
    end

    describe "when destroyed" do
      let(:slideshow) { bit_core_slideshows(:slideshow1) }
      let(:slide) { bit_core_slides(:slide2) }

      it "updates the positions of remaining slides" do
        expect(slideshow.slides.map(&:position)).to eq [1, 2, 3]
        expect(slide.position).to eq 2

        slide.destroy

        expect(slideshow.reload.slides.map(&:position))
          .to eq [1, 2]
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
bit_core-1.4.7 spec/models/bit_core/slide_spec.rb
bit_core-2.0.0.beta2 spec/models/bit_core/slide_spec.rb