Sha256: 8707ac8a8ab81b1bc1c03e791701ce3f1cb16d349eeac613a2945a26d295c558

Contents?: true

Size: 1.76 KB

Versions: 31

Compression:

Stored size: 1.76 KB

Contents

require 'rails_helper'

describe Pulitzer::Post do
  let(:post) { build :post }

  it 'has a valid factory' do
    expect(post).to be_valid
  end

  describe "Active Model validations" do
    it { should validate_presence_of(:title) }
  end

  describe "ActiveRecord associations" do
    it { should belong_to(:post_type_version) }
  end

  describe "#active_version" do
    let(:post) { create :post }
    let!(:preview) { create :version, post: post, status: :preview }
    let!(:active)  { create :version, post: post, status: :active  }

    it "should return the version with status = active" do
      expect(post.active_version).to eq active
    end
  end

  describe "#get_active_version!" do
    let(:post) { create :post} 
    let!(:preview) { create :version, post: post, status: :preview }

    it "should raise an error if the active version is not found" do
      expect{post.get_active_version!}.to raise_error Pulitzer::VersionMissingError
    end
  end

  describe "#get_preview_version!" do
    let(:post) { create :post} 

    it "should raise an error if the version is processing" do
      processing = post.preview_version
      processing.update_columns status: 'processing'
      expect{post.get_preview_version!}.to raise_error Pulitzer::VersionProcessingError
    end

    it "should raise an error if the version is processing" do
      post.preview_version.destroy
      expect{post.get_preview_version!}.to raise_error Pulitzer::VersionMissingError
    end
  end

  describe "Generate a slug" do
    let(:post) { create :post }

    it 'for a new post' do
      expect(post.slug).to match 'winterfell-news-'
    end

    it 'updating a post' do
      post.update title: 'The new King in the North'
      expect(post.slug).to eq 'the-new-king-in-the-north'
    end
  end
end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
pulitzer-0.15.31 spec/models/post_spec.rb
pulitzer-0.15.30 spec/models/post_spec.rb
pulitzer-0.15.29 spec/models/post_spec.rb
pulitzer-0.15.28 spec/models/post_spec.rb
pulitzer-0.15.27 spec/models/post_spec.rb
pulitzer-0.15.26 spec/models/post_spec.rb
pulitzer-0.15.25 spec/models/post_spec.rb
pulitzer-0.15.24 spec/models/post_spec.rb
pulitzer-0.15.23 spec/models/post_spec.rb
pulitzer-0.15.22 spec/models/post_spec.rb
pulitzer-0.15.21 spec/models/post_spec.rb
pulitzer-0.15.20 spec/models/post_spec.rb
pulitzer-0.15.19 spec/models/post_spec.rb
pulitzer-0.15.18 spec/models/post_spec.rb
pulitzer-0.15.17 spec/models/post_spec.rb
pulitzer-0.15.16 spec/models/post_spec.rb
pulitzer-0.15.15 spec/models/post_spec.rb
pulitzer-0.15.14 spec/models/post_spec.rb
pulitzer-0.15.13 spec/models/post_spec.rb
pulitzer-0.15.12 spec/models/post_spec.rb