summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/chef/provider/user.rb12
-rw-r--r--spec/unit/provider/user_spec.rb50
2 files changed, 29 insertions, 33 deletions
diff --git a/lib/chef/provider/user.rb b/lib/chef/provider/user.rb
index e815ba9c9e..78aedd1b30 100644
--- a/lib/chef/provider/user.rb
+++ b/lib/chef/provider/user.rb
@@ -79,9 +79,7 @@ class Chef
end
end
- if @new_resource.gid
- convert_group_name
- end
+ convert_group_name if @new_resource.gid
end
@current_resource
@@ -112,9 +110,15 @@ class Chef
# <true>:: If a change is required
# <false>:: If the users are identical
def compare_user
- [ :uid, :gid, :comment, :home, :shell, :password ].any? do |user_attrib|
+ changed = [ :comment, :home, :shell, :password ].keep_if do |user_attrib|
!@new_resource.send(user_attrib).nil? && @new_resource.send(user_attrib) != @current_resource.send(user_attrib)
end
+
+ changed += [ :uid, :gid ].keep_if do |user_attrib|
+ !@new_resource.send(user_attrib).nil? && @new_resource.send(user_attrib).to_i != @current_resource.send(user_attrib).to_i
+ end
+
+ changed.any?
end
def action_create
diff --git a/spec/unit/provider/user_spec.rb b/spec/unit/provider/user_spec.rb
index 0b3d000b4b..8b1e0a54f4 100644
--- a/spec/unit/provider/user_spec.rb
+++ b/spec/unit/provider/user_spec.rb
@@ -184,42 +184,34 @@ describe Chef::Provider::User do
end
describe "compare_user" do
- before(:each) do
- # @node = Chef::Node.new
- # @new_resource = mock("Chef::Resource::User",
- # :null_object => true,
- # :username => "adam",
- # :comment => "Adam Jacob",
- # :uid => 1000,
- # :gid => 1000,
- # :home => "/home/adam",
- # :shell => "/usr/bin/zsh",
- # :password => nil,
- # :updated => nil
- # )
- # @current_resource = mock("Chef::Resource::User",
- # :null_object => true,
- # :username => "adam",
- # :comment => "Adam Jacob",
- # :uid => 1000,
- # :gid => 1000,
- # :home => "/home/adam",
- # :shell => "/usr/bin/zsh",
- # :password => nil,
- # :updated => nil
- # )
- # @provider = Chef::Provider::User.new(@node, @new_resource)
- # @provider.current_resource = @current_resource
- end
+ let(:mapping) {
+ {
+ 'username' => ["adam", "Adam"],
+ 'comment' => ["Adam Jacob", "adam jacob"],
+ 'uid' => [1000, 1001],
+ 'gid' => [1000, 1001],
+ 'home' => ["/home/adam", "/Users/adam"],
+ 'shell'=> ["/usr/bin/zsh", "/bin/bash"],
+ 'password'=> ["abcd","12345"]
+ }
+ }
%w{uid gid comment home shell password}.each do |attribute|
it "should return true if #{attribute} doesn't match" do
- @new_resource.should_receive(attribute).exactly(2).times.and_return(true)
- @current_resource.should_receive(attribute).once.and_return(false)
+ @new_resource.send(attribute, mapping[attribute][0])
+ @current_resource.send(attribute, mapping[attribute][1])
@provider.compare_user.should eql(true)
end
end
+ %w{uid gid}.each do |attribute|
+ it "should return false if string #{attribute} matches fixnum" do
+ @new_resource.send(attribute, "100")
+ @current_resource.send(attribute, 100)
+ @provider.compare_user.should eql(false)
+ end
+ end
+
it "should return false if the objects are identical" do
@provider.compare_user.should eql(false)
end