Sha256: ebda6e7d58b7c6187fad9331845cd16d2d0527715c279b49a5af75f8c215abfb

Contents?: true

Size: 1.42 KB

Versions: 13

Compression:

Stored size: 1.42 KB

Contents

require 'spec_helper'

describe Locomotive::Steam::Liquid::Tags::Authorize do

  let(:site)        { instance_double('Site', default_locale: 'en', prefix_default_locale: false) }
  let(:page)        { instance_double('Page', fullpath: 'me/sign_in', templatized?: false) }
  let(:page_handle) { "'sign_in'" }
  let(:source)      { "{% authorize 'accounts', #{page_handle} %}Hello world!" }
  let(:assigns)     { {} }
  let(:services)    { Locomotive::Steam::Services.build_instance }
  let(:context)     { ::Liquid::Context.new(assigns, {}, { services: services }) }

  before {
    allow(services).to receive(:current_site).and_return(site)
    allow(services.page_finder).to receive(:by_handle).and_return(page)
  }

  subject { render_template(source, context) }

  describe 'validating syntax' do

    describe 'no page handle' do
      let(:source) { '{% authorize accounts %}' }
      it { expect { subject }.to raise_exception(Liquid::SyntaxError) }
    end

  end

  describe '#render' do

    context 'unauthenticated account' do

      it 'redirects to the sign in page' do
        expect { subject }.to raise_error(Locomotive::Steam::RedirectionException, 'Redirect to /me/sign_in (302)')
      end

    end

    context 'authenticated account' do

      let(:assigns) { { 'current_account' => liquid_instance_double('Account', {}) } }

      it 'renders the page' do
        expect(subject).to eq 'Hello world!'
      end

    end

  end

end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
locomotivecms_steam-1.8.0.alpha2 spec/unit/liquid/tags/authorize_spec.rb
locomotivecms_steam-1.8.0.alpha1 spec/unit/liquid/tags/authorize_spec.rb
locomotivecms_steam-1.7.1 spec/unit/liquid/tags/authorize_spec.rb
locomotivecms_steam-1.7.0 spec/unit/liquid/tags/authorize_spec.rb
locomotivecms_steam-1.6.1 spec/unit/liquid/tags/authorize_spec.rb
locomotivecms_steam-1.6.0 spec/unit/liquid/tags/authorize_spec.rb
locomotivecms_steam-1.6.0.rc1 spec/unit/liquid/tags/authorize_spec.rb
locomotivecms_steam-1.6.0.beta1 spec/unit/liquid/tags/authorize_spec.rb
locomotivecms_steam-1.5.3 spec/unit/liquid/tags/authorize_spec.rb
locomotivecms_steam-1.5.2 spec/unit/liquid/tags/authorize_spec.rb
locomotivecms_steam-1.5.1 spec/unit/liquid/tags/authorize_spec.rb
locomotivecms_steam-1.5.0 spec/unit/liquid/tags/authorize_spec.rb
locomotivecms_steam-1.5.0.rc1 spec/unit/liquid/tags/authorize_spec.rb