2010-05-30 23:57:33 +00:00
|
|
|
require 'spec_helper'
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-05-30 23:57:33 +00:00
|
|
|
describe Locomotive::Liquid::Tags::WithScope do
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2011-04-28 23:16:40 +00:00
|
|
|
it 'should decode basic options (boolean, interger, ...)' do
|
2010-08-20 15:56:15 +00:00
|
|
|
scope = Locomotive::Liquid::Tags::WithScope.new('with_scope', 'active:true price:42 title:\'foo\' hidden:false', ["{% endwith_scope %}"], {})
|
2011-04-28 23:16:40 +00:00
|
|
|
attributes = scope.send(:decode, scope.instance_variable_get(:@attributes), {})
|
2010-05-30 23:57:33 +00:00
|
|
|
attributes['active'].should == true
|
|
|
|
attributes['price'].should == 42
|
|
|
|
attributes['title'].should == 'foo'
|
|
|
|
attributes['hidden'].should == false
|
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2011-04-28 23:16:40 +00:00
|
|
|
it 'should decode context variable' do
|
|
|
|
scope = Locomotive::Liquid::Tags::WithScope.new('with_scope', 'category: params.type', ["{% endwith_scope %}"], {})
|
|
|
|
attributes = scope.send(:decode, scope.instance_variable_get(:@attributes), { 'params.type' => 'posts' })
|
|
|
|
attributes['category'].should == 'posts'
|
|
|
|
end
|
|
|
|
|
2010-05-30 23:57:33 +00:00
|
|
|
it 'should store attributes in the context' do
|
|
|
|
template = ::Liquid::Template.parse("{% with_scope active:true title:'foo' %}{{ with_scope.active }}-{{ with_scope.title }}{% endwith_scope %}")
|
|
|
|
text = template.render
|
|
|
|
text.should == "true-foo"
|
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
|
|
|
|
end
|