Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setup Coverband #15811

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public/images
public/fonts
public/flash
public/static
public/coverband
app/assets/stylesheets/tmp/
app/assets/fonts/icon_font/svgs
db/schema.rb
Expand Down
13 changes: 1 addition & 12 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ group :assets do
gem "compass", "1.0.3"
end

# Importer & sync tables
gem 'roo', '1.13.2'
gem 'state_machines-activerecord', '~> 0.5.0'
gem 'typhoeus', '1.3.1'
Expand All @@ -63,27 +62,17 @@ gem 'google-api-client', '0.34.1'
gem 'dropbox_api', '0.1.17'
gem 'gibbon', '1.1.4'
gem 'instagram-continued-continued'

# GCloud
gem 'google-cloud-pubsub', '1.2.0'

# Service components (/services)
gem 'virtus', '1.0.5'
gem 'cartodb-common', git: 'https://github.com/cartodb/cartodb-common.git', tag: 'v0.3.4'
gem 'email_address', '~> 0.1.11'

# Markdown
gem 'redcarpet', '3.3.3'

# TODO Production gems, put them in :production group
gem 'rollbar', '~>2.11.1'
gem 'resque', '1.25.2'
gem 'resque-metrics', '0.1.1'

gem 'net-telnet'

gem 'rubyzip', '>= 2.0.0'

gem 'coverband'
# This is weird. In ruby 2 test-unit is required. We don't know why for sure
gem 'test-unit'

Expand Down
3 changes: 3 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ GEM
compass-import-once (1.0.5)
sass (>= 3.2, < 3.5)
concurrent-ruby (1.1.6)
coverband (5.0.0)
redis
crass (1.0.6)
daemons (1.2.4)
db-query-matchers (0.4.0)
Expand Down Expand Up @@ -503,6 +505,7 @@ DEPENDENCIES
charlock_holmes (= 0.7.6)
ci_reporter (= 1.8.4)
compass (= 1.0.3)
coverband
db-query-matchers (= 0.4.0)
dbf (= 2.0.6)
delorean
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Development
* Adds logging docs [#15813](https://github.com/CartoDB/cartodb/pull/15813)
* Add wildcard IP for Direct SQL connection [#15818](https://github.com/CartoDB/cartodb/pull/15818)
* Remove usage of `::User` Sequel model from the `ApplicationController` [#15804](https://github.com/CartoDB/cartodb/pull/15804)
* Setup Coverband dead code detector [https://github.com/CartoDB/cartodb/pull/15811](https://github.com/CartoDB/cartodb/pull/15811)

4.41.1 (2020-09-03)
-------------------
Expand Down
6 changes: 6 additions & 0 deletions app/models/carto/helpers/user_commons.rb
Original file line number Diff line number Diff line change
Expand Up @@ -280,4 +280,10 @@ def update_do_subscription(attributes)
end
end

def has_access_to_coverband?
return true unless Rails.env.production?

organization&.name == 'team'
end

end
3 changes: 3 additions & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
require_relative '../lib/carto/configuration'
require_relative '../lib/carto/carto_gears_support'

# Forcefully require Coverband config because otherwise it raises an error in the rails console
require './config/coverband'

if defined?(Bundler)
Bundler.require(:default, :assets, Rails.env)
end
Expand Down
9 changes: 9 additions & 0 deletions config/coverband.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
require 'coverband'

Coverband.configure do |config|
config.store = Coverband::Adapters::RedisStore.new(Redis.new(url: ENV['COVERBAND_REDIS_URL']))
config.logger = Rails.logger
config.verbose = Rails.env.development?
config.web_enable_clear = Rails.env.development?
config.track_views = true
end
8 changes: 8 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -767,4 +767,12 @@
end
end

Rails.application.routes.draw do
mount(
Coverband::Reporters::Web.new,
at: '/coverband',
constraints: lambda { |request| request.env['warden']&.user&.has_access_to_coverband? }
)
end

# rubocop:enable Layout/LineLength, Layout/ExtraSpacing, Layout/SpaceBeforeFirstArg
14 changes: 14 additions & 0 deletions lib/tasks/assets.rake
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,18 @@ namespace :assets do
end
end
end

# bundle exec rake assets:copy_coverband_assets
desc 'Copy Coverband assets to production path'
task :copy_coverband_assets do
gem_path = Gem::Specification.find_by_name('coverband').full_gem_path
src_path = "#{gem_path}/public/."
dst_path = "#{Rails.root}/public/coverband"

puts "Creating directory: #{dst_path}"
FileUtils.mkdir_p(dst_path)

puts "Copying files from #{src_path} to #{dst_path}"
FileUtils.cp_r(src_path, dst_path)
end
end
30 changes: 28 additions & 2 deletions spec/models/carto/user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
require_relative '../user_shared_examples'

describe Carto::User do
let(:user) { create(:carto_user) }

it_behaves_like 'user models' do
def get_twitter_imports_count_by_user_id(user_id)
get_user_by_id(user_id).twitter_imports_count
Expand All @@ -12,11 +14,11 @@ def get_user_by_id(user_id)
end

def create_user
FactoryGirl.create(:carto_user)
create(:carto_user)
end

def build_user
FactoryGirl.build(:carto_user)
build(:carto_user)
end
end

Expand Down Expand Up @@ -99,4 +101,28 @@ def build_user
@user.password_reset_sent_at.to_s.should eql now.to_s
end
end

describe '#has_access_to_coverband?' do
let(:team_organization) { Carto::Organization.find(create(:organization, name: 'team').id) }

subject { user.has_access_to_coverband? }

context 'in development' do
it { should be_true }
end

context 'in production' do
before { Rails.env.stubs(:production?).returns(true) }

context 'when belongs to team' do
before { user.update!(organization: team_organization) }

it { should be_true }
end

context 'in any other case' do
it { should be_false }
end
end
end
end