Module: AutoTest::Authentication

Included in:
AutoTest
Defined in:
lib/authentication.rb

Class Method Summary collapse

Class Method Details

.get_login_attributesObject

return the login attributes



30
31
32
# File 'lib/authentication.rb', line 30

def 
  @login_attributes
end

.get_login_buttonObject



48
49
50
# File 'lib/authentication.rb', line 48

def 
  @login_button
end

.get_login_dataObject



56
57
58
# File 'lib/authentication.rb', line 56

def 
  @data
end

.get_login_fieldsObject



89
90
91
# File 'lib/authentication.rb', line 89

def 
  @fields
end

.get_login_namesObject



80
81
82
# File 'lib/authentication.rb', line 80

def 
  @names
end

.get_login_pathObject

get the login path



35
36
37
# File 'lib/authentication.rb', line 35

def 
  @login
end

.get_logout_pathObject



18
19
20
# File 'lib/authentication.rb', line 18

def get_logout_path
  @logout
end

.get_unique_login_attribute_nameObject



97
98
99
# File 'lib/authentication.rb', line 97

def  
  @unique_login
end

.get_user_dataObject



131
132
133
# File 'lib/authentication.rb', line 131

def get_user_data
  @user_data
end

.get_usersObject

return the users



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/authentication.rb', line 110

def get_users
  if @db_users[0] then
    @users = @db_users[1].find(:all)
  else 
    index = .index()   
    @users = []     
    @db_users[1].find(:all).each do |u|
      .each do |d|
        if d[index] == u.send(.to_sym) then
          @users << u
        end
      end
    end
  end
  return @users
end

.get_users_from_db(user_class_name, bool) ⇒ Object



67
68
69
70
71
72
73
74
# File 'lib/authentication.rb', line 67

def get_users_from_db(user_class_name, bool)
  @users = user_class_name.find(:all)
  if bool then
    @db_users = [true, user_class_name]
  else 
    @db_users = [false, user_class_name]
  end
end

.init_login_dataObject



52
53
54
# File 'lib/authentication.rb', line 52

def 
  @data = []
end

.init_usersObject

initialize the @users array



8
9
10
11
# File 'lib/authentication.rb', line 8

def init_users
  @users = []
  @db_users = [false, nil]
end

.login(user, session) ⇒ Object

login a user



148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
# File 'lib/authentication.rb', line 148

def (user, session)
  begin
    session.visit 
    user = user.class.find(user.id)
    hash = Hash.new
    hash["#{Test.get_sessions_array.index(session)}:#{session.current_path}"] = 
    Test.add_to_action_path hash
    Page.check_for_error_code(session)
    index = .index()        
    @db_users[1].find(:all).each do |u|
      .each do |d|
        if d[index] == u.send(.to_sym) then
          set_user_data([index])
        end
      end  
    end
    if @db_users[0] then
      .each do |field|            
        session.fill_in field[1], :with => user.send(field[0].to_sym)
      end
    else
      .each_with_index do |field, i|
        session.fill_in field[1], :with => get_user_data[i]
      end
    end
    session.click_button 
    
    Page.check_for_error_code(session)
  rescue (ActiveRecord::RecordNotFound)
    Test.sessions(Test.get_sessions_array.index(session), "depth", Test.get_max_depth+1)
    Test.sessions(Test.get_sessions_array.index(session), "current_depth", Test.get_sessions(Test.get_sessions_array.index(session), "depth"))
  end  
        
end

.logout(session) ⇒ Object



136
137
138
139
140
141
142
143
144
145
# File 'lib/authentication.rb', line 136

def logout(session)
  begin
    hash = Hash.new
    hash["#{Test.get_sessions_array.index(session)}:#{session.current_path}"] = get_logout_path
    Test.add_to_action_path hash
    session.visit get_logout_path
    Page.check_for_error_code(session)
  rescue => e
  end
end

.set_login_attribute_names(names, fields) ⇒ Object

set the attribute_names and fields that are needed to login the argument are two arrays, the first are the database names of the attribute the second are the belonging field names



25
26
27
# File 'lib/authentication.rb', line 25

def (names, fields)
  @login_attributes = names.zip fields
end

.set_login_button(text) ⇒ Object



44
45
46
# File 'lib/authentication.rb', line 44

def (text)
  @login_button = text
end

.set_login_data(*data) ⇒ Object



60
61
62
63
64
65
# File 'lib/authentication.rb', line 60

def (*data)
  data.each do |d|
    @data << d
  end
  
end

.set_login_fields(fields) ⇒ Object



85
86
87
# File 'lib/authentication.rb', line 85

def (fields)
  @fields = fields
end

.set_login_names(names) ⇒ Object



76
77
78
# File 'lib/authentication.rb', line 76

def (names)
  @names = names
end

.set_login_path(path) ⇒ Object

set the login path



40
41
42
# File 'lib/authentication.rb', line 40

def (path)
  @login = path
end

.set_logout_path(path) ⇒ Object



14
15
16
# File 'lib/authentication.rb', line 14

def set_logout_path(path)
  @logout = path
end

.set_unique_login_attribute_name(name) ⇒ Object



93
94
95
# File 'lib/authentication.rb', line 93

def (name)
  @unique_login = name
end

.set_user_data(value) ⇒ Object



127
128
129
# File 'lib/authentication.rb', line 127

def set_user_data(value)
  @user_data = value
end

.use_db_usersObject



101
102
103
# File 'lib/authentication.rb', line 101

def use_db_users
  @db_users[0]
end

.user_classObject



105
106
107
# File 'lib/authentication.rb', line 105

def user_class
  @db_users[1]
end