You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
1.9 KiB

  1. require 'rails_helper'
  2. RSpec.describe HomeController, type: :controller do
  3. render_views
  4. describe 'GET #index' do
  5. context 'when not signed in' do
  6. it 'redirects to about page' do
  7. get :index
  8. expect(response).to redirect_to(about_path)
  9. end
  10. end
  11. context 'when signed in' do
  12. let(:user) { Fabricate(:user) }
  13. subject do
  14. sign_in(user)
  15. get :index
  16. end
  17. it 'assigns @body_classes' do
  18. subject
  19. expect(assigns(:body_classes)).to eq 'app-body'
  20. end
  21. it 'assigns @token' do
  22. app = Doorkeeper::Application.create!(name: 'Web', superapp: true, redirect_uri: Doorkeeper.configuration.native_redirect_uri)
  23. allow(Doorkeeper.configuration).to receive(:access_token_expires_in).and_return(42)
  24. subject
  25. token = Doorkeeper::AccessToken.find_by(token: assigns(:token))
  26. expect(token.application).to eq app
  27. expect(token.resource_owner_id).to eq user.id
  28. expect(token.scopes).to eq Doorkeeper::OAuth::Scopes.from_string('read write follow')
  29. expect(token.expires_in_seconds).to eq 42
  30. expect(token.use_refresh_token?).to eq false
  31. end
  32. it 'assigns @web_settings for {} if not available' do
  33. subject
  34. expect(assigns(:web_settings)).to eq({})
  35. end
  36. it 'assigns @web_settings for Web::Setting if available' do
  37. setting = Fabricate('Web::Setting', data: '{"home":{}}', user: user)
  38. subject
  39. expect(assigns(:web_settings)).to eq setting.data
  40. end
  41. it 'assigns @admin' do
  42. admin = Fabricate(:account)
  43. Setting.site_contact_username = admin.username
  44. subject
  45. expect(assigns(:admin)).to eq admin
  46. end
  47. it 'assigns streaming_api_base_url' do
  48. subject
  49. expect(assigns(:streaming_api_base_url)).to eq 'ws://localhost:4000'
  50. end
  51. end
  52. end
  53. end