Feature #170 » patch-squashed.diff
.gitmodules | ||
---|---|---|
[submodule "extras/puppet"]
|
||
path = extras/puppet
|
||
url = git://github.com/ohadlevy/puppet-foreman.git
|
||
[submodule "vendor/plugins/has_many_polymorphs"]
|
||
path = vendor/plugins/has_many_polymorphs
|
||
url = git://github.com/fauna/has_many_polymorphs.git
|
app/controllers/usergroups_controller.rb | ||
---|---|---|
class UsergroupsController < ApplicationController
|
||
def index
|
||
@usergroups = Usergroup.all
|
||
end
|
||
def new
|
||
@usergroup = Usergroup.new
|
||
end
|
||
def create
|
||
@usergroup = Usergroup.new(params[:usergroup])
|
||
if @usergroup.save
|
||
flash[:foreman_notice] = "Successfully created usergroup."
|
||
redirect_to usergroups_path
|
||
else
|
||
render :action => 'new'
|
||
end
|
||
end
|
||
def edit
|
||
@usergroup = Usergroup.find(params[:id])
|
||
end
|
||
def update
|
||
@usergroup = Usergroup.find(params[:id])
|
||
if @usergroup.update_attributes(params[:usergroup])
|
||
flash[:foreman_notice] = "Successfully updated usergroup."
|
||
redirect_to usergroups_path
|
||
else
|
||
render :action => 'edit'
|
||
end
|
||
end
|
||
def destroy
|
||
@usergroup = Usergroup.find(params[:id])
|
||
if @usergroup.destroy
|
||
flash[:foreman_notice] = "Successfully destroyed usergroup."
|
||
else
|
||
logger.error @usergroup.errors.full_messages
|
||
flash[:foreman_error] = @usergroup.errors.full_messages.join "<br>"
|
||
end
|
||
redirect_to usergroups_path
|
||
end
|
||
end
|
app/controllers/users_controller.rb | ||
---|---|---|
columns[:firstname].label = "First name"
|
||
columns[:lastname].label = "Surname"
|
||
columns[:admin].label = "Admin"
|
||
config.columns = [:firstname, :lastname, :login, :mail, :admin, :auth_source, :last_login_on]
|
||
config.columns = [:firstname, :lastname, :login, :mail, :admin, :auth_source, :usergroups, :last_login_on]
|
||
config.update.columns = [:firstname, :lastname, :login, :mail, :admin, :auth_source, :last_login_on]
|
||
config.columns[:auth_source].form_ui = :select
|
||
config.columns[:admin].form_ui = :checkbox
|
||
config.columns[:usergroups].clear_link
|
||
list.sorting = {:last_login_on => 'DESC' }
|
||
config.update.columns.exclude :last_login_on
|
||
end
|
app/helpers/application_helper.rb | ||
---|---|---|
end
|
||
def edit_habtm klass, association
|
||
render :partial => 'common/edit_habtm', :locals =>{ :klass => klass, :associations => association.all}
|
||
render :partial => 'common/edit_habtm', :locals =>{ :klass => klass, :associations => association.all.delete_if{|e| e == klass}}
|
||
end
|
||
def link_to_remove_fields(name, f)
|
app/helpers/usergroups_helper.rb | ||
---|---|---|
module UsergroupsHelper
|
||
end
|
app/models/host.rb | ||
---|---|---|
has_many :reports, :dependent => :destroy
|
||
has_many :host_parameters, :dependent => :destroy
|
||
accepts_nested_attributes_for :host_parameters, :reject_if => lambda { |a| a[:value].blank? }, :allow_destroy => true
|
||
belongs_to :owner, :polymorphic => true
|
||
named_scope :recent, lambda { |*args| {:conditions => ["last_report > ?", (args.first || (SETTINGS[:run_interval] + 5.minutes).ago)]} }
|
||
named_scope :out_of_sync, lambda { |*args| {:conditions => ["last_report < ?", (args.first || (SETTINGS[:run_interval] + 5.minutes).ago)]} }
|
||
... | ... | |
before_validation :normalize_addresses, :normalize_hostname
|
||
def <=>(other)
|
||
self.name <=> other.name
|
||
end
|
||
# Returns the name of this host as a string
|
||
# String: the host's name
|
||
def to_label
|
||
... | ... | |
20
|
||
end
|
||
# method to return the correct owner list for host edit owner select dropbox
|
||
def is_owned_by
|
||
owner.id_and_type if owner
|
||
end
|
||
# virtual attributes which sets the owner based on the user selection
|
||
# supports a simple user, or a usergroup
|
||
# selection parameter is expected to be an ActiveRecord id_and_type method (see Foreman's AR extentions).
|
||
def is_owned_by=(selection)
|
||
oid = nil
|
||
oid = User.find(selection.to_i) if selection =~ /-Users$/
|
||
oid = Usergroup.find(selection.to_i) if selection =~ /-Usergroups$/
|
||
self.owner = oid
|
||
end
|
||
def clearReports
|
||
# Remove any reports that may be held against this host
|
||
Report.delete_all("host_id = #{self.id}")
|
app/models/host_mailer.rb | ||
---|---|---|
def error_state(report)
|
||
host = report.host
|
||
email = SETTINGS[:administrator]
|
||
email = host.owner.recipients if SETTINGS[:ldap] and not host.owner.empty?
|
||
email ||= SETTINGS[:administrator]
|
||
raise "unable to find recipients" if email.empty?
|
||
recipients email
|
||
from "Foreman-noreply"
|
app/models/user.rb | ||
---|---|---|
class User < ActiveRecord::Base
|
||
belongs_to :auth_source
|
||
has_many :changes, :class_name => 'Audit', :as => :user
|
||
has_many :hosts
|
||
has_many :usergroups, :through => :usergroup_member
|
||
has_many :direct_hosts, :as => :owner, :class_name => "Host"
|
||
validates_uniqueness_of :login, :message => "already exists"
|
||
validates_presence_of :login, :mail
|
||
... | ... | |
validates_format_of :mail, :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i, :allow_nil => true
|
||
validates_length_of :mail, :maximum => 60, :allow_nil => true
|
||
before_destroy Ensure_not_used_by.new(:hosts)
|
||
def to_label
|
||
"#{firstname} #{lastname}"
|
||
end
|
||
alias_method :to_s, :to_label
|
||
alias_method :name, :to_label
|
||
def <=>(other)
|
||
self.name <=> other.name
|
||
end
|
||
# The text item to see in a select dropdown menu
|
||
def select_title
|
||
name + " (#{login})"
|
||
end
|
||
def self.try_to_login(login, password)
|
||
# Make sure no one can sign in with an empty password
|
||
... | ... | |
raise text
|
||
end
|
||
def indirect_hosts
|
||
all_groups = []
|
||
for usergroup in usergroups
|
||
all_groups += usergroup.all_usergroups
|
||
end
|
||
all_groups.uniq.map{|g| g.hosts}.flatten.uniq
|
||
end
|
||
def hosts
|
||
direct_hosts + indirect_hosts
|
||
end
|
||
def recipients
|
||
[mail]
|
||
end
|
||
protected
|
||
def validate
|
||
if Usergroup.all.map(&:name).include?(self.login)
|
||
errors.add_to_base "A usergroup already exists with this name"
|
||
end
|
||
end
|
||
end
|
app/models/usergroup.rb | ||
---|---|---|
class Usergroup < ActiveRecord::Base
|
||
has_many_polymorphs :members, :from => [:usergroups, :users ], :as => :member,
|
||
:through => :usergroup_member, :foreign_key => :usergroup_id, :dependent => :destroy
|
||
has_many :hosts, :as => :owner
|
||
validates_uniqueness_of :name
|
||
before_destroy Ensure_not_used_by.new(:hosts, :usergroups)
|
||
def to_s
|
||
name
|
||
end
|
||
# The text item to see in a select dropdown menu
|
||
alias_method :select_title, :to_s
|
||
# Support for sorting the groups by name
|
||
def <=>(other)
|
||
self.name <=> other.name
|
||
end
|
||
# This methods retrieves all user addresses in a usergroup
|
||
# Returns: Array of strings representing the user's email addresses
|
||
def recipients
|
||
all_users.map(&:mail)
|
||
end
|
||
# This methods retrieves all users in a usergroup
|
||
# Returns: Array of users
|
||
def all_users(group_list=[self], user_list=[])
|
||
retrieve_users_and_groups group_list, user_list
|
||
user_list.sort.uniq
|
||
end
|
||
# This methods retrieves all usergroups in a usergroup
|
||
# Returns: Array of usergroups
|
||
def all_usergroups(group_list=[self], user_list=[])
|
||
retrieve_users_and_groups group_list, user_list
|
||
group_list.sort.uniq
|
||
end
|
||
protected
|
||
# Recurses down the tree of usergroups and finds the users
|
||
# [+group_list+]: Array of Usergroups that have already been processed
|
||
# [+users+] : Array of users accumulated at this point
|
||
# Returns : Array of non unique users
|
||
def retrieve_users_and_groups(group_list, user_list)
|
||
for group in usergroups
|
||
next if group_list.include? group
|
||
group_list << group
|
||
group.retrieve_users_and_groups(group_list, user_list)
|
||
end
|
||
user_list.concat users
|
||
end
|
||
def validate
|
||
if User.all.map(&:login).include?(self.name)
|
||
errors.add :name, "is already used by a user account"
|
||
end
|
||
end
|
||
end
|
app/models/usergroup_member.rb | ||
---|---|---|
class UsergroupMember < ActiveRecord::Base
|
||
belongs_to :member, :polymorphic => true
|
||
belongs_to :usergroup
|
||
end
|
app/views/home/settings.erb | ||
---|---|---|
<li><%= link_to 'Global Parameters', common_parameters_path %> </li>
|
||
<li><%= link_to "External Variables", lookup_keys_path %> </li>
|
||
<li><%= link_to 'LDAP Authentication', auth_source_ldaps_path %> </li>
|
||
<li><%= link_to_if SETTINGS[:ldap], 'Users', users_path %> </li>
|
||
<li><%= link_to_if SETTINGS[:ldap], 'Users', users_path %> </li>
|
||
<li><%= link_to_if SETTINGS[:ldap], 'Usergroups', usergroups_path %> </li>
|
||
</ul>
|
||
</div>
|
app/views/hosts/_form.html.erb | ||
---|---|---|
<td>Puppetmaster</td>
|
||
<td><%= f.text_field :puppetmaster, :size => 10, :value => @host.puppetmaster %></td>
|
||
<td><%= link_to_function "Additional Classes", toggle_div(:classlist) %></td>
|
||
<% if SETTINGS[:ldap] -%>
|
||
<td>Owned by</td>
|
||
<td>
|
||
<%= f.select :is_owned_by,
|
||
option_groups_from_collection_for_select( [ User, Usergroup], :all, :table_name, :id_and_type, :select_title, @host.is_owned_by),
|
||
:include_blank => "select an owner" %>
|
||
</td>
|
||
<% end -%>
|
||
</tr>
|
||
</table>
|
||
app/views/usergroups/_form.html.erb | ||
---|---|---|
<% form_for @usergroup do |f| %>
|
||
<%= f.error_messages %>
|
||
<table>
|
||
<tr>
|
||
<td>Name</td>
|
||
<td><%= f.text_field :name %></td>
|
||
</tr>
|
||
<tr>
|
||
<td>User groups</td>
|
||
<td><%= edit_habtm @usergroup, Usergroup %></td>
|
||
</tr>
|
||
<tr>
|
||
<td>Users</td>
|
||
<td><%= edit_habtm @usergroup, User %></td>
|
||
</tr>
|
||
<tr><td><%= f.submit "Submit" %></td></tr>
|
||
</table>
|
||
<% end %>
|
app/views/usergroups/edit.html.erb | ||
---|---|---|
<% title "Edit Usergroup" %>
|
||
<%= render :partial => 'form' %>
|
||
<p>
|
||
<%= link_to "View All", usergroups_path %>
|
||
</p>
|
app/views/usergroups/index.html.erb | ||
---|---|---|
<% title "Usergroups" %>
|
||
<table class="list">
|
||
<tr>
|
||
<th>Name</th>
|
||
<th>Users</th>
|
||
<th>User Groups</th>
|
||
<th></th>
|
||
</tr>
|
||
<% for usergroup in @usergroups %>
|
||
<tr class="<%= cycle("even", "odd") -%>">
|
||
<td><%= link_to h(usergroup.name), edit_usergroup_path(usergroup) %></td>
|
||
<td><%= usergroup.users.map(&:login).to_sentence %></td>
|
||
<td><%= usergroup.usergroups.map(&:name).to_sentence %></td>
|
||
<td align="right">
|
||
<%= link_to "Destroy", usergroup, :confirm => 'Are you sure?', :method => :delete %>
|
||
</td>
|
||
</tr>
|
||
<% end %>
|
||
</table>
|
||
<p><%= link_to "New Usergroup", new_usergroup_path %></p>
|
app/views/usergroups/new.html.erb | ||
---|---|---|
<% title "New Usergroup" %>
|
||
<%= render :partial => 'form' %>
|
||
<p><%= link_to "Back to List", usergroups_path %></p>
|
config/initializers/foreman.rb | ||
---|---|---|
end
|
||
end
|
||
end
|
||
def id_and_type
|
||
"#{id}-#{self.class.table_name.humanize}"
|
||
end
|
||
end
|
||
module ExemptedFromLogging
|
config/routes.rb | ||
---|---|---|
ActionController::Routing::Routes.draw do |map|
|
||
map.resources :usergroups
|
||
map.root :controller => "hosts"
|
||
map.connect "node/:name", :controller => 'hosts', :action => 'externalNodes',
|
db/migrate/20100416124600_create_usergroups.rb | ||
---|---|---|
class CreateUsergroups < ActiveRecord::Migration
|
||
def self.up
|
||
create_table :usergroups do |t|
|
||
t.string :name
|
||
t.timestamps
|
||
end
|
||
create_table :usergroup_members do |t|
|
||
t.references :member, :polymorphic => true
|
||
t.references :usergroup
|
||
end
|
||
end
|
||
def self.down
|
||
drop_table :members
|
||
drop_table :usergroups
|
||
end
|
||
end
|
db/migrate/20100419151910_add_owner_to_hosts.rb | ||
---|---|---|
class AddOwnerToHosts < ActiveRecord::Migration
|
||
def self.up
|
||
add_column :hosts, :owner_id, :integer
|
||
add_column :hosts, :owner_type, :string
|
||
Host.reset_column_information
|
||
updated = []
|
||
owner = User.find_or_create_by_login(:login => "admin", :admin => true, :firstname => "Admin", :lastname => "User", :mail => "root@" + Facter.domain)
|
||
say "setting default owner for all hosts"
|
||
Host.update_all("owner_id = '#{owner.id}'")
|
||
end
|
||
def self.down
|
||
remove_column :hosts, :owner_type
|
||
remove_column :hosts, :owner_id
|
||
end
|
||
end
|
test/fixtures/usergroups.yml | ||
---|---|---|
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
|
||
one:
|
||
name: MyString
|
||
two:
|
||
name: MyString
|
test/fixtures/users.yml | ||
---|---|---|
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
|
||
one:
|
||
login: MyString
|
||
firstname: MyString
|
||
lastname: MyString
|
||
login: one
|
||
firstname: One
|
||
lastname: User
|
||
mail: MyString
|
||
admin: false
|
||
last_login_on: 2009-10-12 21:50:04
|
||
auth_source_id: 1
|
||
two:
|
||
login: MyString
|
||
firstname: MyString
|
||
lastname: MyString
|
||
login: two
|
||
firstname: Two
|
||
lastname: User
|
||
mail: MyString
|
||
admin: false
|
||
last_login_on: 2009-10-12 21:50:04
|
test/functional/architectures_controller_test.rb | ||
---|---|---|
class ArchitecturesControllerTest < ActionController::TestCase
|
||
def test_index
|
||
get :index
|
||
get :index, {}, set_session_user
|
||
assert_template 'index'
|
||
end
|
||
def test_new
|
||
get :new
|
||
get :new, {}, set_session_user
|
||
assert_template 'new'
|
||
end
|
||
def test_create_invalid
|
||
Architecture.any_instance.stubs(:valid?).returns(false)
|
||
post :create
|
||
post :create, {}, set_session_user
|
||
assert_template 'new'
|
||
end
|
||
def test_create_valid
|
||
Architecture.any_instance.stubs(:valid?).returns(true)
|
||
post :create
|
||
post :create, {}, set_session_user
|
||
assert_redirected_to architectures_url
|
||
end
|
||
def test_edit
|
||
get :edit, :id => Architecture.first
|
||
get :edit, {:id => Architecture.first}, set_session_user
|
||
assert_template 'edit'
|
||
end
|
||
def test_update_invalid
|
||
Architecture.any_instance.stubs(:valid?).returns(false)
|
||
put :update, :id => Architecture.first
|
||
put :update, {:id => Architecture.first}, set_session_user
|
||
assert_template 'edit'
|
||
end
|
||
def test_update_valid
|
||
Architecture.any_instance.stubs(:valid?).returns(true)
|
||
put :update, :id => Architecture.first
|
||
put :update, {:id => Architecture.first}, set_session_user
|
||
assert_redirected_to architectures_url
|
||
end
|
||
def test_destroy
|
||
architecture = Architecture.first
|
||
delete :destroy, :id => architecture
|
||
delete :destroy, {:id => architecture}, set_session_user
|
||
assert_redirected_to architectures_url
|
||
assert !Architecture.exists?(architecture.id)
|
||
end
|
test/functional/audit_controller_test.rb | ||
---|---|---|
class AuditControllerTest < ActionController::TestCase
|
||
test "should get index" do
|
||
get :index
|
||
get :index, {}, set_session_user
|
||
assert_response :success
|
||
assert_not_nil assigns(:records)
|
||
end
|
||
test "should get search" do
|
||
get :show_search
|
||
get :show_search, {}, set_session_user
|
||
assert_response :success
|
||
end
|
||
... | ... | |
audited_record = Audit.find_by_auditable_id(parameter.id)
|
||
assert_not_nil audited_record
|
||
get :show, :id => audited_record.id
|
||
get :show, {:id => audited_record.id}, set_session_user
|
||
assert_response :success
|
||
end
|
||
end
|
test/functional/auth_source_ldaps_controller_test.rb | ||
---|---|---|
class AuthSourceLdapsControllerTest < ActionController::TestCase
|
||
def test_index
|
||
get :index
|
||
get :index, {}, set_session_user
|
||
assert_template 'index'
|
||
end
|
||
def test_new
|
||
get :new
|
||
get :new, {}, set_session_user
|
||
assert_template 'new'
|
||
end
|
||
def test_create_invalid
|
||
AuthSourceLdap.any_instance.stubs(:valid?).returns(false)
|
||
post :create
|
||
post :create, {}, set_session_user
|
||
assert_template 'new'
|
||
end
|
||
def test_create_valid
|
||
AuthSourceLdap.any_instance.stubs(:valid?).returns(true)
|
||
post :create
|
||
post :create, {}, set_session_user
|
||
assert_redirected_to auth_source_ldaps_url
|
||
end
|
||
def test_edit
|
||
get :edit, :id => AuthSourceLdap.first
|
||
get :edit, {:id => AuthSourceLdap.first}, set_session_user
|
||
assert_template 'edit'
|
||
end
|
||
def test_update_invalid
|
||
AuthSourceLdap.any_instance.stubs(:valid?).returns(false)
|
||
put :update, :id => AuthSourceLdap.first
|
||
put :update, {:id => AuthSourceLdap.first}, set_session_user
|
||
assert_template 'edit'
|
||
end
|
||
def test_update_valid
|
||
AuthSourceLdap.any_instance.stubs(:valid?).returns(true)
|
||
put :update, :id => AuthSourceLdap.first
|
||
put :update, {:id => AuthSourceLdap.first}, set_session_user
|
||
assert_redirected_to auth_source_ldaps_url
|
||
end
|
||
def test_destroy
|
||
auth_source_ldap = AuthSourceLdap.first
|
||
delete :destroy, :id => auth_source_ldap
|
||
delete :destroy, {:id => auth_source_ldap}, set_session_user
|
||
assert_redirected_to auth_source_ldaps_url
|
||
assert !AuthSourceLdap.exists?(auth_source_ldap.id)
|
||
end
|
test/functional/common_parameters_controller_test.rb | ||
---|---|---|
class CommonParametersControllerTest < ActionController::TestCase
|
||
def test_index
|
||
get :index
|
||
get :index, {}, set_session_user
|
||
assert_template 'index'
|
||
end
|
||
def test_new
|
||
get :new
|
||
get :new, {}, set_session_user
|
||
assert_template 'new'
|
||
end
|
||
def test_create_invalid
|
||
CommonParameter.any_instance.stubs(:valid?).returns(false)
|
||
post :create
|
||
post :create, {}, set_session_user
|
||
assert_template 'new'
|
||
end
|
||
def test_create_valid
|
||
CommonParameter.any_instance.stubs(:valid?).returns(true)
|
||
post :create
|
||
post :create, {}, set_session_user
|
||
assert_redirected_to common_parameters_url
|
||
end
|
||
def test_edit
|
||
get :edit, :id => CommonParameter.first
|
||
get :edit, {:id => CommonParameter.first}, set_session_user
|
||
assert_template 'edit'
|
||
end
|
||
def test_update_invalid
|
||
CommonParameter.any_instance.stubs(:valid?).returns(false)
|
||
put :update, :id => CommonParameter.first
|
||
put :update, {:id => CommonParameter.first}, set_session_user
|
||
assert_template 'edit'
|
||
end
|
||
def test_update_valid
|
||
CommonParameter.any_instance.stubs(:valid?).returns(true)
|
||
put :update, :id => CommonParameter.first
|
||
put :update, {:id => CommonParameter.first}, set_session_user
|
||
assert_redirected_to common_parameters_url
|
||
end
|
||
def test_destroy
|
||
common_parameter = CommonParameter.first
|
||
delete :destroy, :id => common_parameter
|
||
delete :destroy, {:id => common_parameter}, set_session_user
|
||
assert_redirected_to common_parameters_url
|
||
assert !CommonParameter.exists?(common_parameter.id)
|
||
end
|
test/functional/dashboard_controller_test.rb | ||
---|---|---|
class DashboardControllerTest < ActionController::TestCase
|
||
test "should get index" do
|
||
get :index
|
||
get :index, {}, set_session_user
|
||
assert_response :success
|
||
end
|
||
test "should get errors" do
|
||
get :errors
|
||
get :errors, {}, set_session_user
|
||
assert_response :success
|
||
assert_template :partial => "hosts/_minilist"
|
||
end
|
||
test "should get active" do
|
||
get :active
|
||
get :active, {}, set_session_user
|
||
assert_response :success
|
||
assert_template :partial => "hosts/_minilist"
|
||
end
|
||
test "should get out of sync" do
|
||
get :OutOfSync
|
||
get :OutOfSync, {}, set_session_user
|
||
assert_response :success
|
||
assert_template :partial => "hosts/_minilist"
|
||
end
|
test/functional/domains_controller_test.rb | ||
---|---|---|
class DomainsControllerTest < ActionController::TestCase
|
||
def test_index
|
||
get :index
|
||
get :index, {}, set_session_user
|
||
assert_template 'index'
|
||
end
|
||
def test_new
|
||
get :new
|
||
get :new, {}, set_session_user
|
||
assert_template 'new'
|
||
end
|
||
def test_create_invalid
|
||
Domain.any_instance.stubs(:valid?).returns(false)
|
||
post :create
|
||
post :create, {}, set_session_user
|
||
assert_template 'new'
|
||
end
|
||
def test_create_valid
|
||
Domain.any_instance.stubs(:valid?).returns(true)
|
||
post :create
|
||
post :create, {}, set_session_user
|
||
assert_redirected_to domains_url
|
||
end
|
||
def test_edit
|
||
get :edit, :id => Domain.first
|
||
get :edit, {:id => Domain.first}, set_session_user
|
||
assert_template 'edit'
|
||
end
|
||
def test_update_invalid
|
||
Domain.any_instance.stubs(:valid?).returns(false)
|
||
put :update, :id => Domain.first
|
||
put :update, {:id => Domain.first}, set_session_user
|
||
assert_template 'edit'
|
||
end
|
||
def test_update_valid
|
||
Domain.any_instance.stubs(:valid?).returns(true)
|
||
put :update, :id => Domain.first
|
||
put :update, {:id => Domain.first}, set_session_user
|
||
assert_redirected_to domains_url
|
||
end
|
||
def test_destroy
|
||
domain = Domain.first
|
||
delete :destroy, :id => domain
|
||
delete :destroy, {:id => domain}, set_session_user
|
||
assert_redirected_to domains_url
|
||
assert !Domain.exists?(domain.id)
|
||
end
|
test/functional/environments_controller_test.rb | ||
---|---|---|
end
|
||
test "should get index" do
|
||
get :index
|
||
get :index, {}, set_session_user
|
||
assert_response :success
|
||
assert_not_nil assigns(:records)
|
||
end
|
||
test "shuold get new" do
|
||
get :new
|
||
test "should get new" do
|
||
get :new, {}, set_session_user
|
||
assert_response :success
|
||
end
|
||
test "should create new environment" do
|
||
assert_difference 'Environment.count' do
|
||
post :create, { :commit => "Create", :record => {:name => "some_environment"} }
|
||
post :create, { :commit => "Create", :record => {:name => "some_environment"} }, set_session_user
|
||
end
|
||
assert_redirected_to environments_path
|
||
... | ... | |
environment = Environment.new :name => "some_environment"
|
||
assert environment.save!
|
||
get :edit, :id => environment.id
|
||
get :edit, {:id => environment.id}, set_session_user
|
||
assert_response :success
|
||
end
|
||
... | ... | |
environment = Environment.new :name => "some_environment"
|
||
assert environment.save!
|
||
put :update, { :commit => "Update", :id => environment.id, :record => {:name => "other_environment"} }
|
||
put :update, { :commit => "Update", :id => environment.id, :record => {:name => "other_environment"} }, set_session_user
|
||
environment = Environment.find_by_id(environment.id)
|
||
assert environment.name == "other_environment"
|
||
... | ... | |
assert environment.save!
|
||
assert_difference('Environment.count', -1) do
|
||
delete :destroy, :id => environment.id
|
||
delete :destroy, {:id => environment.id}, set_session_user
|
||
end
|
||
assert_redirected_to environments_path
|
test/functional/fact_values_controller_test.rb | ||
---|---|---|
class FactValuesControllerTest < ActionController::TestCase
|
||
test "should get list" do
|
||
get :list
|
||
get :list, {}, set_session_user
|
||
assert_response :success
|
||
assert_not_nil :records
|
||
end
|
||
test "should get list_filter" do
|
||
get :list_filter
|
||
get :list_filter, {}, set_session_user
|
||
assert_response :found
|
||
end
|
||
end
|
test/functional/home_controller_test.rb | ||
---|---|---|
class HomeControllerTest < ActionController::TestCase
|
||
test "should get settings" do
|
||
get :settings
|
||
get :settings, {}, set_session_user
|
||
assert_response :success
|
||
end
|
||
end
|
test/functional/hostgroups_controller_test.rb | ||
---|---|---|
class HostgroupsControllerTest < ActionController::TestCase
|
||
def test_index
|
||
get :index
|
||
get :index, {}, set_session_user
|
||
assert_template 'index'
|
||
end
|
||
def test_new
|
||
get :new
|
||
get :new, {}, set_session_user
|
||
assert_template 'new'
|
||
end
|
||
def test_create_invalid
|
||
Hostgroup.any_instance.stubs(:valid?).returns(false)
|
||
post :create
|
||
post :create, {}, set_session_user
|
||
assert_template 'new'
|
||
end
|
||
def test_create_valid
|
||
Hostgroup.any_instance.stubs(:valid?).returns(true)
|
||
pc = Puppetclass.first
|
||
post :create, "hostgroup" => {"name"=>"test_it", "group_parameters_attributes"=>{"1272344174448"=>{"name"=>"x", "value"=>"y", "_destroy"=>""}}, "puppetclass_ids"=>["", pc.id.to_s]}
|
||
post :create, {"hostgroup" => {"name"=>"test_it", "group_parameters_attributes"=>{"1272344174448"=>{"name"=>"x", "value"=>"y", "_destroy"=>""}}, "puppetclass_ids"=>["", pc.id.to_s]}}, set_session_user
|
||
assert_redirected_to hostgroups_url
|
||
end
|
||
def test_edit
|
||
get :edit, :id => Hostgroup.first
|
||
get :edit, {:id => Hostgroup.first}, set_session_user
|
||
assert_template 'edit'
|
||
end
|
||
def test_update_invalid
|
||
Hostgroup.any_instance.stubs(:valid?).returns(false)
|
||
put :update, :id => Hostgroup.first
|
||
put :update, {:id => Hostgroup.first}, set_session_user
|
||
assert_template 'edit'
|
||
end
|
||
def test_update_valid
|
||
Hostgroup.any_instance.stubs(:valid?).returns(true)
|
||
put :update, :id => Hostgroup.first
|
||
put :update, {:id => Hostgroup.first}, set_session_user
|
||
assert_redirected_to hostgroups_url
|
||
end
|
||
def test_destroy
|
||
hostgroup = Hostgroup.first
|
||
delete :destroy, :id => hostgroup
|
||
delete :destroy, {:id => hostgroup}, set_session_user
|
||
assert_redirected_to hostgroups_url
|
||
assert !Hostgroup.exists?(hostgroup.id)
|
||
end
|
test/functional/hosts_controller_test.rb | ||
---|---|---|
class HostsControllerTest < ActionController::TestCase
|
||
setup :initialize_host
|
||
def test_index
|
||
get :index
|
||
assert_template 'index'
|
||
end
|
||
def test_show
|
||
get :show, :id => Host.first
|
||
get :show, {:id => Host.first}, set_session_user
|
||
assert_template 'show'
|
||
end
|
||
def test_new
|
||
get :new
|
||
assert_template 'new'
|
||
end
|
||
def test_create_invalid
|
||
Host.any_instance.stubs(:valid?).returns(false)
|
||
post :create
|
||
post :create, {}, set_session_user
|
||
assert_template 'new'
|
||
end
|
||
def test_create_valid
|
||
Host.any_instance.stubs(:valid?).returns(true)
|
||
post :create, :host => {:name => "test"}
|
||
assert_redirected_to host_url(assigns(:host))
|
||
post :create, {:host => {:name => "test"}}, set_session_user
|
||
assert_redirected_to host_url(assigns('host'))
|
||
end
|
||
def test_edit
|
||
get :edit, :id => Host.first
|
||
test "should get index" do
|
||
get :index, {}, set_session_user
|
||
assert_response :success
|
||
assert_template 'index'
|
||
end
|
||
test "should get new" do
|
||
get :new, {}, set_session_user
|
||
assert_response :success
|
||
assert_template 'new'
|
||
end
|
||
test "should create new host" do
|
||
assert_difference 'Host.count' do
|
||
post :create, { :commit => "Create",
|
||
:host => {:name => "myotherfullhost",
|
||
:mac => "aabbecddee00",
|
||
:ip => "123.05.02.25",
|
||
:domain => Domain.find_or_create_by_name("othercompany.com"),
|
||
:operatingsystem => Operatingsystem.first,
|
||
:architecture => Architecture.first,
|
||
:environment => Environment.first,
|
||
:disk => "empty partition"
|
||
}
|
||
}, set_session_user
|
||
end
|
||
end
|
||
test "should get edit" do
|
||
get :edit, {:id => @host.id}, set_session_user
|
||
assert_response :success
|
||
assert_template 'edit'
|
||
end
|
||
test "should update host" do
|
||
put :update, { :commit => "Update", :id => @host.id, :host => {:disk => "ntfs"} }, set_session_user
|
||
@host = Host.find_by_id(@host.id)
|
||
assert_equal @host.disk, "ntfs"
|
||
end
|
||
def test_update_invalid
|
||
Host.any_instance.stubs(:valid?).returns(false)
|
||
put :update, :id => Host.first
|
||
put :update, {:id => Host.first}, set_session_user
|
||
assert_template 'edit'
|
||
end
|
||
def test_update_valid
|
||
Host.any_instance.stubs(:valid?).returns(true)
|
||
put :update, :id => Host.first
|
||
put :update, {:id => Host.first}, set_session_user
|
||
assert_redirected_to host_url(assigns(:host))
|
||
end
|
||
def test_destroy
|
||
host = Host.first
|
||
delete :destroy, :id => host
|
||
delete :destroy, {:id => host}, set_session_user
|
||
assert_redirected_to hosts_url
|
||
assert !Host.exists?(host.id)
|
||
end
|
||
test "externalNodes should render 404 when no params are given" do
|
||
get :externalNodes
|
||
test "externalNodes should render 404 when no params are given" do
|
||
get :externalNodes, {}, set_session_user
|
||
assert_response :missing
|
||
assert_template :text => '404 Not Found'
|
||
end
|
||
test "externalNodes should render correctly when id is given" do
|
||
get :externalNodes, :id => @host.id
|
||
get :externalNodes, {:id => @host.id}, set_session_user
|
||
assert_response :success
|
||
assert_template :text => @host.info.to_yaml.gsub("\n","<br>")
|
||
end
|
||
test "externalNodes should render correctly when name is given" do
|
||
get :externalNodes, :name => @host.name
|
||
get :externalNodes, {:name => @host.name}, set_session_user
|
||
assert_response :success
|
||
assert_template :text => @host.info.to_yaml.gsub("\n","<br>")
|
||
end
|
||
test "externalNodes should render yml request correctly" do
|
||
get :externalNodes, :id => @host.id, :format => "yml"
|
||
get :externalNodes, {:id => @host.id, :format => "yml"}, set_session_user
|
||
assert_response :success
|
||
assert_template :text => @host.info.to_yaml
|
||
end
|
||
... | ... | |
mock(Host).find(@host.id.to_s) {@host}
|
||
@request.env['HTTP_REFERER'] = hosts_path
|
||
get :setBuild, {:id => @host.id}
|
||
get :setBuild, {:id => @host.id}, set_session_user
|
||
assert_response :found
|
||
assert_redirected_to hosts_path
|
||
assert_not_nil flash[:foreman_notice]
|
||
... | ... | |
mock(Host).find(@host.id.to_s) {@host}
|
||
@request.env['HTTP_REFERER'] = hosts_path
|
||
get :setBuild, :id => @host.id
|
||
get :setBuild, {:id => @host.id}, set_session_user
|
||
assert_response :found
|
||
assert_redirected_to hosts_path
|
||
assert_not_nil flash[:foreman_error]
|
||
... | ... | |
end
|
||
test "rrdreport should print error message if host has no last_report" do
|
||
get :rrdreport, :id => @host.id
|
||
get :rrdreport, {:id => @host.id}, set_session_user
|
||
assert_response :success
|
||
assert_template :text => "Sorry, no graphs for this host"
|
||
end
|
||
... | ... | |
assert @host.save!
|
||
SETTINGS[:rrd_report_url] = "/some/url"
|
||
get :rrdreport, :id => @host.id
|
||
get :rrdreport, {:id => @host.id}, set_session_user
|
||
assert_response :success
|
||
assert_template :partial => "_rrdreport"
|
||
end
|
||
test "report should redirect to host's last report" do
|
||
get :report, :id => @host.id
|
||
get :report, {:id => @host.id}, set_session_user
|
||
assert_response :found
|
||
assert_redirected_to :controller => "reports", :action => "show", :id => @host.id
|
||
end
|
||
test "query in .yml format should return host.to_yml" do
|
||
get :query, :format => "yml"
|
||
get :query, {:format => "yml"}, set_session_user
|
||
assert_template :text => @host.to_yaml
|
||
end
|
||
test/functional/lookup_keys_controller_test.rb | ||
---|---|---|
class LookupKeysControllerTest < ActionController::TestCase
|
||
test "should get index" do
|
||
get :index
|
||
get :index, {}, set_session_user
|
||
assert_response :success
|
||
assert_not_nil assigns(:lookup_key)
|
||
end
|
||
test "should get new" do
|
||
get :new
|
||
get :new, {}, set_session_user
|
||
assert_response :success
|
||
end
|
||
test "should create lookup_keys" do
|
||
assert_difference('LookupKey.count') do
|
||
post :create, :lookup_key=>{"lookup_values_attributes"=>{"0"=>{"priority"=>"1", "value"=>"x", "_destroy"=>""}, "1"=>{"priority"=>"2", "value"=>"y", "_destroy"=>""}}, "key"=>"tests"}
|
||
post :create, {:lookup_key=>{"lookup_values_attributes"=>{"0"=>{"priority"=>"1", "value"=>"x", "_destroy"=>""},
|
||
"1"=>{"priority"=>"2", "value"=>"y", "_destroy"=>""}},
|
||
"key"=>"tests"}
|
||
},
|
||
set_session_user
|
||
end
|
||
assert_redirected_to lookup_keys_path(assigns(:lookup_keys))
|
||
end
|
||
test "should get edit" do
|
||
get :edit, :id => lookup_keys(:one).to_param
|
||
get :edit, {:id => lookup_keys(:one).to_param}, set_session_user
|
||
assert_response :success
|
||
end
|
||
test "should update lookup_keys" do
|
||
put :update, :id => lookup_keys(:one).to_param, :lookup_key => { :key => "test that" }
|
||
put :update, {:id => lookup_keys(:one).to_param, :lookup_key => { :key => "test that" }}, set_session_user
|
||
assert_redirected_to lookup_keys_path(assigns(:lookup_keys))
|
||
end
|
||
test "should destroy lookup_keys" do
|
||
assert_difference('LookupKey.count', -1) do
|
||
delete :destroy, :id => lookup_keys(:one).to_param
|
||
delete :destroy, {:id => lookup_keys(:one).to_param}, set_session_user
|
||
end
|
||
assert_redirected_to lookup_keys_path
|
test/functional/medias_controller_test.rb | ||
---|---|---|
class MediasControllerTest < ActionController::TestCase
|
||
def test_index
|
||
get :index
|
||
get :index, {}, set_session_user
|
||
assert_template 'index'
|
||
end
|
||
def test_new
|
||
get :new
|
||
get :new, {}, set_session_user
|
||
assert_template 'new'
|
||
end
|
||
def test_create_invalid
|
||
Media.any_instance.stubs(:valid?).returns(false)
|
||
post :create
|
||
post :create, {}, set_session_user
|
||
assert_template 'new'
|
||
end
|
||
def test_create_valid
|
||
Media.any_instance.stubs(:valid?).returns(true)
|
||
post :create
|
||
post :create, {}, set_session_user
|
||
assert_redirected_to medias_url
|
||
end
|
||
def test_edit
|
||
get :edit, :id => Media.first
|
||
get :edit, {:id => Media.first}, set_session_user
|
||
assert_template 'edit'
|
||
end
|
||
def test_update_invalid
|
||
Media.any_instance.stubs(:valid?).returns(false)
|
||
put :update, :id => Media.first
|
||
put :update, {:id => Media.first}, set_session_user
|
||
assert_template 'edit'
|
||
end
|
||
def test_update_valid
|
||
Media.any_instance.stubs(:valid?).returns(true)
|
||
put :update, :id => Media.first
|
||
put :update, {:id => Media.first}, set_session_user
|
||
assert_redirected_to medias_url
|
||
end
|
||
def test_destroy
|
||
media = Media.first
|
||
delete :destroy, :id => media
|
||
delete :destroy, {:id => media}, set_session_user
|
||
assert_redirected_to medias_url
|
||
assert !Media.exists?(media.id)
|
||
end
|
test/functional/models_controller_test.rb | ||
---|---|---|
class ModelsControllerTest < ActionController::TestCase
|
||
def test_index
|
||
get :index
|
||
get :index, {}, set_session_user
|
||
assert_template 'index'
|
||
end
|
||
def test_new
|
||
get :new
|
||
get :new, {}, set_session_user
|
||
assert_template 'new'
|
||
end
|
||
def test_create_invalid
|
||
Model.any_instance.stubs(:valid?).returns(false)
|
||
post :create
|
||
post :create, {}, set_session_user
|
||
assert_template 'new'
|
||
end
|
||
def test_create_valid
|
||
Model.any_instance.stubs(:valid?).returns(true)
|
||
post :create, :model => {:name => "test"}
|
||
post :create, {:model => {:name => "test"}}, set_session_user
|
||
assert_redirected_to models_url
|
||
end
|
||
def test_edit
|
||
get :edit, :id => Model.first
|
||
get :edit, {:id => Model.first}, set_session_user
|
||
assert_template 'edit'
|
||
end
|
||
def test_update_invalid
|
||
Model.any_instance.stubs(:valid?).returns(false)
|
||
put :update, :id => Model.first
|
||
put :update, {:id => Model.first}, set_session_user
|
||
assert_template 'edit'
|
||
end
|
||
def test_update_valid
|
||
Model.any_instance.stubs(:valid?).returns(true)
|
||
put :update, :id => Model.first
|
||
put :update, {:id => Model.first}, set_session_user
|
||
assert_redirected_to models_url
|
||
end
|
||
def test_destroy
|
||
model = Model.first
|
||
delete :destroy, :id => model
|
||
delete :destroy, {:id => model}, set_session_user
|
||
assert_redirected_to models_url
|
||
assert !Model.exists?(model.id)
|
||
end
|
test/functional/operatingsystems_controller_test.rb | ||
---|---|---|
class OperatingsystemsControllerTest < ActionController::TestCase
|
||
def test_index
|
||
get :index
|
||
get :index, {}, set_session_user
|
||
assert_template 'index'
|
||
end
|
||
def test_new
|
||
get :new
|
||
get :new, {}, set_session_user
|
||
assert_template 'new'
|
||
end
|
||
def test_create_invalid
|
||
Operatingsystem.any_instance.stubs(:valid?).returns(false)
|
||
post :create
|
||
post :create, {}, set_session_user
|
||
assert_template 'new'
|
||
end
|
||
def test_create_valid
|
||
Operatingsystem.any_instance.stubs(:valid?).returns(true)
|
||
post :create
|
||
post :create, {}, set_session_user
|
||
assert_redirected_to operatingsystems_url
|
||
end
|
||
def test_edit
|
||
get :edit, :id => Operatingsystem.first
|
||
get :edit, {:id => Operatingsystem.first}, set_session_user
|
||
assert_template 'edit'
|
||
end
|
||
def test_update_invalid
|
||
Operatingsystem.any_instance.stubs(:valid?).returns(false)
|
||
put :update, :id => Operatingsystem.first
|
||
put :update, {:id => Operatingsystem.first}, set_session_user
|
||
assert_template 'edit'
|
||
end
|
||
def test_update_valid
|
||
Operatingsystem.any_instance.stubs(:valid?).returns(true)
|
||
put :update, :id => Operatingsystem.first
|
||
put :update, {:id => Operatingsystem.first}, set_session_user
|
||
assert_redirected_to operatingsystems_url
|
||
end
|
||
def test_destroy
|
||
operatingsystem = Operatingsystem.first
|
||
delete :destroy, :id => operatingsystem
|
||
delete :destroy, {:id => operatingsystem}, set_session_user
|
||
assert_redirected_to operatingsystems_url
|
||
assert !Operatingsystem.exists?(operatingsystem.id)
|
||
end
|
test/functional/ptables_controller_test.rb | ||
---|---|---|
class PtablesControllerTest < ActionController::TestCase
|
||
def test_index
|
||
get :index
|
||
get :index, {}, set_session_user
|
||
assert_template 'index'
|
||
end
|
||
def test_show
|
||
get :show, :id => Ptable.first
|
||
get :show, {:id => Ptable.first}, set_session_user
|
||
assert_template 'show'
|
||
end
|
||
def test_new
|
||
get :new
|
||
get :new, {}, set_session_user
|
||
assert_template 'new'
|
||
end
|
||
def test_create_invalid
|
||
Ptable.any_instance.stubs(:valid?).returns(false)
|
||
post :create
|
||
post :create, {}, set_session_user
|
||
assert_template 'new'
|
||
end
|
||
def test_create_valid
|
||
Ptable.any_instance.stubs(:valid?).returns(true)
|
||
post :create, :ptable => {:name => "dummy", :layout => "dummy"}
|
||
post :create, {:ptable => {:name => "dummy", :layout => "dummy"}}, set_session_user
|
||
assert_redirected_to ptable_url(assigns(:ptable))
|
||
end
|
||
def test_edit
|
||
get :edit, :id => Ptable.first
|
||
get :edit, {:id => Ptable.first}, set_session_user
|
||
assert_template 'edit'
|
||
end
|
||
def test_update_invalid
|
||
Ptable.any_instance.stubs(:valid?).returns(false)
|
||
put :update, :id => Ptable.first
|
||
put :update, {:id => Ptable.first}, set_session_user
|
||
assert_template 'edit'
|
||
end
|
||
def test_update_valid
|
||
Ptable.any_instance.stubs(:valid?).returns(true)
|
||
put :update, :id => Ptable.first
|
||
put :update, {:id => Ptable.first}, set_session_user
|
||
assert_redirected_to ptable_url(assigns(:ptable))
|
||
end
|
||
def test_destroy
|
||
ptable = Ptable.first
|
||
delete :destroy, :id => ptable
|
||
delete :destroy, {:id => ptable}, set_session_user
|
||
assert_redirected_to ptables_url
|
||
assert !Ptable.exists?(ptable.id)
|
||
end
|
test/functional/puppetclasses_controller_test.rb | ||
---|---|---|
class PuppetclassesControllerTest < ActionController::TestCase
|
||
def test_index
|
||
get :index
|
||
get :index, {}, set_session_user
|
||
assert_template 'index'
|
||
end
|
||
def test_new
|
||
get :new
|
||
get :new, {}, set_session_user
|
||
assert_template 'new'
|
||
end
|
||
def test_create_invalid
|
||
Puppetclass.any_instance.stubs(:valid?).returns(false)
|
||
post :create
|
||
post :create, {}, set_session_user
|
||
assert_template 'new'
|
||
end
|
||
def test_create_valid
|
||
Puppetclass.any_instance.stubs(:valid?).returns(true)
|
||
post :create
|
||
post :create, {}, set_session_user
|
||
assert_redirected_to puppetclasses_url
|
||
end
|
||
def test_edit
|
||
get :edit, :id => Puppetclass.first
|
||
get :edit, {:id => Puppetclass.first}, set_session_user
|
||
assert_template 'edit'
|
||
end
|
||
def test_update_invalid
|
||
Puppetclass.any_instance.stubs(:valid?).returns(false)
|
- « Previous
- 1
- 2
- Next »