Permalink
Browse files

Further test fixing. I think this is good enough to merge into master…

… now.
  • Loading branch information...
1 parent 5dd5f37 commit 89c7b8c5f4cf36889a08eebdfcd54160f5beaf0e @radar committed Jan 27, 2010
View
3 app/controllers/posts_controller.rb
@@ -58,7 +58,8 @@ def update
def destroy
@post.destroy
flash[:notice] = t(:deleted, :thing => "post")
- if @post.topic.posts.size.zero?
+ p @post.topic.posts.count
+ if @post.topic.posts.count.zero?
@post.topic.destroy
flash[:notice] += t(:topic_too)
redirect_to forum_path(@post.forum)
View
1 app/views/topics/show.html.haml
@@ -1,3 +1,4 @@
+= render :partial => "sidebar"
- @title = t(:Viewing_topic, :forum => @forum, :topic => @topic)
- content_for :feed do
%link{:href => forum_topic_url(@topic.forum, @topic, :format => :rss), :rel => "alternate", :title => "#{@topic.subject} Feed", :type => "application/rss+xml"}
View
3 config/environment.rb
@@ -1,5 +1,4 @@
# Be sure to restart your web server when you modify this file.
-
require File.join(File.dirname(__FILE__), 'boot')
database = File.join(RAILS_ROOT, "config/database.yml")
if !File.exist?(database)
@@ -69,4 +68,4 @@
Find.prune
end
-Sass::Plugin.options[:template_location] = themes
+Sass::Plugin.options[:template_location] = themes
View
1 config/locales/en.rb
@@ -112,6 +112,7 @@
:all_posts_before_and_including => "All posts before and including this one",
:already_logged_in => "You are already logged in.",
:already_reported => "You have already reported that.",
+ :anonymous_stays => "The anonymous user cannot be deleted.",
:as_the_reason => "as the reason",
:At_first_post => "At first post",
:At_last_post => "At last post",
View
8 spec/blueprints/categories.rb
@@ -1,8 +0,0 @@
-Category.blueprint(:public) do
- name "Public Category"
- description "Category"
-end
-
-Category.blueprint do
- name
-end
View
10 spec/blueprints/configurations.rb
@@ -1,10 +0,0 @@
-Configuration.blueprint do
-
-end
-
-Configuration.blueprint(:subforums_display) do
- key "subforums_display"
- value "1"
- description "Limit the number of subforums displayed on the forums listing."
- title "Number of subforums to display"
-end
View
19 spec/blueprints/forums.rb
@@ -1,19 +0,0 @@
-Forum.blueprint do
- title { Faker::Name.name }
- description { Faker::Company.catch_phrase }
-end
-
-Forum.blueprint(:public) do
- title "Public Forum"
- category { Category.make(:public) }
-end
-
-Forum.blueprint(:sub_of_public) do
- title "Sub of Public Forum"
- parent { Forum("Public Forum") }
-end
-
-Forum.blueprint(:sub_of_sub_of_public) do
- title "Sub of sub of Public Forum"
- parent { Forum("Sub of Public Forum") }
-end
View
19 spec/blueprints/groups.rb
@@ -1,19 +0,0 @@
-
-Group.blueprint do
- name { Faker::Name.name }
-end
-
-Group.blueprint(:administrators) do
- name "Administrators"
- identifier "administrators"
-end
-
-Group.blueprint(:anonymous) do
- name "Anonymous"
- identifier "anonymous"
-end
-
-Group.blueprint(:registered_users) do
- name "Registered Users"
- identifier "registered_users"
-end
View
7 spec/blueprints/ips.rb
@@ -1,7 +0,0 @@
-Ip.blueprint do
-
-end
-
-Ip.blueprint(:localhost) do
- ip "127.0.0.1"
-end
View
4 spec/blueprints/messages.rb
@@ -1,4 +0,0 @@
-Message.blueprint do
- text { Faker::Lorem.paragraphs.join("\n") }
- from { User("registered_user") }
-end
View
3 spec/blueprints/moderations.rb
@@ -1,3 +0,0 @@
-Moderation.blueprint do
-
-end
View
64 spec/blueprints/permissions.rb
@@ -1,64 +0,0 @@
-Permission.blueprint do
- can_see_forum true
- can_see_category true
- group { Group.ensure("Anonymous") }
-end
-
-Permission.blueprint(:moderator) do
- can_reply_to_topics true
- can_start_new_topics true
- can_subscribe true
- group { Group.ensure("Moderators") }
-end
-
-Permission.blueprint(:registered_users) do
- can_reply_to_topics true
- can_start_new_topics true
- can_subscribe true
- can_edit_posts true
- group { Group.ensure("Registered Users") }
-end
-
-Permission.blueprint(:administrator) do
- can_see_forum true
- can_reply_to_topics true
- can_post_stickies true
- can_start_new_topics true
- can_post_in_closed_forums true
- can_use_signature true
- can_delete_own_posts true
- can_edit_own_posts true
- can_subscribe true
- can_lock_own_topics true
- can_ignore_flood_limit true
- can_delete_posts true
- can_edit_posts true
- can_lock_topics true
- can_merge_topics true
- can_move_topics true
- can_split_topics true
- can_send_multiple_messages true
- can_send_messages_to_groups true
- can_read_private_messages true
- can_manage_groups true
- can_manage_bans true
- can_manage_edits true
- can_manage_ips true
- can_manage_posts true
- can_manage_ranks true
- can_manage_users true
- can_manage_themes true
- can_manage_topics true
- can_manage_forums true
- can_manage_categories true
- can_reply_to_locked_topics true
- can_edit_topics true
- can_reply true
- can_edit_locked_topics true
- can_access_admin_section true
- can_see_category true
- can_access_moderator_section true
- can_read_others_private_messages true
- group { Group.ensure("Administrators") }
-end
-
View
3 spec/blueprints/post.rb
@@ -1,3 +0,0 @@
-Post.blueprint do
- text { Faker::Lorem.paragraphs.join("\n") }
-end
View
13 spec/blueprints/ranks.rb
@@ -1,13 +0,0 @@
-Rank.blueprint do
-
-end
-
-Rank.blueprint(:runner) do
- name "Runner"
- posts_required 0
-end
-
-Rank.blueprint(:god) do
- name "God"
- custom true
-end
View
4 spec/blueprints/themes.rb
@@ -1,4 +0,0 @@
-Theme.blueprint do
- name "Default Theme"
- is_default true
-end
View
4 spec/blueprints/topics.rb
@@ -1,4 +0,0 @@
-Topic.blueprint do
- subject "Default topic"
- user { User.ensure(:administrator) }
-end
View
39 spec/blueprints/users.rb
@@ -1,39 +0,0 @@
-
-User.blueprint do
- login { Faker::Internet.user_name }
- password "password"
- password_confirmation "password"
- email { Faker::Internet.email }
- groups { Group.ensure("Registered Users") }
-end
-
-
-User.blueprint(:anonymous) do
- group = Group.ensure("Anonymous")
- login "anonymous"
- email "anony@mous.com"
-end
-
-User.blueprint(:administrator) do
- group = Group.ensure("Administrator")
- login "administrator"
- email "administrator@rboard.com"
- permalink "administrator"
- password "godly"
- password_confirmation "godly"
- remember_token_expires_at { Time.now + 2.weeks }
- rank { Rank.find_by_name("God") || Rank.make(:god) }
-end
-
-User.blueprint(:registered_user) do
- group = Group.ensure("Registered User")
- login "registered_user"
- login_time { Time.now - 5.minutes }
-end
-
-User.blueprint(:banned_noob) do
- group = Group.ensure("Registered User")
- login "Banned Noob"
- ban_time { Time.now + 1.week }
- ban_reason "A nusiance."
-end
View
51 spec/controllers/admin/posts_controller_spec.rb
@@ -1,34 +1,35 @@
require File.dirname(__FILE__) + '/../../spec_helper'
-describe Admin::PostsController, "non-admins" do
- fixtures :users
-
- it "should not be allowed in if not logged in" do
- get 'index'
- response.should redirect_to(root_path)
+describe Admin::PostsController do
+ before do
+ setup_user_base
+ setup_forums
+ end
+
+ describe "non-admins" do
+ it "should not be allowed in if not logged in" do
+ get 'index'
+ response.should redirect_to(root_path)
+ end
end
-end
+ describe "admins" do
+ fixtures :users, :posts, :ips, :permissions, :group_users, :groups
-describe Admin::PostsController, "admins" do
- fixtures :users, :posts, :ips, :permissions, :group_users, :groups
+ before do
+ login_as(:administrator)
+ end
- before do
- login_as(:administrator)
- @ip = mock_model(Ip)
- @post = mock_model(Post)
- @posts = [@post]
- end
+ it "should be able to find all posts created by a specific IP" do
+ get 'index', :ip_id => Ip.make(:localhost)
+ response.should render_template("index")
+ end
- it "should be able to find all posts created by a specific IP" do
- get 'index', :ip_id => ips(:localhost).id
- response.should render_template("index")
- end
+ it "should not be able to find posts created by an imaginary IP" do
+ get 'index', :ip_id => 1234567890
+ flash[:notice].should eql(t(:not_found, :thing => "ip"))
+ response.should redirect_to(admin_root_path)
+ end
- it "should not be able to find posts created by an imaginary IP" do
- get 'index', :ip_id => 1234567890
- flash[:notice].should eql(t(:not_found, :thing => "ip"))
- response.should redirect_to(admin_root_path)
end
-
-end
+end
View
52 spec/controllers/posts_controller_spec.rb
@@ -11,81 +11,85 @@
@admin_topic = @admin_forum.topics.first
@everybody = Forum("Public Forum")
@topic = @everybody.topics.first
+ @post = @topic.posts.first
@other_user_topic = @everybody.topics.last
end
it "should be able to start a new post" do
- get 'new', :topic_id => @user_topic.id
+ get 'new', :topic_id => @topic.id
response.should render_template("new")
end
it "should be able to edit a post" do
- get 'edit', :id => @first_post.id, :topic_id => @everybody.id
+ get 'edit', :id => @first_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 => posts(:admin).id }, :topic_id => @everybody.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 => @everybody.id
+ put 'update', :id => @first_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 => @everybody.id
+ 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"))
end
it "should not be able to update a post with invalid data" do
- put 'update', :id => @first_post.id, :post => { :text => "" }, :topic_id => @everybody.id
+ put 'update', :id => @first_post.id, :post => { :text => "" }, :topic_id => @topic.id
response.should render_template("edit")
end
it "should not be able to edit a post that does not exist" do
- get 'edit', :id => 'post', :topic_id => @everybody.id
+ get 'edit', :id => 'post', :topic_id => @topic.id
flash[:notice].should eql(t(:not_found, :thing => "post"))
response.should redirect_to(forums_path)
end
it "should be able to create a post" do
two_minutes_into_the_future = Time.now + 2.minutes
Time.stub!(:now).and_return(two_minutes_into_the_future)
- post 'create', { :post => { :text => "This is a new post" }, :topic_id => topics(:user).id }
+ 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"))
- response.should redirect_to(forum_topic_path(forums(:everybody), topics(:user)) + "/1#post_#{@post_id}")
+ response.should redirect_to(forum_topic_path(@everybody, @topic) + "/1#post_#{@post_id}")
end
it "should not be able to create an invalid post" do
- post 'create', {:post => { :text => "" }, :topic_id => topics(:user).id }
+ post 'create', {:post => { :text => "" }, :topic_id => @topic.id }
response.should render_template("new")
end
it "should be able to destroy a post, but not the topic" do
- @post.stub!(:forum).and_return(forums(:everybody))
- @post.stub!(:topic).and_return(topics(:user))
- delete 'destroy', :id => @first_post.id, :topic_id => @everybody.id
+ @post.stub!(:forum).and_return(@everybody)
+ @post.stub!(:topic).and_return(@topic)
+ delete 'destroy', :id => @post.id, :topic_id => @topic.id
response.should redirect_to(forum_topic_path(@post.forum, @post.topic))
flash[:notice].should eql(t(:deleted, :thing => "post"))
end
- it "should be able to destroy a post, and the topic" do
- @post.stub!(:forum).and_return(forums(:everybody))
- @post.stub!(:belongs_to?).and_return(true)
- Post.should_receive(:find).and_return(@post)
- @post.should_receive(:topic).twice.and_return(@topic)
- @topic.should_receive(:posts).and_return(@posts)
- @post.should_receive(:destroy)
- @topic.should_receive(:destroy)
- @posts.should_receive(:size).and_return(0)
- delete 'destroy', :id => @first_post.to_param, :topic_id => @everybody.to_param
- response.should redirect_to(forum_path(@post.forum))
+ it "should be able to destroy a post, and the topic if they own the post" do
+ Post.expects(:find).with(@topic.posts.first.to_param).returns(post = stub)
+ Post.expects(:find).returns([post])
+ post.expects(:destroy)
+ post.expects(:topic).returns(topic = stub)
+ topic.expects(:posts).returns([])
+ delete 'destroy', :id => @topic.posts.first.to_param, :topic_id => @topic.to_param
+ response.should redirect_to(forum_path(@everybody))
+ flash[:notice].should eql(t(:deleted, :thing => "post") + t(:topic_too))
+ end
+
+ it "should not be able to destroy a post, and the topic if they do not own the post" do
+ 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))
end
View
3 spec/controllers/users_controller_spec.rb
@@ -15,7 +15,8 @@
end
it "should show a user" do
- get 'show', :id => "plebian"
+ get 'show', :id => "registered_user"
+ flash[:notice].should be_nil
response.should render_template("show")
end
View
4 spec/helpers/admin_forums_helper_spec.rb
@@ -10,7 +10,7 @@
end
it "should correctly output forums" do
- select_display(@everybody).should eql("General Discussion!")
- select_display(@sub_of_everybody).should eql("--Unmoderated Discussion")
+ select_display(@everybody).should eql("Public Forum")
+ select_display(@sub_of_everybody).should eql("--Sub of Public Forum")
end
end
View
6 spec/helpers/application_helper_spec.rb
@@ -15,11 +15,11 @@ class TestView < ActionView::Base
end
it "should correctly output breadcrumbs" do
- breadcrumb(@everybody).should eql("<a href=\"/categories/#{@everybody.category.id}/forums\">test</a> -> <a href=\"/forums/#{@everybody.id}\">General Discussion!</a>")
- breadcrumb(@sub_of_everybody).should eql("<a href=\"/categories/#{@everybody.category.id}/forums\">test</a> -> <a href=\"/forums/#{@everybody.id}\">General Discussion!</a> -> <a href=\"/forums/#{@sub_of_everybody.id}\">Unmoderated Discussion</a>")
+ breadcrumb(@everybody).should eql("<a href=\"/categories/#{@everybody.category.id}/forums\">Public Category</a> &raquo; <a href=\"/forums/#{@everybody.id}\">Public Forum</a>")
+ breadcrumb(@sub_of_everybody).should eql("<a href=\"/categories/#{@everybody.category.id}/forums\">Public Category</a> &raquo; <a href=\"/forums/#{@everybody.id}\">Public Forum</a> &raquo; <a href=\"/forums/#{@sub_of_everybody.id}\">Sub of Public Forum</a>")
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 /><div class='quote'><b>Dog wrote:</b><br /><div class='quote'><b>Turtle wrote:</b><br />turtle, turtle</div>QUOTE INSIDE</div>QUOTE OUTSIDE</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>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>")
end
end
View
1 spec/support/blueprints/ips.rb
@@ -4,5 +4,4 @@
Ip.blueprint(:localhost) do
ip "127.0.0.1"
- user { User.find_by_login("registered_user") || User.make(:registered_user) }
end
View
3 spec/support/blueprints/users.rb
@@ -9,6 +9,7 @@
User.blueprint(:anonymous) do
# group = Group.ensure("Anonymous")
+ identifier "anonymous"
login "anonymous"
email "anony@mous.com"
end
@@ -41,7 +42,7 @@
User.blueprint(:banned_noob) do
group = Group.ensure("Registered User")
- login "Banned Noob"
+ login "banned_noob"
ban_time { Time.now + 1.week }
ban_reason "A nusiance."
end

0 comments on commit 89c7b8c

Please sign in to comment.