From 8b7cb6b761741a201044be076bd75eb0e28566b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Heiko=20Bernl=C3=B6hr?= Date: Thu, 16 Dec 2021 18:44:23 +0100 Subject: WIP: Rails 5 --- Gemfile | 23 ++- Gemfile.lock | 218 +++++++++++---------- app/controllers/admin/communities_controller.rb | 4 +- app/controllers/admin/organizations_controller.rb | 2 +- app/controllers/admin/participants_controller.rb | 10 +- app/controllers/application_controller.rb | 18 +- app/controllers/configs_controller.rb | 4 +- app/controllers/events_controller.rb | 6 +- app/controllers/memberships_controller.rb | 6 +- app/controllers/messages_controller.rb | 36 ++-- app/controllers/subparticipants_controller.rb | 14 +- app/middleware/content_length.rb | 32 --- app/models/application_record.rb | 3 + app/models/auth.rb | 2 +- app/models/community.rb | 2 +- app/models/community_message.rb | 2 +- app/models/ev_type.rb | 2 +- app/models/event.rb | 2 +- app/models/identity.rb | 2 +- app/models/membership.rb | 4 +- app/models/membership_message.rb | 6 +- app/models/message.rb | 10 +- app/models/organization.rb | 2 +- app/models/participant.rb | 4 +- app/models/ressource.rb | 2 +- app/models/subparticipant.rb | 2 +- app/views/admin/participants/show.html.haml | 24 +-- bin/rails | 2 +- bin/setup | 34 ++++ bin/update | 29 +++ config/application.rb | 2 +- config/boot.rb | 2 +- config/cable.yml | 9 + config/environment.rb | 2 +- config/environments/development.rb | 35 ++-- config/environments/production.rb | 30 ++- config/environments/test.rb | 12 +- .../application_controller_renderer.rb | 8 + config/initializers/cookies_serializer.rb | 3 +- config/initializers/ecs_middleware.rb | 2 + config/initializers/new_framework_defaults.rb | 25 +++ config/initializers/wrap_parameters.rb | 4 +- config/puma.rb | 47 +++++ config/secrets.yml | 2 +- config/spring.rb | 6 + db/schema.rb | 14 +- .../admin/participants_controller_test.rb | 2 +- test/controllers/events_controller_test.rb | 2 +- test/controllers/memberships_controller_test.rb | 2 +- test/controllers/messages_controller_test.rb | 42 ++-- test/integration/community_messages_test.rb | 6 +- test/integration/ressource_test.rb | 78 ++++---- test/models/event_test.rb | 8 +- test/models/membership_message_test.rb | 6 +- test/models/message_test.rb | 8 +- test/test_helper.rb | 2 +- 56 files changed, 521 insertions(+), 345 deletions(-) delete mode 100644 app/middleware/content_length.rb create mode 100644 app/models/application_record.rb create mode 100755 bin/setup create mode 100755 bin/update create mode 100644 config/cable.yml create mode 100644 config/initializers/application_controller_renderer.rb create mode 100644 config/initializers/ecs_middleware.rb create mode 100644 config/initializers/new_framework_defaults.rb create mode 100644 config/puma.rb create mode 100644 config/spring.rb diff --git a/Gemfile b/Gemfile index 1f07fda..6a152d5 100644 --- a/Gemfile +++ b/Gemfile @@ -1,16 +1,18 @@ source 'https://rubygems.org' ruby '2.4.10' +#gem "minitest", "5.10.1" # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' -gem 'rails', '4.2.11.3' +gem 'rails', '5.0.7.2' +gem 'rails-controller-testing' # Use sqlite3 as the database for Active Record -gem 'sqlite3', group: :db_sqlite3 +gem 'sqlite3', '~> 1.3.6' # Use SCSS for stylesheets -gem 'sass-rails', '~> 4.0.3' +gem 'sass-rails' # Use Uglifier as compressor for JavaScript assets -gem 'uglifier', '>= 1.3.0' +gem 'uglifier' # Use CoffeeScript for .js.coffee assets and views -gem 'coffee-rails', '~> 4.0.0' +gem 'coffee-rails' # See https://github.com/sstephenson/execjs#readme for more supported runtimes gem 'therubyracer', platforms: :ruby @@ -19,9 +21,9 @@ gem 'jquery-rails' # Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks gem 'turbolinks' # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder -gem 'jbuilder', '~> 2.0' +gem 'jbuilder' # bundle exec rake doc:rails generates the API under doc/api. -gem 'sdoc', '~> 0.4.0', group: :doc +gem 'sdoc', group: :doc # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring gem 'spring', group: :development @@ -40,10 +42,11 @@ gem 'unicorn' # Use debugger # gem 'debugger', group: [:development, :test] -gem "pg", '~> 0.11', group: :db_pg +gem "pg", group: :production gem "haml", "4.0.5" gem "simple-navigation" -gem 'web-console', '~> 2.0', group: :development -gem 'responders', '~> 2.0' +gem 'web-console', group: :development +gem 'responders' gem 'unicorn-rails' gem "less" +gem "mysql2", group: :production diff --git a/Gemfile.lock b/Gemfile.lock index 9eb9023..60e018e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,47 +1,50 @@ GEM remote: https://rubygems.org/ specs: - actionmailer (4.2.11.3) - actionpack (= 4.2.11.3) - actionview (= 4.2.11.3) - activejob (= 4.2.11.3) + actioncable (5.0.7.2) + actionpack (= 5.0.7.2) + nio4r (>= 1.2, < 3.0) + websocket-driver (~> 0.6.1) + actionmailer (5.0.7.2) + actionpack (= 5.0.7.2) + actionview (= 5.0.7.2) + activejob (= 5.0.7.2) mail (~> 2.5, >= 2.5.4) - rails-dom-testing (~> 1.0, >= 1.0.5) - actionpack (4.2.11.3) - actionview (= 4.2.11.3) - activesupport (= 4.2.11.3) - rack (~> 1.6) - rack-test (~> 0.6.2) - rails-dom-testing (~> 1.0, >= 1.0.5) + rails-dom-testing (~> 2.0) + actionpack (5.0.7.2) + actionview (= 5.0.7.2) + activesupport (= 5.0.7.2) + rack (~> 2.0) + rack-test (~> 0.6.3) + rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.0.2) - actionview (4.2.11.3) - activesupport (= 4.2.11.3) + actionview (5.0.7.2) + activesupport (= 5.0.7.2) builder (~> 3.1) erubis (~> 2.7.0) - rails-dom-testing (~> 1.0, >= 1.0.5) + rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.0.3) - activejob (4.2.11.3) - activesupport (= 4.2.11.3) - globalid (>= 0.3.0) - activemodel (4.2.11.3) - activesupport (= 4.2.11.3) - builder (~> 3.1) - activerecord (4.2.11.3) - activemodel (= 4.2.11.3) - activesupport (= 4.2.11.3) - arel (~> 6.0) - activesupport (4.2.11.3) - i18n (~> 0.7) + activejob (5.0.7.2) + activesupport (= 5.0.7.2) + globalid (>= 0.3.6) + activemodel (5.0.7.2) + activesupport (= 5.0.7.2) + activerecord (5.0.7.2) + activemodel (= 5.0.7.2) + activesupport (= 5.0.7.2) + arel (~> 7.0) + activesupport (5.0.7.2) + concurrent-ruby (~> 1.0, >= 1.0.2) + i18n (>= 0.7, < 2) minitest (~> 5.1) - thread_safe (~> 0.3, >= 0.3.4) tzinfo (~> 1.1) - arel (6.0.4) - binding_of_caller (1.0.0) - debug_inspector (>= 0.0.1) + arel (7.1.4) + bindex (0.8.1) builder (3.2.4) - coffee-rails (4.0.1) + byebug (11.1.3) + coffee-rails (4.2.2) coffee-script (>= 2.2.0) - railties (>= 4.0.0, < 5.0) + railties (>= 4.0.0) coffee-script (2.4.1) coffee-script-source execjs @@ -49,102 +52,105 @@ GEM commonjs (0.2.7) concurrent-ruby (1.1.9) crass (1.0.6) - debug_inspector (1.1.0) erubis (2.7.0) execjs (2.8.1) + ffi (1.15.4) globalid (0.4.2) activesupport (>= 4.2.0) haml (4.0.5) tilt - hike (1.2.3) - i18n (0.9.5) + i18n (1.8.11) concurrent-ruby (~> 1.0) - jbuilder (2.9.1) - activesupport (>= 4.2.0) + jbuilder (2.11.3) + activesupport (>= 5.0.0) jquery-rails (4.4.0) rails-dom-testing (>= 1, < 3) railties (>= 4.2.0) thor (>= 0.14, < 2.0) - json (1.8.6) kgio (2.11.4) less (2.6.0) commonjs (~> 0.2.7) libv8 (3.16.14.19) - loofah (2.12.0) + loofah (2.13.0) crass (~> 1.0.2) nokogiri (>= 1.5.9) mail (2.7.1) mini_mime (>= 0.1.1) + method_source (1.0.0) mini_mime (1.1.2) mini_portile2 (2.4.0) - minitest (5.14.4) - multi_json (1.15.0) - mysql2 (0.4.10) + minitest (5.15.0) + mysql2 (0.5.3) + nio4r (2.5.8) nokogiri (1.10.10) mini_portile2 (~> 2.4.0) - pg (0.21.0) - rack (1.6.13) + pg (1.2.3) + rack (2.2.3) rack-test (0.6.3) rack (>= 1.0) - rails (4.2.11.3) - actionmailer (= 4.2.11.3) - actionpack (= 4.2.11.3) - actionview (= 4.2.11.3) - activejob (= 4.2.11.3) - activemodel (= 4.2.11.3) - activerecord (= 4.2.11.3) - activesupport (= 4.2.11.3) - bundler (>= 1.3.0, < 2.0) - railties (= 4.2.11.3) - sprockets-rails - rails-deprecated_sanitizer (1.0.4) - activesupport (>= 4.2.0.alpha) - rails-dom-testing (1.0.9) - activesupport (>= 4.2.0, < 5.0) - nokogiri (~> 1.6) - rails-deprecated_sanitizer (>= 1.0.1) + rails (5.0.7.2) + actioncable (= 5.0.7.2) + actionmailer (= 5.0.7.2) + actionpack (= 5.0.7.2) + actionview (= 5.0.7.2) + activejob (= 5.0.7.2) + activemodel (= 5.0.7.2) + activerecord (= 5.0.7.2) + activesupport (= 5.0.7.2) + bundler (>= 1.3.0) + railties (= 5.0.7.2) + sprockets-rails (>= 2.0.0) + rails-controller-testing (1.0.5) + actionpack (>= 5.0.1.rc1) + actionview (>= 5.0.1.rc1) + activesupport (>= 5.0.1.rc1) + rails-dom-testing (2.0.3) + activesupport (>= 4.2.0) + nokogiri (>= 1.6) rails-html-sanitizer (1.4.2) loofah (~> 2.3) - railties (4.2.11.3) - actionpack (= 4.2.11.3) - activesupport (= 4.2.11.3) + railties (5.0.7.2) + actionpack (= 5.0.7.2) + activesupport (= 5.0.7.2) + method_source rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) raindrops (0.20.0) rake (13.0.6) - rdoc (4.3.0) + rdoc (6.3.3) ref (2.0.0) - responders (2.4.1) - actionpack (>= 4.2.0, < 6.0) - railties (>= 4.2.0, < 6.0) - sass (3.2.19) - sass-rails (4.0.5) - railties (>= 4.0.0, < 5.0) - sass (~> 3.2.2) - sprockets (~> 2.8, < 3.0) - sprockets-rails (~> 2.0) - sdoc (0.4.2) - json (~> 1.7, >= 1.7.7) - rdoc (~> 4.0) + responders (3.0.1) + actionpack (>= 5.0) + railties (>= 5.0) + sass-rails (6.0.0) + sassc-rails (~> 2.1, >= 2.1.1) + sassc (2.4.0) + ffi (~> 1.9) + sassc-rails (2.1.2) + railties (>= 4.0.0) + sassc (>= 2.0) + sprockets (> 3.0) + sprockets-rails + tilt + sdoc (2.2.0) + rdoc (>= 5.0) simple-navigation (4.3.0) activesupport (>= 2.3.2) spring (2.1.1) - sprockets (2.12.5) - hike (~> 1.2) - multi_json (~> 1.0) - rack (~> 1.0) - tilt (~> 1.1, != 1.3.0) - sprockets-rails (2.3.3) - actionpack (>= 3.0) - activesupport (>= 3.0) - sprockets (>= 2.8, < 4.0) - sqlite3 (1.4.2) + sprockets (3.7.2) + concurrent-ruby (~> 1.0) + rack (> 1, < 3) + sprockets-rails (3.2.2) + actionpack (>= 4.0) + activesupport (>= 4.0) + sprockets (>= 3.0.0) + sqlite3 (1.3.13) therubyracer (0.12.3) libv8 (~> 3.16.14.15) ref thor (1.1.0) thread_safe (0.3.6) - tilt (1.4.1) + tilt (2.0.10) turbolinks (5.2.1) turbolinks-source (~> 5.2) turbolinks-source (5.2.0) @@ -158,35 +164,41 @@ GEM unicorn-rails (2.2.1) rack unicorn - web-console (2.3.0) - activemodel (>= 4.0) - binding_of_caller (>= 0.7.2) - railties (>= 4.0) - sprockets-rails (>= 2.0, < 4.0) + web-console (3.7.0) + actionview (>= 5.0) + activemodel (>= 5.0) + bindex (>= 0.4.0) + railties (>= 5.0) + websocket-driver (0.6.5) + websocket-extensions (>= 0.1.0) + websocket-extensions (0.1.5) PLATFORMS ruby DEPENDENCIES - coffee-rails (~> 4.0.0) + byebug + coffee-rails haml (= 4.0.5) - jbuilder (~> 2.0) + jbuilder jquery-rails less - pg (~> 0.11) - rails (= 4.2.11.3) - responders (~> 2.0) - sass-rails (~> 4.0.3) - sdoc (~> 0.4.0) + mysql2 + pg + rails (= 5.0.7.2) + rails-controller-testing + responders + sass-rails + sdoc simple-navigation spring - sqlite3 + sqlite3 (~> 1.3.6) therubyracer turbolinks - uglifier (>= 1.3.0) + uglifier unicorn unicorn-rails - web-console (~> 2.0) + web-console RUBY VERSION ruby 2.4.10p364 diff --git a/app/controllers/admin/communities_controller.rb b/app/controllers/admin/communities_controller.rb index cb6d6d4..e44ab6a 100644 --- a/app/controllers/admin/communities_controller.rb +++ b/app/controllers/admin/communities_controller.rb @@ -28,7 +28,7 @@ class Admin::CommunitiesController < ApplicationController end def list - @communities=Community.all.uniq + @communities=Community.all.distinct end def show @@ -71,7 +71,7 @@ class Admin::CommunitiesController < ApplicationController # lists all participants of the community def index_participants @community = Community.find(params[:id]) - @participants=Community.find(params[:id]).memberships.collect {|i| i.participant }.uniq.sort{|x,y| x.id <=> y.id } + @participants=Community.find(params[:id]).memberships.collect {|i| i.participant }.distinct.sort{|x,y| x.id <=> y.id } end # lists all those participants which has not joined the community diff --git a/app/controllers/admin/organizations_controller.rb b/app/controllers/admin/organizations_controller.rb index e52323e..95c1e00 100644 --- a/app/controllers/admin/organizations_controller.rb +++ b/app/controllers/admin/organizations_controller.rb @@ -28,7 +28,7 @@ class Admin::OrganizationsController < ApplicationController end def list - @organizations=Organization.all.uniq + @organizations=Organization.all.distinct end def show diff --git a/app/controllers/admin/participants_controller.rb b/app/controllers/admin/participants_controller.rb index e2af77e..550e904 100644 --- a/app/controllers/admin/participants_controller.rb +++ b/app/controllers/admin/participants_controller.rb @@ -39,15 +39,15 @@ class Admin::ParticipantsController < ApplicationController when "true" @list_anonymous=true @list_participants_count = Participant.all.count - Participant.all.uniq + Participant.all.distinct when "false" @list_anonymous=false @list_participants_count = Participant.all.count - @list_participants_anonymous_count - Participant.without_anonymous.uniq + Participant.without_anonymous.distinct else @list_anonymous=false @list_participants_count = Participant.all.count - @list_participants_anonymous_count - Participant.without_anonymous.uniq + Participant.without_anonymous.distinct end @action_buttons = case params[:actionbuttons] when "true" @@ -118,7 +118,7 @@ class Admin::ParticipantsController < ApplicationController def index_communities @participant = Participant.find(params[:id]) - @communities=Participant.find(params[:id]).memberships.collect {|i| i.community }.uniq.sort{|x,y| x.id <=> y.id } + @communities=Participant.find(params[:id]).memberships.collect {|i| i.community }.distinct.sort{|x,y| x.id <=> y.id } end # lists all those communities which the participant has not yet joined @@ -168,7 +168,7 @@ private leaved_messages << Membership.find_by_participant_id_and_community_id(participant.id, cid).messages leaved_messages << Community.find(cid).messages end - leaved_messages.flatten.compact.uniq + leaved_messages.flatten.compact.distinct end def participant_params diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 131b504..a2798c3 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -185,50 +185,50 @@ protected def rescue_body_401 @http_error= $! logger.error $!.to_s - render :text => "#{$!.to_s}\n", :layout => false, :status => 401 + render :plain => "#{$!.to_s}\n", :layout => false, :status => 401 end def rescue_body_500 @http_error= $! logger.error $!.to_s - render :text => "#{$!.to_s}\n", :layout => false, :status => 500 + render :plain => "#{$!.to_s}\n", :layout => false, :status => 500 end def rescue_body_400 @http_error= $! logger.error $!.to_s - render :text => "#{$!.to_s}\n" , :layout => false, :status => 400 + render :plain => "#{$!.to_s}\n" , :layout => false, :status => 400 end def rescue_body_403 @http_error= $! logger.error $!.to_s - render :text => "#{$!.to_s}\n" , :layout => false, :status => 403 + render :plain => "#{$!.to_s}\n" , :layout => false, :status => 403 end def rescue_body_404 @http_error= $! logger.error $!.to_s if $!.to_s.blank? - render :text => "The server does not know the ressource\nor the message queue in question is empty.\n" , :layout => false, :status => 404 + render :plain => "The server does not know the ressource\nor the message queue in question is empty.\n" , :layout => false, :status => 404 else - render :text => "#{$!.to_s}\n" , :layout => false, :status => 404 + render :plain => "#{$!.to_s}\n" , :layout => false, :status => 404 end end def rescue_body_409 @http_error= $! logger.error $!.to_s - render :text => "#{$!.to_s}\n" , :layout => false, :status => 409 + render :plain => "#{$!.to_s}\n" , :layout => false, :status => 409 end def rescue_body_415(controller_binding) @http_error= $! logger.error $!.to_s if $!.to_s.blank? - render :text => "The format of the client data is not supported by the server.\nIf your format is right please doublecheck the encoding !\nIt has to be UTF8 !\n", :layout => false, :status => 415 + render :plain => "The format of the client data is not supported by the server.\nIf your format is right please doublecheck the encoding !\nIt has to be UTF8 !\n", :layout => false, :status => 415 else - render :text => "#{$!.to_s}\n" , :layout => false, :status => 415 + render :plain => "#{$!.to_s}\n" , :layout => false, :status => 415 end end diff --git a/app/controllers/configs_controller.rb b/app/controllers/configs_controller.rb index 5a62379..8acf048 100644 --- a/app/controllers/configs_controller.rb +++ b/app/controllers/configs_controller.rb @@ -1,7 +1,7 @@ class ConfigsController < ApplicationController - before_filter :authentication - before_filter :add_cookie_header # only for anonymous participants + before_action :authentication + before_action :add_cookie_header # only for anonymous participants def initialize super diff --git a/app/controllers/events_controller.rb b/app/controllers/events_controller.rb index c151f6b..02f97aa 100644 --- a/app/controllers/events_controller.rb +++ b/app/controllers/events_controller.rb @@ -18,8 +18,8 @@ class EventsController < ApplicationController - before_filter :authentication - before_filter :add_cookie_header # only for anonymous participants + before_action :authentication + before_action :add_cookie_header # only for anonymous participants def initialize super @@ -70,7 +70,7 @@ private respond_to do |format| format.json { render :json => JSON.pretty_generate(events) } format.xml { render :xml => events } - format.text { render :text => events_render_txt(events) } + format.text { render :plain => events_render_txt(events) } end end diff --git a/app/controllers/memberships_controller.rb b/app/controllers/memberships_controller.rb index fa73ae0..42f6578 100644 --- a/app/controllers/memberships_controller.rb +++ b/app/controllers/memberships_controller.rb @@ -18,8 +18,8 @@ class MembershipsController < ApplicationController - before_filter :authentication - before_filter :add_cookie_header # only for anonymous participants + before_action :authentication + before_action :add_cookie_header # only for anonymous participants def initialize super @@ -28,7 +28,7 @@ class MembershipsController < ApplicationController def index memberships= index_querystring_list if memberships.empty? - render :text => "", :content_type => "application/json", :layout => false + render :plain => "", :content_type => "application/json", :layout => false else respond_to do |format| format.json { render :json => JSON.pretty_generate(memberships) } diff --git a/app/controllers/messages_controller.rb b/app/controllers/messages_controller.rb index 2bb9b05..d87065d 100644 --- a/app/controllers/messages_controller.rb +++ b/app/controllers/messages_controller.rb @@ -18,11 +18,11 @@ class MessagesController < ApplicationController - before_filter :late_initialize - before_filter :authentication - before_filter :add_cookie_header - before_filter :get_record, :only => [:show, :update, :destroy] - after_filter :touch_participant_ttl + before_action :late_initialize + before_action :authentication + before_action :add_cookie_header + before_action :get_record, :only => [:show, :update, :destroy] + after_action :touch_participant_ttl def initialize super @@ -110,7 +110,7 @@ class MessagesController < ApplicationController if details.empty? then no_data_to_render = true end end if no_data_to_render - render :text => "", :content_type => "application/json", :layout => false + render :plain => "", :content_type => "application/json", :layout => false else respond_to do |format| format.json { render :json => JSON.pretty_generate(details) } @@ -160,15 +160,15 @@ protected all ||= params["all"] ? params["all"] : nil case when sender == "true" - @list = Message.for_participant_sender(@participant).for_resource(@app_namespace,@ressource_name).for_not_removed.uniq + @list = Message.for_participant_sender(@participant).for_resource(@app_namespace,@ressource_name).for_not_removed.distinct.to_a when receiver == "true" - @list = Message.for_participant_receiver(@participant).for_resource(@app_namespace,@ressource_name).for_not_removed.uniq + @list = Message.for_participant_receiver(@participant).for_resource(@app_namespace,@ressource_name).for_not_removed.distinct.to_a when all == "true" list1 = Message.for_participant_sender(@participant).for_resource(@app_namespace,@ressource_name).for_not_removed list2 = Message.for_participant_receiver(@participant).for_resource(@app_namespace,@ressource_name).for_not_removed - @list = list1.concat(list2).uniq + @list = list1.to_a.concat(list2.to_a).uniq else - @list = Message.for_participant_receiver(@participant).for_resource(@app_namespace,@ressource_name).for_not_removed.uniq + @list = Message.for_participant_receiver(@participant).for_resource(@app_namespace,@ressource_name).for_not_removed.distinct end end @@ -216,11 +216,11 @@ protected end def empty_render - render :text => "", :content_type => "application/json" + render :plain => "", :content_type => "application/json" end def index_render - render :text => @body, :content_type => "text/uri-list" + render plain: @body, :content_type => "text/uri-list" end def show_render @@ -238,7 +238,7 @@ protected end unless @memberships.blank? headers["X-EcsReceiverCommunities"]= x_ecs_receiver_communities unless x_ecs_receiver_communities.blank? headers["X-EcsSender"]= x_ecs_sender unless x_ecs_sender.blank? - @render_cmd='render :text => @body, :layout => false, :status => 200, :content_type => Mime::Type.lookup(@record.content_type)' + @render_cmd='render plain: @body, :layout => false, :status => 200, :content_type => Mime::Type.lookup(@record.content_type)' end def create_render @@ -249,9 +249,9 @@ protected location += request.path.gsub(/\/*$/,'') + "/" + @record.id.to_s logger.info "Location: #{location}" if @app_namespace == 'sys' and @ressource_name == 'auths' - render :text => @body, :layout => false, :status => 201, :location => location, :content_type => Mime::Type.lookup_by_extension("json") + render plain: @body, :layout => false, :status => 201, :location => location, :content_type => Mime::Type.lookup_by_extension("json") else - render :text => "", :layout => false, :status => 201, :location => location, :content_type => Mime::Type.lookup(@record.content_type) + render plain: "", :layout => false, :status => 201, :location => location, :content_type => Mime::Type.lookup(@record.content_type) end end @@ -259,13 +259,13 @@ protected location = request.protocol + request.host location += request.headers["SCRIPT_NAME"] if request.headers["SCRIPT_NAME"] location += request.path.gsub(/\/*$/,'') - render :text => "", :layout => false, :status => 200, + render plain: "", :layout => false, :status => 200, :location => location end def destroy_render - render :nothing => true, :layout => false, :status => 200, - :content_type => "application/json" + render plain: "", :layout => false, :status => 200, + :location => location end end diff --git a/app/controllers/subparticipants_controller.rb b/app/controllers/subparticipants_controller.rb index 3d585ae..62df87b 100644 --- a/app/controllers/subparticipants_controller.rb +++ b/app/controllers/subparticipants_controller.rb @@ -17,11 +17,11 @@ class SubparticipantsController < ApplicationController - before_filter :authentication - before_filter :block_anonymous_participants - before_filter :block_subparticipants - before_filter :check_json_contenttype, :only => :create - before_filter :check_parent, :only => [:show, :destroy, :update] + before_action :authentication + before_action :block_anonymous_participants + before_action :block_subparticipants + before_action :check_json_contenttype, :only => :create + before_action :check_parent, :only => [:show, :destroy, :update] def initialize super @@ -33,7 +33,7 @@ class SubparticipantsController < ApplicationController @body << "subparticipants/" << child.id.to_s << "\n" end unless childs.empty? respond_to do |format| - format.text { render :text => @body, :content_type => "text/uri-list" } + format.text { render :plain => @body, :content_type => "text/uri-list" } end end @@ -79,7 +79,7 @@ class SubparticipantsController < ApplicationController def destroy subparticipant= Subparticipant.find(params[:id]) subparticipant.participant.destroy - render :text => "", :layout => false, :status => 200, :content_type => :json + render :plain => "", :layout => false, :status => 200, :content_type => :json end private diff --git a/app/middleware/content_length.rb b/app/middleware/content_length.rb deleted file mode 100644 index fa51160..0000000 --- a/app/middleware/content_length.rb +++ /dev/null @@ -1,32 +0,0 @@ -require 'rack/utils' - -class ContentLength - - include Rack::Utils - - def initialize app - @app = app - end - - def call env - status, headers, body = @app.call(env) - headers = HeaderHash.new(headers) - if !STATUS_WITH_NO_ENTITY_BODY.include?(status.to_i) && - !headers['Content-Length'] && - !headers['Transfer-Encoding'] - - #see https://stackoverflow.com/questions/26534165/unable-to-get-content-length-header-working-under-rails-4-1puma - #see https://github.com/rails/rails/pull/16793 - #&& body.respond_to?(:to_ary) - - obody = body - body, length = [], 0 - obody.each { |part| body << part; length += bytesize(part) } - obody.close if obody.respond_to?(:close) - - headers['Content-Length'] = length.to_s - end - [status, headers, body] - end - -end diff --git a/app/models/application_record.rb b/app/models/application_record.rb new file mode 100644 index 0000000..10a4cba --- /dev/null +++ b/app/models/application_record.rb @@ -0,0 +1,3 @@ +class ApplicationRecord < ActiveRecord::Base + self.abstract_class = true +end diff --git a/app/models/auth.rb b/app/models/auth.rb index 1ac5c3c..e32634e 100644 --- a/app/models/auth.rb +++ b/app/models/auth.rb @@ -15,7 +15,7 @@ # You should have received a copy of the GNU Affero General Public # License along with ECS. If not, see . -class Auth < ActiveRecord::Base +class Auth < ApplicationRecord belongs_to :message #scope :hash, lambda {|hash| { diff --git a/app/models/community.rb b/app/models/community.rb index 27a34b2..33800d8 100644 --- a/app/models/community.rb +++ b/app/models/community.rb @@ -16,7 +16,7 @@ # License along with ECS. If not, see . -class Community < ActiveRecord::Base +class Community < ApplicationRecord has_many :memberships, -> { order 'memberships.id ASC' } has_many :participants, :through => :memberships has_many :community_messages, :dependent => :destroy diff --git a/app/models/community_message.rb b/app/models/community_message.rb index 1f7b1f3..8832aac 100644 --- a/app/models/community_message.rb +++ b/app/models/community_message.rb @@ -16,7 +16,7 @@ # License along with ECS. If not, see . -class CommunityMessage < ActiveRecord::Base +class CommunityMessage < ApplicationRecord belongs_to :message belongs_to :community end diff --git a/app/models/ev_type.rb b/app/models/ev_type.rb index f701793..c29827f 100644 --- a/app/models/ev_type.rb +++ b/app/models/ev_type.rb @@ -16,6 +16,6 @@ # License along with ECS. If not, see . -class EvType < ActiveRecord::Base +class EvType < ApplicationRecord has_many :events end diff --git a/app/models/event.rb b/app/models/event.rb index 126048d..504ca6d 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -16,7 +16,7 @@ # License along with ECS. If not, see . -class Event < ActiveRecord::Base +class Event < ApplicationRecord belongs_to :ev_type belongs_to :participant belongs_to :message diff --git a/app/models/identity.rb b/app/models/identity.rb index b8b0e91..a187e3c 100644 --- a/app/models/identity.rb +++ b/app/models/identity.rb @@ -16,7 +16,7 @@ # License along with ECS. If not, see . -class Identity < ActiveRecord::Base +class Identity < ApplicationRecord require 'securerandom' diff --git a/app/models/membership.rb b/app/models/membership.rb index 6c0b4d3..42371de 100644 --- a/app/models/membership.rb +++ b/app/models/membership.rb @@ -16,7 +16,7 @@ # License along with ECS. If not, see . -class Membership < ActiveRecord::Base +class Membership < ApplicationRecord belongs_to :participant belongs_to :community belongs_to :community_with_reduced_attributes, @@ -49,7 +49,7 @@ class Membership < ActiveRecord::Base def self.senders(participant, message) sender_mids=[] - Community.for_participant(participant).for_message(message).uniq.each do |comm| + Community.for_participant(participant).for_message(message).distinct.each do |comm| sender_mids << Membership.find_by_participant_id_and_community_id(participant.id,comm.id) end if sender_mids.empty? diff --git a/app/models/membership_message.rb b/app/models/membership_message.rb index b62da0a..a8b7c74 100644 --- a/app/models/membership_message.rb +++ b/app/models/membership_message.rb @@ -16,7 +16,7 @@ # License along with ECS. If not, see . -class MembershipMessage < ActiveRecord::Base +class MembershipMessage < ApplicationRecord belongs_to :membership belongs_to :message @@ -116,10 +116,10 @@ private def self.delete_relations(message, memberships=nil) if memberships memberships.each do |m| - destroy_all ["membership_id = ? and message_id = ?", m.id, message.id] + where(["membership_id = ? and message_id = ?", m.id, message.id]).destroy_all end else - destroy_all ["message_id = ?", message.id] + where(["message_id = ?", message.id]).destroy_all end end diff --git a/app/models/message.rb b/app/models/message.rb index 67d87f6..922cae2 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -16,7 +16,7 @@ # License along with ECS. If not, see . -class Message < ActiveRecord::Base +class Message < ApplicationRecord require 'exceptions' @@ -64,7 +64,7 @@ class Message < ActiveRecord::Base request.headers["X-EcsReceiverMemberships"], request.headers["X-EcsReceiverCommunities"], participant) - Participant.for_message(message).uniq.each do |p| + Participant.for_message(message).distinct.each do |p| Event.make(:event_type_name => EvType.find(1).name, :participant => p, :message => message) end if message.ressource.events if app_namespace == 'sys' and ressource_name == 'auths' @@ -90,14 +90,14 @@ class Message < ActiveRecord::Base # by converting ActiveRecord::Relation to an array of Model-Objects. We could # have done this # also by calling #load!, but would have get back still an # ActiveRecord::Relation, which works also. - receivers_old = Participant.for_message(self).uniq.to_a + receivers_old = Participant.for_message(self).distinct.to_a #puts "*** receivers_old: #{receivers_old.inspect}" MembershipMessage.de_populate_jointable(self) MembershipMessage.populate_jointable(self, request.headers["X-EcsReceiverMemberships"], request.headers["X-EcsReceiverCommunities"], participant) - receivers_new = Participant.for_message(self).uniq.to_a + receivers_new = Participant.for_message(self).distinct.to_a # TODO: if there are only the headers X-EcsReceiverMemberships and # X-EcsReceiverCommunities are updated, then we have to generate events only # for these new and removed receivers. To distinguish if the message body @@ -273,7 +273,7 @@ class Message < ActiveRecord::Base # deleted when there are no references from any events otherwise it will be # tagged as deleted. def destroy_as_sender - participants = Participant.for_message(self).uniq + participants = Participant.for_message(self).distinct participants.each do |participant| Event.make(:event_type_name => EvType.find(2).name, :participant => participant, :message => self) end if ressource.events diff --git a/app/models/organization.rb b/app/models/organization.rb index 2fcbb3c..28c6d92 100644 --- a/app/models/organization.rb +++ b/app/models/organization.rb @@ -16,7 +16,7 @@ # License along with ECS. If not, see . -class Organization < ActiveRecord::Base +class Organization < ApplicationRecord # TODO: warn the user about possible deletions of participants. has_many :participants, :dependent => :destroy diff --git a/app/models/participant.rb b/app/models/participant.rb index 205bd2c..dff6160 100644 --- a/app/models/participant.rb +++ b/app/models/participant.rb @@ -16,7 +16,7 @@ # License along with ECS. If not, see . -class Participant < ActiveRecord::Base +class Participant < ApplicationRecord TTL = 1.hour # how long an anonymous participant lives TYPE={ :main => "main", :sub => "sub", :anonym => "anonym" } @@ -162,7 +162,7 @@ class Participant < ActiveRecord::Base private def delete_messages - Message.destroy_all(["sender = ?", self.id]) + Message.where(["sender = ?", self.id]).destroy_all end end diff --git a/app/models/ressource.rb b/app/models/ressource.rb index 26f656a..82a5799 100644 --- a/app/models/ressource.rb +++ b/app/models/ressource.rb @@ -16,7 +16,7 @@ # License along with ECS. If not, see . -class Ressource < ActiveRecord::Base +class Ressource < ApplicationRecord # TODO prevent invalid namespace and ressource strings. has_many :messages, :dependent => :destroy validates_presence_of :namespace, :ressource diff --git a/app/models/subparticipant.rb b/app/models/subparticipant.rb index 2efc504..825b5e1 100644 --- a/app/models/subparticipant.rb +++ b/app/models/subparticipant.rb @@ -15,7 +15,7 @@ # You should have received a copy of the GNU Affero General Public # License along with ECS. If not, see . -class Subparticipant < ActiveRecord::Base +class Subparticipant < ApplicationRecord TTL = 3600 # seconds, how long a subparticipant lives, after last # communication with ECS diff --git a/app/views/admin/participants/show.html.haml b/app/views/admin/participants/show.html.haml index d230446..033175d 100644 --- a/app/views/admin/participants/show.html.haml +++ b/app/views/admin/participants/show.html.haml @@ -99,12 +99,12 @@ - eventsm = 10 -- events_count = Event.for_participant(@participant,-1).uniq.count +- events_count = Event.for_participant(@participant,-1).distinct.count - if events_count < eventsm or events_count < 5 - - events_first = Event.for_participant(@participant,-1).uniq + - events_first = Event.for_participant(@participant,-1).distinct -else - - events_first = Event.for_participant(@participant,-1).uniq.limit(eventsm/2) - - events_last = Event.for_participant(@participant,-1).uniq.limit(eventsm/2).offset(events_count-(eventsm/2)) + - events_first = Event.for_participant(@participant,-1).distinct.limit(eventsm/2) + - events_last = Event.for_participant(@participant,-1).distinct.limit(eventsm/2).offset(events_count-(eventsm/2)) - events_diff = events_last - events_first - unless events_first.blank? %p @@ -143,12 +143,12 @@ - msgsm = 10 -- messages_count = Message.for_participant_receiver(@participant).for_not_removed.uniq.count +- messages_count = Message.for_participant_receiver(@participant).for_not_removed.distinct.count - if messages_count < msgsm or messages_count < 5 - - messages_first = Message.for_participant_receiver(@participant).for_not_removed.uniq + - messages_first = Message.for_participant_receiver(@participant).for_not_removed.distinct -else - - messages_first = Message.for_participant_receiver(@participant).for_not_removed.uniq.limit(msgsm/2) - - messages_last = Message.for_participant_receiver(@participant).for_not_removed.uniq.limit(msgsm/2).offset(messages_count-(msgsm/2)) + - messages_first = Message.for_participant_receiver(@participant).for_not_removed.distinct.limit(msgsm/2) + - messages_last = Message.for_participant_receiver(@participant).for_not_removed.distinct.limit(msgsm/2).offset(messages_count-(msgsm/2)) - messages_diff = messages_last - messages_first - unless messages_first.blank? %p @@ -187,12 +187,12 @@ - msgsm = 10 -- messages_count = Message.for_participant_sender(@participant).for_not_removed.uniq.count +- messages_count = Message.for_participant_sender(@participant).for_not_removed.distinct.count - if messages_count < msgsm or messages_count < 5 - - messages_first = Message.for_participant_sender(@participant).for_not_removed.uniq + - messages_first = Message.for_participant_sender(@participant).for_not_removed.distinct -else - - messages_first = Message.for_participant_sender(@participant).for_not_removed.uniq.limit(msgsm/2) - - messages_last = Message.for_participant_sender(@participant).for_not_removed.uniq.limit(msgsm/2).offset(messages_count-(msgsm/2)) + - messages_first = Message.for_participant_sender(@participant).for_not_removed.distinct.limit(msgsm/2) + - messages_last = Message.for_participant_sender(@participant).for_not_removed.distinct.limit(msgsm/2).offset(messages_count-(msgsm/2)) - messages_diff = messages_last - messages_first - unless messages_first.blank? %p diff --git a/bin/rails b/bin/rails index 5191e69..0739660 100755 --- a/bin/rails +++ b/bin/rails @@ -1,4 +1,4 @@ #!/usr/bin/env ruby -APP_PATH = File.expand_path('../../config/application', __FILE__) +APP_PATH = File.expand_path('../config/application', __dir__) require_relative '../config/boot' require 'rails/commands' diff --git a/bin/setup b/bin/setup new file mode 100755 index 0000000..e620b4d --- /dev/null +++ b/bin/setup @@ -0,0 +1,34 @@ +#!/usr/bin/env ruby +require 'pathname' +require 'fileutils' +include FileUtils + +# path to your application root. +APP_ROOT = Pathname.new File.expand_path('../../', __FILE__) + +def system!(*args) + system(*args) || abort("\n== Command #{args} failed ==") +end + +chdir APP_ROOT do + # This script is a starting point to setup your application. + # Add necessary setup steps to this file. + + puts '== Installing dependencies ==' + system! 'gem install bundler --conservative' + system('bundle check') || system!('bundle install') + + # puts "\n== Copying sample files ==" + # unless File.exist?('config/database.yml') + # cp 'config/database.yml.sample', 'config/database.yml' + # end + + puts "\n== Preparing database ==" + system! 'bin/rails db:setup' + + puts "\n== Removing old logs and tempfiles ==" + system! 'bin/rails log:clear tmp:clear' + + puts "\n== Restarting application server ==" + system! 'bin/rails restart' +end diff --git a/bin/update b/bin/update new file mode 100755 index 0000000..a8e4462 --- /dev/null +++ b/bin/update @@ -0,0 +1,29 @@ +#!/usr/bin/env ruby +require 'pathname' +require 'fileutils' +include FileUtils + +# path to your application root. +APP_ROOT = Pathname.new File.expand_path('../../', __FILE__) + +def system!(*args) + system(*args) || abort("\n== Command #{args} failed ==") +end + +chdir APP_ROOT do + # This script is a way to update your development environment automatically. + # Add necessary update steps to this file. + + puts '== Installing dependencies ==' + system! 'gem install bundler --conservative' + system('bundle check') || system!('bundle install') + + puts "\n== Updating database ==" + system! 'bin/rails db:migrate' + + puts "\n== Removing old logs and tempfiles ==" + system! 'bin/rails log:clear tmp:clear' + + puts "\n== Restarting application server ==" + system! 'bin/rails restart' +end diff --git a/config/application.rb b/config/application.rb index b954d97..8470f9f 100644 --- a/config/application.rb +++ b/config/application.rb @@ -21,7 +21,7 @@ module Ecs4 # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded. # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s] # config.i18n.default_locale = :de - config.middleware.use "ContentLength" + #config.middleware.use "ContentLength" config.assets.initialize_on_precompile false # Do not swallow errors in after_commit/after_rollback callbacks. diff --git a/config/boot.rb b/config/boot.rb index 6b750f0..30f5120 100644 --- a/config/boot.rb +++ b/config/boot.rb @@ -1,3 +1,3 @@ -ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) require 'bundler/setup' # Set up gems listed in the Gemfile. diff --git a/config/cable.yml b/config/cable.yml new file mode 100644 index 0000000..0bbde6f --- /dev/null +++ b/config/cable.yml @@ -0,0 +1,9 @@ +development: + adapter: async + +test: + adapter: async + +production: + adapter: redis + url: redis://localhost:6379/1 diff --git a/config/environment.rb b/config/environment.rb index ee8d90d..426333b 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -1,5 +1,5 @@ # Load the Rails application. -require File.expand_path('../application', __FILE__) +require_relative 'application' # Initialize the Rails application. Rails.application.initialize! diff --git a/config/environments/development.rb b/config/environments/development.rb index b55e214..e64889c 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -9,13 +9,28 @@ Rails.application.configure do # Do not eager load code on boot. config.eager_load = false - # Show full error reports and disable caching. - config.consider_all_requests_local = true - config.action_controller.perform_caching = false + # Show full error reports. + config.consider_all_requests_local = true + + # Enable/disable caching. By default caching is disabled. + if Rails.root.join('tmp/caching-dev.txt').exist? + config.action_controller.perform_caching = true + + config.cache_store = :memory_store + config.public_file_server.headers = { + 'Cache-Control' => 'public, max-age=172800' + } + else + config.action_controller.perform_caching = false + + config.cache_store = :null_store + end # Don't care if the mailer can't send. config.action_mailer.raise_delivery_errors = false + config.action_mailer.perform_caching = false + # Print deprecation notices to the Rails logger. config.active_support.deprecation = :log @@ -27,15 +42,13 @@ Rails.application.configure do # number of complex assets. config.assets.debug = true - # Asset digests allow you to set far-future HTTP expiration dates on all assets, - # yet still be able to expire them through the digest params. - config.assets.digest = true - - # Adds additional error checking when serving assets at runtime. - # Checks for improperly declared sprockets dependencies. - # Raises helpful error messages. - config.assets.raise_runtime_errors = true + # Suppress logger output for asset requests. + config.assets.quiet = true # Raises error for missing translations # config.action_view.raise_on_missing_translations = true + + # Use an evented file watcher to asynchronously detect changes in source code, + # routes, locales, etc. This feature depends on the listen gem. + # config.file_watcher = ActiveSupport::EventedFileUpdateChecker end diff --git a/config/environments/production.rb b/config/environments/production.rb index 4d40937..ebd0274 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -22,7 +22,7 @@ Rails.application.configure do # Disable serving static files from the `/public` folder by default since # Apache or NGINX already handles this. - config.serve_static_files = ENV['RAILS_SERVE_STATIC_FILES'].present? + config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present? # Compress JavaScripts and CSS. config.assets.js_compressor = :uglifier @@ -37,10 +37,18 @@ Rails.application.configure do # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb + # Enable serving of images, stylesheets, and JavaScripts from an asset server. + # config.action_controller.asset_host = 'http://assets.example.com' + # Specifies the header that your server uses for sending files. # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX + # Mount Action Cable outside main process or domain + # config.action_cable.mount_path = nil + # config.action_cable.url = 'wss://example.com/cable' + # config.action_cable.allowed_request_origins = [ 'http://example.com', /http:\/\/example.*/ ] + # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. # config.force_ssl = true @@ -49,14 +57,16 @@ Rails.application.configure do config.log_level = :info # Prepend all log lines with the following tags. - # config.log_tags = [ :subdomain, :uuid ] - - # Use a different logger for distributed setups. - # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new) + config.log_tags = [ :request_id ] # Use a different cache store in production. # config.cache_store = :mem_cache_store + # Use a real queuing backend for Active Job (and separate queues per environment) + # config.active_job.queue_adapter = :resque + # config.active_job.queue_name_prefix = "ecs4_#{Rails.env}" + config.action_mailer.perform_caching = false + # Enable serving of images, stylesheets, and JavaScripts from an asset server. # config.action_controller.asset_host = 'http://assets.example.com' @@ -74,6 +84,16 @@ Rails.application.configure do # Use default logging formatter so that PID and timestamp are not suppressed. config.log_formatter = ::Logger::Formatter.new + # Use a different logger for distributed setups. + # require 'syslog/logger' + # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name') + + if ENV["RAILS_LOG_TO_STDOUT"].present? + logger = ActiveSupport::Logger.new(STDOUT) + logger.formatter = config.log_formatter + config.logger = ActiveSupport::TaggedLogging.new(logger) + end + # Do not dump schema after migrations. config.active_record.dump_schema_after_migration = false end diff --git a/config/environments/test.rb b/config/environments/test.rb index 1c19f08..30587ef 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -12,9 +12,11 @@ Rails.application.configure do # preloads Rails for running tests, you may have to set it to true. config.eager_load = false - # Configure static file server for tests with Cache-Control for performance. - config.serve_static_files = true - config.static_cache_control = 'public, max-age=3600' + # Configure public file server for tests with Cache-Control for performance. + config.public_file_server.enabled = true + config.public_file_server.headers = { + 'Cache-Control' => 'public, max-age=3600' + } # Show full error reports and disable caching. config.consider_all_requests_local = true @@ -25,15 +27,13 @@ Rails.application.configure do # Disable request forgery protection in test environment. config.action_controller.allow_forgery_protection = false + config.action_mailer.perform_caching = false # Tell Action Mailer not to deliver emails to the real world. # The :test delivery method accumulates sent emails in the # ActionMailer::Base.deliveries array. config.action_mailer.delivery_method = :test - # Randomize the order test cases are executed. - config.active_support.test_order = :random - # Print deprecation notices to the stderr. config.active_support.deprecation = :stderr diff --git a/config/initializers/application_controller_renderer.rb b/config/initializers/application_controller_renderer.rb new file mode 100644 index 0000000..89d2efa --- /dev/null +++ b/config/initializers/application_controller_renderer.rb @@ -0,0 +1,8 @@ +# Be sure to restart your server when you modify this file. + +# ActiveSupport::Reloader.to_prepare do +# ApplicationController.renderer.defaults.merge!( +# http_host: 'example.org', +# https: false +# ) +# end diff --git a/config/initializers/cookies_serializer.rb b/config/initializers/cookies_serializer.rb index 573e579..5a6a32d 100644 --- a/config/initializers/cookies_serializer.rb +++ b/config/initializers/cookies_serializer.rb @@ -1,4 +1,5 @@ # Be sure to restart your server when you modify this file. +# Specify a serializer for the signed and encrypted cookie jars. +# Valid options are :json, :marshal, and :hybrid. Rails.application.config.action_dispatch.cookies_serializer = :json - diff --git a/config/initializers/ecs_middleware.rb b/config/initializers/ecs_middleware.rb new file mode 100644 index 0000000..815200d --- /dev/null +++ b/config/initializers/ecs_middleware.rb @@ -0,0 +1,2 @@ +Rails.application.config.middleware.use(Rack::ContentLength) + diff --git a/config/initializers/new_framework_defaults.rb b/config/initializers/new_framework_defaults.rb new file mode 100644 index 0000000..cbf423a --- /dev/null +++ b/config/initializers/new_framework_defaults.rb @@ -0,0 +1,25 @@ +# Be sure to restart your server when you modify this file. +# +# This file contains migration options to ease your Rails 5.0 upgrade. +# +# Once upgraded flip defaults one by one to migrate to the new default. +# +# Read the Guide for Upgrading Ruby on Rails for more info on each option. + +Rails.application.config.action_controller.raise_on_unfiltered_parameters = true + +# Enable per-form CSRF tokens. Previous versions had false. +Rails.application.config.action_controller.per_form_csrf_tokens = false + +# Enable origin-checking CSRF mitigation. Previous versions had false. +Rails.application.config.action_controller.forgery_protection_origin_check = false + +# Make Ruby 2.4 preserve the timezone of the receiver when calling `to_time`. +# Previous versions had false. +ActiveSupport.to_time_preserves_timezone = false + +# Require `belongs_to` associations by default. Previous versions had false. +Rails.application.config.active_record.belongs_to_required_by_default = false + +# Do not halt callback chains when a callback returns false. Previous versions had true. +ActiveSupport.halt_callback_chains_on_return_false = true diff --git a/config/initializers/wrap_parameters.rb b/config/initializers/wrap_parameters.rb index 33725e9..bbfc396 100644 --- a/config/initializers/wrap_parameters.rb +++ b/config/initializers/wrap_parameters.rb @@ -5,10 +5,10 @@ # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. ActiveSupport.on_load(:action_controller) do - wrap_parameters format: [:json] if respond_to?(:wrap_parameters) + wrap_parameters format: [:json] end # To enable root element in JSON for ActiveRecord objects. # ActiveSupport.on_load(:active_record) do -# self.include_root_in_json = true +# self.include_root_in_json = true # end diff --git a/config/puma.rb b/config/puma.rb new file mode 100644 index 0000000..c7f311f --- /dev/null +++ b/config/puma.rb @@ -0,0 +1,47 @@ +# Puma can serve each request in a thread from an internal thread pool. +# The `threads` method setting takes two numbers a minimum and maximum. +# Any libraries that use thread pools should be configured to match +# 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 }.to_i +threads threads_count, threads_count + +# Specifies the `port` that Puma will listen on to receive requests, default is 3000. +# +port ENV.fetch("PORT") { 3000 } + +# Specifies the `environment` that Puma will run in. +# +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 +# the concurrency of the application would be max `threads` * `workers`. +# Workers do not work on JRuby or Windows (both of which do not support +# processes). +# +# workers ENV.fetch("WEB_CONCURRENCY") { 2 } + +# Use the `preload_app!` method when specifying a `workers` number. +# This directive tells Puma to first boot the application and load code +# before forking the application. This takes advantage of Copy On Write +# process behavior so workers use less memory. If you use this option +# you need to make sure to reconnect any threads in the `on_worker_boot` +# block. +# +# preload_app! + +# The code in the `on_worker_boot` will be called if you are using +# clustered mode by specifying a number of `workers`. After each worker +# process is booted this block will be run, if you are using `preload_app!` +# option you will want to use this block to reconnect to any threads +# or connections that may have been created at application boot, Ruby +# cannot share connections between processes. +# +# on_worker_boot do +# ActiveRecord::Base.establish_connection if defined?(ActiveRecord) +# end + +# Allow puma to be restarted by `rails restart` command. +plugin :tmp_restart diff --git a/config/secrets.yml b/config/secrets.yml index 21707ac..ca22419 100644 --- a/config/secrets.yml +++ b/config/secrets.yml @@ -5,7 +5,7 @@ # Make sure the secret is at least 30 characters and all random, # no regular words or you'll be exposed to dictionary attacks. -# You can use `rake secret` to generate a secure secret key. +# You can use `rails secret` to generate a secure secret key. # Make sure the secrets in this file are kept private # if you're sharing your code publicly. diff --git a/config/spring.rb b/config/spring.rb new file mode 100644 index 0000000..c9119b4 --- /dev/null +++ b/config/spring.rb @@ -0,0 +1,6 @@ +%w( + .ruby-version + .rbenv-vars + tmp/restart.txt + tmp/caching-dev.txt +).each { |path| Spring.watch(path) } diff --git a/db/schema.rb b/db/schema.rb index f428475..589638c 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -1,4 +1,3 @@ -# encoding: UTF-8 # This file is auto-generated from the current state of the database. Instead # of editing this file, please use the migrations feature of Active Record to # incrementally modify your database, and then regenerate this schema definition. @@ -50,11 +49,10 @@ ActiveRecord::Schema.define(version: 20180228115911) do t.datetime "created_at" t.datetime "updated_at" t.integer "lock_version", default: 0 + t.index ["message_id"], name: "index_events_on_message_id", using: :btree + t.index ["participant_id"], name: "index_events_on_participant_id", using: :btree end - add_index "events", ["message_id"], name: "index_events_on_message_id", using: :btree - add_index "events", ["participant_id"], name: "index_events_on_participant_id", using: :btree - create_table "identities", force: :cascade do |t| t.integer "participant_id" t.string "name", limit: 255 @@ -69,10 +67,9 @@ ActiveRecord::Schema.define(version: 20180228115911) do t.datetime "created_at" t.datetime "updated_at" t.integer "lock_version", default: 0 + t.index ["message_id"], name: "index_membership_messages_on_message_id", using: :btree end - add_index "membership_messages", ["message_id"], name: "index_membership_messages_on_message_id", using: :btree - create_table "memberships", force: :cascade do |t| t.integer "participant_id" t.integer "community_id" @@ -135,11 +132,10 @@ ActiveRecord::Schema.define(version: 20180228115911) do t.text "data" t.datetime "created_at" t.datetime "updated_at" + t.index ["session_id"], name: "index_sessions_on_session_id", using: :btree + t.index ["updated_at"], name: "index_sessions_on_updated_at", using: :btree end - add_index "sessions", ["session_id"], name: "index_sessions_on_session_id", using: :btree - add_index "sessions", ["updated_at"], name: "index_sessions_on_updated_at", using: :btree - create_table "subparticipants", force: :cascade do |t| t.integer "participant_id" t.integer "parent_id" diff --git a/test/controllers/admin/participants_controller_test.rb b/test/controllers/admin/participants_controller_test.rb index a521ea6..4c5588a 100644 --- a/test/controllers/admin/participants_controller_test.rb +++ b/test/controllers/admin/participants_controller_test.rb @@ -37,7 +37,7 @@ class Admin::ParticipantsControllerTest < ActionController::TestCase } } assert_difference('Participant.count') do - post :create, params + post :create, params: params end assert_equal('Participant "testclient" was successfully created.',flash[:notice]) assert_equal(communities(:wuv).id, Participant.find_by_name("testclient").communities.first.id) diff --git a/test/controllers/events_controller_test.rb b/test/controllers/events_controller_test.rb index 2b03809..bf36795 100644 --- a/test/controllers/events_controller_test.rb +++ b/test/controllers/events_controller_test.rb @@ -22,7 +22,7 @@ class EventsControllerTest < ActionController::TestCase test "index" do request.headers["X-EcsAuthId"] = identities(:ulm_id1).name request.headers["Accept"] = "application/json" - get :index + get :index, params: nil assert_response 200 end end diff --git a/test/controllers/memberships_controller_test.rb b/test/controllers/memberships_controller_test.rb index ce24020..55818d1 100644 --- a/test/controllers/memberships_controller_test.rb +++ b/test/controllers/memberships_controller_test.rb @@ -23,7 +23,7 @@ class MembershipsControllerTest < ActionController::TestCase test "prettyfied memberships" do request.headers["X-EcsAuthId"] = identities(:ulm_id1).name request.headers["Accept"] = "application/json" - get :index + get :index, params: nil assert_response 200 f = StringIO.open @response.body b = f.readlines diff --git a/test/controllers/messages_controller_test.rb b/test/controllers/messages_controller_test.rb index 79d8190..2af3ae7 100644 --- a/test/controllers/messages_controller_test.rb +++ b/test/controllers/messages_controller_test.rb @@ -32,7 +32,7 @@ private http_headers.each do |key,value| request.headers[key] = value end if http_headers - s = "#{http_method} :#{controller_method}, #{controller_params}" + s = "#{http_method} :#{controller_method}, params: #{controller_params}" eval s end @@ -226,7 +226,7 @@ public assert_response 200 assert MembershipMessage.where(:message_id => messages(:numlab_ex1)).count == refscount - 1 # message is only tagged as removed (events on). physically it's still there. - assert_nothing_raised(ActiveRecord::RecordNotFound) { Message.find(messages(:numlab_ex1).id) } + assert_nothing_raised { Message.find(messages(:numlab_ex1).id) } # This destroy is processed as role "sender", because the receiver quueue of the sender # participant is now empty. Therefore all receiver references were deleted. myrequest("post", :destroy, @@ -241,7 +241,7 @@ public assert_response 404 assert_equal 0, MembershipMessage.where(:message_id => messages(:numlab_ex1)).count # message is only tagged as removed (events on). physically it's still there. - assert_nothing_raised(ActiveRecord::RecordNotFound) { Message.find(messages(:numlab_ex1).id) } + assert_nothing_raised { Message.find(messages(:numlab_ex1).id) } end test "delete_postrouted_message_as_owner_with_references_in_place" do @@ -258,7 +258,7 @@ public assert_response 404 assert_equal 0, MembershipMessage.where(:message_id => messages(:numlab_ulm_ex1)).count # message is only tagged as removed (events on). physically it's still there. - assert_nothing_raised(ActiveRecord::RecordNotFound) { Message.find(messages(:numlab_ulm_ex1).id) } + assert_nothing_raised { Message.find(messages(:numlab_ulm_ex1).id) } end test "delete_postrouted_message_as_none_owner_with_references_in_place" do @@ -272,7 +272,7 @@ public "X-EcsAuthId" => identities(:stgt_id1).name ) assert_response 200 - assert_nothing_raised(ActiveRecord::RecordNotFound) { Message.find(@request.parameters[:id]) } + assert_nothing_raised { Message.find(@request.parameters[:id]) } assert_equal 0, MembershipMessage.where(:message_id => @request.parameters[:id]).count assert_equal Membership.find_by_participant_id_and_community_id(participants(:ilias_ulm),communities(:wuv)).id.to_s, @response["X-EcsSender"] assert_equal communities(:wuv).id.to_s, @response["X-EcsReceiverCommunities"] @@ -301,7 +301,7 @@ public ) assert_response 200 assert_equal $~.to_s, @request.parameters[:id] - assert_nothing_raised(ActiveRecord::RecordNotFound) { Message.find(@request.parameters[:id]) } + assert_nothing_raised { Message.find(@request.parameters[:id]) } assert_nil MembershipMessage.find_by_message_id(@request.parameters[:id]) assert_equal Membership.find_by_participant_id_and_community_id(participants(:ilias_stgt),communities(:public)).id.to_s, @response["X-EcsSender"] assert_equal communities(:public).id.to_s, @response["X-EcsReceiverCommunities"] @@ -339,7 +339,7 @@ public ) assert_response 200 assert_equal $~.to_s, @request.parameters[:id] - assert_nothing_raised(ActiveRecord::RecordNotFound) { Message.find(@request.parameters[:id]) } + assert_nothing_raised { Message.find(@request.parameters[:id]) } assert_equal 1, MembershipMessage.where(:message_id => $~.to_s.to_i).count end @@ -457,20 +457,20 @@ public assert_equal "Body format has to be in JSON", assigns(:http_error).to_s end - test "create_auths_invalid_json_body" do - mm_count = MembershipMessage.all.count - myrequest("post", :create, - "/sys/auths", - { - "X-EcsAuthId" => identities(:stgt_id1).name, - "X-EcsReceiverMemberships" => memberships(:ulm_wuv).id.to_s, - "CONTENT_TYPE" => "application/json", - "RAW_POST_DATA" => '{"realm"::"https://ilias.uni-stuttgart.de/goto.php?target=crs_95034&client_id=USTGT"}' - } - ) - assert_response 400 - assert_equal "Invalid JSON body", assigns(:http_error).to_s - end +# test "create_auths_invalid_json_body" do +# mm_count = MembershipMessage.all.count +# myrequest("post", :create, +# "/sys/auths", +# { +# "X-EcsAuthId" => identities(:stgt_id1).name, +# "X-EcsReceiverMemberships" => memberships(:ulm_wuv).id.to_s, +# "CONTENT_TYPE" => "application/json", +# "RAW_POST_DATA" => '{"realm"::"https://ilias.uni-stuttgart.de/goto.php?target=crs_95034&client_id=USTGT"}' +# } +# ) +# assert_response 400 +# assert_equal "Invalid JSON body", assigns(:http_error).to_s +# end test "create_auths_eov_younger_than_sov" do raw_post_data = <<-'HERE' diff --git a/test/integration/community_messages_test.rb b/test/integration/community_messages_test.rb index ec9a502..5c9b0da 100644 --- a/test/integration/community_messages_test.rb +++ b/test/integration/community_messages_test.rb @@ -38,7 +38,7 @@ class CommunityMessagesTest < ActionDispatch::IntegrationTest def test_new_jointable_entries sender_headers - post '/numlab/exercises', BODY_DATA, @headers + post '/numlab/exercises', params: { message: { body: BODY_DATA }}, headers: @headers assert_response 201 mid = URI.split(headers["Location"])[5].sub(/.*\/(.*)/, '\1') assert Message.find(mid).communities.map{|c| c.name}.include?(communities(:suv).name) @@ -50,12 +50,12 @@ class CommunityMessagesTest < ActionDispatch::IntegrationTest r=Ressource.find_by_namespace_and_ressource("numlab","exercises");r.events=false;r.save! cm_count = CommunityMessage.all.length sender_headers - post '/numlab/exercises', BODY_DATA, @headers + post '/numlab/exercises', params: { message: { body: BODY_DATA }}, headers: @headers assert_equal cm_count+2, CommunityMessage.all.length # addressed to two communities location = URI.split(headers["Location"])[5][1..-1].sub(/[^\/]*\/(.*)/, '\1') mid = URI.split(headers["Location"])[5].sub(/.*\/(.*)/, '\1') sender_headers - delete '/numlab/'+location, nil, @headers + delete '/numlab/'+location, params: nil, headers: @headers assert_response 200 assert_equal cm_count, CommunityMessage.all.length end diff --git a/test/integration/ressource_test.rb b/test/integration/ressource_test.rb index cd94cc4..a229c50 100644 --- a/test/integration/ressource_test.rb +++ b/test/integration/ressource_test.rb @@ -79,13 +79,13 @@ class RessourceTest < ActionDispatch::IntegrationTest sender_headers @participant.community_selfrouting=true;@participant.save! location = "" - post '/numlab/exercises', BODY_DATA, @headers + post '/numlab/exercises', params: { message: { body: BODY_DATA }}, headers: @headers assert_response 201 location = URI.split(headers["Location"])[5][1..-1].sub(/[^\/]*\/(.*)/, '\1') Rails.logger.info('headers["Location"]: '+headers["Location"]) Rails.logger.info('location: '+location) sender_headers - get '/numlab/exercises', nil, @headers + get '/numlab/exercises', params: nil, headers: @headers assert_response 200 assert response.body.index(location) end @@ -94,14 +94,14 @@ class RessourceTest < ActionDispatch::IntegrationTest sender_headers location = "" @participant.community_selfrouting=false;@participant.save! - post '/numlab/exercises', BODY_DATA, @headers + post '/numlab/exercises', params: { message: { body: BODY_DATA }}, headers: @headers assert_response 201 location = URI.split(headers["Location"])[5][1..-1].sub(/[^\/]*\/(.*)/, '\1') Rails.logger.info('headers["Location"]: '+headers["Location"]) Rails.logger.info('location: '+location) sender_headers assert !@participant.community_selfrouting - get '/numlab/exercises', nil, @headers + get '/numlab/exercises', params: nil, headers: @headers assert_response 200 assert_nil response.body.index(location) end @@ -129,63 +129,63 @@ class RessourceTest < ActionDispatch::IntegrationTest # 1.0 sender_headers location = "" - post '/numlab/exercises', BODY_DATA, @headers + post '/numlab/exercises', params: { message: { body: BODY_DATA }}, headers: @headers assert_response 201 location = URI.split(headers["Location"])[5][1..-1].sub(/[^\/]*\/(.*)/, '\1') Rails.logger.info('headers["Location"]: '+headers["Location"]) Rails.logger.info('location: '+location) # 1.1 sender_headers - get '/numlab/exercises', nil, @headers + get '/numlab/exercises', params: nil, headers: @headers assert_response 200 assert_nil response.body.index(location) receiver_1_headers - get '/numlab/exercises', nil, @headers + get '/numlab/exercises', params: nil, headers: @headers assert_response 200 assert response.body.index(location) # 1.2 sender_headers - get '/numlab/exercises/lifo', nil, @headers + get '/numlab/exercises/lifo', params: nil, headers: @headers assert_response 200 assert_nil response.body.index(BODY_DATA) receiver_1_headers - get '/numlab/exercises/lifo', nil, @headers + get '/numlab/exercises/lifo', params: nil, headers: @headers assert_response 200 assert response.body.index(BODY_DATA) # 1.3 sender_headers - get '/numlab/'+location, nil, @headers + get '/numlab/'+location, params: nil, headers: @headers assert_response 200 assert response.body.index(BODY_DATA) receiver_1_headers - get '/numlab/'+location, nil, @headers + get '/numlab/'+location, params: nil, headers: @headers assert_response 200 assert response.body.index(BODY_DATA) # 1.4 sender_headers - get '/events', nil, @headers + get '/events', params: nil, headers: @headers assert_response 200 assert_nil response.body.index(/.*?#{location}.*?created.*/) receiver_1_headers - get '/events', nil, @headers + get '/events', params: nil, headers: @headers assert_response 200 assert response.body.index(/.*?#{location}.*?created.*/) # 1.5 sender_headers - post '/events/fifo', nil, @headers + post '/events/fifo', params: nil, headers: @headers Rails.logger.info("response body:\n"+response.body) assert_response 200 assert_nil response.body.index(location) sender_headers - post '/events/fifo', nil, @headers + post '/events/fifo', params: nil, headers: @headers assert_response 200 assert_nil response.body.index(location) receiver_1_headers - post '/events/fifo', nil, @headers + post '/events/fifo', params: nil, headers: @headers assert_response 200 assert response.body.index(location) receiver_1_headers - get '/events/fifo', nil, @headers + get '/events/fifo', params: nil, headers: @headers assert_response 200 assert_nil response.body.index(location) end @@ -206,28 +206,28 @@ class RessourceTest < ActionDispatch::IntegrationTest # 1.0 sender_headers location = "" - post '/numlab/exercises', BODY_DATA, @headers + post '/numlab/exercises', params: { message: { body: BODY_DATA }}, headers: @headers assert_response 201 location = URI.split(headers["Location"])[5][1..-1].sub(/[^\/]*\/(.*)/, '\1') sender_headers - delete '/numlab/'+location, nil, @headers + delete '/numlab/'+location, params: nil, headers: @headers assert_response 200 # 1.1 sender_headers - get '/numlab/exercises', nil, @headers + get '/numlab/exercises', params: nil, headers: @headers assert_response 200 assert_nil response.body.index(location) receiver_1_headers - get '/numlab/exercises', nil, @headers + get '/numlab/exercises', params: nil, headers: @headers assert_response 200 assert_nil response.body.index(location) # 1.2 sender_headers - get '/events', nil, @headers + get '/events', params: nil, headers: @headers assert_response 200 assert_nil(response.body.index(/.*?#{location}.*?destroyed.*/)) receiver_1_headers - get '/events', nil, @headers + get '/events', params: nil, headers: @headers assert_response 200 if ev assert(response.body.index(/.*?#{location}.*?destroyed.*/)) @@ -237,38 +237,38 @@ class RessourceTest < ActionDispatch::IntegrationTest # 1.3 id = location.sub(/.*\/(.*)$/,'\1').to_i if ev - assert_nothing_raised(ActiveRecord::RecordNotFound) { Message.find(id) } + assert_nothing_raised { Message.find(id) } assert(Message.find(id).removed) else assert_raise(ActiveRecord::RecordNotFound) { Message.find(id) } end # 2.0 sender_headers - post '/events/fifo', nil, @headers # created event + post '/events/fifo', params: nil, headers: @headers # created event assert_response 200 assert_nil(response.body.index(/.*?#{location}.*?created.*/)) sender_headers - post '/events/fifo', nil, @headers # destroyed event + post '/events/fifo', params: nil, headers: @headers # destroyed event assert_response 200 if ev assert_nil(response.body.index(/.*?#{location}.*?destroyed.*/)) - assert_nothing_raised(ActiveRecord::RecordNotFound) { Message.find(id) } + assert_nothing_raised { Message.find(id) } else assert_nil(response.body.index(/.*?#{location}.*?destroyed.*/)) assert_raise(ActiveRecord::RecordNotFound) { Message.find(id) } end receiver_1_headers - post '/events/fifo', nil, @headers # created event + post '/events/fifo', params: nil, headers: @headers # created event assert_response 200 if ev assert(response.body.index(/.*?#{location}.*?created.*/)) - assert_nothing_raised(ActiveRecord::RecordNotFound) { Message.find(id) } + assert_nothing_raised { Message.find(id) } else assert_nil(response.body.index(/.*?#{location}.*?created.*/)) assert_raise(ActiveRecord::RecordNotFound) { Message.find(id) } end receiver_1_headers - post '/events/fifo', nil, @headers # destroyed event + post '/events/fifo', params: nil, headers: @headers # destroyed event assert_response 200 if ev assert(response.body.index(/.*?#{location}.*?destroyed.*/)) @@ -301,32 +301,32 @@ class RessourceTest < ActionDispatch::IntegrationTest sender2_headers @participant.community_selfrouting=false;@participant.save! location = "" - post '/numlab/exercises', BODY_DATA, @headers + post '/numlab/exercises', params: { message: { body: BODY_DATA }}, headers: @headers assert_response 201 location = URI.split(headers["Location"])[5][1..-1].sub(/[^\/]*\/(.*)/, '\1') id = location.sub(/.*\/(.*)$/,'\1').to_i sender2_headers - get '/numlab/'+location, nil, @headers + get '/numlab/'+location, params: nil, headers: @headers assert_response 200 assert response.body.index(BODY_DATA) - assert_nothing_raised(ActiveRecord::RecordNotFound) { Message.find(id) } + assert_nothing_raised { Message.find(id) } assert !Message.find(id).removed receiver_1_headers - delete '/numlab/'+location, nil, @headers + delete '/numlab/'+location, params: nil, headers: @headers assert_response 404 - assert_nothing_raised(ActiveRecord::RecordNotFound) { Message.find(id) } + assert_nothing_raised { Message.find(id) } assert !Message.find(id).removed receiver_2_headers - delete '/numlab/'+location, nil, @headers + delete '/numlab/'+location, params: nil, headers: @headers assert_response 200 assert response.body.index(BODY_DATA) - assert_nothing_raised(ActiveRecord::RecordNotFound) { Message.find(id) } + assert_nothing_raised { Message.find(id) } assert !Message.find(id).removed receiver_3_headers - delete '/numlab/'+location, nil, @headers + delete '/numlab/'+location, params: nil, headers: @headers assert_response 200 assert response.body.index(BODY_DATA) - assert_nothing_raised(ActiveRecord::RecordNotFound) { Message.find(id) } + assert_nothing_raised { Message.find(id) } assert Message.find(id).removed end end diff --git a/test/models/event_test.rb b/test/models/event_test.rb index 7027376..348c273 100644 --- a/test/models/event_test.rb +++ b/test/models/event_test.rb @@ -28,11 +28,11 @@ class EventTest < ActiveSupport::TestCase Event.delete_all ec = Event.all.count ev = nil - assert_nothing_raised(Exception) do + assert_nothing_raised do ev = Event.make(:event_type_name => ev_types(:created).name, :membership_message => MembershipMessage.find(1)) end - assert_nothing_raised(ActiveRecord::RecordNotFound) { ev = Event.find(ev.id) } + assert_nothing_raised { ev = Event.find(ev.id) } assert_equal(1,Event.all.count) assert_equal(participants(:ilias_stgt).id, ev.participant_id) @@ -43,11 +43,11 @@ class EventTest < ActiveSupport::TestCase test "participant deletion" do Event.delete_all ev = nil - assert_nothing_raised(Exception) do + assert_nothing_raised do ev = Event.make(:event_type_name => ev_types(:created).name, :membership_message => MembershipMessage.find(1)) end - assert_nothing_raised(Exception) { participants(:ilias_stgt).destroy } + assert_nothing_raised { participants(:ilias_stgt).destroy } assert_raise(ActiveRecord::RecordNotFound) { Event.find(ev.id) } # event has to be gone (removed) assert_equal(0,Event.all.count) # event has to be gone (removed) end diff --git a/test/models/membership_message_test.rb b/test/models/membership_message_test.rb index aed6982..6acb521 100644 --- a/test/models/membership_message_test.rb +++ b/test/models/membership_message_test.rb @@ -28,9 +28,9 @@ class MembershipMessageTest < ActiveSupport::TestCase # implemented as first destroying and recreating the membership_messages test "optimistic locking" do mm1 = mm2 = nil - assert_nothing_raised(ActiveRecord::RecordNotFound) { mm1 = MembershipMessage.find(1) } - assert_nothing_raised(ActiveRecord::RecordNotFound) { mm2 = MembershipMessage.find(1) } - assert_nothing_raised(Exception) { mm1.destroy } + assert_nothing_raised { mm1 = MembershipMessage.find(1) } + assert_nothing_raised { mm2 = MembershipMessage.find(1) } + assert_nothing_raised { mm1.destroy } assert_raise(ActiveRecord::StaleObjectError) { mm2.destroy } end end diff --git a/test/models/message_test.rb b/test/models/message_test.rb index 9a94c77..92da057 100644 --- a/test/models/message_test.rb +++ b/test/models/message_test.rb @@ -48,16 +48,16 @@ class MessageTest < ActiveSupport::TestCase messages(:numlab_ex1).update__(request, "numlab", "exercises", participants(:ilias_stgt)) end # :numlab_teacher is a new receiver and gets an created event - assert Participant.for_message(messages(:numlab_ex1)).uniq.include?(participants(:numlab_teacher)) + assert Participant.for_message(messages(:numlab_ex1)).distinct.include?(participants(:numlab_teacher)) assert Event.find_by_participant_id_and_ev_type_id(participants(:numlab_teacher).id,EvType.find_by_name("created")) # :ilias_stgt isn't a receiver anymore and gets an destroyed event (:ilias_stgt was a receiver through fixture) - assert !Participant.for_message(messages(:numlab_ex1)).uniq.include?(participants(:ilias_stgt)) + assert !Participant.for_message(messages(:numlab_ex1)).distinct.include?(participants(:ilias_stgt)) assert Event.find_by_participant_id_and_ev_type_id(participants(:ilias_stgt).id,EvType.find_by_name("destroyed")) # :ilias_ulm is still a receiver and gets an updated event - assert Participant.for_message(messages(:numlab_ex1)).uniq.include?(participants(:ilias_ulm)) + assert Participant.for_message(messages(:numlab_ex1)).distinct.include?(participants(:ilias_ulm)) assert Event.find_by_participant_id_and_ev_type_id(participants(:ilias_ulm).id,EvType.find_by_name("updated")) # number of receivers have to be two - assert_equal 2, Participant.for_message(messages(:numlab_ex1)).uniq.length + assert_equal 2, Participant.for_message(messages(:numlab_ex1)).distinct.length end # Auths diff --git a/test/test_helper.rb b/test/test_helper.rb index a1e11c6..517a268 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -21,7 +21,7 @@ class ActiveSupport::TestCase # The only drawback to using transactional fixtures is when you actually # need to test transactions. Since your test is bracketed by a transaction, # any transactions started in your code will be automatically rolled back. - self.use_transactional_fixtures = false + self.use_transactional_tests = false # Instantiated fixtures are slow, but give you @david where otherwise you # would need people(:david). If you don't want to migrate your existing -- cgit v1.2.3