Sha256: a54921c2a4dac7df063a426d60700e2d9ea4d5801c154e7dad8922dca826862a

Contents?: true

Size: 1.64 KB

Versions: 2

Compression:

Stored size: 1.64 KB

Contents

require 'spec_helper'

describe LetterOpenerWeb::LettersController do
  describe 'GET index' do
    before do
      LetterOpenerWeb::Letter.stub(search: :all_letters)
      get :index
    end
    it { should assign_to(:letters).with(:all_letters) }
  end

  describe 'GET show' do
    let(:id)         { 'an-id' }
    let(:rich_text)  { "rich text href=\"plain.html\"" }
    let(:plain_text) { "plain text href=\"rich.html\"" }
    let(:letter)     { mock(:letter, rich_text: rich_text, plain_text: plain_text, id: id) }

    before do
      LetterOpenerWeb::Letter.stub(find: letter)
    end

    context 'rich text version' do
      before { get :show, id: id, style: 'rich' }

      it "returns letter's rich text contents" do
        response.body.should =~ /^rich text/
      end

      it 'fixes plain text link' do
        response.body.should_not =~ /href="plain.html"/
        response.body.should =~ /href="#{Regexp.escape letter_path(id: letter.id, style: 'plain')}"/
      end
    end

    context 'plain text version' do
      before { get :show, id: id, style: 'plain' }

      it "returns letter's plain text contents" do
        response.body.should =~ /^plain text/
      end

      it 'fixes rich text link' do
        response.body.should_not =~ /href="rich.html"/
        response.body.should =~ /href="#{Regexp.escape letter_path(id: letter.id, style: 'rich')}"/
      end
    end
  end

  describe 'DELETE clear' do
    it 'removes all letters' do
      LetterOpenerWeb::Letter.should_receive(:destroy_all)
      delete :clear
    end

    it 'redirects back to index' do
      delete :clear
      response.should redirect_to(letters_path)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
letter_opener_web-0.0.2 spec/controllers/letter_opener_web/letters_controller_spec.rb
letter_opener_web-0.0.1 spec/controllers/letter_opener_web/letters_controller_spec.rb