-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7dc1005
commit 700236c
Showing
7 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module ReadOnlyMode | ||
extend ActiveSupport::Concern | ||
|
||
included do | ||
rescue_from ReadOnlyModeError do | ||
stream_flash_notice \ | ||
"The app is in read only mode for maintenance. Try again in a few minutes." | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class Api::ReadOnlyModeError < Api::Error | ||
def initialize( | ||
title: "Read Only Mode", | ||
detail: "The app is in read only mode for maintenance. Try again in a few minutes.", | ||
status: :service_unavailable, | ||
type: :not_found_error, | ||
backtrace: nil | ||
) | ||
super | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
class ReadOnlyModeError < StandardError | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
module ReadOnly | ||
def readonly? | ||
if ENV["READ_ONLY_MODE"] | ||
true | ||
else | ||
super | ||
end | ||
end | ||
|
||
def _raise_readonly_record_error | ||
if ENV["READ_ONLY_MODE"] | ||
raise ReadOnlyModeError | ||
else | ||
super | ||
end | ||
end | ||
end | ||
|
||
ActiveRecord::Base.prepend ReadOnly |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
require "application_system_test_case" | ||
|
||
class ReadOnlyModeTest < ApplicationSystemTestCase | ||
setup do | ||
ENV["READ_ONLY_MODE"] = "true" | ||
end | ||
|
||
teardown do | ||
ENV.delete "READ_ONLY_MODE" | ||
end | ||
|
||
test "signing in" do | ||
visit sign_in_path | ||
assert_no_text(/read only/i) | ||
|
||
fill_in :email_address, with: users(:matt).email_address | ||
click_on "Send Sign In Link" | ||
|
||
assert_text(/read only/i) | ||
assert_not User::Authentication.exists? user: users(:matt) | ||
end | ||
end |