Patch #16069 » Add-validation-to-api-limit.patch
| app/models/setting.rb | ||
|---|---|---|
| 82 | 82 |
Big5-HKSCS |
| 83 | 83 |
TIS-620) |
| 84 | 84 | |
| 85 |
MINIMUM_API_LIMIT = 100 |
|
| 86 | ||
| 85 | 87 |
cattr_accessor :available_settings |
| 86 | 88 |
self.available_settings ||= {}
|
| 87 | 89 | |
| ... | ... | |
| 191 | 193 |
messages << [:mail_from, l('activerecord.errors.messages.invalid')]
|
| 192 | 194 |
end |
| 193 | 195 |
end |
| 196 |
if settings.key?(:api_limit) |
|
| 197 |
if settings[:api_limit].to_i < MINIMUM_API_LIMIT |
|
| 198 |
messages << [:api_limit, l('activerecord.errors.messages.greater_than_or_equal_to', MINIMUM_API_LIMIT)]
|
|
| 199 |
end |
|
| 200 |
end |
|
| 194 | 201 |
messages |
| 195 | 202 |
end |
| 196 | 203 | |
| test/unit/setting_test.rb | ||
|---|---|---|
| 145 | 145 |
end |
| 146 | 146 |
end |
| 147 | 147 |
end |
| 148 | ||
| 149 |
def test_api_limit_format_should_be_validated |
|
| 150 |
with_locale 'en' do |
|
| 151 |
errors = Setting.set_all_from_params({api_limit: (Setting::MINIMUM_API_LIMIT - 1).to_s})
|
|
| 152 |
assert_includes errors, [:api_limit, "must be greater than or equal to #{Setting::MINIMUM_API_LIMIT}"]
|
|
| 153 | ||
| 154 |
errors = Setting.set_all_from_params({api_limit: Setting::MINIMUM_API_LIMIT.to_s})
|
|
| 155 |
assert_nil errors |
|
| 156 |
end |
|
| 157 |
end |
|
| 148 | 158 |
end |
- « Previous
- 1
- …
- 4
- 5
- 6
- Next »