54 lines
1.7 KiB
Ruby
54 lines
1.7 KiB
Ruby
require "test_helper"
|
|
|
|
class ClientApplicationTest < ActiveSupport::TestCase
|
|
def test_url_valid
|
|
ok = ["http://example.com/test", "https://example.com/test"]
|
|
bad = ["", "ftp://example.com/test", "myapp://somewhere", "http://example.com\nhttp://example.net"]
|
|
|
|
ok.each do |url|
|
|
app = build(:client_application)
|
|
app.url = url
|
|
assert_predicate app, :valid?, "#{url} is invalid, when it should be"
|
|
end
|
|
|
|
bad.each do |url|
|
|
app = build(:client_application)
|
|
app.url = url
|
|
assert_not app.valid?, "#{url} is valid when it shouldn't be"
|
|
end
|
|
end
|
|
|
|
def test_support_url_valid
|
|
ok = ["", "http://example.com/test", "https://example.com/test"]
|
|
bad = ["ftp://example.com/test", "myapp://somewhere", "gibberish", "http://example.com\nhttp://example.net"]
|
|
|
|
ok.each do |url|
|
|
app = build(:client_application)
|
|
app.support_url = url
|
|
assert_predicate app, :valid?, "#{url} is invalid, when it should be"
|
|
end
|
|
|
|
bad.each do |url|
|
|
app = build(:client_application)
|
|
app.support_url = url
|
|
assert_not app.valid?, "#{url} is valid when it shouldn't be"
|
|
end
|
|
end
|
|
|
|
def test_callback_url_valid
|
|
ok = ["", "http://example.com/test", "https://example.com/test", "ftp://example.com/test", "myapp://somewhere"]
|
|
bad = ["gibberish", "http://example.com\nhttp://example.net"]
|
|
|
|
ok.each do |url|
|
|
app = build(:client_application)
|
|
app.callback_url = url
|
|
assert_predicate app, :valid?, "#{url} is invalid, when it should be"
|
|
end
|
|
|
|
bad.each do |url|
|
|
app = build(:client_application)
|
|
app.callback_url = url
|
|
assert_not app.valid?, "#{url} is valid when it shouldn't be"
|
|
end
|
|
end
|
|
end
|