Slightly cleaner code

This commit is contained in:
echarp 2017-05-29 22:18:04 +02:00
parent 7e2c45d006
commit 87e63d0f34
5 changed files with 10 additions and 13 deletions

View File

@ -111,7 +111,7 @@ class EventsController < ApplicationController
end end
def filter_for_rss def filter_for_rss
if params[:future].present? && params[:future] == 'false' if params[:future] == 'false'
@events.order 'id desc' @events.order 'id desc'
else else
@events.future.order('id desc').limit 20 @events.future.order('id desc').limit 20

View File

@ -46,7 +46,6 @@ class ModerationsController < ApplicationController
# DELETE /events/1.json # DELETE /events/1.json
def destroy def destroy
if @moderation.reason == 'r_0' if @moderation.reason == 'r_0'
logger.info 'SPAM! SPAM! SPAM!'
@moderation.paper_trail.without_versioning :destroy @moderation.paper_trail.without_versioning :destroy
else else
@moderation.destroy! @moderation.destroy!
@ -71,7 +70,7 @@ class ModerationsController < ApplicationController
params.require(:event) params.require(:event)
.permit :lock_version, :title, :start_time, :end_time, :repeat, :rule, .permit :lock_version, :title, :start_time, :end_time, :repeat, :rule,
:description, :place_name, :address, :city, :region_id, :description, :place_name, :address, :city, :region_id,
:locality, :url, :contact, :submitter, :tag_list :locality, :url, :contact, :submitter, :tag_list, :reason
end end
# Useful to manage absolute url in mails # Useful to manage absolute url in mails
@ -84,12 +83,8 @@ class ModerationsController < ApplicationController
end end
def generate_destroy_reason def generate_destroy_reason
if params[:reason] == 'r_4' @moderation.attributes = moderation_params
@moderation.reason = params[:event][:reason] return if params[:reason] == 'r_4'
elsif params[:reason] == 'r_0'
@moderation.reason = 'r_0'
else
@moderation.reason = t "moderations.refuse.reason_#{params[:reason]}_long" @moderation.reason = t "moderations.refuse.reason_#{params[:reason]}_long"
end end
end
end end

View File

@ -24,7 +24,7 @@ class Event < ApplicationRecord
validates :region, presence: true validates :region, presence: true
validates :url, allow_nil: true, format: %r{\Ahttps?:\/\/.*\..*\z} validates :url, allow_nil: true, format: %r{\Ahttps?:\/\/.*\..*\z}
validates :contact, email: true validates :contact, email: true
validates :submitter, email: true validates :submitter, email: true, presence: false
geocoded_by :full_address geocoded_by :full_address
after_validation :geocode, if: (lambda do |obj| after_validation :geocode, if: (lambda do |obj|
@ -47,7 +47,7 @@ class Event < ApplicationRecord
scope :last_year, -> { where '? <= end_time', 1.year.ago } scope :last_year, -> { where '? <= end_time', 1.year.ago }
scope :past, -> { where 'start_time <= ?', Time.zone.now } scope :past, -> { where 'start_time <= ?', Time.zone.now }
scope :future, -> { where '? <= end_time', Time.zone.now } scope :future, -> { where '? <= end_time', Time.zone.now }
scope :daylimit, ->(d) { where 'end_time <= ?', d.to_i.days.from_now } scope :daylimit, ->(nb) { where 'end_time <= ?', nb.to_i.days.from_now }
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.to_i, 1, 1).beginning_of_week, Date.new(year.to_i, 1, 1).beginning_of_week,
@ -73,7 +73,7 @@ class Event < ApplicationRecord
self.decision_time = Time.zone.now self.decision_time = Time.zone.now
# Populate submitter using contact info if absent # Populate submitter using contact info if absent
self.submitter = contact if submitter.blank? self.submitter ||= contact
end end
before_validation on: :update do before_validation on: :update do

View File

@ -1,5 +1,6 @@
require 'test_helper' require 'test_helper'
# Will be removed in the future
class CityTest < ActiveSupport::TestCase class CityTest < ActiveSupport::TestCase
# test "the truth" do # test "the truth" do
# assert true # assert true

View File

@ -1,5 +1,6 @@
require 'test_helper' require 'test_helper'
# Mostly a data holder model, to maintain coutry > region data
class RegionTest < ActiveSupport::TestCase class RegionTest < ActiveSupport::TestCase
# test "the truth" do # test "the truth" do
# assert true # assert true