summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorRobert Speicher <rspeicher@gmail.com>2016-04-22 13:04:05 -0400
committerRobert Speicher <rspeicher@gmail.com>2016-04-22 13:08:11 -0400
commitbdd844f312a7bd3d40ae1a0eb29a3c376b3dae27 (patch)
treec11260a604f0ba0e97ce7ccbb8ec465e23dc9f0b /spec
parent7d199b7fcc454a450cdba0f3278ed589ac4d6bd1 (diff)
downloadgitlab-ce-bdd844f312a7bd3d40ae1a0eb29a3c376b3dae27.tar.gz
Refactor Todos feature spec to be faster and less brittle
We now only create two Todos instead of 21 when testing pagination, and we've updated the test to be less brittle when dealing with slower CI environments.
Diffstat (limited to 'spec')
-rw-r--r--spec/features/todos/todos_spec.rb38
1 files changed, 20 insertions, 18 deletions
diff --git a/spec/features/todos/todos_spec.rb b/spec/features/todos/todos_spec.rb
index 113d4c40cfc..248e004ba6e 100644
--- a/spec/features/todos/todos_spec.rb
+++ b/spec/features/todos/todos_spec.rb
@@ -1,12 +1,10 @@
require 'spec_helper'
describe 'Dashboard Todos', feature: true do
- let(:user){ create(:user) }
- let(:author){ create(:user) }
- let(:project){ create(:project) }
- let(:issue){ create(:issue) }
- let(:todos_per_page){ Todo.default_per_page }
- let(:todos_total){ todos_per_page + 1 }
+ let(:user) { create(:user) }
+ let(:author) { create(:user) }
+ let(:project) { create(:project) }
+ let(:issue) { create(:issue) }
describe 'GET /dashboard/todos' do
context 'User does not have todos' do
@@ -46,31 +44,35 @@ describe 'Dashboard Todos', feature: true do
end
context 'User has multiple pages of Todos' do
- let(:todo_total_pages){ (todos_total.to_f/todos_per_page).ceil }
-
before do
- todos_total.times do
- create(:todo, :mentioned, user: user, project: project, target: issue, author: author)
- end
+ allow(Todo).to receive(:default_per_page).and_return(1)
+
+ # Create just enough records to cause us to paginate
+ create_list(:todo, 2, :mentioned, user: user, project: project, target: issue, author: author)
login_as(user)
- visit dashboard_todos_path
end
it 'is paginated' do
+ visit dashboard_todos_path
+
expect(page).to have_selector('.gl-pagination')
end
it 'is has the right number of pages' do
- expect(page).to have_selector('.gl-pagination .page', count: todo_total_pages)
+ visit dashboard_todos_path
+
+ expect(page).to have_selector('.gl-pagination .page', count: 2)
end
- describe 'deleting last todo from last page', js: true do
+ describe 'completing last todo from last page', js: true do
it 'redirects to the previous page' do
- page.within('.gl-pagination') do
- click_link todo_total_pages.to_s
- end
- first('.done-todo').click
+ visit dashboard_todos_path(page: 2)
+ expect(page).to have_content(Todo.first.body)
+
+ click_link('Done')
+
+ expect(current_path).to eq dashboard_todos_path
expect(page).to have_content(Todo.last.body)
end
end