Merge remote-tracking branch 'openstreetmap/pull/1347' into master
[rails.git] / test / models / client_application_test.rb
1 require "test_helper"
2
3 class ClientApplicationTest < ActiveSupport::TestCase
4   def test_url_valid
5     ok = ["http://example.com/test", "https://example.com/test"]
6     bad = ["", "ftp://example.com/test", "myapp://somewhere"]
7
8     ok.each do |url|
9       app = build(:client_application)
10       app.url = url
11       assert app.valid?, "#{url} is invalid, when it should be"
12     end
13
14     bad.each do |url|
15       app = build(:client_application)
16       app.url = url
17       assert !app.valid?, "#{url} is valid when it shouldn't be"
18     end
19   end
20
21   def test_support_url_valid
22     ok = ["", "http://example.com/test", "https://example.com/test"]
23     bad = ["ftp://example.com/test", "myapp://somewhere", "gibberish"]
24
25     ok.each do |url|
26       app = build(:client_application)
27       app.support_url = url
28       assert app.valid?, "#{url} is invalid, when it should be"
29     end
30
31     bad.each do |url|
32       app = build(:client_application)
33       app.support_url = url
34       assert !app.valid?, "#{url} is valid when it shouldn't be"
35     end
36   end
37
38   def test_callback_url_valid
39     ok = ["", "http://example.com/test", "https://example.com/test", "ftp://example.com/test", "myapp://somewhere"]
40     bad = ["gibberish"]
41
42     ok.each do |url|
43       app = build(:client_application)
44       app.callback_url = url
45       assert app.valid?, "#{url} is invalid, when it should be"
46     end
47
48     bad.each do |url|
49       app = build(:client_application)
50       app.callback_url = url
51       assert !app.valid?, "#{url} is valid when it shouldn't be"
52     end
53   end
54 end