Add model TermsOfServiceFile

We want to enable instance managers to upload TOS files.

I also added the rails_helper which is a new convention. It can contain
more Rails specific configuration we currently have in the spec_helper.
This commit is contained in:
Maikel Linke
2021-04-15 15:00:57 +10:00
parent fcbe42f080
commit c4317c5707
5 changed files with 48 additions and 1 deletions

View File

@@ -0,0 +1,8 @@
# frozen_string_literal: true
class TermsOfServiceFile < ApplicationRecord
# The most recently uploaded file is the current one.
def self.current
order(:id).last
end
end

View File

@@ -0,0 +1,11 @@
# frozen_string_literal: true
class CreateTermsOfServiceFiles < ActiveRecord::Migration[5.0]
def change
# rubocop:disable Style/SymbolProc
create_table :terms_of_service_files do |t|
t.timestamps
end
# rubocop:enable Style/SymbolProc
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_14_171109) do
ActiveRecord::Schema.define(version: 2021_04_15_015550) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@@ -1145,6 +1145,11 @@ ActiveRecord::Schema.define(version: 2021_04_14_171109) do
t.index ["name"], name: "index_tags_on_name", unique: true
end
create_table "terms_of_service_files", force: :cascade do |t|
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "variant_overrides", force: :cascade do |t|
t.integer "variant_id", null: false
t.integer "hub_id", null: false

View File

@@ -0,0 +1,20 @@
# frozen_string_literal: true
require 'rails_helper'
describe TermsOfServiceFile do
describe ".current" do
it "returns nil" do
expect(TermsOfServiceFile.current).to be_nil
end
it "returns the last one" do
existing = [
TermsOfServiceFile.create!,
TermsOfServiceFile.create!,
]
expect(TermsOfServiceFile.current).to eq existing.last
end
end
end

3
spec/rails_helper.rb Normal file
View File

@@ -0,0 +1,3 @@
# frozen_string_literal: true
require 'spec_helper'