Skip to content
This repository has been archived by the owner on Aug 15, 2018. It is now read-only.

Commit

Permalink
[PAGES] Imported old pages unit tests and ported it over to rspec. Ca…
Browse files Browse the repository at this point in the history
…ught several bugs in Page model due to slight changes to the database schema.
  • Loading branch information
hosh committed Aug 23, 2008
1 parent e8986a1 commit 6dee4f4
Show file tree
Hide file tree
Showing 4 changed files with 937 additions and 1 deletion.
7 changes: 6 additions & 1 deletion app/models/page.rb
Expand Up @@ -12,6 +12,7 @@ def full_title
end
end

# TODO: Convert to named_scope
def self_and_siblings
Page.find(:all, :conditions => ["parent_id = ?", self.parent_id], :order => 'page_order')
end
Expand Down Expand Up @@ -67,6 +68,9 @@ def page_body(page = self.page_number)
# page/0 should return nil (out of bound)
# page/n where n > pages should return nil (out of bound)
#
# TODO: Possible bug:
# - @split_pages is cached, so if you change the body again and then call
# split_page!, the code looks like it will ignore the cache
def split_page!(page_number = 1)
if self.page_type == 'page'
self[:page_body] = self.body
Expand Down Expand Up @@ -112,7 +116,8 @@ def last_page

protected
def check_page_type
self.page_type = ((@split_pages = self.body.split(/\{pagebreak\}/i)).length > 1) ? "multipage": "page"
self.page_type = "page" and return if self.body.blank? || (@split_pages = self.body.split(/\{pagebreak\}/i)).length == 1
self.page_type = "multipage"
end

def check_page_order
Expand Down
70 changes: 70 additions & 0 deletions spec/fixtures/pages.yml
@@ -0,0 +1,70 @@
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
home:
id: 1
name: home
title: Home
full_title: Home Page
published: 1
linked: 1

second_level:
id: 2
name: second
title: Second Level
parent_id: 1
published: 1
linked: 1

third_level:
id: 3
name: third
title: Third Level
parent_id: 2
published: 1
linked: 1

fourth_level:
id: 9
name: fourth
title: Fourth Level
parent_id: 3
published: 1
linked: 1

unpublished:
id: 4
name: unpublished
title: Unpublished
parent_id: 2
published: 0
linked: 0

swap_test:
id: 5
name: swap_test
title: Swap Test
parent_id: 1

swap_test1:
id: 6
name: swap1
title: Swap Test 1
parent_id: 5
page_order: 1

swap_test2:
id: 7
name: swap2
title: Swap Test 2
parent_id: 5
page_order: 3

swap_test3:
id: 8
name: swap3
title: Swap Test 3
parent_id: 5
page_order: 4



0 comments on commit 6dee4f4

Please sign in to comment.