From 8b69a66380bbe32127e717ca2d79244392b7d2b6 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Tue, 9 Apr 2019 16:06:30 +0200 Subject: Add "why do you want to join" field to invite requests (#10524) * Add "why do you want to join" field to invite requests Fix #10512 * Remove unused translations * Fix broken registrations when no invite request text is submitted --- spec/fabricators/user_invite_request_fabricator.rb | 4 ++++ spec/models/user_invite_request_spec.rb | 4 ++++ 2 files changed, 8 insertions(+) create mode 100644 spec/fabricators/user_invite_request_fabricator.rb create mode 100644 spec/models/user_invite_request_spec.rb (limited to 'spec') diff --git a/spec/fabricators/user_invite_request_fabricator.rb b/spec/fabricators/user_invite_request_fabricator.rb new file mode 100644 index 000000000..5cc6ae56f --- /dev/null +++ b/spec/fabricators/user_invite_request_fabricator.rb @@ -0,0 +1,4 @@ +Fabricator(:user_invite_request) do + user + text { Faker::Lorem.sentence } +end diff --git a/spec/models/user_invite_request_spec.rb b/spec/models/user_invite_request_spec.rb new file mode 100644 index 000000000..1be38d8a4 --- /dev/null +++ b/spec/models/user_invite_request_spec.rb @@ -0,0 +1,4 @@ +require 'rails_helper' + +RSpec.describe UserInviteRequest, type: :model do +end -- cgit From 48f466daf1498173cf6ec36db58562df9a031297 Mon Sep 17 00:00:00 2001 From: Hinaloe Date: Wed, 10 Apr 2019 00:02:12 +0900 Subject: Allow set the voting period to just 5 minutes (#10525) * Add spec of PollValidator for #10190 * Raise fraction less than 1 second * format * simplify time initialize --- app/validators/poll_validator.rb | 2 +- spec/validators/poll_validator_spec.rb | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 spec/validators/poll_validator_spec.rb (limited to 'spec') diff --git a/app/validators/poll_validator.rb b/app/validators/poll_validator.rb index fd497c8d0..9d7321cad 100644 --- a/app/validators/poll_validator.rb +++ b/app/validators/poll_validator.rb @@ -14,6 +14,6 @@ class PollValidator < ActiveModel::Validator poll.errors.add(:options, I18n.t('polls.errors.over_character_limit', max: MAX_OPTION_CHARS)) if poll.options.any? { |option| option.mb_chars.grapheme_length > MAX_OPTION_CHARS } poll.errors.add(:options, I18n.t('polls.errors.duplicate_options')) unless poll.options.uniq.size == poll.options.size poll.errors.add(:expires_at, I18n.t('polls.errors.duration_too_long')) if poll.expires_at.nil? || poll.expires_at - current_time > MAX_EXPIRATION - poll.errors.add(:expires_at, I18n.t('polls.errors.duration_too_short')) if poll.expires_at.present? && poll.expires_at - current_time < MIN_EXPIRATION + poll.errors.add(:expires_at, I18n.t('polls.errors.duration_too_short')) if poll.expires_at.present? && (poll.expires_at - current_time).ceil < MIN_EXPIRATION end end diff --git a/spec/validators/poll_validator_spec.rb b/spec/validators/poll_validator_spec.rb new file mode 100644 index 000000000..941b83401 --- /dev/null +++ b/spec/validators/poll_validator_spec.rb @@ -0,0 +1,28 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe PollValidator, type: :validator do + describe '#validate' do + before do + validator.validate(poll) + end + + let(:validator) { described_class.new } + let(:poll) { double(options: options, expires_at: expires_at, errors: errors) } + let(:errors) { double(add: nil) } + let(:options) { %w(foo bar) } + let(:expires_at) { 1.day.from_now } + + it 'have no errors' do + expect(errors).not_to have_received(:add) + end + + context 'expires just 5 min ago' do + let(:expires_at) { 5.minutes.from_now } + it 'not calls errors add' do + expect(errors).not_to have_received(:add) + end + end + end +end -- cgit From 46cb36fd2cc641ab6c125f7e91140fa1b1d77634 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Wed, 10 Apr 2019 00:36:01 +0200 Subject: Add invite request to pending account notification e-mail (#10528) Fix sorting of the pending accounts page --- app/controllers/admin/pending_accounts_controller.rb | 2 +- app/helpers/application_helper.rb | 5 +++++ app/views/admin_mailer/new_pending_account.text.erb | 10 +++++++--- spec/mailers/previews/admin_mailer_preview.rb | 8 ++++++++ 4 files changed, 21 insertions(+), 4 deletions(-) create mode 100644 spec/mailers/previews/admin_mailer_preview.rb (limited to 'spec') diff --git a/app/controllers/admin/pending_accounts_controller.rb b/app/controllers/admin/pending_accounts_controller.rb index 249525504..b62a9bc84 100644 --- a/app/controllers/admin/pending_accounts_controller.rb +++ b/app/controllers/admin/pending_accounts_controller.rb @@ -30,7 +30,7 @@ module Admin private def set_accounts - @accounts = Account.joins(:user).merge(User.pending).includes(user: :invite_request).page(params[:page]) + @accounts = Account.joins(:user).merge(User.pending.recent).includes(user: :invite_request).page(params[:page]) end def form_account_batch_params diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index b42b1bbdf..9d113263d 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -117,4 +117,9 @@ module ApplicationHelper def storage_host? ENV['S3_ALIAS_HOST'].present? || ENV['S3_CLOUDFRONT_HOST'].present? end + + def quote_wrap(text, line_width: 80, break_sequence: "\n") + text = word_wrap(text, line_width: line_width - 2, break_sequence: break_sequence) + text.split("\n").map { |line| '> ' + line }.join("\n") + end end diff --git a/app/views/admin_mailer/new_pending_account.text.erb b/app/views/admin_mailer/new_pending_account.text.erb index ed31ae2eb..a466ee2de 100644 --- a/app/views/admin_mailer/new_pending_account.text.erb +++ b/app/views/admin_mailer/new_pending_account.text.erb @@ -2,7 +2,11 @@ <%= raw t('admin_mailer.new_pending_account.body') %> -<%= raw t('admin.accounts.email') %>: <%= @account.user_email %> -<%= raw t('admin.accounts.most_recent_ip') %>: <%= @account.user_current_sign_in_ip %> +<%= @account.user_email %> (@<%= @account.username %>) +<%= @account.user_current_sign_in_ip %> +<% if @account.user&.invite_request&.text.present? %> -<%= raw t('application_mailer.view')%> <%= admin_account_url(@account.id) %> +<%= quote_wrap(@account.user&.invite_request&.text) %> +<% end %> + +<%= raw t('application_mailer.view')%> <%= admin_pending_accounts_url %> diff --git a/spec/mailers/previews/admin_mailer_preview.rb b/spec/mailers/previews/admin_mailer_preview.rb new file mode 100644 index 000000000..561a56b78 --- /dev/null +++ b/spec/mailers/previews/admin_mailer_preview.rb @@ -0,0 +1,8 @@ +# Preview all emails at http://localhost:3000/rails/mailers/admin_mailer + +class AdminMailerPreview < ActionMailer::Preview + # Preview this email at http://localhost:3000/rails/mailers/admin_mailer/new_pending_account + def new_pending_account + AdminMailer.new_pending_account(Account.first, User.pending.first) + end +end -- cgit