Nettoyage

This commit is contained in:
echarp 2014-09-05 22:15:38 +02:00
parent cc8369a0f8
commit 98ef208564
5 changed files with 12 additions and 21 deletions

View File

@ -11,7 +11,7 @@ class EventsController < ApplicationController
def index def index
respond_to do |format| respond_to do |format|
format.html { render layout: 'iframe' if params[:iframe] } format.html { render layout: 'iframe' if params[:iframe] }
format.rss { @events = @events.future_in params[:daylimit] } format.rss { @events = @events.future.in params[:daylimit] }
format.ics { @events = @events.last_year.order :id } format.ics { @events = @events.last_year.order :id }
format.xml { @events = @events.includes(:related_region).order :id } format.xml { @events = @events.includes(:related_region).order :id }
end end

View File

@ -22,21 +22,19 @@ class Event < ActiveRecord::Base
scope :moderated, -> { where moderated: true } scope :moderated, -> { where moderated: true }
scope :unmoderated, -> { where moderated: false } scope :unmoderated, -> { where moderated: false }
scope :last_year, -> { where '? <= end_time', 360.days.ago } scope :last_year, -> { where '? <= end_time', 1.year.ago }
scope :past, -> { where 'start_time <= ?', DateTime.now } scope :past, -> { where 'start_time <= ?', DateTime.now }
scope :future, -> { where '? <= end_time', DateTime.now } scope :future, -> { where '? <= end_time', DateTime.now }
scope :future_in, (lambda do |days = 30| scope :in, -> days { where 'end_time <= ?', (days || 30).to_i.days.from_now }
future.where('end_time <= ?', days.to_i.days.from_now).order :start_time
end)
scope :year, (lambda do |year| scope :year, (lambda do |year|
where '? <= end_time and start_time <= ?', where '? <= end_time and start_time <= ?',
Date.new(year, 1, 1).beginning_of_week, Date.new(year, 1, 1).beginning_of_week,
Date.new(year, 12, 31).end_of_week Date.new(year, 12, 31).end_of_week
end) end)
scope :month, (lambda do |start_date| scope :month, (lambda do |start_date|
start_date ||= Date.today.beginning_of_month start_date ||= Date.today
where '? <= end_time and start_time <= ?', where '? <= end_time and start_time <= ?',
start_date.beginning_of_week, start_date.beginning_of_month.beginning_of_week,
start_date.end_of_month.end_of_week start_date.end_of_month.end_of_week
end) end)
scope :region, -> region { where 'region = ? or locality', region } scope :region, -> region { where 'region = ? or locality', region }

View File

@ -12,7 +12,7 @@
- (1..12).each do |i| - (1..12).each do |i|
- params[:start_date] = "#{params[:year]}-#{i}-01" - params[:start_date] = "#{params[:year]}-#{i}-01"
= month_calendar events: @events, = month_calendar day_names: 'date.day_names', events: @events,
previous_link: nil, next_link: nil, previous_link: nil, next_link: nil,
title: ->(start_date) { raw link_to l(start_date, format: :month), title: ->(start_date) { raw link_to l(start_date, format: :month),
root_url(start_date: start_date), class: 'month_selector' } do |date, events| root_url(start_date: start_date), class: 'month_selector' } do |date, events|
@ -28,7 +28,7 @@
- else - else
-# One month calendar -# One month calendar
- @events = @events.month params[:start_date].try :to_date - @events = @events.month params[:start_date].try :to_date
= month_calendar events: @events, = month_calendar day_names: 'date.day_names', events: @events,
title: ->(start_date) { raw "#{I18n.t('date.month_names')[start_date.month]} #{link_to start_date.year, title: ->(start_date) { raw "#{I18n.t('date.month_names')[start_date.month]} #{link_to start_date.year,
root_url(year: start_date.year)}" }, root_url(year: start_date.year)}" },
previous_link: ->(param, date_range) { link_to '<<', previous_link: ->(param, date_range) { link_to '<<',

View File

@ -1,13 +1,5 @@
fr: fr:
date: date:
abbr_day_names:
- Dimanche
- Lundi
- Mardi
- Mercredi
- Jeudi
- Vendredi
- Samedi
formats: formats:
long: "%A %d %B %Y" long: "%A %d %B %Y"
month: "%B %Y" month: "%B %Y"

View File

@ -86,10 +86,11 @@ class EventTest < ActiveSupport::TestCase
assert @event.moderated?, @event.errors.messages assert @event.moderated?, @event.errors.messages
end end
test 'named scope future_in' do test 'named scope future.in' do
assert Event.respond_to? :future_in assert Event.respond_to? :future
assert_match(/<= end_time/, Event.future_in.where_values[0]) assert Event.respond_to? :in
assert_match(/end_time <=/, Event.future_in.where_values[1]) assert_match(/<= end_time/, Event.future.in(nil).where_values[0])
assert_match(/end_time <=/, Event.future.in(nil).where_values[1])
end end
test 'named scope year' do test 'named scope year' do