engine/spec/models/snippet_spec.rb

55 lines
1.5 KiB
Ruby
Raw Normal View History

require 'spec_helper'
describe Snippet do
it 'should have a valid factory' do
2011-08-25 21:28:56 +00:00
FactoryGirl.build(:snippet).should be_valid
end
2011-08-25 21:28:56 +00:00
# Validations ##
%w{site name template}.each do |field|
it "should validate presence of #{field}" do
2011-08-25 21:28:56 +00:00
template = FactoryGirl.build(:snippet, field.to_sym => nil)
template.should_not be_valid
template.errors[field.to_sym].should == ["can't be blank"]
end
end
describe '#update_templates' do
2011-08-25 21:28:56 +00:00
before :each do
2011-08-25 21:28:56 +00:00
@site = FactoryGirl.create(:site, :subdomain => 'omg')
@snippet = FactoryGirl.create(:snippet, :site => @site, :slug => 'my_test_snippet', :template => 'a testing template')
end
context 'with a normal top level snippet' do
before :each do
2011-08-25 21:28:56 +00:00
@page = FactoryGirl.create(:page, :site => @site, :slug => 'my_page_here', :raw_template => "{% include 'my_test_snippet' %}")
end
it 'updates templates with the new snippet template' do
@snippet.update_attributes(:template => 'a new template')
Page.find(@page.id).render({}).should == 'a new template'
end
end
context 'for snippets inside of a block' do
before :each do
2011-08-25 21:28:56 +00:00
@page = FactoryGirl.create(:page, :site => @site, :slug => 'my_page_here', :raw_template => "{% block main %}{% include 'my_test_snippet' %}{% endblock %}")
end
it 'updates templates with the new snippet template' do
@snippet.update_attributes(:template => 'a new template')
Page.find(@page.id).render({}).should == 'a new template'
end
end
end
end