From e2a5415aca5ea7596b735f73ac8f03c629d43deb Mon Sep 17 00:00:00 2001 From: Brian Alexander Date: Tue, 22 Oct 2013 19:14:31 -0600 Subject: [PATCH] fix #1567; nil reference in spam_rules_enforcer.rb --- lib/post_creator.rb | 2 +- spec/components/post_creator_spec.rb | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/post_creator.rb b/lib/post_creator.rb index a3b02d46b92..1279048d8f0 100644 --- a/lib/post_creator.rb +++ b/lib/post_creator.rb @@ -76,7 +76,7 @@ class PostCreator { user: @user, limit_once_per: 24.hours, message_params: {domains: @post.linked_hosts.keys.join(', ')} } ) - else + elsif @post && !@post.errors.present? SpamRulesEnforcer.enforce!(@post) end diff --git a/spec/components/post_creator_spec.rb b/spec/components/post_creator_spec.rb index c9a762b8326..fed5a5cffdf 100644 --- a/spec/components/post_creator_spec.rb +++ b/spec/components/post_creator_spec.rb @@ -44,6 +44,17 @@ describe PostCreator do end + context "invalid raw" do + + let(:creator_invalid_raw) { PostCreator.new(user, basic_topic_params.merge(raw: '')) } + + it "has errors" do + creator_invalid_raw.create + expect(creator_invalid_raw.errors).to be_present + end + + end + context "success" do it "doesn't return true for spam" do