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 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/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/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 04df9e657..e4ac02900 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(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..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('6139efe/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('f8dcbd9/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/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/term_table/finland.rb b/t/web/term_table/finland.rb index 6677e0791..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('ba4fa22/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 63dd483f8..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('75b7651/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 25f1f92df..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('1a17862/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 6cdbac0fd..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('87859a2/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 798ede563..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('beb21e5/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('75b7651/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('f88ce37/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 5ca483b5e..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('f88ce37/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('ba4fa22/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/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