From ea932b74e730529613b66a509ff5ef21c534067e Mon Sep 17 00:00:00 2001 From: Sam Date: Sun, 23 Jun 2013 15:07:25 +1000 Subject: [PATCH] values is a much more consistent name than all_values ... we use {}.values not {}.all_values also fixes random ordering of tests failure in site settings --- app/models/locale_site_setting.rb | 2 +- app/models/s3_region_site_setting.rb | 8 ++++---- docs/INSTALL-ubuntu.md | 2 +- lib/site_setting_extension.rb | 2 +- spec/components/site_setting_extenstion_spec.rb | 4 ++++ spec/models/locale_site_setting_spec.rb | 4 ++-- spec/models/s3_region_site_setting_spec.rb | 6 +++--- 7 files changed, 16 insertions(+), 12 deletions(-) diff --git a/app/models/locale_site_setting.rb b/app/models/locale_site_setting.rb index fa624f8e3e0..1c3ae78ba43 100644 --- a/app/models/locale_site_setting.rb +++ b/app/models/locale_site_setting.rb @@ -4,7 +4,7 @@ class LocaleSiteSetting supported_locales.include?(val) end - def self.all_values + def self.values supported_locales end diff --git a/app/models/s3_region_site_setting.rb b/app/models/s3_region_site_setting.rb index 8239b32ea1d..2b66348f560 100644 --- a/app/models/s3_region_site_setting.rb +++ b/app/models/s3_region_site_setting.rb @@ -1,9 +1,9 @@ class S3RegionSiteSetting def self.valid_value?(val) - all_values.include? val + values.include? val end - def self.all_values - @all_values ||= ['', 'us-east-1', 'us-west-1', 'us-west-2', 'eu-west-1', 'ap-southeast-1', 'ap-southeast-2', 'ap-northeast-1', 'sa-east-1'].sort + def self.values + @values ||= ['', 'us-east-1', 'us-west-1', 'us-west-2', 'eu-west-1', 'ap-southeast-1', 'ap-southeast-2', 'ap-northeast-1', 'sa-east-1'].sort end -end \ No newline at end of file +end diff --git a/docs/INSTALL-ubuntu.md b/docs/INSTALL-ubuntu.md index eabf47bb94c..f893e545940 100644 --- a/docs/INSTALL-ubuntu.md +++ b/docs/INSTALL-ubuntu.md @@ -249,7 +249,7 @@ Not english? Set the default language as appropriate: SiteSetting.default_locale = 'fr' # Not sure if your locale is supported? Check at the rails console: - LocaleSiteSetting.all_values + LocaleSiteSetting.values => ["cs", "da", "de", "en", "es", "fr", "id", "it", "nb_NO", "nl", "pseudo", "pt", "ru", "sv", "zh_CN", "zh_TW"] ## nginx setup diff --git a/lib/site_setting_extension.rb b/lib/site_setting_extension.rb index 05c8234fd42..d63a8745acf 100644 --- a/lib/site_setting_extension.rb +++ b/lib/site_setting_extension.rb @@ -80,7 +80,7 @@ module SiteSettingExtension description: description(s), default: v, type: type.to_s, - value: value.to_s}.merge( type == :enum ? {valid_values: enum_class(s).all_values} : {}) + value: value.to_s}.merge( type == :enum ? {valid_values: enum_class(s).values} : {}) end end diff --git a/spec/components/site_setting_extenstion_spec.rb b/spec/components/site_setting_extenstion_spec.rb index 37eaf068bf1..d84a0b01295 100644 --- a/spec/components/site_setting_extenstion_spec.rb +++ b/spec/components/site_setting_extenstion_spec.rb @@ -142,6 +142,10 @@ describe SiteSettingExtension do expect(settings.test_enum).to eq('en') end + it 'should not hose all_settings' do + settings.all_settings.detect {|s| s[:setting] == :test_enum }.should be_present + end + context 'when overridden' do it 'stores valid values' do diff --git a/spec/models/locale_site_setting_spec.rb b/spec/models/locale_site_setting_spec.rb index c7114fb9880..b623a450282 100644 --- a/spec/models/locale_site_setting_spec.rb +++ b/spec/models/locale_site_setting_spec.rb @@ -12,9 +12,9 @@ describe LocaleSiteSetting do end end - describe 'all_values' do + describe 'values' do it 'returns all the locales that we have translations for' do - expect(LocaleSiteSetting.all_values.sort).to eq(Dir.glob( File.join(Rails.root, 'config', 'locales', 'client.*.yml') ).map {|x| x.split('.')[-2]}.sort) + expect(LocaleSiteSetting.values.sort).to eq(Dir.glob( File.join(Rails.root, 'config', 'locales', 'client.*.yml') ).map {|x| x.split('.')[-2]}.sort) end end diff --git a/spec/models/s3_region_site_setting_spec.rb b/spec/models/s3_region_site_setting_spec.rb index a7c5dc7ac2f..f0bb5421c6f 100644 --- a/spec/models/s3_region_site_setting_spec.rb +++ b/spec/models/s3_region_site_setting_spec.rb @@ -12,10 +12,10 @@ describe S3RegionSiteSetting do end end - describe 'all_values' do + describe 'values' do it 'returns all the S3 regions and blank' do - expect(S3RegionSiteSetting.all_values.sort).to eq(['', 'us-east-1', 'us-west-1', 'us-west-2', 'eu-west-1', 'ap-southeast-1', 'ap-southeast-2', 'ap-northeast-1', 'sa-east-1'].sort) + expect(S3RegionSiteSetting.values.sort).to eq(['', 'us-east-1', 'us-west-1', 'us-west-2', 'eu-west-1', 'ap-southeast-1', 'ap-southeast-2', 'ap-northeast-1', 'sa-east-1'].sort) end end -end \ No newline at end of file +end