Skip to content

Instantly share code, notes, and snippets.

@creich
Created October 26, 2012 09:09
Show Gist options
  • Save creich/3957768 to your computer and use it in GitHub Desktop.
Save creich/3957768 to your computer and use it in GitHub Desktop.
context "with :tt_log_time permission only" do
setup do
Role.find(2).add_permission! :tt_log_time
end
should "update only TT -comments and -round on own trackers" do
put :update, {:time_tracker => {:comments => "new comment"}}
assert_response :success
tt = TimeTracker.where(:id => 1).first
assert_equal("new comment", tt.comments, "updated TT-comment")
put :update, {:time_tracker => {:round => true}}
assert_response :success
tt = TimeTracker.where(:id => 1).first
assert_equal(true, tt.round, "updated TT-round")
put :update, {:time_tracker => {:issue_id => 2}}
assert_response :success
assert_equal(I18n.t(:tt_error_not_allowed_to_change_logs), flash[:error], "flashing the right error")
tt = TimeTracker.where(:id => 1).first
assert_equal(1, tt.issue_id, "illegally updated TT-issue_id")
put :update, {:time_tracker => {:issue_id => nil, :project_id => nil}}
assert_response :success
assert_equal(I18n.t(:tt_error_not_allowed_to_change_logs), flash[:error], "flashing the right error")
tt = TimeTracker.where(:id => 1).first
assert_equal(1, tt.issue_id, "illegally nullified issue_id")
assert_equal(1, tt.project_id, "illegally updated TT-project_id")
put :update, {:time_tracker => {:start_time => "10:23:42", :date => "2012-10-23"}}
assert_response :success
assert_equal(I18n.t(:tt_error_not_allowed_to_change_logs), flash[:error], "flashing the right error")
tt = TimeTracker.where(:id => 1).first
assert_equal("11:47:03", tt.started_on.to_time.strftime("%H:%M:%S"), "illegally updated TT-start_time")
assert_equal("2012-10-25", tt.started_on.to_date.to_s(:db), "illegally updated TT-date")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment