Permalink
Browse files

Test fixes, all tests should be green now!

  • Loading branch information...
1 parent 21637ec commit 885688f8f13d0f11028c42eefe255494876c5633 @radar committed Feb 3, 2010
@@ -1,7 +1,11 @@
require File.dirname(__FILE__) + '/../../spec_helper'
describe Admin::IndexController do
- fixtures :users, :posts
+ before do
+ setup_user_base
+ setup_forums
+ end
+
it "should show the admin page" do
login_as(:administrator)
get 'index'
@@ -7,9 +7,10 @@
setup_forums
login_as(:moderator)
@forum = Forum("Public Forum")
- @first_post = @forum.posts.first
- @second_post = @forum.posts.last
+ valid_topic_for(@forum, 3)
@topic = @forum.topics.first
+ @first_post = @topic.posts.first
+ @second_post = @topic.posts.second
end
def topic_split
@@ -30,7 +31,7 @@ def topic_split
it "should be able to split a topic before" do
post 'split', { :id => @second_post.id, :direction => "before", :how => "just_split", :topic_id => @topic.id }
topic_split
- response.should redirect_to(forum_topic_path(@forum, assigns[:new_topic].id))
+ response.should redirect_to(forum_topic_path(@forum, assigns[:new_topic].id))
end
it "should be able to split a topic before and including a specific post" do
@@ -6,12 +6,17 @@
setup_user_base
setup_forums
login_as(:registered_user)
- @plebian = User("registered_user")
+ @registered_user = User("registered_user")
@admin_forum = Forum("Admins Only")
@admin_topic = @admin_forum.topics.first
@everybody = Forum("Public Forum")
@topic = @everybody.topics.first
+
+ # Post is owned by the registered_user for this.
@post = @topic.posts.first
+ @post.user = @registered_user
+ @post.save!
+
@other_user_topic = @everybody.topics.last
end
@@ -21,23 +26,22 @@
end
it "should be able to edit a post" do
- get 'edit', :id => @first_post.id, :topic_id => @topic.id
+ get 'edit', :id => @post.id, :topic_id => @topic.id
response.should render_template("edit")
end
it "shouldn't be able to edit a post that doesn't belong to them" do
- get 'edit', { :id => @admin_topic.posts.first.id }, :topic_id => @topic.id
+ get 'edit', { :id => @admin_topic.posts.first.id, :topic_id => @topic.id }
flash[:notice].should eql(t(:Cannot_edit_post))
response.should redirect_to(forums_path)
end
it "should be able to update a post" do
- put 'update', :id => @first_post.id, :post => { :text => "Hooray!" }, :topic_id => @topic.id
+ put 'update', :id => @post.id, :post => { :text => "Hooray!" }, :topic_id => @topic.id
flash[:notice].should eql(t(:updated, :thing => "post"))
end
it "shouldn't be able to update a post that doesn't exist" do
- Post.should_receive(:find).and_raise(ActiveRecord::RecordNotFound)
put 'update', :id => 1234567890, :post => { :text => "" }, :topic_id => @topic.id
response.should redirect_to(forums_path)
flash[:notice].should eql(t(:not_found, :thing => "post"))
@@ -59,7 +63,7 @@
Time.stub!(:now).and_return(two_minutes_into_the_future)
post 'create', { :post => { :text => "This is a new post" }, :topic_id => @topic.id }
@post_id = Post.last.id
- flash[:notice].should eql(t(:created, :thing => "post"))
+ flash[:notice].should eql(t(:created, :thing => "Post"))
response.should redirect_to(forum_topic_path(@everybody, @topic) + "/1#post_#{@post_id}")
end
@@ -77,15 +81,28 @@
end
it "should be able to destroy a post, and the topic if they own the post" do
- delete 'destroy', :id => @topic.posts.first.to_param, :topic_id => @topic.to_param
- response.should redirect_to(forum_path(@everybody))
+ # Ensure there's only one post left in this topic.
+ while @topic.posts.count != 1
+ @topic.posts.last.destroy
+ @topic.reload
+ end
+
+ # Ensure that the registered_user still owns this post.
+ @post = @topic.posts.first
+ @post.user = User(:registered_user)
+ @post.save!
+
+ delete 'destroy', :id => @post.to_param, :topic_id => @topic.to_param
flash[:notice].should eql(t(:deleted, :thing => "post") + t(:topic_too))
+ response.should redirect_to(forum_path(@everybody))
end
it "should not be able to destroy a post, and the topic if they do not own the post" do
+ @post.user = User(:administrator)
+ @post.save!
delete 'destroy', :id => @topic.posts.first.to_param, :topic_id => @topic.to_param
response.should redirect_to(forums_path)
- flash[:notice].should eql(t(:deleted, :thing => "post") + t(:topic_too))
+ flash[:notice].should eql(t(:Cannot_edit_post))
end
it "should not be able to destroy a post that does not exist" do
@@ -21,7 +21,7 @@ class TestView < ActionView::Base
end
it "should correctly display multiple nested quotes" do
- TestView.new.parse_text('[quote="Kitten"][quote="Dog"][quote="Turtle"]turtle, turtle[/quote]QUOTE INSIDE[/quote]QUOTE OUTSIDE[/quote]').should eql("<div class='quote'><b>Kitten wrote:</b><br /><span><div class='quote'><b>Dog wrote:</b><br /><span><div class='quote'><b>Turtle wrote:</b><br /><span>turtle, turtle</span></div>QUOTE INSIDE</span></div>QUOTE OUTSIDE</span></div>")
+ TestView.new.parse_text('[quote="Kitten"][quote="Dog"][quote="Turtle"]turtle, turtle[/quote]QUOTE INSIDE[/quote]QUOTE OUTSIDE[/quote]').should eql("<div class='quote'><b>&quot;Kitten&quot; wrote:</b><br /><span><div class='quote'><b>&quot;Dog&quot; wrote:</b><br /><span><div class='quote'><b>&quot;Turtle&quot; wrote:</b><br /><span>turtle, turtle</span></div>QUOTE INSIDE</span></div>QUOTE OUTSIDE</span></div>")
end
it "correctly formats the bbcode when it contains some code blocks" do
Submodule dotiw updated from 291a1d to 404513

0 comments on commit 885688f

Please sign in to comment.