diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-19 21:09:10 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-19 21:09:10 +0300 |
commit | 33795139ea8e72756bee3675b4e16387425e6ab1 (patch) | |
tree | 3ca568fca61482e57810ee30ad5ce4b964a82c4e /spec/models/resource_milestone_event_spec.rb | |
parent | c7e385e282bcb8505589bce526e692b7bb819ffa (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/models/resource_milestone_event_spec.rb')
-rw-r--r-- | spec/models/resource_milestone_event_spec.rb | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/spec/models/resource_milestone_event_spec.rb b/spec/models/resource_milestone_event_spec.rb new file mode 100644 index 00000000000..1b0181e3fd2 --- /dev/null +++ b/spec/models/resource_milestone_event_spec.rb @@ -0,0 +1,55 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe ResourceMilestoneEvent, type: :model do + it_behaves_like 'a resource event' + it_behaves_like 'a resource event for issues' + it_behaves_like 'a resource event for merge requests' + + it_behaves_like 'having unique enum values' + + describe 'associations' do + it { is_expected.to belong_to(:milestone) } + end + + describe 'validations' do + context 'when issue and merge_request are both nil' do + subject { build(described_class.name.underscore.to_sym, issue: nil, merge_request: nil) } + + it { is_expected.not_to be_valid } + end + + context 'when issue and merge_request are both set' do + subject { build(described_class.name.underscore.to_sym, issue: build(:issue), merge_request: build(:merge_request)) } + + it { is_expected.not_to be_valid } + end + + context 'when issue is set' do + subject { create(described_class.name.underscore.to_sym, issue: create(:issue), merge_request: nil) } + + it { is_expected.to be_valid } + end + + context 'when merge_request is set' do + subject { create(described_class.name.underscore.to_sym, issue: nil, merge_request: create(:merge_request)) } + + it { is_expected.to be_valid } + end + end + + describe 'states' do + [Issue, MergeRequest].each do |klass| + klass.available_states.each do |state| + it "supports state #{state.first} for #{klass.name.underscore}" do + model = create(klass.name.underscore, state: state[0]) + key = model.class.name.underscore + event = build(described_class.name.underscore.to_sym, key => model, state: model.state) + + expect(event.state).to eq(state[0]) + end + end + end + end +end |