From 3ab893ebffcb509407073e0c4c56c924bbdd407e Mon Sep 17 00:00:00 2001 From: sathish Date: Sat, 2 Nov 2019 10:19:37 -0700 Subject: [PATCH] Filter ENV VARIABLE GROUP by project --- .../environment_variable_groups_controller.rb | 6 ++++++ .../environment_variable_groups_controller_test.rb | 14 ++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/plugins/env/app/controllers/environment_variable_groups_controller.rb b/plugins/env/app/controllers/environment_variable_groups_controller.rb index f0c2d077aa..7eb3fc6100 100644 --- a/plugins/env/app/controllers/environment_variable_groups_controller.rb +++ b/plugins/env/app/controllers/environment_variable_groups_controller.rb @@ -5,6 +5,12 @@ class EnvironmentVariableGroupsController < ApplicationController def index @groups = EnvironmentVariableGroup.all.includes(:environment_variables) + + if project_id = params[:project_id].presence + @groups = @groups.joins(:project_environment_variable_groups). + where("project_environment_variable_groups.project_id = ?", project_id) + end + respond_to do |format| format.html format.json do diff --git a/plugins/env/test/controllers/environment_variable_groups_controller_test.rb b/plugins/env/test/controllers/environment_variable_groups_controller_test.rb index 7aa4194b05..8aa81d1c17 100644 --- a/plugins/env/test/controllers/environment_variable_groups_controller_test.rb +++ b/plugins/env/test/controllers/environment_variable_groups_controller_test.rb @@ -106,6 +106,20 @@ def self.it_destroys project = JSON.parse(response.body) project.keys.must_include "environment_variables" end + + it "filters by project" do + ProjectEnvironmentVariableGroup.create!(environment_variable_group: other_env_group, project: other_project) + get :index, params: {project_id: other_project.id, format: :json} + assert_response :success + json_response = JSON.parse response.body + first_group = json_response['environment_variable_groups'].first + + json_response['environment_variable_groups'].count.must_equal 1 + first_group.keys.must_include "name" + first_group.keys.must_include "variable_names" + first_group['name'].must_equal other_env_group.name + first_group['variable_names'].must_equal ["X", "Y"] + end end describe "#show" do