From a7ce8d5c70db9adc6dcb40660c70bf51ff64ce39 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Fri, 15 Sep 2017 15:33:43 +0200 Subject: [PATCH 1/8] fixes flaky spec Reactivates feature setting after spec --- spec/features/admin/legislation/questions_spec.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/spec/features/admin/legislation/questions_spec.rb b/spec/features/admin/legislation/questions_spec.rb index 44698a25c..ffbca09b1 100644 --- a/spec/features/admin/legislation/questions_spec.rb +++ b/spec/features/admin/legislation/questions_spec.rb @@ -9,8 +9,15 @@ feature 'Admin legislation questions' do context "Feature flag" do - scenario 'Disabled with a feature flag' do + background do Setting['feature.legislation'] = nil + end + + after do + Setting['feature.legislation'] = true + end + + scenario 'Disabled with a feature flag' do process = create(:legislation_process) expect{ visit admin_legislation_process_questions_path(process) }.to raise_exception(FeatureFlags::FeatureDisabled) end From b101b1f77870820df9e95336fc46bb118cf3b954 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Fri, 15 Sep 2017 15:34:16 +0200 Subject: [PATCH 2/8] removes obsolete legislations specs Obsolete and flaky! --- spec/features/legacy_legislation_spec.rb | 99 ------------------------ 1 file changed, 99 deletions(-) delete mode 100644 spec/features/legacy_legislation_spec.rb diff --git a/spec/features/legacy_legislation_spec.rb b/spec/features/legacy_legislation_spec.rb deleted file mode 100644 index 8ccc7fcb0..000000000 --- a/spec/features/legacy_legislation_spec.rb +++ /dev/null @@ -1,99 +0,0 @@ -require 'rails_helper' - -feature 'Legacy Legislation' do - - scenario 'Show' do - legacy_legislation = create(:legacy_legislation, title: 'Change the world', body: 'To achieve this...') - - visit legacy_legislation_path(legacy_legislation) - - expect(page).to have_content 'Change the world' - expect(page).to have_content 'To achieve this...' - end - - context 'Annotations', :js do - - let(:user) { create(:user) } - background { login_as user } - - scenario 'Create' do - legacy_legislation = create(:legacy_legislation) - - visit legacy_legislation_path(legacy_legislation) - - page.find(:css, "#legacy_legislation_body").double_click - page.find(:css, ".annotator-adder button").click - fill_in 'annotator-field-0', with: 'this is my annotation' - page.find(:css, ".annotator-controls a[href='#save']").click - - expect(page).to have_css ".annotator-hl" - first(:css, ".annotator-hl").click - expect(page).to have_content "this is my annotation" - - visit legacy_legislation_path(legacy_legislation) - - expect(page).to have_css ".annotator-hl" - first(:css, ".annotator-hl").click - expect(page).to have_content "this is my annotation" - end - - scenario 'Update' do - legacy_legislation = create(:legacy_legislation) - annotation = create(:annotation, legacy_legislation: legacy_legislation, user: user, text: "my annotation") - - visit legacy_legislation_path(legacy_legislation) - - expect(page).to have_css ".annotator-hl" - page.find(:css, ".annotator-hl").click - page.find(:css, ".annotator-edit").click - - fill_in 'annotator-field-0', with: 'edited annotation' - page.find(:css, ".annotator-controls a[href='#save']").click - - expect(page).to_not have_css('span', text: 'my annotation') - - page.find(:css, ".annotator-hl").click - expect(page).to have_content "edited annotation" - - visit legacy_legislation_path(legacy_legislation) - - page.find(:css, ".annotator-hl").click - expect(page).to have_content "edited annotation" - end - - scenario 'Destroy' do - legacy_legislation = create(:legacy_legislation) - annotation = create(:annotation, legacy_legislation: legacy_legislation, user: user) - - visit legacy_legislation_path(legacy_legislation) - - expect(page).to have_css ".annotator-hl" - - page.find(:css, ".annotator-hl").click - page.find(:css, ".annotator-delete").click - - expect(page).to_not have_css ".annotator-hl" - end - - scenario 'Search' do - legacy_legislation = create(:legacy_legislation) - annotation1 = create(:annotation, legacy_legislation: legacy_legislation, text: "my annotation", - ranges: [{"start" => "/div[1]", "startOffset" => 5, "end" => "/div[1]", "endOffset" => 10}]) - annotation2 = create(:annotation, legacy_legislation: legacy_legislation, text: "my other annotation", - ranges: [{"start" => "/div[1]", "startOffset" => 12, "end" => "/div[1]", "endOffset" => 19}]) - - visit legacy_legislation_path(legacy_legislation) - - expect(page).to have_css ".annotator-hl" - first(:css, ".annotator-hl").click - expect(page).to have_content "my annotation" - - all(".annotator-hl")[1].click - expect(page).to have_content "my other annotation" - end - - end - -end - -## Notes logged in and not logged in users From 20ca60732b877e60133bee16e2aafba769caab27 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Fri, 15 Sep 2017 15:34:47 +0200 Subject: [PATCH 3/8] fixes flaky spec Using correct resource in path --- spec/features/votes_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/features/votes_spec.rb b/spec/features/votes_spec.rb index 73a255415..093599368 100644 --- a/spec/features/votes_spec.rb +++ b/spec/features/votes_spec.rb @@ -303,7 +303,7 @@ feature 'Votes' do debate = create(:debate) comment = create(:comment, commentable: debate) - visit comment_path(debate) + visit comment_path(comment) within("#comment_#{comment.id}") do find("div.votes").hover expect_message_you_need_to_sign_in_to_vote_comments From 8e0f709cf068752a2d261f4da6dadf88cdc7f771 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Fri, 15 Sep 2017 15:35:10 +0200 Subject: [PATCH 4/8] removes unused expectation --- spec/features/admin/budget_investments_spec.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/spec/features/admin/budget_investments_spec.rb b/spec/features/admin/budget_investments_spec.rb index 925f105b0..deaaf2175 100644 --- a/spec/features/admin/budget_investments_spec.rb +++ b/spec/features/admin/budget_investments_spec.rb @@ -395,8 +395,6 @@ feature 'Admin budget investments' do find('.js-add-tag-link', text: 'Education').click - fill_in 'budget_investment_title', with: 'Updated title' - click_button 'Update' expect(page).to have_content 'Investment project updated succesfully.' From eb89d92320861db9df5b2da05fd1e2920723a28d Mon Sep 17 00:00:00 2001 From: rgarcia Date: Fri, 15 Sep 2017 15:35:43 +0200 Subject: [PATCH 5/8] fixes flaky spec Visits directly the page to avoid flakiness --- spec/features/admin/budget_investments_spec.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/spec/features/admin/budget_investments_spec.rb b/spec/features/admin/budget_investments_spec.rb index deaaf2175..7252e2660 100644 --- a/spec/features/admin/budget_investments_spec.rb +++ b/spec/features/admin/budget_investments_spec.rb @@ -390,8 +390,7 @@ feature 'Admin budget investments' do budget_investment2 = create(:budget_investment) - visit admin_budget_budget_investment_path(budget_investment2.budget, budget_investment2) - click_link 'Edit classification' + visit edit_admin_budget_budget_investment_path(budget_investment2.budget, budget_investment2) find('.js-add-tag-link', text: 'Education').click From 0de87c19c68a43ee9bd9ff959760d61475760ddf Mon Sep 17 00:00:00 2001 From: rgarcia Date: Fri, 15 Sep 2017 15:55:35 +0200 Subject: [PATCH 6/8] fixes flaky spec Maybe using `build` instead of `create` was confusing the spec --- spec/models/geozone_spec.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/spec/models/geozone_spec.rb b/spec/models/geozone_spec.rb index 1a7bf6b09..0eeb331b7 100644 --- a/spec/models/geozone_spec.rb +++ b/spec/models/geozone_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -RSpec.describe Geozone, type: :model do +describe Geozone do let(:geozone) { build(:geozone) } it "should be valid" do @@ -13,6 +13,8 @@ RSpec.describe Geozone, type: :model do end describe "#safe_to_destroy?" do + let(:geozone) { create(:geozone) } + it "is true when not linked to other models" do expect(geozone.safe_to_destroy?).to be_truthy end From 3b76c7428b14f9e35c45804abcd9c1a9ba9ecbf3 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Fri, 15 Sep 2017 16:08:33 +0200 Subject: [PATCH 7/8] fixes flaky spec MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds random number to the proposal’s title, to avoid js popup displaying similar proposals --- spec/shared/features/nested_documentable.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/shared/features/nested_documentable.rb b/spec/shared/features/nested_documentable.rb index d03841d36..49f7b4120 100644 --- a/spec/shared/features/nested_documentable.rb +++ b/spec/shared/features/nested_documentable.rb @@ -250,7 +250,7 @@ def attach_new_file(documentable_factory_name, index, path) end def fill_new_valid_proposal - fill_in :proposal_title, with: "Proposal title" + fill_in :proposal_title, with: "Proposal title #{rand(9999)}" fill_in :proposal_summary, with: "Proposal summary" fill_in :proposal_question, with: "Proposal question?" check :proposal_terms_of_service From 33ba7821d5084d886940c7f6741ee26f6df0d822 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Tue, 19 Sep 2017 14:17:10 +0200 Subject: [PATCH 8/8] precompile assets in test environment Usually the first spec that visits a page fails with a timeout. Hopefully it was due to having to compile assets at runtime and this helps to fix it --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 7d5f6169a..8836964a6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,6 +8,7 @@ before_script: - "for i in config/*.example; do cp \"$i\" \"${i/.example}\"; done" - bundle exec rake db:setup script: + - "bundle exec rake assets:precompile RAILS_ENV=test" - "bundle exec rake knapsack:rspec" env: global: