applications_spec.rb 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe 'Settings applications page' do
  4. let!(:application) { Fabricate :application, owner: user }
  5. let(:user) { Fabricate :user }
  6. before { sign_in user }
  7. describe 'Viewing the list of applications' do
  8. it 'sees the applications' do
  9. visit settings_applications_path
  10. expect(page)
  11. .to have_content(application.name)
  12. .and have_private_cache_control
  13. end
  14. end
  15. describe 'Viewing a single application' do
  16. it 'shows a page with application details' do
  17. visit settings_application_path(application)
  18. expect(page)
  19. .to have_content(application.name)
  20. end
  21. end
  22. describe 'Creating a new application' do
  23. it 'accepts form input to make an application' do
  24. visit new_settings_application_path
  25. fill_in_form
  26. expect { submit_form }
  27. .to change(Doorkeeper::Application, :count).by(1)
  28. expect(page)
  29. .to have_content(I18n.t('doorkeeper.applications.index.title'))
  30. .and have_content('My new app')
  31. end
  32. it 'does not save with invalid form values' do
  33. visit new_settings_application_path
  34. expect { submit_form }
  35. .to not_change(Doorkeeper::Application, :count)
  36. expect(page)
  37. .to have_content("can't be blank")
  38. end
  39. def fill_in_form
  40. fill_in form_app_name_label,
  41. with: 'My new app'
  42. fill_in I18n.t('activerecord.attributes.doorkeeper/application.website'),
  43. with: 'http://google.com'
  44. fill_in I18n.t('activerecord.attributes.doorkeeper/application.redirect_uri'),
  45. with: 'urn:ietf:wg:oauth:2.0:oob'
  46. check 'read', id: :doorkeeper_application_scopes_read
  47. check 'write', id: :doorkeeper_application_scopes_write
  48. check 'follow', id: :doorkeeper_application_scopes_follow
  49. end
  50. def submit_form
  51. click_on I18n.t('doorkeeper.applications.buttons.submit')
  52. end
  53. end
  54. describe 'Updating an application' do
  55. it 'successfully updates with valid values' do
  56. visit settings_application_path(application)
  57. fill_in form_app_name_label,
  58. with: 'My new app name with a new value'
  59. submit_form
  60. expect(page)
  61. .to have_content('My new app name with a new value')
  62. end
  63. it 'does not update with wrong values' do
  64. visit settings_application_path(application)
  65. fill_in form_app_name_label,
  66. with: ''
  67. submit_form
  68. expect(page)
  69. .to have_content("can't be blank")
  70. end
  71. def submit_form
  72. click_on I18n.t('generic.save_changes')
  73. end
  74. end
  75. describe 'Destroying an application' do
  76. let(:redis_pipeline_stub) { instance_double(Redis::Namespace, publish: nil) }
  77. let!(:access_token) { Fabricate(:accessible_access_token, application: application) }
  78. before { stub_redis_pipeline }
  79. it 'destroys the record and tells the broader universe about that' do
  80. visit settings_applications_path
  81. expect { destroy_application }
  82. .to change(Doorkeeper::Application, :count).by(-1)
  83. expect(page)
  84. .to have_no_content(application.name)
  85. expect(redis_pipeline_stub)
  86. .to have_received(:publish).with("timeline:access_token:#{access_token.id}", '{"event":"kill"}')
  87. end
  88. def destroy_application
  89. click_on I18n.t('doorkeeper.applications.index.delete')
  90. end
  91. def stub_redis_pipeline
  92. allow(redis)
  93. .to receive(:pipelined)
  94. .and_yield(redis_pipeline_stub)
  95. end
  96. end
  97. describe 'Regenerating an app token' do
  98. it 'updates the app token' do
  99. visit settings_application_path(application)
  100. expect { regenerate_token }
  101. .to(change { user.token_for_app(application) })
  102. expect(page)
  103. .to have_content(I18n.t('applications.token_regenerated'))
  104. end
  105. def regenerate_token
  106. click_on I18n.t('applications.regenerate_token')
  107. end
  108. end
  109. def form_app_name_label
  110. I18n.t('activerecord.attributes.doorkeeper/application.name')
  111. end
  112. end