Sha256: 7f0d45df7cfebfafcbb2819dfce3d8889437d12fb0cbc36b96833300b5384105

Contents?: true

Size: 1.91 KB

Versions: 12

Compression:

Stored size: 1.91 KB

Contents

require 'spec_helper'

module Alchemy
  describe ElementsController do
    let(:public_page)         { FactoryGirl.create(:public_page) }
    let(:element)             { FactoryGirl.create(:element, :page => public_page, :name => 'download') }
    let(:restricted_page)     { FactoryGirl.create(:public_page, :restricted => true) }
    let(:restricted_element)  { FactoryGirl.create(:element, :page => restricted_page, :name => 'download') }

    describe '#show' do
      it "should render available elements" do
        get :show, :id => element.id
        expect(response.status).to eq(200)
      end

      it "should raise ActiveRecord::RecordNotFound error for trashed elements" do
        element.trash!
        expect { get(:show, :id => element.id) }.to raise_error(ActiveRecord::RecordNotFound)
      end

      it "should raise ActiveRecord::RecordNotFound error for unpublished elements" do
        element.update_attributes(:public => false)
        expect { get(:show, :id => element.id) }.to raise_error(ActiveRecord::RecordNotFound)
      end

      context "for guest user" do
        it "should raise ActiveRecord::RecordNotFound error for elements of restricted pages" do
          expect { get(:show, :id => restricted_element.id) }.to raise_error(ActiveRecord::RecordNotFound)
        end
      end

      context "for member user" do
        before { sign_in(member_user) }

        it "should render elements of restricted pages" do
          get :show, :id => restricted_element.id
          expect(response.status).to eq(200)
        end
      end

      context "requested for json format" do
        it "should render json response but warns about deprecation" do
          expect(ActiveSupport::Deprecation).to receive(:warn)
          get :show, id: element.id, format: :json
          expect(response.status).to eq(200)
          expect(response.content_type).to eq('application/json')
        end
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
alchemy_cms-3.1.3 spec/controllers/elements_controller_spec.rb
alchemy_cms-3.1.1 spec/controllers/elements_controller_spec.rb
alchemy_cms-3.1.0 spec/controllers/elements_controller_spec.rb
alchemy_cms-3.1.0.rc3 spec/controllers/elements_controller_spec.rb
alchemy_cms-3.1.0.rc2 spec/controllers/elements_controller_spec.rb
alchemy_cms-3.1.0.rc1 spec/controllers/elements_controller_spec.rb
alchemy_cms-3.1.0.beta6 spec/controllers/elements_controller_spec.rb
alchemy_cms-3.1.0.beta5 spec/controllers/elements_controller_spec.rb
alchemy_cms-3.1.0.beta4 spec/controllers/elements_controller_spec.rb
alchemy_cms-3.1.0.beta3 spec/controllers/elements_controller_spec.rb
alchemy_cms-3.1.0.beta2 spec/controllers/elements_controller_spec.rb
alchemy_cms-3.1.0.beta1 spec/controllers/elements_controller_spec.rb