Defect #28686 ยป 0001-users-API-accepts-boolean-strings-for-generate_passw.patch
app/models/user.rb | ||
---|---|---|
354 | 354 |
end |
355 | 355 | |
356 | 356 |
def generate_password? |
357 |
generate_password == '1' || generate_password == true
|
|
357 |
ActiveRecord::Type::Boolean.new.deserialize(generate_password)
|
|
358 | 358 |
end |
359 | 359 | |
360 | 360 |
# Generate and set a random password on given length |
test/integration/api_test/users_test.rb | ||
---|---|---|
152 | 152 |
assert_select 'user id', :text => user.id.to_s |
153 | 153 |
end |
154 | 154 | |
155 |
test "POST /users.xml with generate_password should generate password" do |
|
156 |
assert_difference('User.count') do |
|
157 |
post '/users.xml', |
|
158 |
:params => { |
|
159 |
:user => { |
|
160 |
:login => 'foo', :firstname => 'Firstname', :lastname => 'Lastname', |
|
161 |
:mail => 'foo@example.net', :generate_password => 'true' |
|
162 |
} |
|
163 |
}, |
|
164 |
:headers => credentials('admin') |
|
165 |
end |
|
166 | ||
167 |
user = User.order('id DESC').first |
|
168 |
assert user.hashed_password.present? |
|
169 |
end |
|
170 | ||
155 | 171 |
test "POST /users.json with valid parameters should create the user" do |
156 | 172 |
assert_difference('User.count') do |
157 | 173 |
post '/users.json', |