Sha256: 8a22b57e7293834e9aeb602e12ea3572dc2d99a4de8edfe5e21ac8d50b884fa0

Contents?: true

Size: 1.75 KB

Versions: 1

Compression:

Stored size: 1.75 KB

Contents

require 'spec_helper'
require 'model/models/described_model'

require 'ronin/model/has_description'

describe Model::HasDescription do
  let(:model) { DescribedModel }

  describe ".included" do
    subject { model }

    it "should include Ronin::Model" do
      expect(subject.ancestors).to include(Model)
    end

    it "should define a description property" do
      expect(subject.properties).to be_named(:description)
    end
  end

  describe "#description" do
    subject { model.new }

    it "should allow the setting of the description" do
      subject.description = 'test one'
      expect(subject.description).to eq('test one')
    end

    it "should strip leading and tailing white-space" do
      subject.description = %{   test two    }

      expect(subject.description).to eq('test two')
    end

    it "should strip leading and tailing white-space from each line" do
      subject.description = %{
        test
        three
      }

      expect(subject.description).to eq("test\nthree")
    end

    it "should preserve non-bordering empty lines" do
      subject.description = %{
        test

        four
      }

      expect(subject.description).to eq("test\n\nfour")
    end
  end

  describe ".describing" do
    subject { model }

    let(:description1) { 'foo one' }
    let(:description2) { 'foo bar two' }

    before do
      subject.create!(:description => description1)
      subject.create!(:description => description2)
    end

    it "should be able to find resources with similar descriptions" do
      resources = subject.describing('foo')

      expect(resources.length).to be(2)
      expect(resources[0].description).to be == description1
      expect(resources[1].description).to be == description2
    end

    after { subject.destroy }
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ronin-1.5.1 spec/model/has_description_spec.rb