| 
									
										
										
										
											2016-02-29 19:42:08 +01:00
										 |  |  | require 'rails_helper' | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | RSpec.describe StreamEntriesController, type: :controller do | 
					
						
							| 
									
										
										
										
											2016-09-08 00:33:07 +02:00
										 |  |  |   render_views | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-23 22:04:23 +09:00
										 |  |  |   shared_examples 'before_action' do |route| | 
					
						
							| 
									
										
										
										
											2018-09-13 18:53:09 -04:00
										 |  |  |     context 'when account is not suspended and stream_entry is available' do | 
					
						
							| 
									
										
										
										
											2017-05-23 22:04:23 +09:00
										 |  |  |       it 'assigns instance variables' do | 
					
						
							|  |  |  |         status = Fabricate(:status) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         get route, params: { account_username: status.account.username, id: status.stream_entry.id } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         expect(assigns(:account)).to eq status.account | 
					
						
							|  |  |  |         expect(assigns(:stream_entry)).to eq status.stream_entry | 
					
						
							|  |  |  |         expect(assigns(:type)).to eq 'status' | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it 'sets Link headers' do | 
					
						
							|  |  |  |         alice = Fabricate(:account, username: 'alice') | 
					
						
							|  |  |  |         status = Fabricate(:status, account: alice) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         get route, params: { account_username: alice.username, id: status.stream_entry.id } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-13 00:45:04 +02:00
										 |  |  |         expect(response.headers['Link'].to_s).to eq "<http://test.host/users/alice/updates/#{status.stream_entry.id}.atom>; rel=\"alternate\"; type=\"application/atom+xml\", <https://cb6e6126.ngrok.io/users/alice/statuses/#{status.id}>; rel=\"alternate\"; type=\"application/activity+json\"" | 
					
						
							| 
									
										
										
										
											2017-05-23 22:04:23 +09:00
										 |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     context 'when account is suspended' do | 
					
						
							|  |  |  |       it 'returns http status 410' do | 
					
						
							|  |  |  |         account = Fabricate(:account, suspended: true) | 
					
						
							|  |  |  |         status = Fabricate(:status, account: account) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         get route, params: { account_username: account.username, id: status.stream_entry.id } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         expect(response).to have_http_status(410) | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     context 'when activity is nil' do | 
					
						
							|  |  |  |       it 'raises ActiveRecord::RecordNotFound' do | 
					
						
							|  |  |  |         account = Fabricate(:account) | 
					
						
							|  |  |  |         stream_entry = Fabricate.build(:stream_entry, account: account, activity: nil, activity_type: 'Status') | 
					
						
							|  |  |  |         stream_entry.save!(validate: false) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         get route, params: { account_username: account.username, id: stream_entry.id } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         expect(response).to have_http_status(404) | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     context 'when it is hidden and it is not permitted' do | 
					
						
							|  |  |  |       it 'raises ActiveRecord::RecordNotFound' do | 
					
						
							|  |  |  |         status = Fabricate(:status) | 
					
						
							|  |  |  |         user = Fabricate(:user) | 
					
						
							|  |  |  |         status.account.block!(user.account) | 
					
						
							|  |  |  |         status.stream_entry.update!(hidden: true) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         sign_in(user) | 
					
						
							|  |  |  |         get route, params: { account_username: status.account.username, id: status.stream_entry.id } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         expect(response).to have_http_status(404) | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2016-02-29 19:42:08 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |   describe 'GET #show' do | 
					
						
							| 
									
										
										
										
											2017-05-23 22:04:23 +09:00
										 |  |  |     include_examples 'before_action', :show | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-16 17:04:31 +09:00
										 |  |  |     it 'redirects to status page' do | 
					
						
							|  |  |  |       status = Fabricate(:status) | 
					
						
							| 
									
										
										
										
											2017-05-23 22:04:23 +09:00
										 |  |  | 
 | 
					
						
							|  |  |  |       get :show, params: { account_username: status.account.username, id: status.stream_entry.id } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-16 17:04:31 +09:00
										 |  |  |       expect(response).to redirect_to(short_account_status_url(status.account, status)) | 
					
						
							| 
									
										
										
										
											2016-02-29 19:42:08 +01:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-19 14:02:30 +01:00
										 |  |  |     it 'returns http success with Atom' do | 
					
						
							| 
									
										
										
										
											2017-05-23 22:04:23 +09:00
										 |  |  |       status = Fabricate(:status) | 
					
						
							|  |  |  |       get :show, params: { account_username: status.account.username, id: status.stream_entry.id }, format: 'atom' | 
					
						
							| 
									
										
										
										
											2018-04-22 04:35:07 +09:00
										 |  |  |       expect(response).to have_http_status(200) | 
					
						
							| 
									
										
										
										
											2016-02-29 19:42:08 +01:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2017-04-12 10:12:42 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |   describe 'GET #embed' do | 
					
						
							| 
									
										
										
										
											2017-05-23 22:04:23 +09:00
										 |  |  |     include_examples 'before_action', :embed | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-30 10:23:43 +02:00
										 |  |  |     it 'redirects to new embed page' do | 
					
						
							| 
									
										
										
										
											2017-05-23 22:04:23 +09:00
										 |  |  |       status = Fabricate(:status) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       get :embed, params: { account_username: status.account.username, id: status.stream_entry.id } | 
					
						
							| 
									
										
										
										
											2017-04-12 10:12:42 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-30 10:23:43 +02:00
										 |  |  |       expect(response).to redirect_to(embed_short_account_status_url(status.account, status)) | 
					
						
							| 
									
										
										
										
											2017-04-12 10:12:42 -04:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2016-02-29 19:42:08 +01:00
										 |  |  | end |