Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

973 B
Raw Blame
# frozen_string_literal: true

require_relative "../spec_helper"
require_relative "../shared_examples"

RSpec.describe User do
  let(:user) { build(:user) }

  include_examples "there are users with and without avatars"

  specify { expect(user.attachments).to all be_a Attachment }

  describe "#local_avatar_attachment" do
    subject { user.local_avatar_attachment }

    context "when user has an avatar" do
      let(:user) { user_with_avatar }

      it { is_expected.to be_a Attachment }
    end

    context "when user has no avatar" do
      let(:user) { user_without_avatar }

      it { is_expected.to be_blank }
    end
  end

  describe "#local_avatar_attachment=" do
    context "when the uploaded file is a good image" do
      subject { lambda { user.local_avatar_attachment = avatar_file } }

      specify { expect { subject.call }.not_to raise_error }
      specify { expect { subject.call }.to change(user, :local_avatar_attachment) }
    end
  end
end