mirror of
https://github.com/mastodon/mastodon.git
synced 2024-12-22 18:45:41 +01:00
Convert admin/rules
spec controller->system
This commit is contained in:
parent
8770905186
commit
9266600aa7
3 changed files with 84 additions and 86 deletions
|
@ -1,85 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Admin::RulesController do
|
||||
render_views
|
||||
|
||||
let(:user) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')) }
|
||||
|
||||
before do
|
||||
sign_in user, scope: :user
|
||||
end
|
||||
|
||||
describe 'GET #index' do
|
||||
it 'returns http success' do
|
||||
get :index
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'GET #edit' do
|
||||
let(:rule) { Fabricate(:rule) }
|
||||
|
||||
it 'returns http success and renders edit' do
|
||||
get :edit, params: { id: rule.id }
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
expect(response).to render_template(:edit)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'POST #create' do
|
||||
context 'with valid data' do
|
||||
it 'creates a new rule and redirects' do
|
||||
expect do
|
||||
post :create, params: { rule: { text: 'The rule text.' } }
|
||||
end.to change(Rule, :count).by(1)
|
||||
|
||||
expect(response).to redirect_to(admin_rules_path)
|
||||
end
|
||||
end
|
||||
|
||||
context 'with invalid data' do
|
||||
it 'does creates a new rule and renders index' do
|
||||
expect do
|
||||
post :create, params: { rule: { text: '' } }
|
||||
end.to_not change(Rule, :count)
|
||||
|
||||
expect(response).to render_template(:index)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'PUT #update' do
|
||||
let(:rule) { Fabricate(:rule, text: 'Original text') }
|
||||
|
||||
context 'with valid data' do
|
||||
it 'updates the rule and redirects' do
|
||||
put :update, params: { id: rule.id, rule: { text: 'Updated text.' } }
|
||||
|
||||
expect(response).to redirect_to(admin_rules_path)
|
||||
end
|
||||
end
|
||||
|
||||
context 'with invalid data' do
|
||||
it 'does not update the rule and renders index' do
|
||||
put :update, params: { id: rule.id, rule: { text: '' } }
|
||||
|
||||
expect(response).to render_template(:edit)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'DELETE #destroy' do
|
||||
let!(:rule) { Fabricate(:rule) }
|
||||
|
||||
it 'destroys the rule and redirects' do
|
||||
delete :destroy, params: { id: rule.id }
|
||||
|
||||
expect(rule.reload).to be_discarded
|
||||
expect(response).to redirect_to(admin_rules_path)
|
||||
end
|
||||
end
|
||||
end
|
83
spec/system/admin/rules_spec.rb
Normal file
83
spec/system/admin/rules_spec.rb
Normal file
|
@ -0,0 +1,83 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe 'Admin Rules' do
|
||||
describe 'Managing rules' do
|
||||
before { sign_in Fabricate(:user, role: UserRole.find_by(name: 'Admin')) }
|
||||
|
||||
describe 'Viewing rules' do
|
||||
let!(:rule) { Fabricate :rule, text: 'This is a rule' }
|
||||
|
||||
it 'lists existing records' do
|
||||
visit admin_rules_path
|
||||
|
||||
expect(page)
|
||||
.to have_content(I18n.t('admin.rules.title'))
|
||||
.and have_content(rule.text)
|
||||
|
||||
click_on(rule.text)
|
||||
expect(page)
|
||||
.to have_content(I18n.t('admin.rules.title'))
|
||||
end
|
||||
end
|
||||
|
||||
describe 'Creating a new rule' do
|
||||
it 'creates new record with valid attributes' do
|
||||
visit admin_rules_path
|
||||
|
||||
# Invalid submission
|
||||
fill_in 'rule_text', with: ''
|
||||
expect { submit_form }
|
||||
.to_not change(Rule, :count)
|
||||
expect(page)
|
||||
.to have_content(/error below/)
|
||||
|
||||
# Valid submission
|
||||
fill_in 'rule_text', with: 'No yelling on the bus!'
|
||||
expect { submit_form }
|
||||
.to change(Rule, :count).by(1)
|
||||
expect(page)
|
||||
.to have_content(I18n.t('admin.rules.title'))
|
||||
end
|
||||
|
||||
def submit_form
|
||||
click_on I18n.t('admin.rules.add_new')
|
||||
end
|
||||
end
|
||||
|
||||
describe 'Editing an existing rule' do
|
||||
let!(:rule) { Fabricate :rule, text: 'Rule text' }
|
||||
|
||||
it 'updates with valid attributes' do
|
||||
visit admin_rules_path
|
||||
|
||||
# Invalid submission
|
||||
click_on rule.text
|
||||
fill_in 'rule_text', with: ''
|
||||
expect { submit_form }
|
||||
.to_not change(rule.reload, :updated_at)
|
||||
|
||||
# Valid update
|
||||
fill_in 'rule_text', with: 'What day is this?'
|
||||
expect { submit_form }
|
||||
.to(change { rule.reload.text })
|
||||
end
|
||||
|
||||
def submit_form
|
||||
click_on I18n.t('generic.save_changes')
|
||||
end
|
||||
end
|
||||
|
||||
describe 'Destroy a rule' do
|
||||
let!(:rule) { Fabricate :rule }
|
||||
|
||||
it 'removes the record' do
|
||||
visit admin_rules_path
|
||||
|
||||
expect { click_on I18n.t('admin.rules.delete') }
|
||||
.to change { rule.reload.discarded? }.to(true)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -77,7 +77,7 @@ RSpec.describe 'Admin Webhooks' do
|
|||
# Valid update
|
||||
fill_in 'webhook_url', with: 'https://host.example/new/value/123'
|
||||
expect { submit_form }
|
||||
.to_not change(webhook.reload, :url)
|
||||
.to(change { webhook.reload.url })
|
||||
end
|
||||
|
||||
def submit_form
|
||||
|
|
Loading…
Reference in a new issue