Skip to content

Instantly share code, notes, and snippets.

@thiagofm
Created August 14, 2014 21:56
Show Gist options
  • Select an option

  • Save thiagofm/1420027a008628e339e0 to your computer and use it in GitHub Desktop.

Select an option

Save thiagofm/1420027a008628e339e0 to your computer and use it in GitHub Desktop.
paciência_de_jó.rb
describe 'POST #create_from_r7login' do
let(:user_login){ 'var session = { "usersession" : { "userId" : "2c9629db45c75b6b0145cc8bfdba2a71" , "user" : { "login" : "test@r7.com" , "name" : "Test" , "nickname" : "Test" , "country" : "Brasil" , "state" : "Sao Paulo" , "city" : "Sao Paulo" , "zipCode" : "11111-111" , "gender" : "M" , "birthDate" : "30/04/1990"} , "savePassword" : false , "userLogged" : true}};' }
let(:login){ double('login', r7Session: '1234') }
let(:user_id) { '{ "id": "537e0379eba0b0e48d96dc04", "lastInteractionTimestamp": "2014-05-22 11:02:33.351 BRT", "userId": "8aee801a2cf5695d012cf56bf9560003", "savePassword": false, "userLogged": true, "processRetry": 0 }' }
let(:user_info) { '{ "user": { "id": "2c96958d4595cccf0145ae6e93bd000e", "login": "tst51@r7.com", "name": "teste51", "nickname": "teste51", "gender": "MALE", "zipCode": "00000-000", "documentNumber": "353.026.858-50", "city": { "id": 1, "name": "Acrelandia", "state": { "id": 1, "abbreviation": "AC", "name": "Acre" } }, "country": { "id": "BR", "name": "Brasil" }, "birthDate": { "time": 915156000000, "timezone": "America/Sao_Paulo" }, "lastLoginTimestamp": { "time": 1401891682000, "timezone": "America/Sao_Paulo" }, "createdAt": { "time": 1398790853000, "timezone": "America/Sao_Paulo" }, "status": "ENABLED", "createdFromIp": "10.110.60.91", "mobileDDD": 11, "mobilePhone": "11111-1111" } }' }
it 'creates the user and logs in user, redirecting to href' do
Typhoeus.stub('http://login.r7.com/ajax/session/data.js').and_return(Typhoeus::Response.new(code: 200, body: user_login))
Typhoeus.stub(/login\/session\?session/).and_return(Typhoeus::Response.new(code: 200, body: user_id))
Typhoeus.stub(/login\/session\/user/).and_return(Typhoeus::Response.new(code: 200, body: user_info))
allow(Login).to receive(:new).and_return(login)
allow(login).to receive(:execute).and_return(login)
allow(login).to receive(:signed_in?).and_return(true)
post :create_from_r7login, email: 'tfmassa', password: 'admadm123'
expect(response.status).to be 302
expect(response.cookies['r7Session']).to eq('"537e0379eba0b0e48d96dc04')
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment