diff --git a/app/controllers/admin/mail_aliases_controller.rb b/app/controllers/admin/mail_aliases_controller.rb index 12522f007..76c92781f 100644 --- a/app/controllers/admin/mail_aliases_controller.rb +++ b/app/controllers/admin/mail_aliases_controller.rb @@ -20,7 +20,7 @@ def update @aliases = MailAlias.insert_aliases! mail_alias_params[:username], mail_alias_params[:domain], mail_alias_params[:targets] || [] - rescue ActiveRecord::RecordInvalid => ex + rescue ActiveRecord::RecordInvalid render nothing: true, status: :unprocessable_entity return end diff --git a/app/controllers/adventures_controller.rb b/app/controllers/adventures_controller.rb index 6e4494a90..6631e08df 100644 --- a/app/controllers/adventures_controller.rb +++ b/app/controllers/adventures_controller.rb @@ -35,12 +35,12 @@ def set_mission_variables(adventure) @group = current_user.groups.regular.last @adventure_missions.each do |am| - @group_points_sum += am.points(@group) + @group_points_sum += am.points_per_group(@group) end @adventure_missions.map do |am| am.finished = am.finished?(@group) - am.points = am.points(@group) + am.points = am.points_per_group(@group) end @grid = initialize_grid(@adventure_missions, locale: :sv, order: "adventure_missions.index") diff --git a/app/controllers/api/push_devices_controller.rb b/app/controllers/api/push_devices_controller.rb index aa63ef122..f9f1d201a 100644 --- a/app/controllers/api/push_devices_controller.rb +++ b/app/controllers/api/push_devices_controller.rb @@ -14,7 +14,7 @@ def create def destroy @push_device = current_user.push_devices.find_by(token: params[:token]) - if @push_device && @push_device.destroy + if @push_device&.destroy render json: {}, status: :ok else render json: {errors: "Failed to destroy push device"}, status: 422 diff --git a/app/controllers/cafe_controller.rb b/app/controllers/cafe_controller.rb index e9474f61d..fee51cd7f 100644 --- a/app/controllers/cafe_controller.rb +++ b/app/controllers/cafe_controller.rb @@ -23,7 +23,7 @@ def competition def ladybug authorize_admin!(:ladybug, :cafe) - @date = if date = ladybug_date + @date = if (date = ladybug_date) Time.zone.parse(date) else Time.zone.now diff --git a/app/helpers/notification_helper.rb b/app/helpers/notification_helper.rb index 73fc1b724..8a6f03edb 100644 --- a/app/helpers/notification_helper.rb +++ b/app/helpers/notification_helper.rb @@ -4,7 +4,6 @@ def notification_context(notification, data) end def notification_icon(notification) - icon = "" if notification.notifyable_type == "EventUser" if notification.mode == "position" icon("fas", "check") diff --git a/app/models/adventures/adventure_mission.rb b/app/models/adventures/adventure_mission.rb index 09e5e98fe..73c18bc85 100644 --- a/app/models/adventures/adventure_mission.rb +++ b/app/models/adventures/adventure_mission.rb @@ -27,7 +27,7 @@ def accepted?(group) finished?(group) && adventure_mission_groups.by_group(group).first.pending == false end - def points(group) + def points_per_group(group) # Points only rewarded once mission is accepted if accepted?(group) adventure_mission_groups.by_group(group).first.points.to_i diff --git a/app/models/cars/rent.rb b/app/models/cars/rent.rb index 85a814fbf..d6e26cc14 100644 --- a/app/models/cars/rent.rb +++ b/app/models/cars/rent.rb @@ -62,7 +62,7 @@ def p_time # Requests route-helper to print url and path def p_url - Rails.application.routes.url_helpers.rent_url(id, host: PUBLIC_URL) + Rails.application.routes.url_helpers.rent_url(id, host: Rails.application.config.public_url) end def p_path diff --git a/app/models/constant.rb b/app/models/constant.rb index 0057862a1..43424272a 100644 --- a/app/models/constant.rb +++ b/app/models/constant.rb @@ -5,6 +5,6 @@ class Constant < ApplicationRecord def self.get(name) c = Constant.where(name: name).first - c && c.value || "" + c&.value.presence || "" end end diff --git a/app/models/council.rb b/app/models/council.rb index cddc9a453..c9afce00e 100644 --- a/app/models/council.rb +++ b/app/models/council.rb @@ -41,7 +41,7 @@ def to_param end def p_url - Rails.application.routes.url_helpers.council_url(id, host: PUBLIC_URL) + Rails.application.routes.url_helpers.council_url(id, host: Rails.application.config.public_url) end def p_path diff --git a/app/models/introduction.rb b/app/models/introduction.rb index 7524dee8d..3bdc8f88a 100644 --- a/app/models/introduction.rb +++ b/app/models/introduction.rb @@ -5,8 +5,6 @@ class Introduction < ApplicationRecord globalize_accessors(locales: [:en, :sv], attributes: [:title, :description]) - attr_reader :dates, :events_by_day, :dates_by_week - has_many :groups, dependent: :destroy has_many :group_users, through: :groups has_many :users, through: :groups diff --git a/app/models/messages/message_token.rb b/app/models/messages/message_token.rb index 2500a9661..5ecd2e31d 100644 --- a/app/models/messages/message_token.rb +++ b/app/models/messages/message_token.rb @@ -15,7 +15,7 @@ def self.add(user_id) expires = 30.seconds.from_now.to_i redis.expireat(KEY_BASE + token, expires) - data = {token: token, expires: expires} + {token: token, expires: expires} end # Finds the user_id for a token and removes the token diff --git a/app/models/nomination.rb b/app/models/nomination.rb index 6b451ba93..6cfb9814f 100644 --- a/app/models/nomination.rb +++ b/app/models/nomination.rb @@ -9,7 +9,7 @@ class Nomination < ApplicationRecord def candidate_url Rails.application.routes.url_helpers.new_candidate_url(post: post, - host: PUBLIC_URL) + host: Rails.application.config.public_url) end private diff --git a/app/models/notifications/notification.rb b/app/models/notifications/notification.rb index 391e46325..ad51c9aa7 100644 --- a/app/models/notifications/notification.rb +++ b/app/models/notifications/notification.rb @@ -41,11 +41,11 @@ def valid_notifyable end def allowed_class?(notifyable) - ALLOWED.keys.include?(notifyable.class.name) + ALLOWED.key?(notifyable.class.name) end def allowed_mode?(notifyable, mode) - ALLOWED[notifyable.class.name].keys.include?(mode) + ALLOWED[notifyable.class.name].key?(mode) end def update_counter_cache diff --git a/app/models/user.rb b/app/models/user.rb index 555e8991b..77eb8a301 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -88,7 +88,7 @@ def program_year str = "F" if program == PHYSICS str = "Pi" if program == MATH str = "N" if program == NANO - str += start_year.to_s.split("").last(2).join if start_year.present? + str += start_year.to_s.chars.last(2).join if start_year.present? str end diff --git a/app/serializers/api/cafe_shift_serializer.rb b/app/serializers/api/cafe_shift_serializer.rb index 163fc385f..77a350b91 100644 --- a/app/serializers/api/cafe_shift_serializer.rb +++ b/app/serializers/api/cafe_shift_serializer.rb @@ -17,7 +17,7 @@ def isme def councils councils = object.cafe_worker&.councils - council_map = { + { chosen: councils&.map { |c| [c.title, c.id] }.to_h, available: @instance_options[:current_user].councils.map { |c| [c.title, c.id] }.to_h } diff --git a/app/serializers/api/news_serializer.rb b/app/serializers/api/news_serializer.rb index 7ea577f3a..a410f42d9 100644 --- a/app/serializers/api/news_serializer.rb +++ b/app/serializers/api/news_serializer.rb @@ -9,7 +9,7 @@ def content end def image - PUBLIC_URL + object.image.large.url if object.image.present? + Rails.application.config.public_url + object.image.large.url if object.image.present? end class Api::UserSerializer < ActiveModel::Serializer diff --git a/app/serializers/message_serializer.rb b/app/serializers/message_serializer.rb index 767c7b857..4750b62be 100644 --- a/app/serializers/message_serializer.rb +++ b/app/serializers/message_serializer.rb @@ -15,7 +15,7 @@ def updated_at def image_url if object.image.present? # scope is group_id - "#{PUBLIC_URL}#{download_image_group_message_path(group_id: scope, id: object.id)}" + "#{Rails.application.config.public_url}#{download_image_group_message_path(group_id: scope, id: object.id)}" end end @@ -25,6 +25,6 @@ def image_url attribute(:avatar) def avatar - PUBLIC_URL + object.user.thumb_avatar if object.user.thumb_avatar + Rails.application.config.public_url + object.user.thumb_avatar if object.user.thumb_avatar end end diff --git a/app/services/cafe_service.rb b/app/services/cafe_service.rb index 70faf9a77..fc87e2372 100644 --- a/app/services/cafe_service.rb +++ b/app/services/cafe_service.rb @@ -95,9 +95,7 @@ def self.group_cafe_shifts(date_start, date_end, shifts) month = shift.start.month day_name = I18n.t("date.day_names")[week_day].capitalize month_name = I18n.t("date.month_names")[month].capitalize - unless h[:years][shift.start.year][:months][month_name][:days]["#{day_name} - #{shift.start.day}/#{shift.start.month}"].nil? - h[:years][shift.start.year][:months][month_name][:days]["#{day_name} - #{shift.start.day}/#{shift.start.month}"].push(Api::CafeShiftSerializer::Index.new(shift).as_json) - end + h[:years][shift.start.year][:months][month_name][:days]["#{day_name} - #{shift.start.day}/#{shift.start.month}"]&.push(Api::CafeShiftSerializer::Index.new(shift).as_json) end end end diff --git a/app/services/calendar_service.rb b/app/services/calendar_service.rb index 0220eb7c5..fc09ea3d4 100644 --- a/app/services/calendar_service.rb +++ b/app/services/calendar_service.rb @@ -39,7 +39,7 @@ def self.event(resource, locale: "sv") ical_event.created = date_time(resource.created_at.utc, tzid: "UTC") ical_event.last_modified = date_time(resource.updated_at.utc, tzid: "UTC") ical_event.url = Rails.application.routes.url_helpers.event_url(resource.id, - host: PUBLIC_URL) + host: Rails.application.config.public_url) ical_event.ip_class = "PUBLIC" ical_event end diff --git a/app/services/meeting_service.rb b/app/services/meeting_service.rb index efbf5ef86..c37c9e7eb 100644 --- a/app/services/meeting_service.rb +++ b/app/services/meeting_service.rb @@ -23,9 +23,7 @@ def self.create_recurring_meeting(meeting_params, old_recurring = nil) begin RecurringMeeting.transaction do # If old recurring is specified destroy it - if !old_recurring.nil? - old_recurring.destroy! - end + old_recurring&.destroy! recurring_meeting = RecurringMeeting.new(every: every) recurring_meeting.save! meetings.each do |meeting| diff --git a/app/view_objects/cafe_competition.rb b/app/view_objects/cafe_competition.rb index 8e3cd9993..6aabdffb9 100644 --- a/app/view_objects/cafe_competition.rb +++ b/app/view_objects/cafe_competition.rb @@ -1,5 +1,5 @@ class CafeCompetition - attr_accessor :cafe_workers, :lp, :users, :lps, :year, :years, :amount + attr_accessor :cafe_workers, :lp, :users, :lps, :year, :amount def initialize(lp:, year:, amount:) @cafe_workers = CafeQueries.cafe_workers(lp, year) @lp = lp diff --git a/app/view_objects/election_view.rb b/app/view_objects/election_view.rb index e3788ac1c..46e18b51c 100644 --- a/app/view_objects/election_view.rb +++ b/app/view_objects/election_view.rb @@ -1,5 +1,5 @@ class ElectionView - attr_reader :election, :post_count + attr_reader :election attr_accessor :rest_grid, :grid, :candidate, :user, :nomination def initialize(election, candidate: nil) diff --git a/app/views/election_mailer/candidate_email.html.erb b/app/views/election_mailer/candidate_email.html.erb index ba745a1f4..d4c701037 100644 --- a/app/views/election_mailer/candidate_email.html.erb +++ b/app/views/election_mailer/candidate_email.html.erb @@ -20,7 +20,7 @@ date: l(@candidate.election.post_closing(@candidate.post)))) %>
-<%= link_to(t('.show_your_candidacies'), candidates_url(host: PUBLIC_URL), class: 'btn') %> +<%= link_to(t('.show_your_candidacies'), candidates_url(host: Rails.application.config.public_url), class: 'btn') %>

diff --git a/config/environments/development.rb b/config/environments/development.rb index 16d1cc857..8c2e8ffee 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -1,5 +1,6 @@ Fsek::Application.configure do - PUBLIC_URL = "http://localhost:3000".freeze + config.public_url = "http://localhost:3000".freeze + # Settings specified here will take precedence over those in config/application.rb. # In the development environment your application's code is reloaded on @@ -29,7 +30,7 @@ # Don't care if the mailer can't send. # Send deprecation notices to registered listeners. config.active_support.deprecation = :notify - config.action_mailer.default_url_options = {host: PUBLIC_URL} + config.action_mailer.default_url_options = {host: config.public_url} config.action_mailer.delivery_method = :smtp config.action_mailer.perform_deliveries = true config.action_mailer.raise_delivery_errors = false @@ -39,7 +40,7 @@ config.action_mailer.smtp_settings = { address: "127.0.0.1", port: 1025, - domain: PUBLIC_URL, + domain: config.public_url, authentication: "plain", enable_starttls_auto: false } @@ -58,8 +59,8 @@ config.assets.digest = false # Assets for mailers - config.action_controller.asset_host = PUBLIC_URL - config.action_mailer.asset_host = PUBLIC_URL + config.action_controller.asset_host = config.public_url + config.action_mailer.asset_host = config.public_url config.action_view.raise_on_missing_translations = true @@ -75,7 +76,7 @@ Bullet.add_footer = true end - config.action_cable.allowed_request_origins = [PUBLIC_URL, "file://", "file:///"] + config.action_cable.allowed_request_origins = [config.public_url, "file://", "file:///"] # Use an evented file watcher to asynchronously detect changes in source code, # routes, locales, etc. This feature depends on the listen gem. diff --git a/config/environments/production.rb b/config/environments/production.rb index 33eb724f0..28ccebc4d 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -1,5 +1,5 @@ Rails.application.configure do - PUBLIC_URL = "https://fsektionen.se".freeze + config.public_url = "https://fsektionen.se".freeze # Settings specified here will take precedence over those in config/application.rb. # Code is not reloaded between requests. @@ -73,9 +73,9 @@ # Set this to true and configure the email server for immediate delivery to raise delivery errors. # config.action_mailer.raise_delivery_errors = false config.active_support.deprecation = :notify - config.action_mailer.asset_host = PUBLIC_URL + config.action_mailer.asset_host = config.public_url config.action_mailer.default charset: "utf-8" - config.action_mailer.default_url_options = {host: PUBLIC_URL} + config.action_mailer.default_url_options = {host: config.public_url} config.action_mailer.delivery_method = :smtp config.action_mailer.perform_deliveries = true config.action_mailer.raise_delivery_errors = true @@ -106,5 +106,5 @@ # Do not dump schema after migrations. config.active_record.dump_schema_after_migration = false - config.action_cable.allowed_request_origins = [PUBLIC_URL, "file://", "file:///"] + config.action_cable.allowed_request_origins = [config.public_url, "file://", "file:///"] end diff --git a/config/environments/staging.rb b/config/environments/staging.rb index 7c16652f2..66a790e1b 100644 --- a/config/environments/staging.rb +++ b/config/environments/staging.rb @@ -1,5 +1,5 @@ Rails.application.configure do - PUBLIC_URL = "https://stage.fsektionen.se".freeze + config.public_url = "https://stage.fsektionen.se".freeze # Settings specified here will take precedence over those in config/application.rb. # Code is not reloaded between requests. @@ -60,9 +60,9 @@ # Set this to true and configure the email server for immediate delivery to raise delivery errors. # config.action_mailer.raise_delivery_errors = false config.active_support.deprecation = :notify - config.action_mailer.asset_host = PUBLIC_URL + config.action_mailer.asset_host = config.public_url config.action_mailer.default charset: "utf-8" - config.action_mailer.default_url_options = {host: PUBLIC_URL} + config.action_mailer.default_url_options = {host: config.public_url} config.action_mailer.delivery_method = :smtp config.action_mailer.perform_deliveries = true config.action_mailer.raise_delivery_errors = true @@ -93,5 +93,5 @@ # Do not dump schema after migrations. config.active_record.dump_schema_after_migration = false - config.action_cable.allowed_request_origins = [PUBLIC_URL, "file://", "file:///"] + config.action_cable.allowed_request_origins = [config.public_url, "file://", "file:///"] end diff --git a/config/environments/test.rb b/config/environments/test.rb index 24a487c6c..1f0858557 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -1,5 +1,5 @@ Fsek::Application.configure do - PUBLIC_URL = "http://localhost:3000".freeze + config.public_url = "https://fsektionen.se".freeze # Settings specified here will take precedence over those in config/application.rb. # The test environment is used exclusively to run your application's @@ -38,9 +38,9 @@ # Print deprecation notices to the stderr. config.active_support.deprecation = :stderr - config.action_controller.asset_host = PUBLIC_URL - config.action_mailer.default_url_options = {host: PUBLIC_URL} - config.action_mailer.asset_host = PUBLIC_URL + config.action_controller.asset_host = config.public_url + config.action_mailer.default_url_options = {host: config.public_url} + config.action_mailer.asset_host = config.public_url config.action_view.raise_on_missing_translations = true end diff --git a/config/initializers/action_cable_config.rb b/config/initializers/action_cable_config.rb index b9d22ea2c..7c6bad9ae 100644 --- a/config/initializers/action_cable_config.rb +++ b/config/initializers/action_cable_config.rb @@ -3,7 +3,8 @@ module ActionCableConfig def self.[](key) unless @config template = ERB.new(File.read(Rails.root + "config/cable.yml")) - @config = YAML.load(template.result(binding))[Rails.env].symbolize_keys + # TODO: Use safe_load switched to ruby 2.6 + @config = YAML.load(template.result(binding))[Rails.env].symbolize_keys # rubocop:disable Security/YAMLLoad end @config[key] diff --git a/config/initializers/carrierwave.rb b/config/initializers/carrierwave.rb index e564b1216..512aab17e 100644 --- a/config/initializers/carrierwave.rb +++ b/config/initializers/carrierwave.rb @@ -4,9 +4,11 @@ config.enable_processing = false end + # rubocop:disable Lint/Void AttachedImageUploader DocumentUploader ImageUploader + # rubocop:enable Lint/Void CarrierWave::Uploader::Base.descendants.each do |klass| next if klass.anonymous? diff --git a/config/initializers/rpush.rb b/config/initializers/rpush.rb index 9724169d5..6b8e1ea77 100644 --- a/config/initializers/rpush.rb +++ b/config/initializers/rpush.rb @@ -20,7 +20,7 @@ # Path to log file. Relative to current directory unless absolute. config.log_file = "log/rpush.log" - config.log_level = defined?(Rails) && Rails.logger ? Rails.logger.level : ::Logger::Severity::INFO + config.log_level = defined?(Rails) && Rails.logger ? Rails.logger.level : ::Logger::Severity::INFO # rubocop:disable Lint/RequireParentheses # Define a custom logger. # config.logger = MyLogger.new diff --git a/config/puma.rb b/config/puma.rb index 33f5fae7a..943aeaf62 100644 --- a/config/puma.rb +++ b/config/puma.rb @@ -4,16 +4,16 @@ # the maximum value specified for Puma. Default is set to 5 threads for minimum # and maximum; this matches the default thread size of Active Record. # -threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 } +threads_count = ENV.fetch("RAILS_MAX_THREADS", 5) threads threads_count, threads_count # Specifies the `port` that Puma will listen on to receive requests; default is 3000. # -port ENV.fetch("PORT") { 3000 } +port ENV.fetch("PORT", 3000) # Specifies the `environment` that Puma will run in. # -environment ENV.fetch("RAILS_ENV") { "development" } +environment ENV.fetch("RAILS_ENV", "development") # Specifies the number of `workers` to boot in clustered mode. # Workers are forked webserver processes. If using threads and workers together diff --git a/config/sitemap.rb b/config/sitemap.rb index 48e8d74fc..ca14989b8 100644 --- a/config/sitemap.rb +++ b/config/sitemap.rb @@ -1,6 +1,6 @@ # Set the host name for URL creation -puts PUBLIC_URL -SitemapGenerator::Sitemap.default_host = PUBLIC_URL +puts Rails.application.config.public_url +SitemapGenerator::Sitemap.default_host = Rails.application.config.public_url SitemapGenerator::Sitemap.sitemaps_path = "sitemaps/" SitemapGenerator::Sitemap.create do diff --git a/db/migrate/20160922115838_add_use_case_to_category.rb b/db/migrate/20160922115838_add_use_case_to_category.rb index 9b241af80..5edde9c3f 100644 --- a/db/migrate/20160922115838_add_use_case_to_category.rb +++ b/db/migrate/20160922115838_add_use_case_to_category.rb @@ -1,5 +1,5 @@ class AddUseCaseToCategory < ActiveRecord::Migration[5.0] def change - add_column(:categories, :use_case, :string, default: "general", null: :false, index: true) + add_column(:categories, :use_case, :string, default: "general", null: false, index: true) end end diff --git a/lib/tasks/permissions.rake b/lib/tasks/permissions.rake index f3af11679..a8488f88d 100644 --- a/lib/tasks/permissions.rake +++ b/lib/tasks/permissions.rake @@ -44,27 +44,21 @@ def eval_cancan_action(action) when "index" name = "list" cancan_action = "index" # let the cancan action be the actual method name - action_desc = I18n.t(:list) when "new", "create" name = "create and update" cancan_action = "create" - action_desc = I18n.t :create when "show" name = "view" cancan_action = "view" - action_desc = I18n.t :view when "edit", "update" name = "create and update" cancan_action = "update" - action_desc = I18n.t :update when "delete", "destroy" name = "delete" cancan_action = "destroy" - action_desc = I18n.t :destroy else name = action.to_s cancan_action = action.to_s - action_desc = "Other: " < cancan_action end [name, cancan_action] end diff --git a/old/import_old_albums.rb b/old/import_old_albums.rb deleted file mode 100644 index 95f84cded..000000000 --- a/old/import_old_albums.rb +++ /dev/null @@ -1,172 +0,0 @@ -### -### Mega album import script. -### This code was run on 31 Oct 2016 to import the old image albums. -### - -# Ensure no-one runs this by mistake -fail "No! Don't run this code. It's for reference only." - -# Pull in the rails app environment -require "./config/environment" - -# Establish connection to the database -conn = ActiveRecord::Base.connection - -# Load items and item attributes -# Note: we are loading from an external database, not the app DB. -items_and_attributes = conn.execute <<-SQL - select I.g_id, I.g_canContainChildren, I.g_summary, I.g_title, - A.g_parentSequence, F.g_pathComponent - from gallery.g2_Item I - join gallery.g2_ItemAttributesMap A on I.g_id = A.g_itemId - join gallery.g2_FileSystemEntity F on I.g_id = F.g_id - order by A.g_parentSequence asc - ; -SQL - -# Guess the root node -root_id = items_and_attributes.first[0] - -# Build tree structure -tree = {root_id => {title: "ROOT", children: {}}} - -items_and_attributes.each do |vals| - id, ccc, summary, title, parents, pathcomp = vals - - next if id == root_id - - # Find parent node - parent_ids = parents.split("/").map(&:to_i) - parent_ids.shift # remove root id - parent = tree[root_id] - - parent_ids.each do |i| - parent = parent[:children][i] - parent[:children] ||= {} - end - - # Add this node to the tree - parent[:children][id] = { - title: title, - summary: summary, - path: "#{parent[:path]}/#{pathcomp}" - } -end - -# Transform tree to flat table of albums - -@album_counter = 0 -@picture_counter = 0 - -def recursive_collect node, album_acc, pictures_acc = nil, name_acc = nil, year = nil, level = 0 - if level == 0 - elsif level == 1 - year = node[:title].to_i - elsif level >= 2 && node[:children] - name_acc = if name_acc - "#{name_acc} - #{node[:title]}" - else - node[:title] - end - - album = { - year: year, - title: name_acc, - summary: node[:summary], - pictures: [] - } - - album_acc << album - pictures_acc = album[:pictures] - @album_counter += 1 - end - - if node[:children] - node[:children].each do |k, v| - recursive_collect v, album_acc, pictures_acc, name_acc, year, level + 1 - end - else - pictures_acc << node - @picture_counter += 1 - end -end - -album_table = [] -recursive_collect tree[root_id], album_table - -puts sprintf("Found %d pictures in %d albums.", @picture_counter, @album_counter) - -# Insert all the found albums into the database. - -BASE = "/oldroot/var/www/gallery_data/albums" - -album_table.each do |ia| - # No empty albums - if ia[:pictures].empty? - next - end - - # Ensure we don't create any duplicates - result = conn.execute <<-SQL - select 1 from albums a, album_translations t - where a.id = t.album_id - and t.locale = 'sv' - and year(a.start_date) = #{ia[:year]} - and t.title = #{ActiveRecord::Base.sanitize(ia[:title])} - limit 1 - ; - SQL - - if result.any? - next - end - - description = ia[:summary].present? ? ia[:summary] : "_" - - a = Album.new title_sv: ia[:title], - title_en: ia[:title], - description_sv: description, - description_en: description, - start_date: Date.parse("#{ia[:year]}-01-02"), - end_date: Date.parse("#{ia[:year]}-12-30") - begin - a.save! - rescue ActiveRecord::RecordInvalid => ex - binding.pry - end - - puts "#{a.id}: #{a.title} (#{a.start_date.year})" - - ia[:pictures].each do |ip| - # If there are still any bad files in the tree at this point, they are ignored. - filename = File.join(BASE, ip[:path]) - if !File.exist?(filename) || File.directory?(filename) - next - end - - # A small attempt to reformat the "summary" to fit the new system. - photographer_name = ip[:summary] || "" - photograhper_name = photographer_name.gsub(/Fotografe?r?:? /, "") - - i = Image.new album_id: a.id, - file: File.new(File.join(BASE, ip[:path])), - photographer_name: photographer_name - begin - i.save! - rescue ActiveRecord::RecordInvalid => ex - binding.pry - end - - print "." - $stdout.flush - end - - # No idea if this is needed. - a.images_count = ia[:pictures].count - a.save! - - puts " done" -end - -# The cache doesn't work when we insert albums manually, so just nuke it. -Rails.cache.clear diff --git a/spec/controllers/admin/event_signups_controller_spec.rb b/spec/controllers/admin/event_signups_controller_spec.rb index 20408876b..f1fdbf0e6 100644 --- a/spec/controllers/admin/event_signups_controller_spec.rb +++ b/spec/controllers/admin/event_signups_controller_spec.rb @@ -33,14 +33,14 @@ fourth = new_event_user(event, EventSignup::MEMBER, group1) # Group 2 - eu1 = new_event_user(event, EventSignup::MEMBER, group2) + _eu1 = new_event_user(event, EventSignup::MEMBER, group2) eu4 = new_event_user(event, EventSignup::NOVICE, group2) eu7 = new_event_user(event, EventSignup::NOVICE, group2) # Group 3 - eu2 = new_event_user(event, EventSignup::MEMBER, group3) + _eu2 = new_event_user(event, EventSignup::MEMBER, group3) eu5 = new_event_user(event, EventSignup::CUSTOM, group3) - eu8 = new_event_user(event, EventSignup::MEMBER, group3) + _eu8 = new_event_user(event, EventSignup::MEMBER, group3) # Expected results attend = [first, second, third, fourth, eu4, eu7, eu5] diff --git a/spec/controllers/admin/short_links_controller_spec.rb b/spec/controllers/admin/short_links_controller_spec.rb index 8f5b4b054..9127227ce 100644 --- a/spec/controllers/admin/short_links_controller_spec.rb +++ b/spec/controllers/admin/short_links_controller_spec.rb @@ -28,7 +28,7 @@ end it "updates old shortlink for old link" do - old_sl = create :short_link + create :short_link new_sl = build :short_link, target: "newurl.com" post :create, params: {short_link: new_sl.attributes} diff --git a/spec/models/mail_alias_spec.rb b/spec/models/mail_alias_spec.rb index c94b2720a..060ff46fa 100644 --- a/spec/models/mail_alias_spec.rb +++ b/spec/models/mail_alias_spec.rb @@ -46,10 +46,10 @@ m2 = create(:mail_alias, username: "erik", domain: "fsektionen.se", target: "erikhenrikssn@gmail.com") - MailAlias.fulltext_search("johan").should == [m1] - MailAlias.fulltext_search("jo").should == [m1] - MailAlias.fulltext_search("johannes").should == [] - MailAlias.fulltext_search("erik").should == [m2] + MailAlias.fulltext_search("johan").should eq([m1]) + MailAlias.fulltext_search("jo").should eq([m1]) + MailAlias.fulltext_search("johannes").should eq([]) + MailAlias.fulltext_search("erik").should eq([m2]) end end @@ -57,7 +57,7 @@ it "can set empty target list (clear)" do c = create :mail_alias MailAlias.insert_aliases! c.username, c.domain, [] - MailAlias.count.should == 0 + MailAlias.count.should eq(0) end it "can create new alias" do @@ -70,7 +70,7 @@ it "touches existing records" do c = create :mail_alias, updated_at: 1.month.ago MailAlias.insert_aliases! c.username, c.domain, [c.target] - MailAlias.count.should == 1 + MailAlias.count.should eq(1) MailAlias.first.updated_at.to_date.should == Time.zone.now.to_date end end diff --git a/spec/models/nomination_spec.rb b/spec/models/nomination_spec.rb index 8ba7ce8f6..228f36e90 100644 --- a/spec/models/nomination_spec.rb +++ b/spec/models/nomination_spec.rb @@ -24,7 +24,7 @@ nomination = build_stubbed(:nomination) post = nomination.post - nomination.candidate_url.should eq(new_candidate_url(post: post.id, host: PUBLIC_URL)) + nomination.candidate_url.should eq(new_candidate_url(post: post.id, host: Rails.application.config.public_url)) end end end