Reformat spec/requests/maintenance_spec.rb
This commit is contained in:
		
							parent
							
								
									9d2ee08958
								
							
						
					
					
						commit
						16933dde08
					
				
					 1 changed files with 99 additions and 77 deletions
				
			
		|  | @ -4,96 +4,118 @@ | ||||||
| # Full license explanation at https://github.com/houdiniproject/houdini/blob/master/LICENSE | # Full license explanation at https://github.com/houdiniproject/houdini/blob/master/LICENSE | ||||||
| require 'rails_helper' | require 'rails_helper' | ||||||
| require 'controllers/support/shared_user_context' | require 'controllers/support/shared_user_context' | ||||||
| 
 | # rubocop:disable RSpec/InstanceVariable | ||||||
|  | # rubocop:disable RSpec/DescribeClass | ||||||
| describe 'Maintenance Mode' do | describe 'Maintenance Mode' do | ||||||
|   page = 'http://commet' | 	page = 'http://commet' | ||||||
|   token = 'thoathioa' | 	token = 'thoathioa' | ||||||
|   include_context :shared_user_context | 	include_context :shared_user_context | ||||||
| 
 | 
 | ||||||
|   describe OnboardController, type: :controller do | 	describe OnboardController, type: :controller do | ||||||
|     describe '(Onboard is just a basic example controller)' | 		describe '(Onboard is just a basic example controller)' | ||||||
|     it 'not in maintenance mode' do | 		it 'not in maintenance mode' do | ||||||
|       get :index | 			get :index | ||||||
|       assert_response 200 | 			assert_response 200 | ||||||
|     end | 		end | ||||||
| 
 | 
 | ||||||
|     describe 'in maintenance' do | 		describe 'in maintenance' do | ||||||
|       before(:each) do | 			before do | ||||||
|         Houdini.maintenance = Houdini::Maintenance.new(active:true, token: token, page: page) | 				Houdini.maintenance = Houdini::Maintenance.new(active: true, token: token, page: page) | ||||||
|       end | 			end | ||||||
| 
 | 
 | ||||||
|       it 'redirects for onboard' do | 			it 'redirects for onboard' do | ||||||
|         get :index | 				get :index | ||||||
|         assert_redirected_to page | 				assert_redirected_to page | ||||||
|       end | 			end | ||||||
| 
 | 
 | ||||||
|       it 'allows access to non-sign_in pages if youre logged in' do | 			it 'allows access to non-sign_in pages if youre logged in' do | ||||||
|         sign_in user_as_np_associate | 				sign_in user_as_np_associate | ||||||
|         get :index | 				get :index | ||||||
|         assert_response 200 | 				assert_response 200 | ||||||
|       end | 			end | ||||||
|     end | 		end | ||||||
|   end | 	end | ||||||
| 
 | 
 | ||||||
|   describe Users::SessionsController, type: :controller do | 	describe Users::SessionsController, type: :controller do | ||||||
|     after(:each) do | 		after do | ||||||
|       Houdini.maintenance.active = false | 			Houdini.maintenance.active = false | ||||||
|     end | 		end | ||||||
|     describe 'in maintenance' do |  | ||||||
|       include_context :shared_user_context |  | ||||||
| 
 | 
 | ||||||
|       before(:each) do | 		describe 'in maintenance' do | ||||||
|         @request.env['devise.mapping'] = Devise.mappings[:user] | 			include_context :shared_user_context | ||||||
|       end |  | ||||||
| 
 | 
 | ||||||
|       describe 'in maintenance' do | 			before do | ||||||
|         before(:each) do | 				@request.env['devise.mapping'] = Devise.mappings[:user] | ||||||
|           Houdini.maintenance = Houdini::Maintenance.new(active:true, token: token, page: page) | 			end | ||||||
|         end |  | ||||||
| 
 | 
 | ||||||
|         it 'redirects sign_in if the token is wrong' do | 			describe 'in maintenance' do | ||||||
|           get(:new, params: { maintenance_token: "#{token}3" }) | 				before do | ||||||
|           expect(response.code).to eq '302' | 					Houdini.maintenance = Houdini::Maintenance.new(active: true, token: token, page: page) | ||||||
|           expect(response.location).to eq page | 				end | ||||||
|         end |  | ||||||
| 
 | 
 | ||||||
|         it 'redirects for login' do | 				describe 'redirects sign_in if the token is wrong' do | ||||||
|           get(:new) | 					subject do | ||||||
|           expect(response.code).to eq '302' | 						get(:new, params: { maintenance_token: "#{token}3" }) | ||||||
|           expect(response.location).to eq page | 						response | ||||||
|         end | 					end | ||||||
| 
 | 
 | ||||||
|         it 'redirects sign_in if the token is passed in wrong param' do | 					it { is_expected.to have_attributes(code: '302', location: page) } | ||||||
|           get(:new, params: { maintnancerwrwer_token: token.to_s }) | 				end | ||||||
|           expect(response.code).to eq '302' |  | ||||||
|           expect(response.location).to eq page |  | ||||||
|         end |  | ||||||
| 
 | 
 | ||||||
|         it 'allows sign_in if the token is passed' do | 				describe 'redirects to sign_in' do | ||||||
|           get(:new, params: { maintenance_token: token.to_s }) | 					subject do | ||||||
|           expect(response.code).to eq '200' | 						get(:new) | ||||||
|         end | 						response | ||||||
|  | 					end | ||||||
| 
 | 
 | ||||||
|         it 'allows sign_in.json' do | 					it { is_expected.to have_attributes(code: '302', location: page) } | ||||||
|           get(:new, params: { maintenance_token: token.to_s, format: 'json' }) | 				end | ||||||
|           expect(response.code).to eq '200' |  | ||||||
|         end |  | ||||||
|       end |  | ||||||
|     end |  | ||||||
| 
 | 
 | ||||||
|     describe 'in maintenance without maintenance_token set' do | 				describe 'redirects to sign_in if token passed on wrong param' do | ||||||
|       before(:each) do | 					subject do | ||||||
|         @request.env['devise.mapping'] = Devise.mappings[:user] | 						get(:new, params: { maintnancerwrwer_token: token.to_s }) | ||||||
|       end | 						response | ||||||
|       before(:each) do | 					end | ||||||
|         Houdini.maintenance = Houdini::Maintenance.new(active:true, token: nil, page: page) |  | ||||||
|       end |  | ||||||
| 
 | 
 | ||||||
|       it 'redirects sign_in if the token is nil' do | 					it { is_expected.to have_attributes(code: '302', location: page) } | ||||||
|         get(:new) | 				end | ||||||
|         expect(response.code).to eq '302' | 
 | ||||||
|         expect(response.location).to eq page | 				describe 'allows sign_in if the token is passed' do | ||||||
|       end | 					subject do | ||||||
|     end | 						get(:new, params: { maintenance_token: token.to_s }) | ||||||
|   end | 						response | ||||||
|  | 					end | ||||||
|  | 
 | ||||||
|  | 					it { is_expected.to have_attributes(code: '200') } | ||||||
|  | 				end | ||||||
|  | 
 | ||||||
|  | 				describe 'allows sign_in.json if the token is passed' do | ||||||
|  | 					subject do | ||||||
|  | 						get(:new, params: { maintenance_token: token.to_s, format: 'json' }) | ||||||
|  | 						response | ||||||
|  | 					end | ||||||
|  | 
 | ||||||
|  | 					it { is_expected.to have_attributes(code: '200') } | ||||||
|  | 				end | ||||||
|  | 			end | ||||||
|  | 		end | ||||||
|  | 
 | ||||||
|  | 		describe 'in maintenance without maintenance_token set' do | ||||||
|  | 			before do | ||||||
|  | 				@request.env['devise.mapping'] = Devise.mappings[:user] | ||||||
|  | 				Houdini.maintenance = Houdini::Maintenance.new(active: true, token: nil, page: page) | ||||||
|  | 			end | ||||||
|  | 
 | ||||||
|  | 			describe 'redirects sign_in if the token is nil' do | ||||||
|  | 				subject do | ||||||
|  | 					get(:new) | ||||||
|  | 					response | ||||||
|  | 				end | ||||||
|  | 
 | ||||||
|  | 				it { is_expected.to have_attributes(code: '302', location: page) } | ||||||
|  | 			end | ||||||
|  | 		end | ||||||
|  | 	end | ||||||
| end | end | ||||||
|  | 
 | ||||||
|  | # rubocop:enable all | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 Eric Schultz
						Eric Schultz