summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJarka Kadlecova <jarka@gitlab.com>2017-03-16 14:28:14 +0100
committerJarka Kadlecova <jarka@gitlab.com>2017-03-16 16:01:53 +0100
commit398a70f3e53b2adc90460dcc1c55bae276e12ffe (patch)
tree85cb196a6f3942ff3bbbbac3f4e59d643102351e
parent68e64a5b44b7a0f540214ee8a3ca36ffcdb4fc6c (diff)
downloadgitlab-ce-398a70f3e53b2adc90460dcc1c55bae276e12ffe.tar.gz
Include routes when loading user projects
-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