diff options
author | Bob Van Landuyt <bob@vanlanduyt.co> | 2017-09-14 12:53:55 +0300 |
---|---|---|
committer | Bob Van Landuyt <bob@vanlanduyt.co> | 2017-10-04 23:49:41 +0300 |
commit | 20a08965bc949ea233cdde4e777698222fcabff2 (patch) | |
tree | 681a0c40cf5148fa227081fc02fd27028d96b50e /spec/controllers/groups_controller_spec.rb | |
parent | ea4e17e2aec525f249430b0a22dc6a8450648837 (diff) |
[WIP] improve number of queries when rendering a hierarchy
Diffstat (limited to 'spec/controllers/groups_controller_spec.rb')
-rw-r--r-- | spec/controllers/groups_controller_spec.rb | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/spec/controllers/groups_controller_spec.rb b/spec/controllers/groups_controller_spec.rb index 18f9d707e18..18791a01035 100644 --- a/spec/controllers/groups_controller_spec.rb +++ b/spec/controllers/groups_controller_spec.rb @@ -300,22 +300,28 @@ describe GroupsController do let(:expected_queries_per_group) { 5 } let(:expected_queries_per_project) { 0 } + before do + # Create the group before anything so it doesn't get tracked by the + # query recorder + group + end + def get_list get :children, id: group.to_param, format: :json end it 'queries the expected amount for a group row' do - control_count = ActiveRecord::QueryRecorder.new { get_list }.count + control = ActiveRecord::QueryRecorder.new { get_list } _new_group = create(:group, :public, parent: group) - expect { get_list }.not_to exceed_query_limit(control_count + expected_queries_per_group) + expect { get_list }.not_to exceed_query_limit(control).with_threshold(expected_queries_per_group) end it 'queries the expected amount for a project row' do - control_count = ActiveRecord::QueryRecorder.new { get_list }.count + control = ActiveRecord::QueryRecorder.new { get_list } _new_project = create(:project, :public, namespace: group) - expect { get_list }.not_to exceed_query_limit(control_count + expected_queries_per_project) + expect { get_list }.not_to exceed_query_limit(control).with_threshold(expected_queries_per_project) end context 'when rendering hierarchies' do @@ -326,41 +332,42 @@ describe GroupsController do it 'queries the expected amount when nested rows are rendered for a group' do matched_group = create(:group, :public, parent: public_subgroup, name: 'filterme') - control_count = ActiveRecord::QueryRecorder.new { get_filtered_list }.count + control = ActiveRecord::QueryRecorder.new { get_filtered_list } nested_group = create(:group, :public, parent: public_subgroup) matched_group.update!(parent: nested_group) - expect { get_filtered_list }.not_to exceed_query_limit(control_count + expected_queries_per_group) + expect { get_filtered_list }.not_to exceed_query_limit(control).with_threshold(expected_queries_per_group) end it 'queries the expected amount when a new group match is added' do create(:group, :public, parent: public_subgroup, name: 'filterme') - control_count = ActiveRecord::QueryRecorder.new { get_filtered_list }.count + control = ActiveRecord::QueryRecorder.new { get_filtered_list } + create(:group, :public, parent: public_subgroup, name: 'filterme2') - expect { get_filtered_list }.not_to exceed_query_limit(control_count + expected_queries_per_group) + expect { get_filtered_list }.not_to exceed_query_limit(control).with_threshold(expected_queries_per_group) end it 'queries the expected amount when nested rows are rendered for a project' do matched_project = create(:project, :public, namespace: public_subgroup, name: 'filterme') - control_count = ActiveRecord::QueryRecorder.new { get_filtered_list }.count + control = ActiveRecord::QueryRecorder.new { get_filtered_list } nested_group = create(:group, :public, parent: public_subgroup) matched_project.update!(namespace: nested_group) - expect { get_filtered_list }.not_to exceed_query_limit(control_count + expected_queries_per_group) + expect { get_filtered_list }.not_to exceed_query_limit(control).with_threshold(expected_queries_per_group) end it 'queries the expected amount when a new project match is added' do create(:project, :public, namespace: public_subgroup, name: 'filterme') - control_count = ActiveRecord::QueryRecorder.new { get_filtered_list }.count + control = ActiveRecord::QueryRecorder.new { get_filtered_list } create(:project, :public, namespace: public_subgroup, name: 'filterme2') - expect { get_filtered_list }.not_to exceed_query_limit(control_count + expected_queries_per_project) + expect { get_filtered_list }.not_to exceed_query_limit(control).with_threshold(expected_queries_per_project) end end end |