Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

a couple of bug fixes, and some refactoring #9

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,24 @@ def labeled_field(label, value, field_class = 'labeled_field')
("<div class='" + field_class + "'><span class='label'>#{label}</span><span class='value'>#{value}</span></div>").html_safe
end

def getAgeText(birthdate)
return "Forever Young" if birthdate.nil?

bdate = Time.at(birthdate) if (birthdate.class == Fixnum)
return date(bdate) + "&nbsp;(" + time_ago_in_words(bdate) + " old)"
end

# Show the date, formatted
def date(date_value, default = 'never')
def safe_date(date_value, default = 'never')
if date_value
date_value = Time.at(date_value) if date_value.class == Fixnum
date_value.strftime("%d-%b-%Y")
if date_value.class == Fixnum or date_value.class == Bignum
yield Time.at(date_value)
else
yield date_value
end
else
default
end
end

def age_text(birthdate)
safe_date(birthdate, "Forever Young") {|d| date(d) + "&nbsp;(" + time_ago_in_words(d) + " old)"}
end

# Show the date, formatted
def date(date_value, default = 'never')
safe_date(date_value, default) {|d| d.strftime("%d-%b-%Y")}
end
end
2 changes: 1 addition & 1 deletion app/views/records/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<td>
<h2>Demographic Information</h2>
<%= sex(@record) %><br>
<%= getAgeText(@record.birthdate).html_safe %> <br>
<%= age_text(@record.birthdate).html_safe %> <br>
<b>....</b>
<%= render :layout => "section", :locals => {:record => @record, :section => :immunizations} do |x| %>
<% refused = x['refusalInd'] ? 'Refused ' : '' %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/ref_consult_requests/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@

<tr><div class="field">
<td>Age:</td>
<td><%= getAgeText(@record.birthdate).html_safe if @record %> </td>
<td><%= age_text(@record.birthdate).html_safe if @record %> </td>
</div>
</tr>

Expand Down
2 changes: 1 addition & 1 deletion app/views/ref_consult_requests/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ Your consult request has been submitted for authorization by the insurance provi

<tr><div class="field">
<td>Age:</td>
<td><%= getAgeText(@record.birthdate).html_safe if @record %></td>
<td><%= age_text(@record.birthdate).html_safe if @record %></td>
</div>
</tr>

Expand Down
6 changes: 0 additions & 6 deletions config/initializers/devise.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
require 'omniauth-openid'
require 'openid/store/filesystem'

Devise.apply_schema = false

Devise.setup do |config|
# ==> Mailer Configuration
# Configure the e-mail address which will be shown in Devise::Mailer,
Expand Down Expand Up @@ -98,10 +96,6 @@
# If true, extends the user's remember period when remembered via cookie.
# config.extend_remember_period = false

# If true, uses the password salt as remember token. This should be turned
# to false if you are not using database authenticatable.
config.use_salt_as_remember_token = true

# Options to be passed to the created cookie. For instance, you can set
# :secure => true in order to force SSL only cookies.
# config.cookie_options = {}
Expand Down
30 changes: 29 additions & 1 deletion test/unit/helpers/application_helper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,41 @@ class ApplicationHelperTest < ActionView::TestCase
labeled_field("foo", "bar")
end

test "safe_date" do
# Check that we can handle Times
time = Time.new(2001, 1, 1)
assert_equal time, safe_date(time) {|d| d}
# Check that we can handle dates represented by Fixnum
assert_equal Time.at(42), safe_date(42) {|d| d}
# Check that we can handle dates represented by Bignum
assert_equal Time.at(99999999999), safe_date(99999999999) {|d| d}
# Check defaulting behavior
assert_equal 'never', safe_date(nil)
assert_equal 'foobar', safe_date(nil, 'foobar')
end

test "age_text_formatter" do
# Check defaulting behavior
assert_equal 'Forever Young', age_text(nil)
time = Time.new(2001, 1, 1)
assert_match "01-Jan-2001", age_text(time)
# Check that we can handle dates represented by Fixnum
assert_match "01-Jan-1970", age_text(43200)
# Check that we can handle dates represented by Bignum
assert_match "16-Nov-5138", age_text(99999999999)
end

test "date_formatter" do
time = Time.new(2001, 1, 1)
assert_equal "01-Jan-2001", date(time)
# Check defaulting behavior with optional parameter
assert_equal 'present', date(nil, 'present')
# Check defaulting behavior with default value
assert_equal 'never', date(nil)
# Check that we can handle dates represented by Fixnum
assert_equal "01-Jan-1970", date(43200)
# Check that we can handle dates represented by Bignum
assert_equal "16-Nov-5138", date(99999999999)
end

test "breadcrumbs" do
Expand All @@ -25,4 +53,4 @@ class ApplicationHelperTest < ActionView::TestCase
def breadcrumbs
@bc
end
end
end