Commit dfc1a7c3 authored by Mark Chao's avatar Mark Chao

spec styling

parent c0c0cd25
......@@ -344,7 +344,7 @@ describe Epic do
context 'query count check' do
let(:milestone) { create(:milestone, start_date: Date.new(2000, 1, 1), due_date: Date.new(2000, 1, 10)) }
let!(:epics) { [ create(:epic) ] }
let!(:epics) { [create(:epic)] }
def setup_control_group
link_epic_to_milestone(epics[0], milestone)
......
......@@ -40,7 +40,7 @@ describe API::Epics do
end
end
shared_examples 'admin_epic permission' do
shared_examples 'can admin epics' do
let(:extra_date_fields) { %w[start_date_is_fixed start_date_fixed due_date_is_fixed due_date_fixed] }
context 'when permission is absent' do
......@@ -165,7 +165,7 @@ describe API::Epics do
expect_array_response([epic2.id])
end
it_behaves_like 'admin_epic permission'
it_behaves_like 'can admin epics'
end
end
......@@ -191,7 +191,7 @@ describe API::Epics do
expect(response).to match_response_schema('public_api/v4/epic', dir: 'ee')
end
it_behaves_like 'admin_epic permission'
it_behaves_like 'can admin epics'
end
end
......
......@@ -272,6 +272,7 @@ describe EpicIssues::CreateService do
context 'refresh epic dates' do
it 'calls epic#update_dates' do
expect(epic).to receive(:update_dates)
assign_issue([valid_reference])
end
end
......
......@@ -79,6 +79,7 @@ describe EpicIssues::DestroyService do
context 'refresh epic dates' do
it 'calls epic#update_dates' do
expect(epic).to receive(:update_dates)
subject
end
end
......
......@@ -29,12 +29,11 @@ describe Epics::UpdateService do
update_epic(opts)
expect(epic).to be_valid
expect(epic.title).to eq(opts[:title])
expect(epic.description).to eq(opts[:description])
expect(epic.start_date_fixed).to eq(Date.strptime(opts[:start_date_fixed]))
expect(epic.start_date_is_fixed).to eq(opts[:start_date_is_fixed])
expect(epic.due_date_fixed).to eq(Date.strptime(opts[:due_date_fixed]))
expect(epic.due_date_is_fixed).to eq(opts[:due_date_is_fixed])
expect(epic).to have_attributes(opts.except(:due_date_fixed, :start_date_fixed))
expect(epic).to have_attributes(
start_date_fixed: Date.strptime(opts[:start_date_fixed]),
due_date_fixed: Date.strptime(opts[:due_date_fixed])
)
end
it 'updates the last_edited_at value' do
......@@ -125,8 +124,7 @@ describe Epics::UpdateService do
expect { update_epic(start_date: Date.today, end_date: Date.today) }.not_to change { Note.count }
expect(epic).to be_valid
expect(epic.start_date).to eq(nil)
expect(epic.due_date).to eq(nil)
expect(epic).to have_attributes(start_date: nil, due_date: nil)
end
end
......@@ -134,6 +132,7 @@ describe Epics::UpdateService do
context 'date fields are updated' do
it 'calls epic#update_dates' do
expect(epic).to receive(:update_dates)
update_epic(start_date_is_fixed: true, start_date_fixed: Date.today)
end
end
......@@ -141,6 +140,7 @@ describe Epics::UpdateService do
context 'date fields are not updated' do
it 'does not call epic#update_dates' do
expect(epic).not_to receive(:update_dates)
update_epic(title: 'foo')
end
end
......
......@@ -2,25 +2,26 @@
require 'spec_helper'
describe Milestones::UpdateService do
let(:project) { create(:project) }
let(:user) { build(:user) }
let(:milestone) { create(:milestone, project: project) }
describe '#execute' do
context 'refresh related epic dates' do
let(:epic) { create(:epic) }
let!(:issue) { create(:issue, milestone: milestone, epic: epic) }
let(:due_date) { 3.days.from_now.to_date }
it 'calls epic#update_dates' do
project = create(:project)
user = build(:user)
milestone = create(:milestone, project: project)
epic = create(:epic)
create(:issue, milestone: milestone, epic: epic)
due_date = 3.days.from_now.to_date
described_class.new(project, user, { due_date: due_date }).execute(milestone)
epic.reload
expect(epic.start_date).to eq(nil)
expect(epic.start_date_sourcing_milestone).to eq(nil)
expect(epic.due_date).to eq(due_date)
expect(epic.due_date_sourcing_milestone).to eq(milestone)
expect(epic.reload).to have_attributes(
start_date: nil,
start_date_sourcing_milestone: nil,
due_date: due_date,
due_date_sourcing_milestone: milestone
)
end
end
end
......
......@@ -18,6 +18,11 @@ FactoryBot.define do
state "closed"
end
trait :with_dates do
start_date { Date.new(2000, 1, 1) }
due_date { Date.new(2000, 1, 30) }
end
after(:build, :stub) do |milestone, evaluator|
if evaluator.group
milestone.group = evaluator.group
......
......@@ -8,14 +8,34 @@ describe Milestones::UpdateService do
describe '#execute' do
context "valid params" do
let(:inner_service) { double(:service) }
before do
project.add_maintainer(user)
end
subject { described_class.new(project, user, { title: 'new_title' }).execute(milestone) }
it { expect(subject).to be_valid }
it { expect(subject.title).to eq('new_title') }
@milestone = described_class.new(project, user, { title: 'new_title' }).execute(milestone)
context 'state_event is activate' do
it 'calls ReopenService' do
expect(Milestones::ReopenService).to receive(:new).with(project, user, {}).and_return(inner_service)
expect(inner_service).to receive(:execute).with(milestone)
described_class.new(project, user, { state_event: 'activate' }).execute(milestone)
end
end
it { expect(@milestone).to be_valid }
it { expect(@milestone.title).to eq('new_title') }
context 'state_event is close' do
it 'calls ReopenService' do
expect(Milestones::CloseService).to receive(:new).with(project, user, {}).and_return(inner_service)
expect(inner_service).to receive(:execute).with(milestone)
described_class.new(project, user, { state_event: 'close' }).execute(milestone)
end
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment