Sha256: a1ca66c524d065ef3aae121e03737819e81e3efcdb516d8cff105058a2b50497

Contents?: true

Size: 1.21 KB

Versions: 24

Compression:

Stored size: 1.21 KB

Contents

require 'spec_helper'

class ::TestIfBindingController < Volt::ModelController
  model :page
end

describe Volt::IfBinding do
  it 'should render an if' do
    dom = Volt::AttributeTarget.new(0)
    context = ::TestIfBindingController.new(volt_app)
    context._name = 'jimmy'

    branches = [
      [
        proc { _name == 'jimmy' },
        'main/if_true'
      ],
      [
        nil,
        'main/if_false'
      ]
    ]

    binding = ->(volt_app, target, context, id) do
      Volt::IfBinding.new(volt_app, target, context, 0, branches)
    end

    templates = {
      'main/main' => {
        'html' => 'hello <!-- $1 --><!-- $/1 -->',
        'bindings' => { 1 => [binding] }
      },
      'main/if_true' => {
        'html' => 'yes, true',
        'bindings' => {}
      },
      'main/if_false' => {
        'html' => 'no, false',
        'bindings' => {}
      }
    }

    volt_app = double('volt/app')
    expect(volt_app).to receive(:templates).and_return(templates).at_least(1).times

    Volt::TemplateRenderer.new(volt_app, dom, context, 'main', 'main/main')

    expect(dom.to_html).to eq('yes, true')

    context._name = 'bob'
    Volt::Computation.flush!
    expect(dom.to_html).to eq('no, false')
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
volt-0.9.7.pre8 spec/page/bindings/if_binding_spec.rb
volt-0.9.7.pre7 spec/page/bindings/if_binding_spec.rb
volt-0.9.7.pre6 spec/page/bindings/if_binding_spec.rb
volt-0.9.7.pre5 spec/page/bindings/if_binding_spec.rb
volt-0.9.7.pre3 spec/page/bindings/if_binding_spec.rb
volt-0.9.7.pre2 spec/page/bindings/if_binding_spec.rb
volt-0.9.6 spec/page/bindings/if_binding_spec.rb
volt-0.9.6.pre3 spec/page/bindings/if_binding_spec.rb
volt-0.9.6.pre2 spec/page/bindings/if_binding_spec.rb
volt-0.9.6.pre1 spec/page/bindings/if_binding_spec.rb
volt-0.9.5 spec/page/bindings/if_binding_spec.rb
volt-0.9.5.pre12 spec/page/bindings/if_binding_spec.rb
volt-0.9.5.pre11 spec/page/bindings/if_binding_spec.rb
volt-0.9.5.pre9 spec/page/bindings/if_binding_spec.rb
volt-0.9.5.pre8 spec/page/bindings/if_binding_spec.rb
volt-0.9.5.pre7 spec/page/bindings/if_binding_spec.rb
volt-0.9.5.pre6 spec/page/bindings/if_binding_spec.rb
volt-0.9.5.pre5 spec/page/bindings/if_binding_spec.rb
volt-0.9.5.pre4 spec/page/bindings/if_binding_spec.rb
volt-0.9.5.pre3 spec/page/bindings/if_binding_spec.rb