Sha256: 1fd12a45e74c3e6789cd99ea87dc6acda0bba6ee15c6c8d90d7cfaf9a4ababc0

Contents?: true

Size: 1.99 KB

Versions: 3

Compression:

Stored size: 1.99 KB

Contents

require 'spec_helper'

module Alchemy
  describe Admin::ClipboardController do
    let(:public_page)     { build_stubbed(:public_page) }
    let(:element)         { build_stubbed(:element, page: public_page) }
    let(:another_element) { build_stubbed(:element, page: public_page) }

    before do
      sign_in(admin_user)
      session[:clipboard] = Clipboard.new
      Element.stub(find: element)
    end

    describe "#insert" do
      it "should hold element ids" do
        xhr :post, :insert, {remarkable_type: :elements, remarkable_id: element.id}
        session[:clipboard][:elements].should == [{id: element.id, action: 'copy'}]
      end

      it "should not have the same element twice" do
        session[:clipboard][:elements] = {id: element.id, action: 'copy'}
        xhr :post, :insert, {remarkable_type: :elements, remarkable_id: element.id}
        session[:clipboard][:elements].collect { |e| e[:id] }.should_not == [element.id, element.id]
      end
    end

    describe "#delete" do
      it "should remove element ids from clipboard" do
        session[:clipboard][:elements] = {id: element.id, action: 'copy'}
        session[:clipboard][:elements] << {id: another_element.id, action: 'copy'}
        xhr :delete, :remove, {remarkable_type: :elements, remarkable_id: another_element.id}
        session[:clipboard][:elements].should == [{id: element.id, action: 'copy'}]
      end
    end

    describe "#clear" do

      context "with elements as remarkable_type" do
        it "should clear the elements clipboard" do
          session[:clipboard][:elements] = {id: element.id}
          xhr :delete, :clear, {remarkable_type: :elements}
          session[:clipboard].should be_empty
        end
      end

      context "with pages as remarkable_type" do
        it "should clear the pages clipboard" do
          session[:clipboard][:pages] = {id: public_page.id}
          xhr :delete, :clear, {remarkable_type: :pages}
          session[:clipboard].should be_empty
        end
      end

    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
alchemy_cms-3.0.0.rc7 spec/controllers/admin/clipboard_controller_spec.rb
alchemy_cms-3.0.0.rc6 spec/controllers/admin/clipboard_controller_spec.rb
alchemy_cms-3.0.0.rc5 spec/controllers/admin/clipboard_controller_spec.rb