diff --git a/app/controllers/chat_integrations_controller.rb b/app/controllers/chat_integrations_controller.rb new file mode 100644 index 00000000..eaf1094e --- /dev/null +++ b/app/controllers/chat_integrations_controller.rb @@ -0,0 +1,24 @@ +class ChatIntegrationsController < AbstractSecurityController + def create + @chat_integration = chat_klass.new(chat_integration_params) + @chat_integration.project = @project + if @chat_integration.save + flash[:notice] = "Settings saved" + redirect_to edit_project_path(@project) + else + flash[:error] = "Settings could not be saved" + redirect_to edit_project_path(@project) + end + end + + def update + @chat_integration = @project.send(chat_klass.name.underscore) + if @chat_integration.update_attributes(chat_integration_params) + flash[:notice] = "Settings updated" + redirect_to edit_project_path(@project) + else + flash[:error] = "Settings could not be updated" + redirect_to edit_project_path(@project) + end + end +end diff --git a/app/controllers/hip_chat_integrations_controller.rb b/app/controllers/hip_chat_integrations_controller.rb index 159c72af..84553af2 100644 --- a/app/controllers/hip_chat_integrations_controller.rb +++ b/app/controllers/hip_chat_integrations_controller.rb @@ -1,30 +1,12 @@ -class HipChatIntegrationsController < AbstractSecurityController - def create - @hip_chat_integration = HipChatIntegration.new(hip_chat_integration_params) - @hip_chat_integration.project = @project - if @hip_chat_integration.save - flash[:notice] = "HipChat settings saved" - redirect_to edit_project_path(@project) - else - flash[:error] = "HipChat settings could not be saved" - redirect_to edit_project_path(@project) - end - end - - def update - @hip_chat_integration = @project.hip_chat_integration - if @hip_chat_integration.update_attributes(hip_chat_integration_params) - flash[:notice] = "HipChat settings updated" - redirect_to edit_project_path(@project) - else - flash[:error] = "HipChat settings could not be updated" - redirect_to edit_project_path(@project) - end - end +class HipChatIntegrationsController < ChatIntegrationsController private - def hip_chat_integration_params + def chat_klass + HipChatIntegration + end + + def chat_integration_params params[:hip_chat_integration].permit(:token, :room, :notify) end end diff --git a/app/controllers/slack_integrations_controller.rb b/app/controllers/slack_integrations_controller.rb index f6ee3a81..e68f5f1f 100644 --- a/app/controllers/slack_integrations_controller.rb +++ b/app/controllers/slack_integrations_controller.rb @@ -1,30 +1,12 @@ -class SlackIntegrationsController < AbstractSecurityController - def create - @slack_integration = SlackIntegration.new(slack_integration_params) - @slack_integration.project = @project - if @slack_integration.save - flash[:notice] = "Slack settings saved" - redirect_to edit_project_path(@project) - else - flash[:error] = "Slack settings could not be saved" - redirect_to edit_project_path(@project) - end - end - - def update - @slack_integration = @project.slack_integration - if @slack_integration.update_attributes(slack_integration_params) - flash[:notice] = "Slack settings updated" - redirect_to edit_project_path(@project) - else - flash[:error] = "Slack settings could not be updated" - redirect_to edit_project_path(@project) - end - end +class SlackIntegrationsController < ChatIntegrationsController private - def slack_integration_params + def chat_klass + SlackIntegration + end + + def chat_integration_params params[:slack_integration].permit(:team, :token, :channel) end end diff --git a/spec/features/update_project_spec.rb b/spec/features/update_project_spec.rb index 4839a215..8cfa80e0 100644 --- a/spec/features/update_project_spec.rb +++ b/spec/features/update_project_spec.rb @@ -29,7 +29,7 @@ fill_in 'Room', :with => 'Room1' check 'Notify' click_button 'Save HipChat Settings' - expect(page).to have_content "HipChat settings saved" + expect(page).to have_content "Settings saved" end it "creates slack settings" do @@ -39,6 +39,6 @@ fill_in 'Channel', :with => 'agileista' check 'Notify' click_button 'Save Slack Settings' - expect(page).to have_content "Slack settings saved" + expect(page).to have_content "Settings saved" end end