Sha256: 358832d5806b6c54295b9c523987573fda2b18d0ec7809442c686886e751af0d

Contents?: true

Size: 1.03 KB

Versions: 3

Compression:

Stored size: 1.03 KB

Contents

require 'spec_helper'

describe FeaturedWork do
  let(:feature) { FeaturedWork.create(generic_file_id:"99") }

  it "should have a file" do
    expect(feature.generic_file_id).to eq "99"
  end

  it "should not allow six features" do
    5.times do |n|
      expect(FeaturedWork.create(generic_file_id:n.to_s)).to_not be_new_record 
    end
    FeaturedWork.create(generic_file_id:"6").tap do |sixth|
      expect(sixth).to be_new_record 
      expect(sixth.errors.full_messages).to eq ["Limited to 5 featured works."]
    end
    expect(FeaturedWork.count).to eq 5
  end

  describe "can_create_another?" do
    subject { FeaturedWork }
    context "when none exist" do
      its(:can_create_another?) { should be true }
    end
    context "when five exist" do
      before do
        5.times do |n|
          FeaturedWork.create(generic_file_id:n.to_s)
        end
      end
      its(:can_create_another?) { should be false }
    end
  end

  describe "#order" do
    subject { FeaturedWork.new(order: 5) }
    its(:order) {should eq 5 }
  end
end


Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
sufia-4.0.1 spec/models/featured_work_spec.rb
sufia-4.0.0 spec/models/featured_work_spec.rb
sufia-4.0.0.rc2 spec/models/featured_work_spec.rb