From 41fdd20c746f34a02d670dc2784cc279b2478cb7 Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Wed, 19 Aug 2015 16:05:58 -0700 Subject: Test Gitlab::ReplyByEmail. --- spec/lib/gitlab/reply_by_email_spec.rb | 86 ++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 spec/lib/gitlab/reply_by_email_spec.rb (limited to 'spec/lib') diff --git a/spec/lib/gitlab/reply_by_email_spec.rb b/spec/lib/gitlab/reply_by_email_spec.rb new file mode 100644 index 00000000000..a52af51e97c --- /dev/null +++ b/spec/lib/gitlab/reply_by_email_spec.rb @@ -0,0 +1,86 @@ +require "spec_helper" + +describe Gitlab::ReplyByEmail do + describe "self.enabled?" do + context "when reply by email is enabled" do + before do + allow(Gitlab.config.reply_by_email).to receive(:enabled).and_return(true) + end + + context "when the address is valid" do + before do + allow(Gitlab.config.reply_by_email).to receive(:address).and_return("replies+%{reply_key}@example.com") + end + + it "returns true" do + expect(described_class.enabled?).to be_truthy + end + end + + context "when the address is invalid" do + before do + allow(Gitlab.config.reply_by_email).to receive(:address).and_return("replies@example.com") + end + + it "returns false" do + expect(described_class.enabled?).to be_falsey + end + end + end + + context "when reply by email is disabled" do + before do + allow(Gitlab.config.reply_by_email).to receive(:enabled).and_return(false) + end + + it "returns false" do + expect(described_class.enabled?).to be_falsey + end + end + end + + describe "self.reply_key" do + context "when enabled" do + before do + allow(described_class).to receive(:enabled?).and_return(true) + end + + it "returns a random hex" do + key = described_class.reply_key + key2 = described_class.reply_key + + expect(key).not_to eq(key2) + end + end + + context "when disabled" do + before do + allow(described_class).to receive(:enabled?).and_return(false) + end + + it "returns nil" do + expect(described_class.reply_key).to be_nil + end + end + end + + context "self.reply_address" do + before do + allow(Gitlab.config.reply_by_email).to receive(:address).and_return("replies+%{reply_key}@example.com") + end + + it "returns the address with an interpolated reply key" do + expect(described_class.reply_address("key")).to eq("replies+key@example.com") + end + end + + context "self.reply_key_from_address" do + before do + allow(Gitlab.config.reply_by_email).to receive(:address).and_return("replies+%{reply_key}@example.com") + end + + it "returns reply key" do + expect(described_class.reply_key_from_address("replies+key@example.com")).to eq("key") + end + end +end -- cgit v1.2.1 From 83081f167397c6c325a4f8c604191e766b2c3d3b Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Wed, 19 Aug 2015 18:00:13 -0700 Subject: Start on tests. --- spec/lib/gitlab/email_receiver_spec.rb | 481 +++++++++++++++++++++++++++++++++ 1 file changed, 481 insertions(+) create mode 100644 spec/lib/gitlab/email_receiver_spec.rb (limited to 'spec/lib') diff --git a/spec/lib/gitlab/email_receiver_spec.rb b/spec/lib/gitlab/email_receiver_spec.rb new file mode 100644 index 00000000000..d6302eac13a --- /dev/null +++ b/spec/lib/gitlab/email_receiver_spec.rb @@ -0,0 +1,481 @@ +require "spec_helper" + +# Inspired in great part by Discourse's Email::Receiver +describe Gitlab::EmailReceiver do + def fixture_file(filename) + return '' if filename.blank? + file_path = File.expand_path(Rails.root + 'spec/fixtures/' + filename) + File.read(file_path) + end + + before do + allow(Gitlab.config.reply_by_email).to receive(:enabled).and_return(true) + allow(Gitlab.config.reply_by_email).to receive(:address).and_return("reply+%{reply_key}@appmail.adventuretime.ooo") + end + + describe 'parse_body' do + def test_parse_body(mail_string) + Gitlab::EmailReceiver.new(nil).parse_body(Mail::Message.new(mail_string)) + end + + it "raises EmptyEmailError if the message is blank" do + expect { test_parse_body("") }.to raise_error(Gitlab::EmailReceiver::EmptyEmailError) + end + + it "raises EmptyEmailError if the message is not an email" do + expect { test_parse_body("asdf" * 30) }.to raise_error(Gitlab::EmailReceiver::EmptyEmailError) + end + + it "raises EmptyEmailError if there is no reply content" do + expect { test_parse_body(fixture_file("emails/no_content_reply.eml")) }.to raise_error(Gitlab::EmailReceiver::EmptyEmailError) + end + + it "can parse the html section" do + expect(test_parse_body(fixture_file("emails/html_only.eml"))).to eq("The EC2 instance - I've seen that there tends to be odd and " + + "unrecommended settings on the Bitnami installs that I've checked out.") + end + + it "supports a Dutch reply" do + expect(test_parse_body(fixture_file("emails/dutch.eml"))).to eq("Dit is een antwoord in het Nederlands.") + end + + it "removes an 'on date wrote' quoting line" do + expect(test_parse_body(fixture_file("emails/on_wrote.eml"))).to eq("Sure, all you need to do is frobnicate the foobar and you'll be all set!") + end + + it "handles multiple paragraphs" do + expect(test_parse_body(fixture_file("emails/paragraphs.eml"))). + to eq( +"Is there any reason the *old* candy can't be be kept in silos while the new candy +is imported into *new* silos? + +The thing about candy is it stays delicious for a long time -- we can just keep +it there without worrying about it too much, imo. + +Thanks for listening." + ) + end + + it "handles multiple paragraphs when parsing html" do + expect(test_parse_body(fixture_file("emails/html_paragraphs.eml"))). + to eq( +"Awesome! + +Pleasure to have you here! + +:boom:" + ) + end + + it "handles newlines" do + expect(test_parse_body(fixture_file("emails/newlines.eml"))). + to eq( +"This is my reply. +It is my best reply. +It will also be my *only* reply." + ) + end + + it "handles inline reply" do + expect(test_parse_body(fixture_file("emails/inline_reply.eml"))). + to eq( +"On Wed, Oct 8, 2014 at 11:12 AM, techAPJ wrote: + +> techAPJ +> November 28 +> +> Test reply. +> +> First paragraph. +> +> Second paragraph. +> +> To respond, reply to this email or visit +> https://meta.discourse.org/t/testing-default-email-replies/22638/3 in +> your browser. +> ------------------------------ +> Previous Replies codinghorror +> +> November 28 +> +> We're testing the latest GitHub email processing library which we are +> integrating now. +> +> https://github.com/github/email_reply_parser +> +> Go ahead and reply to this topic and I'll reply from various email clients +> for testing. +> ------------------------------ +> +> To respond, reply to this email or visit +> https://meta.discourse.org/t/testing-default-email-replies/22638/3 in +> your browser. +> +> To unsubscribe from these emails, visit your user preferences +> . +> + +The quick brown fox jumps over the lazy dog. The quick brown fox jumps over +the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown +fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. +The quick brown fox jumps over the lazy dog. The quick brown fox jumps over +the lazy dog. The quick brown fox jumps over the lazy dog." + ) + end + + it "strips iPhone signature" do + expect(test_parse_body(fixture_file("emails/iphone_signature.eml"))).not_to match /Sent from my iPhone/ + end + + it "properly renders email reply from gmail web client" do + expect(test_parse_body(fixture_file("emails/gmail_web.eml"))). + to eq( +"### This is a reply from standard GMail in Google Chrome. + +The quick brown fox jumps over the lazy dog. The quick brown fox jumps over +the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown +fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. +The quick brown fox jumps over the lazy dog. The quick brown fox jumps over +the lazy dog. The quick brown fox jumps over the lazy dog. + +Here's some **bold** text in Markdown. + +Here's a link http://example.com" + ) + end + + it "properly renders email reply from iOS default mail client" do + expect(test_parse_body(fixture_file("emails/ios_default.eml"))). + to eq( +"### this is a reply from iOS default mail + +The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. + +Here's some **bold** markdown text. + +Here's a link http://example.com" + ) + end + + it "properly renders email reply from Android 5 gmail client" do + expect(test_parse_body(fixture_file("emails/android_gmail.eml"))). + to eq( +"### this is a reply from Android 5 gmail + +The quick brown fox jumps over the lazy dog. The quick brown fox jumps over +the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown +fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. +The quick brown fox jumps over the lazy dog. + +This is **bold** in Markdown. + +This is a link to http://example.com" + ) + end + + it "properly renders email reply from Windows 8.1 Metro default mail client" do + expect(test_parse_body(fixture_file("emails/windows_8_metro.eml"))). + to eq( +"### reply from default mail client in Windows 8.1 Metro + + +The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. + + +This is a **bold** word in Markdown + + +This is a link http://example.com" + ) + end + + it "properly renders email reply from MS Outlook client" do + expect(test_parse_body(fixture_file("emails/outlook.eml"))).to eq("Microsoft Outlook 2010") + end + end + +# describe "posting replies" do +# let(:reply_key) { raise "Override this in a lower describe block" } +# let(:email_raw) { raise "Override this in a lower describe block" } +# # ---- +# let(:receiver) { Gitlab::EmailReceiver.new(email_raw) } +# let(:post) { create_post } +# let(:topic) { post.topic } +# let(:posting_user) { post.user } +# let(:replying_user_email) { 'jake@adventuretime.ooo' } +# let(:replying_user) { Fabricate(:user, email: replying_user_email, trust_level: 2)} +# let(:email_log) { EmailLog.new(reply_key: reply_key, +# post: post, +# post_id: post.id, +# topic_id: post.topic_id, +# email_type: 'user_posted', +# user: replying_user, +# user_id: replying_user.id, +# to_address: replying_user_email +# ) } + +# before do +# email_log.save +# end + +# # === Success Posting === + +# describe "valid_reply.eml" do +# let!(:reply_key) { '59d8df8370b7e95c5a49fbf86aeb2c93' } +# let!(:email_raw) { fixture_file("emails/valid_reply.eml") } + +# it "creates a post with the correct content" do +# start_count = topic.posts.count + +# receiver.process + +# expect(topic.posts.count).to eq(start_count + 1) +# created_post = topic.posts.last +# expect(created_post.via_email).to eq(true) +# expect(created_post.raw_email).to eq(fixture_file("emails/valid_reply.eml")) +# expect(created_post.cooked.strip).to eq(fixture_file("emails/valid_reply.cooked").strip) +# end +# end + +# describe "paragraphs.eml" do +# let!(:reply_key) { '59d8df8370b7e95c5a49fbf86aeb2c93' } +# let!(:email_raw) { fixture_file("emails/paragraphs.eml") } + +# it "cooks multiple paragraphs with traditional Markdown linebreaks" do +# start_count = topic.posts.count + +# receiver.process + +# expect(topic.posts.count).to eq(start_count + 1) +# expect(topic.posts.last.cooked.strip).to eq(fixture_file("emails/paragraphs.cooked").strip) +# expect(topic.posts.last.cooked).not_to match /
/ +# expect(Upload.find_by(sha1: upload_sha)).not_to eq(nil) +# end + +# end + +# # === Failure Conditions === + +# describe "too_short.eml" do +# let!(:reply_key) { '636ca428858779856c226bb145ef4fad' } +# let!(:email_raw) { +# fixture_file("emails/too_short.eml") +# .gsub("TO", "reply+#{reply_key}@appmail.adventuretime.ooo") +# .gsub("FROM", replying_user_email) +# .gsub("SUBJECT", "re: [Discourse Meta] eviltrout posted in 'Adventure Time Sux'") +# } + +# it "raises an InvalidPost error" do +# SiteSetting.min_post_length = 5 +# expect { receiver.process }.to raise_error(Gitlab::EmailReceiver::InvalidPost) +# end +# end + +# describe "too_many_mentions.eml" do +# let!(:reply_key) { '636ca428858779856c226bb145ef4fad' } +# let!(:email_raw) { fixture_file("emails/too_many_mentions.eml") } + +# it "raises an InvalidPost error" do +# SiteSetting.max_mentions_per_post = 10 +# (1..11).each do |i| +# Fabricate(:user, username: "user#{i}").save +# end + +# expect { receiver.process }.to raise_error(Gitlab::EmailReceiver::InvalidPost) +# end +# end + +# describe "auto response email replies should not be accepted" do +# let!(:reply_key) { '636ca428858779856c226bb145ef4fad' } +# let!(:email_raw) { fixture_file("emails/auto_reply.eml") } +# it "raises a AutoGeneratedEmailError" do +# expect { receiver.process }.to raise_error(Gitlab::EmailReceiver::AutoGeneratedEmailError) +# end +# end + +# end + +# describe "posting reply to a closed topic" do +# let(:reply_key) { raise "Override this in a lower describe block" } +# let(:email_raw) { raise "Override this in a lower describe block" } +# let(:receiver) { Gitlab::EmailReceiver.new(email_raw) } +# let(:topic) { Fabricate(:topic, closed: true) } +# let(:post) { Fabricate(:post, topic: topic, post_number: 1) } +# let(:replying_user_email) { 'jake@adventuretime.ooo' } +# let(:replying_user) { Fabricate(:user, email: replying_user_email, trust_level: 2) } +# let(:email_log) { EmailLog.new(reply_key: reply_key, +# post: post, +# post_id: post.id, +# topic_id: topic.id, +# email_type: 'user_posted', +# user: replying_user, +# user_id: replying_user.id, +# to_address: replying_user_email +# ) } + +# before do +# email_log.save +# end + +# describe "should not create post" do +# let!(:reply_key) { '59d8df8370b7e95c5a49fbf86aeb2c93' } +# let!(:email_raw) { fixture_file("emails/valid_reply.eml") } +# it "raises a TopicClosedError" do +# expect { receiver.process }.to raise_error(Gitlab::EmailReceiver::TopicClosedError) +# end +# end +# end + +# describe "posting reply to a deleted topic" do +# let(:reply_key) { raise "Override this in a lower describe block" } +# let(:email_raw) { raise "Override this in a lower describe block" } +# let(:receiver) { Gitlab::EmailReceiver.new(email_raw) } +# let(:deleted_topic) { Fabricate(:deleted_topic) } +# let(:post) { Fabricate(:post, topic: deleted_topic, post_number: 1) } +# let(:replying_user_email) { 'jake@adventuretime.ooo' } +# let(:replying_user) { Fabricate(:user, email: replying_user_email, trust_level: 2) } +# let(:email_log) { EmailLog.new(reply_key: reply_key, +# post: post, +# post_id: post.id, +# topic_id: deleted_topic.id, +# email_type: 'user_posted', +# user: replying_user, +# user_id: replying_user.id, +# to_address: replying_user_email +# ) } + +# before do +# email_log.save +# end + +# describe "should not create post" do +# let!(:reply_key) { '59d8df8370b7e95c5a49fbf86aeb2c93' } +# let!(:email_raw) { fixture_file("emails/valid_reply.eml") } +# it "raises a TopicNotFoundError" do +# expect { receiver.process }.to raise_error(Gitlab::EmailReceiver::TopicNotFoundError) +# end +# end +# end + +# describe "posting a new topic" do +# let(:category_destination) { raise "Override this in a lower describe block" } +# let(:email_raw) { raise "Override this in a lower describe block" } +# let(:allow_strangers) { false } +# # ---- +# let(:receiver) { Gitlab::EmailReceiver.new(email_raw) } +# let(:user_email) { 'jake@adventuretime.ooo' } +# let(:user) { Fabricate(:user, email: user_email, trust_level: 2)} +# let(:category) { Fabricate(:category, email_in: category_destination, email_in_allow_strangers: allow_strangers) } + +# before do +# SiteSetting.email_in = true +# user.save +# category.save +# end + +# describe "too_short.eml" do +# let!(:category_destination) { 'incoming+amazing@appmail.adventuretime.ooo' } +# let(:email_raw) { +# fixture_file("emails/too_short.eml") +# .gsub("TO", category_destination) +# .gsub("FROM", user_email) +# .gsub("SUBJECT", "A long subject that passes the checks") +# } + +# it "does not create a topic if the post fails" do +# before_topic_count = Topic.count + +# expect { receiver.process }.to raise_error(Gitlab::EmailReceiver::InvalidPost) + +# expect(Topic.count).to eq(before_topic_count) +# end + +# end + +# end + +# def fill_email(mail, from, to, body = nil, subject = nil) +# result = mail.gsub("FROM", from).gsub("TO", to) +# if body +# result.gsub!(/Hey.*/m, body) +# end +# if subject +# result.sub!(/We .*/, subject) +# end +# result +# end + +# def process_email(opts) +# incoming_email = fixture_file("emails/valid_incoming.eml") +# email = fill_email(incoming_email, opts[:from], opts[:to], opts[:body], opts[:subject]) +# Gitlab::EmailReceiver.new(email).process +# end + +# describe "with a valid email" do +# let(:reply_key) { "59d8df8370b7e95c5a49fbf86aeb2c93" } +# let(:to) { SiteSetting.reply_by_email_address.gsub("%{reply_key}", reply_key) } + +# let(:valid_reply) { +# reply = fixture_file("emails/valid_reply.eml") +# to = SiteSetting.reply_by_email_address.gsub("%{reply_key}", reply_key) +# fill_email(reply, "test@test.com", to) +# } + +# let(:receiver) { Gitlab::EmailReceiver.new(valid_reply) } +# let(:post) { create_post } +# let(:user) { post.user } +# let(:email_log) { EmailLog.new(reply_key: reply_key, +# post_id: post.id, +# topic_id: post.topic_id, +# user_id: post.user_id, +# post: post, +# user: user, +# email_type: 'test', +# to_address: 'test@test.com' +# ) } +# let(:reply_body) { +# "I could not disagree more. I am obviously biased but adventure time is the +# greatest show ever created. Everyone should watch it. + +# - Jake out" } + +# describe "with an email log" do + +# it "extracts data" do +# expect{ receiver.process }.to raise_error(Gitlab::EmailReceiver::EmailLogNotFound) + +# email_log.save! +# receiver.process + +# expect(receiver.body).to eq(reply_body) +# expect(receiver.email_log).to eq(email_log) +# end + +# end + +# end +end -- cgit v1.2.1 From e9972efc2f3d730e989907585dd1438c517a0bba Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Thu, 20 Aug 2015 11:05:06 -0700 Subject: Extract ReplyParser and AttachmentUploader from Receiver. --- spec/lib/gitlab/email/reply_parser_spec.rb | 191 ++++++++++++ spec/lib/gitlab/email_receiver_spec.rb | 481 ----------------------------- 2 files changed, 191 insertions(+), 481 deletions(-) create mode 100644 spec/lib/gitlab/email/reply_parser_spec.rb delete mode 100644 spec/lib/gitlab/email_receiver_spec.rb (limited to 'spec/lib') diff --git a/spec/lib/gitlab/email/reply_parser_spec.rb b/spec/lib/gitlab/email/reply_parser_spec.rb new file mode 100644 index 00000000000..999515beb1c --- /dev/null +++ b/spec/lib/gitlab/email/reply_parser_spec.rb @@ -0,0 +1,191 @@ +require "spec_helper" + +# Inspired in great part by Discourse's Email::Receiver +describe Gitlab::Email::ReplyParser do + def fixture_file(filename) + return '' if filename.blank? + file_path = File.expand_path(Rails.root + 'spec/fixtures/' + filename) + File.read(file_path) + end + + describe 'self.parse_body' do + def test_parse_body(mail_string) + described_class.new(Mail::Message.new(mail_string)).execute + end + + it "returns an empty string if the message is blank" do + expect(test_parse_body("")).to eq("") + end + + it "returns an empty string if the message is not an email" do + expect(test_parse_body("asdf" * 30)).to eq("") + end + + it "returns an empty string if there is no reply content" do + expect(test_parse_body(fixture_file("emails/no_content_reply.eml"))).to eq("") + end + + it "can parse the html section" do + expect(test_parse_body(fixture_file("emails/html_only.eml"))).to eq("The EC2 instance - I've seen that there tends to be odd and " + + "unrecommended settings on the Bitnami installs that I've checked out.") + end + + it "supports a Dutch reply" do + expect(test_parse_body(fixture_file("emails/dutch.eml"))).to eq("Dit is een antwoord in het Nederlands.") + end + + it "removes an 'on date wrote' quoting line" do + expect(test_parse_body(fixture_file("emails/on_wrote.eml"))).to eq("Sure, all you need to do is frobnicate the foobar and you'll be all set!") + end + + it "handles multiple paragraphs" do + expect(test_parse_body(fixture_file("emails/paragraphs.eml"))). + to eq( +"Is there any reason the *old* candy can't be be kept in silos while the new candy +is imported into *new* silos? + +The thing about candy is it stays delicious for a long time -- we can just keep +it there without worrying about it too much, imo. + +Thanks for listening." + ) + end + + it "handles multiple paragraphs when parsing html" do + expect(test_parse_body(fixture_file("emails/html_paragraphs.eml"))). + to eq( +"Awesome! + +Pleasure to have you here! + +:boom:" + ) + end + + it "handles newlines" do + expect(test_parse_body(fixture_file("emails/newlines.eml"))). + to eq( +"This is my reply. +It is my best reply. +It will also be my *only* reply." + ) + end + + it "handles inline reply" do + expect(test_parse_body(fixture_file("emails/inline_reply.eml"))). + to eq( +"On Wed, Oct 8, 2014 at 11:12 AM, techAPJ wrote: + +> techAPJ +> November 28 +> +> Test reply. +> +> First paragraph. +> +> Second paragraph. +> +> To respond, reply to this email or visit +> https://meta.discourse.org/t/testing-default-email-replies/22638/3 in +> your browser. +> ------------------------------ +> Previous Replies codinghorror +> +> November 28 +> +> We're testing the latest GitHub email processing library which we are +> integrating now. +> +> https://github.com/github/email_reply_parser +> +> Go ahead and reply to this topic and I'll reply from various email clients +> for testing. +> ------------------------------ +> +> To respond, reply to this email or visit +> https://meta.discourse.org/t/testing-default-email-replies/22638/3 in +> your browser. +> +> To unsubscribe from these emails, visit your user preferences +> . +> + +The quick brown fox jumps over the lazy dog. The quick brown fox jumps over +the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown +fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. +The quick brown fox jumps over the lazy dog. The quick brown fox jumps over +the lazy dog. The quick brown fox jumps over the lazy dog." + ) + end + + it "strips iPhone signature" do + expect(test_parse_body(fixture_file("emails/iphone_signature.eml"))).not_to match /Sent from my iPhone/ + end + + it "properly renders email reply from gmail web client" do + expect(test_parse_body(fixture_file("emails/gmail_web.eml"))). + to eq( +"### This is a reply from standard GMail in Google Chrome. + +The quick brown fox jumps over the lazy dog. The quick brown fox jumps over +the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown +fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. +The quick brown fox jumps over the lazy dog. The quick brown fox jumps over +the lazy dog. The quick brown fox jumps over the lazy dog. + +Here's some **bold** text in Markdown. + +Here's a link http://example.com" + ) + end + + it "properly renders email reply from iOS default mail client" do + expect(test_parse_body(fixture_file("emails/ios_default.eml"))). + to eq( +"### this is a reply from iOS default mail + +The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. + +Here's some **bold** markdown text. + +Here's a link http://example.com" + ) + end + + it "properly renders email reply from Android 5 gmail client" do + expect(test_parse_body(fixture_file("emails/android_gmail.eml"))). + to eq( +"### this is a reply from Android 5 gmail + +The quick brown fox jumps over the lazy dog. The quick brown fox jumps over +the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown +fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. +The quick brown fox jumps over the lazy dog. + +This is **bold** in Markdown. + +This is a link to http://example.com" + ) + end + + it "properly renders email reply from Windows 8.1 Metro default mail client" do + expect(test_parse_body(fixture_file("emails/windows_8_metro.eml"))). + to eq( +"### reply from default mail client in Windows 8.1 Metro + + +The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. + + +This is a **bold** word in Markdown + + +This is a link http://example.com" + ) + end + + it "properly renders email reply from MS Outlook client" do + expect(test_parse_body(fixture_file("emails/outlook.eml"))).to eq("Microsoft Outlook 2010") + end + end +end diff --git a/spec/lib/gitlab/email_receiver_spec.rb b/spec/lib/gitlab/email_receiver_spec.rb deleted file mode 100644 index d6302eac13a..00000000000 --- a/spec/lib/gitlab/email_receiver_spec.rb +++ /dev/null @@ -1,481 +0,0 @@ -require "spec_helper" - -# Inspired in great part by Discourse's Email::Receiver -describe Gitlab::EmailReceiver do - def fixture_file(filename) - return '' if filename.blank? - file_path = File.expand_path(Rails.root + 'spec/fixtures/' + filename) - File.read(file_path) - end - - before do - allow(Gitlab.config.reply_by_email).to receive(:enabled).and_return(true) - allow(Gitlab.config.reply_by_email).to receive(:address).and_return("reply+%{reply_key}@appmail.adventuretime.ooo") - end - - describe 'parse_body' do - def test_parse_body(mail_string) - Gitlab::EmailReceiver.new(nil).parse_body(Mail::Message.new(mail_string)) - end - - it "raises EmptyEmailError if the message is blank" do - expect { test_parse_body("") }.to raise_error(Gitlab::EmailReceiver::EmptyEmailError) - end - - it "raises EmptyEmailError if the message is not an email" do - expect { test_parse_body("asdf" * 30) }.to raise_error(Gitlab::EmailReceiver::EmptyEmailError) - end - - it "raises EmptyEmailError if there is no reply content" do - expect { test_parse_body(fixture_file("emails/no_content_reply.eml")) }.to raise_error(Gitlab::EmailReceiver::EmptyEmailError) - end - - it "can parse the html section" do - expect(test_parse_body(fixture_file("emails/html_only.eml"))).to eq("The EC2 instance - I've seen that there tends to be odd and " + - "unrecommended settings on the Bitnami installs that I've checked out.") - end - - it "supports a Dutch reply" do - expect(test_parse_body(fixture_file("emails/dutch.eml"))).to eq("Dit is een antwoord in het Nederlands.") - end - - it "removes an 'on date wrote' quoting line" do - expect(test_parse_body(fixture_file("emails/on_wrote.eml"))).to eq("Sure, all you need to do is frobnicate the foobar and you'll be all set!") - end - - it "handles multiple paragraphs" do - expect(test_parse_body(fixture_file("emails/paragraphs.eml"))). - to eq( -"Is there any reason the *old* candy can't be be kept in silos while the new candy -is imported into *new* silos? - -The thing about candy is it stays delicious for a long time -- we can just keep -it there without worrying about it too much, imo. - -Thanks for listening." - ) - end - - it "handles multiple paragraphs when parsing html" do - expect(test_parse_body(fixture_file("emails/html_paragraphs.eml"))). - to eq( -"Awesome! - -Pleasure to have you here! - -:boom:" - ) - end - - it "handles newlines" do - expect(test_parse_body(fixture_file("emails/newlines.eml"))). - to eq( -"This is my reply. -It is my best reply. -It will also be my *only* reply." - ) - end - - it "handles inline reply" do - expect(test_parse_body(fixture_file("emails/inline_reply.eml"))). - to eq( -"On Wed, Oct 8, 2014 at 11:12 AM, techAPJ wrote: - -> techAPJ -> November 28 -> -> Test reply. -> -> First paragraph. -> -> Second paragraph. -> -> To respond, reply to this email or visit -> https://meta.discourse.org/t/testing-default-email-replies/22638/3 in -> your browser. -> ------------------------------ -> Previous Replies codinghorror -> -> November 28 -> -> We're testing the latest GitHub email processing library which we are -> integrating now. -> -> https://github.com/github/email_reply_parser -> -> Go ahead and reply to this topic and I'll reply from various email clients -> for testing. -> ------------------------------ -> -> To respond, reply to this email or visit -> https://meta.discourse.org/t/testing-default-email-replies/22638/3 in -> your browser. -> -> To unsubscribe from these emails, visit your user preferences -> . -> - -The quick brown fox jumps over the lazy dog. The quick brown fox jumps over -the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown -fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. -The quick brown fox jumps over the lazy dog. The quick brown fox jumps over -the lazy dog. The quick brown fox jumps over the lazy dog." - ) - end - - it "strips iPhone signature" do - expect(test_parse_body(fixture_file("emails/iphone_signature.eml"))).not_to match /Sent from my iPhone/ - end - - it "properly renders email reply from gmail web client" do - expect(test_parse_body(fixture_file("emails/gmail_web.eml"))). - to eq( -"### This is a reply from standard GMail in Google Chrome. - -The quick brown fox jumps over the lazy dog. The quick brown fox jumps over -the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown -fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. -The quick brown fox jumps over the lazy dog. The quick brown fox jumps over -the lazy dog. The quick brown fox jumps over the lazy dog. - -Here's some **bold** text in Markdown. - -Here's a link http://example.com" - ) - end - - it "properly renders email reply from iOS default mail client" do - expect(test_parse_body(fixture_file("emails/ios_default.eml"))). - to eq( -"### this is a reply from iOS default mail - -The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. - -Here's some **bold** markdown text. - -Here's a link http://example.com" - ) - end - - it "properly renders email reply from Android 5 gmail client" do - expect(test_parse_body(fixture_file("emails/android_gmail.eml"))). - to eq( -"### this is a reply from Android 5 gmail - -The quick brown fox jumps over the lazy dog. The quick brown fox jumps over -the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown -fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. -The quick brown fox jumps over the lazy dog. - -This is **bold** in Markdown. - -This is a link to http://example.com" - ) - end - - it "properly renders email reply from Windows 8.1 Metro default mail client" do - expect(test_parse_body(fixture_file("emails/windows_8_metro.eml"))). - to eq( -"### reply from default mail client in Windows 8.1 Metro - - -The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. - - -This is a **bold** word in Markdown - - -This is a link http://example.com" - ) - end - - it "properly renders email reply from MS Outlook client" do - expect(test_parse_body(fixture_file("emails/outlook.eml"))).to eq("Microsoft Outlook 2010") - end - end - -# describe "posting replies" do -# let(:reply_key) { raise "Override this in a lower describe block" } -# let(:email_raw) { raise "Override this in a lower describe block" } -# # ---- -# let(:receiver) { Gitlab::EmailReceiver.new(email_raw) } -# let(:post) { create_post } -# let(:topic) { post.topic } -# let(:posting_user) { post.user } -# let(:replying_user_email) { 'jake@adventuretime.ooo' } -# let(:replying_user) { Fabricate(:user, email: replying_user_email, trust_level: 2)} -# let(:email_log) { EmailLog.new(reply_key: reply_key, -# post: post, -# post_id: post.id, -# topic_id: post.topic_id, -# email_type: 'user_posted', -# user: replying_user, -# user_id: replying_user.id, -# to_address: replying_user_email -# ) } - -# before do -# email_log.save -# end - -# # === Success Posting === - -# describe "valid_reply.eml" do -# let!(:reply_key) { '59d8df8370b7e95c5a49fbf86aeb2c93' } -# let!(:email_raw) { fixture_file("emails/valid_reply.eml") } - -# it "creates a post with the correct content" do -# start_count = topic.posts.count - -# receiver.process - -# expect(topic.posts.count).to eq(start_count + 1) -# created_post = topic.posts.last -# expect(created_post.via_email).to eq(true) -# expect(created_post.raw_email).to eq(fixture_file("emails/valid_reply.eml")) -# expect(created_post.cooked.strip).to eq(fixture_file("emails/valid_reply.cooked").strip) -# end -# end - -# describe "paragraphs.eml" do -# let!(:reply_key) { '59d8df8370b7e95c5a49fbf86aeb2c93' } -# let!(:email_raw) { fixture_file("emails/paragraphs.eml") } - -# it "cooks multiple paragraphs with traditional Markdown linebreaks" do -# start_count = topic.posts.count - -# receiver.process - -# expect(topic.posts.count).to eq(start_count + 1) -# expect(topic.posts.last.cooked.strip).to eq(fixture_file("emails/paragraphs.cooked").strip) -# expect(topic.posts.last.cooked).not_to match /
/ -# expect(Upload.find_by(sha1: upload_sha)).not_to eq(nil) -# end - -# end - -# # === Failure Conditions === - -# describe "too_short.eml" do -# let!(:reply_key) { '636ca428858779856c226bb145ef4fad' } -# let!(:email_raw) { -# fixture_file("emails/too_short.eml") -# .gsub("TO", "reply+#{reply_key}@appmail.adventuretime.ooo") -# .gsub("FROM", replying_user_email) -# .gsub("SUBJECT", "re: [Discourse Meta] eviltrout posted in 'Adventure Time Sux'") -# } - -# it "raises an InvalidPost error" do -# SiteSetting.min_post_length = 5 -# expect { receiver.process }.to raise_error(Gitlab::EmailReceiver::InvalidPost) -# end -# end - -# describe "too_many_mentions.eml" do -# let!(:reply_key) { '636ca428858779856c226bb145ef4fad' } -# let!(:email_raw) { fixture_file("emails/too_many_mentions.eml") } - -# it "raises an InvalidPost error" do -# SiteSetting.max_mentions_per_post = 10 -# (1..11).each do |i| -# Fabricate(:user, username: "user#{i}").save -# end - -# expect { receiver.process }.to raise_error(Gitlab::EmailReceiver::InvalidPost) -# end -# end - -# describe "auto response email replies should not be accepted" do -# let!(:reply_key) { '636ca428858779856c226bb145ef4fad' } -# let!(:email_raw) { fixture_file("emails/auto_reply.eml") } -# it "raises a AutoGeneratedEmailError" do -# expect { receiver.process }.to raise_error(Gitlab::EmailReceiver::AutoGeneratedEmailError) -# end -# end - -# end - -# describe "posting reply to a closed topic" do -# let(:reply_key) { raise "Override this in a lower describe block" } -# let(:email_raw) { raise "Override this in a lower describe block" } -# let(:receiver) { Gitlab::EmailReceiver.new(email_raw) } -# let(:topic) { Fabricate(:topic, closed: true) } -# let(:post) { Fabricate(:post, topic: topic, post_number: 1) } -# let(:replying_user_email) { 'jake@adventuretime.ooo' } -# let(:replying_user) { Fabricate(:user, email: replying_user_email, trust_level: 2) } -# let(:email_log) { EmailLog.new(reply_key: reply_key, -# post: post, -# post_id: post.id, -# topic_id: topic.id, -# email_type: 'user_posted', -# user: replying_user, -# user_id: replying_user.id, -# to_address: replying_user_email -# ) } - -# before do -# email_log.save -# end - -# describe "should not create post" do -# let!(:reply_key) { '59d8df8370b7e95c5a49fbf86aeb2c93' } -# let!(:email_raw) { fixture_file("emails/valid_reply.eml") } -# it "raises a TopicClosedError" do -# expect { receiver.process }.to raise_error(Gitlab::EmailReceiver::TopicClosedError) -# end -# end -# end - -# describe "posting reply to a deleted topic" do -# let(:reply_key) { raise "Override this in a lower describe block" } -# let(:email_raw) { raise "Override this in a lower describe block" } -# let(:receiver) { Gitlab::EmailReceiver.new(email_raw) } -# let(:deleted_topic) { Fabricate(:deleted_topic) } -# let(:post) { Fabricate(:post, topic: deleted_topic, post_number: 1) } -# let(:replying_user_email) { 'jake@adventuretime.ooo' } -# let(:replying_user) { Fabricate(:user, email: replying_user_email, trust_level: 2) } -# let(:email_log) { EmailLog.new(reply_key: reply_key, -# post: post, -# post_id: post.id, -# topic_id: deleted_topic.id, -# email_type: 'user_posted', -# user: replying_user, -# user_id: replying_user.id, -# to_address: replying_user_email -# ) } - -# before do -# email_log.save -# end - -# describe "should not create post" do -# let!(:reply_key) { '59d8df8370b7e95c5a49fbf86aeb2c93' } -# let!(:email_raw) { fixture_file("emails/valid_reply.eml") } -# it "raises a TopicNotFoundError" do -# expect { receiver.process }.to raise_error(Gitlab::EmailReceiver::TopicNotFoundError) -# end -# end -# end - -# describe "posting a new topic" do -# let(:category_destination) { raise "Override this in a lower describe block" } -# let(:email_raw) { raise "Override this in a lower describe block" } -# let(:allow_strangers) { false } -# # ---- -# let(:receiver) { Gitlab::EmailReceiver.new(email_raw) } -# let(:user_email) { 'jake@adventuretime.ooo' } -# let(:user) { Fabricate(:user, email: user_email, trust_level: 2)} -# let(:category) { Fabricate(:category, email_in: category_destination, email_in_allow_strangers: allow_strangers) } - -# before do -# SiteSetting.email_in = true -# user.save -# category.save -# end - -# describe "too_short.eml" do -# let!(:category_destination) { 'incoming+amazing@appmail.adventuretime.ooo' } -# let(:email_raw) { -# fixture_file("emails/too_short.eml") -# .gsub("TO", category_destination) -# .gsub("FROM", user_email) -# .gsub("SUBJECT", "A long subject that passes the checks") -# } - -# it "does not create a topic if the post fails" do -# before_topic_count = Topic.count - -# expect { receiver.process }.to raise_error(Gitlab::EmailReceiver::InvalidPost) - -# expect(Topic.count).to eq(before_topic_count) -# end - -# end - -# end - -# def fill_email(mail, from, to, body = nil, subject = nil) -# result = mail.gsub("FROM", from).gsub("TO", to) -# if body -# result.gsub!(/Hey.*/m, body) -# end -# if subject -# result.sub!(/We .*/, subject) -# end -# result -# end - -# def process_email(opts) -# incoming_email = fixture_file("emails/valid_incoming.eml") -# email = fill_email(incoming_email, opts[:from], opts[:to], opts[:body], opts[:subject]) -# Gitlab::EmailReceiver.new(email).process -# end - -# describe "with a valid email" do -# let(:reply_key) { "59d8df8370b7e95c5a49fbf86aeb2c93" } -# let(:to) { SiteSetting.reply_by_email_address.gsub("%{reply_key}", reply_key) } - -# let(:valid_reply) { -# reply = fixture_file("emails/valid_reply.eml") -# to = SiteSetting.reply_by_email_address.gsub("%{reply_key}", reply_key) -# fill_email(reply, "test@test.com", to) -# } - -# let(:receiver) { Gitlab::EmailReceiver.new(valid_reply) } -# let(:post) { create_post } -# let(:user) { post.user } -# let(:email_log) { EmailLog.new(reply_key: reply_key, -# post_id: post.id, -# topic_id: post.topic_id, -# user_id: post.user_id, -# post: post, -# user: user, -# email_type: 'test', -# to_address: 'test@test.com' -# ) } -# let(:reply_body) { -# "I could not disagree more. I am obviously biased but adventure time is the -# greatest show ever created. Everyone should watch it. - -# - Jake out" } - -# describe "with an email log" do - -# it "extracts data" do -# expect{ receiver.process }.to raise_error(Gitlab::EmailReceiver::EmailLogNotFound) - -# email_log.save! -# receiver.process - -# expect(receiver.body).to eq(reply_body) -# expect(receiver.email_log).to eq(email_log) -# end - -# end - -# end -end -- cgit v1.2.1 From 991c9f6fdab46909fbbe652b1c88a6521a969c02 Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Thu, 20 Aug 2015 11:33:35 -0700 Subject: Test Email::AttachmentUploader. --- spec/lib/gitlab/email/attachment_uploader_spec.rb | 26 +++++++++++++++++++++++ spec/lib/gitlab/email/reply_parser_spec.rb | 2 +- 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 spec/lib/gitlab/email/attachment_uploader_spec.rb (limited to 'spec/lib') diff --git a/spec/lib/gitlab/email/attachment_uploader_spec.rb b/spec/lib/gitlab/email/attachment_uploader_spec.rb new file mode 100644 index 00000000000..b54ee8aa72a --- /dev/null +++ b/spec/lib/gitlab/email/attachment_uploader_spec.rb @@ -0,0 +1,26 @@ +require "spec_helper" + +describe Gitlab::Email::AttachmentUploader do + def fixture_file(filename) + return '' if filename.blank? + file_path = File.expand_path(Rails.root + 'spec/fixtures/' + filename) + File.read(file_path) + end + + describe "#execute" do + let(:project) { build(:project) } + let(:message_raw) { fixture_file("emails/attachment.eml") } + let(:message) { Mail::Message.new(message_raw) } + + it "creates a post with an attachment" do + links = described_class.new(message).execute(project) + link = links.first + + expect(link).not_to be_nil + expect(link[:is_image]).to be_truthy + expect(link[:alt]).to eq("bricks") + expect(link[:url]).to include("/#{project.path_with_namespace}") + expect(link[:url]).to include("bricks.png") + end + end +end diff --git a/spec/lib/gitlab/email/reply_parser_spec.rb b/spec/lib/gitlab/email/reply_parser_spec.rb index 999515beb1c..32120d56cbc 100644 --- a/spec/lib/gitlab/email/reply_parser_spec.rb +++ b/spec/lib/gitlab/email/reply_parser_spec.rb @@ -8,7 +8,7 @@ describe Gitlab::Email::ReplyParser do File.read(file_path) end - describe 'self.parse_body' do + describe '#execute' do def test_parse_body(mail_string) described_class.new(Mail::Message.new(mail_string)).execute end -- cgit v1.2.1 From 8ec5fb138dde9937814ac138352177399d3e776d Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Thu, 20 Aug 2015 12:17:59 -0700 Subject: Test Gitlab::Email::Receiver. --- spec/lib/gitlab/email/receiver_spec.rb | 135 +++++++++++++++++++++++++++++++++ 1 file changed, 135 insertions(+) create mode 100644 spec/lib/gitlab/email/receiver_spec.rb (limited to 'spec/lib') diff --git a/spec/lib/gitlab/email/receiver_spec.rb b/spec/lib/gitlab/email/receiver_spec.rb new file mode 100644 index 00000000000..65f3ceb5def --- /dev/null +++ b/spec/lib/gitlab/email/receiver_spec.rb @@ -0,0 +1,135 @@ +require "spec_helper" + +describe Gitlab::Email::Receiver do + def fixture_file(filename) + return '' if filename.blank? + file_path = File.expand_path(Rails.root + 'spec/fixtures/' + filename) + File.read(file_path) + end + + before do + allow(Gitlab.config.reply_by_email).to receive(:enabled).and_return(true) + allow(Gitlab.config.reply_by_email).to receive(:address).and_return("reply+%{reply_key}@appmail.adventuretime.ooo") + end + + let(:reply_key) { "59d8df8370b7e95c5a49fbf86aeb2c93" } + let(:email_raw) { fixture_file('emails/valid_reply.eml') } + + let(:project) { create(:project, :public) } + let(:noteable) { create(:issue, project: project) } + let(:user) { create(:user) } + let!(:sent_notification) { SentNotification.record(noteable, user.id, reply_key) } + + let(:receiver) { described_class.new(email_raw) } + + context "when the recipient address doesn't include a reply key" do + let(:email_raw) { fixture_file('emails/valid_reply.eml').gsub(reply_key, "") } + + it "raises a SentNotificationNotFoundError" do + expect { receiver.execute }.to raise_error(Gitlab::Email::Receiver::SentNotificationNotFoundError) + end + end + + context "when no sent notificiation for the reply key could be found" do + let(:email_raw) { fixture_file('emails/valid_reply.eml').gsub(reply_key, "nope") } + + it "raises a SentNotificationNotFoundError" do + expect { receiver.execute }.to raise_error(Gitlab::Email::Receiver::SentNotificationNotFoundError) + end + end + + context "when the email is blank" do + let(:email_raw) { "" } + + it "raises an EmptyEmailError" do + expect { receiver.execute }.to raise_error(Gitlab::Email::Receiver::EmptyEmailError) + end + end + + context "when the email was auto generated" do + let!(:reply_key) { '636ca428858779856c226bb145ef4fad' } + let!(:email_raw) { fixture_file("emails/auto_reply.eml") } + + it "raises an AutoGeneratedEmailError" do + expect { receiver.execute }.to raise_error(Gitlab::Email::Receiver::AutoGeneratedEmailError) + end + end + + context "when the user could not be found" do + before do + user.destroy + end + + it "raises a UserNotFoundError" do + expect { receiver.execute }.to raise_error(Gitlab::Email::Receiver::UserNotFoundError) + end + end + + context "when the user is not authorized to create a note" do + before do + project.update_attribute(:visibility_level, Project::PRIVATE) + end + + it "raises a UserNotAuthorizedError" do + expect { receiver.execute }.to raise_error(Gitlab::Email::Receiver::UserNotAuthorizedError) + end + end + + context "when the noteable could not be found" do + before do + noteable.destroy + end + + it "raises a NoteableNotFoundError" do + expect { receiver.execute }.to raise_error(Gitlab::Email::Receiver::NoteableNotFoundError) + end + end + + context "when the reply is blank" do + let!(:email_raw) { fixture_file("emails/no_content_reply.eml") } + + it "raises an EmptyEmailError" do + expect { receiver.execute }.to raise_error(Gitlab::Email::Receiver::EmptyEmailError) + end + end + + context "when the note could not be saved" do + before do + allow_any_instance_of(Note).to receive(:persisted?).and_return(false) + end + + it "raises an InvalidNoteError" do + expect { receiver.execute }.to raise_error(Gitlab::Email::Receiver::InvalidNoteError) + end + end + + context "when everything is fine" do + before do + allow_any_instance_of(Gitlab::Email::AttachmentUploader).to receive(:execute).and_return( + [ + { + url: "uploads/image.png", + is_image: true, + alt: "image" + } + ] + ) + end + + it "creates a comment" do + expect { receiver.execute }.to change { noteable.notes.count }.by(1) + note = noteable.notes.last + + expect(note.author).to eq(sent_notification.recipient) + expect(note.note).to include("I could not disagree more.") + end + + it "adds all attachments" do + receiver.execute + + note = noteable.notes.last + + expect(note.note).to include("![image](uploads/image.png)") + end + end +end -- cgit v1.2.1 From 2b5a2b8f398aa6af0a24c40cd6586eae76c85a3f Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Thu, 20 Aug 2015 12:29:03 -0700 Subject: Removed unused fixtures. --- spec/lib/gitlab/email/receiver_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/email/receiver_spec.rb b/spec/lib/gitlab/email/receiver_spec.rb index 65f3ceb5def..3d434aeaf91 100644 --- a/spec/lib/gitlab/email/receiver_spec.rb +++ b/spec/lib/gitlab/email/receiver_spec.rb @@ -31,7 +31,7 @@ describe Gitlab::Email::Receiver do end context "when no sent notificiation for the reply key could be found" do - let(:email_raw) { fixture_file('emails/valid_reply.eml').gsub(reply_key, "nope") } + let(:email_raw) { fixture_file('emails/wrong_reply_key.eml') } it "raises a SentNotificationNotFoundError" do expect { receiver.execute }.to raise_error(Gitlab::Email::Receiver::SentNotificationNotFoundError) -- cgit v1.2.1 From 54b04f1c5b6c486a67c654ee9987e5f5ec4501fd Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Thu, 20 Aug 2015 12:41:47 -0700 Subject: Add fixture_file helper. --- spec/lib/gitlab/email/attachment_uploader_spec.rb | 8 +------- spec/lib/gitlab/email/receiver_spec.rb | 6 ------ spec/lib/gitlab/email/reply_parser_spec.rb | 6 ------ spec/lib/gitlab/google_code_import/client_spec.rb | 2 +- spec/lib/gitlab/google_code_import/importer_spec.rb | 2 +- 5 files changed, 3 insertions(+), 21 deletions(-) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/email/attachment_uploader_spec.rb b/spec/lib/gitlab/email/attachment_uploader_spec.rb index b54ee8aa72a..e8208e15e29 100644 --- a/spec/lib/gitlab/email/attachment_uploader_spec.rb +++ b/spec/lib/gitlab/email/attachment_uploader_spec.rb @@ -1,18 +1,12 @@ require "spec_helper" describe Gitlab::Email::AttachmentUploader do - def fixture_file(filename) - return '' if filename.blank? - file_path = File.expand_path(Rails.root + 'spec/fixtures/' + filename) - File.read(file_path) - end - describe "#execute" do let(:project) { build(:project) } let(:message_raw) { fixture_file("emails/attachment.eml") } let(:message) { Mail::Message.new(message_raw) } - it "creates a post with an attachment" do + it "uploads all attachments and returns their links" do links = described_class.new(message).execute(project) link = links.first diff --git a/spec/lib/gitlab/email/receiver_spec.rb b/spec/lib/gitlab/email/receiver_spec.rb index 3d434aeaf91..a6f682a2711 100644 --- a/spec/lib/gitlab/email/receiver_spec.rb +++ b/spec/lib/gitlab/email/receiver_spec.rb @@ -1,12 +1,6 @@ require "spec_helper" describe Gitlab::Email::Receiver do - def fixture_file(filename) - return '' if filename.blank? - file_path = File.expand_path(Rails.root + 'spec/fixtures/' + filename) - File.read(file_path) - end - before do allow(Gitlab.config.reply_by_email).to receive(:enabled).and_return(true) allow(Gitlab.config.reply_by_email).to receive(:address).and_return("reply+%{reply_key}@appmail.adventuretime.ooo") diff --git a/spec/lib/gitlab/email/reply_parser_spec.rb b/spec/lib/gitlab/email/reply_parser_spec.rb index 32120d56cbc..c552e632ce2 100644 --- a/spec/lib/gitlab/email/reply_parser_spec.rb +++ b/spec/lib/gitlab/email/reply_parser_spec.rb @@ -2,12 +2,6 @@ require "spec_helper" # Inspired in great part by Discourse's Email::Receiver describe Gitlab::Email::ReplyParser do - def fixture_file(filename) - return '' if filename.blank? - file_path = File.expand_path(Rails.root + 'spec/fixtures/' + filename) - File.read(file_path) - end - describe '#execute' do def test_parse_body(mail_string) described_class.new(Mail::Message.new(mail_string)).execute diff --git a/spec/lib/gitlab/google_code_import/client_spec.rb b/spec/lib/gitlab/google_code_import/client_spec.rb index 6aa4428f367..37985c062b4 100644 --- a/spec/lib/gitlab/google_code_import/client_spec.rb +++ b/spec/lib/gitlab/google_code_import/client_spec.rb @@ -1,7 +1,7 @@ require "spec_helper" describe Gitlab::GoogleCodeImport::Client do - let(:raw_data) { JSON.parse(File.read(Rails.root.join("spec/fixtures/GoogleCodeProjectHosting.json"))) } + let(:raw_data) { JSON.parse(fixture_file("GoogleCodeProjectHosting.json")) } subject { described_class.new(raw_data) } describe "#valid?" do diff --git a/spec/lib/gitlab/google_code_import/importer_spec.rb b/spec/lib/gitlab/google_code_import/importer_spec.rb index f49cbb7f532..65ad7524cc2 100644 --- a/spec/lib/gitlab/google_code_import/importer_spec.rb +++ b/spec/lib/gitlab/google_code_import/importer_spec.rb @@ -2,7 +2,7 @@ require "spec_helper" describe Gitlab::GoogleCodeImport::Importer do let(:mapped_user) { create(:user, username: "thilo123") } - let(:raw_data) { JSON.parse(File.read(Rails.root.join("spec/fixtures/GoogleCodeProjectHosting.json"))) } + let(:raw_data) { JSON.parse(fixture_file("GoogleCodeProjectHosting.json")) } let(:client) { Gitlab::GoogleCodeImport::Client.new(raw_data) } let(:import_data) do { -- cgit v1.2.1 From 6110e175dc3bcf6d9ef416c7b95696efe509d02b Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Thu, 20 Aug 2015 13:10:55 -0700 Subject: Use heredocs. --- spec/lib/gitlab/email/reply_parser_spec.rb | 202 +++++++++++++++-------------- 1 file changed, 107 insertions(+), 95 deletions(-) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/email/reply_parser_spec.rb b/spec/lib/gitlab/email/reply_parser_spec.rb index c552e632ce2..a94c92ad53c 100644 --- a/spec/lib/gitlab/email/reply_parser_spec.rb +++ b/spec/lib/gitlab/email/reply_parser_spec.rb @@ -34,148 +34,160 @@ describe Gitlab::Email::ReplyParser do it "handles multiple paragraphs" do expect(test_parse_body(fixture_file("emails/paragraphs.eml"))). - to eq( -"Is there any reason the *old* candy can't be be kept in silos while the new candy -is imported into *new* silos? + to eq( + <<-BODY.strip_heredoc.chomp + Is there any reason the *old* candy can't be be kept in silos while the new candy + is imported into *new* silos? -The thing about candy is it stays delicious for a long time -- we can just keep -it there without worrying about it too much, imo. + The thing about candy is it stays delicious for a long time -- we can just keep + it there without worrying about it too much, imo. -Thanks for listening." - ) + Thanks for listening. + BODY + ) end it "handles multiple paragraphs when parsing html" do expect(test_parse_body(fixture_file("emails/html_paragraphs.eml"))). - to eq( -"Awesome! + to eq( + <<-BODY.strip_heredoc.chomp + Awesome! -Pleasure to have you here! + Pleasure to have you here! -:boom:" - ) + :boom: + BODY + ) end it "handles newlines" do expect(test_parse_body(fixture_file("emails/newlines.eml"))). - to eq( -"This is my reply. -It is my best reply. -It will also be my *only* reply." - ) + to eq( + <<-BODY.strip_heredoc.chomp + This is my reply. + It is my best reply. + It will also be my *only* reply. + BODY + ) end it "handles inline reply" do expect(test_parse_body(fixture_file("emails/inline_reply.eml"))). - to eq( -"On Wed, Oct 8, 2014 at 11:12 AM, techAPJ wrote: - -> techAPJ -> November 28 -> -> Test reply. -> -> First paragraph. -> -> Second paragraph. -> -> To respond, reply to this email or visit -> https://meta.discourse.org/t/testing-default-email-replies/22638/3 in -> your browser. -> ------------------------------ -> Previous Replies codinghorror -> -> November 28 -> -> We're testing the latest GitHub email processing library which we are -> integrating now. -> -> https://github.com/github/email_reply_parser -> -> Go ahead and reply to this topic and I'll reply from various email clients -> for testing. -> ------------------------------ -> -> To respond, reply to this email or visit -> https://meta.discourse.org/t/testing-default-email-replies/22638/3 in -> your browser. -> -> To unsubscribe from these emails, visit your user preferences -> . -> - -The quick brown fox jumps over the lazy dog. The quick brown fox jumps over -the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown -fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. -The quick brown fox jumps over the lazy dog. The quick brown fox jumps over -the lazy dog. The quick brown fox jumps over the lazy dog." - ) - end - - it "strips iPhone signature" do - expect(test_parse_body(fixture_file("emails/iphone_signature.eml"))).not_to match /Sent from my iPhone/ + to eq( + <<-BODY.strip_heredoc.chomp + On Wed, Oct 8, 2014 at 11:12 AM, techAPJ wrote: + + > techAPJ + > November 28 + > + > Test reply. + > + > First paragraph. + > + > Second paragraph. + > + > To respond, reply to this email or visit + > https://meta.discourse.org/t/testing-default-email-replies/22638/3 in + > your browser. + > ------------------------------ + > Previous Replies codinghorror + > + > November 28 + > + > We're testing the latest GitHub email processing library which we are + > integrating now. + > + > https://github.com/github/email_reply_parser + > + > Go ahead and reply to this topic and I'll reply from various email clients + > for testing. + > ------------------------------ + > + > To respond, reply to this email or visit + > https://meta.discourse.org/t/testing-default-email-replies/22638/3 in + > your browser. + > + > To unsubscribe from these emails, visit your user preferences + > . + > + + The quick brown fox jumps over the lazy dog. The quick brown fox jumps over + the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown + fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. + The quick brown fox jumps over the lazy dog. The quick brown fox jumps over + the lazy dog. The quick brown fox jumps over the lazy dog. + BODY + ) end it "properly renders email reply from gmail web client" do expect(test_parse_body(fixture_file("emails/gmail_web.eml"))). - to eq( -"### This is a reply from standard GMail in Google Chrome. + to eq( + <<-BODY.strip_heredoc.chomp + ### This is a reply from standard GMail in Google Chrome. -The quick brown fox jumps over the lazy dog. The quick brown fox jumps over -the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown -fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. -The quick brown fox jumps over the lazy dog. The quick brown fox jumps over -the lazy dog. The quick brown fox jumps over the lazy dog. + The quick brown fox jumps over the lazy dog. The quick brown fox jumps over + the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown + fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. + The quick brown fox jumps over the lazy dog. The quick brown fox jumps over + the lazy dog. The quick brown fox jumps over the lazy dog. -Here's some **bold** text in Markdown. + Here's some **bold** text in Markdown. -Here's a link http://example.com" - ) + Here's a link http://example.com + BODY + ) end it "properly renders email reply from iOS default mail client" do expect(test_parse_body(fixture_file("emails/ios_default.eml"))). - to eq( -"### this is a reply from iOS default mail + to eq( + <<-BODY.strip_heredoc.chomp + ### this is a reply from iOS default mail -The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. + The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. -Here's some **bold** markdown text. + Here's some **bold** markdown text. -Here's a link http://example.com" - ) + Here's a link http://example.com + BODY + ) end it "properly renders email reply from Android 5 gmail client" do expect(test_parse_body(fixture_file("emails/android_gmail.eml"))). - to eq( -"### this is a reply from Android 5 gmail + to eq( + <<-BODY.strip_heredoc.chomp + ### this is a reply from Android 5 gmail -The quick brown fox jumps over the lazy dog. The quick brown fox jumps over -the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown -fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. -The quick brown fox jumps over the lazy dog. + The quick brown fox jumps over the lazy dog. The quick brown fox jumps over + the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown + fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. + The quick brown fox jumps over the lazy dog. -This is **bold** in Markdown. + This is **bold** in Markdown. -This is a link to http://example.com" - ) + This is a link to http://example.com + BODY + ) end it "properly renders email reply from Windows 8.1 Metro default mail client" do expect(test_parse_body(fixture_file("emails/windows_8_metro.eml"))). - to eq( -"### reply from default mail client in Windows 8.1 Metro + to eq( + <<-BODY.strip_heredoc.chomp + ### reply from default mail client in Windows 8.1 Metro -The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. + The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. -This is a **bold** word in Markdown + This is a **bold** word in Markdown -This is a link http://example.com" - ) + This is a link http://example.com + BODY + ) end it "properly renders email reply from MS Outlook client" do -- cgit v1.2.1 From 48e25a019a7dacbadeb3a49ed96e41d2c2241feb Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Thu, 20 Aug 2015 13:21:22 -0700 Subject: Add stub_reply_by_email_setting helper. --- spec/lib/gitlab/email/receiver_spec.rb | 3 +-- spec/lib/gitlab/reply_by_email_spec.rb | 12 ++++++------ 2 files changed, 7 insertions(+), 8 deletions(-) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/email/receiver_spec.rb b/spec/lib/gitlab/email/receiver_spec.rb index a6f682a2711..af44c1242ed 100644 --- a/spec/lib/gitlab/email/receiver_spec.rb +++ b/spec/lib/gitlab/email/receiver_spec.rb @@ -2,8 +2,7 @@ require "spec_helper" describe Gitlab::Email::Receiver do before do - allow(Gitlab.config.reply_by_email).to receive(:enabled).and_return(true) - allow(Gitlab.config.reply_by_email).to receive(:address).and_return("reply+%{reply_key}@appmail.adventuretime.ooo") + stub_reply_by_email_setting(enabled: true, address: "reply+%{reply_key}@appmail.adventuretime.ooo") end let(:reply_key) { "59d8df8370b7e95c5a49fbf86aeb2c93" } diff --git a/spec/lib/gitlab/reply_by_email_spec.rb b/spec/lib/gitlab/reply_by_email_spec.rb index a52af51e97c..a678c7e1a76 100644 --- a/spec/lib/gitlab/reply_by_email_spec.rb +++ b/spec/lib/gitlab/reply_by_email_spec.rb @@ -4,12 +4,12 @@ describe Gitlab::ReplyByEmail do describe "self.enabled?" do context "when reply by email is enabled" do before do - allow(Gitlab.config.reply_by_email).to receive(:enabled).and_return(true) + stub_reply_by_email_setting(enabled: true) end context "when the address is valid" do before do - allow(Gitlab.config.reply_by_email).to receive(:address).and_return("replies+%{reply_key}@example.com") + stub_reply_by_email_setting(address: "replies+%{reply_key}@example.com") end it "returns true" do @@ -19,7 +19,7 @@ describe Gitlab::ReplyByEmail do context "when the address is invalid" do before do - allow(Gitlab.config.reply_by_email).to receive(:address).and_return("replies@example.com") + stub_reply_by_email_setting(address: "replies@example.com") end it "returns false" do @@ -30,7 +30,7 @@ describe Gitlab::ReplyByEmail do context "when reply by email is disabled" do before do - allow(Gitlab.config.reply_by_email).to receive(:enabled).and_return(false) + stub_reply_by_email_setting(enabled: false) end it "returns false" do @@ -66,7 +66,7 @@ describe Gitlab::ReplyByEmail do context "self.reply_address" do before do - allow(Gitlab.config.reply_by_email).to receive(:address).and_return("replies+%{reply_key}@example.com") + stub_reply_by_email_setting(address: "replies+%{reply_key}@example.com") end it "returns the address with an interpolated reply key" do @@ -76,7 +76,7 @@ describe Gitlab::ReplyByEmail do context "self.reply_key_from_address" do before do - allow(Gitlab.config.reply_by_email).to receive(:address).and_return("replies+%{reply_key}@example.com") + stub_reply_by_email_setting(address: "replies+%{reply_key}@example.com") end it "returns reply key" do -- cgit v1.2.1 From 747fe7520b244a324b60049cbe22c22a5df29c82 Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Thu, 20 Aug 2015 18:25:16 -0700 Subject: Remove trailing HTML entities from non-Rinku autolinks as well. --- spec/lib/gitlab/markdown/autolink_filter_spec.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/markdown/autolink_filter_spec.rb b/spec/lib/gitlab/markdown/autolink_filter_spec.rb index 982be0782c9..26332ba5217 100644 --- a/spec/lib/gitlab/markdown/autolink_filter_spec.rb +++ b/spec/lib/gitlab/markdown/autolink_filter_spec.rb @@ -86,6 +86,16 @@ module Gitlab::Markdown doc = filter("See #{link}, ok?") expect(doc.at_css('a').text).to eq link + + doc = filter("See #{link}...") + expect(doc.at_css('a').text).to eq link + end + + it 'does not include trailing HTML entities' do + doc = filter("See <<<#{link}>>>") + + expect(doc.at_css('a')['href']).to eq link + expect(doc.text).to eq "See <<<#{link}>>>" end it 'accepts link_attr options' do -- cgit v1.2.1 From 69708dab9f6e1c265dd2bf80eafc39bf68c356e0 Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Fri, 21 Aug 2015 10:14:45 -0700 Subject: Block blocked users from replying to threads by email. --- spec/lib/gitlab/email/receiver_spec.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/email/receiver_spec.rb b/spec/lib/gitlab/email/receiver_spec.rb index af44c1242ed..1cc80f35f98 100644 --- a/spec/lib/gitlab/email/receiver_spec.rb +++ b/spec/lib/gitlab/email/receiver_spec.rb @@ -58,6 +58,16 @@ describe Gitlab::Email::Receiver do end end + context "when the user has been blocked" do + before do + user.block + end + + it "raises a UserBlockedError" do + expect { receiver.execute }.to raise_error(Gitlab::Email::Receiver::UserBlockedError) + end + end + context "when the user is not authorized to create a note" do before do project.update_attribute(:visibility_level, Project::PRIVATE) -- cgit v1.2.1 From 15fc7bd6139f0b429c05c055b4cfab561c926e08 Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Fri, 21 Aug 2015 16:09:55 -0700 Subject: No HTML-only email please --- spec/lib/gitlab/email/reply_parser_spec.rb | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/email/reply_parser_spec.rb b/spec/lib/gitlab/email/reply_parser_spec.rb index a94c92ad53c..7cae1da8050 100644 --- a/spec/lib/gitlab/email/reply_parser_spec.rb +++ b/spec/lib/gitlab/email/reply_parser_spec.rb @@ -19,9 +19,22 @@ describe Gitlab::Email::ReplyParser do expect(test_parse_body(fixture_file("emails/no_content_reply.eml"))).to eq("") end - it "can parse the html section" do - expect(test_parse_body(fixture_file("emails/html_only.eml"))).to eq("The EC2 instance - I've seen that there tends to be odd and " + - "unrecommended settings on the Bitnami installs that I've checked out.") + it "properly renders plaintext-only email" do + expect(test_parse_body(fixture_file("emails/plaintext_only.eml"))). + to eq( + <<-BODY.strip_heredoc.chomp + ### reply from default mail client in Windows 8.1 Metro + + + The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. + + + This is a **bold** word in Markdown + + + This is a link http://example.com + BODY + ) end it "supports a Dutch reply" do -- cgit v1.2.1 From ed1d4fa477789659f9343593bf06d50e70750561 Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Fri, 7 Aug 2015 00:06:20 -0700 Subject: Remove user OAuth tokens stored in database for Bitbucket, GitHub, and GitLab and request them each session. Pass these tokens to the project import data. This prevents the need to encrypt these tokens and clear them in case they expire or get revoked. For example, if you deleted and re-created OAuth2 keys for Bitbucket, you would get an Error 500 with no way to recover: ``` Started GET "/import/bitbucket/status" for x.x.x.x at 2015-08-07 05:24:10 +0000 Processing by Import::BitbucketController#status as HTML Completed 500 Internal Server Error in 607ms (ActiveRecord: 2.3ms) NameError (uninitialized constant Import::BitbucketController::Unauthorized): app/controllers/import/bitbucket_controller.rb:77:in `rescue in go_to_bitbucket_for_permissions' app/controllers/import/bitbucket_controller.rb:74:in `go_to_bitbucket_for_permissions' app/controllers/import/bitbucket_controller.rb:86:in `bitbucket_unauthorized' ``` Closes #1871 --- spec/lib/gitlab/bitbucket_import/project_creator_spec.rb | 7 +++++-- spec/lib/gitlab/github_import/project_creator_spec.rb | 6 ++++-- spec/lib/gitlab/gitlab_import/project_creator_spec.rb | 6 ++++-- 3 files changed, 13 insertions(+), 6 deletions(-) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/bitbucket_import/project_creator_spec.rb b/spec/lib/gitlab/bitbucket_import/project_creator_spec.rb index f8958c9bab8..0e826a319e0 100644 --- a/spec/lib/gitlab/bitbucket_import/project_creator_spec.rb +++ b/spec/lib/gitlab/bitbucket_import/project_creator_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' describe Gitlab::BitbucketImport::ProjectCreator do - let(:user) { create(:user, bitbucket_access_token: "asdffg", bitbucket_access_token_secret: "sekret") } + let(:user) { create(:user) } let(:repo) do { name: 'Vim', @@ -11,6 +11,9 @@ describe Gitlab::BitbucketImport::ProjectCreator do }.with_indifferent_access end let(:namespace){ create(:group, owner: user) } + let(:token) { "asdasd12345" } + let(:secret) { "sekrettt" } + let(:access_params) { { bitbucket_access_token: token, bitbucket_access_token_secret: secret } } before do namespace.add_owner(user) @@ -19,7 +22,7 @@ describe Gitlab::BitbucketImport::ProjectCreator do it 'creates project' do allow_any_instance_of(Project).to receive(:add_import_job) - project_creator = Gitlab::BitbucketImport::ProjectCreator.new(repo, namespace, user) + project_creator = Gitlab::BitbucketImport::ProjectCreator.new(repo, namespace, user, access_params) project = project_creator.execute expect(project.import_url).to eq("ssh://git@bitbucket.org/asd/vim.git") diff --git a/spec/lib/gitlab/github_import/project_creator_spec.rb b/spec/lib/gitlab/github_import/project_creator_spec.rb index 4fe7bd3b77d..ca61d3c5234 100644 --- a/spec/lib/gitlab/github_import/project_creator_spec.rb +++ b/spec/lib/gitlab/github_import/project_creator_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' describe Gitlab::GithubImport::ProjectCreator do - let(:user) { create(:user, github_access_token: "asdffg") } + let(:user) { create(:user) } let(:repo) do OpenStruct.new( login: 'vim', @@ -13,6 +13,8 @@ describe Gitlab::GithubImport::ProjectCreator do ) end let(:namespace){ create(:group, owner: user) } + let(:token) { "asdffg" } + let(:access_params) { { github_access_token: token } } before do namespace.add_owner(user) @@ -21,7 +23,7 @@ describe Gitlab::GithubImport::ProjectCreator do it 'creates project' do allow_any_instance_of(Project).to receive(:add_import_job) - project_creator = Gitlab::GithubImport::ProjectCreator.new(repo, namespace, user) + project_creator = Gitlab::GithubImport::ProjectCreator.new(repo, namespace, user, access_params) project = project_creator.execute expect(project.import_url).to eq("https://asdffg@gitlab.com/asd/vim.git") diff --git a/spec/lib/gitlab/gitlab_import/project_creator_spec.rb b/spec/lib/gitlab/gitlab_import/project_creator_spec.rb index 938d08396fd..2d8923d14bb 100644 --- a/spec/lib/gitlab/gitlab_import/project_creator_spec.rb +++ b/spec/lib/gitlab/gitlab_import/project_creator_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' describe Gitlab::GitlabImport::ProjectCreator do - let(:user) { create(:user, gitlab_access_token: "asdffg") } + let(:user) { create(:user) } let(:repo) do { name: 'vim', @@ -13,6 +13,8 @@ describe Gitlab::GitlabImport::ProjectCreator do }.with_indifferent_access end let(:namespace){ create(:group, owner: user) } + let(:token) { "asdffg" } + let(:access_params) { { gitlab_access_token: token } } before do namespace.add_owner(user) @@ -21,7 +23,7 @@ describe Gitlab::GitlabImport::ProjectCreator do it 'creates project' do allow_any_instance_of(Project).to receive(:add_import_job) - project_creator = Gitlab::GitlabImport::ProjectCreator.new(repo, namespace, user) + project_creator = Gitlab::GitlabImport::ProjectCreator.new(repo, namespace, user, access_params) project = project_creator.execute expect(project.import_url).to eq("https://oauth2:asdffg@gitlab.com/asd/vim.git") -- cgit v1.2.1 From 646c1f0324650c5736e85db0deb55dceb943fa7a Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Mon, 24 Aug 2015 18:56:01 -0700 Subject: Re-enable the "links with adjacent text" UserReferenceFilter spec --- spec/lib/gitlab/markdown/user_reference_filter_spec.rb | 1 - 1 file changed, 1 deletion(-) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/markdown/user_reference_filter_spec.rb b/spec/lib/gitlab/markdown/user_reference_filter_spec.rb index a5405e14a73..02d923b036c 100644 --- a/spec/lib/gitlab/markdown/user_reference_filter_spec.rb +++ b/spec/lib/gitlab/markdown/user_reference_filter_spec.rb @@ -121,7 +121,6 @@ module Gitlab::Markdown end it 'links with adjacent text' do - skip "TODO (rspeicher): Re-enable when usernames can't end in periods." doc = filter("Mention me (#{reference}.)") expect(doc.to_html).to match(/\(#{reference}<\/a>\.\)/) end -- cgit v1.2.1 From 4344b8d2d4367b19c6849c3cab0d02d17ddf2304 Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Tue, 25 Aug 2015 14:31:33 -0700 Subject: Add Gitlab::ColorSchemes module Very similar to Gitlab::Theme, this contains all of the definitions for our syntax highlighting schemes. --- spec/lib/gitlab/color_schemes_spec.rb | 45 +++++++++++++++++++++++++++++++++++ spec/lib/gitlab/themes_spec.rb | 3 --- 2 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 spec/lib/gitlab/color_schemes_spec.rb (limited to 'spec/lib') diff --git a/spec/lib/gitlab/color_schemes_spec.rb b/spec/lib/gitlab/color_schemes_spec.rb new file mode 100644 index 00000000000..c7be45dbcd3 --- /dev/null +++ b/spec/lib/gitlab/color_schemes_spec.rb @@ -0,0 +1,45 @@ +require 'spec_helper' + +describe Gitlab::ColorSchemes do + describe '.body_classes' do + it 'returns a space-separated list of class names' do + css = described_class.body_classes + + expect(css).to include('white') + expect(css).to include(' solarized-light ') + expect(css).to include(' monokai') + end + end + + describe '.by_id' do + it 'returns a scheme by its ID' do + expect(described_class.by_id(1).name).to eq 'White' + expect(described_class.by_id(4).name).to eq 'Solarized Dark' + end + end + + describe '.default' do + it 'returns the default scheme' do + expect(described_class.default.id).to eq 1 + end + end + + describe '.each' do + it 'passes the block to the SCHEMES Array' do + ids = [] + described_class.each { |scheme| ids << scheme.id } + expect(ids).not_to be_empty + end + end + + describe '.for_user' do + it 'returns default when user is nil' do + expect(described_class.for_user(nil).id).to eq 1 + end + + it "returns user's preferred color scheme" do + user = double(color_scheme_id: 5) + expect(described_class.for_user(user).id).to eq 5 + end + end +end diff --git a/spec/lib/gitlab/themes_spec.rb b/spec/lib/gitlab/themes_spec.rb index 9c6c3fd8104..e554458e41c 100644 --- a/spec/lib/gitlab/themes_spec.rb +++ b/spec/lib/gitlab/themes_spec.rb @@ -43,9 +43,6 @@ describe Gitlab::Themes do ids = [] described_class.each { |theme| ids << theme.id } expect(ids).not_to be_empty - - # TODO (rspeicher): RSpec 3.x - # expect(described_class.each).to yield_with_arg(described_class::Theme) end end end -- cgit v1.2.1