<NME> user_spec.rb
<BEF> # frozen_string_literal: true

require 'rails_helper'

RSpec.describe User do
  let(:user) { create(:user) }
  let(:male_user) { create(:user, gender: 'male') }
  let(:female_user) { create(:user, gender: 'female') }
  let(:jack_black) { create(:user, name: 'Jack Black') }
  let(:anonymous) { create(:user, name: nil) }

  describe 'after destroy' do
    let(:demo_mode) { false }

    before do
      allow(DeleteUserJob).to receive(:perform_later)
    end

    around do |example|
      old_demo_mode_value = APP_CONFIG.demo_mode
      APP_CONFIG.set :demo_mode, demo_mode

      example.run
    ensure
      APP_CONFIG.set :demo_mode, old_demo_mode_value
    end

    it 'does not delete user on provider' do
      user.destroy

      expect(DeleteUserJob).not_to have_received(:perform_later)
    end

    context 'when demo mode is enabled' do
      let(:demo_mode) { true }

      it 'deletes user on provider' do
        user.destroy

        expect(DeleteUserJob).to have_received(:perform_later).with(user.uid)
      end
    end
  end

  # rubocop:disable Naming/VariableNumber
  describe '#age' do
    let(:born_on_1960_10_30) { create(:user, birthday: '1960-10-30') }
    let(:born_on_1972_02_29) { create(:user, birthday: '1972-02-29') }
    let(:unknown_birthday) { create(:user, birthday: nil) }

    it "returns user's age" do
      travel_to '2011-02-28 12:00' do
        expect(born_on_1972_02_29.age).to be 38
      end

      travel_to '2011-03-01 12:00' do
        expect(born_on_1972_02_29.age).to be 39
      end

      travel_to '2012-02-28 12:00' do
        expect(born_on_1972_02_29.age).to be 39
      end

      travel_to '2012-02-29 12:00' do
        expect(born_on_1972_02_29.age).to be 40
      end

      travel_to '2012-10-29 12:00' do
    end
  end

  context '.to_param' do
    let(:jackblack) { create :user, username: 'jackblack', uid: '123456' }
    let(:uid123456) { create :user, username: nil, uid: '123456' }
    let(:anonymous) { create :user, username: nil, uid: nil }

    it 'returns username when all fields are available' do
      expect(jackblack.to_param).to eq jackblack.username
    end

    it 'returns uid when username is not available' do
      expect(uid123456.to_param).to eq uid123456.uid
    end

    it 'fallbacks to id when neither the username nor the uid is available' do
      expect(anonymous.to_param).to eq anonymous.id
    end
  end

  context '.profile_picture' do
    it 'returns facebook profile picture of type square (by default)' do
      expect(user.profile_picture).to eq "http://graph.facebook.com/#{user.uid}/picture?type=square"
    end

    it 'does not raise exceptions if user has no birthday' do
      expect(unknown_birthday.age).to be_nil
    end
  end
  # rubocop:enable Naming/VariableNumber

  describe '#female?' do
    it 'answers true if user is female' do
      expect(female_user.female?).to be true
    end

    it 'answers false if user is male' do
      expect(male_user.female?).to be false
    end
  end

  describe '#first_name' do
    it "returns user's first name" do
      expect(jack_black.first_name).to eq 'Jack'
    end

    it 'does not raise exceptions if user has no name' do
      expect(anonymous.first_name).to be_nil
    end
  end

  describe '#to_s' do
    it "returns user's name when available" do
      expect(jack_black.to_s).to eq 'Jack Black'
      expect(anonymous.to_s).to eq anonymous.id.to_s
    end
  end

  describe '#unread_conversations_count' do
    it 'returns the number of unread conversations' do
      driver = create(:user)
      passenger = create(:user)
      itinerary = create(:itinerary, user: driver)
      conversation = create(:conversation, sender: passenger, receiver: driver, conversable: itinerary)
      conversation.messages << build(:message, sender: driver, body: 'First unread message from Driver')
      conversation.save

      expect(passenger.unread_conversations_count).to be 1
    end
  end
end

<MSG> Remove username
<DFF> @@ -69,24 +69,6 @@ describe User do
     end
   end
 
-  context '.to_param' do
-    let(:jackblack) { create :user, username: 'jackblack', uid: '123456' }
-    let(:uid123456) { create :user, username: nil, uid: '123456' }
-    let(:anonymous) { create :user, username: nil, uid: nil }
-
-    it 'returns username when all fields are available' do
-      expect(jackblack.to_param).to eq jackblack.username
-    end
-
-    it 'returns uid when username is not available' do
-      expect(uid123456.to_param).to eq uid123456.uid
-    end
-
-    it 'fallbacks to id when neither the username nor the uid is available' do
-      expect(anonymous.to_param).to eq anonymous.id
-    end
-  end
-
   context '.profile_picture' do
     it 'returns facebook profile picture of type square (by default)' do
       expect(user.profile_picture).to eq "http://graph.facebook.com/#{user.uid}/picture?type=square"

{'commit': 'diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb\nindex 928e3276..983d345f 100644\n--- a/app/controllers/application_controller.rb\n+++ b/app/controllers/application_controller.rb\n@@ -3,7 +3,7 @@ class ApplicationController < ActionController::Base\n   protect_from_forgery with: :exception\n \n   before_action :authenticate_user!\n-  before_action :check_banned, except: [:banned]\n+  before_action :check_banned, except: [:banned], if: :user_signed_in?\n \n   around_action :set_locale_from_params\n   around_action :time_zone_from_user, if: :user_signed_in?\n@@ -28,11 +28,7 @@ class ApplicationController < ActionController::Base\n   end\n \n   def check_banned\n-    redirect_to :banned if user_signed_in? && current_user.banned?\n-  end\n-\n-  def find_user(param)\n-    User.find_by(username_or_uid: param)\n+    redirect_to :banned if current_user.banned?\n   end\n \n   private\ndiff --git a/app/controllers/references_controller.rb b/app/controllers/references_controller.rb\nindex 6c75c3bb..2b632580 100644\n--- a/app/controllers/references_controller.rb\n+++ b/app/controllers/references_controller.rb\n@@ -53,6 +53,6 @@ class ReferencesController < ApplicationController\n   end\n \n   def set_user\n-    @user = find_user params[:user_id]\n+    @user = User.find(params[:user_id])\n   end\n end\ndiff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb\nindex 3eec85d9..f5f3fcec 100644\n--- a/app/controllers/users_controller.rb\n+++ b/app/controllers/users_controller.rb\n@@ -3,7 +3,7 @@ class UsersController < ApplicationController\n   before_action :set_user_as_current_user, only: [:update, :dashboard, :settings, :itineraries]\n \n   def show\n-    @user = find_user params[:id]\n+    @user = User.find(params[:id])\n   end\n \n   def update\ndiff --git a/app/models/user.rb b/app/models/user.rb\nindex f1e9b30a..704c86c0 100644\n--- a/app/models/user.rb\n+++ b/app/models/user.rb\n@@ -46,8 +46,6 @@ class User\n \n   paginates_per 25\n \n-  index(username_or_uid: 1)\n-\n   has_and_belongs_to_many :conversations\n \n   has_many :itineraries, dependent: :destroy\n@@ -73,7 +71,6 @@ class User\n   field :facebook_verified, type: Boolean, default: false\n \n   # Extra\n-  field :username\n   field :gender\n   field :bio\n   field :languages, type: Array, default: []\n@@ -84,7 +81,6 @@ class User\n   field :education, type: Array, default: []\n \n   # Icare\n-  field :username_or_uid\n   field :vehicle_avg_consumption, type: Float, default: APP_CONFIG.fuel_consumption\n \n   # Account\n@@ -116,10 +112,6 @@ class User\n     name || id\n   end\n \n-  def to_param\n-    username || uid || id\n-  end\n-\n   def profile_picture(type = \'square\')\n     "http://graph.facebook.com/#{uid}/picture?type=#{type}"\n   end\ndiff --git a/app/views/pages/demo_terms.en-US.html.slim b/app/views/pages/demo_terms.en-US.html.slim\nindex 11d33c56..691f7e26 100644\n--- a/app/views/pages/demo_terms.en-US.html.slim\n+++ b/app/views/pages/demo_terms.en-US.html.slim\n@@ -24,7 +24,6 @@\n       li\n         | Email, name, birthday, work, education, about, friends, favorites, known languages.\n     | We do not store your public profile picture.\n-    | Your username on #{APP_CONFIG.app_name} will be the same of Facebook.\n   p\n     | We will not send you any email.\n   p\ndiff --git a/config/locales/models/en-US.yml b/config/locales/models/en-US.yml\nindex acac657a..76f9eca6 100755\n--- a/config/locales/models/en-US.yml\n+++ b/config/locales/models/en-US.yml\n@@ -30,7 +30,6 @@ en-US:\n         name: Name\n         facebook_verified: Verified on Facebook\n         about: About\n-        username: Username\n         gender: Gender\n         age: Age\n         locale: Localization\ndiff --git a/config/locales/models/it-IT.yml b/config/locales/models/it-IT.yml\nindex 870286c4..4304aae0 100755\n--- a/config/locales/models/it-IT.yml\n+++ b/config/locales/models/it-IT.yml\n@@ -30,7 +30,6 @@ it-IT:\n         name: Nome\n         facebook_verified: Verificato su Facebook\n         about: Su di te\n-        username: Nome utente\n         gender: Sesso\n         age: Età\n         locale: Localizzazione\ndiff --git a/config/routes.rb b/config/routes.rb\nindex 7c42bdfc..d922e08c 100644\n--- a/config/routes.rb\n+++ b/config/routes.rb\n@@ -20,7 +20,7 @@ Rails.application.routes.draw do\n \n   resources :notifications, only: :index\n \n-  resources :users, constraints: { id: /[A-Za-z0-9\\.]+/ }, only: [:show, :update, :destroy] do\n+  resources :users, only: [:show, :update, :destroy] do\n     get :itineraries, on: :member\n     resources :references, only: [:show, :new, :create, :update, :index]\n   end\ndiff --git a/spec/factories.rb b/spec/factories.rb\nindex b7a60719..4c46b869 100644\n--- a/spec/factories.rb\n+++ b/spec/factories.rb\n@@ -1,14 +1,11 @@\n # frozen_string_literal: true\n FactoryGirl.define do\n   sequence(:uid)      { |n| "100#{n}" }\n-  sequence(:username) { |n| "person#{n}" }\n   sequence(:email)    { |n| "person#{n}@example.com" }\n \n   factory :user do\n     uid\n-    username\n     email\n-    username_or_uid { |u| [u.username, u.uid] }\n     provider \'facebook\'\n     name { Faker::Name.name }\n     gender \'male\'\ndiff --git a/spec/features/admin_spec.rb b/spec/features/admin_spec.rb\nindex 9dec9558..035a23e9 100644\n--- a/spec/features/admin_spec.rb\n+++ b/spec/features/admin_spec.rb\n@@ -3,7 +3,7 @@ require \'spec_helper\'\n \n describe \'Admin\' do\n   before(:each) do\n-    @admin = create :user, admin: true, uid: \'123456\', username: \'johndoe\'\n+    @admin = create :user, admin: true, uid: \'123456\'\n \n     visit user_facebook_omniauth_authorize_path\n   end\ndiff --git a/spec/features/conversations_spec.rb b/spec/features/conversations_spec.rb\nindex a873b8e8..ddb43759 100644\n--- a/spec/features/conversations_spec.rb\n+++ b/spec/features/conversations_spec.rb\n@@ -3,7 +3,7 @@ require \'spec_helper\'\n \n describe \'Conversations\' do\n   let(:driver) { create :user }\n-  let(:passenger) { create :user, uid: \'123456\', username: \'johndoe\' }\n+  let(:passenger) { create :user, uid: \'123456\' }\n   let(:itinerary) { create :itinerary, user: driver }\n \n   it \'allows to see own notifications\' do\ndiff --git a/spec/features/feedbacks_spec.rb b/spec/features/feedbacks_spec.rb\nindex 0fc45323..830c9d02 100644\n--- a/spec/features/feedbacks_spec.rb\n+++ b/spec/features/feedbacks_spec.rb\n@@ -3,7 +3,7 @@ require \'spec_helper\'\n \n describe \'Feedbacks\' do\n   it \'allows creation from registered users\' do\n-    create :user, uid: \'123456\', username: \'johndoe\'\n+    create :user, uid: \'123456\'\n \n     visit user_facebook_omniauth_authorize_path\n \n@@ -16,7 +16,7 @@ describe \'Feedbacks\' do\n   end\n \n   it \'allows editing by owners\' do\n-    user = create :user, uid: \'123456\', username: \'johndoe\'\n+    user = create :user, uid: \'123456\'\n     feedback = create :feedback, user: user\n \n     visit user_facebook_omniauth_authorize_path\n@@ -32,7 +32,7 @@ describe \'Feedbacks\' do\n \n   it \'allows editing by admins\' do\n     feedback = create :feedback\n-    create :user, uid: \'123456\', username: \'johndoe\', admin: true\n+    create :user, uid: \'123456\', admin: true\n \n     visit user_facebook_omniauth_authorize_path\n     visit feedback_path(feedback)\n@@ -47,7 +47,7 @@ describe \'Feedbacks\' do\n \n   it \'allows closing by admins\' do\n     feedback = create :feedback\n-    create :user, uid: \'123456\', username: \'johndoe\', admin: true\n+    create :user, uid: \'123456\', admin: true\n \n     visit user_facebook_omniauth_authorize_path\n     visit feedback_path(feedback)\n@@ -61,7 +61,7 @@ describe \'Feedbacks\' do\n   end\n \n   it \'allows deletion by owners\' do\n-    user = create :user, uid: \'123456\', username: \'johndoe\'\n+    user = create :user, uid: \'123456\'\n     feedback = create :feedback, user: user\n \n     visit user_facebook_omniauth_authorize_path\n@@ -74,7 +74,7 @@ describe \'Feedbacks\' do\n \n   it \'allows deletion by admins\' do\n     feedback = create :feedback\n-    create :user, uid: \'123456\', username: \'johndoe\', admin: true\n+    create :user, uid: \'123456\', admin: true\n \n     visit user_facebook_omniauth_authorize_path\n     visit feedbacks_path\n@@ -85,7 +85,7 @@ describe \'Feedbacks\' do\n   end\n \n   it "doesn\'t fail when user deletes their account" do\n-    create :user, uid: \'123456\', username: \'johndoe\'\n+    create :user, uid: \'123456\'\n     feedback = create :feedback\n     former_user_feedback = create :feedback\n     former_user_feedback.user.destroy\n@@ -98,7 +98,7 @@ describe \'Feedbacks\' do\n   end\n \n   it "doesn\'t fail when creating with wrong parameters" do\n-    create :user, uid: \'123456\', username: \'johndoe\'\n+    create :user, uid: \'123456\'\n \n     visit user_facebook_omniauth_authorize_path\n     visit new_feedback_path\n@@ -108,7 +108,7 @@ describe \'Feedbacks\' do\n   end\n \n   it "doesn\'t fail when updating with wrong parameters" do\n-    user = create :user, uid: \'123456\', username: \'johndoe\'\n+    user = create :user, uid: \'123456\'\n     feedback = create :feedback, user: user\n \n     visit user_facebook_omniauth_authorize_path\ndiff --git a/spec/features/references_spec.rb b/spec/features/references_spec.rb\nindex 5fb423f4..2ac5b8f8 100644\n--- a/spec/features/references_spec.rb\n+++ b/spec/features/references_spec.rb\n@@ -10,13 +10,13 @@ describe \'References\' do\n   let(:itinerary) { create :itinerary, user: driver }\n \n   def login_as_driver\n-    driver.update_attributes uid: \'123456\', username: \'johndoe\'\n+    driver.update_attributes uid: \'123456\'\n \n     visit user_facebook_omniauth_authorize_path\n   end\n \n   def login_as_passenger\n-    passenger.update_attributes uid: \'123456\', username: \'johndoe\'\n+    passenger.update_attributes uid: \'123456\'\n \n     visit user_facebook_omniauth_authorize_path\n   end\ndiff --git a/spec/features/users_spec.rb b/spec/features/users_spec.rb\nindex 0dc06f01..9ef3eb87 100644\n--- a/spec/features/users_spec.rb\n+++ b/spec/features/users_spec.rb\n@@ -13,7 +13,7 @@ describe \'Users\' do\n   end\n \n   it \'allows to delete account\' do\n-    create :user, uid: \'123456\', username: \'johndoe\'\n+    create :user, uid: \'123456\'\n \n     visit user_facebook_omniauth_authorize_path\n \n@@ -26,7 +26,7 @@ describe \'Users\' do\n \n   context \'Settings\' do\n     it \'allows to edit profile\' do\n-      user = create :user, uid: \'123456\', username: \'johndoe\'\n+      user = create :user, uid: \'123456\'\n       visit user_facebook_omniauth_authorize_path\n       visit settings_path\n       fill_in \'user_vehicle_avg_consumption\', with: \'0.29\'\n@@ -36,7 +36,7 @@ describe \'Users\' do\n     end\n \n     it \'recovers from errors\' do\n-      create :user, uid: \'123456\', username: \'johndoe\'\n+      create :user, uid: \'123456\'\n       visit user_facebook_omniauth_authorize_path\n       visit settings_path\n       fill_in \'user_vehicle_avg_consumption\', with: nil\n@@ -50,7 +50,7 @@ describe \'Users\' do\n       female_user = create :user, gender: \'female\'\n       create :itinerary, pink: true, user: female_user\n       create_list :itinerary, 5\n-      create :user, uid: \'123456\', username: \'johndoe\'\n+      create :user, uid: \'123456\'\n \n       visit user_facebook_omniauth_authorize_path\n \n@@ -84,7 +84,7 @@ describe \'Users\' do\n     end\n \n     before(:each) do\n-      @user = create :user, uid: \'123456\', username: \'johndoe\'\n+      @user = create :user, uid: \'123456\'\n       visit user_facebook_omniauth_authorize_path\n       visit user_path(@user)\n     end\ndiff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb\nindex c67edd26..a8aac63e 100644\n--- a/spec/models/user_spec.rb\n+++ b/spec/models/user_spec.rb\n@@ -69,24 +69,6 @@ describe User do\n     end\n   end\n \n-  context \'.to_param\' do\n-    let(:jackblack) { create :user, username: \'jackblack\', uid: \'123456\' }\n-    let(:uid123456) { create :user, username: nil, uid: \'123456\' }\n-    let(:anonymous) { create :user, username: nil, uid: nil }\n-\n-    it \'returns username when all fields are available\' do\n-      expect(jackblack.to_param).to eq jackblack.username\n-    end\n-\n-    it \'returns uid when username is not available\' do\n-      expect(uid123456.to_param).to eq uid123456.uid\n-    end\n-\n-    it \'fallbacks to id when neither the username nor the uid is available\' do\n-      expect(anonymous.to_param).to eq anonymous.id\n-    end\n-  end\n-\n   context \'.profile_picture\' do\n     it \'returns facebook profile picture of type square (by default)\' do\n       expect(user.profile_picture).to eq "http://graph.facebook.com/#{user.uid}/picture?type=square"\n', 'commit_subject': 'Remove username', 'repo_name': 'diowa/icare', 'committer': {'name': 'Geremia Taglialatela', 'email': '37202d6068035727e15d6c4bd05dbee26d50f5e4@gmail.com', 'time_sec': '1464253507', 'tz_offset': '120', 'date': {'seconds': '1464253507'}}, 'commit_tree': 'be65c19750c31ddd22e9fed26c87f9a8a256dcaf', 'commit_message': 'Remove username', 'language_name': 'Ruby', 'license': 'bsd-2-clause', 'hunks': '@@ -69,24 +69,6 @@ describe User do\n     end\n   end\n \n-  context \'.to_param\' do\n-    let(:jackblack) { create :user, username: \'jackblack\', uid: \'123456\' }\n-    let(:uid123456) { create :user, username: nil, uid: \'123456\' }\n-    let(:anonymous) { create :user, username: nil, uid: nil }\n-\n-    it \'returns username when all fields are available\' do\n-      expect(jackblack.to_param).to eq jackblack.username\n-    end\n-\n-    it \'returns uid when username is not available\' do\n-      expect(uid123456.to_param).to eq uid123456.uid\n-    end\n-\n-    it \'fallbacks to id when neither the username nor the uid is available\' do\n-      expect(anonymous.to_param).to eq anonymous.id\n-    end\n-  end\n-\n   context \'.profile_picture\' do\n     it \'returns facebook profile picture of type square (by default)\' do\n       expect(user.profile_picture).to eq "http://graph.facebook.com/#{user.uid}/picture?type=square"\n', 'addition_count': 0, 'deletion_count': 18, 'src_file': 'a/spec/models/user_spec.rb', 'tgt_file': 'b/spec/models/user_spec.rb', 'file_extension': '.rb', 'before_file': '# frozen_string_literal: true\n\nrequire \'rails_helper\'\n\nRSpec.describe User do\n  let(:user) { create(:user) }\n  let(:male_user) { create(:user, gender: \'male\') }\n  let(:female_user) { create(:user, gender: \'female\') }\n  let(:jack_black) { create(:user, name: \'Jack Black\') }\n  let(:anonymous) { create(:user, name: nil) }\n\n  describe \'after destroy\' do\n    let(:demo_mode) { false }\n\n    before do\n      allow(DeleteUserJob).to receive(:perform_later)\n    end\n\n    around do |example|\n      old_demo_mode_value = APP_CONFIG.demo_mode\n      APP_CONFIG.set :demo_mode, demo_mode\n\n      example.run\n    ensure\n      APP_CONFIG.set :demo_mode, old_demo_mode_value\n    end\n\n    it \'does not delete user on provider\' do\n      user.destroy\n\n      expect(DeleteUserJob).not_to have_received(:perform_later)\n    end\n\n    context \'when demo mode is enabled\' do\n      let(:demo_mode) { true }\n\n      it \'deletes user on provider\' do\n        user.destroy\n\n        expect(DeleteUserJob).to have_received(:perform_later).with(user.uid)\n      end\n    end\n  end\n\n  # rubocop:disable Naming/VariableNumber\n  describe \'#age\' do\n    let(:born_on_1960_10_30) { create(:user, birthday: \'1960-10-30\') }\n    let(:born_on_1972_02_29) { create(:user, birthday: \'1972-02-29\') }\n    let(:unknown_birthday) { create(:user, birthday: nil) }\n\n    it "returns user\'s age" do\n      travel_to \'2011-02-28 12:00\' do\n        expect(born_on_1972_02_29.age).to be 38\n      end\n\n      travel_to \'2011-03-01 12:00\' do\n        expect(born_on_1972_02_29.age).to be 39\n      end\n\n      travel_to \'2012-02-28 12:00\' do\n        expect(born_on_1972_02_29.age).to be 39\n      end\n\n      travel_to \'2012-02-29 12:00\' do\n        expect(born_on_1972_02_29.age).to be 40\n      end\n\n      travel_to \'2012-10-29 12:00\' do\n    end\n  end\n\n  context \'.to_param\' do\n    let(:jackblack) { create :user, username: \'jackblack\', uid: \'123456\' }\n    let(:uid123456) { create :user, username: nil, uid: \'123456\' }\n    let(:anonymous) { create :user, username: nil, uid: nil }\n\n    it \'returns username when all fields are available\' do\n      expect(jackblack.to_param).to eq jackblack.username\n    end\n\n    it \'returns uid when username is not available\' do\n      expect(uid123456.to_param).to eq uid123456.uid\n    end\n\n    it \'fallbacks to id when neither the username nor the uid is available\' do\n      expect(anonymous.to_param).to eq anonymous.id\n    end\n  end\n\n  context \'.profile_picture\' do\n    it \'returns facebook profile picture of type square (by default)\' do\n      expect(user.profile_picture).to eq "http://graph.facebook.com/#{user.uid}/picture?type=square"\n    end\n\n    it \'does not raise exceptions if user has no birthday\' do\n      expect(unknown_birthday.age).to be_nil\n    end\n  end\n  # rubocop:enable Naming/VariableNumber\n\n  describe \'#female?\' do\n    it \'answers true if user is female\' do\n      expect(female_user.female?).to be true\n    end\n\n    it \'answers false if user is male\' do\n      expect(male_user.female?).to be false\n    end\n  end\n\n  describe \'#first_name\' do\n    it "returns user\'s first name" do\n      expect(jack_black.first_name).to eq \'Jack\'\n    end\n\n    it \'does not raise exceptions if user has no name\' do\n      expect(anonymous.first_name).to be_nil\n    end\n  end\n\n  describe \'#to_s\' do\n    it "returns user\'s name when available" do\n      expect(jack_black.to_s).to eq \'Jack Black\'\n      expect(anonymous.to_s).to eq anonymous.id.to_s\n    end\n  end\n\n  describe \'#unread_conversations_count\' do\n    it \'returns the number of unread conversations\' do\n      driver = create(:user)\n      passenger = create(:user)\n      itinerary = create(:itinerary, user: driver)\n      conversation = create(:conversation, sender: passenger, receiver: driver, conversable: itinerary)\n      conversation.messages << build(:message, sender: driver, body: \'First unread message from Driver\')\n      conversation.save\n\n      expect(passenger.unread_conversations_count).to be 1\n    end\n  end\nend\n', 'message': 'Remove username', 'author_name': 'Geremia Taglialatela', 'lang': 'rb'}