diff --git a/README.rdoc b/README.rdoc index f1afbc5..b146399 100644 --- a/README.rdoc +++ b/README.rdoc @@ -1,22 +1,10 @@ -= Harvest Plugin For Redmine - -==Overview - -The object of this plugin is to sync timesheet data from {Harvest}[http://www.getharvest.com/] with individual projects within Redmine. When activated, this plugin will include a new "Harvest" tab and a "Harvest Time" section on the issue detail page with a summed up total of hours tied to a Redmine issue. Harvest time entries are tied to Redmine issues by included #ticket_no (ie #1234) in the text portion of the timesheet entry. - -Currently, data is automatically imported for the past week's worth of data every time a user goes to the "Harvest" tab of a particular Redmine project. += harvest ==Installation - Install the plugin as described at: http://www.redmine.org/wiki/redmine/Plugins, according to the way you've obtained the plugin (this plugin does not require a plugin database migration) -- Install the {Harvestr}[http://github.com/squeejee/harvestr] plugin - Restart Redmine -- Create a "config/harvest.yml" file with the following: - domain: - email: - password: - ==Global setup Before you can actually use the plugin within the preferred projects some setup has to be done first. diff --git a/app/.DS_Store b/app/.DS_Store new file mode 100644 index 0000000..a8f0fe3 Binary files /dev/null and b/app/.DS_Store differ diff --git a/app/models/harvest_time.rb b/app/models/harvest_time.rb index a26ad18..718cb2c 100644 --- a/app/models/harvest_time.rb +++ b/app/models/harvest_time.rb @@ -40,7 +40,17 @@ def self.import_time(project) ht = HarvestTime.find_or_create_by_id(entry.id) - ht.update_attributes(entry.to_hash) + # Key names from the Harvest API + harvest_keys = entry.to_hash.keys + + # Column names of HarvestTime + harvest_time_keys = HarvestTime.column_names + + # These keys are not in our db, so do not try to include with the insert / update + excess_keys = harvest_keys - harvest_time_keys + entry_hash = entry.to_hash.reject {|k,v| excess_keys.include?(k)} + + ht.update_attributes(entry_hash) end if harvest_entries end diff --git a/init.rb b/init.rb index 82f1f70..df3a5cd 100644 --- a/init.rb +++ b/init.rb @@ -15,7 +15,7 @@ name 'Redmine Harvest plugin' author 'Jim Mulholland' description 'This is a plugin for Redmine to import project timesheet data from Harvest.' - version '0.0.1' + version '0.0.2' # This plugin contains settings settings :default => { diff --git a/test/fixtures/harvest_project_entries_extra_attr.xml b/test/fixtures/harvest_project_entries_extra_attr.xml new file mode 100644 index 0000000..bf3fcd8 --- /dev/null +++ b/test/fixtures/harvest_project_entries_extra_attr.xml @@ -0,0 +1,31 @@ + + + + 2009-08-01T02:21:32Z + 4.5 + 14316565 + false + false + This is a test + 408960 + 2009-07-31 + 333865 + + 86342 + New attribute added to api + + + 2009-08-01T02:21:46Z + 2.0 + 14316569 + false + false + Ticket #1234 - Working on stuff + 408960 + 2009-07-31 + 333867 + + 86342 + New attribute added to api + + diff --git a/test/unit/harvest_times_test.rb b/test/unit/harvest_times_test.rb index 8ad6b40..8ec45b2 100644 --- a/test/unit/harvest_times_test.rb +++ b/test/unit/harvest_times_test.rb @@ -32,5 +32,13 @@ class HarvestTimesTest < ActiveSupport::TestCase should "extract out integers prepended by # and store as issue_id" do assert HarvestTime.find(14316569).issue_id == 1234 end + + should "be successful if attributes are added to Harvest api" do + url = /http:\/\/test%40example.com:OU812@testing.harvestapp.com\/projects\/408960\/entries.*/ + stub_get url, 'harvest_project_entries_extra_attr.xml' + project = Project.first + assert HarvestTime.import_time(project) + end + end end