Add attachment to TOS record

This commit is contained in:
Maikel Linke
2021-04-15 16:36:20 +10:00
parent c4317c5707
commit 9027f8b604
4 changed files with 26 additions and 5 deletions

View File

@@ -1,6 +1,10 @@
# frozen_string_literal: true
class TermsOfServiceFile < ApplicationRecord
has_attached_file :attachment
validates :attachment, presence: true
# The most recently uploaded file is the current one.
def self.current
order(:id).last

View File

@@ -0,0 +1,11 @@
# frozen_string_literal: true
class AddAttachmentToTermsOfServiceFile < ActiveRecord::Migration[5.0]
def up
add_attachment :terms_of_service_files, :attachment
end
def down
remove_attachment :terms_of_service_files, :attachment
end
end

View File

@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2021_04_15_015550) do
ActiveRecord::Schema.define(version: 2021_04_15_052410) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@@ -1146,8 +1146,12 @@ ActiveRecord::Schema.define(version: 2021_04_15_015550) do
end
create_table "terms_of_service_files", force: :cascade do |t|
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "attachment_file_name"
t.string "attachment_content_type"
t.integer "attachment_file_size"
t.datetime "attachment_updated_at"
end
create_table "variant_overrides", force: :cascade do |t|

View File

@@ -3,6 +3,8 @@
require 'rails_helper'
describe TermsOfServiceFile do
let(:pdf) { File.open(Rails.root.join("public/Terms-of-service.pdf")) }
describe ".current" do
it "returns nil" do
expect(TermsOfServiceFile.current).to be_nil
@@ -10,8 +12,8 @@ describe TermsOfServiceFile do
it "returns the last one" do
existing = [
TermsOfServiceFile.create!,
TermsOfServiceFile.create!,
TermsOfServiceFile.create!(attachment: pdf),
TermsOfServiceFile.create!(attachment: pdf),
]
expect(TermsOfServiceFile.current).to eq existing.last