Permalink
Browse files

* Clean up tests (Convert some from functional to integration for les…

…s brittleness)

* Remove duplicate tests
* Add rvmrc for 1.9.2@rails3.0
* Fix html_safe bug for rendering tags.
  • Loading branch information...
1 parent 7917576 commit 42ec0d94206a3a8c31302ec8f6a6d99ce53a0ecf @peakpg peakpg committed Jan 9, 2012
View
1 .rvmrc
@@ -0,0 +1 @@
+rvm use 1.9.2@rails3.0
@@ -16,6 +16,8 @@ def render
raise BlogPost::INCORRECT_PARAMETERS
end
+ make_page_title_use_blog_post_name(@blog_post)
+
pmap = flash[instance_name] || params
pmap[:blog_comment] ||= {}
@@ -42,5 +44,15 @@ def create_comment
def work_around_cms_3_3_bug_where_current_user_is_not_correctly_set
User.current = current_user
end
+
+ # This is a work around for a bug in bcms 3.3 where the Cms::PageHeler#page_title doesnt
+ # share state between the portlet view and the page view.
+ # When the portlet view (app/views/portlets/blog_post/render) calls 'page_title @post.name'
+ # that instance variable isn't shared back to the page template.
+ # Instead, we just temporarily set the name of the page itself.
+ def make_page_title_use_blog_post_name(post)
+ page = @controller.current_page
+ page.name = post.name
+ end
end
@@ -38,7 +38,7 @@
<% if blog_post.tags.any? %>
Tags:
<span class="tags">
- <%= blog_post.tags.map{|t| link_to(h(t.name), _blog_path(blog_post.blog, 'posts_with_tag', :tag => t.name)) }.join(", ") %>
+ <%= blog_post.tags.map{|t| link_to(h(t.name), _blog_path(blog_post.blog, 'posts_with_tag', :tag => t.name)) }.join(", ").html_safe %>
</span>
<strong>|</strong>
<% end %>
@@ -75,7 +75,7 @@
- if blog_post.tags.any?
Tags:
%span.tags
- = blog_post.tags.map{|t| link_to(h(t.name), _blog_path(blog_post.blog, 'posts_with_tag', :tag => t.name)) }.join(", ")
+ = blog_post.tags.map{|t| link_to(h(t.name), _blog_path(blog_post.blog, 'posts_with_tag', :tag => t.name)) }.join(", ").html_safe
%strong |
= link_to h(pluralize(blog_post.comments_count, "Comment")), "#{_blog_post_path(blog_post)}#comments"
%br.clear/
@@ -1,8 +1,13 @@
+<%
+ logger.warn "Page title is: #{page_title}"
+ page_title "SOMETHING ELSE"
+ logger.warn "Now it's #{page_title}"
+%>
<% page_title @blog_post.name %>
<%= render :partial => "partials/blog_post", :object => @blog_post %>
<div class="blog_comment_form">
- <% form_for @blog_comment, :url => new_comment_path(@portlet) do |f| %>
+ <%= form_for @blog_comment, :url => new_comment_path(@portlet) do |f| %>
<%= f.hidden_field :post_id %>
<%= f.cms_error_messages %>
<div class="fields text_fields">
@@ -1,31 +0,0 @@
-require 'test_helper'
-
-class BlogPostControllerTest < ActionController::TestCase
- tests Cms::ContentController
-
- def setup
- seed_bcms_data
- seed_blog_data
- create_test_data
- end
-
- test "show_post" do
- get :show, :path => ['myblog', 'post'], :year => 2008, :month => 07, :day => 05, :slug => 'the-first-post'
- assert_response :success
-
- assert_select "title", @first_post.name
- assert_select ".blog_post", 1
-
- assert_select "#blog_post_#{@first_post.id}" do
- assert_select "h2 a", @first_post.name
- assert_select "div.body", @first_post.body
- assert_select "div.meta a", "General"
- assert_select "div.meta a", "0 Comments"
- end
- end
-
- test "non_existent_post_should_return_404" do
- get :show, :path => ["myblog"], :year => 2005, :month => 6, :day => 14, :slug => "not-here"
- assert_response :not_found
- end
-end
@@ -1,42 +0,0 @@
-require 'test_helper'
-
-class BlogPostTest < ActionController::TestCase
- tests Cms::ContentController
-
- def setup
- setup_stubs
- create_baseline_data
- end
-
- # def teardown
- # destroy_baseline_data
- # end
-
- def test_show_post
- get :show, :path => ["blog", "post"],
- :year => @first_post.year,
- :month => @first_post.month,
- :day => @first_post.day,
- :slug => @first_post.slug
- #log @response.body
- assert_response :success
- assert_select "title", @first_post.name
- assert_select ".blog_post", 1
-
- assert_select "#blog_post_#{@first_post.id}" do
- assert_select "h2 a", @first_post.name
- assert_select "p.body", @first_post.body
- assert_select "p.meta a", "General"
- assert_select "p.meta a", "0 Comments"
- end
-
- end
-
- # def test_non_existent_slug_should_return_404
- # get :show, :path => ["blog", "post"],
- # :year => 2005, :month => 6, :day => 14,
- # :slug => "not-here"
- # assert_response :not_found
- # end
-
-end
@@ -1,74 +0,0 @@
-require 'test_helper'
-
-class BlogTest < ActionController::TestCase
- tests Cms::ContentController
-
- def setup
- # create_baseline_data
- # `rake db:test:purge`
- # `rake db:migrate`
- create_baseline_data
- end
- #
- # def teardown
- # destroy_baseline_data
- # end
- #
- def test_list_of_blog_posts
-
-
- get :show
- log @response.body
- assert_response :success
- assert_select ".blog_post", 5
-
- assert_select "#blog_post_#{@first_post.id}" do
- assert_select "h2 a", @first_post.name
- assert_select "p.body", @first_post.body
- assert_select "p.meta a", "General"
- assert_select "p.meta a", "0 Comments"
- end
-
- assert_select "#blog_post_#{@foo_post_1.id}" do
- assert_select "h2 a", @foo_post_1.name
- assert_select "p.body", @foo_post_1.body
- assert_select "p.meta .tags a", "foo"
- assert_select "p.meta .tags a", "stuff"
- end
- end
-
- # def test_list_of_tagged_blog_posts
- # get :show, :category => "General"
- # puts @response.body
- # assert_response :success
- # assert_select ".blog_post", 3
- # end
- #
- # def test_list_of_categorized_blog_posts
- # get :show, :tag => "foo"
- # #log @response.body
- # assert_response :success
- # assert_select ".blog_post", 2
- # end
- #
- # def test_list_of_blog_posts_in_day
- # get :show, :path => ["blog", "posts_in_day"],
- # :year => 2008, :month => 7, :day => 5
- # assert_response :success
- # assert_select ".blog_post", 2
- # end
- #
- # def test_list_of_blog_posts_in_month
- # get :show, :path => ["blog", "posts_in_month"],
- # :year => 2008, :month => 7
- # assert_response :success
- # assert_select ".blog_post", 3
- # end
- #
- # def test_list_of_blog_posts_in_year
- # get :show, :path => ["blog", "posts_in_year"],
- # :year => 2008
- # assert_response :success
- # assert_select ".blog_post", 4
- # end
-end
@@ -20,6 +20,6 @@ def setup
login_as(create_user)
get :index
assert_response :success
- assert_template("admin_only.html.erb")
+ assert_select "p", "Sorry, this section is restricted to administrators."
end
end
@@ -1,16 +1,14 @@
require 'test_helper'
-class BlogControllerTest < ActionController::TestCase
- tests Cms::ContentController
-
+class BlogControllerTest < ActionDispatch::IntegrationTest
def setup
seed_bcms_data
seed_blog_data
create_test_data
end
test "displays the list of blog posts" do
- get :show, :path => ['myblog']
+ get "/myblog"
assert_response :success
assert_select ".blog_post", 5
@@ -22,7 +20,6 @@ def setup
assert_select "a", 2
end
end
-
assert_select "#blog_post_#{@foo_post_1.id}" do
assert_select "h2 a", @foo_post_1.name
assert_select "div.body", @foo_post_1.body
@@ -32,32 +29,35 @@ def setup
end
test "list of blog posts by category" do
- get :show, :path => ['myblog'], :category => 'General'
+ get "/myblog/category/General"
assert_response :success
assert_select ".blog_post", 3
end
test "list of blog posts by tag" do
- get :show, :path => ['myblog'], :tag => 'foo'
+ get "/myblog/tag/foo"
assert_response :success
assert_select ".blog_post", 2
end
test "list_of_blog_posts_in_day" do
- get :show, :path => ["myblog"], :year => 2008, :month => 7, :day => 5
+ get "/myblog/2008/07/05"
assert_response :success
assert_select ".blog_post", 2
end
test "list_of_blog_posts_in_month" do
- get :show, :path => ["myblog"], :year => 2008, :month => 7
+ get '/myblog/2008/07'
assert_response :success
assert_select ".blog_post", 3
end
test "list_of_blog_posts_in_year" do
- get :show, :path => ["myblog"], :year => 2008
+ get "/myblog/2008"
assert_response :success
assert_select ".blog_post", 4
end
+
+ private
+
end
@@ -0,0 +1,31 @@
+require 'test_helper'
+
+class BlogPostTest < ActionDispatch::IntegrationTest
+
+ def setup
+ seed_bcms_data
+ seed_blog_data
+ create_test_data
+ end
+
+ def test_show_post
+ get "/myblog/#{@first_post.year}/#{@first_post.month}/#{@first_post.day}/#{@first_post.slug}"
+ assert_response :success
+ assert_select "title", @first_post.name
+ assert_select ".blog_post", 1
+
+ assert_select "#blog_post_#{@first_post.id}" do
+ assert_select "h2 a", @first_post.name
+ assert_select ".body", @first_post.body
+ assert_select ".meta a", "General"
+ assert_select ".meta a", "0 Comments"
+ end
+
+ end
+
+ test "non_existent_post_should_return_404" do
+ get "/myblog/2005/6/14/non-existent"
+ assert_response :not_found
+ end
+
+end

0 comments on commit 42ec0d9

Please sign in to comment.