Skip to content

Commit

Permalink
Added tests for content node rss feed, paragraph. Fixed rss title for…
Browse files Browse the repository at this point in the history
… content node.
  • Loading branch information
Doug Youch committed Feb 19, 2010
1 parent 88653fa commit 81ecc33
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 7 deletions.
4 changes: 0 additions & 4 deletions app/controllers/editor/content_controller.rb
Expand Up @@ -25,10 +25,6 @@ def content_type_options
ContentType.select_options
end

def yes_no
[["Yes".t,true],["No".t,false]]
end

def order_by_options
[['Newest', 'newest'], ['Recently Updated', 'updated']]
end
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/editor/content_feature.rb
Expand Up @@ -20,8 +20,8 @@ def recent_content_feature(data)
def content_node_tags(prefix, c, data)
c.h_tag(prefix + ':title') { |t| t.locals.content.title }
c.h_tag(prefix + ':author') { |t| t.locals.content.author.name if t.locals.content.author }
c.h_tag(prefix + ':category') { |t| t.locals.content.content_type.type_description }
c.h_tag(prefix + ':type') { |t| t.locals.content.content_type.content_name }
c.h_tag(prefix + ':category') { |t| t.locals.content.content_type.type_description if t.locals.content.content_type }
c.h_tag(prefix + ':type') { |t| t.locals.content.content_type.content_name if t.locals.content.content_type }
c.link_tag(prefix + ':content') { |t| t.locals.content.link }
c.date_tag(prefix + ':updated_at',DEFAULT_DATETIME_FORMAT.t) { |t| t.locals.content.updated_at }
c.date_tag(prefix + ':created_at',DEFAULT_DATETIME_FORMAT.t) { |t| t.locals.content.created_at }
Expand Down
28 changes: 28 additions & 0 deletions spec/controllers/editor/content_feature_spec.rb
@@ -0,0 +1,28 @@
require File.dirname(__FILE__) + "/../../spec_helper"

describe Editor::ContentFeature, :type => :view do

reset_domain_tables :site_nodes, :content_nodes, :site_versions, :content_types

before(:each) do
@feature = build_feature('/editor/content_feature')
end

it "should render recent content" do
SiteVersion.default.root_node.add_subpage('home')
SiteVersion.default.root_node.add_subpage('about-us')
SiteVersion.default.root_node.add_subpage('contact')

@type = ContentType.create :component => 'editor', :content_name => 'Static Pages', :content_type => 'SiteNode', :title_field => 'name', :url_field => 'id', :search_results => 1, :editable => 0, :created_at => Time.now, :updated_at => Time.now
@type.id.should_not be_nil
ContentNode.update_all :content_type_id => @type.id

@nodes = ContentNode.find(:all, :limit => 10)

@output = @feature.recent_content_feature(:nodes => @nodes)
@output.should include('home')
@output.should include('about-us')
@output.should include('contact')
@output.should include('Static Pages')
end
end
35 changes: 35 additions & 0 deletions spec/controllers/editor/content_renderer_spec.rb
@@ -0,0 +1,35 @@
require File.dirname(__FILE__) + "/../../spec_helper"


describe Editor::ContentRenderer, :type => :controller do
controller_name :page

integrate_views

describe "Recent Content Paragraph" do
def generate_renderer(data = {})
build_renderer('/page','/editor/content/recent_content',data,{})
end

it "should render the recent content paragraph" do
ContentNode.should_receive(:find).once.with(:all, :conditions => nil, :limit => 10, :order => 'created_at DESC').and_return([])
@rnd = generate_renderer
@rnd.should_render_feature("recent_content")
renderer_get @rnd
end

it "should render the recent content paragraph for specific types" do
ContentNode.should_receive(:find).once.with(:all, :conditions => {:content_type_id => [4, 5]}, :limit => 10, :order => 'created_at DESC').and_return([])
@rnd = generate_renderer :content_type_ids => [4, 5]
@rnd.should_render_feature("recent_content")
renderer_get @rnd
end

it "should render the recent content paragraph by most recently updated" do
ContentNode.should_receive(:find).once.with(:all, :conditions => nil, :limit => 5, :order => 'updated_at DESC').and_return([])
@rnd = generate_renderer :order_by => 'updated', :count => 5
@rnd.should_render_feature("recent_content")
renderer_get @rnd
end
end
end
Expand Up @@ -13,7 +13,7 @@ def initialize(options)
end

def get_feed
data = { :title => @options.title,
data = { :title => @options.feed_title,
:description => @options.description,
:link => Configuration.domain_link(@options.link_url),
:items => []}
Expand Down
@@ -0,0 +1,27 @@
require File.expand_path(File.dirname(__FILE__)) + "/../../../../../../spec/spec_helper"

describe Feed::ContentNodeRssHandler do

reset_domain_tables :site_nodes, :content_nodes, :site_versions, :content_types

it "should create the data for a content node rss feed" do
home = SiteVersion.default.root_node.add_subpage('home')
SiteVersion.default.root_node.add_subpage('about-us')
SiteVersion.default.root_node.add_subpage('contact')

@type = ContentType.create :component => 'editor', :content_name => 'Static Pages', :content_type => 'SiteNode', :title_field => 'name', :url_field => 'id', :search_results => 1, :editable => 0, :created_at => Time.now, :updated_at => Time.now
@type.id.should_not be_nil
ContentNode.update_all :content_type_id => @type.id

@options = Feed::ContentNodeRssHandler::Options.new({:feed_title => 'My Static Pages', :description => 'My Description for static pages', :link_id => home.id})
@feed = Feed::ContentNodeRssHandler.new(@options)
data = @feed.get_feed
data[:title].should == 'My Static Pages'
data[:description].should == 'My Description for static pages'
data[:link].should include('/home')

data[:items].detect { |item| item[:link].include?('/home') && item[:title] == 'Home' }.should be_true
data[:items].detect { |item| item[:link].include?('/about-us') && item[:title] == 'About Us' }.should be_true
data[:items].detect { |item| item[:link].include?('/contact') && item[:title] == 'Contact' }.should be_true
end
end

0 comments on commit 81ecc33

Please sign in to comment.