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