Skip to content

Commit

Permalink
Make sure a blog object is available for page specs.
Browse files Browse the repository at this point in the history
  • Loading branch information
mvz committed Apr 6, 2012
1 parent c82817e commit 1d0cb68
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
4 changes: 2 additions & 2 deletions app/models/page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Page < Content

before_save :set_permalink
after_save :shorten_url

def set_permalink
self.name = self.title.to_permalink if self.name.blank?
end
Expand All @@ -36,7 +36,7 @@ def self.search_paginate(search_hash, paginate_hash)
paginate_hash[:order] = 'title ASC'
list_function << "page(paginate_hash[:page])"
list_function << "per(paginate_hash[:per_page])"

eval(list_function.join('.'))
end

Expand Down
10 changes: 7 additions & 3 deletions spec/models/page_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,28 @@

describe "Testing redirects" do
it "a new published page gets a redirect" do
Factory(:blog)
a = Page.create(:title => "Some title", :body => "some text", :published => true)
a.should be_valid
a.redirects.first.should_not be_nil
a.redirects.first.to_path.should == a.permalink_url
end

it "a new unpublished page should not get a redirect" do
Factory(:blog)
a = Page.create(:title => "Some title", :body => "some text", :published => true)
a = Page.create(:title => "Another title", :body => "some text", :published => false)
a.redirects.first.should be_nil
end

it "Changin a published article permalink url should only change the to redirection" do
Factory(:blog)
a = Page.create(:title => "Third title", :body => "some text", :published => true)
a.should be_valid
a.redirects.first.should_not be_nil
a.redirects.first.to_path.should == a.permalink_url
r = a.redirects.first.from_path

a.name = "some-new-permalink"
a.save
a.redirects.first.should_not be_nil
Expand Down

0 comments on commit 1d0cb68

Please sign in to comment.