From 6f7934da5a7bdb2d8be26a6c415f4346c8149fbc Mon Sep 17 00:00:00 2001 From: giusepped Date: Wed, 15 Feb 2017 16:24:28 +0000 Subject: [PATCH] implemented #current? for party_membership and #empty? for reponse --- lib/parliament/decorators/party_membership.rb | 6 + lib/parliament/response.rb | 2 +- ...urrent_or_non_current_party_membership.yml | 110 ++++++++++++++++++ .../decorators/party_membership_spec.rb | 8 ++ spec/parliament/response_spec.rb | 4 + 5 files changed, 129 insertions(+), 1 deletion(-) create mode 100644 spec/fixtures/vcr_cassettes/Parliament_Decorators_PartyMembership/_current_/Grom_Node_returns_the_correct_value_for_a_current_or_non_current_party_membership.yml diff --git a/lib/parliament/decorators/party_membership.rb b/lib/parliament/decorators/party_membership.rb index bfb62de..4a56702 100644 --- a/lib/parliament/decorators/party_membership.rb +++ b/lib/parliament/decorators/party_membership.rb @@ -12,6 +12,12 @@ def start_date def end_date respond_to?(:partyMembershipEndDate) ? DateTime.parse(partyMembershipEndDate) : nil end + + def current? + has_end_date = respond_to?(:partyMembershipEndDate) + + !has_end_date + end end end end diff --git a/lib/parliament/response.rb b/lib/parliament/response.rb index ac4259a..29d40c6 100644 --- a/lib/parliament/response.rb +++ b/lib/parliament/response.rb @@ -5,7 +5,7 @@ class Response include Enumerable extend Forwardable attr_reader :nodes - def_delegators :@nodes, :size, :each, :select, :map, :select!, :map!, :count, :length, :[] + def_delegators :@nodes, :size, :each, :select, :map, :select!, :map!, :count, :length, :[], :empty? def initialize(nodes) @nodes = nodes diff --git a/spec/fixtures/vcr_cassettes/Parliament_Decorators_PartyMembership/_current_/Grom_Node_returns_the_correct_value_for_a_current_or_non_current_party_membership.yml b/spec/fixtures/vcr_cassettes/Parliament_Decorators_PartyMembership/_current_/Grom_Node_returns_the_correct_value_for_a_current_or_non_current_party_membership.yml new file mode 100644 index 0000000..2318b6d --- /dev/null +++ b/spec/fixtures/vcr_cassettes/Parliament_Decorators_PartyMembership/_current_/Grom_Node_returns_the_correct_value_for_a_current_or_non_current_party_membership.yml @@ -0,0 +1,110 @@ +--- +http_interactions: +- request: + method: get + uri: http://localhost:3030/people/626b57f9-6ef0-475a-ae12-40a44aca7eff.nt + body: + encoding: US-ASCII + string: '' + headers: + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + User-Agent: + - Ruby + Host: + - localhost:3030 + response: + status: + code: 200 + message: OK + headers: + X-Frame-Options: + - SAMEORIGIN + X-Xss-Protection: + - 1; mode=block + X-Content-Type-Options: + - nosniff + Content-Type: + - application/n-triples; charset=utf-8 + Etag: + - W/"0d1204977f2acac07c059d95380c652e" + Cache-Control: + - max-age=0, private, must-revalidate + X-Request-Id: + - 88a81d4b-bed6-4f9e-8a98-a38b7685fc10 + X-Runtime: + - '0.094576' + Transfer-Encoding: + - chunked + body: + encoding: UTF-8 + string: | + . + "1947-09-17"^^ . + "Person 1 - givenName" . + "Person 1 - familyName" . + . + . + . + . + . + . + "F" . + . + "Dulwich" . + . + "1997-05-01"^^ . + "1992-04-09"^^ . + . + . + . + . + . + "Labour" . + . + "1992-04-09"^^ . + "2015-03-30"^^ . + . + . + "House of Commons" . + . + . + "2015-10-27"^^ . + . + . + . + "Dulwich and West Norwood" . + . + "2001-06-07"^^ . + "1997-05-01"^^ . + . + . + . + . + . + . + "2005-05-05"^^ . + "2001-06-07"^^ . + . + . + . + "2010-05-06"^^ . + "2005-05-05"^^ . + . + . + . + "Dulwich and West Norwood" . + . + "2015-03-30"^^ . + "2010-05-06"^^ . + . + . + . + . + . + + http_version: + recorded_at: Mon, 06 Feb 2017 15:15:39 GMT +recorded_with: VCR 3.0.3 diff --git a/spec/parliament/decorators/party_membership_spec.rb b/spec/parliament/decorators/party_membership_spec.rb index 9f995eb..ea2ffad 100644 --- a/spec/parliament/decorators/party_membership_spec.rb +++ b/spec/parliament/decorators/party_membership_spec.rb @@ -63,4 +63,12 @@ end end end + + describe '#current?' do + it 'Grom::Node returns the correct value for a current or non current party membership' do + party_membership_results = @party_membership_nodes.map(&:current?) + + expect(party_membership_results).to eq([false, true]) + end + end end diff --git a/spec/parliament/response_spec.rb b/spec/parliament/response_spec.rb index 1cd11d2..ab0121f 100644 --- a/spec/parliament/response_spec.rb +++ b/spec/parliament/response_spec.rb @@ -44,6 +44,10 @@ it 'should respond to []' do expect(subject).to respond_to(:[]) end + + it 'should respond to empty?' do + expect(subject).to respond_to(:empty?) + end end describe '#filter' do