Skip to content

Commit

Permalink
Add User#receive_system_mail
Browse files Browse the repository at this point in the history
  • Loading branch information
joseivanlopez committed Sep 24, 2021
1 parent 3c68224 commit e786aaf
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/lib/y2users/user.rb
Expand Up @@ -95,10 +95,15 @@ class User < ConfigElement
# @return [Array<String>]
attr_accessor :authorized_keys

# Whether the user should receive system mails (i.e., be a root alias)
#
# @return [Boolean]
attr_accessor :receive_system_mail

# Only relevant attributes are compared. For example, the config in which the user is attached
# and the internal user id are not considered.
eql_attr :name, :uid, :gid, :shell, :home, :gecos, :source, :password, :authorized_keys,
:secondary_groups_name
:receive_system_mail, :secondary_groups_name

# Creates a prototype root user
#
Expand Down Expand Up @@ -236,6 +241,13 @@ def system=(value)
@system = value
end

# @see receive_system_mail
#
# @return [Boolean]
def receive_system_mail?
!!@receive_system_mail
end

# Generates a deep copy of the user
#
# @see ConfigElement#copy
Expand Down
41 changes: 41 additions & 0 deletions test/lib/y2users/user_test.rb
Expand Up @@ -340,6 +340,7 @@
subject.home = Y2Users::Home.new("/home/test1")
subject.gecos = ["User Test1", "Other"]
subject.source = [:ldap]
subject.receive_system_mail = true
subject.password = Y2Users::Password.create_plain("S3cr3T")
end

Expand Down Expand Up @@ -421,6 +422,16 @@
end
end

context "when #receive_system_mail does not match" do
before do
other.receive_system_mail = false
end

it "returns false" do
expect(subject == other).to eq(false)
end
end

context "when the #password does not match" do
before do
other.password.value.content = "M0r3-S3cr3T"
Expand Down Expand Up @@ -585,6 +596,36 @@
end
end

describe "#receive_system_mail?" do
before do
subject.receive_system_mail = value
end

context "when the value is set to nil" do
let(:value) { nil }

it "returns false" do
expect(subject.receive_system_mail?).to eq(false)
end
end

context "when the value is set to false" do
let(:value) { false }

it "returns false" do
expect(subject.receive_system_mail?).to eq(false)
end
end

context "when the value is set to true" do
let(:value) { true }

it "returns true" do
expect(subject.receive_system_mail?).to eq(true)
end
end
end

describe "#issues" do
let(:user_validator) { instance_double(Y2Users::UserValidator, issues: Y2Issues::List.new) }

Expand Down

0 comments on commit e786aaf

Please sign in to comment.