From: Andy Allan Date: Thu, 26 Jan 2017 18:03:13 +0000 (+0000) Subject: Convert client applications fixtures into a factory X-Git-Tag: live~3658 X-Git-Url: https://git.openstreetmap.org/rails.git/commitdiff_plain/8a6e8ae128d3cc9a991d119c45b9ddb13e848f97 Convert client applications fixtures into a factory Closes #1415 --- diff --git a/test/controllers/oauth_clients_controller_test.rb b/test/controllers/oauth_clients_controller_test.rb index a1c6fbc21..020521bac 100644 --- a/test/controllers/oauth_clients_controller_test.rb +++ b/test/controllers/oauth_clients_controller_test.rb @@ -1,7 +1,7 @@ require "test_helper" class OauthClientsControllerTest < ActionController::TestCase - fixtures :users, :client_applications + fixtures :users ## # test all routes which lead to this controller @@ -38,6 +38,7 @@ class OauthClientsControllerTest < ActionController::TestCase def test_index user = users(:public_user) + create_list(:client_application, 2, :user => user) get :index, :display_name => user.display_name assert_response :redirect @@ -104,13 +105,14 @@ class OauthClientsControllerTest < ActionController::TestCase def test_show user = users(:public_user) - client = client_applications(:oauth_web_app) + client = create(:client_application, :user => user) + other_client = create(:client_application) get :show, :display_name => user.display_name, :id => client.id assert_response :redirect assert_redirected_to login_path(:referer => oauth_client_path(:display_name => user.display_name, :id => client.id)) - get :show, { :display_name => user.display_name, :id => client_applications(:normal_user_app).id }, { :user => user } + get :show, { :display_name => user.display_name, :id => other_client.id }, { :user => user } assert_response :not_found assert_template "not_found" @@ -121,13 +123,14 @@ class OauthClientsControllerTest < ActionController::TestCase def test_edit user = users(:public_user) - client = client_applications(:oauth_web_app) + client = create(:client_application, :user => user) + other_client = create(:client_application) get :edit, :display_name => user.display_name, :id => client.id assert_response :redirect assert_redirected_to login_path(:referer => edit_oauth_client_path(:display_name => user.display_name, :id => client.id)) - get :edit, { :display_name => user.display_name, :id => client_applications(:normal_user_app).id }, { :user => user } + get :edit, { :display_name => user.display_name, :id => other_client.id }, { :user => user } assert_response :not_found assert_template "not_found" @@ -147,12 +150,13 @@ class OauthClientsControllerTest < ActionController::TestCase def test_update user = users(:public_user) - client = client_applications(:oauth_web_app) + client = create(:client_application, :user => user) + other_client = create(:client_application) put :update, :display_name => user.display_name, :id => client.id assert_response :forbidden - put :update, { :display_name => user.display_name, :id => client_applications(:normal_user_app).id }, { :user => user } + put :update, { :display_name => user.display_name, :id => other_client.id }, { :user => user } assert_response :not_found assert_template "not_found" @@ -181,7 +185,8 @@ class OauthClientsControllerTest < ActionController::TestCase def test_destroy user = users(:public_user) - client = client_applications(:oauth_web_app) + client = create(:client_application, :user => user) + other_client = create(:client_application) assert_difference "ClientApplication.count", 0 do delete :destroy, :display_name => user.display_name, :id => client.id @@ -189,7 +194,7 @@ class OauthClientsControllerTest < ActionController::TestCase assert_response :forbidden assert_difference "ClientApplication.count", 0 do - delete :destroy, { :display_name => user.display_name, :id => client_applications(:normal_user_app).id }, { :user => user } + delete :destroy, { :display_name => user.display_name, :id => other_client.id }, { :user => user } end assert_response :not_found assert_template "not_found" diff --git a/test/controllers/site_controller_test.rb b/test/controllers/site_controller_test.rb index d559760af..5efddd52e 100644 --- a/test/controllers/site_controller_test.rb +++ b/test/controllers/site_controller_test.rb @@ -6,8 +6,8 @@ class SiteControllerTest < ActionController::TestCase ## # setup oauth keys def setup - Object.const_set("ID_KEY", client_applications(:oauth_web_app).key) - Object.const_set("POTLATCH2_KEY", client_applications(:oauth_web_app).key) + Object.const_set("ID_KEY", create(:client_application).key) + Object.const_set("POTLATCH2_KEY", create(:client_application).key) stub_hostip_requests end diff --git a/test/factories/client_applications.rb b/test/factories/client_applications.rb new file mode 100644 index 000000000..413dc57c9 --- /dev/null +++ b/test/factories/client_applications.rb @@ -0,0 +1,6 @@ +FactoryGirl.define do + factory :client_application do + sequence(:name) { |n| "Client application #{n}" } + sequence(:url) { |n| "http://example.com/app/#{n}" } + end +end diff --git a/test/fixtures/client_applications.yml b/test/fixtures/client_applications.yml deleted file mode 100644 index 13f9c086a..000000000 --- a/test/fixtures/client_applications.yml +++ /dev/null @@ -1,50 +0,0 @@ -# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html - -oauth_web_app: - name: Some OAuth Web App - created_at: "2009-04-21 00:00:00" - support_url: http://some.web.app.org/support - updated_at: "2009-04-21 00:00:00" - callback_url: http://some.web.app.org/callback - url: http://some.web.app.org/ - user_id: 2 - secret: Ur1s9LWWJJuYBiV9cDi3za3OV8TGCoRgUvVXJ5zp7pc - key: ewvENqsaTXFnZbMWmGDX2g - allow_read_prefs: true - allow_write_prefs: false - allow_write_diary: false - allow_write_api: true - allow_read_gpx: true - allow_write_gpx: false - -oauth_desktop_app: - name: Some OAuth Desktop App - created_at: "2009-04-21 00:00:00" - url: http://some.desktop.app.org/ - support_url: http://some.desktop.app.org/support - updated_at: "2009-04-21 00:00:00" - user_id: 2 - secret: V9DOm1H5qSdIG9IeCTiOkAcCx15bK8bkGxf7XEpF - key: rlEdPM6Tp8lpLwvSyNJQ4w - allow_read_prefs: true - allow_write_prefs: false - allow_write_diary: false - allow_write_api: true - allow_read_gpx: true - allow_write_gpx: false - -normal_user_app: - name: Some OAuth Desktop App - created_at: "2009-05-21 00:00:00" - url: http://some.desktop.app.org/ - support_url: http://some.desktop.app.org/support - updated_at: "2009-05-21 00:00:00" - user_id: 1 - secret: jgYx43yx1FAMQbG6T0qZhvvFsKEf6Pgd5XfHr5kFgv4 - key: N6KVhfeaT626fhBt9aCMeA - allow_read_prefs: true - allow_write_prefs: false - allow_write_diary: false - allow_write_api: true - allow_read_gpx: true - allow_write_gpx: false diff --git a/test/integration/client_applications_test.rb b/test/integration/client_applications_test.rb index 2cc15bd56..f5d235d95 100644 --- a/test/integration/client_applications_test.rb +++ b/test/integration/client_applications_test.rb @@ -1,7 +1,7 @@ require "test_helper" class ClientApplicationsTest < ActionDispatch::IntegrationTest - fixtures :users, :client_applications + fixtures :users ## # run through the procedure of creating a client application and checking diff --git a/test/integration/oauth_test.rb b/test/integration/oauth_test.rb index c10699f2a..ceee95892 100644 --- a/test/integration/oauth_test.rb +++ b/test/integration/oauth_test.rb @@ -1,7 +1,7 @@ require "test_helper" class OAuthTest < ActionDispatch::IntegrationTest - fixtures :users, :client_applications, :gpx_files + fixtures :users, :gpx_files set_fixture_class :gpx_files => Trace include OAuth::Helper @@ -11,18 +11,18 @@ class OAuthTest < ActionDispatch::IntegrationTest end def test_oauth10_web_app - client = client_applications(:oauth_web_app) + client = create(:client_application, :callback_url => "http://some.web.app.example.org/callback", :user => users(:public_user), :allow_read_prefs => true, :allow_write_api => true, :allow_read_gpx => true) post_via_redirect "/login", :username => client.user.email, :password => "test" assert_response :success oauth10_without_callback(client) - oauth10_with_callback(client, "http://another.web.app.org/callback") + oauth10_with_callback(client, "http://another.web.app.example.org/callback") oauth10_refused(client) end def test_oauth10_desktop_app - client = client_applications(:oauth_desktop_app) + client = create(:client_application, :user => users(:public_user), :allow_read_prefs => true, :allow_write_api => true, :allow_read_gpx => true) post_via_redirect "/login", :username => client.user.email, :password => "test" assert_response :success @@ -32,18 +32,18 @@ class OAuthTest < ActionDispatch::IntegrationTest end def test_oauth10a_web_app - client = client_applications(:oauth_web_app) + client = create(:client_application, :callback_url => "http://some.web.app.example.org/callback", :user => users(:public_user), :allow_read_prefs => true, :allow_write_api => true, :allow_read_gpx => true) post_via_redirect "/login", :username => client.user.email, :password => "test" assert_response :success oauth10a_without_callback(client) - oauth10a_with_callback(client, "http://another.web.app.org/callback") + oauth10a_with_callback(client, "http://another.web.app.example.org/callback") oauth10a_refused(client) end def test_oauth10a_desktop_app - client = client_applications(:oauth_desktop_app) + client = create(:client_application, :user => users(:public_user), :allow_read_prefs => true, :allow_write_api => true, :allow_read_gpx => true) post_via_redirect "/login", :username => client.user.email, :password => "test" assert_response :success @@ -196,7 +196,7 @@ class OAuthTest < ActionDispatch::IntegrationTest if client.callback_url assert_response :redirect verifier = parse_verifier(response) - assert_redirected_to "http://some.web.app.org/callback?oauth_token=#{token.token}&oauth_verifier=#{verifier}" + assert_redirected_to "http://some.web.app.example.org/callback?oauth_token=#{token.token}&oauth_verifier=#{verifier}" else assert_response :success assert_template :authorize_success diff --git a/test/models/client_application_test.rb b/test/models/client_application_test.rb index 604a5de33..9684513c4 100644 --- a/test/models/client_application_test.rb +++ b/test/models/client_application_test.rb @@ -1,20 +1,18 @@ require "test_helper" class ClientApplicationTest < ActiveSupport::TestCase - fixtures :client_applications - def test_url_valid ok = ["http://example.com/test", "https://example.com/test"] bad = ["", "ftp://example.com/test", "myapp://somewhere"] ok.each do |url| - app = client_applications(:normal_user_app).dup + app = build(:client_application) app.url = url assert app.valid?, "#{url} is invalid, when it should be" end bad.each do |url| - app = client_applications(:normal_user_app) + app = build(:client_application) app.url = url assert !app.valid?, "#{url} is valid when it shouldn't be" end @@ -25,13 +23,13 @@ class ClientApplicationTest < ActiveSupport::TestCase bad = ["ftp://example.com/test", "myapp://somewhere", "gibberish"] ok.each do |url| - app = client_applications(:normal_user_app) + app = build(:client_application) app.support_url = url assert app.valid?, "#{url} is invalid, when it should be" end bad.each do |url| - app = client_applications(:normal_user_app) + app = build(:client_application) app.support_url = url assert !app.valid?, "#{url} is valid when it shouldn't be" end @@ -42,13 +40,13 @@ class ClientApplicationTest < ActiveSupport::TestCase bad = ["gibberish"] ok.each do |url| - app = client_applications(:normal_user_app) + app = build(:client_application) app.callback_url = url assert app.valid?, "#{url} is invalid, when it should be" end bad.each do |url| - app = client_applications(:normal_user_app) + app = build(:client_application) app.callback_url = url assert !app.valid?, "#{url} is valid when it shouldn't be" end diff --git a/test/models/oauth_token_test.rb b/test/models/oauth_token_test.rb index ac10bf7fe..c2df0d131 100644 --- a/test/models/oauth_token_test.rb +++ b/test/models/oauth_token_test.rb @@ -15,7 +15,7 @@ class OauthTokenTest < ActiveSupport::TestCase ## # check that an authorized token is authorised and can be invalidated def test_token_authorisation - tok = RequestToken.create(:client_application => client_applications(:oauth_web_app)) + tok = RequestToken.create(:client_application => create(:client_application)) assert_equal false, tok.authorized?, "Token should be created unauthorised." tok.authorize!(users(:public_user)) assert_equal true, tok.authorized?, "Token should now be authorised." diff --git a/test/test_helper.rb b/test/test_helper.rb index 9633989cd..e535d1645 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -50,8 +50,6 @@ module ActiveSupport set_fixture_class :gps_points => Tracepoint set_fixture_class :gpx_file_tags => Tracetag - fixtures :client_applications - fixtures :redactions end