Cucumber tag steps now pass.

This commit is contained in:
Uģis Ozols 2011-07-27 22:32:26 +03:00
parent ded42bc691
commit 164dc27a42
12 changed files with 88 additions and 86 deletions

View file

@ -73,10 +73,9 @@ module Refinery
def tagged def tagged
@tag = ActsAsTaggableOn::Tag.find(params[:tag_id]) @tag = ActsAsTaggableOn::Tag.find(params[:tag_id])
@tag_name = @tag.name @tag_name = @tag.name
@blog_posts = Refinery::BlogPost.tagged_with(@tag_name).paginate({ @blog_posts = Refinery::BlogPost.tagged_with(@tag_name)
:page => params[:page], .page(params[:page])
:per_page => Refinery::Setting.find_or_set(:blog_posts_per_page, 10) .per(Refinery::Setting.find_or_set(:blog_posts_per_page, 10))
})
end end
protected protected
@ -92,10 +91,10 @@ module Refinery
end end
def find_all_blog_posts def find_all_blog_posts
@blog_posts = Refinery::BlogPost.live.includes(:comments, :categories).paginate({ @blog_posts = Refinery::BlogPost.live
:page => params[:page], .includes(:comments, :categories)
:per_page => Refinery::Setting.find_or_set(:blog_posts_per_page, 10) .page(params[:page])
}) .per(Refinery::Setting.find_or_set(:blog_posts_per_page, 10))
end end
def find_tags def find_tags

View file

@ -1,7 +1,7 @@
module Refinery module Refinery
class BlogController < ::ApplicationController class BlogController < ::ApplicationController
helper :blog_posts helper :'refinery/blog_posts'
before_filter :find_page, :find_all_blog_categories before_filter :find_page, :find_all_blog_categories
protected protected

View file

@ -1,59 +0,0 @@
module BlogPostsHelper
def blog_archive_list
posts = BlogPost.select('published_at').all_previous
return nil if posts.blank?
html = '<section id="blog_archive_list"><h2>'
html << t('archives', :scope => 'blog.shared')
html << '</h2><nav><ul>'
links = []
super_old_links = []
posts.each do |e|
if e.published_at >= Time.now.end_of_year.advance(:years => -3)
links << e.published_at.strftime('%m/%Y')
else
super_old_links << e.published_at.strftime('01/%Y')
end
end
links.uniq!
super_old_links.uniq!
links.each do |l|
year = l.split('/')[1]
month = l.split('/')[0]
count = BlogPost.by_archive(Time.parse(l)).size
text = t("date.month_names")[month.to_i] + " #{year} (#{count})"
html << "<li>"
html << link_to(text, archive_blog_posts_path(:year => year, :month => month))
html << "</li>"
end
super_old_links.each do |l|
year = l.split('/')[1]
count = BlogPost.by_year(Time.parse(l)).size
text = "#{year} (#{count})"
html << "<li>"
html << link_to(text, archive_blog_posts_path(:year => year))
html << "</li>"
end
html << '</ul></nav></section>'
html.html_safe
end
def next_or_previous?(post)
post.next.present? or post.prev.present?
end
def blog_post_teaser_enabled?
BlogPost.teasers_enabled?
end
def blog_post_teaser(post)
if post.respond_to?(:custom_teaser) && post.custom_teaser.present?
post.custom_teaser.html_safe
else
truncate(post.body, {
:length => RefinerySetting.find_or_set(:blog_post_teaser_length, 250),
:preserve_html_tags => true
}).html_safe
end
end
end

View file

@ -0,0 +1,61 @@
module Refinery
module BlogPostsHelper
def blog_archive_list
posts = Refinery::BlogPost.select('published_at').all_previous
return nil if posts.blank?
html = '<section id="blog_archive_list"><h2>'
html << t('archives', :scope => 'blog.shared')
html << '</h2><nav><ul>'
links = []
super_old_links = []
posts.each do |e|
if e.published_at >= Time.now.end_of_year.advance(:years => -3)
links << e.published_at.strftime('%m/%Y')
else
super_old_links << e.published_at.strftime('01/%Y')
end
end
links.uniq!
super_old_links.uniq!
links.each do |l|
year = l.split('/')[1]
month = l.split('/')[0]
count = BlogPost.by_archive(Time.parse(l)).size
text = t("date.month_names")[month.to_i] + " #{year} (#{count})"
html << "<li>"
html << link_to(text, main_app.archive_blog_posts_path(:year => year, :month => month))
html << "</li>"
end
super_old_links.each do |l|
year = l.split('/')[1]
count = Refinery::BlogPost.by_year(Time.parse(l)).size
text = "#{year} (#{count})"
html << "<li>"
html << link_to(text, main_app.archive_blog_posts_path(:year => year))
html << "</li>"
end
html << '</ul></nav></section>'
html.html_safe
end
def next_or_previous?(post)
post.next.present? or post.prev.present?
end
def blog_post_teaser_enabled?
Refinery::BlogPost.teasers_enabled?
end
def blog_post_teaser(post)
if post.respond_to?(:custom_teaser) && post.custom_teaser.present?
post.custom_teaser.html_safe
else
truncate(post.body, {
:length => Refinery::Setting.find_or_set(:blog_post_teaser_length, 250),
:preserve_html_tags => true
}).html_safe
end
end
end
end

View file

@ -3,8 +3,8 @@
<% content_for :body_content_left do %> <% content_for :body_content_left do %>
<% if @blog_posts.any? %> <% if @blog_posts.any? %>
<section id="blog_posts"> <section id="blog_posts">
<%= render :partial => "/blog/shared/post", :collection => @blog_posts %> <%= render :partial => "/refinery/blog/shared/post", :collection => @blog_posts %>
<%= will_paginate @blog_posts %> <%= paginate @blog_posts %>
</section> </section>
<% else %> <% else %>
<p><%= t('.no_blog_articles_yet') %></p> <p><%= t('.no_blog_articles_yet') %></p>
@ -12,11 +12,11 @@
<% end %> <% end %>
<% content_for :body_content_right do %> <% content_for :body_content_right do %>
<%= render :partial => "/blog/shared/categories" %> <%= render :partial => "/refinery/blog/shared/categories" %>
<%= render :partial => "/blog/shared/tags" %> <%= render :partial => "/refinery/blog/shared/tags" %>
<%= render :partial => "/blog/shared/rss_feed" %> <%= render :partial => "/refinery/blog/shared/rss_feed" %>
<%= blog_archive_list %> <%= blog_archive_list %>
<% end %> <% end %>
<%= render :partial => "/shared/content_page" %> <%= render :partial => "/refinery/content_page" %>
<% content_for :stylesheets, stylesheet_link_tag('refinerycms-blog') %> <% content_for :stylesheets, stylesheet_link_tag('refinerycms-blog') %>

View file

@ -3,7 +3,7 @@
<ul id='categories'> <ul id='categories'>
<% @blog_categories.each do |category| %> <% @blog_categories.each do |category| %>
<li<%= " class='selected'" if @category.present? and @category.id == category.id %>> <li<%= " class='selected'" if @category.present? and @category.id == category.id %>>
<%= link_to "#{category.title} (#{category.post_count})", blog_category_url(category) %> <%= link_to "#{category.title} (#{category.post_count})", main_app.blog_category_path(category) %>
</li> </li>
<% end %> <% end %>
</ul> </ul>

View file

@ -1,7 +1,7 @@
<% if post.live? %> <% if post.live? %>
<article class="blog_post" id="<%= dom_id(post) %>"> <article class="blog_post" id="<%= dom_id(post) %>">
<header> <header>
<h1><%= link_to post.title, blog_post_url(post) %></h1> <h1><%= link_to post.title, main_app.blog_post_path(post) %></h1>
<section class='details'> <section class='details'>
<time datetime="<%=l post.published_at.to_date, :format => :default %>" class='posted_at'> <time datetime="<%=l post.published_at.to_date, :format => :default %>" class='posted_at'>
<%= t('created_at', :scope => 'blog.shared.posts', :when => l(post.published_at.to_date, :format => :short)) %> <%= t('created_at', :scope => 'blog.shared.posts', :when => l(post.published_at.to_date, :format => :short)) %>
@ -10,13 +10,13 @@
<% if (categories = post.categories).any? %> <% if (categories = post.categories).any? %>
<aside class='filed_in'> <aside class='filed_in'>
<%= t('filed_in', :scope => 'blog.posts.show') %> <%= t('filed_in', :scope => 'blog.posts.show') %>
<%=raw categories.collect { |category| link_to category.title, blog_category_url(category) }.to_sentence %> <%=raw categories.collect { |category| link_to category.title, main_app.blog_category_path(category) }.to_sentence %>
</aside> </aside>
<% end %> <% end %>
<% if (tags = post.tags).any? %> <% if (tags = post.tags).any? %>
<aside class='tagged'> <aside class='tagged'>
<%= t('tagged', :scope => 'blog.posts.show') %> <%= t('tagged', :scope => 'blog.posts.show') %>
<%=raw tags.collect { |tag| link_to tag, tagged_posts_path(tag.id, tag.name.parameterize) }.to_sentence %> <%=raw tags.collect { |tag| link_to tag, main_app.tagged_posts_path(tag.id, tag.name.parameterize) }.to_sentence %>
</aside> </aside>
<% end %> <% end %>
</section> </section>
@ -30,10 +30,10 @@
</section> </section>
<footer> <footer>
<p> <p>
<%= link_to t('read_more', :scope => 'blog.shared.posts'), blog_post_url(post) if blog_post_teaser_enabled? %> <%= link_to t('read_more', :scope => 'blog.shared.posts'), main_app.blog_post_path(post) if blog_post_teaser_enabled? %>
</p> </p>
<aside class='comment_count'> <aside class='comment_count'>
<% if BlogPost.comments_allowed? %> <% if Refinery::BlogPost.comments_allowed? %>
<% if post.comments.any? %> <% if post.comments.any? %>
(<%= pluralize(post.comments.approved.count, t('singular', :scope => 'blog.shared.comments')) %>) (<%= pluralize(post.comments.approved.count, t('singular', :scope => 'blog.shared.comments')) %>)
<% else %> <% else %>

View file

@ -3,7 +3,7 @@
<ul id="blog_posts"> <ul id="blog_posts">
<% @blog_posts.each do |blog_post| %> <% @blog_posts.each do |blog_post| %>
<li class='clearfix'> <li class='clearfix'>
<%= link_to blog_post.title, blog_post_url(blog_post) %> <%= link_to blog_post.title, main_app.blog_post_path(blog_post) %>
</li> </li>
<% end %> <% end %>
</ul> </ul>

View file

@ -1,2 +1,2 @@
<h2><%= t('.title') %></h2> <h2><%= t('.title') %></h2>
<%= link_to t('.subscribe'), blog_rss_feed_url, :id => "rss_feed_subscribe"%> <%= link_to t('.subscribe'), main_app.blog_rss_feed_path, :id => "rss_feed_subscribe"%>

View file

@ -2,7 +2,7 @@
<h2><%= t('.title') %></h2> <h2><%= t('.title') %></h2>
<nav id='tags'> <nav id='tags'>
<% tag_cloud(@tags, %w(tag1 tag2 tag3 tag4)) do |tag, css_class| %> <% tag_cloud(@tags, %w(tag1 tag2 tag3 tag4)) do |tag, css_class| %>
<%= link_to tag.name, tagged_posts_path(tag.id, tag.name.parameterize), :class => css_class %> <%= link_to tag.name, main_app.tagged_posts_path(tag.id, tag.name.parameterize), :class => css_class %>
<% end %> <% end %>
</nav> </nav>
<% end %> <% end %>

View file

@ -4,10 +4,10 @@ end
When /^I visit the tagged posts page for "([^"]*)"$/ do |tag_name| When /^I visit the tagged posts page for "([^"]*)"$/ do |tag_name|
@blog_post ||= Factory.create(:blog_post, :tag_list => tag_name) @blog_post ||= Factory.create(:blog_post, :tag_list => tag_name)
tag = BlogPost.tag_counts_on(:tags).first tag = ::Refinery::BlogPost.tag_counts_on(:tags).first
visit tagged_posts_path(tag.id, tag_name.parameterize) visit tagged_posts_path(tag.id, tag_name.parameterize)
end end
Then /^the blog post should have the tags "([^"]*)"$/ do |tag_list| Then /^the blog post should have the tags "([^"]*)"$/ do |tag_list|
BlogPost.last.tag_list == tag_list.split(', ') ::Refinery::BlogPost.last.tag_list == tag_list.split(', ')
end end

View file

@ -33,7 +33,8 @@ Gem::Specification.new do |s|
app/controllers/refinery/blog/posts_controller.rb app/controllers/refinery/blog/posts_controller.rb
app/controllers/refinery/blog_controller.rb app/controllers/refinery/blog_controller.rb
app/helpers app/helpers
app/helpers/blog_posts_helper.rb app/helpers/refinery
app/helpers/refinery/blog_posts_helper.rb
app/mailers app/mailers
app/mailers/refinery app/mailers/refinery
app/mailers/refinery/blog app/mailers/refinery/blog