yolk / mite-rb

The official ruby library for interacting with the RESTful mite.api.
http://mite.yo.lk/en/api
MIT License
21 stars 10 forks source link

Mite::Tracker.start not working as expected #5

Closed koppen closed 11 years ago

koppen commented 11 years ago

I get the following:

time_entry = Mite::TimeEntry.first(:params => {:at => 'today'})
# => #<Mite::TimeEntry:0x00000101ecfa98 @attributes={"billable"=>true, "created_at"=>"2012-11-29T22:05:48+01:00", "date_at"=>"2012-11-29", "id"=>14693669, "locked"=>false, "minutes"=>8, "project_id"=>625108, "revenue"=>0.0, "service_id"=>98557, "updated_at"=>"2012-11-29T22:23:52+01:00", "user_id"=>23934, "note"=>"", "user_name"=>"Jakob Skjerning", "customer_id"=>83878, "customer_name"=>"Open Source", "project_name"=>"mite-rb", "service_name"=>"Application development", "tracker"=>#<Mite::Tracker:0x00000101ecd8d8 @attributes={"since"=>"2012-11-29T22:23:12+01:00", "minutes"=>33}, @prefix_options={}, @persisted=false>}, @prefix_options={}, @persisted=true>
Mite::Tracker.start(time_entry)
# => ActiveResource::ResourceNotFound: Failed.  Response code = 404.  Response message = Not Found.

... which isn't quite what I expected.

Digging further it seems it is sending a PUT request to "/tracker/.json", ie without the id of the TimeEntry for whatever reason, which naturally results in a 404.

Running Ruby 1.9.3p194 with a gem list of

koppen commented 11 years ago

If I downgrade Active Resource to 3.0.x, making my gem list look like

the problem goes away. I'd have to dig further to figure out exactly what dependency is causing the problem.

koppen commented 11 years ago

Dug a little further: Starting with ActiveResource 3.1.0 the behavior of ActiveResource::Base#persisted? was changed. The following code behaves differently:

# 3.0.9:
Mite::Tracker.new(:id => 42).persisted? #=> true
# 3.1.0:
Mite::Tracker.new(:id => 42).persisted? #=> false

This then causes the return value of element_path to change, since it returns nil when a resource hasn't been persisted. And that causes Mite::Tracker#start to use the wrong URL.

yolk commented 11 years ago

Hi Jakob,

thx for your detailed description of the issue. I'll look into it during the coming days.

Best, Sebastian.

koppen commented 11 years ago

I'll race ya ;)

I suspect it's a matter of simply fetching the actual TimeEntry from the API instead of only building it locally, but I just haven't taken the time to try it out yet.

yolk commented 11 years ago

Fixed in version v0.5.0

From this version mite-rb only supports activeresource 3.1 and up.

Thanks for reporting! Sebastian