2017-08-17 22:00:37 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Admin::ApplicationsController do
|
|
|
|
let(:admin) { create(:admin) }
|
|
|
|
let(:application) { create(:oauth_application, owner_id: nil, owner_type: nil) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in(admin)
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'GET #new' do
|
|
|
|
it 'renders the application form' do
|
|
|
|
get :new
|
|
|
|
|
|
|
|
expect(response).to render_template :new
|
|
|
|
expect(assigns[:scopes]).to be_kind_of(Doorkeeper::OAuth::Scopes)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'GET #edit' do
|
|
|
|
it 'renders the application form' do
|
2019-02-13 22:33:31 +05:30
|
|
|
get :edit, params: { id: application.id }
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
expect(response).to render_template :edit
|
|
|
|
expect(assigns[:scopes]).to be_kind_of(Doorkeeper::OAuth::Scopes)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'POST #create' do
|
|
|
|
it 'creates the application' do
|
2017-09-10 17:25:29 +05:30
|
|
|
create_params = attributes_for(:application, trusted: true)
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
expect do
|
2019-02-13 22:33:31 +05:30
|
|
|
post :create, params: { doorkeeper_application: create_params }
|
2017-08-17 22:00:37 +05:30
|
|
|
end.to change { Doorkeeper::Application.count }.by(1)
|
|
|
|
|
|
|
|
application = Doorkeeper::Application.last
|
|
|
|
|
|
|
|
expect(response).to redirect_to(admin_application_path(application))
|
2017-09-10 17:25:29 +05:30
|
|
|
expect(application).to have_attributes(create_params.except(:uid, :owner_type))
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'renders the application form on errors' do
|
|
|
|
expect do
|
2019-02-13 22:33:31 +05:30
|
|
|
post :create, params: { doorkeeper_application: attributes_for(:application).merge(redirect_uri: nil) }
|
2017-08-17 22:00:37 +05:30
|
|
|
end.not_to change { Doorkeeper::Application.count }
|
|
|
|
|
|
|
|
expect(response).to render_template :new
|
|
|
|
expect(assigns[:scopes]).to be_kind_of(Doorkeeper::OAuth::Scopes)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'PATCH #update' do
|
|
|
|
it 'updates the application' do
|
2019-02-13 22:33:31 +05:30
|
|
|
patch :update, params: { id: application.id, doorkeeper_application: { redirect_uri: 'http://example.com/', trusted: true } }
|
2017-09-10 17:25:29 +05:30
|
|
|
|
|
|
|
application.reload
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
expect(response).to redirect_to(admin_application_path(application))
|
2017-09-10 17:25:29 +05:30
|
|
|
expect(application).to have_attributes(redirect_uri: 'http://example.com/', trusted: true)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'renders the application form on errors' do
|
2019-02-13 22:33:31 +05:30
|
|
|
patch :update, params: { id: application.id, doorkeeper_application: { redirect_uri: nil } }
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
expect(response).to render_template :edit
|
|
|
|
expect(assigns[:scopes]).to be_kind_of(Doorkeeper::OAuth::Scopes)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|