Refactor specs for WikiPage services

parent dab26621
...@@ -3,6 +3,7 @@ require 'spec_helper' ...@@ -3,6 +3,7 @@ require 'spec_helper'
describe WikiPages::CreateService, services: true do describe WikiPages::CreateService, services: true do
let(:project) { create(:empty_project) } let(:project) { create(:empty_project) }
let(:user) { create(:user) } let(:user) { create(:user) }
let(:opts) do let(:opts) do
{ {
title: 'Title', title: 'Title',
...@@ -10,27 +11,28 @@ describe WikiPages::CreateService, services: true do ...@@ -10,27 +11,28 @@ describe WikiPages::CreateService, services: true do
format: 'markdown' format: 'markdown'
} }
end end
let(:service) { described_class.new(project, user, opts) }
describe '#execute' do subject(:service) { described_class.new(project, user, opts) }
context "valid params" do
before do before do
allow(service).to receive(:execute_hooks) project.add_developer(user)
project.add_master(user)
end end
subject { service.execute } describe '#execute' do
it 'creates wiki page with valid attributes' do
page = service.execute
it 'creates a valid wiki page' do expect(page).to be_valid
is_expected.to be_valid expect(page.title).to eq(opts[:title])
expect(subject.title).to eq(opts[:title]) expect(page.content).to eq(opts[:content])
expect(subject.content).to eq(opts[:content]) expect(page.format).to eq(opts[:format].to_sym)
expect(subject.format).to eq(opts[:format].to_sym)
end end
it 'executes webhooks' do it 'executes webhooks' do
expect(service).to have_received(:execute_hooks).once.with(subject, 'create') expect(service).to receive(:execute_hooks).once
end .with(instance_of(WikiPage), 'create')
service.execute
end end
end end
end end
...@@ -3,19 +3,20 @@ require 'spec_helper' ...@@ -3,19 +3,20 @@ require 'spec_helper'
describe WikiPages::DestroyService, services: true do describe WikiPages::DestroyService, services: true do
let(:project) { create(:empty_project) } let(:project) { create(:empty_project) }
let(:user) { create(:user) } let(:user) { create(:user) }
let(:wiki_page) { create(:wiki_page) } let(:page) { create(:wiki_page) }
let(:service) { described_class.new(project, user) }
subject(:service) { described_class.new(project, user) }
describe '#execute' do
before do before do
allow(service).to receive(:execute_hooks) project.add_developer(user)
project.add_master(user)
end end
describe '#execute' do
it 'executes webhooks' do it 'executes webhooks' do
service.execute(wiki_page) expect(service).to receive(:execute_hooks).once
.with(instance_of(WikiPage), 'delete')
expect(service).to have_received(:execute_hooks).once.with(wiki_page, 'delete') service.execute(page)
end end
end end
end end
...@@ -3,7 +3,8 @@ require 'spec_helper' ...@@ -3,7 +3,8 @@ require 'spec_helper'
describe WikiPages::UpdateService, services: true do describe WikiPages::UpdateService, services: true do
let(:project) { create(:empty_project) } let(:project) { create(:empty_project) }
let(:user) { create(:user) } let(:user) { create(:user) }
let(:wiki_page) { create(:wiki_page) } let(:page) { create(:wiki_page) }
let(:opts) do let(:opts) do
{ {
content: 'New content for wiki page', content: 'New content for wiki page',
...@@ -11,27 +12,28 @@ describe WikiPages::UpdateService, services: true do ...@@ -11,27 +12,28 @@ describe WikiPages::UpdateService, services: true do
message: 'New wiki message' message: 'New wiki message'
} }
end end
let(:service) { described_class.new(project, user, opts) }
describe '#execute' do subject(:service) { described_class.new(project, user, opts) }
context "valid params" do
before do before do
allow(service).to receive(:execute_hooks) project.add_developer(user)
project.add_master(user)
end end
subject { service.execute(wiki_page) } describe '#execute' do
it 'updates the wiki page' do it 'updates the wiki page' do
is_expected.to be_valid updated_page = service.execute(page)
expect(subject.content).to eq(opts[:content])
expect(subject.format).to eq(opts[:format].to_sym) expect(updated_page).to be_valid
expect(subject.message).to eq(opts[:message]) expect(updated_page.message).to eq(opts[:message])
expect(updated_page.content).to eq(opts[:content])
expect(updated_page.format).to eq(opts[:format].to_sym)
end end
it 'executes webhooks' do it 'executes webhooks' do
expect(service).to have_received(:execute_hooks).once.with(subject, 'update') expect(service).to receive(:execute_hooks).once
end .with(instance_of(WikiPage), 'update')
service.execute(page)
end 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