File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -2,11 +2,7 @@ class ApplicationController < ActionController::Base
22 protect_from_forgery with : :exception
33
44 helper_method :current_user
5-
65 before_action :require_login
7- if ENV . has_key? 'ALLOW_ANONYMOUS_TO_READ'
8- skip_before_action :require_login , only : [ :index , :show ]
9- end
106 before_action :set_sidebar_databases , :set_search_result , only : %w( index show new edit )
117
128 private
@@ -17,6 +13,7 @@ def current_user
1713
1814 def require_login
1915 return if current_user
16+ return if Rails . application . config . allow_anonymous_to_read && [ "index" , "show" ] . include? ( params [ :action ] )
2017 redirect_to google_oauth2_path ( state : url_for ( params . merge ( only_path : true ) ) )
2118 end
2219
Original file line number Diff line number Diff line change @@ -32,5 +32,6 @@ class Application < Rails::Application
3232 # Do not swallow errors in after_commit/after_rollback callbacks.
3333 config . active_record . raise_in_transactional_callbacks = true
3434 config . autoload_paths << "#{ Rails . root } /lib/autoload"
35+ config . allow_anonymous_to_read = ENV . has_key? 'ALLOW_ANONYMOUS_TO_READ'
3536 end
3637end
Original file line number Diff line number Diff line change 1515 end
1616 end
1717end
18+
19+ # without allow anonymous login
20+ describe :top , type : :request do
21+ let ( :data_source ) { FactoryGirl . create ( :data_source ) }
22+ describe "#show" do
23+ it "shows top page" do
24+ get root_path
25+ expect ( response . location ) . to match ( 'http://www.example.com/auth/google_oauth2.*?' )
26+ end
27+ end
28+ end
29+
30+ # allow anonymous login
31+ describe :top , type : :request do
32+ let ( :data_source ) { FactoryGirl . create ( :data_source ) }
33+ before do
34+ Rails . application . config . allow_anonymous_to_read = true
35+ end
36+ describe "#show" do
37+ it "shows top page" do
38+ get root_path
39+ expect ( page ) . to have_content ( "DatabaseMEMO" )
40+ end
41+ end
42+ after do
43+ Rails . application . config . allow_anonymous_to_read = false
44+ end
45+ end
You can’t perform that action at this time.
0 commit comments