Refactor the gravatar email changes to use webmock stubbing

The main reason for doing this is to make the tests easier to read,
rather than having to look up both the gravatar fixture, and then
correlate that with the users fixture. Putting the expected response
code in the tests is much more explicit.
This commit is contained in:
Andy Allan 2016-10-30 11:06:35 +01:00
parent 5e86393f72
commit 4d73706ff3
3 changed files with 37 additions and 34 deletions

View file

@ -168,5 +168,11 @@ module ActiveSupport
yield
end
def stub_gravatar_request(email, status = 200, body = nil)
hash = Digest::MD5.hexdigest(email.downcase)
url = "https://www.gravatar.com/avatar/#{hash}?d=404"
stub_request(:get, url).and_return(:status => status, :body => body)
end
end
end