From 3e3e2fcf4d3250f5501ed1528690d3466abdf53b Mon Sep 17 00:00:00 2001 From: Darren Oakley Date: Tue, 16 Feb 2016 10:34:11 +0000 Subject: [PATCH 1/2] Some small rubocop suggested updates. --- Rakefile | 42 +++++++++++------------ lib/bandiera/api_v1.rb | 9 +++-- lib/bandiera/db.rb | 2 +- lib/bandiera/feature_service.rb | 12 +++---- lib/bandiera/web_app_base.rb | 4 +-- spec/lib/bandiera/api_v1_spec.rb | 12 +++---- spec/lib/bandiera/api_v2_spec.rb | 14 ++++---- spec/lib/bandiera/feature_service_spec.rb | 10 +++--- spec/lib/bandiera/feature_spec.rb | 2 +- spec/lib/bandiera/gui_spec.rb | 10 +++--- spec/spec_helper.rb | 4 +-- 11 files changed, 59 insertions(+), 62 deletions(-) diff --git a/Rakefile b/Rakefile index 7514751..3ace5ff 100755 --- a/Rakefile +++ b/Rakefile @@ -42,26 +42,26 @@ namespace :db do db[:groups].delete serv.add_features([ - { - group: 'pubserv', - name: 'show-article-metrics', - description: 'Show metrics on the article pages?', - active: true - }, - { - group: 'pubserv', - name: 'show-new-search', - description: 'Show the new search feature?', - active: true, - percentage: 50 - }, - { - group: 'pubserv', - name: 'show-reorganised-homepage', - description: 'Show the new homepage layout?', - active: true, - user_groups: { list: ['editor'], regex: '' } - } - ]) + { + group: 'pubserv', + name: 'show-article-metrics', + description: 'Show metrics on the article pages?', + active: true + }, + { + group: 'pubserv', + name: 'show-new-search', + description: 'Show the new search feature?', + active: true, + percentage: 50 + }, + { + group: 'pubserv', + name: 'show-reorganised-homepage', + description: 'Show the new homepage layout?', + active: true, + user_groups: { list: ['editor'], regex: '' } + } + ]) end end diff --git a/lib/bandiera/api_v1.rb b/lib/bandiera/api_v1.rb index 96b60ab..6542ff0 100644 --- a/lib/bandiera/api_v1.rb +++ b/lib/bandiera/api_v1.rb @@ -26,7 +26,7 @@ def _post_groups status 201 render_json(group: { name: group_name }) else - fail InvalidParams, "Invalid parameters, required params are { 'group' => { 'name' => 'YOUR GROUP NAME' } }" + raise InvalidParams, "Invalid parameters, required params are { 'group' => { 'name' => 'YOUR GROUP NAME' } }" end end @@ -126,10 +126,9 @@ def _get_all private def render_json(data) - data.merge!( - information: 'You are using the v1 Bandiera API - this interface is deprecated, you should switch to use ' \ + data[:information] = 'You are using the v1 Bandiera API - this interface is deprecated, you should switch to use ' \ 'the latest version (see https://github.com/springernature/bandiera/wiki/API-Documentation for more ' \ - 'information).') + 'information).' content_type :json JSON.generate(data) end @@ -141,7 +140,7 @@ def with_valid_feature_params(feature, inc_option_params_in_error = false) error_msg = "Invalid parameters, required params are { 'feature' => { 'name' => 'FEATURE NAME', " \ "'description' => 'FEATURE DESCRIPTION', 'enabled' => 'TRUE OR FALSE' } }" error_msg << ", optional params are { 'feature' => { 'group' => 'GROUP NAME' } }" if inc_option_params_in_error - fail InvalidParams, error_msg + raise InvalidParams, error_msg end end end diff --git a/lib/bandiera/db.rb b/lib/bandiera/db.rb index 4658630..0963b10 100644 --- a/lib/bandiera/db.rb +++ b/lib/bandiera/db.rb @@ -7,7 +7,7 @@ module Bandiera class Db def self.connect - fail ArgumentError, 'You must set a DATABASE_URL environment variable' unless ENV['DATABASE_URL'] + raise ArgumentError, 'You must set a DATABASE_URL environment variable' unless ENV['DATABASE_URL'] @db ||= Sequel.connect(ENV['DATABASE_URL']) end diff --git a/lib/bandiera/feature_service.rb b/lib/bandiera/feature_service.rb index b86cd85..fe098ff 100644 --- a/lib/bandiera/feature_service.rb +++ b/lib/bandiera/feature_service.rb @@ -20,7 +20,7 @@ def initialize(db = Db.connect) def find_group(name) group = Group.find(name: name) - fail GroupNotFound, "Cannot find group '#{name}'" unless group + raise GroupNotFound, "Cannot find group '#{name}'" unless group group end @@ -41,7 +41,7 @@ def fetch_group_features(group_name) def fetch_feature(group, name) group_id = find_group_id(group) feature = Feature.first(group_id: group_id, name: name) - fail FeatureNotFound, "Cannot find feature '#{name}'" unless feature + raise FeatureNotFound, "Cannot find feature '#{name}'" unless feature feature end @@ -58,15 +58,15 @@ def add_features(features) def remove_feature(group, name) group_id = find_group_id(group) affected_rows = Feature.where(group_id: group_id, name: name).delete - fail FeatureNotFound, "Cannot find feature '#{name}'" unless affected_rows > 0 + raise FeatureNotFound, "Cannot find feature '#{name}'" unless affected_rows > 0 end def update_feature(group, name, params) group_id = find_group_id(group) feature = Feature.first(group_id: group_id, name: name) - fail FeatureNotFound, "Cannot find feature '#{name}'" unless feature + raise FeatureNotFound, "Cannot find feature '#{name}'" unless feature - fields = { + fields = { description: params[:description], active: params[:active], user_groups: params[:user_groups], @@ -79,7 +79,7 @@ def update_feature(group, name, params) def find_group_id(name) group_id = Group.where(name: name).get(:id) - fail GroupNotFound, "Cannot find group '#{name}'" unless group_id + raise GroupNotFound, "Cannot find group '#{name}'" unless group_id group_id end diff --git a/lib/bandiera/web_app_base.rb b/lib/bandiera/web_app_base.rb index 8ab8801..e537761 100644 --- a/lib/bandiera/web_app_base.rb +++ b/lib/bandiera/web_app_base.rb @@ -19,7 +19,7 @@ def feature_service end before do - path = request.path.sub(%r{^/}, '').gsub('/', '.') + path = request.path.sub(%r{^/}, '').tr('/', '.') path = 'homepage' if path.empty? method = request.request_method.downcase add_statsd_timer_and_increment "#{path}.#{method}" @@ -59,7 +59,7 @@ def process_user_group_list_param(val) when String then val.split("\n") when Array then val else - fail InvalidParams, 'params[user_groups][list] must be a string or array.' + raise InvalidParams, 'params[user_groups][list] must be a string or array.' end list.map(&:strip) diff --git a/spec/lib/bandiera/api_v1_spec.rb b/spec/lib/bandiera/api_v1_spec.rb index e59efd5..42b0972 100644 --- a/spec/lib/bandiera/api_v1_spec.rb +++ b/spec/lib/bandiera/api_v1_spec.rb @@ -20,12 +20,12 @@ def assert_last_response_matches(expected_data) before do service = Bandiera::FeatureService.new service.add_features([ - { group: 'pubserv', name: 'show_subjects', description: 'Show all subject related features', active: false }, - { group: 'pubserv', name: 'show_search', description: 'Show the search bar', active: true }, - { group: 'pubserv', name: 'xmas_mode', description: 'Xmas mode: SNOWFLAKES!', active: false }, - { group: 'laserwolf', name: 'enable_caching', description: 'Enable caching', active: false }, - { group: 'shunter', name: 'stats_logging', description: 'Log stats', active: true } - ]) + { group: 'pubserv', name: 'show_subjects', description: 'Show all subject related features', active: false }, + { group: 'pubserv', name: 'show_search', description: 'Show the search bar', active: true }, + { group: 'pubserv', name: 'xmas_mode', description: 'Xmas mode: SNOWFLAKES!', active: false }, + { group: 'laserwolf', name: 'enable_caching', description: 'Enable caching', active: false }, + { group: 'shunter', name: 'stats_logging', description: 'Log stats', active: true } + ]) end describe 'GET /groups' do diff --git a/spec/lib/bandiera/api_v2_spec.rb b/spec/lib/bandiera/api_v2_spec.rb index 4910cdc..83ee89d 100644 --- a/spec/lib/bandiera/api_v2_spec.rb +++ b/spec/lib/bandiera/api_v2_spec.rb @@ -14,13 +14,13 @@ def app before do feature_service = Bandiera::FeatureService.new feature_service.add_features([ - { group: 'pubserv', name: 'show_subjects', description: '', active: true, - user_groups: { list: ['editor'], regex: '' } }, - { group: 'pubserv', name: 'show_metrics', description: '', active: false }, - { group: 'pubserv', name: 'use_content_hub', description: '', active: true }, - { group: 'shunter', name: 'stats_logging', description: '', active: true }, - { group: 'shunter', name: 'use_img_serv', description: '', active: true, percentage: 50 } - ]) + { group: 'pubserv', name: 'show_subjects', description: '', active: true, + user_groups: { list: ['editor'], regex: '' } }, + { group: 'pubserv', name: 'show_metrics', description: '', active: false }, + { group: 'pubserv', name: 'use_content_hub', description: '', active: true }, + { group: 'shunter', name: 'stats_logging', description: '', active: true }, + { group: 'shunter', name: 'use_img_serv', description: '', active: true, percentage: 50 } + ]) end describe 'GET /all' do diff --git a/spec/lib/bandiera/feature_service_spec.rb b/spec/lib/bandiera/feature_service_spec.rb index 101e6d6..bf6c3ca 100644 --- a/spec/lib/bandiera/feature_service_spec.rb +++ b/spec/lib/bandiera/feature_service_spec.rb @@ -260,7 +260,7 @@ it 'returns the updated feature' do expect( - subject.update_feature('group', 'feat', description: 'updated') + subject.update_feature('group', 'feat', description: 'updated') ).to be_an_instance_of(Bandiera::Feature) end end @@ -281,10 +281,10 @@ describe '#fetch_group_features' do before do subject.add_features([ - { name: 'feature1', group: 'group_name' }, - { name: 'feature2', group: 'group_name' }, - { name: 'wibble', group: 'something_else' } - ]) + { name: 'feature1', group: 'group_name' }, + { name: 'feature2', group: 'group_name' }, + { name: 'wibble', group: 'something_else' } + ]) end context 'when the group exists' do diff --git a/spec/lib/bandiera/feature_spec.rb b/spec/lib/bandiera/feature_spec.rb index 3153d11..f0b18ba 100644 --- a/spec/lib/bandiera/feature_spec.rb +++ b/spec/lib/bandiera/feature_spec.rb @@ -323,7 +323,7 @@ end context 'with a percentage feature' do - let(:percentage) { 20 } + let(:percentage) { 20 } context 'when user_id HAS been supplied' do it 'returns an empty array' do diff --git a/spec/lib/bandiera/gui_spec.rb b/spec/lib/bandiera/gui_spec.rb index 0aaaf05..399b4d7 100644 --- a/spec/lib/bandiera/gui_spec.rb +++ b/spec/lib/bandiera/gui_spec.rb @@ -19,11 +19,11 @@ before do service.add_features([ - { group: 'pubserv', name: 'show_subjects', description: 'Show all subject related features', active: false }, - { group: 'pubserv', name: 'show_search', description: 'Show the search bar', active: true }, - { group: 'laserwolf', name: 'enable_caching', description: 'Enable caching', active: false }, - { group: 'shunter', name: 'stats_logging', description: 'Log stats', active: true } - ]) + { group: 'pubserv', name: 'show_subjects', description: 'Show all subject related features', active: false }, + { group: 'pubserv', name: 'show_search', description: 'Show the search bar', active: true }, + { group: 'laserwolf', name: 'enable_caching', description: 'Enable caching', active: false }, + { group: 'shunter', name: 'stats_logging', description: 'Log stats', active: true } + ]) end describe 'the homepage' do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index cc1e4a2..de11c72 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -31,9 +31,7 @@ config.disable_monkey_patching! - if config.files_to_run.one? - config.default_formatter = 'doc' - end + config.default_formatter = 'doc' if config.files_to_run.one? config.order = :random Kernel.srand config.seed From b1cb393353c2e5d25546a7aa52cfa809218a1c8a Mon Sep 17 00:00:00 2001 From: Darren Oakley Date: Tue, 16 Feb 2016 10:34:22 +0000 Subject: [PATCH 2/2] Bump VERSION to 3.1.1 --- lib/bandiera/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bandiera/version.rb b/lib/bandiera/version.rb index 19d5b1e..8fc8bb5 100644 --- a/lib/bandiera/version.rb +++ b/lib/bandiera/version.rb @@ -1,3 +1,3 @@ module Bandiera - VERSION = '3.1.0' + VERSION = '3.1.1'.freeze end