Skip to content

Commit

Permalink
Merge branch 'release/0.5.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
benlangfeld committed Feb 12, 2016
2 parents eaa6cbc + a161d06 commit a98bf77
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# [develop](https://github.com/adhearsion/electric_slide)

# [0.5.0](https://github.com/adhearsion/electric_slide/compare/v0.4.2...v0.5.0) - [2016-02-12](https://rubygems.org/gems/adhearsion/versions/0.5.0)
* API Breakage: Fixed priority strategy now ensures that the same agent cannot be in multiple priorities

# [0.4.2](https://github.com/adhearsion/electric_slide/compare/v0.4.1...v0.4.2) - [2016-02-04](https://rubygems.org/gems/adhearsion/versions/0.4.2)
* Bugfix: FixedPriority now correctly checks out agents in priority order.

Expand Down
8 changes: 6 additions & 2 deletions lib/electric_slide/agent_strategy/fixed_priority.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,15 @@ def checkout_agent
end

def <<(agent)
# TODO: How aggressively do we check for agents duplicated in multiple priorities?
raise ArgumentError, "Agents must have a specified priority" unless agent.respond_to?(:priority)

priority = agent.priority || 999999
@priorities[priority] ||= []
@priorities[priority] << agent unless @priorities[priority].include? agent

unless @priorities[priority].include?(agent)
delete(agent)
@priorities[priority] << agent
end
end

def delete(agent)
Expand Down
2 changes: 1 addition & 1 deletion lib/electric_slide/version.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# encoding: utf-8
class ElectricSlide
VERSION = '0.4.2'
VERSION = '0.5.0'
end
21 changes: 21 additions & 0 deletions spec/electric_slide/agent_strategy/fixed_priority_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,25 @@
subject.checkout_agent
expect(subject.agent_available?).to be true
end

context 'when agents at different priorities are available' do
let(:agent1) { agent1 = OpenStruct.new(id: 101, priority: 1) }
let(:agent2) { agent1 = OpenStruct.new(id: 102, priority: 2) }

before do
subject << agent1
subject << agent2
end

describe 'and the higher priority agent is added again, but at the lowest priority' do
before do
agent1.priority = 3
subject << agent1
end

it 'moves the agent to the new, lower priority' do
expect(subject.checkout_agent).to eq(agent2)
end
end
end
end

0 comments on commit a98bf77

Please sign in to comment.