Feature: Improve label experience (#975)

Co-authored-by: Sojan <sojan@pepalo.com>
This commit is contained in:
Pranav Raj S
2020-06-25 21:04:03 +05:30
committed by GitHub
parent 8b61452d56
commit 97ad39713b
56 changed files with 1712 additions and 284 deletions

View File

@@ -76,7 +76,7 @@ RSpec.describe 'Label API', type: :request do
end
describe 'PATCH /api/v1/accounts/{account.id}/labels/:id' do
let(:valid_params) { { title: 'Test 2' } }
let(:valid_params) { { title: 'Test_2' } }
context 'when it is an unauthenticated user' do
it 'returns unauthorized' do
@@ -97,7 +97,7 @@ RSpec.describe 'Label API', type: :request do
as: :json
expect(response).to have_http_status(:success)
expect(label.reload.title).to eq('Test 2')
expect(label.reload.title).to eq('test_2')
end
end
end

View File

@@ -3,6 +3,6 @@
FactoryBot.define do
factory :label do
account
sequence(:title) { |n| "Label #{n}" }
sequence(:title) { |n| "Label_#{n}" }
end
end

View File

@@ -4,4 +4,39 @@ RSpec.describe Label, type: :model do
describe 'associations' do
it { is_expected.to belong_to(:account) }
end
describe 'title validations' do
it 'would not let you start title without numbers or letters' do
label = FactoryBot.build(:label, title: '_12')
expect(label.valid?).to eq false
end
it 'would not let you use special characters' do
label = FactoryBot.build(:label, title: 'jell;;2_12')
expect(label.valid?).to eq false
end
it 'would not allow space' do
label = FactoryBot.build(:label, title: 'heeloo _12')
expect(label.valid?).to eq false
end
it 'allows foreign charactes' do
label = FactoryBot.build(:label, title: '学中文_12')
expect(label.valid?).to eq true
end
it 'converts uppercase letters to lowercase' do
label = FactoryBot.build(:label, title: 'Hello_World')
expect(label.valid?).to eq true
expect(label.title).to eq 'hello_world'
end
it 'validates uniqueness of label name for account' do
account = create(:account)
label = FactoryBot.create(:label, account: account)
duplicate_label = FactoryBot.build(:label, title: label.title, account: account)
expect(duplicate_label.valid?).to eq false
end
end
end