Skip to content

Commit

Permalink
add tests for ranking position
Browse files Browse the repository at this point in the history
  • Loading branch information
danReynolds committed Jan 2, 2017
1 parent ef9e5aa commit cc03bcb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
4 changes: 2 additions & 2 deletions app/controllers/champions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ def ranking
role = champion_params[:lane]
list_position = champion_params[:list_position].to_i
list_size = champion_params[:list_size].to_i
list_position = RANKING_LIST_POSITION unless list_position.positive?
list_position = RANKING_LIST_POSITION unless list_position > 0
list_size = RANKING_LIST_SIZE unless list_size.positive?

champions = Rails.cache.read(:champions)
rankings = Rails.cache.read({ rankings: role })[list_position..-1]
rankings = Rails.cache.read({ rankings: role })[(list_position - 1)..-1]
.first(list_size)

ranking_message = rankings.map do |key|
Expand Down
16 changes: 15 additions & 1 deletion spec/controllers/champions_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,24 @@ def speech
describe 'POST ranking' do
let(:action) { :ranking }

context 'with list position specified' do
before :each do
allow(controller).to receive(:champion_params).and_return({
list_size: '1',
lane: 'Top',
list_position: '2'
})
end

it 'should determine the best champion at that list position' do
post action, params
expect(speech).to eq "The second best champion in Top is Nasus."
end
end

context 'with list size specified' do
it 'determine the best champions for the specified list size and role' do
post action, params

expect(speech).to eq "The best three champions in Top are Darius, Nasus, and Jayce."
end
end
Expand Down

0 comments on commit cc03bcb

Please sign in to comment.