Skip to content
This repository has been archived by the owner on Apr 19, 2022. It is now read-only.

Commit

Permalink
Use let rather than instance variable in forum_spec
Browse files Browse the repository at this point in the history
  • Loading branch information
radar committed Jun 18, 2012
1 parent 179c875 commit b9f9b82
Showing 1 changed file with 20 additions and 28 deletions.
48 changes: 20 additions & 28 deletions spec/models/forum_spec.rb
Original file line number Diff line number Diff line change
@@ -1,50 +1,42 @@
require 'spec_helper'

describe Forem::Forum do
before(:each) do
category = FactoryGirl.create(:category)
@attr = {
:title => "A forum",
:description => "My sweet forum of goodness",
:category_id => category.id
}
@forum = Forem::Forum.create!(@attr)
end

let!(:forum) { FactoryGirl.create(:forum) }

it "is valid with valid attributes" do
@forum.should be_valid
forum.should be_valid
end

describe "validations" do
it "requires a title" do
@forum.title = nil
@forum.should_not be_valid
forum.title = nil
forum.should_not be_valid
end

it "requires a description" do
@forum.description = nil
@forum.should_not be_valid
forum.description = nil
forum.should_not be_valid
end

it "requires a category id" do
@forum.category_id = nil
@forum.should_not be_valid
forum.category_id = nil
forum.should_not be_valid
end
end

describe "helper methods" do
# Regression tests + tests related to fix for #42
context "last_post" do
let!(:visible_topic) { FactoryGirl.create(:topic, :forum => @forum) }
let!(:hidden_topic) { FactoryGirl.create(:topic, :forum => @forum, :hidden => true) }
let!(:visible_topic) { FactoryGirl.create(:topic, :forum => forum) }
let!(:hidden_topic) { FactoryGirl.create(:topic, :forum => forum, :hidden => true) }

let(:user) { FactoryGirl.create(:user) }
let(:admin) { FactoryGirl.create(:admin) }


context "finding the last visible post for a user" do
it "does not find non-approved posts" do
@forum.last_visible_post(user).should be_nil
forum.last_visible_post(user).should be_nil
end

context "with approved topic + post" do
Expand All @@ -55,16 +47,16 @@
end

it "finds the last post for a user" do
@forum.last_visible_post(user).should == visible_topic.posts.last
forum.last_visible_post(user).should == visible_topic.posts.last
# visible post doesn't contain hidden topics, duh
@forum.last_visible_post(admin).should == visible_topic.posts.last
forum.last_visible_post(admin).should == visible_topic.posts.last
end
end
end

context "finding the last post for a user" do
it "does not find non-approved posts" do
@forum.last_post_for(user).should be_nil
forum.last_post_for(user).should be_nil
end

context "with approved topic + post" do
Expand All @@ -75,22 +67,22 @@
end

it "finds the last post for a user" do
@forum.last_post_for(user).should == visible_topic.posts.last
@forum.last_post_for(admin).should == hidden_topic.posts.last
forum.last_post_for(user).should == visible_topic.posts.last
forum.last_post_for(admin).should == hidden_topic.posts.last
end
end
end
end

context "moderator?" do
it "no user is no moderator" do
@forum.moderator?(nil).should be_false
forum.moderator?(nil).should be_false
end

it "is a moderator if group ids intersect" do
@forum.stub :moderator_ids => [1,2]
forum.stub :moderator_ids => [1,2]
user = stub :forem_group_ids => [2,3]
@forum.moderator?(user).should be_true
forum.moderator?(user).should be_true
end

end
Expand Down

0 comments on commit b9f9b82

Please sign in to comment.