Advertisement
Guest User

Untitled

a guest
Sep 12th, 2015
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1. class ContactsController < ApplicationController
  2.  
  3. before_action :authenticate_user!
  4.  
  5. def index
  6. @contacts = current_user.contacts
  7. # @contacts = Contact.all
  8. end
  9.  
  10. require 'rails_helper'
  11.  
  12. describe ContactsController do
  13.  
  14. before do
  15. @user = FactoryGirl.create(:user_with_contacts)
  16. sign_in @user
  17. end
  18.  
  19. describe "GET INDEX" do
  20. it "assigns @contacts" do
  21. expect(assigns(:contacts)).to eq(@user.contacts)
  22. end
  23. end
  24.  
  25. Failure/Error: expect(assigns(:contact)).to eq([contact])
  26.  
  27. expected: [#<Contact id: 295, first_name: "Loy", email: "leon@hegmannhintz.net", phone_number: "6044339393", created_at: "2015-09-12 19:13:42", updated_at: "2015-09-12 19:13:42", last_name: "Wyman", user_id: 343>]
  28. got: #<Contact id: nil, first_name: nil, email: nil, phone_number: nil, created_at: nil, updated_at: nil, last_name: nil, user_id: nil>
  29.  
  30. FactoryGirl.define do
  31. factory :user do
  32. email { Faker::Internet.email }
  33. password { "32423fdsfasf42" }
  34.  
  35. factory :user_with_contacts do
  36. transient do
  37. contacts_count 2
  38. end
  39. after(:create) do |user, evaluator|
  40. create_list(:contact, evaluator.contacts_count, user: user)
  41. end
  42. end
  43. end
  44. end
  45.  
  46. puts @user.inspect
  47.  
  48. #<User id: 340, email: "johnson_kaulke@brekke.com", encrypted_password: "$2a$04$Si5k6Q1eYERvhQITXKBoIOGEzPyK50E3IQ.yjRcqmDj...", reset_password_token: nil, reset_password_sent_at: nil, remember_created_at: nil, sign_in_count: 0, current_sign_in_at: nil, last_sign_in_at: nil, current_sign_in_ip: nil, last_sign_in_ip: nil, created_at: "2015-09-12 19:13:42", updated_at: "2015-09-12 19:13:42">
  49.  
  50. puts @user.contacts.inspect
  51.  
  52. #<ActiveRecord::Associations::CollectionProxy [#<Contact id: 289, first_name: "Fae", email: "ariane@johnston.net", phone_number: "6044339393", created_at: "2015-09-12 19:13:42", updated_at: "2015-09-12 19:13:42", last_name: "Spinka", user_id: 340>, #<Contact id: 290, first_name: "Marcellus", email: "chloe_deckow@buckridge.net", phone_number: "6044339393", created_at: "2015-09-12 19:13:42", updated_at: "2015-09-12 19:13:42", last_name: "Bashirian", user_id: 340>]>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement