diff options
author | Robert Speicher <robert@gitlab.com> | 2016-04-22 20:51:08 +0300 |
---|---|---|
committer | Robert Speicher <robert@gitlab.com> | 2016-04-22 20:51:08 +0300 |
commit | d83d43c553281718749da1f18edc8e254264c059 (patch) | |
tree | a6bcdf8b20068be1b10a6b870fcd816279a6dde7 /spec/features | |
parent | 84d3649d57a4445ed2f414430d14896208a485e2 (diff) | |
parent | bdd844f312a7bd3d40ae1a0eb29a3c376b3dae27 (diff) |
Merge branch 'rs-todos-feature-spec' into 'master'
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.
See merge request !3889
Diffstat (limited to 'spec/features')
-rw-r--r-- | spec/features/todos/todos_spec.rb | 38 |
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 |