This repository has been archived by the owner on Aug 15, 2018. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added page controller test, initial xml output for pages
- Loading branch information
Josh Adams
committed
Apr 20, 2009
1 parent
5bd3c74
commit 8592dcf
Showing
12 changed files
with
255 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
require 'hpricot' | ||
|
||
module HpricotTestHelper | ||
# returns the inner content of | ||
# the first tag found by the css query | ||
def tag(css_query) | ||
process_output | ||
@output.content_for(css_query) | ||
end | ||
|
||
# returns an array of tag contents | ||
# for all of the tags found by the | ||
# css query | ||
def tags(css_query) | ||
process_output | ||
@output.content_for_all(css_query) | ||
end | ||
|
||
# returns a raw Hpricot::Elem object | ||
# for the first result found by the query | ||
def element(css_query) | ||
process_output | ||
@output[css_query].first | ||
end | ||
|
||
# returns an array of Hpricot::Elem objects | ||
# for the results found by the query | ||
def elements(css_query) | ||
process_output | ||
@output[css_query] | ||
end | ||
|
||
# small utility class for working with | ||
# the Hpricot parser class | ||
class DocumentOutput | ||
def initialize(response_body) | ||
@parser = Hpricot.parse(response_body) | ||
end | ||
|
||
def content_for(css_query) | ||
@parser.search(css_query).first.inner_text | ||
end | ||
|
||
def content_for_all(css_query) | ||
@parser.search(css_query).collect(&:inner_text) | ||
end | ||
|
||
def [](css_query) | ||
@parser.search(css_query) | ||
end | ||
end | ||
|
||
protected | ||
# creates a new DocumentOutput object from the response | ||
# body if hasn't already been created. This is | ||
# called automatically by the element and tag methods | ||
def process_output(force=false) | ||
@output = HpricotTestHelper::DocumentOutput.new(@response.body) if @output.nil? || force | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
Factory.sequence :page_name do |pn| | ||
"Page #{pn}" | ||
"home#{pn}" | ||
end | ||
|
||
Factory.sequence :user_login do |n| | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
home_content: | ||
id: 1 | ||
name: home content | ||
contents: These are the contents |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,6 @@ | ||
# == Schema Information | ||
# Schema version: 20090125222830 | ||
# | ||
# Table name: page_plugins | ||
# | ||
# id :integer(4) not null, primary key | ||
# page_id :integer(4) | ||
# module_type :string(255) | ||
# module_id :integer(4) | ||
# created_at :datetime | ||
# updated_at :datetime | ||
# position :integer(4) | ||
# | ||
|
||
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html | ||
|
||
one: | ||
home_content: | ||
id: 1 | ||
page_id: 1 | ||
module_type: MyString | ||
module_id: | ||
|
||
two: | ||
page_id: 1 | ||
module_type: MyString | ||
module_id: | ||
module_type: "Ansuz::JAdams::ContentSection" | ||
module_id: 1 | ||
position: 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
# == Schema Information | ||
# Schema version: 2 | ||
# | ||
# Table name: pages | ||
# | ||
# id :integer(11) not null, primary key | ||
# name :string(255) | ||
# title :string(255) | ||
# full_title :string(255) | ||
# body :text | ||
# created_at :datetime | ||
# updated_at :datetime | ||
# page_order :integer(11) default(0) | ||
# parent_id :integer(11) | ||
# page_type :string(255) default("page") | ||
# display_title :boolean(1) default(TRUE) | ||
# published :boolean(1) default(TRUE) | ||
# linked :boolean(1) default(TRUE) | ||
# show_sub_menu :boolean(1) | ||
# | ||
|
||
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html | ||
home: | ||
id: 1 | ||
name: home | ||
title: Home | ||
full_title: Home Page | ||
published: true | ||
status: published | ||
linked: true | ||
|
||
second_level: | ||
id: 2 | ||
name: second | ||
title: Second Level | ||
parent_id: 1 | ||
published: true | ||
status: published | ||
linked: true | ||
|
||
third_level: | ||
id: 3 | ||
name: third | ||
title: Third Level | ||
parent_id: 2 | ||
published: true | ||
status: published | ||
linked: true | ||
|
||
fourth_level: | ||
id: 9 | ||
name: fourth | ||
title: Fourth Level | ||
parent_id: 3 | ||
published: true | ||
status: published | ||
linked: true | ||
|
||
unpublished: | ||
id: 4 | ||
name: unpublished | ||
title: Unpublished | ||
parent_id: 2 | ||
published: false | ||
status: draft | ||
linked: false | ||
|
||
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 | ||
|
||
expired: | ||
id: 245 | ||
name: Expired | ||
title: Expired test | ||
parent_id: 9 | ||
page_order: 5 | ||
expires_on: <%= 2.days.ago %> |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
require 'test_helper' | ||
|
||
class PageControllerTest < ActionController::TestCase | ||
context "When hitting /pages/" do | ||
setup do | ||
# set up a page to visit | ||
@page = pages(:home) | ||
end | ||
context "as a public user" do | ||
context "for html" do | ||
setup do | ||
get :indexer, :path => ["home"] | ||
end | ||
|
||
should_respond_with :ok | ||
should "have the content section module's content included" do | ||
assert_select "div.page-plugin-0" | ||
end | ||
end | ||
|
||
context "for xml" do | ||
setup do | ||
get :indexer, :path => ["home.xml"] | ||
end | ||
|
||
should_respond_with :ok | ||
should "have the content section module's content included" do | ||
assert tag("page page-plugins page-plugin contents") | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters