summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Speicher <rspeicher@gmail.com>2017-06-09 18:12:00 -0400
committerRobert Speicher <rspeicher@gmail.com>2017-06-09 18:23:19 -0400
commitf2dee8e8555409d3b1d333703581c6d62166cf83 (patch)
tree6096261b6d7aa2d15f1c51f8c3e671f19ff40782
parentb16730fc8317b282d5dc86dbc8936c74303f5a36 (diff)
downloadgitlab-ce-rs-simplify-todo-count-spec.tar.gz
Test todos_count_format helper at the correct level to improve speedrs-simplify-todo-count-spec
Instead of an integration test that creates 101 Todo records to test a simple view helper, just unit test the helper.
-rw-r--r--app/controllers/dashboard/todos_controller.rb5
-rw-r--r--app/helpers/todos_helper.rb2
-rw-r--r--spec/features/todos/todos_spec.rb23
-rw-r--r--spec/helpers/todos_helper_spec.rb13
4 files changed, 14 insertions, 29 deletions
diff --git a/app/controllers/dashboard/todos_controller.rb b/app/controllers/dashboard/todos_controller.rb
index 623392c1240..28c90548cc1 100644
--- a/app/controllers/dashboard/todos_controller.rb
+++ b/app/controllers/dashboard/todos_controller.rb
@@ -47,11 +47,6 @@ class Dashboard::TodosController < Dashboard::ApplicationController
render json: todos_counts
end
- # Used in TodosHelper also
- def self.todos_count_format(count)
- count >= 100 ? '99+' : count
- end
-
private
def find_todos
diff --git a/app/helpers/todos_helper.rb b/app/helpers/todos_helper.rb
index 19286fadb19..3d1b3a4711a 100644
--- a/app/helpers/todos_helper.rb
+++ b/app/helpers/todos_helper.rb
@@ -4,7 +4,7 @@ module TodosHelper
end
def todos_count_format(count)
- count > 99 ? '99+' : count
+ count > 99 ? '99+' : count.to_s
end
def todos_done_count
diff --git a/spec/features/todos/todos_spec.rb b/spec/features/todos/todos_spec.rb
index bb4b2aed0e3..feb2fe8a7d1 100644
--- a/spec/features/todos/todos_spec.rb
+++ b/spec/features/todos/todos_spec.rb
@@ -333,29 +333,6 @@ describe 'Dashboard Todos', feature: true do
end
end
- context 'User have large number of todos' do
- before do
- create_list(:todo, 101, :mentioned, user: user, project: project, target: issue, author: author)
-
- login_as(user)
- visit dashboard_todos_path
- end
-
- it 'shows 99+ for count >= 100 in notification' do
- expect(page).to have_selector('.todos-count', text: '99+')
- end
-
- it 'shows exact number in To do tab' do
- expect(page).to have_selector('.todos-pending .badge', text: '101')
- end
-
- it 'shows exact number for count < 100' do
- 3.times { first('.js-done-todo').click }
-
- expect(page).to have_selector('.todos-count', text: '98')
- end
- end
-
context 'User has a Build Failed todo' do
let!(:todo) { create(:todo, :build_failed, user: user, project: project, author: author) }
diff --git a/spec/helpers/todos_helper_spec.rb b/spec/helpers/todos_helper_spec.rb
index 50060a0925d..18a41ca24e3 100644
--- a/spec/helpers/todos_helper_spec.rb
+++ b/spec/helpers/todos_helper_spec.rb
@@ -1,6 +1,19 @@
require "spec_helper"
describe TodosHelper do
+ describe '#todos_count_format' do
+ it 'shows fuzzy count for 100 or more items' do
+ expect(helper.todos_count_format(100)).to eq '99+'
+ expect(helper.todos_count_format(1000)).to eq '99+'
+ end
+
+ it 'shows exact count for 99 or fewer items' do
+ expect(helper.todos_count_format(99)).to eq '99'
+ expect(helper.todos_count_format(50)).to eq '50'
+ expect(helper.todos_count_format(1)).to eq '1'
+ end
+ end
+
describe '#todo_projects_options' do
let(:projects) { create_list(:empty_project, 3) }
let(:user) { create(:user) }