Sha256: 9cc3b57e9de11134699531f05badaceeb447a64b19fb0d81f4dc526f9d45b11a

Contents?: true

Size: 1.68 KB

Versions: 8

Compression:

Stored size: 1.68 KB

Contents

require 'spec_helper'

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

module Alchemy
  describe AttachmentsController do

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

    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

    context "as registered user" do

      before do
        sign_in :user, FactoryGirl.create(: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 :user, FactoryGirl.create(: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

8 entries across 8 versions & 1 rubygems

Version Path
alchemy_cms-2.5.3.1 spec/controllers/attachments_controller_spec.rb
alchemy_cms-2.5.3 spec/controllers/attachments_controller_spec.rb
alchemy_cms-2.5.2.2 spec/controllers/attachments_controller_spec.rb
alchemy_cms-2.5.2.1 spec/controllers/attachments_controller_spec.rb
alchemy_cms-2.5.2 spec/controllers/attachments_controller_spec.rb
alchemy_cms-2.5.1 spec/controllers/attachments_controller_spec.rb
alchemy_cms-2.5.0 spec/controllers/attachments_controller_spec.rb
alchemy_cms-2.5.0.rc3 spec/controllers/attachments_controller_spec.rb