Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class ContactsController < ApplicationController
- before_action :authenticate_user!
- def index
- @contacts = current_user.contacts
- # @contacts = Contact.all
- end
- require 'rails_helper'
- describe ContactsController do
- before do
- @user = FactoryGirl.create(:user_with_contacts)
- sign_in @user
- end
- describe "GET INDEX" do
- it "assigns @contacts" do
- expect(assigns(:contacts)).to eq(@user.contacts)
- end
- end
- Failure/Error: expect(assigns(:contact)).to eq([contact])
- 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>]
- got: #<Contact id: nil, first_name: nil, email: nil, phone_number: nil, created_at: nil, updated_at: nil, last_name: nil, user_id: nil>
- FactoryGirl.define do
- factory :user do
- email { Faker::Internet.email }
- password { "32423fdsfasf42" }
- factory :user_with_contacts do
- transient do
- contacts_count 2
- end
- after(:create) do |user, evaluator|
- create_list(:contact, evaluator.contacts_count, user: user)
- end
- end
- end
- end
- puts @user.inspect
- #<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">
- puts @user.contacts.inspect
- #<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