Sha256: 20359efd2c27bcacfd8e038bbc47b46341cfd0e14f28363035edbb499c2a4435

Contents?: true

Size: 1.56 KB

Versions: 3

Compression:

Stored size: 1.56 KB

Contents

# frozen_string_literal: true

require "rails_helper"

module Archangel
  RSpec.describe Widget, type: :model do
    context "callbacks" do
      it { is_expected.to callback(:parameterize_slug).before(:validation) }

      it { is_expected.to callback(:column_reset).after(:destroy) }
    end

    context "validations" do
      it { is_expected.to validate_presence_of(:content) }
      it { is_expected.to validate_presence_of(:name) }
      it { is_expected.to validate_presence_of(:slug) }

      it { is_expected.to allow_value("{{ foo }}").for(:content) }
      it { is_expected.to_not allow_value("{{ foo }").for(:content) }

      it "has a unique slug scoped to Site" do
        resource = build(:widget)

        expect(resource)
          .to validate_uniqueness_of(:slug).scoped_to(:site_id).case_insensitive
      end
    end

    context "associations" do
      it { is_expected.to belong_to(:site) }

      it "belongs to Template" do
        expect(subject).to(
          belong_to(:template).conditions(partial: true)
                              .class_name("Archangel::Template")
        )
      end
    end

    context "#to_param" do
      it "uses `slug` as the identifier for routes" do
        resource = build(:widget, slug: "foo")

        expect(resource.to_param).to eq("foo")
      end
    end

    context "#column_reset" do
      it "resets `slug` to `slug` + current time" do
        resource = create(:widget)

        slug = resource.slug

        resource.destroy!

        expect(resource.slug).to eq "#{Time.current.to_i}_#{slug}"
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
archangel-0.3.0 spec/models/archangel/widget_spec.rb
archangel-0.0.8 spec/models/archangel/widget_spec.rb
archangel-0.0.7 spec/models/archangel/widget_spec.rb