diff options
Diffstat (limited to 'spec/models/concerns')
-rw-r--r-- | spec/models/concerns/deployment_platform_spec.rb | 20 | ||||
-rw-r--r-- | spec/models/concerns/from_union_spec.rb | 6 | ||||
-rw-r--r-- | spec/models/concerns/issuable_spec.rb | 28 | ||||
-rw-r--r-- | spec/models/concerns/noteable_spec.rb | 44 | ||||
-rw-r--r-- | spec/models/concerns/redactable_spec.rb | 38 | ||||
-rw-r--r-- | spec/models/concerns/subscribable_spec.rb | 56 |
6 files changed, 105 insertions, 87 deletions
diff --git a/spec/models/concerns/deployment_platform_spec.rb b/spec/models/concerns/deployment_platform_spec.rb index f99bf18768f..9164c3a75c5 100644 --- a/spec/models/concerns/deployment_platform_spec.rb +++ b/spec/models/concerns/deployment_platform_spec.rb @@ -13,7 +13,11 @@ describe DeploymentPlatform do end context 'when project is the cluster\'s management project ' do - let!(:cluster_with_management_project) { create(:cluster, :provided_by_user, management_project: project) } + let(:another_project) { create(:project, namespace: project.namespace) } + + let!(:cluster_with_management_project) do + create(:cluster, :provided_by_user, projects: [another_project], management_project: project) + end context 'cluster_management_project feature is enabled' do it 'returns the cluster with management project' do @@ -66,7 +70,11 @@ describe DeploymentPlatform do end context 'when project is the cluster\'s management project ' do - let!(:cluster_with_management_project) { create(:cluster, :provided_by_user, management_project: project) } + let(:another_project) { create(:project, namespace: project.namespace) } + + let!(:cluster_with_management_project) do + create(:cluster, :provided_by_user, projects: [another_project], management_project: project) + end context 'cluster_management_project feature is enabled' do it 'returns the cluster with management project' do @@ -130,5 +138,13 @@ describe DeploymentPlatform do end end end + + context 'when instance has configured kubernetes cluster' do + let!(:instance_cluster) { create(:cluster, :provided_by_user, :instance) } + + it 'returns the Kubernetes platform' do + is_expected.to eq(instance_cluster.platform_kubernetes) + end + end end end diff --git a/spec/models/concerns/from_union_spec.rb b/spec/models/concerns/from_union_spec.rb index ee427a667c6..735e14b47ec 100644 --- a/spec/models/concerns/from_union_spec.rb +++ b/spec/models/concerns/from_union_spec.rb @@ -15,7 +15,7 @@ describe FromUnion do it 'selects from the results of the UNION' do query = model.from_union([model.where(id: 1), model.where(id: 2)]) - expect(query.to_sql).to match(/FROM \(SELECT.+UNION.+SELECT.+\) users/m) + expect(query.to_sql).to match(/FROM \(\(SELECT.+\)\nUNION\n\(SELECT.+\)\) users/m) end it 'supports the use of a custom alias for the sub query' do @@ -24,7 +24,7 @@ describe FromUnion do alias_as: 'kittens' ) - expect(query.to_sql).to match(/FROM \(SELECT.+UNION.+SELECT.+\) kittens/m) + expect(query.to_sql).to match(/FROM \(\(SELECT.+\)\nUNION\n\(SELECT.+\)\) kittens/m) end it 'supports keeping duplicate rows' do @@ -34,7 +34,7 @@ describe FromUnion do ) expect(query.to_sql) - .to match(/FROM \(SELECT.+UNION ALL.+SELECT.+\) users/m) + .to match(/FROM \(\(SELECT.+\)\nUNION ALL\n\(SELECT.+\)\) users/m) end end end diff --git a/spec/models/concerns/issuable_spec.rb b/spec/models/concerns/issuable_spec.rb index e8116f0a301..f7bef9e71e2 100644 --- a/spec/models/concerns/issuable_spec.rb +++ b/spec/models/concerns/issuable_spec.rb @@ -111,6 +111,34 @@ describe Issuable do end end + describe '.initialize' do + it 'maps the state to the right state_id' do + described_class::STATE_ID_MAP.each do |key, value| + issuable = MergeRequest.new(state: key) + + expect(issuable.state).to eq(key) + expect(issuable.state_id).to eq(value) + end + end + + it 'maps a string version of the state to the right state_id' do + described_class::STATE_ID_MAP.each do |key, value| + issuable = MergeRequest.new('state' => key) + + expect(issuable.state).to eq(key) + expect(issuable.state_id).to eq(value) + end + end + + it 'gives preference to state_id if present' do + issuable = MergeRequest.new('state' => 'opened', + 'state_id' => described_class::STATE_ID_MAP['merged']) + + expect(issuable.state).to eq('merged') + expect(issuable.state_id).to eq(described_class::STATE_ID_MAP['merged']) + end + end + describe '#milestone_available?' do let(:group) { create(:group) } let(:project) { create(:project, group: group) } diff --git a/spec/models/concerns/noteable_spec.rb b/spec/models/concerns/noteable_spec.rb index f823ac0165f..e8991a3a015 100644 --- a/spec/models/concerns/noteable_spec.rb +++ b/spec/models/concerns/noteable_spec.rb @@ -177,50 +177,6 @@ describe Noteable do end end - describe "#discussions_to_be_resolved?" do - context "when discussions are not resolvable" do - before do - allow(subject).to receive(:discussions_resolvable?).and_return(false) - end - - it "returns false" do - expect(subject.discussions_to_be_resolved?).to be false - end - end - - context "when discussions are resolvable" do - before do - allow(subject).to receive(:discussions_resolvable?).and_return(true) - - allow(first_discussion).to receive(:resolvable?).and_return(true) - allow(second_discussion).to receive(:resolvable?).and_return(false) - allow(third_discussion).to receive(:resolvable?).and_return(true) - end - - context "when all resolvable discussions are resolved" do - before do - allow(first_discussion).to receive(:resolved?).and_return(true) - allow(third_discussion).to receive(:resolved?).and_return(true) - end - - it "returns false" do - expect(subject.discussions_to_be_resolved?).to be false - end - end - - context "when some resolvable discussions are not resolved" do - before do - allow(first_discussion).to receive(:resolved?).and_return(true) - allow(third_discussion).to receive(:resolved?).and_return(false) - end - - it "returns true" do - expect(subject.discussions_to_be_resolved?).to be true - end - end - end - end - describe "#discussions_to_be_resolved" do before do allow(first_discussion).to receive(:to_be_resolved?).and_return(true) diff --git a/spec/models/concerns/redactable_spec.rb b/spec/models/concerns/redactable_spec.rb index 57c7d2cb767..3f6a2e2410c 100644 --- a/spec/models/concerns/redactable_spec.rb +++ b/spec/models/concerns/redactable_spec.rb @@ -7,44 +7,6 @@ describe Redactable do stub_commonmark_sourcepos_disabled end - shared_examples 'model with redactable field' do - it 'redacts unsubscribe token' do - model[field] = 'some text /sent_notifications/00000000000000000000000000000000/unsubscribe more text' - - model.save! - - expect(model[field]).to eq 'some text /sent_notifications/REDACTED/unsubscribe more text' - end - - it 'ignores not hexadecimal tokens' do - text = 'some text /sent_notifications/token/unsubscribe more text' - model[field] = text - - model.save! - - expect(model[field]).to eq text - end - - it 'ignores not matching texts' do - text = 'some text /sent_notifications/.*/unsubscribe more text' - model[field] = text - - model.save! - - expect(model[field]).to eq text - end - - it 'redacts the field when saving the model before creating markdown cache' do - model[field] = 'some text /sent_notifications/00000000000000000000000000000000/unsubscribe more text' - - model.save! - - expected = 'some text /sent_notifications/REDACTED/unsubscribe more text' - expect(model[field]).to eq expected - expect(model["#{field}_html"]).to eq "<p dir=\"auto\">#{expected}</p>" - end - end - context 'when model is an issue' do it_behaves_like 'model with redactable field' do let(:model) { create(:issue) } diff --git a/spec/models/concerns/subscribable_spec.rb b/spec/models/concerns/subscribable_spec.rb index 2f88adf08dd..f189cd7633c 100644 --- a/spec/models/concerns/subscribable_spec.rb +++ b/spec/models/concerns/subscribable_spec.rb @@ -133,4 +133,60 @@ describe Subscribable, 'Subscribable' do end end end + + describe '#set_subscription' do + shared_examples 'setting subscriptions' do + context 'when desired_state is set to true' do + context 'when a user is subscribed to the resource' do + it 'keeps the user subscribed' do + resource.subscriptions.create(user: user_1, subscribed: true, project: resource_project) + + resource.set_subscription(user_1, true, resource_project) + + expect(resource.subscribed?(user_1, resource_project)).to be_truthy + end + end + + context 'when a user is not subscribed to the resource' do + it 'subscribes the user to the resource' do + expect { resource.set_subscription(user_1, true, resource_project) } + .to change { resource.subscribed?(user_1, resource_project) } + .from(false).to(true) + end + end + end + + context 'when desired_state is set to false' do + context 'when a user is subscribed to the resource' do + it 'unsubscribes the user from the resource' do + resource.subscriptions.create(user: user_1, subscribed: true, project: resource_project) + + expect { resource.set_subscription(user_1, false, resource_project) } + .to change { resource.subscribed?(user_1, resource_project) } + .from(true).to(false) + end + end + + context 'when a user is not subscribed to the resource' do + it 'keeps the user unsubscribed' do + resource.set_subscription(user_1, false, resource_project) + + expect(resource.subscribed?(user_1, resource_project)).to be_falsey + end + end + end + end + + context 'without project' do + let(:resource_project) { nil } + + it_behaves_like 'setting subscriptions' + end + + context 'with project' do + let(:resource_project) { project } + + it_behaves_like 'setting subscriptions' + end + end end |