Skip to content

Commit

Permalink
Merge pull request #3595 from zendesk/sathish/filter_env_group_variables
Browse files Browse the repository at this point in the history
Filter env-variables group by project
  • Loading branch information
sathishavm authored Nov 2, 2019
2 parents 2712311 + 3ab893e commit 83f3b19
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 83f3b19

Please sign in to comment.