mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-11 03:40:20 +00:00
Add attachment to TOS record
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
10
db/schema.rb
10
db/schema.rb
@@ -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|
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user