Browse Source

Display next collection resources to users when released

pull/2683/head
Kat 2 years ago
parent
commit
c206dbaf2a
  1. 3
      app/helpers/collection_resources_helper.rb
  2. 5
      app/models/collection_resource.rb
  3. 15
      db/migrate/20241008100119_add_collection_resources_table.rb
  4. 15
      db/schema.rb
  5. 24
      spec/helpers/collection_resources_helper_spec.rb

3
app/helpers/collection_resources_helper.rb

@ -26,6 +26,7 @@ module CollectionResourcesHelper
def displayed_collection_resource_years
return [previous_collection_start_year, current_collection_start_year] if FormHandler.instance.in_edit_crossover_period?
return [current_collection_start_year, next_collection_start_year] if CollectionResource.where(year: next_collection_start_year, mandatory: true, released_to_user: true).any?
[current_collection_start_year]
end
@ -70,6 +71,8 @@ module CollectionResourcesHelper
end
def display_next_year_banner?
return false if CollectionResource.where(year: next_collection_start_year, mandatory: true, released_to_user: true).any?
editable_collection_resource_years.include?(next_collection_start_year)
end

5
app/models/collection_resource.rb

@ -1,8 +1,7 @@
class CollectionResource
include ActiveModel::Model
class CollectionResource < ApplicationRecord
include Rails.application.routes.url_helpers
attr_accessor :resource_type, :display_name, :short_display_name, :year, :log_type, :download_filename, :file
attr_accessor :file
def download_path
download_mandatory_collection_resource_path(log_type:, year:, resource_type:)

15
db/migrate/20241008100119_add_collection_resources_table.rb

@ -0,0 +1,15 @@
class AddCollectionResourcesTable < ActiveRecord::Migration[7.0]
def change
create_table :collection_resources do |t|
t.column :log_type, :string
t.column :resource_type, :string
t.column :display_name, :string
t.column :short_display_name, :string
t.column :year, :integer
t.column :download_filename, :string
t.column :mandatory, :boolean
t.column :released_to_user, :boolean
t.timestamps
end
end
end

15
db/schema.rb

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[7.0].define(version: 2024_10_02_163937) do
ActiveRecord::Schema[7.0].define(version: 2024_10_08_100119) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -50,6 +50,19 @@ ActiveRecord::Schema[7.0].define(version: 2024_10_02_163937) do
t.index ["user_id"], name: "index_bulk_uploads_on_user_id"
end
create_table "collection_resources", force: :cascade do |t|
t.string "log_type"
t.string "resource_type"
t.string "display_name"
t.string "short_display_name"
t.integer "year"
t.string "download_filename"
t.boolean "mandatory"
t.boolean "released_to_user"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "csv_variable_definitions", force: :cascade do |t|
t.string "variable", null: false
t.string "definition", null: false

24
spec/helpers/collection_resources_helper_spec.rb

@ -91,6 +91,18 @@ RSpec.describe CollectionResourcesHelper do
it "returns current year" do
expect(displayed_collection_resource_years).to eq([2024])
end
context "and next year resources were manually released" do
before do
CollectionResource.create!(year: 2025, resource_type: "paper_form", display_name: "lettings log for tenants (2025 to 2026)", download_filename: "file.pdf", mandatory: true, released_to_user: true)
CollectionResource.create!(year: 2025, resource_type: "bulk_upload_template", display_name: "bulk upload template (2025 to 2026)", download_filename: "file.xlsx", mandatory: true, released_to_user: true)
CollectionResource.create!(year: 2025, resource_type: "bulk_upload_specification", display_name: "sales log for tenants (2025 to 2026)", download_filename: "file.xlsx", mandatory: true, released_to_user: true)
end
it "reutrns current and next years" do
expect(displayed_collection_resource_years).to eq([2024, 2025])
end
end
end
end
@ -184,6 +196,18 @@ RSpec.describe CollectionResourcesHelper do
it "returns true" do
expect(display_next_year_banner?).to be_truthy
end
context "and the resources have been manually released" do
before do
CollectionResource.create!(year: 2025, resource_type: "paper_form", display_name: "lettings log for tenants (2025 to 2026)", download_filename: "file.pdf", mandatory: true, released_to_user: true)
CollectionResource.create!(year: 2025, resource_type: "bulk_upload_template", display_name: "bulk upload template (2025 to 2026)", download_filename: "file.xlsx", mandatory: true, released_to_user: true)
CollectionResource.create!(year: 2025, resource_type: "bulk_upload_specification", display_name: "sales log for tenants (2025 to 2026)", download_filename: "file.xlsx", mandatory: true, released_to_user: true)
end
it "returns false" do
expect(display_next_year_banner?).to be_falsey
end
end
end
end

Loading…
Cancel
Save