Removed duplicate date_string method
This commit is contained in:
parent
390e68b1ac
commit
5b3b054d0b
7 changed files with 6 additions and 42 deletions
|
|
@ -167,7 +167,7 @@ module Admin
|
||||||
|
|
||||||
def edit
|
def edit
|
||||||
@conferences = Conference.all
|
@conferences = Conference.all
|
||||||
@date_string = date_string(@conference.start_date, @conference.end_date)
|
@date_string = @conference.date_range_string
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html
|
format.html
|
||||||
format.json { render json: @conference.to_json }
|
format.json { render json: @conference.to_json }
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,6 @@ class ApplicationController < ActionController::Base
|
||||||
protect_from_forgery with: :exception
|
protect_from_forgery with: :exception
|
||||||
before_filter :get_conferences
|
before_filter :get_conferences
|
||||||
before_filter :store_location
|
before_filter :store_location
|
||||||
helper_method :date_string
|
|
||||||
# Ensure every controller authorizes resource or skips authorization (skip_authorization_check)
|
# Ensure every controller authorizes resource or skips authorization (skip_authorization_check)
|
||||||
check_authorization unless: :devise_controller?
|
check_authorization unless: :devise_controller?
|
||||||
|
|
||||||
|
|
@ -68,39 +67,4 @@ class ApplicationController < ActionController::Base
|
||||||
def not_found
|
def not_found
|
||||||
raise ActionController::RoutingError.new('Not Found')
|
raise ActionController::RoutingError.new('Not Found')
|
||||||
end
|
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
|
end
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@
|
||||||
= "#{@conference.venue.street},"
|
= "#{@conference.venue.street},"
|
||||||
= "#{@conference.venue.city} / #{@conference.venue.country_name}."
|
= "#{@conference.venue.city} / #{@conference.venue.country_name}."
|
||||||
%small
|
%small
|
||||||
= date_string(@conference.start_date, @conference.end_date)
|
= @conference.date_range_string
|
||||||
.row
|
.row
|
||||||
.col-md-12
|
.col-md-12
|
||||||
%h4
|
%h4
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@
|
||||||
= conference.title
|
= conference.title
|
||||||
%small
|
%small
|
||||||
%b
|
%b
|
||||||
= date_string(conference.start_date, conference.end_date)
|
= conference.date_range_string
|
||||||
- if conference.venue
|
- if conference.venue
|
||||||
%p
|
%p
|
||||||
= "#{conference.venue.city}/#{conference.venue.country_name}"
|
= "#{conference.venue.city}/#{conference.venue.country_name}"
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@
|
||||||
= "#{@conference.venue.city} / #{@conference.venue.country_name}"
|
= "#{@conference.venue.city} / #{@conference.venue.country_name}"
|
||||||
- if @conference.start_date && @conference.end_date
|
- if @conference.start_date && @conference.end_date
|
||||||
%br
|
%br
|
||||||
= date_string(@conference.start_date, @conference.end_date)
|
= @conference.date_range_string
|
||||||
|
|
||||||
- unless @conference.description.blank?
|
- unless @conference.description.blank?
|
||||||
%section#about
|
%section#about
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ require 'spec_helper'
|
||||||
|
|
||||||
describe 'conferences/index' do
|
describe 'conferences/index' do
|
||||||
it 'renders _conference partial for each conference' 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)])
|
assign(:current, [create(:conference), create(:conference)])
|
||||||
render
|
render
|
||||||
expect(view).to render_template(partial: '_conference_details', count: 2)
|
expect(view).to render_template(partial: '_conference_details', count: 2)
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ describe 'conferences/show.html.haml' do
|
||||||
let!(:conference) { create(:full_conference) }
|
let!(:conference) { create(:full_conference) }
|
||||||
|
|
||||||
before(:each) do
|
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
|
assign :conference, conference
|
||||||
render
|
render
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue