diff options
author | Z.J. van de Weg <git@zjvandeweg.nl> | 2017-02-24 15:25:42 +0300 |
---|---|---|
committer | Z.J. van de Weg <git@zjvandeweg.nl> | 2017-02-24 15:25:42 +0300 |
commit | 9f0e23d6093d67d368485e2ac7e4df0059935770 (patch) | |
tree | 1306e799f14360a76336f7622df21f4503c5939d | |
parent | 4535129e45cc98ab5a1f17f0950a93bd062e3a5a (diff) |
Fix tests
-rw-r--r-- | app/assets/javascripts/behaviors/toggler_behavior.js | 2 | ||||
-rw-r--r-- | app/services/groups/base_service.rb | 6 | ||||
-rw-r--r-- | app/services/groups/create_service.rb | 6 | ||||
-rw-r--r-- | app/services/groups/update_service.rb | 17 | ||||
-rw-r--r-- | app/views/groups/_create_chat_team.html.haml | 2 | ||||
-rw-r--r-- | db/migrate/20170120131253_create_chat_teams.rb | 5 | ||||
-rw-r--r-- | spec/services/groups/create_service_spec.rb | 6 |
7 files changed, 29 insertions, 15 deletions
diff --git a/app/assets/javascripts/behaviors/toggler_behavior.js b/app/assets/javascripts/behaviors/toggler_behavior.js index 2d98fc5a545..0726c6c9636 100644 --- a/app/assets/javascripts/behaviors/toggler_behavior.js +++ b/app/assets/javascripts/behaviors/toggler_behavior.js @@ -21,7 +21,7 @@ // %a.js-toggle-button // %div.js-toggle-content // - $('body').on('click', '.js-toggle-button', function(e) { + $('body').on('click', '.js-toggle-button', function() { toggleContainer($(this).closest('.js-toggle-container')); }); diff --git a/app/services/groups/base_service.rb b/app/services/groups/base_service.rb index a8fa098246a..eb2abcd3723 100644 --- a/app/services/groups/base_service.rb +++ b/app/services/groups/base_service.rb @@ -5,5 +5,11 @@ module Groups def initialize(group, user, params = {}) @group, @current_user, @params = group, user, params.dup end + + private + + def create_chat_team? + @chat_team == "true" && Gitlab.config.mattermost.enabled + end end end diff --git a/app/services/groups/create_service.rb b/app/services/groups/create_service.rb index 3028025fc6e..4ed2cb7c8af 100644 --- a/app/services/groups/create_service.rb +++ b/app/services/groups/create_service.rb @@ -32,11 +32,5 @@ module Groups @group.add_owner(current_user) @group end - - private - - def create_chat_team? - @chat_team && Gitlab.config.mattermost.enabled - end end end diff --git a/app/services/groups/update_service.rb b/app/services/groups/update_service.rb index aff42ad598c..e8ad6d41ed4 100644 --- a/app/services/groups/update_service.rb +++ b/app/services/groups/update_service.rb @@ -1,10 +1,7 @@ module Groups class UpdateService < Groups::BaseService def execute - if params.delete(:create_chat_team) == '1' - chat_name = params[:chat_team_name] - options = chat_name ? { name: chat_name } : {} - end + @chat_team = params.delete(:create_chat_team) # check that user is allowed to set specified visibility_level new_visibility = params[:visibility_level] @@ -19,6 +16,12 @@ module Groups group.assign_attributes(params) + if create_chat_team? + Mattermost::CreateTeamService.new(group, current_user).execute + + return group if group.errors.any? + end + begin group.save rescue Gitlab::UpdatePathError => e @@ -27,5 +30,11 @@ module Groups false end end + + private + + def create_chat_team? + super && group.chat_team.nil? + end end end diff --git a/app/views/groups/_create_chat_team.html.haml b/app/views/groups/_create_chat_team.html.haml index 8b908e233dc..b9bf9fe39c2 100644 --- a/app/views/groups/_create_chat_team.html.haml +++ b/app/views/groups/_create_chat_team.html.haml @@ -13,4 +13,4 @@ Team URL: = Settings.mattermost.host %span> / - %span{ "data-bind-out" => "create_chat_team"} + %span{ "data-bind-out" => "create_chat_team" } diff --git a/db/migrate/20170120131253_create_chat_teams.rb b/db/migrate/20170120131253_create_chat_teams.rb index 6476c239152..2d9341d235f 100644 --- a/db/migrate/20170120131253_create_chat_teams.rb +++ b/db/migrate/20170120131253_create_chat_teams.rb @@ -1,7 +1,8 @@ class CreateChatTeams < ActiveRecord::Migration include Gitlab::Database::MigrationHelpers - DOWNTIME = false + DOWNTIME = true + DOWNTIME_REASON = "Adding a foreign key" def change create_table :chat_teams do |t| @@ -12,6 +13,6 @@ class CreateChatTeams < ActiveRecord::Migration t.timestamps null: false end - add_foreign_key :chat_teams, :namespaces, on_delete: :cascade + add_concurrent_foreign_key :chat_teams, :namespaces, on_delete: :cascade end end diff --git a/spec/services/groups/create_service_spec.rb b/spec/services/groups/create_service_spec.rb index d8181f73110..b11483fb407 100644 --- a/spec/services/groups/create_service_spec.rb +++ b/spec/services/groups/create_service_spec.rb @@ -40,9 +40,13 @@ describe Groups::CreateService, '#execute', services: true do end describe 'creating a mattermost team' do - let!(:params) { group_params.merge(create_chat_team: true) } + let!(:params) { group_params.merge(create_chat_team: "true") } let!(:service) { described_class.new(user, params) } + before do + Settings.mattermost['enabled'] = true + end + it 'triggers the service' do expect_any_instance_of(Mattermost::CreateTeamService).to receive(:execute) |