Skip to content

Commit ac41dc7

Browse files
committed
Adding jquery and the useradd spec
1 parent 6ee7d67 commit ac41dc7

9 files changed

Lines changed: 283 additions & 7 deletions

File tree

chef-server/lib/controllers/nodes.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ def show
3535
rescue Net::HTTPServerException => e
3636
raise NotFound, "Cannot load node #{params[:id]}"
3737
end
38+
3839
display @node
3940
end
4041

1.52 KB
Loading
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//
2+
// Author:: Adam Jacob (<adam@hjksolutions.com>)
3+
// Copyright:: Copyright (c) 2008 HJK Solutions, LLC
4+
// License:: Apache License, Version 2.0
5+
//
6+
// Licensed under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
//
18+
19+
// $(document).ready(function() {
20+
// $(".edit_area").editable(location.href + ".json", {
21+
// type : 'textarea',
22+
// cancel : 'Cancel',
23+
// submit : 'Save',
24+
// indicator : "<img src='/images/indicator.gif'>",
25+
// target : location.href + ".json",
26+
// loadtype : "GET",
27+
// loadurl : location.href + ".json?pretty=true",
28+
// tooltip : 'Click to edit...'
29+
// });
30+
// });

chef-server/lib/public/jquery/jquery-1.2.6.min.js

Lines changed: 32 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

chef-server/lib/public/jquery/jquery.jeditable.mini.js

Lines changed: 30 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

chef-server/lib/views/layout/application.html.haml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
%title Chef Server
66
%meta{"http-equiv" => "content-type", :content => "text/html; charset=utf-8" }
77
%link{:rel => "stylesheet", :href => "/stylesheets/master.css", :type => "text/css", :media => "screen", :charset => "utf-8" }
8+
%script{:type => "text/javascript", :src => "/jquery/jquery-1.2.6.min.js" }
9+
%script{:type => "text/javascript", :src => "/jquery/jquery.jeditable.mini.js" }
10+
%script{:type => "text/javascript", :src => "/javascript/chef.js" }
811
%body
912
.header
1013
%a{:href => url(:searches) } Search
Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
.node
22
%h1
33
= "Node #{h node.name}"
4-
%h2 Recipes
5-
%ol
6-
= recipe_list(node)
7-
%h2 Attributes
8-
%ol
9-
= attribute_list(node)
4+
%div.edit_area#node{:to_update => node.name}
5+
%h2 Recipes
6+
%ol
7+
= recipe_list(node)
8+
%h2 Attributes
9+
%ol
10+
= attribute_list(node)

chef/lib/chef/provider/user/useradd.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def set_options
6060
'shell' => "-s",
6161
'password' => "-p"
6262
}
63-
field_list.each do |field, option|
63+
field_list.sort{ |a,b| a[0] <=> b[0] }.each do |field, option|
6464
field_symbol = field.to_sym
6565
if @current_resource.send(field_symbol) != @new_resource.send(field_symbol)
6666
if @new_resource.send(field_symbol)
Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
#
2+
# Author:: Adam Jacob (<adam@hjksolutions.com>)
3+
# Copyright:: Copyright (c) 2008 HJK Solutions, LLC
4+
# License:: Apache License, Version 2.0
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
#
18+
19+
require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "..", "spec_helper"))
20+
21+
describe Chef::Provider::User::Useradd, "set_options" do
22+
before(:each) do
23+
@node = mock("Chef::Node", :null_object => true)
24+
@new_resource = mock("Chef::Resource::User",
25+
:null_object => true,
26+
:username => "adam",
27+
:comment => "Adam Jacob",
28+
:uid => 1000,
29+
:gid => 1000,
30+
:home => "/home/adam",
31+
:shell => "/usr/bin/zsh",
32+
:password => "abracadabra",
33+
:updated => nil
34+
)
35+
@current_resource = mock("Chef::Resource::User",
36+
:null_object => true,
37+
:username => "adam",
38+
:comment => "Adam Jacob",
39+
:uid => 1000,
40+
:gid => 1000,
41+
:home => "/home/adam",
42+
:shell => "/usr/bin/zsh",
43+
:password => "abracadabra",
44+
:updated => nil
45+
)
46+
@provider = Chef::Provider::User::Useradd.new(@node, @new_resource)
47+
@provider.current_resource = @current_resource
48+
end
49+
50+
field_list = {
51+
'comment' => "-c",
52+
'home' => "-d",
53+
'gid' => "-g",
54+
'uid' => "-u",
55+
'shell' => "-s",
56+
'password' => "-p"
57+
}
58+
field_list.each do |attribute, option|
59+
it "should check for differences in #{attribute} between the new and current resources" do
60+
@current_resource.should_receive(attribute)
61+
@new_resource.should_receive(attribute)
62+
@provider.set_options
63+
end
64+
65+
it "should set the option for #{attribute} if the new resources #{attribute} is not null" do
66+
@new_resource.stub!(attribute).and_return("hola")
67+
@provider.set_options.should eql(" #{option} '#{@new_resource.send(attribute)}' -m #{@new_resource.username}")
68+
end
69+
70+
it "should set the option for #{attribute} if the new resources #{attribute} is not null, without homedir management" do
71+
@new_resource.stub!(:supports).and_return({:manage_home => false})
72+
@new_resource.stub!(attribute).and_return("hola")
73+
@provider.set_options.should eql(" #{option} '#{@new_resource.send(attribute)}' #{@new_resource.username}")
74+
end
75+
end
76+
77+
it "should combine all the possible options" do
78+
match_string = ""
79+
field_list.sort{ |a,b| a[0] <=> b[0] }.each do |attribute, option|
80+
@new_resource.stub!(attribute).and_return("hola")
81+
match_string << " #{option} 'hola'"
82+
end
83+
match_string << " -m adam"
84+
@provider.set_options.should eql(match_string)
85+
end
86+
87+
it "should use -m unless the operating system is a redhat descendent" do
88+
@node.stub!(:[]).with(:operatingsystem).and_return("Debian")
89+
@provider.set_options.should eql(" -m adam")
90+
end
91+
92+
it "should use -M if the operating system is a redhat descendent" do
93+
@node.stub!(:[]).with(:operatingsystem).and_return("RedHat")
94+
@provider.set_options.should eql(" -M adam")
95+
end
96+
end
97+
98+
describe Chef::Provider::User::Useradd, "create_user" do
99+
before(:each) do
100+
@node = mock("Chef::Node", :null_object => true)
101+
@new_resource = mock("Chef::Resource::User", :null_object => true)
102+
@provider = Chef::Provider::User::Useradd.new(@node, @new_resource)
103+
@provider.stub!(:set_options).and_return(" monkey")
104+
end
105+
106+
it "should run useradd with the return of set_options" do
107+
@provider.should_receive(:run_command).with({ :command => "useradd monkey" }).and_return(true)
108+
@provider.create_user
109+
end
110+
end
111+
112+
describe Chef::Provider::User::Useradd, "manage_user" do
113+
before(:each) do
114+
@node = mock("Chef::Node", :null_object => true)
115+
@new_resource = mock("Chef::Resource::User", :null_object => true)
116+
@provider = Chef::Provider::User::Useradd.new(@node, @new_resource)
117+
@provider.stub!(:set_options).and_return(" monkey")
118+
end
119+
120+
it "should run usermod with the return of set_options" do
121+
@provider.should_receive(:run_command).with({ :command => "usermod monkey" }).and_return(true)
122+
@provider.manage_user
123+
end
124+
end
125+
126+
describe Chef::Provider::User::Useradd, "remove_user" do
127+
before(:each) do
128+
@node = mock("Chef::Node", :null_object => true)
129+
@new_resource = mock("Chef::Resource::User",
130+
:null_object => true,
131+
:username => "adam",
132+
:supports => { :manage_home => false }
133+
)
134+
@provider = Chef::Provider::User::Useradd.new(@node, @new_resource)
135+
end
136+
137+
it "should run userdel with the new resources user name" do
138+
@provider.should_receive(:run_command).with({ :command => "userdel #{@new_resource.username}" }).and_return(true)
139+
@provider.remove_user
140+
end
141+
142+
it "should run userdel with the new resources user name and -r if manage_home is true" do
143+
@new_resource.stub!(:supports).and_return({ :manage_home => true })
144+
@provider.should_receive(:run_command).with({ :command => "userdel -r #{@new_resource.username}"}).and_return(true)
145+
@provider.remove_user
146+
end
147+
end
148+
149+
describe Chef::Provider::User::Useradd, "lock_user" do
150+
before(:each) do
151+
@node = mock("Chef::Node", :null_object => true)
152+
@new_resource = mock("Chef::Resource::User",
153+
:null_object => true,
154+
:username => "adam"
155+
)
156+
@provider = Chef::Provider::User::Useradd.new(@node, @new_resource)
157+
end
158+
159+
it "should run usermod -L with the new resources username" do
160+
@provider.should_receive(:run_command).with({ :command => "usermod -L #{@new_resource.username}"})
161+
@provider.lock_user
162+
end
163+
end
164+
165+
describe Chef::Provider::User::Useradd, "unlock_user" do
166+
before(:each) do
167+
@node = mock("Chef::Node", :null_object => true)
168+
@new_resource = mock("Chef::Resource::User",
169+
:null_object => true,
170+
:username => "adam"
171+
)
172+
@provider = Chef::Provider::User::Useradd.new(@node, @new_resource)
173+
end
174+
175+
it "should run usermod -L with the new resources username" do
176+
@provider.should_receive(:run_command).with({ :command => "usermod -U #{@new_resource.username}"})
177+
@provider.unlock_user
178+
end
179+
end

0 commit comments

Comments
 (0)