-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add person memberships class #7
base: master
Are you sure you want to change the base?
Conversation
d8b5e9f
to
0f0c020
Compare
test/person_memberships_test.rb
Outdated
let(:profile_page_response) { open(profile_url) } | ||
let(:cookie) { Cookie.new(profile_page_response.meta['set-cookie'])} | ||
# We can now send a request to the memberships page with correct cookie. | ||
let(:header){ { 'Cookie' => cookie.to_s } } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think you need the Cookie
class at all. You can just pass the cookie back exactly as you received it:
let(:header){ { 'Cookie' => profile_page_response.meta['set-cookie'] } }
However in my experimenting it seemed that there wasn't always a cookie in the response, so we should probably only be sending this when there's a cookie in the response.
Here's the script I've been using to experiment with the cookies that are being returned:
require 'open-uri'
def error?(res)
if res.read.include?('missing string: error')
warn "! Error"
else
warn "OK"
end
end
memberships_url = 'http://www.congreso.es/portal/page/portal/Congreso/Congreso/Diputados/BusqForm?next_page=/wc/listadoFichas?idDiputado=338&idLegislatura=12'
warn "Requesting member page"
membership_page = open('http://www.congreso.es/portal/page/portal/Congreso/Congreso/Diputados/BusqForm?next_page=/wc/fichaDiputado?idDiputado=338&idLegislatura=12')
if membership_page.meta['set-cookie'].to_s.empty?
warn "No Set-Cookie response header from membership page"
warn "Requesting person memberships without Cookie"
res = open(memberships_url)
error?(res)
else
warn "Requesting person memberships with Cookie"
res = open(memberships_url, 'Cookie' => membership_page.meta['set-cookie'])
error?(res)
end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. I'd somehow convinced myself that it wouldn't work. Works every time!
c197b9d
to
6d34f72
Compare
39433af
to
ed44549
Compare
d0e8f54
to
b836de2
Compare
15469a7
to
9f40ca4
Compare
Represent a single row on the page that lists all memberships of a person
:memberships returns a fragment MembershipRow fragment for each listed membership.
The latest version allows custom headers to be added to requests
Tests that correct number of memberships is captured and membership row contains expected data.
9f40ca4
to
b577c5a
Compare
In addition to the membership profile:

…members have a list of memberships reached via the 'Todas las legislaturas' link.
PersonMemberships
returns a collection ofMembershipRow
objects. Each of these contains the legislature id, url and name of deputy. The url points to a separate profile page for each of the memberships. (That is, if a member has sat it terms 9,10, and 11, there will be a separate profile page for the member for these three terms.)