Project

General

Profile

Defect #32774 » 0001-Fix-creating-time-tracking-entry-through-rest-API-do.patch

Marius BĂLTEANU, 2020-01-12 23:51

View differences:

app/controllers/timelog_controller.rb
288 288
    end
289 289
  end
290 290

  
291
  def find_optional_project
292
    if params[:project_id].present? || params[:time_entry].present? && params[:time_entry][:project_id].present?
293
      project_id = params[:project_id] || params[:time_entry][:project_id]
294
      find_project(project_id)
295
    end
296
    authorize_global
297
  end
298

  
291 299
  # Returns the TimeEntry scope for index and report actions
292 300
  def time_entry_scope(options={})
293 301
    @query.results_scope(options)
test/integration/api_test/time_entries_test.rb
144 144
    assert_select 'errors error', :text => "Hours cannot be blank"
145 145
  end
146 146

  
147
  test "POST /time_entries.xml for other user" do
148
    Role.find_by_name('Manager').add_permission! :log_time_for_other_users
149

  
150
    assert_difference 'TimeEntry.count' do
151
      post(
152
        '/time_entries.xml',
153
        :params =>
154
          {:time_entry =>
155
            {:project_id => '1', :spent_on => '2010-12-02', :user_id => '3',
156
             :hours => '3.5', :activity_id => '11'}},
157
        :headers => credentials('jsmith'))
158
    end
159
    assert_response :created
160

  
161
    assert_equal 'application/xml', @response.content_type
162

  
163
    entry = TimeEntry.order('id DESC').first
164
    assert_equal 3, entry.user_id
165
    assert_equal 2, entry.author_id
166
  end
167

  
147 168
  test "PUT /time_entries/:id.xml with valid parameters should update time entry" do
148 169
    assert_no_difference 'TimeEntry.count' do
149 170
      put(
    (1-1/1)