From 86684e6bf2533950928ff0b44957a6f154151266 Mon Sep 17 00:00:00 2001 From: echarp Date: Sat, 11 Nov 2017 12:44:09 +0100 Subject: [PATCH] Intermediary upgrade to rails 5 --- Gemfile.lock | 78 +++++++++-------- Guardfile | 2 +- app/controllers/application_controller.rb | 2 +- app/models/event.rb | 2 +- app/views/devise/confirmations/new.html.haml | 9 +- .../confirmation_instructions.html.haml | 2 +- .../devise/mailer/email_changed.html.haml | 8 ++ .../devise/mailer/password_change.html.haml | 3 + .../reset_password_instructions.html.haml | 2 +- .../mailer/unlock_instructions.html.haml | 2 +- app/views/devise/passwords/edit.html.haml | 17 ++-- app/views/devise/passwords/new.html.haml | 9 +- app/views/devise/registrations/edit.html.haml | 28 ++++--- app/views/devise/registrations/new.html.haml | 20 +++-- app/views/devise/sessions/new.html.haml | 11 ++- app/views/devise/shared/_links.html.haml | 19 +++++ app/views/devise/unlocks/new.html.haml | 9 +- app/views/orgas/_types.haml | 2 +- app/views/orgas/index.html.haml | 2 +- test/controllers/orgas_controller_test.rb | 83 ++++++++++--------- test/mailers/previews/event_mailer_preview.rb | 4 +- test/models/event_test.rb | 8 +- test/test_helper.rb | 10 ++- 23 files changed, 194 insertions(+), 138 deletions(-) create mode 100644 app/views/devise/mailer/email_changed.html.haml create mode 100644 app/views/devise/mailer/password_change.html.haml create mode 100644 app/views/devise/shared/_links.html.haml diff --git a/Gemfile.lock b/Gemfile.lock index b98408d8..3bc9e9fd 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -95,8 +95,8 @@ GEM railties (>= 4.1.0, < 5.2) responders warden (~> 1.2.3) - devise-i18n (1.3.0) - devise (>= 2.0) + devise-i18n (1.4.0) + devise (>= 3.1) differ (0.1.2) domain_name (0.5.20170404) unf (>= 0.0.5, < 1.0.0) @@ -110,8 +110,6 @@ GEM erubis (2.7.0) eventmachine (1.2.5) execjs (2.7.0) - faraday (0.11.0) - multipart-post (>= 1.2, < 3) ffi (1.9.18) flag-icons-rails (2.5.0) sass (~> 3.2) @@ -122,7 +120,7 @@ GEM actionpack (>= 3.2.13) formtastic_i18n (0.6.0) geocoder (1.4.4) - globalid (0.4.0) + globalid (0.4.1) activesupport (>= 4.2.0) guard (2.14.1) formatador (>= 0.2.4) @@ -168,11 +166,11 @@ GEM haml (>= 4.0.6, < 6.0) html2haml (>= 1.0.1) railties (>= 4.0.1) - haml_lint (0.26.0) + haml_lint (0.27.0) haml (>= 4.0, < 5.1) rainbow rake (>= 10, < 13) - rubocop (>= 0.49.0) + rubocop (>= 0.50.0) sysexits (~> 1.1) has_scope (0.7.1) actionpack (>= 4.1, < 5.2) @@ -183,17 +181,17 @@ GEM haml (>= 4.0, < 6) nokogiri (>= 1.6.0) ruby_parser (~> 3.5) - http (2.2.2) + http (3.0.0) addressable (~> 2.3) http-cookie (~> 1.0) - http-form_data (~> 1.0.1) + http-form_data (>= 2.0.0.pre.pre2, < 3) http_parser.rb (~> 0.6.0) http-cookie (1.0.3) domain_name (~> 0.5) - http-form_data (1.0.3) + http-form_data (2.0.0) http_accept_language (2.1.1) http_parser.rb (0.6.0) - i18n (0.9.0) + i18n (0.9.1) concurrent-ruby (~> 1.0) i18n-active_record (0.2.0) i18n (>= 0.5.0) @@ -213,18 +211,18 @@ GEM jquery-ui-rails (6.0.1) railties (>= 3.2.16) json (1.8.6) - kaminari (1.1.0) + kaminari (1.1.1) activesupport (>= 4.1.0) - kaminari-actionview (= 1.1.0) - kaminari-activerecord (= 1.1.0) - kaminari-core (= 1.1.0) - kaminari-actionview (1.1.0) + kaminari-actionview (= 1.1.1) + kaminari-activerecord (= 1.1.1) + kaminari-core (= 1.1.1) + kaminari-actionview (1.1.1) actionview - kaminari-core (= 1.1.0) - kaminari-activerecord (1.1.0) + kaminari-core (= 1.1.1) + kaminari-activerecord (1.1.1) activerecord - kaminari-core (= 1.1.0) - kaminari-core (1.1.0) + kaminari-core (= 1.1.1) + kaminari-core (1.1.1) kramdown (1.15.0) libv8 (3.16.14.19) listen (3.1.5) @@ -235,17 +233,14 @@ GEM crass (~> 1.0.2) nokogiri (>= 1.5.9) lumberjack (1.0.12) - mail (2.6.6) - mime-types (>= 1.16, < 4) + mail (2.7.0) + mini_mime (>= 0.1.1) memoizable (0.4.2) thread_safe (~> 0.3, >= 0.3.1) meta-tags (2.6.0) actionpack (>= 3.2.0, < 5.3) method_source (0.9.0) - mime-types (3.1) - mime-types-data (~> 3.2015) - mime-types-data (3.2016.0521) - mini_mime (0.1.4) + mini_mime (1.0.0) minitest (5.10.3) modernizr-rails (2.7.1) multi_json (1.12.2) @@ -259,7 +254,7 @@ GEM nenv (~> 0.1) shellany (~> 0.0) orm_adapter (0.5.0) - paper_trail (8.0.0) + paper_trail (8.0.1) activerecord (>= 4.2, < 5.2) request_store (~> 1.1) parallel (1.12.0) @@ -275,7 +270,7 @@ GEM pry (0.11.2) coderay (~> 1.1.0) method_source (~> 0.9.0) - public_suffix (3.0.0) + public_suffix (3.0.1) puma (3.10.0) rack (2.0.3) rack-livereload (0.3.16) @@ -296,7 +291,7 @@ GEM sprockets-rails (>= 2.0.0) rails-assets-jquery-sparkline (2.1.3) rails-assets-leaflet (1.2.0) - rails-assets-leaflet.markercluster (1.1.0) + rails-assets-leaflet.markercluster (1.2.0) rails-assets-leaflet (>= 1.0.3) rails-dom-testing (2.0.3) activesupport (>= 4.2.0) @@ -314,7 +309,7 @@ GEM thor (>= 0.18.1, < 2.0) rainbow (2.2.2) rake - rake (12.1.0) + rake (12.2.1) ransack (1.8.4) actionpack (>= 3.0) activerecord (>= 3.0) @@ -342,7 +337,7 @@ GEM ruby_parser (3.10.1) sexp_processor (~> 4.9) rubyzip (1.2.1) - sass (3.5.2) + sass (3.5.3) sass-listen (~> 4.0.0) sass-listen (4.0.0) rb-fsevent (~> 0.9, >= 0.9.4) @@ -356,7 +351,7 @@ GEM sdoc (0.4.2) json (~> 1.7, >= 1.7.7) rdoc (~> 4.0) - selenium-webdriver (3.6.0) + selenium-webdriver (3.7.0) childprocess (~> 0.5) rubyzip (~> 1.0) sexp_processor (4.10.0) @@ -396,17 +391,18 @@ GEM turbolinks (5.0.1) turbolinks-source (~> 5) turbolinks-source (5.0.3) - twitter (6.1.0) - addressable (~> 2.5) + twitter (6.2.0) + addressable (~> 2.3) buftok (~> 0.2.0) - equalizer (= 0.0.11) - faraday (~> 0.11.0) - http (~> 2.1) + equalizer (~> 0.0.11) + http (~> 3.0) + http-form_data (~> 2.0) http_parser.rb (~> 0.6.0) - memoizable (~> 0.4.2) - naught (~> 1.1) - simple_oauth (~> 0.3.1) - tzinfo (1.2.3) + memoizable (~> 0.4.0) + multipart-post (~> 2.0) + naught (~> 1.0) + simple_oauth (~> 0.3.0) + tzinfo (1.2.4) thread_safe (~> 0.1) uglifier (3.2.0) execjs (>= 0.3.0, < 3) diff --git a/Guardfile b/Guardfile index 98ab417c..f9fa6181 100644 --- a/Guardfile +++ b/Guardfile @@ -11,7 +11,7 @@ guard :livereload do watch(%r{(app|vendor)(/assets/\w+/(.+\.(sass|coffee|haml))).*}) { |m| "/assets/#{m[3]}" } end -guard :minitest do +guard :minitest, spring: 'bin/rails test' do # with Minitest::Unit watch(%r{^test/(.*)\/?test_(.*)\.rb}) watch(%r{^lib/(.*/)?([^/]+)\.rb}) { |m| "test/#{m[1]}test_#{m[2]}.rb" } diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index f6cf2e93..76dfaedb 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -3,7 +3,7 @@ class ApplicationController < ActionController::Base before_action :set_paper_trail_whodunnit, :set_locale, :set_filters # Prevent CSRF attacks by raising an exception. # For APIs, you may want to use :null_session instead. - protect_from_forgery with: :exception + protect_from_forgery prepend: true, with: :exception private diff --git a/app/models/event.rb b/app/models/event.rb index 1e770535..db30d3cd 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -18,7 +18,7 @@ class Event < ApplicationRecord validates :title, presence: true validate :end_after_start RULES = %w[daily weekly monthly monthly_day].freeze - validates :rule, allow_nil: true, inclusion: RULES + validates :rule, inclusion: RULES validates :description, presence: true validates :city, presence: true validates :region, presence: true diff --git a/app/views/devise/confirmations/new.html.haml b/app/views/devise/confirmations/new.html.haml index 88c63737..0ae8b1e7 100644 --- a/app/views/devise/confirmations/new.html.haml +++ b/app/views/devise/confirmations/new.html.haml @@ -1,9 +1,10 @@ %h2 Resend confirmation instructions -= form_for(resource, :as => resource_name, :url => confirmation_path(resource_name), :html => { :method => :post }) do |f| += form_for(resource, as: resource_name, url: confirmation_path(resource_name), html: { method: :post }) do |f| = devise_error_messages! - %div + .field = f.label :email %br/ - = f.email_field :email, :autofocus => true - %div= f.submit "Resend confirmation instructions" + = f.email_field :email, autofocus: true, value: (resource.pending_reconfirmation? ? resource.unconfirmed_email : resource.email) + .actions + = f.submit "Resend confirmation instructions" = render "devise/shared/links" diff --git a/app/views/devise/mailer/confirmation_instructions.html.haml b/app/views/devise/mailer/confirmation_instructions.html.haml index dfa5989a..27d48e6d 100644 --- a/app/views/devise/mailer/confirmation_instructions.html.haml +++ b/app/views/devise/mailer/confirmation_instructions.html.haml @@ -1,4 +1,4 @@ %p Welcome #{@email}! %p You can confirm your account email through the link below: -%p= link_to 'Confirm my account', confirmation_url(@resource, :confirmation_token => @token) +%p= link_to 'Confirm my account', confirmation_url(@resource, confirmation_token: @token) diff --git a/app/views/devise/mailer/email_changed.html.haml b/app/views/devise/mailer/email_changed.html.haml new file mode 100644 index 00000000..94ebba05 --- /dev/null +++ b/app/views/devise/mailer/email_changed.html.haml @@ -0,0 +1,8 @@ +%p + Hello #{@email}! +- if @resource.try(:unconfirmed_email?) + %p + We're contacting you to notify you that your email is being changed to #{@resource.unconfirmed_email}. +- else + %p + We're contacting you to notify you that your email has been changed to #{@resource.email}. diff --git a/app/views/devise/mailer/password_change.html.haml b/app/views/devise/mailer/password_change.html.haml new file mode 100644 index 00000000..ab7c04c4 --- /dev/null +++ b/app/views/devise/mailer/password_change.html.haml @@ -0,0 +1,3 @@ +%p + Hello #{@resource.email}! +%p We're contacting you to notify you that your password has been changed. diff --git a/app/views/devise/mailer/reset_password_instructions.html.haml b/app/views/devise/mailer/reset_password_instructions.html.haml index eda27ee3..0711cd5a 100644 --- a/app/views/devise/mailer/reset_password_instructions.html.haml +++ b/app/views/devise/mailer/reset_password_instructions.html.haml @@ -1,6 +1,6 @@ %p Hello #{@resource.email}! %p Someone has requested a link to change your password. You can do this through the link below. -%p= link_to 'Change my password', edit_password_url(@resource, :reset_password_token => @token) +%p= link_to 'Change my password', edit_password_url(@resource, reset_password_token: @token) %p If you didn't request this, please ignore this email. %p Your password won't change until you access the link above and create a new one. diff --git a/app/views/devise/mailer/unlock_instructions.html.haml b/app/views/devise/mailer/unlock_instructions.html.haml index 47f55a54..282c98a2 100644 --- a/app/views/devise/mailer/unlock_instructions.html.haml +++ b/app/views/devise/mailer/unlock_instructions.html.haml @@ -2,4 +2,4 @@ Hello #{@resource.email}! %p Your account has been locked due to an excessive number of unsuccessful sign in attempts. %p Click the link below to unlock your account: -%p= link_to 'Unlock my account', unlock_url(@resource, :unlock_token => @token) +%p= link_to 'Unlock my account', unlock_url(@resource, unlock_token: @token) diff --git a/app/views/devise/passwords/edit.html.haml b/app/views/devise/passwords/edit.html.haml index 85156881..fc6f52d8 100644 --- a/app/views/devise/passwords/edit.html.haml +++ b/app/views/devise/passwords/edit.html.haml @@ -1,14 +1,19 @@ %h2 Change your password -= form_for(resource, :as => resource_name, :url => password_path(resource_name), :html => { :method => :put }) do |f| += form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :put }) do |f| = devise_error_messages! = f.hidden_field :reset_password_token - %div + .field = f.label :password, "New password" %br/ - = f.password_field :password, :autofocus => true - %div + - if @minimum_password_length + %em + (#{@minimum_password_length} characters minimum) + %br/ + = f.password_field :password, autofocus: true, autocomplete: "off" + .field = f.label :password_confirmation, "Confirm new password" %br/ - = f.password_field :password_confirmation - %div= f.submit "Change my password" + = f.password_field :password_confirmation, autocomplete: "off" + .actions + = f.submit "Change my password" = render "devise/shared/links" diff --git a/app/views/devise/passwords/new.html.haml b/app/views/devise/passwords/new.html.haml index 591033be..9add188d 100644 --- a/app/views/devise/passwords/new.html.haml +++ b/app/views/devise/passwords/new.html.haml @@ -1,9 +1,10 @@ %h2 Forgot your password? -= form_for(resource, :as => resource_name, :url => password_path(resource_name), :html => { :method => :post }) do |f| += form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :post }) do |f| = devise_error_messages! - %div + .field = f.label :email %br/ - = f.email_field :email, :autofocus => true - %div= f.submit "Send me reset password instructions" + = f.email_field :email, autofocus: true + .actions + = f.submit "Send me reset password instructions" = render "devise/shared/links" diff --git a/app/views/devise/registrations/edit.html.haml b/app/views/devise/registrations/edit.html.haml index 74491142..09789dee 100644 --- a/app/views/devise/registrations/edit.html.haml +++ b/app/views/devise/registrations/edit.html.haml @@ -1,30 +1,36 @@ %h2 Edit #{resource_name.to_s.humanize} -= form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => { :method => :put }) do |f| += form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put }) do |f| = devise_error_messages! - %div + .field = f.label :email %br/ - = f.email_field :email, :autofocus => true + = f.email_field :email, autofocus: true - if devise_mapping.confirmable? && resource.pending_reconfirmation? %div Currently waiting confirmation for: #{resource.unconfirmed_email} - %div + .field = f.label :password %i (leave blank if you don't want to change it) %br/ - = f.password_field :password, :autocomplete => "off" - %div + = f.password_field :password, autocomplete: "off" + - if @minimum_password_length + %br/ + %em + = @minimum_password_length + characters minimum + .field = f.label :password_confirmation %br/ - = f.password_field :password_confirmation - %div + = f.password_field :password_confirmation, autocomplete: "off" + .field = f.label :current_password %i (we need your current password to confirm your changes) %br/ - = f.password_field :current_password - %div= f.submit "Update" + = f.password_field :current_password, autocomplete: "off" + .actions + = f.submit "Update" %h3 Cancel my account %p - Unhappy? #{button_to "Cancel my account", registration_path(resource_name), :data => { :confirm => "Are you sure?" }, :method => :delete} + Unhappy? #{button_to "Cancel my account", registration_path(resource_name), data: { confirm: "Are you sure?" }, method: :delete} = link_to "Back", :back diff --git a/app/views/devise/registrations/new.html.haml b/app/views/devise/registrations/new.html.haml index 521431c0..41dc5e85 100644 --- a/app/views/devise/registrations/new.html.haml +++ b/app/views/devise/registrations/new.html.haml @@ -1,17 +1,21 @@ %h2 Sign up -= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| += form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| = devise_error_messages! - %div + .field = f.label :email %br/ - = f.email_field :email, :autofocus => true - %div + = f.email_field :email, autofocus: true + .field = f.label :password + - if @minimum_password_length + %em + (#{@minimum_password_length} characters minimum) %br/ - = f.password_field :password - %div + = f.password_field :password, autocomplete: "off" + .field = f.label :password_confirmation %br/ - = f.password_field :password_confirmation - %div= f.submit "Sign up" + = f.password_field :password_confirmation, autocomplete: "off" + .actions + = f.submit "Sign up" = render "devise/shared/links" diff --git a/app/views/devise/sessions/new.html.haml b/app/views/devise/sessions/new.html.haml index 846a4550..cff8709d 100644 --- a/app/views/devise/sessions/new.html.haml +++ b/app/views/devise/sessions/new.html.haml @@ -2,20 +2,19 @@ %fieldset = form_for resource, as: resource_name, - url: session_path(resource_name) do |f| + url: session_path(resource_name) do |f| .field.login = f.label :login - = f.text_field :login, autofocus: true - + %br/ + = f.email_field :login, autofocus: true .field.password = f.label :password - = f.password_field :password - + %br/ + = f.password_field :password, autocomplete: 'off' - if devise_mapping.rememberable? .field = f.check_box :remember_me = f.label :remember_me - .actions= f.submit t('.sign_in') = render 'devise/shared/links' diff --git a/app/views/devise/shared/_links.html.haml b/app/views/devise/shared/_links.html.haml new file mode 100644 index 00000000..d0ebcbb5 --- /dev/null +++ b/app/views/devise/shared/_links.html.haml @@ -0,0 +1,19 @@ +- if controller_name != 'sessions' + = link_to "Log in", new_session_path(resource_name) + %br/ +- if devise_mapping.registerable? && controller_name != 'registrations' + = link_to "Sign up", new_registration_path(resource_name) + %br/ +- if devise_mapping.recoverable? && controller_name != 'passwords' && controller_name != 'registrations' + = link_to "Forgot your password?", new_password_path(resource_name) + %br/ +- if devise_mapping.confirmable? && controller_name != 'confirmations' + = link_to "Didn't receive confirmation instructions?", new_confirmation_path(resource_name) + %br/ +- if devise_mapping.lockable? && resource_class.unlock_strategy_enabled?(:email) && controller_name != 'unlocks' + = link_to "Didn't receive unlock instructions?", new_unlock_path(resource_name) + %br/ +- if devise_mapping.omniauthable? + - resource_class.omniauth_providers.each do |provider| + = link_to "Sign in with #{OmniAuth::Utils.camelize(provider)}", omniauth_authorize_path(resource_name, provider) + %br/ diff --git a/app/views/devise/unlocks/new.html.haml b/app/views/devise/unlocks/new.html.haml index d3c87d07..8df87885 100644 --- a/app/views/devise/unlocks/new.html.haml +++ b/app/views/devise/unlocks/new.html.haml @@ -1,9 +1,10 @@ %h2 Resend unlock instructions -= form_for(resource, :as => resource_name, :url => unlock_path(resource_name), :html => { :method => :post }) do |f| += form_for(resource, as: resource_name, url: unlock_path(resource_name), html: { method: :post }) do |f| = devise_error_messages! - %div + .field = f.label :email %br/ - = f.email_field :email, :autofocus => true - %div= f.submit "Resend unlock instructions" + = f.email_field :email, autofocus: true + .actions + = f.submit "Resend unlock instructions" = render "devise/shared/links" diff --git a/app/views/orgas/_types.haml b/app/views/orgas/_types.haml index 44ed85d5..a5de50ed 100644 --- a/app/views/orgas/_types.haml +++ b/app/views/orgas/_types.haml @@ -1,5 +1,5 @@ - params[:q] = {} if params[:q].nil? -- p = params[:q].clone +- p = params[:q].clone.permit %ul.counters -# The reorder and specific count are required for the "near" scope diff --git a/app/views/orgas/index.html.haml b/app/views/orgas/index.html.haml index 59ac6869..950d80dd 100644 --- a/app/views/orgas/index.html.haml +++ b/app/views/orgas/index.html.haml @@ -54,7 +54,7 @@ = link_to orga.feed do %em.fa.fa-rss{ title: Orga.human_attribute_name(:feed) } %td.view - = link_to orga_path(orga, q: params[:q], page: params[:page]) do + = link_to orga_path orga, q: params[:q].permit, page: params[:page] do %em.fa.fa-eye %td.edit - if orga.secret.nil? || user_signed_in? diff --git a/test/controllers/orgas_controller_test.rb b/test/controllers/orgas_controller_test.rb index 570fac19..839a69fa 100644 --- a/test/controllers/orgas_controller_test.rb +++ b/test/controllers/orgas_controller_test.rb @@ -1,40 +1,42 @@ require 'test_helper' -# Free Software groups life cycle -class OrgasControllerTest < ActionController::TestCase - include Devise::Test::ControllerHelpers - +# Organisations life cycle tests +class OrgasControllerTest < ActionDispatch::IntegrationTest setup do @orga = orgas :one end test 'should get index' do - get :index + get orgas_url, params: { + orga: { + region: regions(:region_one) + } + } assert_response :success end test 'should get new' do sign_in users(:one) - get :new + get new_orga_url assert_response :success end test 'should create orga' do sign_in users(:one) assert_difference 'Orga.count' do - post :create, orga: { - kind_id: @orga.kind_id, - name: @orga.name, - city: @orga.city, - region_id: @orga.region.id, - description: @orga.description, - url: @orga.url, - feed: @orga.feed, - contact: @orga.contact, - submitter: @orga.contact + post orgas_url, params: { + orga: { + kind_id: @orga.kind_id, + name: @orga.name, + city: @orga.city, + region_id: @orga.region.id, + description: @orga.description, + url: @orga.url, + feed: @orga.feed, + contact: @orga.contact, + submitter: @orga.contact + } } - - assert_empty assigns(:orga).errors.messages end assert_redirected_to :root @@ -43,31 +45,30 @@ class OrgasControllerTest < ActionController::TestCase test 'should create minimalist orga' do sign_in users(:one) assert_difference 'Orga.count' do - post :create, orga: { - kind_id: @orga.kind_id, - name: @orga.name, - region_id: @orga.region.id, - description: @orga.description, - url: @orga.url + post orgas_url, params: { + orga: { + kind_id: @orga.kind_id, + name: @orga.name, + region_id: @orga.region.id, + description: @orga.description, + url: @orga.url + } } - - assert_empty assigns(:orga).errors.messages end assert_redirected_to :root end test 'should not create orga' do - sign_in users(:one) assert_no_difference 'Orga.count' do - post :create, orga: { url: @orga.url } - - assert_not_empty assigns(:orga).errors.messages + post orgas_url, params: { + orga: { url: @orga.url } + } end end test 'should get show' do - get :show, id: @orga + get orga_url(@orga.id) assert_response :success end @@ -75,22 +76,28 @@ class OrgasControllerTest < ActionController::TestCase # Necessary to have the proper paper_trail version @orga.update_attributes name: 'My Title' - patch :update, id: @orga, secret: @orga.secret, orga: { name: @orga.name } + patch orga_url(@orga), params: { + secret: @orga.secret, + orga: { name: @orga.name } + } - assert_empty assigns(:orga).errors.messages - assert_redirected_to assigns(:orga) + assert_redirected_to orga_url(@orga) end test 'should not update orga' do sign_in users(:one) - patch :update, id: @orga, orga: { name: nil } + patch orga_url(@orga), params: { + orga: { name: nil } + } - assert_not_empty assigns(:orga).errors.messages + assert_redirected_to :new_user_session end test 'should not update orga without proper secret' do - patch :update, id: @orga, orga: { - name: 'hello world' + patch orga_url(@orga), params: { + orga: { + name: 'hello world' + } } assert_redirected_to :new_user_session diff --git a/test/mailers/previews/event_mailer_preview.rb b/test/mailers/previews/event_mailer_preview.rb index 67721f64..a980e749 100644 --- a/test/mailers/previews/event_mailer_preview.rb +++ b/test/mailers/previews/event_mailer_preview.rb @@ -18,8 +18,8 @@ class EventMailerPreview < ActionMailer::Preview event = Event.first event.start_time += 1.day - event.description = event.description + ' -hello world' + event.description = event.description + '

et

+

hello world

' EventMailer.update event end diff --git a/test/models/event_test.rb b/test/models/event_test.rb index a83f493c..ba8dc54b 100644 --- a/test/models/event_test.rb +++ b/test/models/event_test.rb @@ -84,14 +84,14 @@ class EventTest < ActiveSupport::TestCase test 'named scope future.daylimit' do assert Event.respond_to? :future assert Event.respond_to? :daylimit - assert_match(/<= end_time/, Event.future.daylimit(nil).where_values[0]) - assert_match(/end_time <=/, Event.future.daylimit(nil).where_values[1]) + assert_match(/<= end_time/, Event.future.daylimit(nil).to_sql) + assert_match(/end_time <=/, Event.future.daylimit(nil).to_sql) end test 'named scope year' do assert Event.respond_to? :year - assert_match(/<= end_time/, Event.year(2014).where_values[0]) - assert_match(/start_time <=/, Event.year(2014).where_values[0]) + assert_match(/<= end_time/, Event.year(2014).to_sql) + assert_match(/start_time <=/, Event.year(2014).to_sql) end test 'named scope region' do diff --git a/test/test_helper.rb b/test/test_helper.rb index b1d4ead6..830963a4 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -2,9 +2,9 @@ ENV['RAILS_ENV'] ||= 'test' require File.expand_path('../../config/environment', __FILE__) require 'rails/test_help' -require 'simplecov' +# require 'simplecov' -SimpleCov.start 'rails' +# SimpleCov.start 'rails' module ActiveSupport # Standard helper class for almost all tests @@ -32,5 +32,11 @@ module ActiveSupport 'country' => 'United States', 'country_code' => 'US' }] + + def sign_in(user) + post user_session_path \ + 'user[email]' => user.email, + 'user[password]' => user.password + end end end