diff --git a/.gitignore b/.gitignore index 70a3775c7..00ec87fc7 100644 --- a/.gitignore +++ b/.gitignore @@ -48,3 +48,5 @@ sgemset tags .localeapp + +.byebug_history diff --git a/.rubocop.yml b/.rubocop.yml index 62dfcb6ab..d36a46731 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -5,9 +5,6 @@ AllCops: Naming/AccessorMethodName: Enabled: false -Rails/ActionFilter: - Enabled: false - Style/Alias: Enabled: false @@ -57,15 +54,15 @@ Style/CommentAnnotation: Metrics/CyclomaticComplexity: Enabled: false -Rails/Delegate: - Enabled: false - Style/Documentation: Enabled: false Layout/DotPosition: EnforcedStyle: trailing +Layout/ConditionPosition: + Enabled: false + Style/DoubleNegation: Enabled: false @@ -84,9 +81,6 @@ Style/EvenOdd: Naming/FileName: Enabled: false -Style/FlipFlop: - Enabled: false - Style/FormatString: Enabled: false @@ -114,7 +108,7 @@ Style/LambdaCall: Style/LineEndConcatenation: Enabled: false -Metrics/LineLength: +Layout/LineLength: Max: 80 Metrics/MethodLength: @@ -154,7 +148,7 @@ Style/PerlBackrefs: Enabled: false Naming/PredicateName: - NamePrefixBlacklist: + ForbiddenPrefixes: - is_ Style/Proc: @@ -187,16 +181,16 @@ Style/StringLiterals: Style/VariableInterpolation: Enabled: false -Style/TrailingCommaInLiteral: +Style/TrailingCommaInArrayLiteral: Enabled: false -Style/TrailingCommaInArguments: +Style/TrailingCommaInHashLiteral: Enabled: false -Style/TrivialAccessors: +Style/TrailingCommaInArguments: Enabled: false -Style/VariableInterpolation: +Style/TrivialAccessors: Enabled: false Style/WhenThen: @@ -214,16 +208,13 @@ Lint/AmbiguousRegexpLiteral: Lint/AssignmentInCondition: Enabled: false -Lint/ConditionPosition: - Enabled: false - Lint/DeprecatedClassMethods: Enabled: false Lint/ElseLayout: Enabled: false -Lint/HandleExceptions: +Lint/SuppressedException: Enabled: false Lint/LiteralInInterpolation: @@ -243,3 +234,6 @@ Lint/UnderscorePrefixedVariableName: Lint/Void: Enabled: false + +Lint/FlipFlop: + Enabled: false diff --git a/Gemfile b/Gemfile index 76bb04c84..2c30d18f8 100644 --- a/Gemfile +++ b/Gemfile @@ -16,17 +16,13 @@ gem 'unicorn' gem 'kaminari', '~> 1.1.1' gem "simple_form", ">= 3.0.0" gem 'rollbar', '2.8.3' -gem 'whenever', require: false gem 'prawn', '~> 2.2.0' gem 'prawn-table', '~> 0.2.2' gem 'elasticsearch-model' gem 'elasticsearch-rails' gem 'skylight' gem 'sidekiq', '5.1.3' -gem 'sidekiq-cron', '0.6.3' -# TODO: remove this once the following issue has been addressed -# https://github.com/ondrejbartas/sidekiq-cron/issues/199 -gem 'rufus-scheduler', '~> 3.4.2' +gem 'sidekiq-cron', '~> 1.1.0' # Assets gem 'jquery-rails', '>= 4.2.0' @@ -39,7 +35,7 @@ gem 'select2-rails' group :development do gem "binding_of_caller", '~> 0.8.0' gem "better_errors", '~> 2.4.0' - gem 'rubocop', '~> 0.52.1', require: false + gem 'rubocop', '~> 0.80.0', require: false gem 'web-console', '2.1.3' gem 'capistrano', '~> 3.1' gem 'capistrano-rails', '~> 1.1' @@ -51,17 +47,17 @@ group :development do end group :development, :test do - gem "byebug" + gem "byebug", '~> 11.0' end group :test do gem "rspec-rails", '~> 3.8.2' gem "database_cleaner", '1.6.2' gem 'shoulda-matchers', '~> 3.1.2' - gem 'fabrication' + gem 'fabrication', '~> 2.20' gem 'faker', '~> 1.9' gem 'capybara', '~> 3.15' gem 'selenium-webdriver', '~> 3.142' - gem 'webdrivers', '~> 4.1.2' + gem 'webdrivers', '~> 4.2.0' gem 'simplecov', '~> 0.17', require: false end diff --git a/Gemfile.lock b/Gemfile.lock index 400b860bc..fcf98c7a3 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -47,8 +47,8 @@ GEM minitest (~> 5.1) thread_safe (~> 0.3, >= 0.3.4) tzinfo (~> 1.1) - addressable (2.5.1) - public_suffix (~> 2.0, >= 2.0.2) + addressable (2.7.0) + public_suffix (>= 2.0.2, < 5.0) airbrussh (0.8.0) sshkit (>= 1.6.1, != 1.7.0) arbre (1.1.1) @@ -69,8 +69,7 @@ GEM autoprefixer-rails (>= 5.2.1) sass (>= 3.3.4) builder (3.2.3) - byebug (4.0.5) - columnize (= 0.9.0) + byebug (11.0.0) capistrano (3.4.1) i18n rake (>= 10.0.0) @@ -84,17 +83,15 @@ GEM capistrano-rbenv (2.1.3) capistrano (~> 3.1) sshkit (~> 1.3) - capybara (3.15.1) + capybara (3.31.0) addressable mini_mime (>= 0.1.3) nokogiri (~> 1.8) rack (>= 1.6.0) rack-test (>= 0.6.3) - regexp_parser (~> 1.2) + regexp_parser (~> 1.5) xpath (~> 3.2) - childprocess (1.0.1) - rake (< 13.0) - chronic (0.10.2) + childprocess (3.0.0) coderay (1.1.2) coffee-rails (4.1.0) coffee-script (>= 2.2.0) @@ -103,7 +100,6 @@ GEM coffee-script-source execjs coffee-script-source (1.8.0) - columnize (0.9.0) concurrent-ruby (1.1.5) connection_pool (2.2.1) crass (1.0.4) @@ -138,10 +134,10 @@ GEM multi_json erubi (1.7.1) erubis (2.7.0) - et-orbi (1.1.2) + et-orbi (1.1.7) tzinfo execjs (2.6.0) - fabrication (2.11.3) + fabrication (2.20.1) faker (1.9.3) i18n (>= 0.7) faraday (0.9.1) @@ -149,6 +145,9 @@ GEM formtastic (3.1.5) actionpack (>= 3.2.13) formtastic_i18n (0.6.0) + fugit (1.1.8) + et-orbi (~> 1.1, >= 1.1.7) + raabro (~> 1.1) gli (2.16.0) globalid (0.4.2) activesupport (>= 4.2.0) @@ -168,6 +167,7 @@ GEM has_scope (~> 0.6) railties (>= 4.2, <= 5.2) responders + jaro_winkler (1.5.4) jquery-rails (4.3.1) rails-dom-testing (>= 1, < 3) railties (>= 4.2.0) @@ -203,7 +203,7 @@ GEM mime-types (3.1) mime-types-data (~> 3.2015) mime-types-data (3.2016.0521) - mini_mime (1.0.1) + mini_mime (1.0.2) mini_portile2 (2.4.0) minitest (5.11.3) multi_json (1.11.2) @@ -212,26 +212,26 @@ GEM net-ssh (>= 2.6.5, < 6.0.0) net-ssh (5.2.0) netrc (0.11.0) - nokogiri (1.10.3) + nokogiri (1.10.8) mini_portile2 (~> 2.4.0) orm_adapter (0.5.0) - parallel (1.12.1) - parser (2.5.0.0) + parallel (1.19.1) + parser (2.7.0.2) ast (~> 2.4.0) pdf-core (0.7.0) pg (0.21.0) polyamorous (1.3.3) activerecord (>= 3.0) - powerpack (0.1.1) prawn (2.2.2) pdf-core (~> 0.7.0) ttfunk (~> 1.5) prawn-table (0.2.2) prawn (>= 1.3.0, < 3.0.0) - public_suffix (2.0.5) + public_suffix (4.0.3) pundit (2.0.0) activesupport (>= 3.0.0) - rack (1.6.11) + raabro (1.1.6) + rack (1.6.13) rack-protection (2.0.1) rack rack-test (0.6.3) @@ -265,7 +265,7 @@ GEM thor (>= 0.18.1, < 2.0) rainbow (3.0.0) raindrops (0.16.0) - rake (12.3.3) + rake (13.0.1) ransack (1.8.6) actionpack (>= 3.0) activerecord (>= 3.0) @@ -282,6 +282,7 @@ GEM http-cookie (>= 1.0.2, < 2.0) mime-types (>= 1.16, < 4.0) netrc (~> 0.8) + rexml (3.2.4) rollbar (2.8.3) multi_json rspec-core (3.8.0) @@ -301,17 +302,16 @@ GEM rspec-mocks (~> 3.8.0) rspec-support (~> 3.8.0) rspec-support (3.8.0) - rubocop (0.52.1) + rubocop (0.80.0) + jaro_winkler (~> 1.5.1) parallel (~> 1.10) - parser (>= 2.4.0.2, < 3.0) - powerpack (~> 0.1) + parser (>= 2.7.0.1) rainbow (>= 2.2.2, < 4.0) + rexml ruby-progressbar (~> 1.7) - unicode-display_width (~> 1.0, >= 1.0.1) - ruby-progressbar (1.9.0) - rubyzip (1.2.3) - rufus-scheduler (3.4.2) - et-orbi (~> 1.0) + unicode-display_width (>= 1.4.0, < 1.7) + ruby-progressbar (1.10.1) + rubyzip (2.2.0) sass (3.4.21) sass-rails (5.0.7) railties (>= 4.0.0, < 6) @@ -321,9 +321,9 @@ GEM tilt (>= 1.1, < 3) select2-rails (4.0.1) thor (~> 0.14) - selenium-webdriver (3.142.3) - childprocess (>= 0.5, < 2.0) - rubyzip (~> 1.2, >= 1.2.2) + selenium-webdriver (3.142.7) + childprocess (>= 0.5, < 4.0) + rubyzip (>= 1.2.2) shoulda-matchers (3.1.2) activesupport (>= 4.0.0) sidekiq (5.1.3) @@ -331,8 +331,8 @@ GEM connection_pool (~> 2.2, >= 2.2.0) rack-protection (>= 1.5.0) redis (>= 3.3.5, < 5) - sidekiq-cron (0.6.3) - rufus-scheduler (>= 3.3.0) + sidekiq-cron (1.1.0) + fugit (~> 1.1) sidekiq (>= 4.2.1) simple_form (3.1.0) actionpack (~> 4.0) @@ -368,7 +368,7 @@ GEM unf (0.1.4) unf_ext unf_ext (0.0.7.2) - unicode-display_width (1.3.0) + unicode-display_width (1.6.1) unicorn (5.0.1) kgio (~> 2.6) rack @@ -380,12 +380,10 @@ GEM binding_of_caller (>= 0.7.2) railties (>= 4.0) sprockets-rails (>= 2.0, < 4.0) - webdrivers (4.1.2) + webdrivers (4.2.0) nokogiri (~> 1.6) - rubyzip (~> 1.0) + rubyzip (>= 1.3.0) selenium-webdriver (>= 3.0, < 4.0) - whenever (0.9.4) - chronic (>= 0.6.3) xpath (3.2.0) nokogiri (~> 1.8) @@ -398,7 +396,7 @@ DEPENDENCIES better_errors (~> 2.4.0) binding_of_caller (~> 0.8.0) bootstrap-sass - byebug + byebug (~> 11.0) capistrano (~> 3.1) capistrano-rails (~> 1.1) capistrano-rbenv (~> 2.1) @@ -409,7 +407,7 @@ DEPENDENCIES dotenv-rails (~> 2.7.1) elasticsearch-model elasticsearch-rails - fabrication + fabrication (~> 2.20) faker (~> 1.9) has_scope hstore_translate @@ -427,22 +425,20 @@ DEPENDENCIES rdiscount rollbar (= 2.8.3) rspec-rails (~> 3.8.2) - rubocop (~> 0.52.1) - rufus-scheduler (~> 3.4.2) + rubocop (~> 0.80.0) sass-rails (~> 5.0.7) select2-rails selenium-webdriver (~> 3.142) shoulda-matchers (~> 3.1.2) sidekiq (= 5.1.3) - sidekiq-cron (= 0.6.3) + sidekiq-cron (~> 1.1.0) simple_form (>= 3.0.0) simplecov (~> 0.17) skylight uglifier (= 2.7.2) unicorn web-console (= 2.1.3) - webdrivers (~> 4.1.2) - whenever + webdrivers (~> 4.2.0) RUBY VERSION ruby 2.6.3p62 diff --git a/app/jobs/organization_notifier_job.rb b/app/jobs/organization_notifier_job.rb new file mode 100644 index 000000000..1bd46729c --- /dev/null +++ b/app/jobs/organization_notifier_job.rb @@ -0,0 +1,20 @@ +# A weekly digest email. +# +# Strategy: go throught all organizations and take latest active posts from last week +# posted by active members. Send an email to all active and online members +# with the email notifications enabled with those posts. + +# Schedule defined in config/schedule.yml file. + +class OrganizationNotifierJob < ActiveJob::Base + queue_as :cron + + def perform + Organization.all.find_each do |org| + posts = org.posts.active.of_active_members.from_last_week + if posts.present? + OrganizationNotifier.recent_posts(posts).deliver_now + end + end + end +end diff --git a/app/mailers/.gitkeep b/app/mailers/.gitkeep deleted file mode 100644 index e69de29bb..000000000 diff --git a/app/mailers/.keep b/app/mailers/.keep deleted file mode 100644 index e69de29bb..000000000 diff --git a/app/services/organization_notifier_service.rb b/app/services/organization_notifier_service.rb deleted file mode 100644 index cd00e0013..000000000 --- a/app/services/organization_notifier_service.rb +++ /dev/null @@ -1,14 +0,0 @@ -class OrganizationNotifierService - def initialize(organization) - @organization = organization - end - - def send_recent_posts_to_online_members - @organization.each do |org| - posts = org.posts.active.of_active_members.from_last_week - if posts.present? - OrganizationNotifier.recent_posts(posts).deliver_now - end - end - end -end diff --git a/bin/whenever b/bin/whenever deleted file mode 100755 index 373d0612a..000000000 --- a/bin/whenever +++ /dev/null @@ -1,16 +0,0 @@ -#!/usr/bin/env ruby -# -# This file was generated by Bundler. -# -# The application 'whenever' is installed as part of a gem, and -# this file is here to facilitate running it. -# - -require 'pathname' -ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile", - Pathname.new(__FILE__).realpath) - -require 'rubygems' -require 'bundler/setup' - -load Gem.bin_path('whenever', 'whenever') diff --git a/config/schedule.rb b/config/schedule.rb deleted file mode 100644 index bf3363e67..000000000 --- a/config/schedule.rb +++ /dev/null @@ -1,34 +0,0 @@ -set :environment, "production" -set :output, "log/cron_log.log" - -every :monday, at: "9am" do - runner "OrganizationNotifierService.new(Organization.all). - send_recent_posts_to_online_members" -end - -# Cada vez que se modifique este archivo, crontab debe actualizarse: -# whenever --update-crontab - -# Use this file to easily define all of your cron jobs. -# -# It's helpful, but not entirely necessary to understand cron before proceeding. -# http://en.wikipedia.org/wiki/Cron - -# Example: -# -# set :output, "/path/to/my/cron_log.log" -# -# every 2.hours do -# command "/usr/bin/some_great_command" -# runner "MyModel.some_method" -# rake "some:great:rake:task" -# end -# -# every 4.days do -# runner "AnotherModel.prune_old_records" -# end - -# Learn more: http://github.com/javan/whenever - -# rake "pruebas:hello" #task en lib/tasks para comprobar el funcionamiento de -# whenever diff --git a/config/schedule.yml b/config/schedule.yml index 56487c3a6..7116ad52d 100644 --- a/config/schedule.yml +++ b/config/schedule.yml @@ -2,3 +2,7 @@ send_push_notifications_job: cron: '*/5 * * * *' class: 'SendPushNotificationsJob' queue: cron +weekly_digest: + cron: '0 9 * * 1' # every monday at 9am + class: 'OrganizationNotifierJob' + queue: cron diff --git a/spec/controllers/inquiries_controller_spec.rb b/spec/controllers/inquiries_controller_spec.rb index 495c13a4f..f7bc2141e 100644 --- a/spec/controllers/inquiries_controller_spec.rb +++ b/spec/controllers/inquiries_controller_spec.rb @@ -11,10 +11,6 @@ organization: test_organization, category: test_category) end - - include_context "stub browser locale" - - before { set_browser_locale("ca") } describe "GET #index" do context "with a logged user" do @@ -42,7 +38,7 @@ describe "POST #create" do context "with valid params" do - context "with a logged user" do + context "with a logged user" do it "creates a new inquiry" do login(another_member.user) expect do @@ -59,7 +55,7 @@ context "with valid params" do context "with a logged user" do before { login(member.user) } - + it "located the requested @inquiry" do put "update", id: inquiry.id, inquiry: Fabricate.to_params(:inquiry) expect(assigns(:inquiry)).to eq(inquiry) @@ -83,7 +79,7 @@ end context "with invalid params" do - context "with a logged user" do + context "with a logged user" do it "does not change @inquiry's attributes" do login(member.user) @@ -103,7 +99,7 @@ describe "DELETE destroy" do before { login(member.user) } - + it "toggle active field" do delete :destroy, id: inquiry.id diff --git a/spec/controllers/multi_transfers_controller_spec.rb b/spec/controllers/multi_transfers_controller_spec.rb index bab67003e..1caa040c7 100644 --- a/spec/controllers/multi_transfers_controller_spec.rb +++ b/spec/controllers/multi_transfers_controller_spec.rb @@ -14,10 +14,6 @@ category: test_category) end - include_context "stub browser locale" - - before { set_browser_locale("en") } - it 'creates one to many transfers' do expect do login(admin.user) diff --git a/spec/controllers/offers_controller_spec.rb b/spec/controllers/offers_controller_spec.rb index 4f1db8ecf..7d0619b89 100644 --- a/spec/controllers/offers_controller_spec.rb +++ b/spec/controllers/offers_controller_spec.rb @@ -13,10 +13,6 @@ category: test_category) end - include_context "stub browser locale" - - before { set_browser_locale("ca") } - describe "GET #index" do context "with a logged user" do it "populates an array of offers" do diff --git a/spec/controllers/transfers_controller_spec.rb b/spec/controllers/transfers_controller_spec.rb index 96b4bd05f..453b861c9 100644 --- a/spec/controllers/transfers_controller_spec.rb +++ b/spec/controllers/transfers_controller_spec.rb @@ -6,10 +6,6 @@ let (:member_giver) { Fabricate(:member, organization: test_organization) } let (:member_taker) { Fabricate(:member, organization: test_organization) } - include_context 'stub browser locale' - - before { set_browser_locale('ca') } - describe '#new' do let(:user) { member_giver.user } diff --git a/spec/controllers/users_controller_spec.rb b/spec/controllers/users_controller_spec.rb index 698af6d57..23842b261 100644 --- a/spec/controllers/users_controller_spec.rb +++ b/spec/controllers/users_controller_spec.rb @@ -34,9 +34,6 @@ let!(:wrong_user) { wrong_email_member.user } let!(:empty_email_user) { empty_email_member.user } - include_context "stub browser locale" - before { set_browser_locale("ca") } - describe "GET #index" do before { login(user) } diff --git a/spec/fabricators/user_fabricator.rb b/spec/fabricators/user_fabricator.rb index 5d0b196da..e2d5c3f34 100644 --- a/spec/fabricators/user_fabricator.rb +++ b/spec/fabricators/user_fabricator.rb @@ -1,6 +1,4 @@ Fabricator(:user) do - Faker::Config.locale = :es - username { Faker::Internet.user_name } email { Faker::Internet.email } date_of_birth { DateTime.now.utc } @@ -11,7 +9,7 @@ gender { ["male", "female"].shuffle.first } description { Faker::Lorem.paragraph } last_sign_in_at { DateTime.new(2018, 10, 1) } - terms_accepted_at DateTime.now.utc confirmed_at DateTime.now.utc + locale I18n.default_locale end diff --git a/spec/features/sign_in_spec.rb b/spec/features/sign_in_spec.rb index 03b83d9d9..341b887fa 100644 --- a/spec/features/sign_in_spec.rb +++ b/spec/features/sign_in_spec.rb @@ -12,7 +12,7 @@ sign_in_with(user.email, user.password) expect(Capybara.current_session.driver.browser.manage.cookie_named('_timeoverflow_session')).to be_truthy - expect(page).to have_no_content(I18n.t('devise.failure.invalid')) + expect(page).not_to have_selector('.alert-danger') end end @@ -20,7 +20,7 @@ it 'shows an error' do sign_in_with(user.email, 'wrong_password') - expect(page).to have_content(I18n.t('devise.failure.invalid')) + expect(page).to have_selector('.alert-danger') end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index daa6c289b..0c9b42df5 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -139,16 +139,14 @@ DatabaseCleaner.clean end + config.before(:each, type: :feature) do + I18n.locale = I18n.default_locale + end + # Controllers must render the content of the view config.render_views end -RSpec.shared_context 'stub browser locale' do - def set_browser_locale(locale) - request.env["HTTP_ACCEPT_LANGUAGE"] = "#{locale}" - end -end - RSpec.configure(&:infer_spec_type_from_file_location!) Shoulda::Matchers.configure do |config| diff --git a/spec/support/features/session_helpers.rb b/spec/support/features/session_helpers.rb index d9a686c19..45164a79c 100644 --- a/spec/support/features/session_helpers.rb +++ b/spec/support/features/session_helpers.rb @@ -4,7 +4,7 @@ def sign_in_with(email, password) visit '/login' fill_in 'user_email', with: email fill_in 'user_password', with: password - click_button I18n.t('application.login_form.button') + find('input[type=submit]').click end end end