Sha256: 7fa731720ae31edfc91b5cace86e12cc2815238240e91ae3c118f2932722c076

Contents?: true

Size: 1.2 KB

Versions: 8

Compression:

Stored size: 1.2 KB

Contents

require 'spec_helper'

describe Locomotive::Steam::Liquid::Tags::Action do

  let(:site)      { instance_double('Site', default_locale: 'en') }
  let(:source)    { '{% action "random Javascript action" %}var foo = 42; setProp("foo", foo);{% endaction %}' }
  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) }

  subject { render_template(source, context) }

  describe 'parsing' do

    describe 'raises an error if the syntax is incorrect' do
      let(:source) { '{% action %}{% endaction %}' }
      it { expect { subject }.to raise_exception(Liquid::SyntaxError) }
    end

  end

  describe 'rendering' do

    it { is_expected.to eq '' }

    it { subject; expect(context['foo']).to eq 42.0 }

    describe 'uploaded file' do

      let(:assigns) { { 'params' => { 'my_file' => { 'tempfile' => Tempfile.new('my_file') } } } }
      let(:source)  { '{% action "uploaded file" %}setProp("path", params.my_file.tempfile);{% endaction %}' }

      it { subject; expect(context['path']).to match /\/my_file/ }

    end

  end

end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
locomotivecms_steam-1.4.1 spec/unit/liquid/tags/action_spec.rb
locomotivecms_steam-1.4.0 spec/unit/liquid/tags/action_spec.rb
locomotivecms_steam-1.4.0.rc2 spec/unit/liquid/tags/action_spec.rb
locomotivecms_steam-1.4.0.rc1 spec/unit/liquid/tags/action_spec.rb
locomotivecms_steam-1.4.0.pre.rc.1 spec/unit/liquid/tags/action_spec.rb
locomotivecms_steam-1.3.0 spec/unit/liquid/tags/action_spec.rb
locomotivecms_steam-1.3.0.rc2 spec/unit/liquid/tags/action_spec.rb
locomotivecms_steam-1.3.0.rc1 spec/unit/liquid/tags/action_spec.rb