Browse Source

Introduce rubocop

main
Bèr Kessels 1 year ago
parent
commit
f27a503de5
10 changed files with 84 additions and 74 deletions
  1. 5
    0
      .rubocop.yml
  2. 6
    3
      Gemfile
  3. 21
    0
      Gemfile.lock
  4. 19
    13
      Rakefile
  5. 9
    8
      app/web/server.rb
  6. 2
    0
      config.ru
  7. 11
    3
      config/environment.rb
  8. 0
    38
      test/spec_helper.rb
  9. 4
    2
      test/support/request_helpers.rb
  10. 7
    7
      test/test_helper.rb

+ 5
- 0
.rubocop.yml View File

@@ -0,0 +1,5 @@
AllCops:
NewCops: enable

Metrics/BlockLength:
ExcludedMethods: ['describe', 'context', 'define', 'factory', 'namespace']

+ 6
- 3
Gemfile View File

@@ -1,3 +1,5 @@
# frozen_string_literal: true

source 'https://rubygems.org'

gem 'event_sourcery', git: 'https://github.com/envato/event_sourcery.git'
@@ -10,10 +12,11 @@ gem 'sinatra'
gem 'pg', '0.20.0'

group :development, :test do
gem 'better_errors'
gem 'database_cleaner'
gem 'pry'
gem 'rspec'
gem 'rack-test'
gem 'database_cleaner'
gem 'better_errors'
gem 'rspec'
gem 'rubocop'
gem 'shotgun'
end

+ 21
- 0
Gemfile.lock View File

@@ -16,6 +16,7 @@ GIT
GEM
remote: https://rubygems.org/
specs:
ast (2.4.1)
better_errors (2.8.3)
coderay (>= 1.0.0)
erubi (>= 1.0.0)
@@ -27,6 +28,9 @@ GEM
method_source (1.0.0)
mustermann (1.1.1)
ruby2_keywords (~> 0.0.1)
parallel (1.19.2)
parser (2.7.1.5)
ast (~> 2.4.1)
pg (0.20.0)
pry (0.13.1)
coderay (~> 1.1)
@@ -36,7 +40,10 @@ GEM
rack
rack-test (1.1.0)
rack (>= 1.0, < 3)
rainbow (3.0.0)
rake (13.0.1)
regexp_parser (1.8.1)
rexml (3.2.4)
rspec (3.9.0)
rspec-core (~> 3.9.0)
rspec-expectations (~> 3.9.0)
@@ -50,6 +57,18 @@ GEM
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.9.0)
rspec-support (3.9.3)
rubocop (0.92.0)
parallel (~> 1.10)
parser (>= 2.7.1.5)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.7)
rexml
rubocop-ast (>= 0.5.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 2.0)
rubocop-ast (0.7.1)
parser (>= 2.7.1.5)
ruby-progressbar (1.10.1)
ruby2_keywords (0.0.2)
sequel (5.37.0)
shotgun (0.9.2)
@@ -60,6 +79,7 @@ GEM
rack-protection (= 2.1.0)
tilt (~> 2.0)
tilt (2.0.10)
unicode-display_width (1.7.0)

PLATFORMS
ruby
@@ -74,6 +94,7 @@ DEPENDENCIES
rack-test
rake
rspec
rubocop
shotgun
sinatra


+ 19
- 13
Rakefile View File

@@ -1,3 +1,5 @@
# frozen_string_literal: true

$LOAD_PATH.unshift '.'

task :environment do
@@ -20,26 +22,21 @@ task run_processors: :environment do
$stdout.sync = true

processors = [
# Add your processors here, like so:
#
# EventSourceryTodoApp::Projections::CompletedTodos::Projector.new(
# tracker: tracker,
# db_connection: db_connection,
# ),
Roost::Projections::Invitations::Projector.new(
tracker: tracker,
db_connection: db_connection
)
]

EventSourcery::EventProcessing::ESPRunner.new(
event_processors: processors,
event_source: event_source,
event_source: event_source
).start!
end

namespace :db do
desc 'Create database'
task create: :environment do
url = Roost.config.database_url
database_name = File.basename(url)
database = Sequel.connect URI.join(url, '/template1').to_s
begin
database.run("CREATE DATABASE #{database_name}")
rescue StandardError => e
@@ -50,9 +47,6 @@ namespace :db do

desc 'Drop database'
task drop: :environment do
url = Roost.config.database_url
database_name = File.basename(url)
database = Sequel.connect URI.join(url, '/template1').to_s
database.run("DROP DATABASE IF EXISTS #{database_name}")
database.disconnect
end
@@ -66,4 +60,16 @@ namespace :db do
puts "Could not create event store: #{e.class.name} #{e.message}"
end
end

def database
Sequel.connect URI.join(url, '/template1').to_s
end

def database_name
File.basename(url)
end

def url
Roost.config.database_url
end
end

+ 9
- 8
app/web/server.rb View File

@@ -1,9 +1,14 @@
# frozen_string_literal: true

require 'sinatra'

Dir.glob(__dir__ + '/../commands/**/*.rb').each { |f| require f }
Dir.glob(__dir__ + '/../projections/**/query.rb').each { |f| require f }
Dir.glob("#{__dir__}/../commands/**/*.rb").sort.each { |f| require f }
Dir.glob("#{__dir__}/../projections/**/query.rb").sort.each { |f| require f }

module Roost
##
# The webserver. Sinatra API only server. Main trigger for the commands
# and entrypoint for reading data.
class Server < Sinatra::Base
BadRequest = Class.new(StandardError)
UnprocessableEntity = Class.new(StandardError)
@@ -36,13 +41,9 @@ module Roost
# structures don't leak into the command layer

request_body = request.body.read
unless request_body.empty?
params.merge!(JSON.parse(request_body))
end
params.merge!(JSON.parse(request_body)) unless request_body.empty?

Hash[
params.map{ |k, v| [k.to_sym, v] }
]
params.transform_keys(&:to_sym)
end

# Add your API routes here!

+ 2
- 0
config.ru View File

@@ -1,3 +1,5 @@
# frozen_string_literal: true

$LOAD_PATH << '.'

require 'config/environment'

+ 11
- 3
config/environment.rb View File

@@ -1,11 +1,19 @@
# frozen_string_literal: true

require 'event_sourcery'
require 'event_sourcery/postgres'

Dir.glob(__dir__ + '/../app/events/*.rb').each { |f| require f }
Dir.glob(__dir__ + '/../app/reactors/*.rb').each { |f| require f }
Dir.glob(__dir__ + '/../app/projections/**/projector.rb').each { |f| require f }
Dir.glob("#{__dir__}/../app/events/*.rb").sort.each { |f| require f }
Dir.glob("#{__dir__}/../app/reactors/*.rb").sort.each { |f| require f }
Dir.glob("#{__dir__}/../app/projections/**/projector.rb").sort.each { |f| require f }

##
# Roost is the suite namespace for flockingbird.
# It has an API, handles commands and projects that into read projections,
# where the data can be read from, through the API.
module Roost
##
# Holds the configuration for Roost. Mainly event-sourcery config.
class Config
attr_accessor :database_url
end

+ 0
- 38
test/spec_helper.rb View File

@@ -1,38 +0,0 @@
ENV['RACK_ENV'] = 'test'

require 'rack/test'
require 'securerandom'
require 'database_cleaner'

$LOAD_PATH << '.'

require 'config/environment'
require 'app/web/server'
require 'spec/support/request_helpers'

RSpec.configure do |config|
config.include(Rack::Test::Methods, type: :request)
config.include(RequestHelpers, type: :request)

config.expect_with :rspec do |expectations|
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
end

config.mock_with :rspec do |mocks|
mocks.verify_partial_doubles = true
end

config.shared_context_metadata_behavior = :apply_to_host_groups
config.disable_monkey_patching!
config.order = :random
Kernel.srand config.seed

EventSourcery.configure do |config|
config.logger = Logger.new(nil)
end

config.before do
DatabaseCleaner.strategy = :truncation
DatabaseCleaner.clean
end
end

+ 4
- 2
test/support/request_helpers.rb View File

@@ -1,10 +1,12 @@
# frozen_string_literal: true

module RequestHelpers
def app
@@app ||= Roost::Server
@app ||= Roost::Server
end

def last_event(aggregate_id)
Roost.event_store
.get_events_for_aggregate_id(aggregate_id).last
.get_events_for_aggregate_id(aggregate_id).last
end
end

+ 7
- 7
test/test_helper.rb View File

@@ -13,13 +13,13 @@ $LOAD_PATH << '.'
require 'config/environment'
require 'app/web/server'

require_relative 'support/data_helpers.rb'
require_relative 'support/event_helpers.rb'
require_relative 'support/file_helpers.rb'
require_relative 'support/location_helpers.rb'
require_relative 'support/request_helpers.rb'
require_relative 'support/time_helpers.rb'
require_relative 'support/web_test_helpers.rb'
require_relative 'support/data_helpers'
require_relative 'support/event_helpers'
require_relative 'support/file_helpers'
require_relative 'support/location_helpers'
require_relative 'support/request_helpers'
require_relative 'support/time_helpers'
require_relative 'support/web_test_helpers'

Minitest::Test.make_my_diffs_pretty!


Loading…
Cancel
Save