From 166de600e73d14df39d9855edb8accdb8612dcaf Mon Sep 17 00:00:00 2001 From: Chris Mytton Date: Tue, 21 Feb 2017 16:32:05 +0100 Subject: [PATCH 1/4] Remove hard-coded SHAs in tests Having the SHA in the path makes it harder to script updates to the fixtures and means that the knowledge of the current SHA is duplicated between `countries.json` and the path. We do want to track the SHA of the fixtures, but this information is already in git in the `countries.json` fixture and in the VCR cassettes, so we don't need to also be tracking it in the directory names in the fixtures and in the tests themselves. --- .../data/Afghanistan/Wolesi_Jirga/ep-popolo-v1.0.json | 0 .../{beb21e5 => }/data/Alderney/States/ep-popolo-v1.0.json | 0 .../data/Australia/Representatives/ep-popolo-v1.0.json | 0 .../{f8dcbd9 => }/data/Australia/Senate/ep-popolo-v1.0.json | 0 .../data/Austria/Nationalrat/ep-popolo-v1.0.json | 0 .../data/Bahamas/House_of_Assembly/ep-popolo-v1.0.json | 0 .../{6e39048 => }/data/Croatia/Sabor/ep-popolo-v1.0.json | 0 .../data/Estonia/Riigikogu/ep-popolo-v1.0.json | 0 .../data/Finland/Eduskunta/ep-popolo-v1.0.json | 0 .../data/Malaysia/Dewan_Rakyat/ep-popolo-v1.0.json | 0 .../data/New_Zealand/House/ep-popolo-v1.0.json | 0 .../data/North_Korea/National_Assembly/ep-popolo-v1.0.json | 0 .../data/Northern_Ireland/Assembly/ep-popolo-v1.0.json | 0 .../data/Transnistria/Supreme_Council/ep-popolo-v1.0.json | 0 .../data/Uganda/Parliament/ep-popolo-v1.0.json | 0 t/test_helper.rb | 6 +++--- t/web/term_table/australia.rb | 4 ++-- t/web/term_table/finland.rb | 2 +- t/web/term_table/malaysia.rb | 2 +- t/web/term_table/ni.rb | 2 +- t/web/term_table/nz.rb | 2 +- t/web/term_table/party_groupings.rb | 6 +++--- t/web/term_table/seat_count.rb | 4 ++-- 23 files changed, 14 insertions(+), 14 deletions(-) rename t/fixtures/everypolitician-data/{2b38667 => }/data/Afghanistan/Wolesi_Jirga/ep-popolo-v1.0.json (100%) rename t/fixtures/everypolitician-data/{beb21e5 => }/data/Alderney/States/ep-popolo-v1.0.json (100%) rename t/fixtures/everypolitician-data/{6139efe => }/data/Australia/Representatives/ep-popolo-v1.0.json (100%) rename t/fixtures/everypolitician-data/{f8dcbd9 => }/data/Australia/Senate/ep-popolo-v1.0.json (100%) rename t/fixtures/everypolitician-data/{3df153b => }/data/Austria/Nationalrat/ep-popolo-v1.0.json (100%) rename t/fixtures/everypolitician-data/{4da60b8 => }/data/Bahamas/House_of_Assembly/ep-popolo-v1.0.json (100%) rename t/fixtures/everypolitician-data/{6e39048 => }/data/Croatia/Sabor/ep-popolo-v1.0.json (100%) rename t/fixtures/everypolitician-data/{f88ce37 => }/data/Estonia/Riigikogu/ep-popolo-v1.0.json (100%) rename t/fixtures/everypolitician-data/{ba4fa22 => }/data/Finland/Eduskunta/ep-popolo-v1.0.json (100%) rename t/fixtures/everypolitician-data/{75b7651 => }/data/Malaysia/Dewan_Rakyat/ep-popolo-v1.0.json (100%) rename t/fixtures/everypolitician-data/{87859a2 => }/data/New_Zealand/House/ep-popolo-v1.0.json (100%) rename t/fixtures/everypolitician-data/{bd08b5e => }/data/North_Korea/National_Assembly/ep-popolo-v1.0.json (100%) rename t/fixtures/everypolitician-data/{1a17862 => }/data/Northern_Ireland/Assembly/ep-popolo-v1.0.json (100%) rename t/fixtures/everypolitician-data/{75b7651 => }/data/Transnistria/Supreme_Council/ep-popolo-v1.0.json (100%) rename t/fixtures/everypolitician-data/{0cef4ab => }/data/Uganda/Parliament/ep-popolo-v1.0.json (100%) diff --git a/t/fixtures/everypolitician-data/2b38667/data/Afghanistan/Wolesi_Jirga/ep-popolo-v1.0.json b/t/fixtures/everypolitician-data/data/Afghanistan/Wolesi_Jirga/ep-popolo-v1.0.json similarity index 100% rename from t/fixtures/everypolitician-data/2b38667/data/Afghanistan/Wolesi_Jirga/ep-popolo-v1.0.json rename to t/fixtures/everypolitician-data/data/Afghanistan/Wolesi_Jirga/ep-popolo-v1.0.json diff --git a/t/fixtures/everypolitician-data/beb21e5/data/Alderney/States/ep-popolo-v1.0.json b/t/fixtures/everypolitician-data/data/Alderney/States/ep-popolo-v1.0.json similarity index 100% rename from t/fixtures/everypolitician-data/beb21e5/data/Alderney/States/ep-popolo-v1.0.json rename to t/fixtures/everypolitician-data/data/Alderney/States/ep-popolo-v1.0.json diff --git a/t/fixtures/everypolitician-data/6139efe/data/Australia/Representatives/ep-popolo-v1.0.json b/t/fixtures/everypolitician-data/data/Australia/Representatives/ep-popolo-v1.0.json similarity index 100% rename from t/fixtures/everypolitician-data/6139efe/data/Australia/Representatives/ep-popolo-v1.0.json rename to t/fixtures/everypolitician-data/data/Australia/Representatives/ep-popolo-v1.0.json diff --git a/t/fixtures/everypolitician-data/f8dcbd9/data/Australia/Senate/ep-popolo-v1.0.json b/t/fixtures/everypolitician-data/data/Australia/Senate/ep-popolo-v1.0.json similarity index 100% rename from t/fixtures/everypolitician-data/f8dcbd9/data/Australia/Senate/ep-popolo-v1.0.json rename to t/fixtures/everypolitician-data/data/Australia/Senate/ep-popolo-v1.0.json diff --git a/t/fixtures/everypolitician-data/3df153b/data/Austria/Nationalrat/ep-popolo-v1.0.json b/t/fixtures/everypolitician-data/data/Austria/Nationalrat/ep-popolo-v1.0.json similarity index 100% rename from t/fixtures/everypolitician-data/3df153b/data/Austria/Nationalrat/ep-popolo-v1.0.json rename to t/fixtures/everypolitician-data/data/Austria/Nationalrat/ep-popolo-v1.0.json diff --git a/t/fixtures/everypolitician-data/4da60b8/data/Bahamas/House_of_Assembly/ep-popolo-v1.0.json b/t/fixtures/everypolitician-data/data/Bahamas/House_of_Assembly/ep-popolo-v1.0.json similarity index 100% rename from t/fixtures/everypolitician-data/4da60b8/data/Bahamas/House_of_Assembly/ep-popolo-v1.0.json rename to t/fixtures/everypolitician-data/data/Bahamas/House_of_Assembly/ep-popolo-v1.0.json diff --git a/t/fixtures/everypolitician-data/6e39048/data/Croatia/Sabor/ep-popolo-v1.0.json b/t/fixtures/everypolitician-data/data/Croatia/Sabor/ep-popolo-v1.0.json similarity index 100% rename from t/fixtures/everypolitician-data/6e39048/data/Croatia/Sabor/ep-popolo-v1.0.json rename to t/fixtures/everypolitician-data/data/Croatia/Sabor/ep-popolo-v1.0.json diff --git a/t/fixtures/everypolitician-data/f88ce37/data/Estonia/Riigikogu/ep-popolo-v1.0.json b/t/fixtures/everypolitician-data/data/Estonia/Riigikogu/ep-popolo-v1.0.json similarity index 100% rename from t/fixtures/everypolitician-data/f88ce37/data/Estonia/Riigikogu/ep-popolo-v1.0.json rename to t/fixtures/everypolitician-data/data/Estonia/Riigikogu/ep-popolo-v1.0.json diff --git a/t/fixtures/everypolitician-data/ba4fa22/data/Finland/Eduskunta/ep-popolo-v1.0.json b/t/fixtures/everypolitician-data/data/Finland/Eduskunta/ep-popolo-v1.0.json similarity index 100% rename from t/fixtures/everypolitician-data/ba4fa22/data/Finland/Eduskunta/ep-popolo-v1.0.json rename to t/fixtures/everypolitician-data/data/Finland/Eduskunta/ep-popolo-v1.0.json diff --git a/t/fixtures/everypolitician-data/75b7651/data/Malaysia/Dewan_Rakyat/ep-popolo-v1.0.json b/t/fixtures/everypolitician-data/data/Malaysia/Dewan_Rakyat/ep-popolo-v1.0.json similarity index 100% rename from t/fixtures/everypolitician-data/75b7651/data/Malaysia/Dewan_Rakyat/ep-popolo-v1.0.json rename to t/fixtures/everypolitician-data/data/Malaysia/Dewan_Rakyat/ep-popolo-v1.0.json diff --git a/t/fixtures/everypolitician-data/87859a2/data/New_Zealand/House/ep-popolo-v1.0.json b/t/fixtures/everypolitician-data/data/New_Zealand/House/ep-popolo-v1.0.json similarity index 100% rename from t/fixtures/everypolitician-data/87859a2/data/New_Zealand/House/ep-popolo-v1.0.json rename to t/fixtures/everypolitician-data/data/New_Zealand/House/ep-popolo-v1.0.json diff --git a/t/fixtures/everypolitician-data/bd08b5e/data/North_Korea/National_Assembly/ep-popolo-v1.0.json b/t/fixtures/everypolitician-data/data/North_Korea/National_Assembly/ep-popolo-v1.0.json similarity index 100% rename from t/fixtures/everypolitician-data/bd08b5e/data/North_Korea/National_Assembly/ep-popolo-v1.0.json rename to t/fixtures/everypolitician-data/data/North_Korea/National_Assembly/ep-popolo-v1.0.json diff --git a/t/fixtures/everypolitician-data/1a17862/data/Northern_Ireland/Assembly/ep-popolo-v1.0.json b/t/fixtures/everypolitician-data/data/Northern_Ireland/Assembly/ep-popolo-v1.0.json similarity index 100% rename from t/fixtures/everypolitician-data/1a17862/data/Northern_Ireland/Assembly/ep-popolo-v1.0.json rename to t/fixtures/everypolitician-data/data/Northern_Ireland/Assembly/ep-popolo-v1.0.json diff --git a/t/fixtures/everypolitician-data/75b7651/data/Transnistria/Supreme_Council/ep-popolo-v1.0.json b/t/fixtures/everypolitician-data/data/Transnistria/Supreme_Council/ep-popolo-v1.0.json similarity index 100% rename from t/fixtures/everypolitician-data/75b7651/data/Transnistria/Supreme_Council/ep-popolo-v1.0.json rename to t/fixtures/everypolitician-data/data/Transnistria/Supreme_Council/ep-popolo-v1.0.json diff --git a/t/fixtures/everypolitician-data/0cef4ab/data/Uganda/Parliament/ep-popolo-v1.0.json b/t/fixtures/everypolitician-data/data/Uganda/Parliament/ep-popolo-v1.0.json similarity index 100% rename from t/fixtures/everypolitician-data/0cef4ab/data/Uganda/Parliament/ep-popolo-v1.0.json rename to t/fixtures/everypolitician-data/data/Uganda/Parliament/ep-popolo-v1.0.json diff --git a/t/test_helper.rb b/t/test_helper.rb index 04df9e657..84183a880 100644 --- a/t/test_helper.rb +++ b/t/test_helper.rb @@ -37,14 +37,14 @@ def index_at_known_sha end def stub_everypolitician_data_request(path) - stub_request(:get, "https://cdn.rawgit.com/everypolitician/everypolitician-data/#{path}") + stub_request(:get, %r{https://cdn.rawgit.com/everypolitician/everypolitician-data/\w+/#{path}}) .to_return(body: File.read("t/fixtures/everypolitician-data/#{path}")) rescue Errno::ENOENT => error raise "#{error.message}\n\nTo download this fixture run the following\n\n\tbundle exec rake 'everypolitician-data[#{path}]'\n" end - def stub_popolo(sha, legislature) - stub_everypolitician_data_request("#{sha}/data/#{legislature}/ep-popolo-v1.0.json") + def stub_popolo(_sha, legislature) + stub_everypolitician_data_request("data/#{legislature}/ep-popolo-v1.0.json") end def stub_github_api diff --git a/t/web/term_table/australia.rb b/t/web/term_table/australia.rb index 12902593e..ca5983085 100644 --- a/t/web/term_table/australia.rb +++ b/t/web/term_table/australia.rb @@ -21,7 +21,7 @@ describe 'Representatives' do before do - stub_everypolitician_data_request('6139efe/data/Australia/Representatives/ep-popolo-v1.0.json') + stub_everypolitician_data_request('data/Australia/Representatives/ep-popolo-v1.0.json') get '/australia/representatives/term-table/44.html' end @@ -51,7 +51,7 @@ describe 'Senate' do before do - stub_everypolitician_data_request('f8dcbd9/data/Australia/Senate/ep-popolo-v1.0.json') + stub_everypolitician_data_request('data/Australia/Senate/ep-popolo-v1.0.json') get '/australia/senate/term-table/44.html' end diff --git a/t/web/term_table/finland.rb b/t/web/term_table/finland.rb index 6677e0791..c900fb644 100644 --- a/t/web/term_table/finland.rb +++ b/t/web/term_table/finland.rb @@ -12,7 +12,7 @@ describe 'Finland' do before do - stub_everypolitician_data_request('ba4fa22/data/Finland/Eduskunta/ep-popolo-v1.0.json') + stub_everypolitician_data_request('data/Finland/Eduskunta/ep-popolo-v1.0.json') get '/finland/eduskunta/term-table/35.html' end diff --git a/t/web/term_table/malaysia.rb b/t/web/term_table/malaysia.rb index 63dd483f8..6e5f5dc29 100644 --- a/t/web/term_table/malaysia.rb +++ b/t/web/term_table/malaysia.rb @@ -4,7 +4,7 @@ describe 'Per Country Tests' do before do - stub_everypolitician_data_request('75b7651/data/Malaysia/Dewan_Rakyat/ep-popolo-v1.0.json') + stub_everypolitician_data_request('data/Malaysia/Dewan_Rakyat/ep-popolo-v1.0.json') end subject { Nokogiri::HTML(last_response.body) } diff --git a/t/web/term_table/ni.rb b/t/web/term_table/ni.rb index 25f1f92df..7662ef6df 100644 --- a/t/web/term_table/ni.rb +++ b/t/web/term_table/ni.rb @@ -12,7 +12,7 @@ describe 'membership dates' do before do - stub_everypolitician_data_request('1a17862/data/Northern_Ireland/Assembly/ep-popolo-v1.0.json') + stub_everypolitician_data_request('data/Northern_Ireland/Assembly/ep-popolo-v1.0.json') get '/northern-ireland/assembly/term-table/3.html' end diff --git a/t/web/term_table/nz.rb b/t/web/term_table/nz.rb index 6cdbac0fd..f35a79e5b 100644 --- a/t/web/term_table/nz.rb +++ b/t/web/term_table/nz.rb @@ -4,7 +4,7 @@ describe 'Per Country Tests' do before do - stub_everypolitician_data_request('87859a2/data/New_Zealand/House/ep-popolo-v1.0.json') + stub_everypolitician_data_request('data/New_Zealand/House/ep-popolo-v1.0.json') end subject { Nokogiri::HTML(last_response.body) } diff --git a/t/web/term_table/party_groupings.rb b/t/web/term_table/party_groupings.rb index 798ede563..dbebad96d 100644 --- a/t/web/term_table/party_groupings.rb +++ b/t/web/term_table/party_groupings.rb @@ -8,7 +8,7 @@ describe 'only Independent' do before do - stub_everypolitician_data_request('beb21e5/data/Alderney/States/ep-popolo-v1.0.json') + stub_everypolitician_data_request('data/Alderney/States/ep-popolo-v1.0.json') get '/alderney/states/term-table/2014.html' end @@ -19,7 +19,7 @@ describe 'only Unknown' do before do - stub_everypolitician_data_request('75b7651/data/Transnistria/Supreme_Council/ep-popolo-v1.0.json') + stub_everypolitician_data_request('data/Transnistria/Supreme_Council/ep-popolo-v1.0.json') get '/transnistria/supreme-council/term-table/6.html' end @@ -30,7 +30,7 @@ describe 'regular section' do before do - stub_everypolitician_data_request('f88ce37/data/Estonia/Riigikogu/ep-popolo-v1.0.json') + stub_everypolitician_data_request('data/Estonia/Riigikogu/ep-popolo-v1.0.json') get '/estonia/riigikogu/term-table/13.html' end it 'should have party groupings' do diff --git a/t/web/term_table/seat_count.rb b/t/web/term_table/seat_count.rb index 5ca483b5e..3e798b973 100644 --- a/t/web/term_table/seat_count.rb +++ b/t/web/term_table/seat_count.rb @@ -9,7 +9,7 @@ describe 'Estonia' do before do - stub_everypolitician_data_request('f88ce37/data/Estonia/Riigikogu/ep-popolo-v1.0.json') + stub_everypolitician_data_request('data/Estonia/Riigikogu/ep-popolo-v1.0.json') get '/estonia/riigikogu/term-table/13.html' end @@ -29,7 +29,7 @@ describe 'Historic Finland' do before do - stub_everypolitician_data_request('ba4fa22/data/Finland/Eduskunta/ep-popolo-v1.0.json') + stub_everypolitician_data_request('data/Finland/Eduskunta/ep-popolo-v1.0.json') get '/finland/eduskunta/term-table/35.html' end From f5074b2f6edf54f2b46ee5ba512b71a10a929f98 Mon Sep 17 00:00:00 2001 From: Chris Mytton Date: Tue, 21 Feb 2017 16:50:08 +0100 Subject: [PATCH 2/4] Remove SHA from stub_popolo method This removes the SHA argument from the stub_popolo method. We don't want to couple ourselves to the SHA in too many places, as it makes updating the test fixtures much harder than it needs to be. --- t/everypolitician_extensions/membership_extension.rb | 4 ++-- t/page/house_wikidata.rb | 6 +++--- t/page/term_table.rb | 4 ++-- t/test_helper.rb | 2 +- t/web/term_table/bahamas.rb | 2 +- t/web/wikidata.rb | 2 +- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/t/everypolitician_extensions/membership_extension.rb b/t/everypolitician_extensions/membership_extension.rb index 62dec218e..20ecf418c 100644 --- a/t/everypolitician_extensions/membership_extension.rb +++ b/t/everypolitician_extensions/membership_extension.rb @@ -4,7 +4,7 @@ describe 'MembershipExtensions' do subject do - stub_popolo('3df153b', 'Austria/Nationalrat') + stub_popolo('Austria/Nationalrat') index_at_known_sha.country('austria') .legislature('nationalrat') .popolo @@ -31,7 +31,7 @@ describe 'MembershipExtensions -- memberships with no known groups or area names' do subject do - stub_popolo('2b38667', 'Afghanistan/Wolesi_Jirga') + stub_popolo('Afghanistan/Wolesi_Jirga') index_at_known_sha.country('afghanistan') .legislature('wolesi-jirga') .popolo diff --git a/t/page/house_wikidata.rb b/t/page/house_wikidata.rb index 3234c146d..eb57ff4d7 100644 --- a/t/page/house_wikidata.rb +++ b/t/page/house_wikidata.rb @@ -10,17 +10,17 @@ def page_for(country, house) describe 'HouseWikidata' do let(:austria_page) do - stub_popolo('3df153b', 'Austria/Nationalrat') + stub_popolo('Austria/Nationalrat') page_for('austria', 'nationalrat') end let(:alderney_page) do - stub_popolo('beb21e5', 'Alderney/States') + stub_popolo('Alderney/States') page_for('alderney', 'states') end let(:uganda_page) do - stub_popolo('0cef4ab', 'Uganda/Parliament') + stub_popolo('Uganda/Parliament') page_for('uganda', 'parliament') end diff --git a/t/page/term_table.rb b/t/page/term_table.rb index ecafcf52b..aa19d5849 100644 --- a/t/page/term_table.rb +++ b/t/page/term_table.rb @@ -5,7 +5,7 @@ describe 'TermTable' do describe 'Austria' do subject do - stub_popolo('3df153b', 'Austria/Nationalrat') + stub_popolo('Austria/Nationalrat') Page::TermTable.new( term: index_at_known_sha.country('austria').legislature('nationalrat').term('25') ) @@ -59,7 +59,7 @@ end it 'returns an empty array when there is only a single group' do - stub_popolo('bd08b5e', 'North_Korea/National_Assembly') + stub_popolo('North_Korea/National_Assembly') north_korea = Page::TermTable.new( term: index_at_known_sha.country('north-korea').legislature('national-assembly').term('13') ) diff --git a/t/test_helper.rb b/t/test_helper.rb index 84183a880..e4ac02900 100644 --- a/t/test_helper.rb +++ b/t/test_helper.rb @@ -43,7 +43,7 @@ def stub_everypolitician_data_request(path) raise "#{error.message}\n\nTo download this fixture run the following\n\n\tbundle exec rake 'everypolitician-data[#{path}]'\n" end - def stub_popolo(_sha, legislature) + def stub_popolo(legislature) stub_everypolitician_data_request("data/#{legislature}/ep-popolo-v1.0.json") end diff --git a/t/web/term_table/bahamas.rb b/t/web/term_table/bahamas.rb index 0085ac672..86b24c8db 100644 --- a/t/web/term_table/bahamas.rb +++ b/t/web/term_table/bahamas.rb @@ -6,7 +6,7 @@ subject { Nokogiri::HTML(last_response.body) } before do - stub_popolo('4da60b8', 'Bahamas/House_of_Assembly') + stub_popolo('Bahamas/House_of_Assembly') get '/bahamas/house-of-assembly/term-table/2012.html' end diff --git a/t/web/wikidata.rb b/t/web/wikidata.rb index 35959f608..f1530b40d 100644 --- a/t/web/wikidata.rb +++ b/t/web/wikidata.rb @@ -9,7 +9,7 @@ describe 'Croatia' do before do - stub_popolo('6e39048', 'Croatia/Sabor') + stub_popolo('Croatia/Sabor') get '/croatia/sabor/wikidata' end From 2a0d9c6a9053c5210d2b0ae384ac3690d91645e4 Mon Sep 17 00:00:00 2001 From: Chris Mytton Date: Tue, 21 Feb 2017 16:53:49 +0100 Subject: [PATCH 3/4] Switch to using stub_popolo where appropriate This makes the tests use stub_popolo consistently, whereas before we were using stub_popolo in some places and stub_everypolitician_data_request in others. --- t/web/term_table/australia.rb | 4 ++-- t/web/term_table/finland.rb | 2 +- t/web/term_table/malaysia.rb | 2 +- t/web/term_table/ni.rb | 2 +- t/web/term_table/nz.rb | 2 +- t/web/term_table/party_groupings.rb | 6 +++--- t/web/term_table/seat_count.rb | 4 ++-- 7 files changed, 11 insertions(+), 11 deletions(-) diff --git a/t/web/term_table/australia.rb b/t/web/term_table/australia.rb index ca5983085..f98478c8e 100644 --- a/t/web/term_table/australia.rb +++ b/t/web/term_table/australia.rb @@ -21,7 +21,7 @@ describe 'Representatives' do before do - stub_everypolitician_data_request('data/Australia/Representatives/ep-popolo-v1.0.json') + stub_popolo('Australia/Representatives') get '/australia/representatives/term-table/44.html' end @@ -51,7 +51,7 @@ describe 'Senate' do before do - stub_everypolitician_data_request('data/Australia/Senate/ep-popolo-v1.0.json') + stub_popolo('Australia/Senate') get '/australia/senate/term-table/44.html' end diff --git a/t/web/term_table/finland.rb b/t/web/term_table/finland.rb index c900fb644..ad7faad0e 100644 --- a/t/web/term_table/finland.rb +++ b/t/web/term_table/finland.rb @@ -12,7 +12,7 @@ describe 'Finland' do before do - stub_everypolitician_data_request('data/Finland/Eduskunta/ep-popolo-v1.0.json') + stub_popolo('Finland/Eduskunta') get '/finland/eduskunta/term-table/35.html' end diff --git a/t/web/term_table/malaysia.rb b/t/web/term_table/malaysia.rb index 6e5f5dc29..8fad7d508 100644 --- a/t/web/term_table/malaysia.rb +++ b/t/web/term_table/malaysia.rb @@ -4,7 +4,7 @@ describe 'Per Country Tests' do before do - stub_everypolitician_data_request('data/Malaysia/Dewan_Rakyat/ep-popolo-v1.0.json') + stub_popolo('Malaysia/Dewan_Rakyat') end subject { Nokogiri::HTML(last_response.body) } diff --git a/t/web/term_table/ni.rb b/t/web/term_table/ni.rb index 7662ef6df..309cd7e12 100644 --- a/t/web/term_table/ni.rb +++ b/t/web/term_table/ni.rb @@ -12,7 +12,7 @@ describe 'membership dates' do before do - stub_everypolitician_data_request('data/Northern_Ireland/Assembly/ep-popolo-v1.0.json') + stub_popolo('Northern_Ireland/Assembly') get '/northern-ireland/assembly/term-table/3.html' end diff --git a/t/web/term_table/nz.rb b/t/web/term_table/nz.rb index f35a79e5b..e60d08393 100644 --- a/t/web/term_table/nz.rb +++ b/t/web/term_table/nz.rb @@ -4,7 +4,7 @@ describe 'Per Country Tests' do before do - stub_everypolitician_data_request('data/New_Zealand/House/ep-popolo-v1.0.json') + stub_popolo('New_Zealand/House') end subject { Nokogiri::HTML(last_response.body) } diff --git a/t/web/term_table/party_groupings.rb b/t/web/term_table/party_groupings.rb index dbebad96d..aeaad54fe 100644 --- a/t/web/term_table/party_groupings.rb +++ b/t/web/term_table/party_groupings.rb @@ -8,7 +8,7 @@ describe 'only Independent' do before do - stub_everypolitician_data_request('data/Alderney/States/ep-popolo-v1.0.json') + stub_popolo('Alderney/States') get '/alderney/states/term-table/2014.html' end @@ -19,7 +19,7 @@ describe 'only Unknown' do before do - stub_everypolitician_data_request('data/Transnistria/Supreme_Council/ep-popolo-v1.0.json') + stub_popolo('Transnistria/Supreme_Council') get '/transnistria/supreme-council/term-table/6.html' end @@ -30,7 +30,7 @@ describe 'regular section' do before do - stub_everypolitician_data_request('data/Estonia/Riigikogu/ep-popolo-v1.0.json') + stub_popolo('Estonia/Riigikogu') get '/estonia/riigikogu/term-table/13.html' end it 'should have party groupings' do diff --git a/t/web/term_table/seat_count.rb b/t/web/term_table/seat_count.rb index 3e798b973..8fe53b3c2 100644 --- a/t/web/term_table/seat_count.rb +++ b/t/web/term_table/seat_count.rb @@ -9,7 +9,7 @@ describe 'Estonia' do before do - stub_everypolitician_data_request('data/Estonia/Riigikogu/ep-popolo-v1.0.json') + stub_popolo('Estonia/Riigikogu') get '/estonia/riigikogu/term-table/13.html' end @@ -29,7 +29,7 @@ describe 'Historic Finland' do before do - stub_everypolitician_data_request('data/Finland/Eduskunta/ep-popolo-v1.0.json') + stub_popolo('Finland/Eduskunta') get '/finland/eduskunta/term-table/35.html' end From a7684cd51d62b6cd8e3574ca558fe26f2ff278f2 Mon Sep 17 00:00:00 2001 From: Chris Mytton Date: Wed, 22 Feb 2017 08:39:41 +0100 Subject: [PATCH 4/4] Fix rake task to download missing test fixtures We no longer include the SHA in the tests, so this rake task needs to lookup the current SHA for the requested legislature using the local `countries.json` file. Then it can use this information to grab the correct version of the requested file. --- Rakefile | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Rakefile b/Rakefile index bde00a0f6..8b7bc5164 100644 --- a/Rakefile +++ b/Rakefile @@ -45,9 +45,14 @@ Reek::Rake::Task.new do |t| end task 'everypolitician-data', [:path] do |_, args| + require 'everypolitician' + index = Everypolitician::Index.new(index_url: 't/fixtures/d8a4682f-countries.json') + legislature = index.countries.flat_map(&:legislatures).find do |l| + args[:path].start_with?("data/#{l.directory}") + end fixture_path = Pathname.new(File.join('t/fixtures/everypolitician-data', args[:path])) mkdir_p(fixture_path.dirname) - fixture_path.write(open("https://cdn.rawgit.com/everypolitician/everypolitician-data/#{args[:path]}").read) + fixture_path.write(open("https://cdn.rawgit.com/everypolitician/everypolitician-data/#{legislature.sha}/#{args[:path]}").read) end # Check for known vulnerabilities in Gemfile.lock