@@ -122,13 +122,7 @@ class AgentsController < ApplicationController |
||
122 | 122 |
@agent = current_user.agents.find(params[:id]) |
123 | 123 |
|
124 | 124 |
respond_to do |format| |
125 |
- if @agent.with_transaction_returning_status { |
|
126 |
- @agent.attributes = params[:agent] |
|
127 |
- if params[:drop_pending_events] && @agent.can_receive_events? |
|
128 |
- @agent.set_last_checked_event_id |
|
129 |
- end |
|
130 |
- @agent.save |
|
131 |
- } |
|
125 |
+ if @agent.update_attributes(params[:agent]) |
|
132 | 126 |
format.html { redirect_back "'#{@agent.name}' was successfully updated." } |
133 | 127 |
format.json { render json: @agent, status: :ok, location: agent_path(@agent) } |
134 | 128 |
else |
@@ -22,7 +22,7 @@ class Agent < ActiveRecord::Base |
||
22 | 22 |
|
23 | 23 |
EVENT_RETENTION_SCHEDULES = [["Forever", 0], ["1 day", 1], *([2, 3, 4, 5, 7, 14, 21, 30, 45, 90, 180, 365].map {|n| ["#{n} days", n] })] |
24 | 24 |
|
25 |
- attr_accessible :options, :memory, :name, :type, :schedule, :controller_ids, :control_target_ids, :disabled, :source_ids, :scenario_ids, :keep_events_for, :propagate_immediately |
|
25 |
+ attr_accessible :options, :memory, :name, :type, :schedule, :controller_ids, :control_target_ids, :disabled, :source_ids, :scenario_ids, :keep_events_for, :propagate_immediately, :drop_pending_events |
|
26 | 26 |
|
27 | 27 |
json_serialize :options, :memory |
28 | 28 |
|
@@ -196,6 +196,14 @@ class Agent < ActiveRecord::Base |
||
196 | 196 |
update_column :last_error_log_at, nil |
197 | 197 |
end |
198 | 198 |
|
199 |
+ def drop_pending_events |
|
200 |
+ false |
|
201 |
+ end |
|
202 |
+ |
|
203 |
+ def drop_pending_events=(bool) |
|
204 |
+ set_last_checked_event_id if bool |
|
205 |
+ end |
|
206 |
+ |
|
199 | 207 |
# Callbacks |
200 | 208 |
|
201 | 209 |
def set_default_schedule |
@@ -66,8 +66,8 @@ |
||
66 | 66 |
<%= form_for(agent, as: :agent, url: agent_path(agent, return: returnTo), method: 'PUT') do |f| %> |
67 | 67 |
<% if agent.disabled && agent.can_receive_events? %> |
68 | 68 |
<div class="form-group"> |
69 |
- <%= check_box_tag check_box_id = "agent#{agent.id}_drop_pending_events", 'true', false, name: :drop_pending_events %> |
|
70 |
- <%= label_tag check_box_id, 'Drop pending events' %> |
|
69 |
+ <%= f.check_box :drop_pending_events %> |
|
70 |
+ <%= f.label :drop_pending_events, 'Drop pending events' %> |
|
71 | 71 |
<span class="glyphicon glyphicon-question-sign hover-help" data-content="As soon as you enable this agent, it starts to receive pending events that have not been processed while it was disabled. To prevent that from happening, you can check this option."></span> |
72 | 72 |
</div> |
73 | 73 |
<% end %> |
@@ -258,7 +258,7 @@ describe AgentsController do |
||
258 | 258 |
agent.disabled = true |
259 | 259 |
agent.last_checked_event_id = nil |
260 | 260 |
agent.save! |
261 |
- post :update, id: agents(:bob_website_agent).to_param, agent: { disabled: 'false' }, drop_pending_events: true |
|
261 |
+ post :update, id: agents(:bob_website_agent).to_param, agent: { disabled: 'false', drop_pending_events: 'true' } |
|
262 | 262 |
agent.reload |
263 | 263 |
agent.disabled.should == false |
264 | 264 |
agent.last_checked_event_id.should == Event.maximum(:id) |
@@ -852,4 +852,18 @@ describe AgentDrop do |
||
852 | 852 |
interpolate(t, @wsa2).should eq('1: Formatter') |
853 | 853 |
interpolate(t, @efa).should eq('0: ') |
854 | 854 |
end |
855 |
+ |
|
856 |
+ describe 'last_checked_event_id' do |
|
857 |
+ it "should be updated by setting drop_pending_events to true" do |
|
858 |
+ @wsa1.last_checked_event_id = nil |
|
859 |
+ @wsa1.save! |
|
860 |
+ @wsa1.update!(drop_pending_events: true) |
|
861 |
+ @wsa1.reload.last_checked_event_id.should == Event.maximum(:id) |
|
862 |
+ end |
|
863 |
+ |
|
864 |
+ it "should not affect a virtual attribute drop_pending_events" do |
|
865 |
+ @wsa1.update!(drop_pending_events: true) |
|
866 |
+ @wsa1.reload.drop_pending_events.should == false |
|
867 |
+ end |
|
868 |
+ end |
|
855 | 869 |
end |