Sha256: 1b67569bf456b810119590a09042e83f052c912908b8f38cdd4106529fd7553e

Contents?: true

Size: 1.78 KB

Versions: 9

Compression:

Stored size: 1.78 KB

Contents

require 'spec_helper'

# Fixes missing method tempfile error
class Rack::Test::UploadedFile
  attr_reader :tempfile
end

module Alchemy
  describe AttachmentsController do

    let(:public_page) { FactoryGirl.create(:public_page, :restricted => true) }
    let(:element)     { FactoryGirl.create(:element, :page => public_page, :name => 'download', :create_contents_after_create => true) }
    let(:attachment)  { Attachment.create(:file => File.new(File.expand_path('../../support/image.png', __FILE__))) }

    before do
      essence = element.contents.where(:name => 'file').first.essence
      essence.attachment_id = attachment.id
      essence.save
    end

    it "should not be possible to download attachments from restricted pages" do
      get :download, :id => attachment.id
      response.status.should == 302
      response.should redirect_to(login_path)
    end

    it "should raise ActiveRecord::RecordNotFound for requesting not existing attachments" do
      expect { get :download, id: 0 }.to raise_error(ActiveRecord::RecordNotFound)
    end

    context "as registered user" do

      before do
        sign_in(registered_user)
      end

      it "should be possible to download attachments from restricted pages" do
        get :download, :id => attachment.id
        response.status.should == 200
      end

    end

    it "should not be possible to see attachments from restricted pages" do
      get :show, :id => attachment.id
      response.status.should == 302
      response.should redirect_to(login_path)
    end

    context "as registered user" do

      before do
        sign_in(registered_user)
      end

      it "should be possible to see attachments from restricted pages" do
        get :show, :id => attachment.id
        response.status.should == 200
      end

    end

  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
alchemy_cms-2.8.3 spec/controllers/attachments_controller_spec.rb
alchemy_cms-2.7.5 spec/controllers/attachments_controller_spec.rb
alchemy_cms-2.7.4 spec/controllers/attachments_controller_spec.rb
alchemy_cms-2.8.2 spec/controllers/attachments_controller_spec.rb
alchemy_cms-2.8.1 spec/controllers/attachments_controller_spec.rb
alchemy_cms-2.7.3 spec/controllers/attachments_controller_spec.rb
alchemy_cms-2.7.2 spec/controllers/attachments_controller_spec.rb
alchemy_cms-2.7.1 spec/controllers/attachments_controller_spec.rb
alchemy_cms-2.7.0 spec/controllers/attachments_controller_spec.rb