Skip to content

Commit

Permalink
Upgrade Rubocop (#119)
Browse files Browse the repository at this point in the history
The specified Rubocop version was quite old. Running the specs against Ruby 3.1 isn't possible without upgrading due to [this issue](rubocop/rubocop#10258).
  • Loading branch information
rzane committed Mar 6, 2023
1 parent d56e2dc commit d9c0a7a
Show file tree
Hide file tree
Showing 12 changed files with 27 additions and 31 deletions.
8 changes: 4 additions & 4 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ RuboCop::RakeTask.new

desc "Pull the latest versions of all dependencies into the gem for distribution"
task :vendor_deps do
TEST_TRACK_JS_CLIENT_VERSION = '2.0.0'.freeze
TEST_TRACK_CLI_VERSION = 'v1.2.0'.freeze
test_track_js_client_version = '2.0.0'.freeze
test_track_cli_version = 'v1.2.0'.freeze

# Bundle JS client
sh 'npm init -y'
sh "npm install --no-save test_track_js_client@#{TEST_TRACK_JS_CLIENT_VERSION}"
sh "npm install --no-save test_track_js_client@#{test_track_js_client_version}"
sh 'cp', 'node_modules/test_track_js_client/dist/testTrack.bundle.js', 'app/assets/javascripts/testTrack.bundle.min.js'
sh 'rm package.json'

Expand All @@ -44,7 +44,7 @@ task :vendor_deps do
rm_r Dir.glob('*')

%w(darwin linux).each do |arch|
`curl -L https://github.com/Betterment/testtrack-cli/releases/download/#{TEST_TRACK_CLI_VERSION}/testtrack.#{arch} \
`curl -L https://github.com/Betterment/testtrack-cli/releases/download/#{test_track_cli_version}/testtrack.#{arch} \
> testtrack.#{arch}`
chmod 'u=wrx,go=rx', "testtrack.#{arch}"
end
Expand Down
6 changes: 2 additions & 4 deletions app/controllers/concerns/test_track/controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,8 @@ def test_track_visitor
test_track_session.visitor_dsl
end

def manage_test_track_session
def manage_test_track_session(&block)
RequestStore[:test_track_web_session] = test_track_session
test_track_session.manage do
yield
end
test_track_session.manage(&block)
end
end
2 changes: 1 addition & 1 deletion app/models/test_track/ab_configuration.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class TestTrack::AbConfiguration
include TestTrack::RequiredOptions

def initialize(opts) # rubocop:disable Metrics/AbcSize
def initialize(opts)
@split_name = require_option!(opts, :split_name).to_s
true_variant = require_option!(opts, :true_variant, allow_nil: true)
@split_registry = require_option!(opts, :split_registry)
Expand Down
6 changes: 2 additions & 4 deletions app/models/test_track/identity_session_locator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,15 @@ def initialize(identity)
@identity = identity
end

def with_visitor # rubocop:disable Metrics/AbcSize
def with_visitor(&block) # rubocop:disable Metrics/AbcSize
raise ArgumentError, "must provide block to `with_visitor`" unless block_given?

if web_session.present?
yield web_session.visitor_dsl_for(identity)
elsif job_session.present?
yield job_session.visitor_dsl_for(identity)
else
TestTrack::OfflineSession.with_visitor_for(identity.test_track_identifier_type, identity.test_track_identifier_value) do |v|
yield v
end
TestTrack::OfflineSession.with_visitor_for(identity.test_track_identifier_type, identity.test_track_identifier_value, &block)
end
end

Expand Down
12 changes: 4 additions & 8 deletions app/models/test_track/offline_session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,20 @@ def initialize(remote_visitor)
@remote_visitor = remote_visitor
end

def self.with_visitor_for(identifier_type, identifier_value)
def self.with_visitor_for(identifier_type, identifier_value, &block)
raise ArgumentError, "must provide block to `with_visitor_for`" unless block_given?

remote_visitor = TestTrack::Remote::Visitor.from_identifier(identifier_type, identifier_value)

new(remote_visitor).send :manage do |visitor_dsl|
yield visitor_dsl
end
new(remote_visitor).send(:manage, &block)
end

def self.with_visitor_id(visitor_id)
def self.with_visitor_id(visitor_id, &block)
raise ArgumentError, "must provide block to `with_visitor_id`" unless block_given?

remote_visitor = TestTrack::Remote::Visitor.find(visitor_id)

new(remote_visitor).send :manage do |visitor_dsl|
yield visitor_dsl
end
new(remote_visitor).send(:manage, &block)
end

private
Expand Down
1 change: 1 addition & 0 deletions app/models/test_track/vary_dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def default(variant, &block)
private

attr_reader :split_registry, :assignment, :context

delegate :split_name, to: :assignment

def split
Expand Down
4 changes: 2 additions & 2 deletions app/models/test_track/web_session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def sign_up!(identity)
attr_reader :controller

def current_identity
raise <<~ERROR unless controller.class.test_track_identity&.is_a?(Symbol)
raise <<~ERROR unless controller.class.test_track_identity.is_a?(Symbol)
Your controller (or controller base class) must set test_track_identity for
TestTrack to work properly. e.g.:
Expand Down Expand Up @@ -106,7 +106,7 @@ def bare_ip_address?
end

def wildcard_domain
"." + (public_suffix_domain || request.host)
".#{public_suffix_domain || request.host}"
end

def public_suffix_domain
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def response_json
it "sets a UUID tt_visitor_id cookie if unset" do
expect(request.cookies['tt_visitor_id']).to eq nil
get :index
expect(response.cookies['tt_visitor_id']).to match(/[0-9a-f\-]{36}/)
expect(response.cookies['tt_visitor_id']).to match(/[0-9a-f-]{36}/)
end

it "preserves tt_visitor_id cookie if set" do
Expand Down
2 changes: 1 addition & 1 deletion spec/models/test_track/ab_configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@

describe "#variants" do
it "should only have true and false keys" do
expect(subject.variants.keys).to eq %i(true false) # rubocop:disable Lint/BooleanSymbol
expect(subject.variants.keys).to eq %i(true false)
end

it "tells notifier if there are more than two variants" do
Expand Down
9 changes: 6 additions & 3 deletions spec/models/test_track/analytics/safe_wrapper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,13 @@
end

context 'when sign_up! method does not accept one argument' do
class TestClient
def sign_up!(visitor_id, extraneous_arg); end
let(:underlying) do
klass = Class.new do
def sign_up!(visitor_id, extraneous_arg); end
end

klass.new
end
let(:underlying) { TestClient.new }

it 'logs an argument error' do
expect(Rails.logger).to receive(:error).with(ArgumentError)
Expand Down
4 changes: 2 additions & 2 deletions spec/models/test_track/web_session_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def current_clown; end

it "returns a new visitor id" do
subject.manage {}
expect(cookies['tt_visitor_id'][:value]).to match(/\A[a-z0-9\-]{36}\z/)
expect(cookies['tt_visitor_id'][:value]).to match(/\A[a-z0-9-]{36}\z/)
end
end
end
Expand Down Expand Up @@ -122,7 +122,7 @@ def current_clown; end
expect(TestTrack::Visitor).to have_received(:new)
expect(TestTrack::Remote::Identifier).to have_received(:create!).with(
identifier_type: "clown_id",
visitor_id: /\A[a-f0-9\-]{36}\z/,
visitor_id: /\A[a-f0-9-]{36}\z/,
value: "1234"
)
end
Expand Down
2 changes: 1 addition & 1 deletion test_track_rails_client.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Gem::Specification.new do |s|
s.add_development_dependency 'pry-rails'
s.add_development_dependency 'rails-controller-testing'
s.add_development_dependency 'rspec-rails'
s.add_development_dependency 'rubocop', '~> 0.81.0'
s.add_development_dependency 'rubocop', '~> 1.48.0'
s.add_development_dependency 'rubocop-performance'
s.add_development_dependency 'rubocop-rails'
s.add_development_dependency 'shoulda-matchers', '>= 2.8'
Expand Down

0 comments on commit d9c0a7a

Please sign in to comment.