Convert settings/featured_tags
controller->request/system spec (#33880)
This commit is contained in:
parent
dd2cb77f1a
commit
7d20c12913
3 changed files with 56 additions and 74 deletions
|
@ -1,68 +0,0 @@
|
||||||
# frozen_string_literal: true
|
|
||||||
|
|
||||||
require 'rails_helper'
|
|
||||||
|
|
||||||
RSpec.describe Settings::FeaturedTagsController do
|
|
||||||
render_views
|
|
||||||
|
|
||||||
context 'when user is not signed in' do
|
|
||||||
subject { post :create }
|
|
||||||
|
|
||||||
it { is_expected.to redirect_to new_user_session_path }
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'when user is signed in' do
|
|
||||||
let(:user) { Fabricate(:user, password: '12345678') }
|
|
||||||
|
|
||||||
before { sign_in user, scope: :user }
|
|
||||||
|
|
||||||
describe 'POST #create' do
|
|
||||||
subject { post :create, params: { featured_tag: params } }
|
|
||||||
|
|
||||||
context 'when parameter is valid' do
|
|
||||||
let(:params) { { name: 'test' } }
|
|
||||||
|
|
||||||
it 'creates featured tag' do
|
|
||||||
expect { subject }.to change { user.account.featured_tags.count }.by(1)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'when parameter is invalid' do
|
|
||||||
let(:params) { { name: 'test, #foo !bleh' } }
|
|
||||||
|
|
||||||
it 'renders new' do
|
|
||||||
expect(subject).to render_template :index
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe 'GET to #index' do
|
|
||||||
let(:tag) { Fabricate(:tag) }
|
|
||||||
|
|
||||||
before do
|
|
||||||
status = Fabricate :status, account: user.account
|
|
||||||
status.tags << tag
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'responds with success' do
|
|
||||||
get :index
|
|
||||||
|
|
||||||
expect(response).to have_http_status(200)
|
|
||||||
expect(response.body).to include(
|
|
||||||
settings_featured_tags_path(featured_tag: { name: tag.name })
|
|
||||||
)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe 'DELETE to #destroy' do
|
|
||||||
let(:featured_tag) { Fabricate(:featured_tag, account: user.account) }
|
|
||||||
|
|
||||||
it 'removes the featured tag' do
|
|
||||||
delete :destroy, params: { id: featured_tag.id }
|
|
||||||
|
|
||||||
expect(response).to redirect_to(settings_featured_tags_path)
|
|
||||||
expect { featured_tag.reload }.to raise_error(ActiveRecord::RecordNotFound)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -2,15 +2,23 @@
|
||||||
|
|
||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
RSpec.describe 'Settings Aliases' do
|
RSpec.describe 'Settings Featured Tags' do
|
||||||
describe 'POST /settings/featured_tags' do
|
describe 'POST /settings/featured_tags' do
|
||||||
before { sign_in Fabricate(:user) }
|
context 'when signed in' do
|
||||||
|
before { sign_in Fabricate(:user) }
|
||||||
|
|
||||||
it 'gracefully handles invalid nested params' do
|
it 'gracefully handles invalid nested params' do
|
||||||
post settings_featured_tags_path(featured_tag: 'invalid')
|
post settings_featured_tags_path(featured_tag: 'invalid')
|
||||||
|
|
||||||
expect(response)
|
expect(response)
|
||||||
.to have_http_status(400)
|
.to have_http_status(400)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when not signed in' do
|
||||||
|
subject { post settings_featured_tags_path }
|
||||||
|
|
||||||
|
it { is_expected.to redirect_to new_user_session_path }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
42
spec/system/settings/featured_tags_spec.rb
Normal file
42
spec/system/settings/featured_tags_spec.rb
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
RSpec.describe 'Settings Featured Tags' do
|
||||||
|
let(:user) { Fabricate(:user) }
|
||||||
|
|
||||||
|
before { sign_in(user) }
|
||||||
|
|
||||||
|
describe 'Managing tags' do
|
||||||
|
let(:tag) { Fabricate(:tag) }
|
||||||
|
let(:status) { Fabricate :status, account: user.account }
|
||||||
|
|
||||||
|
before { status.tags << tag }
|
||||||
|
|
||||||
|
it 'Views, adds, and removes featured tags' do
|
||||||
|
visit settings_featured_tags_path
|
||||||
|
|
||||||
|
# Link to existing tag used on a status
|
||||||
|
expect(page.body)
|
||||||
|
.to include(
|
||||||
|
settings_featured_tags_path(featured_tag: { name: tag.name })
|
||||||
|
)
|
||||||
|
|
||||||
|
# Invalid entry
|
||||||
|
fill_in 'featured_tag_name', with: 'test, #foo !bleh'
|
||||||
|
expect { click_on I18n.t('featured_tags.add_new') }
|
||||||
|
.to_not change(user.account.featured_tags, :count)
|
||||||
|
|
||||||
|
# Valid entry
|
||||||
|
fill_in 'featured_tag_name', with: '#friends'
|
||||||
|
expect { click_on I18n.t('featured_tags.add_new') }
|
||||||
|
.to change(user.account.featured_tags, :count).by(1)
|
||||||
|
|
||||||
|
# Delete the created entry
|
||||||
|
expect { click_on I18n.t('filters.index.delete') }
|
||||||
|
.to change(user.account.featured_tags, :count).by(-1)
|
||||||
|
expect(page)
|
||||||
|
.to have_title(I18n.t('settings.featured_tags'))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Add table
Add a link
Reference in a new issue