summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean McGivern <sean@mcgivern.me.uk>2017-03-16 16:23:55 +0000
committerSean McGivern <sean@mcgivern.me.uk>2017-03-16 16:23:55 +0000
commit9f6299c47f22893fb135cab38652749cd473b62b (patch)
tree37a47a3df6e987f353b676159a0943bef0267cba
parent8f92de7b636d46ae9969df2aa791bfb3833ebd4a (diff)
parent398a70f3e53b2adc90460dcc1c55bae276e12ffe (diff)
downloadgitlab-ce-9f6299c47f22893fb135cab38652749cd473b62b.tar.gz
Merge branch '29534-todos-performance' into 'master'
Improve TODOs performance See merge request !10004
-rw-r--r--app/helpers/todos_helper.rb3
-rw-r--r--spec/helpers/todos_helper_spec.rb23
2 files changed, 24 insertions, 2 deletions
diff --git a/app/helpers/todos_helper.rb b/app/helpers/todos_helper.rb
index 7f8efb0a4ac..4f5adf623f2 100644
--- a/app/helpers/todos_helper.rb
+++ b/app/helpers/todos_helper.rb
@@ -99,8 +99,7 @@ module TodosHelper
end
def todo_projects_options
- projects = current_user.authorized_projects.sorted_by_activity.non_archived
- projects = projects.includes(:namespace)
+ projects = current_user.authorized_projects.sorted_by_activity.non_archived.with_route
projects = projects.map do |project|
{ id: project.id, text: project.name_with_namespace }
diff --git a/spec/helpers/todos_helper_spec.rb b/spec/helpers/todos_helper_spec.rb
new file mode 100644
index 00000000000..50060a0925d
--- /dev/null
+++ b/spec/helpers/todos_helper_spec.rb
@@ -0,0 +1,23 @@
+require "spec_helper"
+
+describe TodosHelper do
+ describe '#todo_projects_options' do
+ let(:projects) { create_list(:empty_project, 3) }
+ let(:user) { create(:user) }
+
+ it 'returns users authorised projects in json format' do
+ projects.first.add_developer(user)
+ projects.second.add_developer(user)
+
+ allow(helper).to receive(:current_user).and_return(user)
+
+ expected_results = [
+ { 'id' => '', 'text' => 'Any Project' },
+ { 'id' => projects.second.id, 'text' => projects.second.name_with_namespace },
+ { 'id' => projects.first.id, 'text' => projects.first.name_with_namespace }
+ ]
+
+ expect(JSON.parse(helper.todo_projects_options)).to match_array(expected_results)
+ end
+ end
+end