|
3 | 3 | module SmartAnswer::Calculators
|
4 | 4 | class ArrestedAbroadCalculatorTest < ActiveSupport::TestCase
|
5 | 5 | context ArrestedAbroad do
|
6 |
| - setup do |
7 |
| - @calc = ArrestedAbroad.new |
8 |
| - end |
9 |
| - |
10 | 6 | context "generating a URL" do
|
11 | 7 | should "not error if the country doesn't exist" do
|
12 | 8 | assert_nothing_raised do
|
13 |
| - @calc.generate_url_for_download("doesntexist", "pdf", "hello world") |
| 9 | + calc = ArrestedAbroad.new("doesntexist") |
| 10 | + calc.generate_url_for_download("pdf", "hello world") |
14 | 11 | end
|
15 | 12 | end
|
16 | 13 |
|
17 | 14 | should "generate link if country exists" do
|
18 |
| - link = @calc.generate_url_for_download("argentina", "pdf", "Prisoner pack") |
| 15 | + calc = ArrestedAbroad.new("argentina") |
| 16 | + link = calc.generate_url_for_download("pdf", "Prisoner pack") |
19 | 17 | assert_equal "- [Prisoner pack](/government/publications/argentina-prisoner-pack)", link
|
20 | 18 | end
|
21 | 19 |
|
22 | 20 | should "not include external tag if URL is internal" do
|
23 |
| - link = @calc.generate_url_for_download("israel", "pdf", "Foo") |
| 21 | + calc = ArrestedAbroad.new("israel") |
| 22 | + link = calc.generate_url_for_download("pdf", "Foo") |
24 | 23 | assert_not link.include?("{:rel=\"external\"}")
|
25 | 24 | end
|
26 | 25 | end
|
27 | 26 |
|
| 27 | + context "has extra downloads" do |
| 28 | + should "return true for countries with regions" do |
| 29 | + calc = ArrestedAbroad.new("cyprus") |
| 30 | + calc.stubs(:country_name).returns("Cyprus") |
| 31 | + assert calc.has_extra_downloads |
| 32 | + end |
| 33 | + |
| 34 | + should "return false if not a country with regions nor has extra download links" do |
| 35 | + calc = ArrestedAbroad.new("bermuda") |
| 36 | + calc.stubs(:country_name).returns("Bermuda") |
| 37 | + assert_not calc.has_extra_downloads |
| 38 | + end |
| 39 | + |
| 40 | + should "return true if country has extra download links" do |
| 41 | + calc = ArrestedAbroad.new("australia") |
| 42 | + calc.stubs(:country_name).returns("Australia") |
| 43 | + assert calc.has_extra_downloads |
| 44 | + end |
| 45 | + end |
| 46 | + |
| 47 | + context "region downloads" do |
| 48 | + should "return list of region links for countries with regions" do |
| 49 | + calc = ArrestedAbroad.new("cyprus") |
| 50 | + calc.stubs(:get_country_regions).returns({ |
| 51 | + "a": { "url_text" => "Text 1", "link" => "link1" }, |
| 52 | + "b": { "url_text" => "Text 2", "link" => "link2" }, |
| 53 | + }) |
| 54 | + assert_equal calc.region_downloads, "- [Text 1](link1)\n- [Text 2](link2)" |
| 55 | + end |
| 56 | + |
| 57 | + should "return empty for countries without regions" do |
| 58 | + calc = ArrestedAbroad.new("bermuda") |
| 59 | + assert_equal calc.region_downloads, "" |
| 60 | + end |
| 61 | + end |
| 62 | + |
28 | 63 | context "countries with regions" do
|
29 | 64 | should "pull out regions of the YML for Cyprus" do
|
30 |
| - resp = @calc.get_country_regions("cyprus") |
| 65 | + calc = ArrestedAbroad.new("cyprus") |
| 66 | + resp = calc.get_country_regions |
31 | 67 | assert resp["north"]
|
32 | 68 | assert resp["north_lawyer"]
|
33 | 69 | assert resp["republic"]
|
34 | 70 | assert resp["republic_lawyers"]
|
35 | 71 | end
|
36 | 72 |
|
37 | 73 | should "pull the regions out of the YML for Cyprus" do
|
38 |
| - resp = @calc.get_country_regions("cyprus")["north"] |
| 74 | + calc = ArrestedAbroad.new("cyprus") |
| 75 | + resp = calc.get_country_regions["north"] |
39 | 76 | expected = {
|
40 | 77 | "link" => "/government/publications/cyprus-north-prisoner-pack",
|
41 | 78 | "url_text" => "Prisoner pack for the north of Cyprus",
|
|
0 commit comments