Merge pull request #1091 from mfeckie/refactor-tests

Refactor tests
This commit is contained in:
Robin Ward 2013-06-25 07:31:19 -07:00
commit a4e8a828c8
6 changed files with 16 additions and 18 deletions

View File

@ -11,7 +11,7 @@ describe Draft do
it "uses the user id and key correctly" do it "uses the user id and key correctly" do
Draft.set(@user, "test", 0,"data") Draft.set(@user, "test", 0,"data")
Draft.get(Fabricate(:coding_horror), "test", 0).should be_nil Draft.get(Fabricate.build(:coding_horror), "test", 0).should be_nil
end end
it "should overwrite draft data correctly" do it "should overwrite draft data correctly" do

View File

@ -75,7 +75,7 @@ describe Group do
end end
it "Correctly updates all automatic groups upon request" do it "Correctly updates all automatic groups upon request" do
admin = Fabricate(:admin) Fabricate(:admin)
user = Fabricate(:user) user = Fabricate(:user)
user.change_trust_level!(:regular) user.change_trust_level!(:regular)

View File

@ -5,13 +5,9 @@ describe IncomingLink do
it { should belong_to :topic } it { should belong_to :topic }
it { should validate_presence_of :url } it { should validate_presence_of :url }
let :post do let(:post) { Fabricate(:post) }
Fabricate(:post)
end
let :topic do let(:topic) { post.topic }
post.topic
end
let :incoming_link do let :incoming_link do
IncomingLink.create(url: "/t/slug/#{topic.id}/#{post.post_number}", IncomingLink.create(url: "/t/slug/#{topic.id}/#{post.post_number}",
@ -77,7 +73,7 @@ describe IncomingLink do
describe 'non-topic url' do describe 'non-topic url' do
it 'has nothing set' do it 'has nothing set' do
link = Fabricate(:incoming_link_not_topic) link = Fabricate.build(:incoming_link_not_topic)
link.topic_id.should be_blank link.topic_id.should be_blank
link.user_id.should be_blank link.user_id.should be_blank
end end

View File

@ -9,6 +9,8 @@ describe Invite do
it { should validate_presence_of :email } it { should validate_presence_of :email }
it { should validate_presence_of :invited_by_id } it { should validate_presence_of :invited_by_id }
let(:iceking) { 'iceking@adventuretime.ooo' }
context 'user validators' do context 'user validators' do
let(:coding_horror) { Fabricate(:coding_horror) } let(:coding_horror) { Fabricate(:coding_horror) }
let(:user) { Fabricate(:user) } let(:user) { Fabricate(:user) }
@ -32,7 +34,7 @@ describe Invite do
its(:email_already_exists) { should be_false } its(:email_already_exists) { should be_false }
it 'should store a lower case version of the email' do it 'should store a lower case version of the email' do
subject.email.should == "iceking@adventuretime.ooo" subject.email.should == iceking
end end
end end
@ -43,22 +45,22 @@ describe Invite do
context 'email' do context 'email' do
it 'enqueues a job to email the invite' do it 'enqueues a job to email the invite' do
Jobs.expects(:enqueue).with(:invite_email, has_key(:invite_id)) Jobs.expects(:enqueue).with(:invite_email, has_key(:invite_id))
topic.invite_by_email(inviter, 'iceking@adventuretime.ooo') topic.invite_by_email(inviter, iceking)
end end
end end
context 'destroyed' do context 'destroyed' do
it "can invite the same user after their invite was destroyed" do it "can invite the same user after their invite was destroyed" do
invite = topic.invite_by_email(inviter, 'iceking@adventuretime.ooo') invite = topic.invite_by_email(inviter, iceking)
invite.destroy invite.destroy
invite = topic.invite_by_email(inviter, 'iceking@adventuretime.ooo') invite = topic.invite_by_email(inviter, iceking)
invite.should be_present invite.should be_present
end end
end end
context 'after created' do context 'after created' do
before do before do
@invite = topic.invite_by_email(inviter, 'iceking@adventuretime.ooo') @invite = topic.invite_by_email(inviter, iceking)
end end
it 'belongs to the topic' do it 'belongs to the topic' do
@ -76,7 +78,7 @@ describe Invite do
context 'when added by another user' do context 'when added by another user' do
let(:coding_horror) { Fabricate(:coding_horror) } let(:coding_horror) { Fabricate(:coding_horror) }
let(:new_invite) { topic.invite_by_email(coding_horror, 'iceking@adventuretime.ooo') } let(:new_invite) { topic.invite_by_email(coding_horror, iceking) }
it 'returns a different invite' do it 'returns a different invite' do
new_invite.should_not == @invite new_invite.should_not == @invite
@ -109,7 +111,7 @@ describe Invite do
let!(:another_topic) { Fabricate(:topic, user: topic.user) } let!(:another_topic) { Fabricate(:topic, user: topic.user) }
before do before do
@new_invite = another_topic.invite_by_email(inviter, 'iceking@adventuretime.ooo') @new_invite = another_topic.invite_by_email(inviter, iceking)
end end
it 'should be the same invite' do it 'should be the same invite' do

View File

@ -46,7 +46,7 @@ describe Post do
describe '#with_user' do describe '#with_user' do
it 'gives you a user' do it 'gives you a user' do
Fabricate(:post, user: Fabricate(:user)) Fabricate(:post, user: Fabricate.build(:user))
Post.with_user.first.user.should be_a User Post.with_user.first.user.should be_a User
end end
end end