From 6e213f754f68e43cca42637a365ede0fde7f34a7 Mon Sep 17 00:00:00 2001 From: Janis4411 Date: Tue, 2 Aug 2022 17:35:56 +0200 Subject: [PATCH] minor styling change to authenticationtoken model, changed the expire_at column of AuthenticationToken form date to datetime --- app/models/authentication_token.rb | 1 + .../20220721131946_create_authentication_tokens.rb | 2 +- db/schema.rb | 2 +- spec/features/authentication_spec.rb | 13 +++++++------ 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/app/models/authentication_token.rb b/app/models/authentication_token.rb index b1bda282..9de51c21 100644 --- a/app/models/authentication_token.rb +++ b/app/models/authentication_token.rb @@ -4,6 +4,7 @@ require 'securerandom' class AuthenticationToken < ApplicationRecord include Creation + def self.generate!(user) create!( shared_secret: SecureRandom.hex(32), diff --git a/db/migrate/20220721131946_create_authentication_tokens.rb b/db/migrate/20220721131946_create_authentication_tokens.rb index 6cf1208d..a70791f5 100644 --- a/db/migrate/20220721131946_create_authentication_tokens.rb +++ b/db/migrate/20220721131946_create_authentication_tokens.rb @@ -5,7 +5,7 @@ class CreateAuthenticationTokens < ActiveRecord::Migration[6.1] create_table :authentication_tokens, id: :uuid do |t| t.string :shared_secret, null: false, index: {unique: true} t.references :user, polymorphic: true, null: false - t.date :expire_at, null: false + t.datetime :expire_at, null: false t.timestamps end end diff --git a/db/schema.rb b/db/schema.rb index 4a9ca522..f0cba53b 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -34,7 +34,7 @@ ActiveRecord::Schema.define(version: 2022_07_21_131946) do t.string "shared_secret", null: false t.string "user_type", null: false t.bigint "user_id", null: false - t.date "expire_at", null: false + t.datetime "expire_at", null: false t.datetime "created_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false t.index ["shared_secret"], name: "index_authentication_tokens_on_shared_secret", unique: true diff --git a/spec/features/authentication_spec.rb b/spec/features/authentication_spec.rb index 8e3fa21c..998d83fb 100644 --- a/spec/features/authentication_spec.rb +++ b/spec/features/authentication_spec.rb @@ -35,12 +35,13 @@ describe 'Authentication' do context 'with no authentication token' do let(:request_for_comment) { create(:rfc_with_comment, user: user) } + let(:rfc_path) { request_for_comment_url(request_for_comment) } it 'denies access to the request for comment' do - mail.deliver_now - visit(rfc_link) + visit(rfc_path) + expect(page).not_to have_current_path(rfc_path) expect(page).not_to have_content(request_for_comment.exercise.title) - expect(response).to redirect_to(root_path) + expect(page).to have_current_path(root_path) expect(page).to have_content(I18n.t('application.not_authorized')) end end @@ -60,8 +61,7 @@ describe 'Authentication' do it 'allows access to the request for comment' do mail.deliver_now visit(rfc_link) - expect(current_url).to be(rfc_link) - expect(response).to have_http_status :ok + expect(page).to have_current_path(rfc_link) expect(page).to have_content(request_for_comment.exercise.title) end end @@ -72,8 +72,9 @@ describe 'Authentication' do it 'denies access to the request for comment' do mail.deliver_now visit(rfc_link) + expect(page).not_to have_current_path(rfc_link) expect(page).not_to have_content(request_for_comment.exercise.title) - expect(response).to redirect_to(root_path) + expect(page).to have_current_path(root_path) expect(page).to have_content(I18n.t('application.not_authorized')) end end