Skip to content

Commit

Permalink
Convert settings/applications controller spec to system/request spe…
Browse files Browse the repository at this point in the history
  • Loading branch information
mjankowski authored Sep 23, 2024
1 parent aaab6b7 commit 5dfdec6
Show file tree
Hide file tree
Showing 7 changed files with 230 additions and 220 deletions.
36 changes: 0 additions & 36 deletions app/views/settings/applications/_fields.html.haml

This file was deleted.

36 changes: 36 additions & 0 deletions app/views/settings/applications/_form.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
.fields-group
= form.input :name,
label: t('activerecord.attributes.doorkeeper/application.name'),
wrapper: :with_label

.fields-group
= form.input :website,
label: t('activerecord.attributes.doorkeeper/application.website'),
wrapper: :with_label

.fields-group
= form.input :redirect_uri,
label: t('activerecord.attributes.doorkeeper/application.redirect_uri'), hint: t('doorkeeper.applications.help.redirect_uri'),
required: true,
wrapper: :with_block_label

%p.hint= t('doorkeeper.applications.help.native_redirect_uri', native_redirect_uri: content_tag(:code, Doorkeeper.configuration.native_redirect_uri)).html_safe

.field-group
.input.with_block_label
%label= t('activerecord.attributes.doorkeeper/application.scopes')
%span.hint= t('simple_form.hints.defaults.scopes')

- Doorkeeper.configuration.scopes.group_by { |s| s.split(':').first }.each_value do |value|
= form.input :scopes,
as: :check_boxes,
collection_wrapper_tag: 'ul',
collection: value.sort,
hint: false,
include_blank: false,
item_wrapper_tag: 'li',
label_method: ->(scope) { safe_join([content_tag(:samp, scope, class: class_for_scope(scope)), content_tag(:span, t("doorkeeper.scopes.#{scope}"), class: 'hint')]) },
label: false,
required: false,
selected: form.object.scopes.all,
wrapper: :with_block_label
6 changes: 3 additions & 3 deletions app/views/settings/applications/new.html.haml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
- content_for :page_title do
= t('doorkeeper.applications.new.title')

= simple_form_for @application, url: settings_applications_path do |f|
= render 'fields', f: f
= simple_form_for @application, url: settings_applications_path do |form|
= render form

.actions
= f.button :button, t('doorkeeper.applications.buttons.submit'), type: :submit
= form.button :button, t('doorkeeper.applications.buttons.submit'), type: :submit
6 changes: 3 additions & 3 deletions app/views/settings/applications/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@

%hr/

= simple_form_for @application, url: settings_application_path(@application), method: :put do |f|
= render 'fields', f: f
= simple_form_for @application, url: settings_application_path(@application), method: :put do |form|
= render form

.actions
= f.button :button, t('generic.save_changes'), type: :submit
= form.button :button, t('generic.save_changes'), type: :submit
178 changes: 0 additions & 178 deletions spec/controllers/settings/applications_controller_spec.rb

This file was deleted.

44 changes: 44 additions & 0 deletions spec/requests/settings/applications_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe 'Settings / Exports' do
let(:user) { Fabricate :user }

before { sign_in user }

describe 'GET /settings/application/:id' do
context 'when user does not own application' do
let(:application) { Fabricate :application }

it 'returns http missing' do
get settings_application_path(application)

expect(response)
.to have_http_status(404)
end
end
end

describe 'POST /settings/applications' do
subject { post '/settings/applications', params: params }

let(:params) do
{
doorkeeper_application: {
name: 'My New App',
redirect_uri: 'urn:ietf:wg:oauth:2.0:oob',
website: 'http://google.com',
scopes: 'read write follow',
},
}
end

it 'supports passing scope values as string' do
expect { subject }
.to change(Doorkeeper::Application, :count).by(1)
expect(response)
.to redirect_to(settings_applications_path)
end
end
end
Loading

0 comments on commit 5dfdec6

Please sign in to comment.