Module: AutoTest::Authentication
- Defined in:
- lib/authentication.rb
Class Method Summary collapse
-
.get_login_attributes ⇒ Object
return the login attributes.
- .get_login_data ⇒ Object
- .get_login_fields ⇒ Object
- .get_login_names ⇒ Object
-
.get_login_path ⇒ Object
get the login path.
- .get_logout_path ⇒ Object
- .get_unique_login_attribute_name ⇒ Object
- .get_user_data ⇒ Object
-
.get_users ⇒ Object
return the users.
- .get_users_from_db(user_class_name, bool) ⇒ Object
- .init_login_data ⇒ Object
-
.init_users ⇒ Object
initialize the @users array.
-
.login(user, session) ⇒ Object
login a user.
- .logout(session) ⇒ Object
-
.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.
- .set_login_data(*data) ⇒ Object
- .set_login_fields(fields) ⇒ Object
- .set_login_names(names) ⇒ Object
-
.set_login_path(path) ⇒ Object
set the login path.
- .set_logout_path(path) ⇒ Object
- .set_unique_login_attribute_name(name) ⇒ Object
- .set_user_data(value) ⇒ Object
- .use_db_users ⇒ Object
- .user_class ⇒ Object
Class Method Details
.get_login_attributes ⇒ Object
return the login attributes
31 32 33 |
# File 'lib/authentication.rb', line 31 def get_login_attributes @login_attributes end |
.get_login_data ⇒ Object
50 51 52 |
# File 'lib/authentication.rb', line 50 def get_login_data @data end |
.get_login_fields ⇒ Object
83 84 85 |
# File 'lib/authentication.rb', line 83 def get_login_fields @fields end |
.get_login_names ⇒ Object
74 75 76 |
# File 'lib/authentication.rb', line 74 def get_login_names @names end |
.get_login_path ⇒ Object
get the login path
36 37 38 |
# File 'lib/authentication.rb', line 36 def get_login_path @login end |
.get_logout_path ⇒ Object
19 20 21 |
# File 'lib/authentication.rb', line 19 def get_logout_path @logout end |
.get_unique_login_attribute_name ⇒ Object
91 92 93 |
# File 'lib/authentication.rb', line 91 def get_unique_login_attribute_name @unique_login end |
.get_user_data ⇒ Object
124 125 126 |
# File 'lib/authentication.rb', line 124 def get_user_data @user_data end |
.get_users ⇒ Object
return the users
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/authentication.rb', line 104 def get_users if @db_users[0] then @users = @db_users[1].find(:all) else index = get_login_names.index(get_unique_login_attribute_name) @users = [] @db_users[1].find(:all).each do |u| get_login_data.each do |d| if d[index] == u.send(get_unique_login_attribute_name.to_sym) then @users << u end end end end end |
.get_users_from_db(user_class_name, bool) ⇒ Object
61 62 63 64 65 66 67 68 |
# File 'lib/authentication.rb', line 61 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_data ⇒ Object
46 47 48 |
# File 'lib/authentication.rb', line 46 def init_login_data @data = [] end |
.init_users ⇒ Object
initialize the @users array
9 10 11 12 |
# File 'lib/authentication.rb', line 9 def init_users @users = [] @db_users = [false, nil] end |
.login(user, session) ⇒ Object
login a user
141 142 143 144 145 146 147 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 |
# File 'lib/authentication.rb', line 141 def login(user, session) begin session.visit get_login_path user = user.class.find(user.id) hash = Hash.new hash["#{Test.get_sessions_array.index(session)}:#{session.current_path}"] = Page.all_submits(session).first.value Test.add_to_action_path hash Page.check_for_error_code(session) index = get_login_names.index(get_unique_login_attribute_name) @db_users[1].find(:all).each do |u| get_login_data.each do |d| if d[index] == u.send(get_unique_login_attribute_name.to_sym) then set_user_data(get_login_data[index]) end end end if @db_users[0] then get_login_attributes.each do |field| session.fill_in field[1], :with => user.send(field[0].to_sym) end else get_login_attributes.each_with_index do |field, i| session.fill_in field[1], :with => get_user_data[i] end end session. Page.all_submits(session).first.value 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
129 130 131 132 133 134 135 136 137 138 |
# File 'lib/authentication.rb', line 129 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
26 27 28 |
# File 'lib/authentication.rb', line 26 def set_login_attribute_names(names, fields) @login_attributes = names.zip fields end |
.set_login_data(*data) ⇒ Object
54 55 56 57 58 59 |
# File 'lib/authentication.rb', line 54 def set_login_data(*data) data.each do |d| @data << d end end |
.set_login_fields(fields) ⇒ Object
79 80 81 |
# File 'lib/authentication.rb', line 79 def set_login_fields(fields) @fields = fields end |
.set_login_names(names) ⇒ Object
70 71 72 |
# File 'lib/authentication.rb', line 70 def set_login_names(names) @names = names end |
.set_login_path(path) ⇒ Object
set the login path
41 42 43 |
# File 'lib/authentication.rb', line 41 def set_login_path(path) @login = path end |
.set_logout_path(path) ⇒ Object
15 16 17 |
# File 'lib/authentication.rb', line 15 def set_logout_path(path) @logout = path end |
.set_unique_login_attribute_name(name) ⇒ Object
87 88 89 |
# File 'lib/authentication.rb', line 87 def set_unique_login_attribute_name(name) @unique_login = name end |
.set_user_data(value) ⇒ Object
120 121 122 |
# File 'lib/authentication.rb', line 120 def set_user_data(value) @user_data = value end |
.use_db_users ⇒ Object
95 96 97 |
# File 'lib/authentication.rb', line 95 def use_db_users @db_users[0] end |
.user_class ⇒ Object
99 100 101 |
# File 'lib/authentication.rb', line 99 def user_class @db_users[1] end |