Validate Web address
When changing the address of an existing Web (or creating a new one), check that the new name is valid. (Reported by Richard Marquez.)
This commit is contained in:
parent
844ce0ed40
commit
c010e6b7a4
2 changed files with 17 additions and 2 deletions
|
@ -1,3 +1,5 @@
|
||||||
|
require 'instiki_stringsupport'
|
||||||
|
|
||||||
class Web < ActiveRecord::Base
|
class Web < ActiveRecord::Base
|
||||||
## Associations
|
## Associations
|
||||||
|
|
||||||
|
@ -15,8 +17,7 @@ class Web < ActiveRecord::Base
|
||||||
|
|
||||||
## Validations
|
## Validations
|
||||||
|
|
||||||
validates_uniqueness_of :address
|
validates_uniqueness_of :address, :message => 'already exists'
|
||||||
|
|
||||||
validates_length_of :color, :in => 3..6
|
validates_length_of :color, :in => 3..6
|
||||||
|
|
||||||
## Methods
|
## Methods
|
||||||
|
@ -203,6 +204,10 @@ class Web < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def validate_address
|
def validate_address
|
||||||
|
if ['create_system', 'create_web', 'delete_web', 'delete_files', 'web_list', ''].include?(address)
|
||||||
|
self.errors.add(:address, 'is not a valid address')
|
||||||
|
raise Instiki::ValidationError.new("\"#{address.purify.escapeHTML}\" #{errors.on(:address)}")
|
||||||
|
end
|
||||||
unless address == CGI.escape(address)
|
unless address == CGI.escape(address)
|
||||||
self.errors.add(:address, 'should contain only valid URI characters')
|
self.errors.add(:address, 'should contain only valid URI characters')
|
||||||
raise Instiki::ValidationError.new("#{self.class.human_attribute_name('address')} #{errors.on(:address)}")
|
raise Instiki::ValidationError.new("#{self.class.human_attribute_name('address')} #{errors.on(:address)}")
|
||||||
|
|
|
@ -56,6 +56,16 @@ class WebTest < ActiveSupport::TestCase
|
||||||
assert_raises(Instiki::ValidationError) {
|
assert_raises(Instiki::ValidationError) {
|
||||||
Web.create(:name => 'Wiki2', :address => "wiki\234", :password => '123')
|
Web.create(:name => 'Wiki2', :address => "wiki\234", :password => '123')
|
||||||
}
|
}
|
||||||
|
assert_raises(Instiki::ValidationError) {
|
||||||
|
Web.create(:name => 'Wiki2', :address => "web_list", :password => '123')
|
||||||
|
}
|
||||||
|
assert_raises(Instiki::ValidationError) {
|
||||||
|
Web.create(:name => 'Wiki2', :address => "", :password => '123')
|
||||||
|
}
|
||||||
|
assert_raises(Instiki::ValidationError) {
|
||||||
|
Web.create!(:name => 'Wiki2', :address => "", :password => '123')
|
||||||
|
Web.create(:name => 'Wiki2', :address => "", :password => '123')
|
||||||
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_new_page_linked_from_mother_page
|
def test_new_page_linked_from_mother_page
|
||||||
|
|
Loading…
Reference in a new issue