From c68c6394bc754d1092901268260fff054ed07edb Mon Sep 17 00:00:00 2001 From: Gopesh Tulsyan Date: Thu, 10 Jul 2014 21:29:07 +0530 Subject: [PATCH] Removed conference_date_string_helper, moved date_string to application_controller Deleted home_helper.rb --- app/controllers/application_controller.rb | 29 +++++++++++++++ app/helpers/home_helper.rb | 37 -------------------- app/views/conference/show.html.haml | 2 +- app/views/home/_conference_details.html.haml | 4 +-- spec/views/conference/show.html.haml_spec.rb | 1 + spec/views/home/index.html.haml_spec.rb | 1 + 6 files changed, 34 insertions(+), 40 deletions(-) delete mode 100644 app/helpers/home_helper.rb diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 42419769..21416ebf 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -3,6 +3,7 @@ class ApplicationController < ActionController::Base protect_from_forgery before_filter :get_conferences before_filter :store_location + helper_method :date_string def store_location session[:return_to] = request.fullpath if request.get? and controller_name != "user_sessions" and controller_name != "sessions" @@ -76,4 +77,32 @@ 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 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 + startstr = start_date.strftime('%B %d - ') + endstr = end_date.strftime('%d, %Y') + 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/helpers/home_helper.rb b/app/helpers/home_helper.rb deleted file mode 100644 index 60d959c4..00000000 --- a/app/helpers/home_helper.rb +++ /dev/null @@ -1,37 +0,0 @@ -## -# This class contains helper for the home views. - -module HomeHelper - - ## - # Returns a string build from the start and end date of the given conference. - # - # 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 conference_date_string(conf) - date_string(conf.start_date, conf.end_date) - end - - 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 - startstr = start_date.strftime('%B %d - ') - endstr = end_date.strftime('%d, %Y') - 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/show.html.haml b/app/views/conference/show.html.haml index 83285ff4..0ece7865 100644 --- a/app/views/conference/show.html.haml +++ b/app/views/conference/show.html.haml @@ -11,7 +11,7 @@ - if @conference.start_date && @conference.end_date .row %h3 - = conference_date_string(@conference) + = date_string(@conference.start_date, @conference.end_date) - unless @conference.description.blank? .row-fluid diff --git a/app/views/home/_conference_details.html.haml b/app/views/home/_conference_details.html.haml index 19378be5..a401ea44 100644 --- a/app/views/home/_conference_details.html.haml +++ b/app/views/home/_conference_details.html.haml @@ -9,7 +9,7 @@ = conference.title %small %b - = conference_date_string(conference) + = date_string(conference.start_date, conference.end_date) - if conference.venue.name and conference.venue.website and conference.venue.address %p %small @@ -32,4 +32,4 @@ - if !current_user.nil? && current_user.proposal_count(conference) > 0 = link_to "View My Proposals", conference_proposal_index_path(conference.short_title), :class =>"btn btn-default" - elsif conference.cfp_open? - = link_to "Submit Proposal", conference_proposal_index_path(conference.short_title), :class =>"btn btn-default" \ No newline at end of file + = link_to "Submit Proposal", conference_proposal_index_path(conference.short_title), :class =>"btn btn-default" diff --git a/spec/views/conference/show.html.haml_spec.rb b/spec/views/conference/show.html.haml_spec.rb index fb809d84..28bab522 100644 --- a/spec/views/conference/show.html.haml_spec.rb +++ b/spec/views/conference/show.html.haml_spec.rb @@ -1,6 +1,7 @@ require 'spec_helper' describe 'conference/show.html.haml' do before(:each) do + allow(view).to receive(:date_string).and_return("January 17 - 21 2014") @conference = create(:conference, registration_description: 'Lorem Ipsum Dolor', registration_start_date: Date.today, registration_end_date: Date.tomorrow, diff --git a/spec/views/home/index.html.haml_spec.rb b/spec/views/home/index.html.haml_spec.rb index 997fff79..32599a2a 100644 --- a/spec/views/home/index.html.haml_spec.rb +++ b/spec/views/home/index.html.haml_spec.rb @@ -2,6 +2,7 @@ require 'spec_helper' describe 'home/index' do it "renders _conference partial for each conference" do + allow(view).to receive(:date_string).and_return("January 17 - 21 2014") assign(:current, [create(:conference), create(:conference)]) render expect(view).to render_template(:partial => "_conference_details", :count => 2)