Sha256: 6abcdf848c9f825a086fbfc03d0a1610f6204f648eb2a441f269bb2095aab663

Contents?: true

Size: 1.63 KB

Versions: 1

Compression:

Stored size: 1.63 KB

Contents

require 'rails_helper'

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

describe AnnouncementsHelper do

  it "should return the current announcement when sent current_announcement and cache doesn't exist" do
    assign :current_announcement, nil
    allow(Announcement).to receive(:current).and_return(:foo)
    expect(helper.current_announcement).to eq :foo
  end

  it "should return a cached announcement when sent current_announcement and cache exists" do
    assign :current_announcement, :foo
    expect(Announcement).not_to receive(:current)
    expect(helper.current_announcement).to eq :foo
  end

  describe "when there is an announcement" do
    before do
      @announcement = Announcement.create!(:body => 'a body')
      assign :announcement, @announcement
    end

    describe "and the user has hidden an announcement" do
      before do
        allow(helper).to receive(:cookies).and_return("announcement_#{@announcement.created_at}" => "hidden")
      end

      it "should return true when sent announcement_hidden? with announcement" do
        expect(helper.announcement_hidden?(@announcement)).to be true
      end
    end

    describe "and the user has not hidden an announcement" do
      before do
        allow(helper).to receive(:cookies).and_return("announcement_#{@announcement.created_at}" => "not hidden")
      end

      it "should return false when sent announcement_hidden? with announcement" do
        expect(helper.announcement_hidden?(@announcement)).to be false
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
paul_revere-1.3 spec/helpers/announcements_helper_spec.rb