Newer
Older
module HelperMethods
Raphael
a validé
def connect_users_with_aspects(u1,u2)
connect_users(u1, u1.aspects.first, u2, u2.aspects.first)
end
def connect_users(user1, aspect1, user2, aspect2)
Contact.create!(:user => user1,
:person => user2.person,
:aspects => [aspect1],
:pending => false)
Contact.create!(:user => user2,
:person => user1.person,
:aspects => [aspect2],
:pending => false)
user1.reload
user2.reload
aspect1.reload
aspect2.reload
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
end
def stub_success(address = 'abc@example.com', opts = {})
host = address.split('@')[1]
stub_request(:get, "https://#{host}/.well-known/host-meta").to_return(:status => 200, :body => host_xrd)
stub_request(:get, "http://#{host}/.well-known/host-meta").to_return(:status => 200, :body => host_xrd)
if opts[:diaspora] || host.include?("diaspora")
stub_request(:get, /webfinger\/\?q=#{address}/).to_return(:status => 200, :body => finger_xrd)
stub_request(:get, "http://#{host}/hcard/users/4c8eccce34b7da59ff000002").to_return(:status => 200, :body => hcard_response)
else
stub_request(:get, /webfinger\/\?q=#{address}/).to_return(:status => 200, :body => nonseed_finger_xrd)
stub_request(:get, 'http://evan.status.net/hcard').to_return(:status => 200, :body => evan_hcard)
end
end
def stub_failure(address = 'abc@example.com')
host = address.split('@')[1]
stub_request(:get, "https://#{host}/.well-known/host-meta").to_return(:status => 200, :body => host_xrd)
stub_request(:get, "http://#{host}/.well-known/host-meta").to_return(:status => 200, :body => host_xrd)
stub_request(:get, /webfinger\/\?q=#{address}/).to_return(:status => 500)
end
def host_xrd
File.open(File.dirname(__FILE__) + '/fixtures/host_xrd').read
end
def finger_xrd
File.open(File.dirname(__FILE__) + '/fixtures/finger_xrd').read
end
def hcard_response
File.open(File.dirname(__FILE__) + '/fixtures/hcard_response').read
end
def nonseed_finger_xrd
File.open(File.dirname(__FILE__) + '/fixtures/nonseed_finger_xrd').read
end
def evan_hcard
File.open(File.dirname(__FILE__) + '/fixtures/evan_hcard').read
end
def uploaded_photo
fixture_filename = 'button.png'
fixture_name = File.join(File.dirname(__FILE__), 'fixtures', fixture_filename)
File.open(fixture_name)
end