Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Put message behind feature flipper and rake task #3688

Merged
merged 1 commit into from
Aug 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,3 +221,15 @@ MY_URL=the url you copied above
curl $MY_URL -o config/hosts.dat
```
1. Optionally, alphabetize the file using your local editor

## Announcement messages

1. To see the current announcement message and feature status, run
```bash
bundle exec rake announcement:show
```
1. To set a new announcement message, run
```bash
bundle exec rake announcement:set\["My message in a string. Must escape quotes."\]
```
1. To toggle announcements on and off, sign in and go to /features and toggle message display.
3 changes: 3 additions & 0 deletions app/models/announcement.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# frozen_string_literal: true
class Announcement < ApplicationRecord
end
8 changes: 5 additions & 3 deletions app/views/shared/_announcement.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<%# to remove messages altogether, set this to empty string %>
<% message = '' %>
<%# To remove messages altogether, go to /features and turn off Message display %>
<%# To set a new message, run the rake task `bundle exec rake announcement:set\["This is my new text."\]` %>
<%# To see the current message, run `bundle exec rake announcement:show` %>
<% message = Announcement&.first&.text %>
<% if Orangelight.read_only_mode %>
<div class="col-12 alert alert-warning announcement">
<div class="container">
Expand All @@ -8,7 +10,7 @@
</p>
</div>
</div>
<% elsif message.present? %>
<% elsif Flipflop.message_display? %>
<div class="col-12 alert alert-warning announcement">
<div class="container">
<p>
Expand Down
4 changes: 4 additions & 0 deletions config/features.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
default: true,
description: "When on / true, uses the old locator service for Firestone. When off / false uses the new Stackmap service for Firestone."

feature :message_display,
default: false,
description: "When on / true, displays the message set by the announcement rake task."

group :blacklight_8 do
feature :json_query_dsl,
description: "When on / true, use the JSON query DSL for search fields in the advanced search. When off / false, use query params"
Expand Down
9 changes: 9 additions & 0 deletions db/migrate/20230817164417_create_announcements.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class CreateAnnouncements < ActiveRecord::Migration[6.1]
def change
create_table :announcements do |t|
t.string :text

t.timestamps
end
end
end
8 changes: 7 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2023_04_19_231330) do
ActiveRecord::Schema.define(version: 2023_08_17_164417) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand Down Expand Up @@ -54,6 +54,12 @@
t.index ["sort"], name: "index_alma_orangelight_subjects_on_sort"
end

create_table "announcements", force: :cascade do |t|
t.string "text"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
end

create_table "bookmarks", id: :serial, force: :cascade do |t|
t.integer "user_id", null: false
t.string "user_type"
Expand Down
20 changes: 20 additions & 0 deletions lib/tasks/announcement.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# frozen_string_literal: true
namespace :announcement do
desc 'Set text for announcement'
task :set, [:text] => [:environment] do |_task, args|
if Announcement.count.zero?
Announcement.create!(text: args.text)
else
announcement = Announcement.first
announcement.text = args.text
announcement.save!
end
Rake::Task["announcement:show"].invoke
end

desc 'Show current text of announcement'
task show: :environment do
puts "The currently set text is: #{Announcement.first.text}"
puts "The text will be displayed in the Catalog: #{Flipflop.message_display?}"
end
end
7 changes: 7 additions & 0 deletions spec/factories/announcements.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

FactoryBot.define do
factory :announcement do
text { 'Text announcement text' }
end
end
9 changes: 9 additions & 0 deletions spec/models/announcement_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true
require 'rails_helper'

RSpec.describe Announcement, type: :model do
it 'can be instantiated' do
described_class.create(text: "My announcement text")
expect(described_class.last.text).to eq("My announcement text")
end
end
24 changes: 24 additions & 0 deletions spec/views/shared/_announcement.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
require 'rails_helper'

RSpec.describe 'shared/_announcement' do
let!(:announcement) { FactoryBot.create(:announcement) }

it 'renders an announcement' do
render
expect(rendered).to match(//)
Expand All @@ -16,4 +18,26 @@
expect(rendered).to match(/test message/)
end
end

context 'with a non-read-only announcement' do
before do
allow(Flipflop).to receive(:message_display?).and_return(true)
allow(Orangelight).to receive(:read_only_mode).and_return(false)
end

it 'displays the message' do
render
expect(rendered).to match(/#{announcement.text}/)
end
end
context 'without a non-read-only announcement' do
before do
allow(Flipflop).to receive(:message_display?).and_return(false)
end

it 'renders an empty announcement partial' do
render
expect(rendered).to match(//)
end
end
end
Loading