From 082e0a307f4bce6277613e8dddc07162422020dd Mon Sep 17 00:00:00 2001 From: echarp Date: Sat, 22 Apr 2017 20:01:47 +0200 Subject: [PATCH] Bundle update and subsequent cleaning up related to the new rubocop version --- Gemfile.lock | 156 +++++++++--------- app/admin/admin_user.rb | 2 +- app/controllers/digests_controller.rb | 2 +- app/controllers/events_controller.rb | 10 +- app/controllers/maps_controller.rb | 4 +- app/controllers/moderations_controller.rb | 2 +- app/controllers/notes_controller.rb | 4 +- app/controllers/orgas_controller.rb | 8 +- app/controllers/stats_controller.rb | 4 +- app/controllers/tags_controller.rb | 2 +- app/controllers/users_controller.rb | 2 +- app/models/event.rb | 8 +- app/models/orga.rb | 8 +- app/views/events/index.rss.builder | 35 ++-- app/views/versions/index.rss.builder | 102 ++++++------ config/application.rb | 4 +- config/initializers/mime_types.rb | 2 +- config/routes.rb | 10 +- ...1114103121_create_active_admin_comments.rb | 6 +- db/migrate/20150711164423_create_versions.rb | 2 +- ...on_migration.acts_as_taggable_on_engine.rb | 2 +- ...ique_indices.acts_as_taggable_on_engine.rb | 8 +- ...ggable_index.acts_as_taggable_on_engine.rb | 4 +- ...sing_indexes.acts_as_taggable_on_engine.rb | 4 +- db/schema.rb | 12 +- 25 files changed, 207 insertions(+), 196 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index eb35cf2e..3694a680 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,18 +1,18 @@ GIT remote: git://github.com/activeadmin/activeadmin.git - revision: 8ddc07eefb9c4c39f96e1ad990fe7789555fd4ff + revision: 5e2d9c2f8620476b2045b1f05fc129fe9900846b specs: - activeadmin (1.0.0.pre4) - arbre (~> 1.0, >= 1.0.2) + activeadmin (1.0.0.pre5) + arbre (>= 1.1.1) bourbon coffee-rails formtastic (~> 3.1) formtastic_i18n - inherited_resources (~> 1.6) + inherited_resources (~> 1.7) jquery-rails jquery-ui-rails kaminari (>= 0.15, < 2.0) - railties (>= 3.2, < 5.1) + railties (>= 4.2, < 5.2) ransack (~> 1.3) sass-rails sprockets (< 4.1) @@ -27,65 +27,64 @@ GIT GIT remote: git://github.com/svenfuchs/i18n-active_record.git - revision: 35abff38bae09c65ab9404a8292bcda9f0f49d34 + revision: a61b6840b746d303de17f12d35522388c16ad003 specs: - i18n-active_record (0.1.2) + i18n-active_record (0.2.0) i18n (>= 0.5.0) GEM remote: https://rubygems.org/ remote: https://rails-assets.org/ specs: - actionmailer (4.2.7.1) - actionpack (= 4.2.7.1) - actionview (= 4.2.7.1) - activejob (= 4.2.7.1) + actionmailer (4.2.8) + actionpack (= 4.2.8) + actionview (= 4.2.8) + activejob (= 4.2.8) mail (~> 2.5, >= 2.5.4) rails-dom-testing (~> 1.0, >= 1.0.5) - actionpack (4.2.7.1) - actionview (= 4.2.7.1) - activesupport (= 4.2.7.1) + actionpack (4.2.8) + actionview (= 4.2.8) + activesupport (= 4.2.8) rack (~> 1.6) rack-test (~> 0.6.2) rails-dom-testing (~> 1.0, >= 1.0.5) rails-html-sanitizer (~> 1.0, >= 1.0.2) - actionview (4.2.7.1) - activesupport (= 4.2.7.1) + actionview (4.2.8) + activesupport (= 4.2.8) builder (~> 3.1) erubis (~> 2.7.0) rails-dom-testing (~> 1.0, >= 1.0.5) - rails-html-sanitizer (~> 1.0, >= 1.0.2) + rails-html-sanitizer (~> 1.0, >= 1.0.3) actionview-encoded_mail_to (1.0.9) rails - activejob (4.2.7.1) - activesupport (= 4.2.7.1) + activejob (4.2.8) + activesupport (= 4.2.8) globalid (>= 0.3.0) - activemodel (4.2.7.1) - activesupport (= 4.2.7.1) + activemodel (4.2.8) + activesupport (= 4.2.8) builder (~> 3.1) - activerecord (4.2.7.1) - activemodel (= 4.2.7.1) - activesupport (= 4.2.7.1) + activerecord (4.2.8) + activemodel (= 4.2.8) + activesupport (= 4.2.8) arel (~> 6.0) - activesupport (4.2.7.1) + activesupport (4.2.8) i18n (~> 0.7) - json (~> 1.7, >= 1.7.7) minitest (~> 5.1) thread_safe (~> 0.3, >= 0.3.4) tzinfo (~> 1.1) acts-as-taggable-on (4.0.0) activerecord (>= 4.0) - addressable (2.5.0) + addressable (2.5.1) public_suffix (~> 2.0, >= 2.0.2) arbre (1.1.1) activesupport (>= 3.0.0) arel (6.0.4) ast (2.3.0) bcrypt (3.1.11) - bourbon (4.3.2) + bourbon (4.3.4) sass (~> 3.4) thor (~> 0.19) - brakeman (3.5.0) + brakeman (3.6.1) buftok (0.2.0) builder (3.2.3) bundler-audit (0.5.0) @@ -100,18 +99,18 @@ GEM coffee-script-source execjs coffee-script-source (1.12.2) - concurrent-ruby (1.0.4) + concurrent-ruby (1.0.5) debug_inspector (0.0.2) - devise (4.2.0) + devise (4.2.1) bcrypt (~> 3.0) orm_adapter (~> 0.1) railties (>= 4.1.0, < 5.1) responders warden (~> 1.2.3) - devise-i18n (1.1.1) + devise-i18n (1.1.2) differ (0.1.2) docile (1.1.5) - domain_name (0.5.20161129) + domain_name (0.5.20170404) unf (>= 0.0.5, < 1.0.0) em-websocket (0.5.1) eventmachine (>= 0.12.9) @@ -120,20 +119,20 @@ GEM activemodel equalizer (0.0.11) erubis (2.7.0) - eventmachine (1.2.2) + eventmachine (1.2.3) execjs (2.7.0) faraday (0.11.0) multipart-post (>= 1.2, < 3) - ffi (1.9.17) + ffi (1.9.18) font-awesome-sass (4.7.0) sass (>= 3.2) formatador (0.2.5) - formtastic (3.1.4) + formtastic (3.1.5) actionpack (>= 3.2.13) formtastic_i18n (0.6.0) geocoder (1.4.3) - globalid (0.3.7) - activesupport (>= 4.1.0) + globalid (0.4.0) + activesupport (>= 4.2.0) guard (2.14.1) formatador (>= 0.2.4) listen (>= 2.7, < 4.0) @@ -156,7 +155,7 @@ GEM guard (~> 2.8) guard-compat (~> 1.0) multi_json (~> 1.8) - guard-migrate (1.2.1) + guard-migrate (2.0.0) activerecord (>= 4.1.0) guard (~> 2.3) guard-compat (~> 1.1) @@ -177,8 +176,9 @@ GEM haml (>= 4.0.6, < 5.0) html2haml (>= 1.0.1) railties (>= 4.0.1) - haml_lint (0.21.0) - haml (~> 4.0) + haml_lint (0.24.0) + haml (>= 4.0, < 5.1) + rainbow rake (>= 10, < 13) rubocop (>= 0.47.0) sysexits (~> 1.1) @@ -201,17 +201,17 @@ GEM http-form_data (1.0.1) http_accept_language (2.1.0) http_parser.rb (0.6.0) - i18n (0.8.0) - ice_cube (0.15.0) - inherited_resources (1.7.0) + i18n (0.8.1) + ice_cube (0.16.0) + inherited_resources (1.7.1) actionpack (>= 3.2, < 5.1) has_scope (~> 0.6) railties (>= 3.2, < 5.1) responders - jbuilder (2.6.1) - activesupport (>= 3.0.0, < 5.1) + jbuilder (2.6.3) + activesupport (>= 3.0.0, < 5.2) multi_json (~> 1.2) - jquery-rails (4.2.2) + jquery-rails (4.3.1) rails-dom-testing (>= 1, < 3) railties (>= 4.2.0) thor (>= 0.14, < 2.0) @@ -230,8 +230,9 @@ GEM activerecord kaminari-core (= 1.0.1) kaminari-core (1.0.1) - leaflet-rails (1.0.2) - libv8 (3.16.14.17) + leaflet-rails (1.0.3) + rails (>= 4.2.0) + libv8 (3.16.14.19) listen (3.1.5) rb-fsevent (~> 0.9, >= 0.9.4) rb-inotify (~> 0.9, >= 0.9.7) @@ -257,13 +258,13 @@ GEM mysql2 (0.4.5) naught (1.1.0) nenv (0.3.0) - nokogiri (1.7.0.1) + nokogiri (1.7.1) mini_portile2 (~> 2.1.0) notiffany (0.1.1) nenv (~> 0.1) shellany (~> 0.0) orm_adapter (0.5.0) - paper_trail (6.0.2) + paper_trail (7.0.1) activerecord (>= 4.0, < 5.2) request_store (~> 1.1) parser (2.4.0.0) @@ -287,19 +288,19 @@ GEM rack rack-test (0.6.3) rack (>= 1.0) - rails (4.2.7.1) - actionmailer (= 4.2.7.1) - actionpack (= 4.2.7.1) - actionview (= 4.2.7.1) - activejob (= 4.2.7.1) - activemodel (= 4.2.7.1) - activerecord (= 4.2.7.1) - activesupport (= 4.2.7.1) + rails (4.2.8) + actionmailer (= 4.2.8) + actionpack (= 4.2.8) + actionview (= 4.2.8) + activejob (= 4.2.8) + activemodel (= 4.2.8) + activerecord (= 4.2.8) + activesupport (= 4.2.8) bundler (>= 1.3.0, < 2.0) - railties (= 4.2.7.1) + railties (= 4.2.8) sprockets-rails rails-assets-leaflet (1.0.3) - rails-assets-leaflet.markercluster (1.0.3) + rails-assets-leaflet.markercluster (1.0.4) rails-assets-leaflet (>= 1.0.3) rails-deprecated_sanitizer (1.0.3) activesupport (>= 4.2.0.alpha) @@ -312,12 +313,13 @@ GEM rails-i18n (4.0.9) i18n (~> 0.7) railties (~> 4.0) - railties (4.2.7.1) - actionpack (= 4.2.7.1) - activesupport (= 4.2.7.1) + railties (4.2.8) + actionpack (= 4.2.8) + activesupport (= 4.2.8) rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) - rainbow (2.2.1) + rainbow (2.2.2) + rake rake (12.0.0) ransack (1.8.2) actionpack (>= 3.0) @@ -334,7 +336,7 @@ GEM request_store (1.3.2) responders (2.3.0) railties (>= 4.2.0, < 5.1) - rubocop (0.47.1) + rubocop (0.48.1) parser (>= 2.3.3.1, < 3.0) powerpack (~> 0.1) rainbow (>= 1.99.1, < 3.0) @@ -342,7 +344,7 @@ GEM unicode-display_width (~> 1.0, >= 1.0.1) ruby-progressbar (1.8.1) ruby_dep (1.5.0) - ruby_parser (3.8.4) + ruby_parser (3.9.0) sexp_processor (~> 4.1) sass (3.4.23) sass-rails (5.0.6) @@ -354,12 +356,12 @@ GEM sdoc (0.4.2) json (~> 1.7, >= 1.7.7) rdoc (~> 4.0) - sexp_processor (4.8.0) + sexp_processor (4.9.0) shellany (0.0.1) - simple_calendar (2.2.3) + simple_calendar (2.2.5) rails (>= 3.0) simple_oauth (0.3.1) - simplecov (0.13.0) + simplecov (0.14.1) docile (~> 1.1.0) json (>= 1.8, < 3) simplecov-html (~> 0.10.0) @@ -382,9 +384,9 @@ GEM libv8 (~> 3.16.14.15) ref thor (0.19.4) - thread_safe (0.3.5) - tilt (2.0.6) - tinymce-rails (4.5.3) + thread_safe (0.3.6) + tilt (2.0.7) + tinymce-rails (4.5.6) railties (>= 3.1.1) tinymce-rails-langs (4.20160310) tinymce-rails (~> 4.1, >= 4.1.10) @@ -401,14 +403,14 @@ GEM memoizable (~> 0.4.2) naught (~> 1.1) simple_oauth (~> 0.3.1) - tzinfo (1.2.2) + tzinfo (1.2.3) thread_safe (~> 0.1) - uglifier (3.0.4) + uglifier (3.2.0) execjs (>= 0.3.0, < 3) unf (0.1.4) unf_ext - unf_ext (0.0.7.2) - unicode-display_width (1.1.3) + unf_ext (0.0.7.4) + unicode-display_width (1.2.1) warden (1.2.7) rack (>= 1.0) web-console (3.3.0) diff --git a/app/admin/admin_user.rb b/app/admin/admin_user.rb index 6f603bd2..588fc356 100644 --- a/app/admin/admin_user.rb +++ b/app/admin/admin_user.rb @@ -20,7 +20,7 @@ ActiveAdmin.register AdminUser do end controller do def permitted_params - params.permit admin_user: [:email, :password, :password_confirmation] + params.permit admin_user: %i[email password password_confirmation] end end end diff --git a/app/controllers/digests_controller.rb b/app/controllers/digests_controller.rb index 4a9641f4..e3a1d44d 100644 --- a/app/controllers/digests_controller.rb +++ b/app/controllers/digests_controller.rb @@ -2,7 +2,7 @@ class DigestsController < ApplicationController has_scope :moderated, default: nil, allow_blank: true has_scope :region, :locality, :tag - has_scope :period, allow_blank: true, type: :hash, using: [:year, :week], + has_scope :period, allow_blank: true, type: :hash, using: %i[year week], default: ( lambda do { year: (Time.zone.today + 7.days).year, diff --git a/app/controllers/events_controller.rb b/app/controllers/events_controller.rb index c878e762..bf3edb2d 100644 --- a/app/controllers/events_controller.rb +++ b/app/controllers/events_controller.rb @@ -2,12 +2,12 @@ # This is a central part to this project class EventsController < ApplicationController has_scope :region, :locality, :tag, :daylimit, :year - has_scope :near, type: :hash, using: [:location, :distance] + has_scope :near, type: :hash, using: %i[location distance] before_action :set_events, only: [:index] - before_action :set_event, except: [:index, :new, :preview_create, :create] - before_action :set_create_event, only: [:preview_create, :create] - before_action :check_secret, only: [:edit, :preview, :update, :destroy] + before_action :set_event, except: %i[index new preview_create create] + before_action :set_create_event, only: %i[preview_create create] + before_action :check_secret, only: %i[edit preview update destroy] before_action :set_mailer_host rescue_from ActiveRecord::StaleObjectError, with: :locked @@ -123,7 +123,7 @@ class EventsController < ApplicationController # Check that you can only edit an existing event if you know its secret def check_secret - redirect_to :root, alert: t(:forbidden, scope: [:events, :edit]) \ + redirect_to :root, alert: t(:forbidden, scope: %i[events edit]) \ unless params[:secret] == @event.secret end end diff --git a/app/controllers/maps_controller.rb b/app/controllers/maps_controller.rb index eea2cdd9..dff32b4d 100644 --- a/app/controllers/maps_controller.rb +++ b/app/controllers/maps_controller.rb @@ -4,8 +4,8 @@ class MapsController < ApplicationController has_scope :region, :locality, :tag, :daylimit has_scope :future, type: :boolean, default: true - has_scope :period, type: :hash, using: [:year, :week] - has_scope :near, type: :hash, using: [:location, :distance] + has_scope :period, type: :hash, using: %i[year week] + has_scope :near, type: :hash, using: %i[location distance] def index respond_to do |format| diff --git a/app/controllers/moderations_controller.rb b/app/controllers/moderations_controller.rb index 4fa841ba..f25c8946 100644 --- a/app/controllers/moderations_controller.rb +++ b/app/controllers/moderations_controller.rb @@ -2,7 +2,7 @@ class ModerationsController < ApplicationController before_action :authenticate_user! before_action :set_moderation, :set_mailer_host, only: - [:show, :edit, :preview, :update, :validate, :accept, :refuse, :destroy] + %i[show edit preview update validate accept refuse destroy] before_action :generate_destroy_reason, only: :destroy rescue_from ActiveRecord::StaleObjectError, with: :locked diff --git a/app/controllers/notes_controller.rb b/app/controllers/notes_controller.rb index 1695a9ce..89771480 100644 --- a/app/controllers/notes_controller.rb +++ b/app/controllers/notes_controller.rb @@ -1,7 +1,7 @@ # Events, particulary during moderation, can have notes associated to them class NotesController < ApplicationController - before_action :set_event, only: [:new, :create] - before_action :create_note, :set_mailer_host, only: [:create] + before_action :set_event, only: %i[new create] + before_action :create_note, :set_mailer_host, only: %i[create] # GET /moderations/id/new def new diff --git a/app/controllers/orgas_controller.rb b/app/controllers/orgas_controller.rb index 4812e1cb..6a68f66e 100644 --- a/app/controllers/orgas_controller.rb +++ b/app/controllers/orgas_controller.rb @@ -1,11 +1,11 @@ # Groups life cycle class OrgasController < ApplicationController has_scope :region - has_scope :near, type: :hash, using: [:location, :distance] + has_scope :near, type: :hash, using: %i[location distance] - before_action :set_orga, except: [:index, :new, :create] + before_action :set_orga, except: %i[index new create] before_action :set_mailer_host - before_action :authenticate_user!, except: [:index, :new, :create, :show], + before_action :authenticate_user!, except: %i[index new create show], unless: :check_secret def index @@ -97,7 +97,7 @@ class OrgasController < ApplicationController # Check that you can only edit an existing event if you know its secret def check_secret - !%w(validate refuse).include?(action_name) && + !%w[validate refuse].include?(action_name) && (!@orga.secret || @orga.secret == params[:secret]) end end diff --git a/app/controllers/stats_controller.rb b/app/controllers/stats_controller.rb index 5c0da9e7..e3b2d20a 100644 --- a/app/controllers/stats_controller.rb +++ b/app/controllers/stats_controller.rb @@ -16,7 +16,7 @@ class StatsController < ApplicationController end def year_grouping - if %w(Mysql2 MySQL PostgreSQL).include? Event.connection.adapter_name + if %w[Mysql2 MySQL PostgreSQL].include? Event.connection.adapter_name 'extract(year from start_time)' elsif Event.connection.adapter_name == 'SQLite' 'strftime("%Y", start_time)' @@ -24,7 +24,7 @@ class StatsController < ApplicationController end def month_grouping - if %w(Mysql2 MySQL PostgreSQL).include? Event.connection.adapter_name + if %w[Mysql2 MySQL PostgreSQL].include? Event.connection.adapter_name 'extract(month from start_time)' elsif Event.connection.adapter_name == 'SQLite' 'strftime("%m", start_time)' diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb index b4ab5693..de835530 100644 --- a/app/controllers/tags_controller.rb +++ b/app/controllers/tags_controller.rb @@ -1,7 +1,7 @@ # Manage event and organisation tags class TagsController < InheritedResources::Base has_scope :region, :locality, :daylimit - has_scope :period, type: :hash, using: [:year, :week] + has_scope :period, type: :hash, using: %i[year week] has_scope :tag, as: :id def index diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 59719747..9f51e6d1 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1,7 +1,7 @@ # Moderators life cycle class UsersController < ApplicationController before_action :authenticate_user! - before_action :set_user, only: [:show, :edit, :update, :destroy] + before_action :set_user, only: %i[show edit update destroy] # GET /users # GET /users.json diff --git a/app/models/event.rb b/app/models/event.rb index 86545574..11d93bbe 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -6,8 +6,8 @@ class Event < ActiveRecord::Base include Schedule acts_as_taggable strip_attributes - has_paper_trail ignore: [:last_updated, :lock_version, :secret, :submitter, - :decision_time, :latitude, :longitude] + has_paper_trail ignore: %i[last_updated lock_version secret submitter + decision_time latitude longitude] belongs_to :region # This is the scheduled first event @@ -17,7 +17,7 @@ class Event < ActiveRecord::Base validates :title, presence: true validate :end_after_start - RULES = %w(daily weekly monthly monthly_day).freeze + RULES = %w[daily weekly monthly monthly_day].freeze validates :rule, allow_nil: true, inclusion: RULES validates :description, presence: true validates :city, presence: true @@ -120,6 +120,6 @@ class Event < ActiveRecord::Base def end_after_start errors.add :end_time, :before_start if - !end_time.blank? && !start_time.blank? && end_time <= start_time + end_time.present? && start_time.present? && end_time <= start_time end end diff --git a/app/models/orga.rb b/app/models/orga.rb index dc15b500..d4893a05 100644 --- a/app/models/orga.rb +++ b/app/models/orga.rb @@ -2,8 +2,8 @@ class Orga < ActiveRecord::Base acts_as_taggable strip_attributes - has_paper_trail ignore: [:last_updated, :secret, :submitter, :decision_time, - :lock_version, :latitude, :longitude] + has_paper_trail ignore: %i[last_updated secret submitter decision_time + lock_version latitude longitude] belongs_to :region belongs_to :kind @@ -63,9 +63,9 @@ class Orga < ActiveRecord::Base end before_destroy do - OrgaMailer.destroy(self).deliver_now! unless submitter.blank? + OrgaMailer.destroy(self).deliver_now! if submitter.present? # Send email to moderators when an orga is deleted - ModerationorgaMailer.destroy(self).deliver_now! unless submitter.blank? + ModerationorgaMailer.destroy(self).deliver_now! if submitter.present? end def send_secret diff --git a/app/views/events/index.rss.builder b/app/views/events/index.rss.builder index 7638ae31..ae252f0d 100644 --- a/app/views/events/index.rss.builder +++ b/app/views/events/index.rss.builder @@ -1,12 +1,27 @@ +def meta(xml, event) + domain = root_url.gsub(/www/, '').gsub(/http.?:../, '').gsub(/:.*/, '') + xml.dc :identifier, "#{event.id}@#{domain}" + xml.dc :date, event.start_time.iso8601 + + return unless event.latitude || event.longitude + xml.georss :point, event.latitude, ' ', event.longitude +end + +def event_to_rss(xml, event) + meta xml, event + + xml.title "#{event.city}: #{event.title}, #{display_date event}" + xml.link event_url event + xml.description strip_tags event.description + xml.content(:encoded) { xml.cdata! event.description } +end + xml.instruct! xml.rdf :RDF, - 'xmlns:rdf' => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#', 'xmlns' => 'http://purl.org/rss/1.0/', + 'xmlns:rdf' => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#', 'xmlns:dc' => 'http://purl.org/dc/elements/1.1/', - 'xmlns:sy' => 'http://purl.org/rss/1.0/modules/syndication/', - 'xmlns:admin' => 'http://webns.net/mvcb/', - 'xmlns:cc' => 'http://web.resource.org/cc/', 'xmlns:content' => 'http://purl.org/rss/1.0/modules/content/', 'xmlns:georss' => 'http://www.georss.org/georss' do xml.channel 'rdf:about' => root_url do @@ -32,17 +47,7 @@ xml.rdf :RDF, @events.each do |event| xml.item 'rdf:about' => event_url(event) do - xml.title "#{event.city}: #{event.title}, #{display_date event}" - xml.link event_url event - domain = root_url.gsub(/www/, '').gsub(/http.?:../, '').gsub(/:.*/, '') - xml.dc :identifier, "#{event.id}@#{domain}" - xml.dc :date, event.start_time.iso8601 - if event.latitude && event.longitude - xml.georss :point, event.latitude, ' ', event.longitude - end - - xml.description strip_tags event.description - xml.content(:encoded) { xml.cdata! event.description } + event_to_rss xml, event end end end diff --git a/app/views/versions/index.rss.builder b/app/views/versions/index.rss.builder index 967d5acf..cf7e42ed 100644 --- a/app/views/versions/index.rss.builder +++ b/app/views/versions/index.rss.builder @@ -1,45 +1,65 @@ require 'differ/format/patch' Differ.format = Differ::Format::Patch +def gen_title + t 'layouts.application.title' + + if params[:region].present? && params[:region] != 'all' + region = Region.find(params[:region]).name + " [#{region}]" + else + '' + end +end + +def meta(xml) + xml.items do + xml.rdf :Seq do + @versions.each do |version| + xml.rdf :li, 'rdf:resource' => + polymorphic_url(version.item_type.tableize.singularize, + id: version.item_id) + end + end + end +end + +def about(xml) + xml.title gen_title + xml.description t 'layouts.application.subtitle' + xml.link root_url + xml.dc :language, 'fr' + xml.dc :creator, root_url + + meta xml +end + +def version_changes(version) + version.changeset.collect do |key, val| + version.item_type.constantize.human_attribute_name(key) + + ': ' + + if key == 'description' + Differ.diff(val[1], val[0]).to_s + else + "#{val[0]} → #{val[1]}" + end + end +end + xml.instruct! xml.rdf :RDF, 'xmlns:rdf' => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#', 'xmlns' => 'http://purl.org/rss/1.0/', 'xmlns:dc' => 'http://purl.org/dc/elements/1.1/', - 'xmlns:sy' => 'http://purl.org/rss/1.0/modules/syndication/', - 'xmlns:admin' => 'http://webns.net/mvcb/', - 'xmlns:cc' => 'http://web.resource.org/cc/', - 'xmlns:content' => 'http://purl.org/rss/1.0/modules/content/', - 'xmlns:georss' => 'http://www.georss.org/georss' do + 'xmlns:content' => 'http://purl.org/rss/1.0/modules/content/' do xml.channel 'rdf:about' => root_url do - title = t 'layouts.application.title' - if params[:region].present? && params[:region] != 'all' - region = Region.find(params[:region]).name - title += " [#{region}]" - end - xml.title title - xml.description t 'layouts.application.subtitle' - xml.link root_url - xml.dc :language, 'fr' - xml.dc :creator, root_url - - xml.items do - xml.rdf :Seq do - @versions.each do |version| - xml.rdf :li, 'rdf:resource' => - polymorphic_url(version.item_type.tableize.singularize, - id: version.item_id) - end - end - end + about xml end - @versions.each do |version| - if version.event == 'create' - object = version.item_type.constantize.find_by_id version.item_id - next unless object.try(:moderated?) - end + @versions.reject { |version| version.event == 'create' }.each do |version| + object = version.item_type.constantize.find_by id: version.item_id + next unless object.try(:moderated?) + object = version.reify if object.nil? url = polymorphic_url(version.item_type.tableize.singularize, id: version.item_id) @@ -52,25 +72,9 @@ xml.rdf :RDF, xml.dc :date, version.created_at.iso8601 if object.try(:description) - if version.event == 'create' - xml.description strip_tags object.description - xml.content(:encoded) { xml.cdata! object.description } - elsif version.event == 'update' - changes = '' - version.changeset.each do |key, val| - changes += version.item_type.constantize.human_attribute_name(key) - changes += ': ' - if key == 'description' && val[0].present? && val[1].present? - changes += Differ.diff(val[1], val[0]).to_s - else - changes += "#{val[0]} → #{val[1]}" - end - changes += ' - ' - end - xml.description changes - xml.content(:encoded) { xml.cdata! changes } - end + changes = version_changes(version).join "\n" + xml.description changes + xml.content(:encoded) { xml.cdata! changes } end end end diff --git a/config/application.rb b/config/application.rb index 9ffce224..dd041c74 100644 --- a/config/application.rb +++ b/config/application.rb @@ -29,7 +29,7 @@ module AgendaDuLibreRails Dir[Rails.root.join('config', 'locales', '**', '*.{rb,yml}')] # config.i18n.default_locale = :de config.i18n.default_locale = :fr - config.i18n.available_locales = [:fr, :en, :'pt-BR'] + config.i18n.available_locales = %i[fr en 'pt-BR'] config.action_mailer.default_options = { from: 'moderateurs@agendadulibre.org', @@ -44,6 +44,6 @@ module AgendaDuLibreRails config.active_record.raise_in_transactional_callbacks = true # In rails 4, plugin and vendor images need to be precompiled - config.assets.precompile += %w(*.png *.jpg *.jpeg *.gif) + config.assets.precompile += %w[*.png *.jpg *.jpeg *.gif] end end diff --git a/config/initializers/mime_types.rb b/config/initializers/mime_types.rb index cc13b1fd..0b9940c4 100644 --- a/config/initializers/mime_types.rb +++ b/config/initializers/mime_types.rb @@ -4,4 +4,4 @@ # Mime::Type.register 'text/richtext', :rtf # Necessary for the /ical.php redirect to /events.ics -Mime::Type.register 'text/calendar', :ics, [], %w(ical) +Mime::Type.register 'text/calendar', :ics, [], %w[ical] diff --git a/config/routes.rb b/config/routes.rb index 6ef0d697..f163d5a9 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -9,16 +9,16 @@ Rails.application.routes.draw do patch :preview, on: :member end resources :moderations do - resources :notes, only: [:new, :create] + resources :notes, only: %i[new create] patch :preview, on: :member get :validate, :refuse, on: :member put :accept, on: :member end - resources :digests, only: [:index, :show] - resources :regions, only: [:index] + resources :digests, only: %i[index show] + resources :regions, only: %i[index] get 'tags/orgas', to: 'tags#orgas' - resources :tags, only: [:index, :show] - resources :maps, only: [:index, :show] + resources :tags, only: %i[index show] + resources :maps, only: %i[index show] resources :orgas do get :cancel, :validate, :refuse, on: :member put :accept, on: :member diff --git a/db/migrate/20131114103121_create_active_admin_comments.rb b/db/migrate/20131114103121_create_active_admin_comments.rb index 09216896..e040f8bc 100644 --- a/db/migrate/20131114103121_create_active_admin_comments.rb +++ b/db/migrate/20131114103121_create_active_admin_comments.rb @@ -10,9 +10,9 @@ class CreateActiveAdminComments < ActiveRecord::Migration t.references :author, polymorphic: true t.timestamps end - add_index :active_admin_comments, [:namespace] - add_index :active_admin_comments, [:author_type, :author_id] - add_index :active_admin_comments, [:resource_type, :resource_id] + add_index :active_admin_comments, %i[namespace] + add_index :active_admin_comments, %i[author_type author_id] + add_index :active_admin_comments, %i[resource_type resource_id] end def self.down diff --git a/db/migrate/20150711164423_create_versions.rb b/db/migrate/20150711164423_create_versions.rb index ea506fb2..81fc462f 100644 --- a/db/migrate/20150711164423_create_versions.rb +++ b/db/migrate/20150711164423_create_versions.rb @@ -9,6 +9,6 @@ class CreateVersions < ActiveRecord::Migration t.text :object t.datetime :created_at end - add_index :versions, [:item_type, :item_id] + add_index :versions, %i[item_type item_id] end end diff --git a/db/migrate/20161210105328_acts_as_taggable_on_migration.acts_as_taggable_on_engine.rb b/db/migrate/20161210105328_acts_as_taggable_on_migration.acts_as_taggable_on_engine.rb index 72b88fe0..069b01ca 100644 --- a/db/migrate/20161210105328_acts_as_taggable_on_migration.acts_as_taggable_on_engine.rb +++ b/db/migrate/20161210105328_acts_as_taggable_on_migration.acts_as_taggable_on_engine.rb @@ -17,7 +17,7 @@ class ActsAsTaggableOnMigration < ActiveRecord::Migration end add_index :taggings, :tag_id - add_index :taggings, [:taggable_id, :taggable_type, :context] + add_index :taggings, %i[taggable_id taggable_type context] end def self.up diff --git a/db/migrate/20161210105329_add_missing_unique_indices.acts_as_taggable_on_engine.rb b/db/migrate/20161210105329_add_missing_unique_indices.acts_as_taggable_on_engine.rb index 1f3aaea4..45bc2dd2 100644 --- a/db/migrate/20161210105329_add_missing_unique_indices.acts_as_taggable_on_engine.rb +++ b/db/migrate/20161210105329_add_missing_unique_indices.acts_as_taggable_on_engine.rb @@ -4,10 +4,10 @@ class AddMissingUniqueIndices < ActiveRecord::Migration add_index :tags, :name, unique: true remove_index :taggings, :tag_id if index_exists?(:taggings, :tag_id) - remove_index :taggings, [:taggable_id, :taggable_type, :context] + remove_index :taggings, %i[taggable_id taggable_type context] add_index :taggings, - [:tag_id, :taggable_id, :taggable_type, :context, :tagger_id, - :tagger_type], + %i[tag_id taggable_id taggable_type context tagger_id + tagger_type], unique: true, name: 'taggings_idx' end @@ -17,6 +17,6 @@ class AddMissingUniqueIndices < ActiveRecord::Migration remove_index :taggings, name: 'taggings_idx' add_index :taggings, :tag_id unless index_exists?(:taggings, :tag_id) - add_index :taggings, [:taggable_id, :taggable_type, :context] + add_index :taggings, %i[taggable_id taggable_type context] end end diff --git a/db/migrate/20161210105331_add_missing_taggable_index.acts_as_taggable_on_engine.rb b/db/migrate/20161210105331_add_missing_taggable_index.acts_as_taggable_on_engine.rb index 71f2d7f4..d841559c 100644 --- a/db/migrate/20161210105331_add_missing_taggable_index.acts_as_taggable_on_engine.rb +++ b/db/migrate/20161210105331_add_missing_taggable_index.acts_as_taggable_on_engine.rb @@ -1,10 +1,10 @@ # This migration comes from acts_as_taggable_on_engine (originally 4) class AddMissingTaggableIndex < ActiveRecord::Migration def self.up - add_index :taggings, [:taggable_id, :taggable_type, :context] + add_index :taggings, %i[taggable_id taggable_type context] end def self.down - remove_index :taggings, [:taggable_id, :taggable_type, :context] + remove_index :taggings, %i[taggable_id taggable_type context] end end diff --git a/db/migrate/20161210105333_add_missing_indexes.acts_as_taggable_on_engine.rb b/db/migrate/20161210105333_add_missing_indexes.acts_as_taggable_on_engine.rb index 1be2d315..9a5fcfae 100644 --- a/db/migrate/20161210105333_add_missing_indexes.acts_as_taggable_on_engine.rb +++ b/db/migrate/20161210105333_add_missing_indexes.acts_as_taggable_on_engine.rb @@ -7,8 +7,8 @@ class AddMissingIndexes < ActiveRecord::Migration add_index :taggings, :tagger_id add_index :taggings, :context - add_index :taggings, [:tagger_id, :tagger_type] - add_index :taggings, [:taggable_id, :taggable_type, :tagger_id, :context], + add_index :taggings, %i[tagger_id tagger_type] + add_index :taggings, %i[taggable_id taggable_type tagger_id context], name: 'taggings_idy' end end diff --git a/db/schema.rb b/db/schema.rb index fac548fe..c1d85b78 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -14,12 +14,12 @@ ActiveRecord::Schema.define(version: 20170422083422) do create_table "active_admin_comments", force: :cascade do |t| - t.string "namespace", limit: 255 - t.text "body", limit: 65535 - t.string "resource_id", limit: 255, null: false - t.string "resource_type", limit: 255, null: false - t.integer "author_id", limit: 4 - t.string "author_type", limit: 255 + t.string "namespace" + t.text "body" + t.string "resource_id", null: false + t.string "resource_type", null: false + t.integer "author_id" + t.string "author_type" t.datetime "created_at" t.datetime "updated_at" end