Sha256: 8b30e1e25a412aa6d626bb3dba21b458b2785de4ab3c6d857f66f2a758ca2672

Contents?: true

Size: 1.75 KB

Versions: 22

Compression:

Stored size: 1.75 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) }
  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

22 entries across 22 versions & 1 rubygems

Version Path
pulitzer-0.15.0 spec/models/post_spec.rb
pulitzer-0.14.4 spec/models/post_spec.rb
pulitzer-0.14.3 spec/models/post_spec.rb
pulitzer-0.14.2 spec/models/post_spec.rb
pulitzer-0.14.1 spec/models/post_spec.rb
pulitzer-0.14.0 spec/models/post_spec.rb
pulitzer-0.13.1 spec/models/post_spec.rb
pulitzer-0.12.5 spec/models/post_spec.rb
pulitzer-0.13.0 spec/models/post_spec.rb
pulitzer-0.12.4 spec/models/post_spec.rb
pulitzer-0.12.3 spec/models/post_spec.rb
pulitzer-0.12.2 spec/models/post_spec.rb
pulitzer-0.12.1 spec/models/post_spec.rb
pulitzer-0.12.0 spec/models/post_spec.rb
pulitzer-0.11.3 spec/models/post_spec.rb
pulitzer-0.11.2 spec/models/post_spec.rb
pulitzer-0.11.1 spec/models/post_spec.rb
pulitzer-0.11.0 spec/models/post_spec.rb
pulitzer-0.10.3 spec/models/post_spec.rb
pulitzer-0.10.2 spec/models/post_spec.rb