From 3ba52acfe09c6e7093cce137a352e21287028c15 Mon Sep 17 00:00:00 2001 From: albert Date: Fri, 28 Jan 2011 18:03:00 -0500 Subject: [PATCH] added post controller test --- app/controllers/posts_controller.rb | 2 +- app/logical/post_sets/post.rb | 4 +- app/models/post.rb | 2 +- .../partials/common/_secondary_links.html.erb | 2 +- .../posts/partials/show/_information.html.erb | 2 +- test/functional/posts_controller_test.rb | 48 +++++++++++++++++++ 6 files changed, 54 insertions(+), 6 deletions(-) diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index 8b6f3c30b..f78738c88 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -23,7 +23,7 @@ class PostsController < ApplicationController @post = Post.find(params[:id]) @version = PostVersion.find(params[:version_id]) @post.revert_to!(@version) - respond_width(@post) + respond_with(@post) end private diff --git a/app/logical/post_sets/post.rb b/app/logical/post_sets/post.rb index 837d15c27..dc0cba220 100644 --- a/app/logical/post_sets/post.rb +++ b/app/logical/post_sets/post.rb @@ -50,8 +50,8 @@ module PostSets end def load_posts - @count = Post.fast_count(tags) - @posts = Post.tag_match(tags).before_id(before_id).all(:order => "posts.id desc", :limit => limit, :offset => offset) + @count = ::Post.fast_count(tags) + @posts = ::Post.tag_match(tags).before_id(before_id).all(:order => "posts.id desc", :limit => limit, :offset => offset) end def load_suggestions diff --git a/app/models/post.rb b/app/models/post.rb index 5e3305054..bf87624a8 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -30,7 +30,7 @@ class Post < ActiveRecord::Base scope :commented_before, lambda {|date| where("last_commented_at < ?", date).order("last_commented_at DESC")} scope :available_for_moderation, lambda {where(["id NOT IN (SELECT pd.post_id FROM post_disapprovals pd WHERE pd.user_id = ?)", CurrentUser.id])} scope :hidden_from_moderation, lambda {where(["id IN (SELECT pd.post_id FROM post_disapprovals pd WHERE pd.user_id = ?)", CurrentUser.id])} - scope :before_id, lambda {|id| where(["posts.id < ?", options[:before_id]])} + scope :before_id, lambda {|id| where(["posts.id < ?", id])} scope :tag_match, lambda {|query| Post.tag_match_helper(query)} module FileMethods diff --git a/app/views/posts/partials/common/_secondary_links.html.erb b/app/views/posts/partials/common/_secondary_links.html.erb index 70bca6994..f66ee881a 100644 --- a/app/views/posts/partials/common/_secondary_links.html.erb +++ b/app/views/posts/partials/common/_secondary_links.html.erb @@ -5,7 +5,7 @@
  • Popular
  • Favorites
  • Subscriptions
  • -
  • <%= link_to "Changes", post_histories_path %>
  • +
  • <%= link_to "Changes", post_versions_path %>
  • Approvals
  • Moderate
  • Help
  • diff --git a/app/views/posts/partials/show/_information.html.erb b/app/views/posts/partials/show/_information.html.erb index ce1c090f3..e79f18d80 100644 --- a/app/views/posts/partials/show/_information.html.erb +++ b/app/views/posts/partials/show/_information.html.erb @@ -10,6 +10,6 @@ (<%= post.image_width %>x<%= post.image_height %>) <% end %> -
  • <%= link_to "Tag History", post_histories_path(:search => {:post_id_eq => post.id}) %>
  • +
  • <%= link_to "Tag History", post_versions_path(:search => {:post_id_eq => post.id}) %>
  • <%= link_to "Note History", note_versions_path(:search => {:post_id_eq => post.id}) %>
  • \ No newline at end of file diff --git a/test/functional/posts_controller_test.rb b/test/functional/posts_controller_test.rb index b664725ea..d37951afd 100644 --- a/test/functional/posts_controller_test.rb +++ b/test/functional/posts_controller_test.rb @@ -3,13 +3,61 @@ require "test_helper" class PostsControllerTest < ActionController::TestCase context "The posts controller" do setup do + @user = Factory.create(:user) + CurrentUser.user = @user + CurrentUser.ip_addr = "127.0.0.1" + @post = Factory.create(:post, :uploader_id => @user.id, :tag_string => "aaa") end teardown do + CurrentUser.user = nil + CurrentUser.ip_addr = nil end context "index action" do + should "render" do + get :index + assert_response :success + end + context "with a search" do + should "render" do + get :index, {:tags => "aaa"} + assert_response :success + end + end + end + + context "show action" do + should "render" do + get :show, {:id => @post.id} + assert_response :success + end + end + + context "update action" do + should "work" do + post :update, {:id => @post.id, :post => {:tag_string => "bbb"}}, {:user_id => @user.id} + assert_redirected_to post_path(@post) + + @post.reload + assert_equal("bbb", @post.tag_string) + end + end + + context "revert action" do + setup do + @post.update_attributes(:tag_string => "zzz") + end + + should "work" do + @version = @post.versions(true).first + assert_equal("aaa", @version.add_tags) + post :revert, {:id => @post.id, :version_id => @version.id}, {:user_id => @user.id} + assert_redirected_to post_path(@post) + @post.reload + assert_equal("aaa", @post.tag_string) + end end end end