2010-07-06 00:05:47 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Locomotive::Liquid::Tags::Consume do
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-07-06 00:05:47 +00:00
|
|
|
context '#validating syntax' do
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-07-06 00:05:47 +00:00
|
|
|
it 'validates a basic syntax' do
|
|
|
|
markup = 'blog from "http://blog.locomotiveapp.org"'
|
|
|
|
lambda do
|
|
|
|
Locomotive::Liquid::Tags::Consume.new('consume', markup, ["{% endconsume %}"])
|
|
|
|
end.should_not raise_error
|
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-07-06 00:05:47 +00:00
|
|
|
it 'validates more complex syntax with attributes' do
|
|
|
|
markup = 'blog from "http://www.locomotiveapp.org" username: "john", password: "easyone"'
|
|
|
|
lambda do
|
|
|
|
Locomotive::Liquid::Tags::Consume.new('consume', markup, ["{% endconsume %}"])
|
|
|
|
end.should_not raise_error
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'raises an error if the syntax is incorrect' do
|
|
|
|
markup = 'blog from http://www.locomotiveapp.org'
|
|
|
|
lambda do
|
|
|
|
Locomotive::Liquid::Tags::Consume.new('consume', markup, ["{% endconsume %}"])
|
|
|
|
end.should raise_error
|
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-07-06 00:05:47 +00:00
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-07-06 00:05:47 +00:00
|
|
|
context '#rendering' do
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-07-06 00:05:47 +00:00
|
|
|
it 'puts the response into the liquid variable' do
|
|
|
|
Locomotive::Httparty::Webservice.stubs(:get).returns({ 'title' => 'Locomotive rocks !' })
|
|
|
|
template = "{% consume blog from \"http://blog.locomotiveapp.org/api/read\" %}{{ blog.title }}{% endconsume %}"
|
|
|
|
Liquid::Template.parse(template).render.should == 'Locomotive rocks !'
|
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-07-06 00:05:47 +00:00
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
|
|
|
|
end
|