Advertisement
Guest User

Untitled

a guest
Sep 4th, 2017
549
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.46 KB | None | 0 0
  1. FactoryGirl.define do
  2. factory :student do
  3. end
  4.  
  5. factory :student_with_profile_and_identity, class: 'Student' do
  6. after(:create) do |student|
  7. create(:profile, profileable: student)
  8. create(:student_identity, student: student)
  9. end
  10. end
  11. end
  12.  
  13. FactoryGirl.define do
  14. factory :profile do
  15. birthday { Faker::Date.birthday(15, 150) }
  16. sequence(:email) { |i| "profile_#{i}@email.com" }
  17. first_name { Faker::Name.first_name }
  18. last_name { Faker::Name.first_name }
  19. password { Faker::Internet.password(6, 72, true, true) }
  20. end
  21. end
  22.  
  23. FactoryGirl.define do
  24. factory :student_identity do
  25. provider { ['facebook.com', 'google.com', 'twitter.com'].sample }
  26. uid { Faker::Number.number(10) }
  27. end
  28. end
  29.  
  30. require 'rails_helper'
  31.  
  32. RSpec.describe 'Authorizations', type: :request do
  33. describe 'POST /v1/authorizations/sign_in' do
  34. let!(:student) { create(:student_with_profile_and_identity) }
  35.  
  36. context 'when the request is valid' do
  37. subject do
  38. post '/v1/authorizations/sign_in',
  39. params: credentials
  40. end
  41.  
  42. context "user signs up via social network" do
  43. let(:credentials) do
  44. {
  45. authorization: {
  46. student: {
  47. profile_attributes: {
  48. email: student.profile.email
  49. },
  50. student_identities_attributes: {
  51. provider: student.student_identities[0].provider,
  52. uid: student.student_identities[0].uid
  53. }
  54. }
  55. }
  56. }
  57. end
  58.  
  59. it 'returns an authentication token' do
  60. subject
  61. p "1 student.profile.inspect #{student.profile.inspect}"
  62. expect(json['token']).to(be_present)
  63. end
  64. end
  65.  
  66. context 'when the user has already an account' do
  67. let(:credentials) do
  68. {
  69. authorization: {
  70. email: student.profile.email,
  71. password: student.profile.password
  72. }
  73. }
  74. end
  75.  
  76. it 'returns an authentication token' do
  77. p "2 student.profile.inspect #{student.profile.inspect}"
  78. subject
  79. expect(json['token']).to(be_present)
  80. end
  81. end
  82. end
  83. end
  84. end
  85.  
  86. "1 student.profile.inspect #<Profile id: 1, email: "profile_1@email.com", profileable_type: "Student", profileable_id: 1>"
  87.  
  88. "2 student.profile.inspect #<Profile id: 2, email: "profile_2@email.com", profileable_type: "Student", profileable_id: 2>"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement