| @@ -7,7 +7,7 @@ module AgentControllerConcern | ||
| 7 | 7 |  | 
| 8 | 8 | def default_options | 
| 9 | 9 |      { | 
| 10 | - 'action' => 'run', | |
| 10 | + 'action' => 'run' | |
| 11 | 11 | } | 
| 12 | 12 | end | 
| 13 | 13 |  | 
| @@ -68,7 +68,7 @@ module AgentControllerConcern | ||
| 68 | 68 |              log "Agent '#{target.name}' is disabled" | 
| 69 | 69 | end | 
| 70 | 70 | when 'configure' | 
| 71 | - target.update!(options: target.options.merge(interpolated['configure_options'])) | |
| 71 | + target.update! options: target.options.deep_merge(interpolated['configure_options']) | |
| 72 | 72 |            log "Agent '#{target.name}' is configured with #{interpolated['configure_options'].inspect}" | 
| 73 | 73 | when '' | 
| 74 | 74 | # Do nothing | 
| @@ -36,7 +36,7 @@ module Agents | ||
| 36 | 36 | true | 
| 37 | 37 | end | 
| 38 | 38 |  | 
| 39 | - def check! | |
| 39 | + def check | |
| 40 | 40 | control! | 
| 41 | 41 | end | 
| 42 | 42 |  | 
| @@ -87,7 +87,7 @@ module Agents | ||
| 87 | 87 | true | 
| 88 | 88 | end | 
| 89 | 89 |  | 
| 90 | - def check! | |
| 90 | + def check | |
| 91 | 91 | control! | 
| 92 | 92 | end | 
| 93 | 93 |  | 
| @@ -111,3 +111,24 @@ jane_basecamp_agent: | ||
| 111 | 111 | user: jane | 
| 112 | 112 | service: generic | 
| 113 | 113 | guid: <%= SecureRandom.hex %> | 
| 114 | + | |
| 115 | + | |
| 116 | +bob_data_output_agent: | |
| 117 | + type: Agents::DataOutputAgent | |
| 118 | + user: bob | |
| 119 | + name: RSS Feed | |
| 120 | + guid: <%= SecureRandom.hex %> | |
| 121 | +  options: <%= { | |
| 122 | + expected_receive_period_in_days: 3, | |
| 123 | + secrets: ['secret'], | |
| 124 | +    template: { | |
| 125 | + title: 'unchanged', | |
| 126 | + description: 'unchanged', | |
| 127 | +      item: { | |
| 128 | + title: 'unchanged', | |
| 129 | + description: 'unchanged', | |
| 130 | + author: 'unchanged', | |
| 131 | + link: 'http://example.com' | |
| 132 | + } | |
| 133 | + } | |
| 134 | + }.to_json.inspect %> | 
| @@ -19,10 +19,10 @@ describe Agents::CommanderAgent do | ||
| 19 | 19 |  | 
| 20 | 20 | it_behaves_like AgentControllerConcern | 
| 21 | 21 |  | 
| 22 | - describe "check!" do | |
| 22 | + describe "check" do | |
| 23 | 23 | it "should command targets" do | 
| 24 | 24 |        stub(agent).control!.once { nil } | 
| 25 | - agent.check! | |
| 25 | + agent.check | |
| 26 | 26 | end | 
| 27 | 27 | end | 
| 28 | 28 |  | 
| @@ -88,7 +88,7 @@ describe Agents::SchedulerAgent do | ||
| 88 | 88 | describe "check!" do | 
| 89 | 89 | it "should control targets" do | 
| 90 | 90 |        stub(agent).control!.once { nil } | 
| 91 | - agent.check! | |
| 91 | + agent.check | |
| 92 | 92 | end | 
| 93 | 93 | end | 
| 94 | 94 | end | 
| @@ -128,5 +128,24 @@ shared_examples_for AgentControllerConcern do | ||
| 128 | 128 |        expect(agent.control_targets.reload).to all(satisfy { |a| a.options['url'] == 'http://some-new-url.com/SOMETHING' }) | 
| 129 | 129 |        expect(agents(:bob_website_agent).reload.options).to eq(old_options.merge('url' => 'http://some-new-url.com/SOMETHING')) | 
| 130 | 130 | end | 
| 131 | + | |
| 132 | + it "should configure targets with nested objects" do | |
| 133 | + agent.control_targets << agents(:bob_data_output_agent) | |
| 134 | + agent.options['action'] = 'configure' | |
| 135 | +      agent.options['configure_options'] = {  | |
| 136 | +        template: { | |
| 137 | +          item: { | |
| 138 | + title: "changed" | |
| 139 | + } | |
| 140 | + } | |
| 141 | + } | |
| 142 | + agent.save! | |
| 143 | + old_options = agents(:bob_data_output_agent).options | |
| 144 | + | |
| 145 | + agent.check | |
| 146 | + | |
| 147 | +      expect(agent.control_targets.reload).to all(satisfy { |a| a.options['template'] && a.options['template']['item'] && (a.options['template']['item']['title'] == 'changed') }) | |
| 148 | + expect(agents(:bob_data_output_agent).reload.options).to eq(old_options.deep_merge(agent.options['configure_options'])) | |
| 149 | + end | |
| 131 | 150 | end | 
| 132 | 151 | end |