From 674e26e6c3772d13256d56cb942ed45cdd13b4b3 Mon Sep 17 00:00:00 2001 From: Martin Feckie Date: Tue, 25 Jun 2013 22:15:41 +0800 Subject: [PATCH] Updated tests to decrease string repetition Removed an unused variable Some minor style changes --- spec/models/draft_spec.rb | 2 +- spec/models/group_spec.rb | 2 +- spec/models/incoming_link_spec.rb | 10 +++------- spec/models/invite_spec.rb | 16 +++++++++------- spec/models/post_spec.rb | 2 +- spec/models/report_spec.rb | 2 +- 6 files changed, 16 insertions(+), 18 deletions(-) diff --git a/spec/models/draft_spec.rb b/spec/models/draft_spec.rb index 43d05bb5a48..77cf977e96d 100644 --- a/spec/models/draft_spec.rb +++ b/spec/models/draft_spec.rb @@ -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 diff --git a/spec/models/group_spec.rb b/spec/models/group_spec.rb index 23741dd1bc1..0141de462db 100644 --- a/spec/models/group_spec.rb +++ b/spec/models/group_spec.rb @@ -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) diff --git a/spec/models/incoming_link_spec.rb b/spec/models/incoming_link_spec.rb index 8eaf04b1d8e..16066d63627 100644 --- a/spec/models/incoming_link_spec.rb +++ b/spec/models/incoming_link_spec.rb @@ -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 diff --git a/spec/models/invite_spec.rb b/spec/models/invite_spec.rb index 7e8540fa1da..55154b00cfc 100644 --- a/spec/models/invite_spec.rb +++ b/spec/models/invite_spec.rb @@ -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 diff --git a/spec/models/post_spec.rb b/spec/models/post_spec.rb index bd2bc0411cb..525e14133df 100644 --- a/spec/models/post_spec.rb +++ b/spec/models/post_spec.rb @@ -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 diff --git a/spec/models/report_spec.rb b/spec/models/report_spec.rb index 7201aa87bc0..62462411861 100644 --- a/spec/models/report_spec.rb +++ b/spec/models/report_spec.rb @@ -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