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
|
|
|
|
2012-03-08 17:24:33 +00:00
|
|
|
it 'decodes basic options (boolean, integer, ...)' 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 %}"], {})
|
2012-03-08 17:24:33 +00:00
|
|
|
attributes = scope.send(:decode, scope.instance_variable_get(:@attributes), ::Liquid::Context.new)
|
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
|
|
|
|
2012-03-08 17:24:33 +00:00
|
|
|
it 'decodes more complex options' do
|
|
|
|
scope = Locomotive::Liquid::Tags::WithScope.new('with_scope', 'price.gt:42.0 price.lt:50', ["{% endwith_scope %}"], {})
|
|
|
|
attributes = scope.send(:decode, scope.instance_variable_get(:@attributes), ::Liquid::Context.new)
|
|
|
|
attributes['price.gt'].should == 42.0
|
|
|
|
attributes['price.lt'].should == 50
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'decodes context variable' do
|
2011-04-28 23:16:40 +00:00
|
|
|
scope = Locomotive::Liquid::Tags::WithScope.new('with_scope', 'category: params.type', ["{% endwith_scope %}"], {})
|
2012-03-08 17:24:33 +00:00
|
|
|
attributes = scope.send(:decode, scope.instance_variable_get(:@attributes), ::Liquid::Context.new({ 'params' => { 'type' => 'posts' } }))
|
2011-04-28 23:16:40 +00:00
|
|
|
attributes['category'].should == 'posts'
|
|
|
|
end
|
|
|
|
|
2012-03-08 17:24:33 +00:00
|
|
|
it 'stores attributes in the context' do
|
2010-05-30 23:57:33 +00:00
|
|
|
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
|
|
|
|
2012-03-08 17:24:33 +00:00
|
|
|
|
2010-07-23 20:09:54 +00:00
|
|
|
end
|