Skip to content

Commit

Permalink
Fix functional test
Browse files Browse the repository at this point in the history
  • Loading branch information
lacek committed Feb 3, 2016
1 parent 87d040d commit 967b8ab
Showing 1 changed file with 35 additions and 3 deletions.
38 changes: 35 additions & 3 deletions test/functional/github_hook_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,21 @@ def project
end

def setup
Setting.sys_api_enabled = '1'
Setting.sys_api_key = 'my_secret_key'
Project.stubs(:find_by_identifier).with("github").returns(project)

# Make sure we don't run actual commands in test
GithubHook::Updater.any_instance.expects(:system).never
Repository.expects(:fetch_changesets).never
end

def do_post
post :index, :payload => json
def teardown
Setting.clear_cache
end

def do_post(key: 'my_secret_key')
post :index, :payload => json, :key => key
end

def test_should_render_response_from_github_hook_when_done
Expand All @@ -83,6 +89,27 @@ def test_should_render_response_from_github_hook_when_done
assert_match "GithubHook: Redmine repository updated", @response.body
end

def test_should_render_response_from_github_hook_when_done_with_empty_sys_api_key
GithubHook::Updater.any_instance.expects(:update_repository).returns(true)
with_settings :sys_api_key => '' do
do_post :key => 'wrong_key'
end
assert_response :success
assert_match "GithubHook: Redmine repository updated", @response.body
end

def test_disabled_ws_should_respond_with_403
with_settings :sys_api_enabled => '0' do
do_post
assert_response 403
end
end

def test_wrong_key_should_respond_with_403
do_post :key => 'wrong_key'
assert_response 403
end

def test_should_render_error_message
GithubHook::Updater
.any_instance
Expand Down Expand Up @@ -115,7 +142,12 @@ def test_exec_should_log_output_from_git_as_error_when_things_go_sour
end

def test_should_respond_to_get
get :index
get :index, :key => 'my_secret_key'
assert_response :success
end

def test_wrong_key_should_respond_to_get_with_403
get :index, :key => 'wrong_key'
assert_response 403
end
end

0 comments on commit 967b8ab

Please sign in to comment.