Project

General

Profile

patch-squashed.diff

Ohad Levy, 05/17/2010 06:52 AM

View differences:

.gitmodules
25 25
[submodule "extras/puppet"]
26 26
	path = extras/puppet
27 27
	url = git://github.com/ohadlevy/puppet-foreman.git
28
[submodule "vendor/plugins/has_many_polymorphs"]
29
	path = vendor/plugins/has_many_polymorphs
30
	url = git://github.com/fauna/has_many_polymorphs.git
app/controllers/usergroups_controller.rb
1
class UsergroupsController < ApplicationController
2
  def index
3
    @usergroups = Usergroup.all
4
  end
5

  
6
  def new
7
    @usergroup = Usergroup.new
8
  end
9

  
10
  def create
11
    @usergroup = Usergroup.new(params[:usergroup])
12
    if @usergroup.save
13
      flash[:foreman_notice] = "Successfully created usergroup."
14
      redirect_to usergroups_path
15
    else
16
      render :action => 'new'
17
    end
18
  end
19

  
20
  def edit
21
    @usergroup = Usergroup.find(params[:id])
22
  end
23

  
24
  def update
25
    @usergroup = Usergroup.find(params[:id])
26

  
27
    if @usergroup.update_attributes(params[:usergroup])
28
      flash[:foreman_notice] = "Successfully updated usergroup."
29
      redirect_to usergroups_path
30
    else
31
      render :action => 'edit'
32
    end
33
  end
34

  
35
  def destroy
36
    @usergroup = Usergroup.find(params[:id])
37
    if @usergroup.destroy
38
      flash[:foreman_notice] = "Successfully destroyed usergroup."
39
    else
40
      logger.error @usergroup.errors.full_messages
41
      flash[:foreman_error] = @usergroup.errors.full_messages.join "<br>"
42
    end
43
    redirect_to usergroups_path
44
  end
45
end
app/controllers/users_controller.rb
10 10
    columns[:firstname].label = "First name"
11 11
    columns[:lastname].label = "Surname"
12 12
    columns[:admin].label = "Admin"
13
    config.columns = [:firstname, :lastname, :login, :mail, :admin, :auth_source, :last_login_on]
13
    config.columns = [:firstname, :lastname, :login, :mail, :admin, :auth_source, :usergroups, :last_login_on]
14
    config.update.columns = [:firstname, :lastname, :login, :mail, :admin, :auth_source, :last_login_on]
14 15
    config.columns[:auth_source].form_ui  = :select
15 16
    config.columns[:admin].form_ui  = :checkbox
17
    config.columns[:usergroups].clear_link
16 18
    list.sorting = {:last_login_on => 'DESC' }
17 19
    config.update.columns.exclude :last_login_on
18 20
  end
app/helpers/application_helper.rb
10 10
  end
11 11

  
12 12
  def edit_habtm klass, association
13
    render :partial => 'common/edit_habtm', :locals =>{ :klass => klass, :associations => association.all}
13
    render :partial => 'common/edit_habtm', :locals =>{ :klass => klass, :associations => association.all.delete_if{|e| e == klass}}
14 14
  end
15 15

  
16 16
  def link_to_remove_fields(name, f)
app/helpers/usergroups_helper.rb
1
module UsergroupsHelper
2
end
app/models/host.rb
12 12
  has_many :reports, :dependent => :destroy
13 13
  has_many :host_parameters, :dependent => :destroy
14 14
  accepts_nested_attributes_for :host_parameters, :reject_if => lambda { |a| a[:value].blank? }, :allow_destroy => true
15
  belongs_to :owner, :polymorphic => true
15 16

  
16 17
  named_scope :recent, lambda { |*args| {:conditions => ["last_report > ?", (args.first || (SETTINGS[:run_interval] + 5.minutes).ago)]} }
17 18
  named_scope :out_of_sync, lambda { |*args| {:conditions => ["last_report < ?", (args.first || (SETTINGS[:run_interval] + 5.minutes).ago)]} }
......
80 81

  
81 82
  before_validation :normalize_addresses, :normalize_hostname
82 83

  
84
  def <=>(other)
85
    self.name <=> other.name
86
  end
87

  
83 88
  # Returns the name of this host as a string
84 89
  # String: the host's name
85 90
  def to_label
......
99 104
    20
100 105
  end
101 106

  
107
  # method to return the correct owner list for host edit owner select dropbox
108
  def is_owned_by
109
    owner.id_and_type if owner
110
  end
111

  
112
  # virtual attributes which sets the owner based on the user selection
113
  # supports a simple user, or a usergroup
114
  # selection parameter is expected to be an ActiveRecord id_and_type method (see Foreman's AR extentions).
115
  def is_owned_by=(selection)
116
    oid = nil
117
    oid = User.find(selection.to_i) if selection =~ /-Users$/
118
    oid = Usergroup.find(selection.to_i) if selection =~ /-Usergroups$/
119
    self.owner = oid
120
  end
121

  
102 122
  def clearReports
103 123
    # Remove any reports that may be held against this host
104 124
    Report.delete_all("host_id = #{self.id}")
app/models/host_mailer.rb
44 44

  
45 45
  def error_state(report)
46 46
    host = report.host
47
    email = SETTINGS[:administrator]
47
    email = host.owner.recipients if SETTINGS[:ldap] and not host.owner.empty?
48
    email ||= SETTINGS[:administrator]
48 49
    raise "unable to find recipients" if email.empty?
49 50
    recipients email
50 51
    from "Foreman-noreply"
app/models/user.rb
1 1
class User < ActiveRecord::Base
2 2
  belongs_to :auth_source
3 3
  has_many :changes, :class_name => 'Audit', :as => :user
4

  
5
  has_many :hosts
4
  has_many :usergroups, :through => :usergroup_member
5
  has_many :direct_hosts, :as => :owner, :class_name => "Host"
6 6

  
7 7
  validates_uniqueness_of :login, :message => "already exists"
8 8
  validates_presence_of :login, :mail
......
13 13
  validates_format_of :mail, :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i, :allow_nil => true
14 14
  validates_length_of :mail, :maximum => 60, :allow_nil => true
15 15

  
16
  before_destroy Ensure_not_used_by.new(:hosts)
17

  
16 18
  def to_label
17 19
    "#{firstname} #{lastname}"
18 20
  end
21
  alias_method :to_s, :to_label
22
  alias_method :name, :to_label
23

  
24
  def <=>(other)
25
    self.name <=> other.name
26
  end
27

  
28
  # The text item to see in a select dropdown menu
29
  def select_title
30
    name + " (#{login})"
31
  end
19 32

  
20 33
  def self.try_to_login(login, password)
21 34
    # Make sure no one can sign in with an empty password
......
49 62
    raise text
50 63
  end
51 64

  
65
  def indirect_hosts
66
    all_groups = []
67
    for usergroup in usergroups
68
      all_groups += usergroup.all_usergroups
69
    end
70
    all_groups.uniq.map{|g| g.hosts}.flatten.uniq
71
  end
72

  
73
  def hosts
74
    direct_hosts + indirect_hosts
75
  end
76

  
77
  def recipients
78
    [mail]
79
  end
80

  
81
  protected
82

  
83
  def validate
84
    if Usergroup.all.map(&:name).include?(self.login)
85
      errors.add_to_base "A usergroup already exists with this name"
86
    end
87
  end
88

  
52 89
end
app/models/usergroup.rb
1
class Usergroup < ActiveRecord::Base
2
  has_many_polymorphs :members, :from => [:usergroups, :users ], :as => :member,
3
    :through => :usergroup_member, :foreign_key => :usergroup_id, :dependent => :destroy
4

  
5
  has_many :hosts, :as => :owner
6
  validates_uniqueness_of :name
7
  before_destroy Ensure_not_used_by.new(:hosts, :usergroups)
8

  
9
  def to_s
10
    name
11
  end
12

  
13
  # The text item to see in a select dropdown menu
14
  alias_method :select_title, :to_s
15

  
16
  # Support for sorting the groups by name
17
  def <=>(other)
18
    self.name <=> other.name
19
  end
20

  
21
  # This methods retrieves all user addresses in a usergroup
22
  # Returns: Array of strings representing the user's email addresses
23
  def recipients
24
    all_users.map(&:mail)
25
  end
26

  
27
  # This methods retrieves all users in a usergroup
28
  # Returns: Array of users
29
  def all_users(group_list=[self], user_list=[])
30
    retrieve_users_and_groups group_list, user_list
31
    user_list.sort.uniq
32
  end
33

  
34
  # This methods retrieves all usergroups in a usergroup
35
  # Returns: Array of usergroups
36
  def all_usergroups(group_list=[self], user_list=[])
37
    retrieve_users_and_groups group_list, user_list
38
    group_list.sort.uniq
39
  end
40

  
41
  protected
42
  # Recurses down the tree of usergroups and finds the users
43
  # [+group_list+]: Array of Usergroups that have already been processed
44
  # [+users+]     : Array of users accumulated at this point
45
  # Returns       : Array of non unique users
46
  def retrieve_users_and_groups(group_list, user_list)
47
    for group in usergroups
48
      next if group_list.include? group
49
      group_list << group
50

  
51
      group.retrieve_users_and_groups(group_list, user_list)
52
    end
53
    user_list.concat users
54
  end
55

  
56
  def validate
57
    if User.all.map(&:login).include?(self.name)
58
      errors.add :name, "is already used by a user account"
59
    end
60
  end
61

  
62
end
app/models/usergroup_member.rb
1
class UsergroupMember < ActiveRecord::Base
2
  belongs_to :member, :polymorphic => true
3
  belongs_to :usergroup
4

  
5
end
app/views/home/settings.erb
12 12
    <li><%= link_to 'Global Parameters',  common_parameters_path %>  </li>
13 13
    <li><%= link_to "External Variables", lookup_keys_path %>        </li>
14 14
    <li><%= link_to 'LDAP Authentication', auth_source_ldaps_path %> </li>
15
    <li><%= link_to_if SETTINGS[:ldap], 'Users', users_path %>       </li>
15
    <li><%= link_to_if SETTINGS[:ldap], 'Users', users_path %>           </li>
16
    <li><%= link_to_if SETTINGS[:ldap], 'Usergroups', usergroups_path %> </li>
16 17
  </ul>
17 18
</div>
app/views/hosts/_form.html.erb
13 13
        <td>Puppetmaster</td>
14 14
        <td><%= f.text_field :puppetmaster, :size => 10, :value => @host.puppetmaster %></td>
15 15
        <td><%= link_to_function "Additional Classes", toggle_div(:classlist) %></td>
16
        <% if SETTINGS[:ldap] -%>
17
          <td>Owned by</td>
18
          <td>
19
          <%= f.select :is_owned_by,
20
            option_groups_from_collection_for_select( [ User, Usergroup], :all, :table_name, :id_and_type, :select_title, @host.is_owned_by),
21
            :include_blank => "select an owner" %>
22
          </td>
23
        <% end -%>
16 24
      </tr>
17 25
    </table>
18 26

  
app/views/usergroups/_form.html.erb
1
<% form_for @usergroup do |f| %>
2
  <%= f.error_messages %>
3
  <table>
4
    <tr>
5
      <td>Name</td>
6
      <td><%= f.text_field :name %></td>
7
    </tr>
8
    <tr>
9
      <td>User groups</td>
10
      <td><%= edit_habtm @usergroup, Usergroup %></td>
11
    </tr>
12
    <tr>
13
      <td>Users</td>
14
      <td><%= edit_habtm @usergroup, User %></td>
15
    </tr>
16
    <tr><td><%= f.submit "Submit" %></td></tr>
17
  </table>
18
<% end %>
app/views/usergroups/edit.html.erb
1
<% title "Edit Usergroup" %>
2

  
3
<%= render :partial => 'form' %>
4

  
5
<p>
6
  <%= link_to "View All", usergroups_path %>
7
</p>
app/views/usergroups/index.html.erb
1
<% title "Usergroups" %>
2

  
3
<table class="list">
4
  <tr>
5
    <th>Name</th>
6
    <th>Users</th>
7
    <th>User Groups</th>
8
    <th></th>
9
  </tr>
10
  <% for usergroup in @usergroups %>
11
    <tr class="<%= cycle("even", "odd") -%>">
12
      <td><%= link_to h(usergroup.name), edit_usergroup_path(usergroup) %></td>
13
      <td><%= usergroup.users.map(&:login).to_sentence %></td>
14
      <td><%= usergroup.usergroups.map(&:name).to_sentence %></td>
15
      <td align="right">
16
        <%= link_to "Destroy", usergroup, :confirm => 'Are you sure?', :method => :delete %>
17
      </td>
18
    </tr>
19
  <% end %>
20
</table>
21

  
22
<p><%= link_to "New Usergroup", new_usergroup_path %></p>
app/views/usergroups/new.html.erb
1
<% title "New Usergroup" %>
2

  
3
<%= render :partial => 'form' %>
4

  
5
<p><%= link_to "Back to List", usergroups_path %></p>
config/initializers/foreman.rb
48 48
      end
49 49
    end
50 50
  end
51

  
52
  def id_and_type
53
    "#{id}-#{self.class.table_name.humanize}"
54
  end
55

  
51 56
end
52 57

  
53 58
module ExemptedFromLogging
config/routes.rb
1 1
ActionController::Routing::Routes.draw do |map|
2
  map.resources :usergroups
2 3
  map.root :controller => "hosts"
3 4

  
4 5
  map.connect "node/:name", :controller => 'hosts', :action => 'externalNodes',
db/migrate/20100416124600_create_usergroups.rb
1
class CreateUsergroups < ActiveRecord::Migration
2
  def self.up
3
    create_table :usergroups do |t|
4
      t.string :name
5
      t.timestamps
6
    end
7
    create_table :usergroup_members do |t|
8
      t.references :member, :polymorphic => true
9
      t.references :usergroup
10
    end
11
  end
12

  
13
  def self.down
14
    drop_table :members
15
    drop_table :usergroups
16
  end
17
end
db/migrate/20100419151910_add_owner_to_hosts.rb
1
class AddOwnerToHosts < ActiveRecord::Migration
2
  def self.up
3
    add_column :hosts, :owner_id,   :integer
4
    add_column :hosts, :owner_type, :string
5

  
6
    Host.reset_column_information
7

  
8
    updated = []
9
    owner = User.find_or_create_by_login(:login => "admin", :admin => true, :firstname => "Admin", :lastname => "User", :mail => "root@" + Facter.domain)
10
    say "setting default owner for all hosts"
11
    Host.update_all("owner_id = '#{owner.id}'")
12
  end
13

  
14
  def self.down
15
    remove_column :hosts, :owner_type
16
    remove_column :hosts, :owner_id
17
  end
18
end
test/fixtures/usergroups.yml
1
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
2

  
3
one:
4
  name: MyString
5

  
6
two:
7
  name: MyString
test/fixtures/users.yml
1 1
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
2 2

  
3 3
one:
4
  login: MyString
5
  firstname: MyString
6
  lastname: MyString
4
  login: one
5
  firstname: One
6
  lastname: User
7 7
  mail: MyString
8 8
  admin: false
9 9
  last_login_on: 2009-10-12 21:50:04
10 10
  auth_source_id: 1
11 11

  
12 12
two:
13
  login: MyString
14
  firstname: MyString
15
  lastname: MyString
13
  login: two
14
  firstname: Two
15
  lastname: User
16 16
  mail: MyString
17 17
  admin: false
18 18
  last_login_on: 2009-10-12 21:50:04
test/functional/architectures_controller_test.rb
2 2

  
3 3
class ArchitecturesControllerTest < ActionController::TestCase
4 4
  def test_index
5
    get :index
5
    get :index, {}, set_session_user
6 6
    assert_template 'index'
7 7
  end
8 8

  
9 9
  def test_new
10
    get :new
10
    get :new, {}, set_session_user
11 11
    assert_template 'new'
12 12
  end
13 13

  
14 14
  def test_create_invalid
15 15
    Architecture.any_instance.stubs(:valid?).returns(false)
16
    post :create
16
    post :create, {}, set_session_user
17 17
    assert_template 'new'
18 18
  end
19 19

  
20 20
  def test_create_valid
21 21
    Architecture.any_instance.stubs(:valid?).returns(true)
22
    post :create
22
    post :create, {}, set_session_user
23 23
    assert_redirected_to architectures_url
24 24
  end
25 25

  
26 26
  def test_edit
27
    get :edit, :id => Architecture.first
27
    get :edit, {:id => Architecture.first}, set_session_user
28 28
    assert_template 'edit'
29 29
  end
30 30

  
31 31
  def test_update_invalid
32 32
    Architecture.any_instance.stubs(:valid?).returns(false)
33
    put :update, :id => Architecture.first
33
    put :update, {:id => Architecture.first}, set_session_user
34 34
    assert_template 'edit'
35 35
  end
36 36

  
37 37
  def test_update_valid
38 38
    Architecture.any_instance.stubs(:valid?).returns(true)
39
    put :update, :id => Architecture.first
39
    put :update, {:id => Architecture.first}, set_session_user
40 40
    assert_redirected_to architectures_url
41 41
  end
42 42

  
43 43
  def test_destroy
44 44
    architecture = Architecture.first
45
    delete :destroy, :id => architecture
45
    delete :destroy, {:id => architecture}, set_session_user
46 46
    assert_redirected_to architectures_url
47 47
    assert !Architecture.exists?(architecture.id)
48 48
  end
test/functional/audit_controller_test.rb
2 2

  
3 3
class AuditControllerTest < ActionController::TestCase
4 4
  test "should get index" do
5
    get :index
5
    get :index, {}, set_session_user
6 6
    assert_response :success
7 7
    assert_not_nil assigns(:records)
8 8
  end
9 9

  
10 10
  test "should get search" do
11
    get :show_search
11
    get :show_search, {}, set_session_user
12 12
    assert_response :success
13 13
  end
14 14

  
......
19 19
    audited_record = Audit.find_by_auditable_id(parameter.id)
20 20
    assert_not_nil audited_record
21 21

  
22
    get :show, :id => audited_record.id
22
    get :show, {:id => audited_record.id}, set_session_user
23 23
    assert_response :success
24 24
  end
25 25
end
test/functional/auth_source_ldaps_controller_test.rb
2 2

  
3 3
class AuthSourceLdapsControllerTest < ActionController::TestCase
4 4
  def test_index
5
    get :index
5
    get :index, {}, set_session_user
6 6
    assert_template 'index'
7 7
  end
8 8

  
9 9
  def test_new
10
    get :new
10
    get :new, {}, set_session_user
11 11
    assert_template 'new'
12 12
  end
13 13

  
14 14
  def test_create_invalid
15 15
    AuthSourceLdap.any_instance.stubs(:valid?).returns(false)
16
    post :create
16
    post :create, {}, set_session_user
17 17
    assert_template 'new'
18 18
  end
19 19

  
20 20
  def test_create_valid
21 21
    AuthSourceLdap.any_instance.stubs(:valid?).returns(true)
22
    post :create
22
    post :create, {}, set_session_user
23 23
    assert_redirected_to auth_source_ldaps_url
24 24
  end
25 25

  
26 26
  def test_edit
27
    get :edit, :id => AuthSourceLdap.first
27
    get :edit, {:id => AuthSourceLdap.first}, set_session_user
28 28
    assert_template 'edit'
29 29
  end
30 30

  
31 31
  def test_update_invalid
32 32
    AuthSourceLdap.any_instance.stubs(:valid?).returns(false)
33
    put :update, :id => AuthSourceLdap.first
33
    put :update, {:id => AuthSourceLdap.first}, set_session_user
34 34
    assert_template 'edit'
35 35
  end
36 36

  
37 37
  def test_update_valid
38 38
    AuthSourceLdap.any_instance.stubs(:valid?).returns(true)
39
    put :update, :id => AuthSourceLdap.first
39
    put :update, {:id => AuthSourceLdap.first}, set_session_user
40 40
    assert_redirected_to auth_source_ldaps_url
41 41
  end
42 42

  
43 43
  def test_destroy
44 44
    auth_source_ldap = AuthSourceLdap.first
45
    delete :destroy, :id => auth_source_ldap
45
    delete :destroy, {:id => auth_source_ldap}, set_session_user
46 46
    assert_redirected_to auth_source_ldaps_url
47 47
    assert !AuthSourceLdap.exists?(auth_source_ldap.id)
48 48
  end
test/functional/common_parameters_controller_test.rb
2 2

  
3 3
class CommonParametersControllerTest < ActionController::TestCase
4 4
  def test_index
5
    get :index
5
    get :index, {}, set_session_user
6 6
    assert_template 'index'
7 7
  end
8 8

  
9 9
  def test_new
10
    get :new
10
    get :new, {}, set_session_user
11 11
    assert_template 'new'
12 12
  end
13 13

  
14 14
  def test_create_invalid
15 15
    CommonParameter.any_instance.stubs(:valid?).returns(false)
16
    post :create
16
    post :create, {}, set_session_user
17 17
    assert_template 'new'
18 18
  end
19 19

  
20 20
  def test_create_valid
21 21
    CommonParameter.any_instance.stubs(:valid?).returns(true)
22
    post :create
22
    post :create, {}, set_session_user
23 23
    assert_redirected_to common_parameters_url
24 24
  end
25 25

  
26 26
  def test_edit
27
    get :edit, :id => CommonParameter.first
27
    get :edit, {:id => CommonParameter.first}, set_session_user
28 28
    assert_template 'edit'
29 29
  end
30 30

  
31 31
  def test_update_invalid
32 32
    CommonParameter.any_instance.stubs(:valid?).returns(false)
33
    put :update, :id => CommonParameter.first
33
    put :update, {:id => CommonParameter.first}, set_session_user
34 34
    assert_template 'edit'
35 35
  end
36 36

  
37 37
  def test_update_valid
38 38
    CommonParameter.any_instance.stubs(:valid?).returns(true)
39
    put :update, :id => CommonParameter.first
39
    put :update, {:id => CommonParameter.first}, set_session_user
40 40
    assert_redirected_to common_parameters_url
41 41
  end
42 42

  
43 43
  def test_destroy
44 44
    common_parameter = CommonParameter.first
45
    delete :destroy, :id => common_parameter
45
    delete :destroy, {:id => common_parameter}, set_session_user
46 46
    assert_redirected_to common_parameters_url
47 47
    assert !CommonParameter.exists?(common_parameter.id)
48 48
  end
test/functional/dashboard_controller_test.rb
2 2

  
3 3
class DashboardControllerTest < ActionController::TestCase
4 4
  test "should get index" do
5
    get :index
5
    get :index, {}, set_session_user
6 6
    assert_response :success
7 7
  end
8 8

  
9 9
  test "should get errors" do
10
    get :errors
10
    get :errors, {}, set_session_user
11 11
    assert_response :success
12 12
    assert_template :partial => "hosts/_minilist"
13 13
  end
14 14

  
15 15
  test "should get active" do
16
    get :active
16
    get :active, {}, set_session_user
17 17
    assert_response :success
18 18
    assert_template :partial => "hosts/_minilist"
19 19
  end
20 20

  
21 21
  test "should get out of sync" do
22
    get :OutOfSync
22
    get :OutOfSync, {}, set_session_user
23 23
    assert_response :success
24 24
    assert_template :partial => "hosts/_minilist"
25 25
  end
test/functional/domains_controller_test.rb
2 2

  
3 3
class DomainsControllerTest < ActionController::TestCase
4 4
  def test_index
5
    get :index
5
    get :index, {}, set_session_user
6 6
    assert_template 'index'
7 7
  end
8 8

  
9 9
  def test_new
10
    get :new
10
    get :new, {}, set_session_user
11 11
    assert_template 'new'
12 12
  end
13 13

  
14 14
  def test_create_invalid
15 15
    Domain.any_instance.stubs(:valid?).returns(false)
16
    post :create
16
    post :create, {}, set_session_user
17 17
    assert_template 'new'
18 18
  end
19 19

  
20 20
  def test_create_valid
21 21
    Domain.any_instance.stubs(:valid?).returns(true)
22
    post :create
22
    post :create, {}, set_session_user
23 23
    assert_redirected_to domains_url
24 24
  end
25 25

  
26 26
  def test_edit
27
    get :edit, :id => Domain.first
27
    get :edit, {:id => Domain.first}, set_session_user
28 28
    assert_template 'edit'
29 29
  end
30 30

  
31 31
  def test_update_invalid
32 32
    Domain.any_instance.stubs(:valid?).returns(false)
33
    put :update, :id => Domain.first
33
    put :update, {:id => Domain.first}, set_session_user
34 34
    assert_template 'edit'
35 35
  end
36 36

  
37 37
  def test_update_valid
38 38
    Domain.any_instance.stubs(:valid?).returns(true)
39
    put :update, :id => Domain.first
39
    put :update, {:id => Domain.first}, set_session_user
40 40
    assert_redirected_to domains_url
41 41
  end
42 42

  
43 43
  def test_destroy
44 44
    domain = Domain.first
45
    delete :destroy, :id => domain
45
    delete :destroy, {:id => domain}, set_session_user
46 46
    assert_redirected_to domains_url
47 47
    assert !Domain.exists?(domain.id)
48 48
  end
test/functional/environments_controller_test.rb
7 7
  end
8 8

  
9 9
  test "should get index" do
10
    get :index
10
    get :index, {}, set_session_user
11 11
    assert_response :success
12 12
    assert_not_nil assigns(:records)
13 13
  end
14 14

  
15
  test "shuold get new" do
16
    get :new
15
  test "should get new" do
16
    get :new, {}, set_session_user
17 17
    assert_response :success
18 18
  end
19 19

  
20 20
  test "should create new environment" do
21 21
    assert_difference 'Environment.count' do
22
      post :create, { :commit => "Create", :record => {:name => "some_environment"} }
22
      post :create, { :commit => "Create", :record => {:name => "some_environment"} }, set_session_user
23 23
    end
24 24

  
25 25
    assert_redirected_to environments_path
......
29 29
    environment = Environment.new :name => "some_environment"
30 30
    assert environment.save!
31 31

  
32
    get :edit, :id => environment.id
32
    get :edit, {:id => environment.id}, set_session_user
33 33
    assert_response :success
34 34
  end
35 35

  
......
37 37
    environment = Environment.new :name => "some_environment"
38 38
    assert environment.save!
39 39

  
40
    put :update, { :commit => "Update", :id => environment.id, :record => {:name => "other_environment"} }
40
    put :update, { :commit => "Update", :id => environment.id, :record => {:name => "other_environment"} }, set_session_user
41 41
    environment = Environment.find_by_id(environment.id)
42 42
    assert environment.name == "other_environment"
43 43

  
......
49 49
    assert environment.save!
50 50

  
51 51
    assert_difference('Environment.count', -1) do
52
      delete :destroy, :id => environment.id
52
      delete :destroy, {:id => environment.id}, set_session_user
53 53
    end
54 54

  
55 55
    assert_redirected_to environments_path
test/functional/fact_values_controller_test.rb
2 2

  
3 3
class FactValuesControllerTest < ActionController::TestCase
4 4
  test "should get list" do
5
    get :list
5
    get :list, {}, set_session_user
6 6
    assert_response :success
7 7
    assert_not_nil :records
8 8
  end
9 9

  
10 10
  test "should get list_filter" do
11
    get :list_filter
11
    get :list_filter, {}, set_session_user
12 12
    assert_response :found
13 13
  end
14 14
end
test/functional/home_controller_test.rb
2 2

  
3 3
class HomeControllerTest < ActionController::TestCase
4 4
  test "should get settings" do
5
    get :settings
5
    get :settings, {}, set_session_user
6 6
    assert_response :success
7 7
  end
8 8
end
test/functional/hostgroups_controller_test.rb
2 2

  
3 3
class HostgroupsControllerTest < ActionController::TestCase
4 4
  def test_index
5
    get :index
5
    get :index, {}, set_session_user
6 6
    assert_template 'index'
7 7
  end
8 8

  
9 9
  def test_new
10
    get :new
10
    get :new, {}, set_session_user
11 11
    assert_template 'new'
12 12
  end
13 13

  
14 14
  def test_create_invalid
15 15
    Hostgroup.any_instance.stubs(:valid?).returns(false)
16
    post :create
16
    post :create, {}, set_session_user
17 17
    assert_template 'new'
18 18
  end
19 19

  
20 20
  def test_create_valid
21 21
    Hostgroup.any_instance.stubs(:valid?).returns(true)
22 22
    pc = Puppetclass.first
23
    post :create, "hostgroup" => {"name"=>"test_it", "group_parameters_attributes"=>{"1272344174448"=>{"name"=>"x", "value"=>"y", "_destroy"=>""}}, "puppetclass_ids"=>["", pc.id.to_s]}
23
    post :create, {"hostgroup" => {"name"=>"test_it", "group_parameters_attributes"=>{"1272344174448"=>{"name"=>"x", "value"=>"y", "_destroy"=>""}}, "puppetclass_ids"=>["", pc.id.to_s]}}, set_session_user
24 24
    assert_redirected_to hostgroups_url
25 25
  end
26 26

  
27 27
  def test_edit
28
    get :edit, :id => Hostgroup.first
28
    get :edit, {:id => Hostgroup.first}, set_session_user
29 29
    assert_template 'edit'
30 30
  end
31 31

  
32 32
  def test_update_invalid
33 33
    Hostgroup.any_instance.stubs(:valid?).returns(false)
34
    put :update, :id => Hostgroup.first
34
    put :update, {:id => Hostgroup.first}, set_session_user
35 35
    assert_template 'edit'
36 36
  end
37 37

  
38 38
  def test_update_valid
39 39
    Hostgroup.any_instance.stubs(:valid?).returns(true)
40
    put :update, :id => Hostgroup.first
40
    put :update, {:id => Hostgroup.first}, set_session_user
41 41
    assert_redirected_to hostgroups_url
42 42
  end
43 43

  
44 44
  def test_destroy
45 45
    hostgroup = Hostgroup.first
46
    delete :destroy, :id => hostgroup
46
    delete :destroy, {:id => hostgroup}, set_session_user
47 47
    assert_redirected_to hostgroups_url
48 48
    assert !Hostgroup.exists?(hostgroup.id)
49 49
  end
test/functional/hosts_controller_test.rb
3 3
class HostsControllerTest < ActionController::TestCase
4 4
  setup :initialize_host
5 5

  
6
  def test_index
7
    get :index
8
    assert_template 'index'
9
  end
10

  
11 6
  def test_show
12
    get :show, :id => Host.first
7
    get :show, {:id => Host.first}, set_session_user
13 8
    assert_template 'show'
14 9
  end
15 10

  
16
  def test_new
17
    get :new
18
    assert_template 'new'
19
  end
20

  
21 11
  def test_create_invalid
22 12
    Host.any_instance.stubs(:valid?).returns(false)
23
    post :create
13
    post :create, {}, set_session_user
24 14
    assert_template 'new'
25 15
  end
26 16

  
27 17
  def test_create_valid
28 18
    Host.any_instance.stubs(:valid?).returns(true)
29
    post :create, :host => {:name => "test"}
30
    assert_redirected_to host_url(assigns(:host))
19
    post :create, {:host => {:name => "test"}}, set_session_user
20
    assert_redirected_to host_url(assigns('host'))
31 21
  end
32 22

  
33
  def test_edit
34
    get :edit, :id => Host.first
23
  test "should get index" do
24
    get :index, {}, set_session_user
25
    assert_response :success
26
    assert_template 'index'
27
  end
28

  
29
  test "should get new" do
30
    get :new, {}, set_session_user
31
    assert_response :success
32
    assert_template 'new'
33
  end
34

  
35
  test "should create new host" do
36
    assert_difference 'Host.count' do
37
      post :create, { :commit => "Create",
38
        :host => {:name => "myotherfullhost",
39
          :mac => "aabbecddee00",
40
          :ip => "123.05.02.25",
41
          :domain => Domain.find_or_create_by_name("othercompany.com"),
42
          :operatingsystem => Operatingsystem.first,
43
          :architecture => Architecture.first,
44
          :environment => Environment.first,
45
          :disk => "empty partition"
46
      }
47
      }, set_session_user
48
    end
49
  end
50

  
51
  test "should get edit" do
52
    get :edit, {:id => @host.id}, set_session_user
53
    assert_response :success
35 54
    assert_template 'edit'
36 55
  end
37 56

  
57
  test "should update host" do
58
    put :update, { :commit => "Update", :id => @host.id, :host => {:disk => "ntfs"} }, set_session_user
59
    @host = Host.find_by_id(@host.id)
60
    assert_equal @host.disk, "ntfs"
61
  end
62

  
38 63
  def test_update_invalid
39 64
    Host.any_instance.stubs(:valid?).returns(false)
40
    put :update, :id => Host.first
65
    put :update, {:id => Host.first}, set_session_user
41 66
    assert_template 'edit'
42 67
  end
43 68

  
44 69
  def test_update_valid
45 70
    Host.any_instance.stubs(:valid?).returns(true)
46
    put :update, :id => Host.first
71
    put :update, {:id => Host.first}, set_session_user
47 72
    assert_redirected_to host_url(assigns(:host))
48 73
  end
49 74

  
50 75
  def test_destroy
51 76
    host = Host.first
52
    delete :destroy, :id => host
77
    delete :destroy, {:id => host}, set_session_user
53 78
    assert_redirected_to hosts_url
54 79
    assert !Host.exists?(host.id)
55 80
  end
56
test "externalNodes should render 404 when no params are given" do
57
    get :externalNodes
81

  
82
  test "externalNodes should render 404 when no params are given" do
83
    get :externalNodes, {}, set_session_user
58 84
    assert_response :missing
59 85
    assert_template :text => '404 Not Found'
60 86
  end
61 87

  
62 88
  test "externalNodes should render correctly when id is given" do
63
    get :externalNodes, :id => @host.id
89
    get :externalNodes, {:id => @host.id}, set_session_user
64 90
    assert_response :success
65 91
    assert_template :text => @host.info.to_yaml.gsub("\n","<br>")
66 92
  end
67 93

  
68 94
  test "externalNodes should render correctly when name is given" do
69
    get :externalNodes, :name => @host.name
95
    get :externalNodes, {:name => @host.name}, set_session_user
70 96
    assert_response :success
71 97
    assert_template :text => @host.info.to_yaml.gsub("\n","<br>")
72 98
  end
73 99

  
74 100
  test "externalNodes should render yml request correctly" do
75
    get :externalNodes, :id => @host.id, :format => "yml"
101
    get :externalNodes, {:id => @host.id, :format => "yml"}, set_session_user
76 102
    assert_response :success
77 103
    assert_template :text => @host.info.to_yaml
78 104
  end
......
82 108
    mock(Host).find(@host.id.to_s) {@host}
83 109
    @request.env['HTTP_REFERER'] = hosts_path
84 110

  
85
    get :setBuild, {:id => @host.id}
111
    get :setBuild, {:id => @host.id}, set_session_user
86 112
    assert_response :found
87 113
    assert_redirected_to hosts_path
88 114
    assert_not_nil flash[:foreman_notice]
......
94 120
    mock(Host).find(@host.id.to_s) {@host}
95 121
    @request.env['HTTP_REFERER'] = hosts_path
96 122

  
97
    get :setBuild, :id => @host.id
123
    get :setBuild, {:id => @host.id}, set_session_user
98 124
    assert_response :found
99 125
    assert_redirected_to hosts_path
100 126
    assert_not_nil flash[:foreman_error]
......
102 128
  end
103 129

  
104 130
  test "rrdreport should print error message if host has no last_report" do
105
    get :rrdreport, :id => @host.id
131
    get :rrdreport, {:id => @host.id}, set_session_user
106 132
    assert_response :success
107 133
    assert_template :text => "Sorry, no graphs for this host"
108 134
  end
......
112 138
    assert @host.save!
113 139
    SETTINGS[:rrd_report_url] = "/some/url"
114 140

  
115
    get :rrdreport, :id => @host.id
141
    get :rrdreport, {:id => @host.id}, set_session_user
116 142
    assert_response :success
117 143
    assert_template :partial => "_rrdreport"
118 144
  end
119 145

  
120 146
  test "report should redirect to host's last report" do
121
    get :report, :id => @host.id
147
    get :report, {:id => @host.id}, set_session_user
122 148
    assert_response :found
123 149
    assert_redirected_to :controller => "reports", :action => "show", :id => @host.id
124 150
  end
125 151

  
126 152
  test "query in .yml format should return host.to_yml" do
127
    get :query, :format => "yml"
153
    get :query, {:format => "yml"}, set_session_user
128 154
    assert_template :text => @host.to_yaml
129 155
  end
130 156

  
test/functional/lookup_keys_controller_test.rb
2 2

  
3 3
class LookupKeysControllerTest < ActionController::TestCase
4 4
  test "should get index" do
5
    get :index
5
    get :index, {}, set_session_user
6 6
    assert_response :success
7 7
    assert_not_nil assigns(:lookup_key)
8 8
  end
9 9

  
10 10
  test "should get new" do
11
    get :new
11
    get :new, {}, set_session_user
12 12
    assert_response :success
13 13
  end
14 14

  
15 15
  test "should create lookup_keys" do
16 16
    assert_difference('LookupKey.count') do
17
      post :create, :lookup_key=>{"lookup_values_attributes"=>{"0"=>{"priority"=>"1", "value"=>"x", "_destroy"=>""}, "1"=>{"priority"=>"2", "value"=>"y", "_destroy"=>""}}, "key"=>"tests"}
17
      post :create, {:lookup_key=>{"lookup_values_attributes"=>{"0"=>{"priority"=>"1", "value"=>"x", "_destroy"=>""},
18
        "1"=>{"priority"=>"2", "value"=>"y", "_destroy"=>""}},
19
        "key"=>"tests"}
20
      },
21
        set_session_user
18 22
    end
19 23

  
20 24
    assert_redirected_to lookup_keys_path(assigns(:lookup_keys))
21 25
  end
22 26

  
23 27
  test "should get edit" do
24
    get :edit, :id => lookup_keys(:one).to_param
28
    get :edit, {:id => lookup_keys(:one).to_param}, set_session_user
25 29
    assert_response :success
26 30
  end
27 31

  
28 32
  test "should update lookup_keys" do
29
    put :update, :id => lookup_keys(:one).to_param, :lookup_key => { :key => "test that" }
33
    put :update, {:id => lookup_keys(:one).to_param, :lookup_key => { :key => "test that" }}, set_session_user
30 34
    assert_redirected_to lookup_keys_path(assigns(:lookup_keys))
31 35
  end
32 36

  
33 37
  test "should destroy lookup_keys" do
34 38
    assert_difference('LookupKey.count', -1) do
35
      delete :destroy, :id => lookup_keys(:one).to_param
39
      delete :destroy, {:id => lookup_keys(:one).to_param}, set_session_user
36 40
    end
37 41

  
38 42
    assert_redirected_to lookup_keys_path
test/functional/medias_controller_test.rb
2 2

  
3 3
class MediasControllerTest < ActionController::TestCase
4 4
  def test_index
5
    get :index
5
    get :index, {}, set_session_user
6 6
    assert_template 'index'
7 7
  end
8 8

  
9 9
  def test_new
10
    get :new
10
    get :new, {}, set_session_user
11 11
    assert_template 'new'
12 12
  end
13 13

  
14 14
  def test_create_invalid
15 15
    Media.any_instance.stubs(:valid?).returns(false)
16
    post :create
16
    post :create, {}, set_session_user
17 17
    assert_template 'new'
18 18
  end
19 19

  
20 20
  def test_create_valid
21 21
    Media.any_instance.stubs(:valid?).returns(true)
22
    post :create
22
    post :create, {}, set_session_user
23 23
    assert_redirected_to medias_url
24 24
  end
25 25

  
26 26
  def test_edit
27
    get :edit, :id => Media.first
27
    get :edit, {:id => Media.first}, set_session_user
28 28
    assert_template 'edit'
29 29
  end
30 30

  
31 31
  def test_update_invalid
32 32
    Media.any_instance.stubs(:valid?).returns(false)
33
    put :update, :id => Media.first
33
    put :update, {:id => Media.first}, set_session_user
34 34
    assert_template 'edit'
35 35
  end
36 36

  
37 37
  def test_update_valid
38 38
    Media.any_instance.stubs(:valid?).returns(true)
39
    put :update, :id => Media.first
39
    put :update, {:id => Media.first}, set_session_user
40 40
    assert_redirected_to medias_url
41 41
  end
42 42

  
43 43
  def test_destroy
44 44
    media = Media.first
45
    delete :destroy, :id => media
45
    delete :destroy, {:id => media}, set_session_user
46 46
    assert_redirected_to medias_url
47 47
    assert !Media.exists?(media.id)
48 48
  end
test/functional/models_controller_test.rb
2 2

  
3 3
class ModelsControllerTest < ActionController::TestCase
4 4
  def test_index
5
    get :index
5
    get :index, {}, set_session_user
6 6
    assert_template 'index'
7 7
  end
8 8

  
9 9
  def test_new
10
    get :new
10
    get :new, {}, set_session_user
11 11
    assert_template 'new'
12 12
  end
13 13

  
14 14
  def test_create_invalid
15 15
    Model.any_instance.stubs(:valid?).returns(false)
16
    post :create
16
    post :create, {}, set_session_user
17 17
    assert_template 'new'
18 18
  end
19 19

  
20 20
  def test_create_valid
21 21
    Model.any_instance.stubs(:valid?).returns(true)
22
    post :create, :model => {:name => "test"}
22
    post :create, {:model => {:name => "test"}}, set_session_user
23 23
    assert_redirected_to models_url
24 24
  end
25 25

  
26 26
  def test_edit
27
    get :edit, :id => Model.first
27
    get :edit, {:id => Model.first}, set_session_user
28 28
    assert_template 'edit'
29 29
  end
30 30

  
31 31
  def test_update_invalid
32 32
    Model.any_instance.stubs(:valid?).returns(false)
33
    put :update, :id => Model.first
33
    put :update, {:id => Model.first}, set_session_user
34 34
    assert_template 'edit'
35 35
  end
36 36

  
37 37
  def test_update_valid
38 38
    Model.any_instance.stubs(:valid?).returns(true)
39
    put :update, :id => Model.first
39
    put :update, {:id => Model.first}, set_session_user
40 40
    assert_redirected_to models_url
41 41
  end
42 42

  
43 43
  def test_destroy
44 44
    model = Model.first
45
    delete :destroy, :id => model
45
    delete :destroy, {:id => model}, set_session_user
46 46
    assert_redirected_to models_url
47 47
    assert !Model.exists?(model.id)
48 48
  end
test/functional/operatingsystems_controller_test.rb
2 2

  
3 3
class OperatingsystemsControllerTest < ActionController::TestCase
4 4
  def test_index
5
    get :index
5
    get :index, {}, set_session_user
6 6
    assert_template 'index'
7 7
  end
8 8

  
9 9
  def test_new
10
    get :new
10
    get :new, {}, set_session_user
11 11
    assert_template 'new'
12 12
  end
13 13

  
14 14
  def test_create_invalid
15 15
    Operatingsystem.any_instance.stubs(:valid?).returns(false)
16
    post :create
16
    post :create, {}, set_session_user
17 17
    assert_template 'new'
18 18
  end
19 19

  
20 20
  def test_create_valid
21 21
    Operatingsystem.any_instance.stubs(:valid?).returns(true)
22
    post :create
22
    post :create, {}, set_session_user
23 23
    assert_redirected_to operatingsystems_url
24 24
  end
25 25

  
26 26
  def test_edit
27
    get :edit, :id => Operatingsystem.first
27
    get :edit, {:id => Operatingsystem.first}, set_session_user
28 28
    assert_template 'edit'
29 29
  end
30 30
  def test_update_invalid
31 31
    Operatingsystem.any_instance.stubs(:valid?).returns(false)
32
    put :update, :id => Operatingsystem.first
32
    put :update, {:id => Operatingsystem.first}, set_session_user
33 33
    assert_template 'edit'
34 34
  end
35 35

  
36 36
  def test_update_valid
37 37
    Operatingsystem.any_instance.stubs(:valid?).returns(true)
38
    put :update, :id => Operatingsystem.first
38
    put :update, {:id => Operatingsystem.first}, set_session_user
39 39
    assert_redirected_to operatingsystems_url
40 40
  end
41 41

  
42 42
  def test_destroy
43 43
    operatingsystem = Operatingsystem.first
44
    delete :destroy, :id => operatingsystem
44
    delete :destroy, {:id => operatingsystem}, set_session_user
45 45
    assert_redirected_to operatingsystems_url
46 46
    assert !Operatingsystem.exists?(operatingsystem.id)
47 47
  end
test/functional/ptables_controller_test.rb
2 2

  
3 3
class PtablesControllerTest < ActionController::TestCase
4 4
  def test_index
5
    get :index
5
    get :index, {}, set_session_user
6 6
    assert_template 'index'
7 7
  end
8 8

  
9 9
  def test_show
10
    get :show, :id => Ptable.first
10
    get :show, {:id => Ptable.first}, set_session_user
11 11
    assert_template 'show'
12 12
  end
13 13

  
14 14
  def test_new
15
    get :new
15
    get :new, {}, set_session_user
16 16
    assert_template 'new'
17 17
  end
18 18

  
19 19
  def test_create_invalid
20 20
    Ptable.any_instance.stubs(:valid?).returns(false)
21
    post :create
21
    post :create, {}, set_session_user
22 22
    assert_template 'new'
23 23
  end
24 24

  
25 25
  def test_create_valid
26 26
    Ptable.any_instance.stubs(:valid?).returns(true)
27
    post :create, :ptable => {:name => "dummy", :layout => "dummy"}
27
    post :create, {:ptable => {:name => "dummy", :layout => "dummy"}}, set_session_user
28 28
    assert_redirected_to ptable_url(assigns(:ptable))
29 29
  end
30 30

  
31 31
  def test_edit
32
    get :edit, :id => Ptable.first
32
    get :edit, {:id => Ptable.first}, set_session_user
33 33
    assert_template 'edit'
34 34
  end
35 35

  
36 36
  def test_update_invalid
37 37
    Ptable.any_instance.stubs(:valid?).returns(false)
38
    put :update, :id => Ptable.first
38
    put :update, {:id => Ptable.first}, set_session_user
39 39
    assert_template 'edit'
40 40
  end
41 41

  
42 42
  def test_update_valid
43 43
    Ptable.any_instance.stubs(:valid?).returns(true)
44
    put :update, :id => Ptable.first
44
    put :update, {:id => Ptable.first}, set_session_user
45 45
    assert_redirected_to ptable_url(assigns(:ptable))
46 46
  end
47 47

  
48 48
  def test_destroy
49 49
    ptable = Ptable.first
50
    delete :destroy, :id => ptable
50
    delete :destroy, {:id => ptable}, set_session_user
51 51
    assert_redirected_to ptables_url
52 52
    assert !Ptable.exists?(ptable.id)
53 53
  end
test/functional/puppetclasses_controller_test.rb
2 2

  
3 3
class PuppetclassesControllerTest < ActionController::TestCase
4 4
  def test_index
5
    get :index
5
    get :index, {}, set_session_user
6 6
    assert_template 'index'
7 7
  end
8 8

  
9 9
  def test_new
10
    get :new
10
    get :new, {}, set_session_user
11 11
    assert_template 'new'
12 12
  end
13 13

  
14 14
  def test_create_invalid
15 15
    Puppetclass.any_instance.stubs(:valid?).returns(false)
16
    post :create
16
    post :create, {}, set_session_user
17 17
    assert_template 'new'
18 18
  end
19 19

  
20 20
  def test_create_valid
21 21
    Puppetclass.any_instance.stubs(:valid?).returns(true)
22
    post :create
22
    post :create, {}, set_session_user
23 23
    assert_redirected_to puppetclasses_url
24 24
  end
25 25

  
26 26
  def test_edit
27
    get :edit, :id => Puppetclass.first
27
    get :edit, {:id => Puppetclass.first}, set_session_user
28 28
    assert_template 'edit'
29 29
  end
30 30

  
31 31
  def test_update_invalid
32 32
    Puppetclass.any_instance.stubs(:valid?).returns(false)
... This diff was truncated because it exceeds the maximum size that can be displayed.