Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorDouwe Maan <douwe@gitlab.com>2015-08-20 02:05:58 +0300
committerDouwe Maan <douwe@gitlab.com>2015-08-20 02:05:58 +0300
commit41fdd20c746f34a02d670dc2784cc279b2478cb7 (patch)
treed2d731b9dcf23a98a03e55ce27cbafad258f3da3 /spec
parenteacdd5080a4f62442e7ee885d4053562a4bb8acc (diff)
Test Gitlab::ReplyByEmail.
Diffstat (limited to 'spec')
-rw-r--r--spec/lib/gitlab/reply_by_email_spec.rb86
1 files changed, 86 insertions, 0 deletions
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