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
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
it "should overwrite draft data correctly" do

View File

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

View File

@ -5,13 +5,9 @@ describe IncomingLink do
it { should belong_to :topic }
it { should validate_presence_of :url }
let :post do
Fabricate(:post)
end
let(:post) { Fabricate(:post) }
let :topic do
post.topic
end
let(:topic) { post.topic }
let :incoming_link do
IncomingLink.create(url: "/t/slug/#{topic.id}/#{post.post_number}",
@ -77,7 +73,7 @@ describe IncomingLink do
describe 'non-topic url' 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.user_id.should be_blank
end

View File

@ -9,6 +9,8 @@ describe Invite do
it { should validate_presence_of :email }
it { should validate_presence_of :invited_by_id }
let(:iceking) { 'iceking@adventuretime.ooo' }
context 'user validators' do
let(:coding_horror) { Fabricate(:coding_horror) }
let(:user) { Fabricate(:user) }
@ -32,7 +34,7 @@ describe Invite do
its(:email_already_exists) { should be_false }
it 'should store a lower case version of the email' do
subject.email.should == "iceking@adventuretime.ooo"
subject.email.should == iceking
end
end
@ -43,22 +45,22 @@ describe Invite do
context 'email' do
it 'enqueues a job to email the invite' do
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
context '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 = topic.invite_by_email(inviter, 'iceking@adventuretime.ooo')
invite = topic.invite_by_email(inviter, iceking)
invite.should be_present
end
end
context 'after created' do
before do
@invite = topic.invite_by_email(inviter, 'iceking@adventuretime.ooo')
@invite = topic.invite_by_email(inviter, iceking)
end
it 'belongs to the topic' do
@ -76,7 +78,7 @@ describe Invite do
context 'when added by another user' do
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
new_invite.should_not == @invite
@ -109,7 +111,7 @@ describe Invite do
let!(:another_topic) { Fabricate(:topic, user: topic.user) }
before do
@new_invite = another_topic.invite_by_email(inviter, 'iceking@adventuretime.ooo')
@new_invite = another_topic.invite_by_email(inviter, iceking)
end
it 'should be the same invite' do

View File

@ -46,7 +46,7 @@ describe Post do
describe '#with_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
end
end

View File

@ -138,7 +138,7 @@ describe Report do
it "returns a report with data" do
report.data.should be_present
report.data.find {|d| d[:x] == TrustLevel.levels[:newuser]} [:y].should == 3
report.data.find {|d| d[:x] == TrustLevel.levels[:newuser]}[:y].should == 3
report.data.find {|d| d[:x] == TrustLevel.levels[:regular]}[:y].should == 2
report.data.find {|d| d[:x] == TrustLevel.levels[:elder]}[:y].should == 1
end