Skip to content

Commit 15fa29a

Browse files
authored
Merge pull request #32 from alphagov/mb-upgrade-gds-api-adapters
Upgrade gds-api-adapters from 29.4.0 to 40.1
2 parents 34acf20 + 9b2d8d9 commit 15fa29a

File tree

5 files changed

+46
-34
lines changed

5 files changed

+46
-34
lines changed

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ gem 'plek', '~> 1.11.0'
1414
gem 'airbrake', '~> 4.1.0'
1515
gem 'decent_exposure', '~> 2.3.2'
1616

17-
gem 'gds-api-adapters', '~> 29.4.0'
17+
gem 'gds-api-adapters', '~> 40.1'
1818

1919
group :development, :test do
2020
gem 'pry-byebug'

Gemfile.lock

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -77,17 +77,17 @@ GEM
7777
debug_inspector (0.0.2)
7878
decent_exposure (2.3.2)
7979
diff-lcs (1.2.5)
80-
domain_name (0.5.24)
80+
domain_name (0.5.20170223)
8181
unf (>= 0.0.5, < 1.0.0)
8282
erubis (2.7.0)
8383
execjs (2.6.0)
84-
gds-api-adapters (29.4.0)
84+
gds-api-adapters (40.5.0)
8585
link_header
8686
lrucache (~> 0.1.1)
8787
null_logger
8888
plek (>= 1.9.0)
8989
rack-cache
90-
rest-client (~> 1.8.0)
90+
rest-client (~> 2.0)
9191
gherkin (2.12.2)
9292
multi_json (~> 1.3)
9393
globalid (0.3.6)
@@ -97,7 +97,7 @@ GEM
9797
govuk_frontend_toolkit (3.1.0)
9898
rails (>= 3.1.0)
9999
sass (>= 3.2.0)
100-
http-cookie (1.0.2)
100+
http-cookie (1.0.3)
101101
domain_name (~> 0.5)
102102
i18n (0.7.0)
103103
json (1.8.3)
@@ -114,12 +114,12 @@ GEM
114114
mail (2.6.3)
115115
mime-types (>= 1.16, < 3)
116116
method_source (0.8.2)
117-
mime-types (2.99.1)
117+
mime-types (2.99.3)
118118
mini_portile2 (2.0.0)
119119
minitest (5.8.4)
120120
multi_json (1.11.2)
121121
multi_test (0.1.2)
122-
netrc (0.10.3)
122+
netrc (0.11.0)
123123
nokogiri (1.6.7.2)
124124
mini_portile2 (~> 2.0.0.rc2)
125125
null_logger (0.0.1)
@@ -133,8 +133,8 @@ GEM
133133
pry (~> 0.10)
134134
quiet_assets (1.1.0)
135135
railties (>= 3.1, < 5.0)
136-
rack (1.6.4)
137-
rack-cache (1.6.1)
136+
rack (1.6.5)
137+
rack-cache (1.7.0)
138138
rack (>= 0.4)
139139
rack-test (0.6.3)
140140
rack (>= 1.0)
@@ -164,10 +164,10 @@ GEM
164164
thor (>= 0.18.1, < 2.0)
165165
raindrops (0.15.0)
166166
rake (10.5.0)
167-
rest-client (1.8.0)
167+
rest-client (2.0.1)
168168
http-cookie (>= 1.0.2, < 2.0)
169-
mime-types (>= 1.16, < 3.0)
170-
netrc (~> 0.7)
169+
mime-types (>= 1.16, < 4.0)
170+
netrc (~> 0.8)
171171
rspec-core (3.2.3)
172172
rspec-support (~> 3.2.0)
173173
rspec-expectations (3.2.1)
@@ -220,7 +220,7 @@ GEM
220220
json (>= 1.8.0)
221221
unf (0.1.4)
222222
unf_ext
223-
unf_ext (0.0.7.1)
223+
unf_ext (0.0.7.2)
224224
unicorn (4.9.0)
225225
kgio (~> 2.6)
226226
rack
@@ -240,7 +240,7 @@ DEPENDENCIES
240240
binding_of_caller
241241
cucumber-rails (~> 1.4.2)
242242
decent_exposure (~> 2.3.2)
243-
gds-api-adapters (~> 29.4.0)
243+
gds-api-adapters (~> 40.1)
244244
govuk-content-schema-test-helpers (~> 1.0.2)
245245
govuk_frontend_toolkit (~> 3.1.0)
246246
launchy
@@ -257,4 +257,4 @@ DEPENDENCIES
257257
webmock (~> 1.20.4)
258258

259259
BUNDLED WITH
260-
1.11.2
260+
1.14.5

app/controllers/email_alert_signups_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def content_store
1919
end
2020

2121
def email_alert_signup
22-
@email_alert_signup ||= EmailAlertSignup.new(content_store.content_item!("/#{params[:base_path]}"))
22+
@email_alert_signup ||= EmailAlertSignup.new(content_store.content_item("/#{params[:base_path]}"))
2323
end
2424
helper_method :email_alert_signup
2525
end

app/models/email_alert_signup.rb

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,16 @@ class EmailAlertSignup
55

66
validates_presence_of :signup_page
77

8-
delegate :title, to: :signup_page
9-
delegate :summary, :govdelivery_title, to: :"signup_page.details"
10-
118
attr_reader :subscription_url
129

1310
def initialize(signup_page)
1411
@signup_page = signup_page
15-
@base_path = signup_page.base_path if signup_page
12+
@base_path = signup_page['base_path'] if signup_page
1613
end
1714

1815
def save
1916
if valid?
20-
@subscription_url = find_or_create_subscription.subscriber_list.subscription_url
17+
@subscription_url = find_or_create_subscription.dig("subscriber_list" , "subscription_url")
2118
true
2219
else
2320
false
@@ -37,32 +34,45 @@ def government_content_section
3734
base_path.split('/')[2]
3835
end
3936

37+
def details
38+
signup_page['details']
39+
end
40+
41+
def title
42+
signup_page['title']
43+
end
44+
45+
def govdelivery_title
46+
details['govdelivery_title']
47+
end
48+
49+
def summary
50+
details['summary']
51+
end
52+
4053
private
54+
4155
attr_reader :signup_page, :base_path
4256

4357
def subscription_params
44-
subscriber_list = signup_page.details.subscriber_list
58+
subscriber_list = details['subscriber_list']
4559

4660
subscription_params = {
4761
title: govdelivery_title.present? ? govdelivery_title : title
4862
}
4963

50-
if subscriber_list.document_type.present?
51-
subscription_params[:document_type] = subscriber_list.document_type
64+
if subscriber_list['document_type'].present?
65+
subscription_params[:document_type] = subscriber_list['document_type']
5266
end
5367

54-
if subscriber_list.tags.present?
55-
subscription_params[:tags] = subscriber_list.tags.to_h
68+
if subscriber_list['tags'].present?
69+
subscription_params[:tags] = subscriber_list['tags'].to_h
5670
end
5771

58-
if subscriber_list.links.present?
59-
subscription_params[:links] = subscriber_list.links.to_h
72+
if subscriber_list['links'].present?
73+
subscription_params[:links] = subscriber_list['links'].to_h
6074
end
6175

6276
subscription_params.deep_stringify_keys
6377
end
64-
65-
def openstruct_to_hash(openstruct)
66-
openstruct.marshal_dump
67-
end
6878
end

spec/models/email_alert_signup_spec.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,16 @@
1212
let(:travel_index_item) { govuk_content_schema_example('travel_advice_index_email_alert_signup') }
1313
let(:travel_country_item) { govuk_content_schema_example('travel_advice_country_email_alert_signup') }
1414

15-
let(:mock_subscriber_list) { double(subscriber_list: double(subscription_url: 'http://foo')) }
15+
let(:mock_subscriber_list) do
16+
mock_response(subscriber_list: { subscription_url: "http://foo" })
17+
end
1618

1719
def mock_response(body)
1820
GdsApi::Response.new(double("net http response",
1921
code: 200,
2022
body: body.to_json,
2123
headers: {},
22-
)).to_ostruct
24+
))
2325
end
2426

2527
before do

0 commit comments

Comments
 (0)