Skip to content

Instantly share code, notes, and snippets.

@macasek
Created October 12, 2012 14:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save macasek/3879463 to your computer and use it in GitHub Desktop.
Save macasek/3879463 to your computer and use it in GitHub Desktop.
# application_controller.rb
class ApplicationController < ActionController::Base
helper_method :get_ab
private
def do_thing(val)
a, b = 0, 0
begin
val = val.to_i
rescue
val = 0
end
a = val % 1000
b = val / 1000
[a, b]
end
end
# application_controller_test.rb
class TestController < ApplicationController
def test_action
render :text => "ok"
end
end
class ApplicationControllerTest < ActionController::TestCase
test '#do_thing' do
a, b = @controller.send :do_thing, "14001"
puts a
puts b
flunk
end
# output:
# 1
# 14001/1000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment