Skip to content

Commit

Permalink
Add EU country mappings and accessors
Browse files Browse the repository at this point in the history
  • Loading branch information
garethrees committed Feb 16, 2016
1 parent 618f231 commit a267777
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
42 changes: 42 additions & 0 deletions lib/world_foi_websites.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,34 @@
# -*- encoding : utf-8 -*-
class WorldFOIWebsites
EU_COUNTRIES = { 'BE' => 'Belgium',
'BG' => 'Bulgaria',
'CZ' => 'Czech Republic',
'DK' => 'Denmark',
'DE' => 'Germany',
'EE' => 'Estonia',
'IE' => 'Ireland',
'GR' => 'Greece',
'ES' => 'Spain',
'FR' => 'France',
'HR' => 'Croatia',
'IT' => 'Italy',
'CY' => 'Cyprus',
'LV' => 'Latvia',
'LT' => 'Lithuania',
'LU' => 'Luxembourg',
'HU' => 'Hungary',
'MT' => 'Malta',
'NL' => 'Netherlands',
'AT' => 'Austria',
'PL' => 'Poland',
'PT' => 'Portugal',
'RO' => 'Romania',
'SI' => 'Slovenia',
'SK' => 'Slovakia',
'FI' => 'Finland',
'SE' => 'Sweden',
'GB' => 'United Kingdom' }.freeze

def self.world_foi_websites
world_foi_websites = [
{ :name => "WhatDoTheyKnow",
Expand Down Expand Up @@ -94,4 +123,17 @@ def self.by_code(code)
result = self.world_foi_websites.find{|x| x[:country_iso_code].downcase == code.downcase}
return result
end

def self.can_ask_the_eu?(code)
country_in_eu?(code) && !is_ask_the_eu?
end

def self.country_in_eu?(code)
EU_COUNTRIES.key?(code.to_s.upcase)
end

def self.is_ask_the_eu?
AlaveteliConfiguration.domain == 'www.asktheeu.org'
end

end
24 changes: 24 additions & 0 deletions spec/lib/world_foi_websites_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# -*- encoding : utf-8 -*-
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')

describe WorldFOIWebsites do

describe '.can_ask_the_eu?' do

it 'is false if the current site is AskTheEU' do
allow(AlaveteliConfiguration).
to receive(:domain).and_return('www.asktheeu.org')
expect(described_class.can_ask_the_eu?('ES')).to eq(false)
end

it 'is false if the current user is not in an EU country' do
expect(described_class.can_ask_the_eu?('US')).to eq(false)
end

it 'is true if the current user is in an EU country' do
expect(described_class.can_ask_the_eu?('ES')).to eq(true)
end

end

end

0 comments on commit a267777

Please sign in to comment.