From cd1fd5b3c00094a6f52d0a6517fd0ef3607b375e Mon Sep 17 00:00:00 2001 From: Jens Kraemer Date: Fri, 10 May 2013 14:49:56 +0200 Subject: [PATCH] rename actions to create, fix the test --- app/controllers/notices_controller.rb | 22 ++++++++++++---------- config/routes.rb | 4 ++-- test/functional/notices_controller_test.rb | 18 ++++++++++-------- test/test_helper.rb | 3 --- 4 files changed, 24 insertions(+), 23 deletions(-) diff --git a/app/controllers/notices_controller.rb b/app/controllers/notices_controller.rb index d221929..52b9cf6 100644 --- a/app/controllers/notices_controller.rb +++ b/app/controllers/notices_controller.rb @@ -12,12 +12,12 @@ class NoticesController < ActionController::Base /^\d+:/ ] - def index_v2 + def create_v2 #logger.debug {"received v2 request:\n#{@notice.inspect}\nwith redmine_params:\n#{@redmine_params.inspect}"} create_or_update_issue @redmine_params, @notice end - def index + def create #logger.debug {"received v1 request:\n#{@notice.inspect}\nwith redmine_params:\n#{@redmine_params.inspect}"} notice = v2_notice_hash(@notice) #logger.debug {"transformed arguments:\n#{notice.inspect}"} @@ -76,7 +76,9 @@ def create_or_update_issue(redmine_params, notice) # set standard redmine issue fields issue.category = IssueCategory.find_by_name(redmine_params["category"]) unless redmine_params["category"].blank? issue.assigned_to = (User.find_by_login(redmine_params["assigned_to"]) || Group.find_by_lastname(redmine_params["assigned_to"])) unless redmine_params["assigned_to"].blank? - issue.priority_id = redmine_params["priority"] unless redmine_params["priority"].blank? + issue.priority_id = redmine_params["priority"].blank? ? + IssuePriority.default.id : + redmine_params["priority"] issue.description = description ensure_project_has_fields(project) @@ -195,7 +197,7 @@ def check_enabled def parse_request logger.debug { "hoptoad error notification:\n#{request.raw_post}" } case params[:action] - when 'index_v2' + when 'create_v2' if defined?(Nokogiri) @notice = HoptoadV2Notice.new request.raw_post @redmine_params = @notice.redmine_params @@ -206,7 +208,7 @@ def parse_request @notice['error']['backtrace'] = @notice['error']['backtrace']['line'] @redmine_params = YAML.load(@notice['api_key'], :safe => true) end - when 'index' + when 'create' @notice = YAML.load(request.raw_post, :safe => true)['notice'] @redmine_params = YAML.load(@notice['api_key'], :safe => true) else @@ -226,31 +228,31 @@ def find_or_create_custom_fields @error_class_field = IssueCustomField.find_or_initialize_by_name('Error class') if @error_class_field.new_record? @error_class_field.attributes = {:field_format => 'string', :searchable => true, :is_filter => true} - @error_class_field.save(false) + @error_class_field.save(:validate => false) end @occurences_field = IssueCustomField.find_or_initialize_by_name('# Occurences') if @occurences_field.new_record? @occurences_field.attributes = {:field_format => 'int', :default_value => '0', :is_filter => true} - @occurences_field.save(false) + @occurences_field.save(:validate => false) end @environment_field = IssueCustomField.find_or_initialize_by_name('Environment') if @environment_field.new_record? @environment_field.attributes = {:field_format => 'string', :searchable => true, :is_filter => true} - @environment_field.save(false) + @environment_field.save(:validate => false) end @trace_filter_field = ProjectCustomField.find_or_initialize_by_name('Backtrace filter') if @trace_filter_field.new_record? @trace_filter_field.attributes = {:field_format => 'text'} - @trace_filter_field.save(false) + @trace_filter_field.save(:validate => false) end @repository_root_field = ProjectCustomField.find_or_initialize_by_name('Repository root') if @repository_root_field.new_record? @repository_root_field.attributes = {:field_format => 'string'} - @repository_root_field.save(false) + @repository_root_field.save(:validate => false) end end diff --git a/config/routes.rb b/config/routes.rb index 6494566..b052e1f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,7 +1,7 @@ # API v1 (hoptoad) -post 'notices', :to => 'notices#index' +post 'notices', :to => 'notices#create' # API v2 (hoptoad / airbrake, xml based) -post 'notifier_api/v2/notices', :to => 'notices#index_v2' +post 'notifier_api/v2/notices', :to => 'notices#create_v2' diff --git a/test/functional/notices_controller_test.rb b/test/functional/notices_controller_test.rb index 8db8498..77fec25 100644 --- a/test/functional/notices_controller_test.rb +++ b/test/functional/notices_controller_test.rb @@ -1,7 +1,7 @@ require File.dirname(__FILE__) + '/../test_helper' class NoticesControllerTest < ActionController::TestCase - fixtures :projects, :users, :trackers, :projects_trackers + fixtures :projects, :users, :trackers, :projects_trackers, :enumerations, :issue_statuses def setup Setting.mail_handler_api_key = 'asdfghjk' @@ -12,13 +12,15 @@ def setup test 'should create an issue with journal entry' do assert_difference "Issue.count", 1 do assert_difference "Journal.count", 1 do - raw_post :index_v2, {}, create_error.to_xml + raw_post :create_v2, {}, create_error.to_xml end end assert_response :success - assert issue = Issue.find(:first, - :conditions => "subject like 'RuntimeError in vendor/plugins/redmine_hoptoad_server/test/functional/notices_controller_test.rb%'") + assert issue = Issue.where("subject like ?", + 'RuntimeError in plugins/redmine_hoptoad_server/test/functional/notices_controller_test.rb%' + ).first assert_equal(1, issue.journals.size) + assert_equal(6, issue.priority_id) assert occurences_field = IssueCustomField.find_by_name('# Occurences') assert occurences_value = issue.custom_value_for(occurences_field) assert_equal('1', occurences_value.value) @@ -26,7 +28,7 @@ def setup assert_no_difference 'Issue.count' do assert_difference "Journal.count", 1 do - raw_post :index_v2, {}, create_error.to_xml + raw_post :create_v2, {}, create_error.to_xml end end occurences_value.reload @@ -36,7 +38,7 @@ def setup test "should render 404 for non existing project" do assert_no_difference "Issue.count" do assert_no_difference "Journal.count" do - raw_post :index_v2, {}, create_error(:project => 'Unknown').to_xml + raw_post :create_v2, {}, create_error(:project => 'Unknown').to_xml end end assert_response 404 @@ -45,7 +47,7 @@ def setup test "should render 404 for non existing tracker" do assert_no_difference "Issue.count" do assert_no_difference "Journal.count" do - raw_post :index_v2, {}, create_error(:tracker => 'Unknown').to_xml + raw_post :create_v2, {}, create_error(:tracker => 'Unknown').to_xml end end assert_response 404 @@ -61,7 +63,7 @@ def create_error(options = {}) :project => @project.identifier, :tracker => @tracker.name, :api_key => 'asdfghjk', - :priority => 5 + :priority => 6 }.merge(options).to_yaml) end end diff --git a/test/test_helper.rb b/test/test_helper.rb index 9016719..0902a1f 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,9 +1,6 @@ # Load the normal Rails helper require File.expand_path(File.dirname(__FILE__) + '/../../../test/test_helper') -# Ensure that we are using the temporary fixture path -Engines::Testing.set_fixture_path - class ActionController::TestCase def raw_post(action, params, body = '')