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
def filter_for_rss
if params[:future].present? && params[:future] == 'false'
if params[:future] == 'false'
@events.order 'id desc'
else
@events.future.order('id desc').limit 20

View File

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

View File

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

View File

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

View File

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