diff --git a/app/models/project_services/slack_service/wiki_page_message.rb b/app/models/project_services/slack_service/wiki_page_message.rb index 61134054859..f336d9e7691 100644 --- a/app/models/project_services/slack_service/wiki_page_message.rb +++ b/app/models/project_services/slack_service/wiki_page_message.rb @@ -19,7 +19,7 @@ class SlackService @wiki_page_url = obj_attr[:url] @description = obj_attr[:content] - @action = \ + @action = case obj_attr[:action] when "create" "created" diff --git a/db/migrate/20160227120047_add_event_to_services.rb b/db/migrate/20160227120047_add_event_to_services.rb index 879f4b96b12..f5040d770de 100644 --- a/db/migrate/20160227120047_add_event_to_services.rb +++ b/db/migrate/20160227120047_add_event_to_services.rb @@ -1,5 +1,5 @@ class AddEventToServices < ActiveRecord::Migration def change - add_column :services, :wiki_page_events, :boolean, :default => true + add_column :services, :wiki_page_events, :boolean, default: true end end diff --git a/spec/models/project_services/slack_service/wiki_page_message_spec.rb b/spec/models/project_services/slack_service/wiki_page_message_spec.rb index c272e0e0aac..a2dfe1bf234 100644 --- a/spec/models/project_services/slack_service/wiki_page_message_spec.rb +++ b/spec/models/project_services/slack_service/wiki_page_message_spec.rb @@ -11,11 +11,9 @@ describe SlackService::WikiPageMessage, models: true do }, project_name: 'project_name', project_url: 'somewhere.com', - object_attributes: { title: 'Wiki page title', url: 'url', - action: 'create', content: 'Wiki page description' } } @@ -23,34 +21,53 @@ describe SlackService::WikiPageMessage, models: true do let(:color) { '#345' } - context 'create' do - it 'returns a message regarding creation of pages' do - expect(subject.pretext).to eq( - 'Test User created in : '\ - '*Wiki page title*') - expect(subject.attachments).to eq([ - { - text: "Wiki page description", - color: color, - } - ]) + describe '#pretext' do + context 'when :action == "create"' do + before { args[:object_attributes][:action] = 'create' } + + it do + expect(pretext).to eq( + 'Test User created in : '\ + '*Wiki page title*') + end + end + + context 'when :action == "update"' do + before { args[:object_attributes][:action] = 'update' } + + it do + expect(pretext).to eq( + 'Test User edited in : '\ + '*Wiki page title*') + end end end - context 'update' do - before do - args[:object_attributes][:action] = 'update' + describe '#attachments' do + context 'when :action == "create"' do + before { args[:object_attributes][:action] = 'create' } + + it do + expect(attachments).to eq([ + { + text: "Wiki page description", + color: color, + } + ]) + end end - it 'returns a message regarding updating of pages' do - expect(subject.pretext). to eq( - 'Test User edited in : '\ - '*Wiki page title*') - expect(subject.attachments).to eq([ - { - text: "Wiki page description", - color: color, - } - ]) + + context 'when :action == "update"' do + before { args[:object_attributes][:action] = 'update' } + + it do + expect(attachments).to eq([ + { + text: "Wiki page description", + color: color, + } + ]) + end end end end