From 5b3b054d0b42d2850dd359b5f7246a71e874b439 Mon Sep 17 00:00:00 2001 From: Christopher Date: Fri, 24 Feb 2017 19:01:08 -0800 Subject: [PATCH] Removed duplicate date_string method --- .../admin/conferences_controller.rb | 2 +- app/controllers/application_controller.rb | 36 ------------------- .../conference_registrations/show.html.haml | 2 +- .../conferences/_conference_details.html.haml | 2 +- app/views/conferences/show.html.haml | 2 +- .../views/conferences/index.html.haml_spec.rb | 2 +- spec/views/conferences/show.html.haml_spec.rb | 2 +- 7 files changed, 6 insertions(+), 42 deletions(-) diff --git a/app/controllers/admin/conferences_controller.rb b/app/controllers/admin/conferences_controller.rb index 84f92838..5afbb780 100644 --- a/app/controllers/admin/conferences_controller.rb +++ b/app/controllers/admin/conferences_controller.rb @@ -167,7 +167,7 @@ module Admin def edit @conferences = Conference.all - @date_string = date_string(@conference.start_date, @conference.end_date) + @date_string = @conference.date_range_string respond_to do |format| format.html format.json { render json: @conference.to_json } diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 9cd0aca7..481d1e53 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -5,7 +5,6 @@ class ApplicationController < ActionController::Base protect_from_forgery with: :exception before_filter :get_conferences before_filter :store_location - helper_method :date_string # Ensure every controller authorizes resource or skips authorization (skip_authorization_check) check_authorization unless: :devise_controller? @@ -68,39 +67,4 @@ class ApplicationController < ActionController::Base def not_found raise ActionController::RoutingError.new('Not Found') end - - ## - # Returns a string build from the start and end date of the given conference. - # - # If the conference is only one day long - # * %B %d %Y (January 17 2014) - # If the conference starts and ends in the same month and year - # * %B %d - %d, %Y (January 17 - 21 2014) - # If the conference ends in another month but in the same year - # * %B %d - %B %d, %Y (January 31 - February 02 2014) - # All other cases - # * %B %d, %Y - %B %d, %Y (December 30, 2013 - January 02, 2014) - def date_string(start_date, end_date) - startstr = 'Unknown - ' - endstr = 'Unknown' - # When the conference in the same month - if start_date.month == end_date.month && start_date.year == end_date.year - if start_date.day == end_date.day - startstr = start_date.strftime('%B %d') - endstr = end_date.strftime(' %Y') - else - startstr = start_date.strftime('%B %d - ') - endstr = end_date.strftime('%d, %Y') - end - elsif start_date.month != end_date.month && start_date.year == end_date.year - startstr = start_date.strftime('%B %d - ') - endstr = end_date.strftime('%B %d, %Y') - else - startstr = start_date.strftime('%B %d, %Y - ') - endstr = end_date.strftime('%B %d, %Y') - end - - result = startstr + endstr - result - end end diff --git a/app/views/conference_registrations/show.html.haml b/app/views/conference_registrations/show.html.haml index 5225deb1..f99088c9 100644 --- a/app/views/conference_registrations/show.html.haml +++ b/app/views/conference_registrations/show.html.haml @@ -13,7 +13,7 @@ = "#{@conference.venue.street}," = "#{@conference.venue.city} / #{@conference.venue.country_name}." %small - = date_string(@conference.start_date, @conference.end_date) + = @conference.date_range_string .row .col-md-12 %h4 diff --git a/app/views/conferences/_conference_details.html.haml b/app/views/conferences/_conference_details.html.haml index 3f60d997..d9bc1ac9 100644 --- a/app/views/conferences/_conference_details.html.haml +++ b/app/views/conferences/_conference_details.html.haml @@ -9,7 +9,7 @@ = conference.title %small %b - = date_string(conference.start_date, conference.end_date) + = conference.date_range_string - if conference.venue %p = "#{conference.venue.city}/#{conference.venue.country_name}" diff --git a/app/views/conferences/show.html.haml b/app/views/conferences/show.html.haml index fb488e22..0ec6be8f 100644 --- a/app/views/conferences/show.html.haml +++ b/app/views/conferences/show.html.haml @@ -27,7 +27,7 @@ = "#{@conference.venue.city} / #{@conference.venue.country_name}" - if @conference.start_date && @conference.end_date %br - = date_string(@conference.start_date, @conference.end_date) + = @conference.date_range_string - unless @conference.description.blank? %section#about diff --git a/spec/views/conferences/index.html.haml_spec.rb b/spec/views/conferences/index.html.haml_spec.rb index c4ff3aa2..678677d8 100644 --- a/spec/views/conferences/index.html.haml_spec.rb +++ b/spec/views/conferences/index.html.haml_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' describe 'conferences/index' do it 'renders _conference partial for each conference' do - allow(view).to receive(:date_string).and_return('January 17 - 21 2014') + allow(view).to receive(:date_range_string).and_return('January 17 - 21 2014') assign(:current, [create(:conference), create(:conference)]) render expect(view).to render_template(partial: '_conference_details', count: 2) diff --git a/spec/views/conferences/show.html.haml_spec.rb b/spec/views/conferences/show.html.haml_spec.rb index 72e68c4f..582ed12c 100644 --- a/spec/views/conferences/show.html.haml_spec.rb +++ b/spec/views/conferences/show.html.haml_spec.rb @@ -3,7 +3,7 @@ describe 'conferences/show.html.haml' do let!(:conference) { create(:full_conference) } before(:each) do - allow(view).to receive(:date_string).and_return('January 17 - 21 2014') + allow(view).to receive(:date_range_string).and_return('January 17 - 21 2014') assign :conference, conference render end