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
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-02-12 21:09:21 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-02-12 21:09:21 +0300
commit43e3dc2f95a25c600e08f65d4f1c406a1a63ed3d (patch)
treedb5c72020c7c8916020c8aff7c1b7128028d650b /spec/lib/gitlab/redis
parent2c89e169769ead722394a79ed67fcd08e96863dd (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib/gitlab/redis')
-rw-r--r--spec/lib/gitlab/redis/boolean_spec.rb150
1 files changed, 150 insertions, 0 deletions
diff --git a/spec/lib/gitlab/redis/boolean_spec.rb b/spec/lib/gitlab/redis/boolean_spec.rb
new file mode 100644
index 00000000000..bfacf0c448b
--- /dev/null
+++ b/spec/lib/gitlab/redis/boolean_spec.rb
@@ -0,0 +1,150 @@
+# frozen_string_literal: true
+
+require "spec_helper"
+
+describe Gitlab::Redis::Boolean do
+ subject(:redis_boolean) { described_class.new(bool) }
+
+ let(:bool) { true }
+ let(:label_section) { "#{described_class::LABEL}#{described_class::DELIMITER}" }
+
+ describe "#to_s" do
+ subject { redis_boolean.to_s }
+
+ context "true" do
+ let(:bool) { true }
+
+ it { is_expected.to eq("#{label_section}#{described_class::TRUE_STR}") }
+ end
+
+ context "false" do
+ let(:bool) { false }
+
+ it { is_expected.to eq("#{label_section}#{described_class::FALSE_STR}") }
+ end
+ end
+
+ describe ".encode" do
+ subject { redis_boolean.class.encode(bool) }
+
+ context "true" do
+ let(:bool) { true }
+
+ it { is_expected.to eq("#{label_section}#{described_class::TRUE_STR}") }
+ end
+
+ context "false" do
+ let(:bool) { false }
+
+ it { is_expected.to eq("#{label_section}#{described_class::FALSE_STR}") }
+ end
+ end
+
+ describe ".decode" do
+ subject { redis_boolean.class.decode(str) }
+
+ context "valid encoded bool" do
+ let(:str) { "#{label_section}#{bool_str}" }
+
+ context "true" do
+ let(:bool_str) { described_class::TRUE_STR }
+
+ it { is_expected.to be(true) }
+ end
+
+ context "false" do
+ let(:bool_str) { described_class::FALSE_STR }
+
+ it { is_expected.to be(false) }
+ end
+ end
+
+ context "partially invalid bool" do
+ let(:str) { "#{label_section}whoops" }
+
+ it "raises an error" do
+ expect { subject }.to raise_error(described_class::NotAnEncodedBooleanStringError)
+ end
+ end
+
+ context "invalid encoded bool" do
+ let(:str) { "whoops" }
+
+ it "raises an error" do
+ expect { subject }.to raise_error(described_class::NotAnEncodedBooleanStringError)
+ end
+ end
+ end
+
+ describe ".true?" do
+ subject { redis_boolean.class.true?(str) }
+
+ context "valid encoded bool" do
+ let(:str) { "#{label_section}#{bool_str}" }
+
+ context "true" do
+ let(:bool_str) { described_class::TRUE_STR }
+
+ it { is_expected.to be(true) }
+ end
+
+ context "false" do
+ let(:bool_str) { described_class::FALSE_STR }
+
+ it { is_expected.to be(false) }
+ end
+ end
+
+ context "partially invalid bool" do
+ let(:str) { "#{label_section}whoops" }
+
+ it "raises an error" do
+ expect { subject }.to raise_error(described_class::NotAnEncodedBooleanStringError)
+ end
+ end
+
+ context "invalid encoded bool" do
+ let(:str) { "whoops" }
+
+ it "raises an error" do
+ expect { subject }.to raise_error(described_class::NotAnEncodedBooleanStringError)
+ end
+ end
+ end
+
+ describe ".false?" do
+ subject { redis_boolean.class.false?(str) }
+
+ context "valid encoded bool" do
+ let(:str) { "#{label_section}#{bool_str}" }
+
+ context "true" do
+ let(:bool_str) { described_class::TRUE_STR }
+
+ it { is_expected.to be(false) }
+ end
+
+ context "false" do
+ let(:bool_str) { described_class::FALSE_STR }
+
+ it { is_expected.to be(true) }
+ end
+ end
+
+ context "partially invalid bool" do
+ let(:str) { "#{label_section}whoops" }
+
+ it "raises an error" do
+ expect { subject }.to raise_error(described_class::NotAnEncodedBooleanStringError)
+ end
+ end
+
+ context "invalid encoded bool" do
+ let(:str) { "whoops" }
+
+ it "raises an error" do
+ expect { subject }.to raise_error(described_class::NotAnEncodedBooleanStringError)
+ end
+ end
+ end
+end