Skip to content

Commit

Permalink
[webui] Moving computed data to a constant Hash
Browse files Browse the repository at this point in the history
  • Loading branch information
kobliha authored and coolo committed Nov 1, 2012
1 parent 1d160a6 commit 21f5fae
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/webui/app/helpers/request_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ def reqtype(req)
type
end

STATE_ICONS = {
'new' => 'icons/flag_green.png',
'review' => 'icons/flag_yellow.png',
'declined' => 'icons/flag_red.png',
}

# FIXME: belongs to CSS
def request_state_icon(request)
case request.get('state')['name']
when 'new' then return 'flag_green'
when 'review' then return 'flag_yellow'
when 'declined' then return'flag_red'
else return ''
end
STATE_ICONS[request.get('state')['name']] || ''
end

end
28 changes: 28 additions & 0 deletions src/webui/test/unit/request_helper_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
require File.join File.dirname(__FILE__), '..', 'test_helper'

include RequestHelper
include ActionView::Helpers::TagHelper

class RequestHelperTest < ActiveSupport::TestCase

def test_request_state_icon
request = RequestHelperTmp.new('new')
assert_equal 'icons/flag_green.png', request_state_icon(request)

request = RequestHelperTmp.new('unknown')
assert_equal '', request_state_icon(request)
end
end

class RequestHelperTmp
@ret = nil
def initialize(ret)
@ret = ret
end
def state
self
end
def value(key)
@ret
end
end

0 comments on commit 21f5fae

Please sign in to comment.