added post controller test
This commit is contained in:
@@ -23,7 +23,7 @@ class PostsController < ApplicationController
|
|||||||
@post = Post.find(params[:id])
|
@post = Post.find(params[:id])
|
||||||
@version = PostVersion.find(params[:version_id])
|
@version = PostVersion.find(params[:version_id])
|
||||||
@post.revert_to!(@version)
|
@post.revert_to!(@version)
|
||||||
respond_width(@post)
|
respond_with(@post)
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|||||||
@@ -50,8 +50,8 @@ module PostSets
|
|||||||
end
|
end
|
||||||
|
|
||||||
def load_posts
|
def load_posts
|
||||||
@count = Post.fast_count(tags)
|
@count = ::Post.fast_count(tags)
|
||||||
@posts = Post.tag_match(tags).before_id(before_id).all(:order => "posts.id desc", :limit => limit, :offset => offset)
|
@posts = ::Post.tag_match(tags).before_id(before_id).all(:order => "posts.id desc", :limit => limit, :offset => offset)
|
||||||
end
|
end
|
||||||
|
|
||||||
def load_suggestions
|
def load_suggestions
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ class Post < ActiveRecord::Base
|
|||||||
scope :commented_before, lambda {|date| where("last_commented_at < ?", date).order("last_commented_at DESC")}
|
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 :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 :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)}
|
scope :tag_match, lambda {|query| Post.tag_match_helper(query)}
|
||||||
|
|
||||||
module FileMethods
|
module FileMethods
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
<li>Popular</li>
|
<li>Popular</li>
|
||||||
<li>Favorites</li>
|
<li>Favorites</li>
|
||||||
<li>Subscriptions</li>
|
<li>Subscriptions</li>
|
||||||
<li><%= link_to "Changes", post_histories_path %></li>
|
<li><%= link_to "Changes", post_versions_path %></li>
|
||||||
<li>Approvals</li>
|
<li>Approvals</li>
|
||||||
<li>Moderate</li>
|
<li>Moderate</li>
|
||||||
<li>Help</li>
|
<li>Help</li>
|
||||||
|
|||||||
@@ -10,6 +10,6 @@
|
|||||||
(<%= post.image_width %>x<%= post.image_height %>)
|
(<%= post.image_width %>x<%= post.image_height %>)
|
||||||
<% end %>
|
<% end %>
|
||||||
</li>
|
</li>
|
||||||
<li><%= link_to "Tag History", post_histories_path(:search => {:post_id_eq => post.id}) %></li>
|
<li><%= link_to "Tag History", post_versions_path(:search => {:post_id_eq => post.id}) %></li>
|
||||||
<li><%= link_to "Note History", note_versions_path(:search => {:post_id_eq => post.id}) %></li>
|
<li><%= link_to "Note History", note_versions_path(:search => {:post_id_eq => post.id}) %></li>
|
||||||
</ul>
|
</ul>
|
||||||
@@ -3,13 +3,61 @@ require "test_helper"
|
|||||||
class PostsControllerTest < ActionController::TestCase
|
class PostsControllerTest < ActionController::TestCase
|
||||||
context "The posts controller" do
|
context "The posts controller" do
|
||||||
setup 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
|
end
|
||||||
|
|
||||||
teardown do
|
teardown do
|
||||||
|
CurrentUser.user = nil
|
||||||
|
CurrentUser.ip_addr = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
context "index action" do
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user