Sha256: 1b5013700cba81df586c0f156e3e497c124a27f839392c55d12ba5e3746279d3

Contents?: true

Size: 1.41 KB

Versions: 12

Compression:

Stored size: 1.41 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')
      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

12 entries across 12 versions & 1 rubygems

Version Path
locomotivecms_steam-1.5.0.rc0 spec/unit/liquid/tags/authorize_spec.rb
locomotivecms_steam-1.5.0.beta3 spec/unit/liquid/tags/authorize_spec.rb
locomotivecms_steam-1.5.0.beta2 spec/unit/liquid/tags/authorize_spec.rb
locomotivecms_steam-1.5.0.beta1 spec/unit/liquid/tags/authorize_spec.rb
locomotivecms_steam-1.4.1 spec/unit/liquid/tags/authorize_spec.rb
locomotivecms_steam-1.4.0 spec/unit/liquid/tags/authorize_spec.rb
locomotivecms_steam-1.4.0.rc2 spec/unit/liquid/tags/authorize_spec.rb
locomotivecms_steam-1.4.0.rc1 spec/unit/liquid/tags/authorize_spec.rb
locomotivecms_steam-1.4.0.pre.rc.1 spec/unit/liquid/tags/authorize_spec.rb
locomotivecms_steam-1.3.0 spec/unit/liquid/tags/authorize_spec.rb
locomotivecms_steam-1.3.0.rc2 spec/unit/liquid/tags/authorize_spec.rb
locomotivecms_steam-1.3.0.rc1 spec/unit/liquid/tags/authorize_spec.rb