Sha256: d66498522ccfc7cbaa07ce30243159d3bdaed45238bac3200298aa9d31f1b63f

Contents?: true

Size: 1.13 KB

Versions: 1

Compression:

Stored size: 1.13 KB

Contents

require 'rails_helper'

require File.join(File.dirname(__FILE__), '..', '..', 'app', 'models', 'announcement')

describe Announcement do
  it "should return the latest announcement when there are several" do
    old = create_announcement(:body => 'no fun', :created_at => 2.days.ago)
    latest = create_announcement(:body => 'fun', :created_at => 1.day.ago)
    older = create_announcement(:body => 'less fun', :created_at => 3.days.ago)

    expect(Announcement.current).to eq latest
  end

  it "should return an existent announcement where there is no announcement" do
    create_announcement(:body => 'body')
    expect(Announcement.current.exists?).to be true
  end

  it "should return a non-existent announcement where there is no announcement" do
    expect(Announcement.current.exists?).to be false
  end

  it 'can always assign straight to the body' do
    expect(Announcement.create!(:body => 'hello').body).to eq 'hello'
  end

  def create_announcement(attributes)
    announcement = Announcement.new
    attributes.each do |key, value|
      announcement.send("#{key}=", value)
    end
    announcement.save!
    announcement
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
paul_revere-1.3 spec/models/announcement_spec.rb