spec/models/landable/template_spec.rb in landable-1.7.0 vs spec/models/landable/template_spec.rb in landable-1.7.1.rc1

- old
+ new

@@ -41,7 +41,74 @@ it 'returns false when template has no file' do template = create :template template.partial?.should be_false end end + + describe '#publish' do + let(:template) { FactoryGirl.create :template } + let(:author) { FactoryGirl.create :author } + + it 'should create a template_revision' do + expect {template.publish!(author: author)}.to change{template.revisions.count}.from(0).to(1) + end + + it 'should have the provided author' do + template.publish! author: author + revision = template.revisions.last + + revision.author.should == author + end + + it 'should update the published_revision_id' do + template.publish! author: author + revision = template.revisions.last + + template.published_revision.should == revision + end + + it 'should unset previous revision.is_published' do + template.publish! author: author + revision1 = template.published_revision + template.publish! author: author + revision1.is_published.should be_false + end + end + + describe '#revert_to' do + let(:template) { FactoryGirl.create :template } + let(:author) { FactoryGirl.create :author } + + it 'should NOT update published_revision for the page' do + template.name = 'Bar' + template.publish! author: author + revision = template.published_revision + + template.name = 'Foo' + template.publish! author: author + + template.revert_to! revision + + template.published_revision.id.should_not == revision.id + end + + it 'should copy revision attributes into the page model' do + template.name = 'Bar' + template.publish! author: author + + revision = template.published_revision + + template.name = 'Foo' + template.save! + template.publish! author: author + + # ensure assignment for all copied attributes + keys = %w(name body description slug) + keys.each do |key| + template.should_receive("#{key}=").with(revision.send(key)) + end + + template.revert_to! revision + end + end end end