# Pull Request Template ## Description Extends account-level feature flags by adding a second bigint bitset column, `feature_flags_ext_2`, while preserving the existing `flag_shih_tzu` feature check and enable/disable APIs. Existing flags continue to live on `feature_flags`; future flags can opt into the extension column through `config/features.yml` metadata. Fixes [CW-7238](https://linear.app/chatwoot/issue/CW-7238/feature-flag-extension) ## Type of change - [ ] Bug fix (non-breaking change which fixes an issue) - [x] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality not to work as expected) - [ ] This change requires a documentation update ## How Has This Been Tested? - `eval "$(rbenv init -)" && RAILS_ENV=test POSTGRES_DATABASE=chatwoot_test_31a6 bundle exec rspec spec/models/concerns/featurable_spec.rb spec/models/account_spec.rb spec/lib/config_loader_spec.rb spec/controllers/platform/api/v1/accounts_controller_spec.rb spec/controllers/super_admin/accounts_controller_spec.rb spec/enterprise/models/account_spec.rb` - 144 examples, 0 failures - `eval "$(rbenv init -)" && bundle exec rubocop app/models/concerns/featurable.rb app/models/account.rb db/migrate/20260706215758_add_feature_flags_ext_2_to_accounts.rb spec/models/concerns/featurable_spec.rb spec/models/account_spec.rb spec/lib/config_loader_spec.rb spec/enterprise/models/account_spec.rb` - 7 files inspected, no offenses detected - `ruby -ryaml -e "features = YAML.safe_load(File.read('config/features.yml')); abort unless features.size == 63; puts features.group_by { |f| f['column'] || 'feature_flags' }.transform_values(&:size).inspect"` - `{"feature_flags" => 63}` - `git diff --check` ## Checklist: - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my code - [x] I have commented on my code, particularly in hard-to-understand areas - [x] I have made corresponding changes to the documentation - [x] My changes generate no new warnings - [x] I have added tests that prove my fix is effective or that my feature works - [x] New and existing unit tests pass locally with my changes - [x] Any dependent changes have been merged and published in downstream modules
51 lines
2.2 KiB
Ruby
51 lines
2.2 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require 'rails_helper'
|
|
|
|
RSpec.describe Featurable do
|
|
describe '.feature_flag_mappings_for' do
|
|
it 'maps features to the default feature_flags column when column is omitted' do
|
|
mappings = described_class.feature_flag_mappings_for([
|
|
{ 'name' => 'inbound_emails' },
|
|
{ 'name' => 'ip_lookup' }
|
|
])
|
|
|
|
expect(mappings['feature_flags']).to eq(
|
|
1 => :feature_inbound_emails,
|
|
2 => :feature_ip_lookup
|
|
)
|
|
expect(mappings['feature_flags_ext_1']).to eq({})
|
|
end
|
|
|
|
it 'maps extension flags to feature_flags_ext_1 with independent bit positions' do
|
|
mappings = described_class.feature_flag_mappings_for([
|
|
{ 'name' => 'inbound_emails' },
|
|
{ 'name' => 'ext_one', 'column' => 'feature_flags_ext_1' },
|
|
{ 'name' => 'ext_two', 'column' => 'feature_flags_ext_1' }
|
|
])
|
|
|
|
expect(mappings['feature_flags']).to eq(1 => :feature_inbound_emails)
|
|
expect(mappings['feature_flags_ext_1']).to eq(
|
|
1 => :feature_ext_one,
|
|
2 => :feature_ext_two
|
|
)
|
|
end
|
|
|
|
it 'raises when a feature references an unknown flag column' do
|
|
expect do
|
|
described_class.feature_flag_mappings_for([
|
|
{ 'name' => 'unknown_column_feature', 'column' => 'feature_flags_3' }
|
|
])
|
|
end.to raise_error(ArgumentError, /Unknown account feature flag column: feature_flags_3/)
|
|
end
|
|
|
|
it 'raises when a flag column has more than the supported number of features' do
|
|
features = Array.new(64) { |index| { 'name' => "feature_#{index}" } }
|
|
|
|
expect do
|
|
described_class.feature_flag_mappings_for(features)
|
|
end.to raise_error(ArgumentError, /feature_flags supports up to 63 features/)
|
|
end
|
|
end
|
|
end
|