Sha256: 4952b8bf766c78cf1cbcde704f9677e5cc9856ab7851d39860be35e9c0214af2

Contents?: true

Size: 1.44 KB

Versions: 6

Compression:

Stored size: 1.44 KB

Contents

require 'spec_helper'

describe ContentBlockHelper, type: :helper do
  let(:content_block) { FactoryGirl.create(:content_block, value: "<p>foo bar</p>") }

  subject { helper.editable_content_block(content_block) }

  context "for someone" do
    context "with access" do
      before do
        expect(helper).to receive(:can?).with(:update, content_block).and_return(true)
      end
      let(:node) { Capybara::Node::Simple.new(subject) }

      it "shows the preview and the form" do
        expect(node).to have_selector "button[data-target='#edit_content_block_1'][data-behavior='reveal-editor']"
        expect(node).to have_selector "form#edit_content_block_1[action='#{sufia.content_block_path(content_block)}']"
        expect(subject).to be_html_safe
      end

      context "with option to create new:" do
        subject { helper.editable_content_block(content_block, true) }

        it "shows the button & form for a new content block" do
          expect(node).to have_selector "button[data-target='#new_content_block'][data-behavior='reveal-editor']"
          expect(node).to have_selector "form#new_content_block[action='#{sufia.content_blocks_path}']"
        end
      end
    end
  end

  context "anonymous" do
    before do
      expect(helper).to receive(:can?).with(:update, content_block).and_return(false)
    end
    it "shows the content" do
      expect(subject).to eq '<p>foo bar</p>'
      expect(subject).to be_html_safe
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
sufia-6.7.0 spec/helpers/content_block_helper_spec.rb
sufia-6.6.1 spec/helpers/content_block_helper_spec.rb
sufia-6.6.0 spec/helpers/content_block_helper_spec.rb
sufia-6.5.0 spec/helpers/content_block_helper_spec.rb
sufia-6.4.0 spec/helpers/content_block_helper_spec.rb
sufia-6.3.0 spec/helpers/content_block_helper_spec.rb