diff options
Diffstat (limited to 'spec/controllers')
-rw-r--r-- | spec/controllers/about_controller_spec.rb | 11 | ||||
-rw-r--r-- | spec/controllers/admin/reports_controller_spec.rb | 14 | ||||
-rw-r--r-- | spec/controllers/admin/settings_controller_spec.rb | 14 | ||||
-rw-r--r-- | spec/controllers/api/v1/accounts_controller_spec.rb | 39 | ||||
-rw-r--r-- | spec/controllers/api/v1/notifications_controller_spec.rb | 62 | ||||
-rw-r--r-- | spec/controllers/auth/registrations_controller_spec.rb | 2 | ||||
-rw-r--r-- | spec/controllers/xrd_controller_spec.rb | 2 |
7 files changed, 138 insertions, 6 deletions
diff --git a/spec/controllers/about_controller_spec.rb b/spec/controllers/about_controller_spec.rb index 4282649e1..f49de9622 100644 --- a/spec/controllers/about_controller_spec.rb +++ b/spec/controllers/about_controller_spec.rb @@ -3,9 +3,16 @@ require 'rails_helper' RSpec.describe AboutController, type: :controller do render_views - describe 'GET #index' do + describe 'GET #show' do it 'returns http success' do - get :index + get :show + expect(response).to have_http_status(:success) + end + end + + describe 'GET #more' do + it 'returns http success' do + get :more expect(response).to have_http_status(:success) end end diff --git a/spec/controllers/admin/reports_controller_spec.rb b/spec/controllers/admin/reports_controller_spec.rb new file mode 100644 index 000000000..622ea87c1 --- /dev/null +++ b/spec/controllers/admin/reports_controller_spec.rb @@ -0,0 +1,14 @@ +require 'rails_helper' + +RSpec.describe Admin::ReportsController, type: :controller do + describe 'GET #index' do + before do + sign_in Fabricate(:user, admin: true), scope: :user + end + + it 'returns http success' do + get :index + expect(response).to have_http_status(:success) + end + end +end diff --git a/spec/controllers/admin/settings_controller_spec.rb b/spec/controllers/admin/settings_controller_spec.rb new file mode 100644 index 000000000..c126b645b --- /dev/null +++ b/spec/controllers/admin/settings_controller_spec.rb @@ -0,0 +1,14 @@ +require 'rails_helper' + +RSpec.describe Admin::SettingsController, type: :controller do + describe 'GET #index' do + before do + sign_in Fabricate(:user, admin: true), scope: :user + end + + it 'returns http success' do + get :index + expect(response).to have_http_status(:success) + end + end +end diff --git a/spec/controllers/api/v1/accounts_controller_spec.rb b/spec/controllers/api/v1/accounts_controller_spec.rb index 5d36b0159..ed49779b4 100644 --- a/spec/controllers/api/v1/accounts_controller_spec.rb +++ b/spec/controllers/api/v1/accounts_controller_spec.rb @@ -24,6 +24,45 @@ RSpec.describe Api::V1::AccountsController, type: :controller do end end + describe 'PATCH #update_credentials' do + describe 'with valid data' do + before do + avatar = File.read(Rails.root.join('app', 'assets', 'images', 'logo.png')) + header = File.read(Rails.root.join('app', 'assets', 'images', 'mastodon-getting-started.png')) + + patch :update_credentials, params: { + display_name: "Alice Isn't Dead", + note: "Hi!\n\nToot toot!", + avatar: "data:image/png;base64,#{Base64.encode64(avatar)}", + header: "data:image/png;base64,#{Base64.encode64(header)}", + } + end + + it 'returns http success' do + expect(response).to have_http_status(:success) + end + + it 'updates account info' do + user.account.reload + + expect(user.account.display_name).to eq("Alice Isn't Dead") + expect(user.account.note).to eq("Hi!\n\nToot toot!") + expect(user.account.avatar).to exist + expect(user.account.header).to exist + end + end + + describe 'with invalid data' do + before do + patch :update_credentials, params: { note: 'This is too long. ' * 10 } + end + + it 'returns http unprocessable entity' do + expect(response).to have_http_status(:unprocessable_entity) + end + end + end + describe 'GET #statuses' do it 'returns http success' do get :statuses, params: { id: user.account.id } diff --git a/spec/controllers/api/v1/notifications_controller_spec.rb b/spec/controllers/api/v1/notifications_controller_spec.rb index e5f7eec73..c390d4f01 100644 --- a/spec/controllers/api/v1/notifications_controller_spec.rb +++ b/spec/controllers/api/v1/notifications_controller_spec.rb @@ -5,15 +5,71 @@ RSpec.describe Api::V1::NotificationsController, type: :controller do let(:user) { Fabricate(:user, account: Fabricate(:account, username: 'alice')) } let(:token) { double acceptable?: true, resource_owner_id: user.id } + let(:other) { Fabricate(:user, account: Fabricate(:account, username: 'bob')) } before do allow(controller).to receive(:doorkeeper_token) { token } end describe 'GET #index' do - it 'returns http success' do - get :index - expect(response).to have_http_status(:success) + before do + status = PostStatusService.new.call(user.account, 'Test') + @reblog = ReblogService.new.call(other.account, status) + @mention = PostStatusService.new.call(other.account, 'Hello @alice') + @favourite = FavouriteService.new.call(other.account, status) + @follow = FollowService.new.call(other.account, 'alice') + end + + describe 'with no options' do + before do + get :index + end + + it 'returns http success' do + expect(response).to have_http_status(:success) + end + + it 'includes reblog' do + expect(assigns(:notifications).map(&:activity_id)).to include(@reblog.id) + end + + it 'includes mention' do + expect(assigns(:notifications).map(&:activity_id)).to include(@mention.mentions.first.id) + end + + it 'includes favourite' do + expect(assigns(:notifications).map(&:activity_id)).to include(@favourite.id) + end + + it 'includes follow' do + expect(assigns(:notifications).map(&:activity_id)).to include(@follow.id) + end + end + + describe 'with excluded mentions' do + before do + get :index, params: { exclude_types: ['mention'] } + end + + it 'returns http success' do + expect(response).to have_http_status(:success) + end + + it 'includes reblog' do + expect(assigns(:notifications).map(&:activity_id)).to include(@reblog.id) + end + + it 'excludes mention' do + expect(assigns(:notifications).map(&:activity_id)).to_not include(@mention.mentions.first.id) + end + + it 'includes favourite' do + expect(assigns(:notifications).map(&:activity_id)).to include(@favourite.id) + end + + it 'includes follow' do + expect(assigns(:notifications).map(&:activity_id)).to include(@follow.id) + end end end end diff --git a/spec/controllers/auth/registrations_controller_spec.rb b/spec/controllers/auth/registrations_controller_spec.rb index 27ad6cbde..6b26e6693 100644 --- a/spec/controllers/auth/registrations_controller_spec.rb +++ b/spec/controllers/auth/registrations_controller_spec.rb @@ -5,6 +5,7 @@ RSpec.describe Auth::RegistrationsController, type: :controller do describe 'GET #new' do before do + Setting.open_registrations = true request.env["devise.mapping"] = Devise.mappings[:user] end @@ -16,6 +17,7 @@ RSpec.describe Auth::RegistrationsController, type: :controller do describe 'POST #create' do before do + Setting.open_registrations = true request.env["devise.mapping"] = Devise.mappings[:user] post :create, params: { user: { account_attributes: { username: 'test' }, email: 'test@example.com', password: '12345678', password_confirmation: '12345678' } } end diff --git a/spec/controllers/xrd_controller_spec.rb b/spec/controllers/xrd_controller_spec.rb index e687cf9e0..b56c68f5c 100644 --- a/spec/controllers/xrd_controller_spec.rb +++ b/spec/controllers/xrd_controller_spec.rb @@ -14,7 +14,7 @@ RSpec.describe XrdController, type: :controller do let(:alice) { Fabricate(:account, username: 'alice') } it 'returns http success when account can be found' do - get :webfinger, params: { resource: "acct:#{alice.username}@#{Rails.configuration.x.local_domain}" } + get :webfinger, params: { resource: alice.to_webfinger_s } expect(response).to have_http_status(:success) end |