├── .gitattributes ├── .gitignore ├── .rspec ├── .ruby-version ├── Gemfile ├── Gemfile.lock ├── Guardfile ├── LICENSE ├── README.md ├── Rakefile ├── app ├── assets │ ├── config │ │ └── manifest.js │ ├── images │ │ └── .keep │ └── stylesheets │ │ └── application.css ├── channels │ └── application_cable │ │ ├── channel.rb │ │ └── connection.rb ├── controllers │ ├── application_controller.rb │ └── concerns │ │ └── .keep ├── helpers │ └── application_helper.rb ├── javascript │ ├── application.js │ └── controllers │ │ ├── application.js │ │ ├── hello_controller.js │ │ └── index.js ├── jobs │ └── application_job.rb ├── lib │ ├── autowired_repository.rb │ ├── clock.rb │ ├── event_store.rb │ └── read_model_handler.rb ├── mailers │ └── application_mailer.rb ├── models │ ├── application_record.rb │ ├── concerns │ │ └── .keep │ └── read_models │ │ └── signed_contract.rb ├── modules │ ├── authorization │ │ └── application │ │ │ └── api.rb │ ├── commons │ │ └── domain │ │ │ └── with_events.rb │ ├── cooperation_negotiation │ │ ├── application │ │ │ ├── controllers │ │ │ │ └── contract_controller.rb │ │ │ └── services │ │ │ │ ├── modify_contract_text.rb │ │ │ │ ├── prepare_draft_contract.rb │ │ │ │ ├── sign_contract_by_client.rb │ │ │ │ └── sign_contract_by_company.rb │ │ ├── domain │ │ │ ├── contract.rb │ │ │ ├── contract_repository.rb │ │ │ └── events │ │ │ │ ├── contract_draft_prepared.rb │ │ │ │ ├── contract_signed.rb │ │ │ │ └── contract_text_modified.rb │ │ └── infrastructure │ │ │ ├── db_contract.rb │ │ │ ├── db_contract_repository.rb │ │ │ └── in_memory_contract_repository.rb │ └── dragon_hunt │ │ ├── application │ │ └── handlers │ │ │ └── cooperation_negotiation │ │ │ └── contract_signed.rb │ │ ├── domain │ │ ├── party.rb │ │ └── party_repository.rb │ │ └── infrastructure │ │ ├── db_party.rb │ │ └── db_party_repository.rb └── views │ └── layouts │ ├── application.html.erb │ ├── mailer.html.erb │ └── mailer.text.erb ├── bin ├── bundle ├── importmap ├── rails ├── rake └── setup ├── config.ru ├── config ├── application.rb ├── boot.rb ├── cable.yml ├── credentials.yml.enc ├── database.yml ├── environment.rb ├── environments │ ├── development.rb │ ├── production.rb │ └── test.rb ├── importmap.rb ├── initializers │ ├── assets.rb │ ├── content_security_policy.rb │ ├── filter_parameter_logging.rb │ ├── inflections.rb │ └── permissions_policy.rb ├── locales │ └── en.yml ├── puma.rb ├── routes.rb └── storage.yml ├── db ├── migrate │ ├── 20221123212261_enable_pgcypto.rb │ ├── 20221123212610_create_cooperation_negotiation_contracts.rb │ ├── 20221123212818_create_dragon_hunt_parties.rb │ └── 20221124233218_create_read_models_signed_contracts.rb ├── schema.rb └── seeds.rb ├── lib ├── assets │ └── .keep └── tasks │ └── .keep ├── log └── .keep ├── public ├── 404.html ├── 422.html ├── 500.html ├── apple-touch-icon-precomposed.png ├── apple-touch-icon.png ├── favicon.ico └── robots.txt ├── spec ├── modules │ ├── authorization │ │ └── application │ │ │ └── api_spec.rb │ ├── cooperation_negotiation │ │ ├── application │ │ │ └── services │ │ │ │ ├── modify_contract_text_spec.rb │ │ │ │ ├── prepare_draft_contract_spec.rb │ │ │ │ ├── sign_contract_by_client_spec.rb │ │ │ │ └── sign_contract_by_company_spec.rb │ │ ├── domain │ │ │ ├── contract_spec.rb │ │ │ └── events │ │ │ │ ├── contract_draft_prepared_spec.rb │ │ │ │ ├── contract_signed_spec.rb │ │ │ │ └── contract_text_modified_spec.rb │ │ └── infrastructure │ │ │ ├── db_contract_repository_spec.rb │ │ │ └── db_contract_spec.rb │ └── dragon_hunt │ │ ├── application │ │ └── handlers │ │ │ └── cooperation_negotiation │ │ │ └── contract_signed_spec.rb │ │ ├── domain │ │ └── party_spec.rb │ │ └── infrastructure │ │ ├── db_party_repository_spec.rb │ │ └── db_party_spec.rb ├── rails_helper.rb └── spec_helper.rb ├── storage └── .keep ├── tmp ├── .keep ├── pids │ └── .keep └── storage │ └── .keep └── vendor ├── .keep └── javascript └── .keep /.gitattributes: -------------------------------------------------------------------------------- 1 | # See https://git-scm.com/docs/gitattributes for more about git attribute files. 2 | 3 | # Mark the database schema as having been generated. 4 | db/schema.rb linguist-generated 5 | 6 | # Mark any vendored files as having been vendored. 7 | vendor/* linguist-vendored 8 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files for more about ignoring files. 2 | # 3 | # If you find yourself ignoring temporary files generated by your text editor 4 | # or operating system, you probably want to add a global ignore instead: 5 | # git config --global core.excludesfile '~/.gitignore_global' 6 | 7 | # Ignore bundler config. 8 | /.bundle 9 | 10 | # Ignore all logfiles and tempfiles. 11 | /log/* 12 | /tmp/* 13 | !/log/.keep 14 | !/tmp/.keep 15 | 16 | # Ignore pidfiles, but keep the directory. 17 | /tmp/pids/* 18 | !/tmp/pids/ 19 | !/tmp/pids/.keep 20 | 21 | # Ignore uploaded files in development. 22 | /storage/* 23 | !/storage/.keep 24 | /tmp/storage/* 25 | !/tmp/storage/ 26 | !/tmp/storage/.keep 27 | 28 | /public/assets 29 | 30 | # Ignore master key for decrypting credentials and more. 31 | /config/master.key 32 | 33 | # Ignore Simplecov coverage report files 34 | /coverage 35 | -------------------------------------------------------------------------------- /.rspec: -------------------------------------------------------------------------------- 1 | --require spec_helper 2 | -------------------------------------------------------------------------------- /.ruby-version: -------------------------------------------------------------------------------- 1 | ruby-3.1.2 2 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source "https://rubygems.org" 2 | git_source(:github) { |repo| "https://github.com/#{repo}.git" } 3 | 4 | ruby "3.1.2" 5 | 6 | # Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main" 7 | gem "rails", "~> 7" 8 | 9 | # The original asset pipeline for Rails [https://github.com/rails/sprockets-rails] 10 | gem "sprockets-rails" 11 | 12 | # Use postgresql as the database for Active Record 13 | gem "pg", "~> 1.1" 14 | 15 | # Use the Puma web server [https://github.com/puma/puma] 16 | gem "puma", "~> 5.0" 17 | 18 | # Use JavaScript with ESM import maps [https://github.com/rails/importmap-rails] 19 | gem "importmap-rails" 20 | 21 | # Hotwire's SPA-like page accelerator [https://turbo.hotwired.dev] 22 | gem "turbo-rails" 23 | 24 | # Hotwire's modest JavaScript framework [https://stimulus.hotwired.dev] 25 | gem "stimulus-rails" 26 | 27 | # Build JSON APIs with ease [https://github.com/rails/jbuilder] 28 | gem "jbuilder" 29 | 30 | # Use Redis adapter to run Action Cable in production 31 | gem "redis", "~> 4.0" 32 | 33 | # Use Kredis to get higher-level data types in Redis [https://github.com/rails/kredis] 34 | # gem "kredis" 35 | 36 | # Use Active Model has_secure_password [https://guides.rubyonrails.org/active_model_basics.html#securepassword] 37 | # gem "bcrypt", "~> 3.1.7" 38 | 39 | # Windows does not include zoneinfo files, so bundle the tzinfo-data gem 40 | gem "tzinfo-data", platforms: %i[ mingw mswin x64_mingw jruby ] 41 | 42 | # Reduces boot times through caching; required in config/boot.rb 43 | gem "bootsnap", require: false 44 | 45 | # Use Sass to process CSS 46 | # gem "sassc-rails" 47 | 48 | # Use Active Storage variants [https://guides.rubyonrails.org/active_storage_overview.html#transforming-images] 49 | # gem "image_processing", "~> 1.2" 50 | 51 | group :development, :test do 52 | # See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem 53 | gem "debug", platforms: %i[ mri mingw x64_mingw ] 54 | end 55 | 56 | group :development do 57 | # Use console on exceptions pages [https://github.com/rails/web-console] 58 | gem "web-console" 59 | 60 | # Add speed badges [https://github.com/MiniProfiler/rack-mini-profiler] 61 | # gem "rack-mini-profiler" 62 | 63 | # Speed up commands on slow machines / big apps [https://github.com/rails/spring] 64 | # gem "spring" 65 | end 66 | 67 | group :test do 68 | gem "guard" 69 | gem "guard-rspec", require: false 70 | 71 | gem 'rspec-rails', '~> 6.0.0' 72 | gem "simplecov", require: false 73 | end 74 | -------------------------------------------------------------------------------- /Gemfile.lock: -------------------------------------------------------------------------------- 1 | GEM 2 | remote: https://rubygems.org/ 3 | specs: 4 | actioncable (7.0.4) 5 | actionpack (= 7.0.4) 6 | activesupport (= 7.0.4) 7 | nio4r (~> 2.0) 8 | websocket-driver (>= 0.6.1) 9 | actionmailbox (7.0.4) 10 | actionpack (= 7.0.4) 11 | activejob (= 7.0.4) 12 | activerecord (= 7.0.4) 13 | activestorage (= 7.0.4) 14 | activesupport (= 7.0.4) 15 | mail (>= 2.7.1) 16 | net-imap 17 | net-pop 18 | net-smtp 19 | actionmailer (7.0.4) 20 | actionpack (= 7.0.4) 21 | actionview (= 7.0.4) 22 | activejob (= 7.0.4) 23 | activesupport (= 7.0.4) 24 | mail (~> 2.5, >= 2.5.4) 25 | net-imap 26 | net-pop 27 | net-smtp 28 | rails-dom-testing (~> 2.0) 29 | actionpack (7.0.4) 30 | actionview (= 7.0.4) 31 | activesupport (= 7.0.4) 32 | rack (~> 2.0, >= 2.2.0) 33 | rack-test (>= 0.6.3) 34 | rails-dom-testing (~> 2.0) 35 | rails-html-sanitizer (~> 1.0, >= 1.2.0) 36 | actiontext (7.0.4) 37 | actionpack (= 7.0.4) 38 | activerecord (= 7.0.4) 39 | activestorage (= 7.0.4) 40 | activesupport (= 7.0.4) 41 | globalid (>= 0.6.0) 42 | nokogiri (>= 1.8.5) 43 | actionview (7.0.4) 44 | activesupport (= 7.0.4) 45 | builder (~> 3.1) 46 | erubi (~> 1.4) 47 | rails-dom-testing (~> 2.0) 48 | rails-html-sanitizer (~> 1.1, >= 1.2.0) 49 | activejob (7.0.4) 50 | activesupport (= 7.0.4) 51 | globalid (>= 0.3.6) 52 | activemodel (7.0.4) 53 | activesupport (= 7.0.4) 54 | activerecord (7.0.4) 55 | activemodel (= 7.0.4) 56 | activesupport (= 7.0.4) 57 | activestorage (7.0.4) 58 | actionpack (= 7.0.4) 59 | activejob (= 7.0.4) 60 | activerecord (= 7.0.4) 61 | activesupport (= 7.0.4) 62 | marcel (~> 1.0) 63 | mini_mime (>= 1.1.0) 64 | activesupport (7.0.4) 65 | concurrent-ruby (~> 1.0, >= 1.0.2) 66 | i18n (>= 1.6, < 2) 67 | minitest (>= 5.1) 68 | tzinfo (~> 2.0) 69 | bindex (0.8.1) 70 | bootsnap (1.15.0) 71 | msgpack (~> 1.2) 72 | builder (3.2.4) 73 | coderay (1.1.3) 74 | concurrent-ruby (1.1.10) 75 | crass (1.0.6) 76 | date (3.3.3) 77 | debug (1.7.1) 78 | irb (>= 1.5.0) 79 | reline (>= 0.3.1) 80 | diff-lcs (1.5.0) 81 | docile (1.4.0) 82 | erubi (1.12.0) 83 | ffi (1.15.5) 84 | formatador (1.1.0) 85 | globalid (1.0.0) 86 | activesupport (>= 5.0) 87 | guard (2.18.0) 88 | formatador (>= 0.2.4) 89 | listen (>= 2.7, < 4.0) 90 | lumberjack (>= 1.0.12, < 2.0) 91 | nenv (~> 0.1) 92 | notiffany (~> 0.0) 93 | pry (>= 0.13.0) 94 | shellany (~> 0.0) 95 | thor (>= 0.18.1) 96 | guard-compat (1.2.1) 97 | guard-rspec (4.7.3) 98 | guard (~> 2.1) 99 | guard-compat (~> 1.1) 100 | rspec (>= 2.99.0, < 4.0) 101 | i18n (1.12.0) 102 | concurrent-ruby (~> 1.0) 103 | importmap-rails (1.1.5) 104 | actionpack (>= 6.0.0) 105 | railties (>= 6.0.0) 106 | io-console (0.6.0) 107 | irb (1.6.2) 108 | reline (>= 0.3.0) 109 | jbuilder (2.11.5) 110 | actionview (>= 5.0.0) 111 | activesupport (>= 5.0.0) 112 | listen (3.7.1) 113 | rb-fsevent (~> 0.10, >= 0.10.3) 114 | rb-inotify (~> 0.9, >= 0.9.10) 115 | loofah (2.19.1) 116 | crass (~> 1.0.2) 117 | nokogiri (>= 1.5.9) 118 | lumberjack (1.2.8) 119 | mail (2.8.0) 120 | mini_mime (>= 0.1.1) 121 | net-imap 122 | net-pop 123 | net-smtp 124 | marcel (1.0.2) 125 | method_source (1.0.0) 126 | mini_mime (1.1.2) 127 | minitest (5.17.0) 128 | msgpack (1.6.0) 129 | nenv (0.3.0) 130 | net-imap (0.3.4) 131 | date 132 | net-protocol 133 | net-pop (0.1.2) 134 | net-protocol 135 | net-protocol (0.2.1) 136 | timeout 137 | net-smtp (0.3.3) 138 | net-protocol 139 | nio4r (2.5.8) 140 | nokogiri (1.13.10-arm64-darwin) 141 | racc (~> 1.4) 142 | nokogiri (1.13.10-x86_64-darwin) 143 | racc (~> 1.4) 144 | notiffany (0.1.3) 145 | nenv (~> 0.1) 146 | shellany (~> 0.0) 147 | pg (1.4.5) 148 | pry (0.14.1) 149 | coderay (~> 1.1) 150 | method_source (~> 1.0) 151 | puma (5.6.5) 152 | nio4r (~> 2.0) 153 | racc (1.6.2) 154 | rack (2.2.5) 155 | rack-test (2.0.2) 156 | rack (>= 1.3) 157 | rails (7.0.4) 158 | actioncable (= 7.0.4) 159 | actionmailbox (= 7.0.4) 160 | actionmailer (= 7.0.4) 161 | actionpack (= 7.0.4) 162 | actiontext (= 7.0.4) 163 | actionview (= 7.0.4) 164 | activejob (= 7.0.4) 165 | activemodel (= 7.0.4) 166 | activerecord (= 7.0.4) 167 | activestorage (= 7.0.4) 168 | activesupport (= 7.0.4) 169 | bundler (>= 1.15.0) 170 | railties (= 7.0.4) 171 | rails-dom-testing (2.0.3) 172 | activesupport (>= 4.2.0) 173 | nokogiri (>= 1.6) 174 | rails-html-sanitizer (1.4.4) 175 | loofah (~> 2.19, >= 2.19.1) 176 | railties (7.0.4) 177 | actionpack (= 7.0.4) 178 | activesupport (= 7.0.4) 179 | method_source 180 | rake (>= 12.2) 181 | thor (~> 1.0) 182 | zeitwerk (~> 2.5) 183 | rake (13.0.6) 184 | rb-fsevent (0.11.2) 185 | rb-inotify (0.10.1) 186 | ffi (~> 1.0) 187 | redis (4.8.0) 188 | reline (0.3.2) 189 | io-console (~> 0.5) 190 | rspec (3.12.0) 191 | rspec-core (~> 3.12.0) 192 | rspec-expectations (~> 3.12.0) 193 | rspec-mocks (~> 3.12.0) 194 | rspec-core (3.12.0) 195 | rspec-support (~> 3.12.0) 196 | rspec-expectations (3.12.1) 197 | diff-lcs (>= 1.2.0, < 2.0) 198 | rspec-support (~> 3.12.0) 199 | rspec-mocks (3.12.1) 200 | diff-lcs (>= 1.2.0, < 2.0) 201 | rspec-support (~> 3.12.0) 202 | rspec-rails (6.0.1) 203 | actionpack (>= 6.1) 204 | activesupport (>= 6.1) 205 | railties (>= 6.1) 206 | rspec-core (~> 3.11) 207 | rspec-expectations (~> 3.11) 208 | rspec-mocks (~> 3.11) 209 | rspec-support (~> 3.11) 210 | rspec-support (3.12.0) 211 | shellany (0.0.1) 212 | simplecov (0.22.0) 213 | docile (~> 1.1) 214 | simplecov-html (~> 0.11) 215 | simplecov_json_formatter (~> 0.1) 216 | simplecov-html (0.12.3) 217 | simplecov_json_formatter (0.1.4) 218 | sprockets (4.2.0) 219 | concurrent-ruby (~> 1.0) 220 | rack (>= 2.2.4, < 4) 221 | sprockets-rails (3.4.2) 222 | actionpack (>= 5.2) 223 | activesupport (>= 5.2) 224 | sprockets (>= 3.0.0) 225 | stimulus-rails (1.2.1) 226 | railties (>= 6.0.0) 227 | thor (1.2.1) 228 | timeout (0.3.1) 229 | turbo-rails (1.3.2) 230 | actionpack (>= 6.0.0) 231 | activejob (>= 6.0.0) 232 | railties (>= 6.0.0) 233 | tzinfo (2.0.5) 234 | concurrent-ruby (~> 1.0) 235 | web-console (4.2.0) 236 | actionview (>= 6.0.0) 237 | activemodel (>= 6.0.0) 238 | bindex (>= 0.4.0) 239 | railties (>= 6.0.0) 240 | websocket-driver (0.7.5) 241 | websocket-extensions (>= 0.1.0) 242 | websocket-extensions (0.1.5) 243 | zeitwerk (2.6.6) 244 | 245 | PLATFORMS 246 | arm64-darwin-21 247 | x86_64-darwin-21 248 | 249 | DEPENDENCIES 250 | bootsnap 251 | debug 252 | guard 253 | guard-rspec 254 | importmap-rails 255 | jbuilder 256 | pg (~> 1.1) 257 | puma (~> 5.0) 258 | rails (~> 7) 259 | redis (~> 4.0) 260 | rspec-rails (~> 6.0.0) 261 | simplecov 262 | sprockets-rails 263 | stimulus-rails 264 | turbo-rails 265 | tzinfo-data 266 | web-console 267 | 268 | RUBY VERSION 269 | ruby 3.1.2p20 270 | 271 | BUNDLED WITH 272 | 2.3.7 273 | -------------------------------------------------------------------------------- /Guardfile: -------------------------------------------------------------------------------- 1 | # A sample Guardfile 2 | # More info at https://github.com/guard/guard#readme 3 | 4 | ## Uncomment and set this to only include directories you want to watch 5 | # directories %w(app lib config test spec features) \ 6 | # .select{|d| Dir.exist?(d) ? d : UI.warning("Directory #{d} does not exist")} 7 | 8 | ## Note: if you are using the `directories` clause above and you are not 9 | ## watching the project directory ('.'), then you will want to move 10 | ## the Guardfile to a watched dir and symlink it back, e.g. 11 | # 12 | # $ mkdir config 13 | # $ mv Guardfile config/ 14 | # $ ln -s config/Guardfile . 15 | # 16 | # and, you'll have to watch "config/Guardfile" instead of "Guardfile" 17 | 18 | # Note: The cmd option is now required due to the increasing number of ways 19 | # rspec may be run, below are examples of the most common uses. 20 | # * bundler: 'bundle exec rspec' 21 | # * bundler binstubs: 'bin/rspec' 22 | # * spring: 'bin/rspec' (This will use spring if running and you have 23 | # installed the spring binstubs per the docs) 24 | # * zeus: 'zeus rspec' (requires the server to be started separately) 25 | # * 'just' rspec: 'rspec' 26 | 27 | guard :rspec, cmd: "bundle exec rspec" do 28 | require "guard/rspec/dsl" 29 | dsl = Guard::RSpec::Dsl.new(self) 30 | 31 | # Feel free to open issues for suggestions and improvements 32 | 33 | # RSpec files 34 | rspec = dsl.rspec 35 | watch(rspec.spec_helper) { rspec.spec_dir } 36 | watch(rspec.spec_support) { rspec.spec_dir } 37 | watch(rspec.spec_files) 38 | 39 | # Ruby files 40 | ruby = dsl.ruby 41 | dsl.watch_spec_files_for(ruby.lib_files) 42 | 43 | # Rails files 44 | rails = dsl.rails(view_extensions: %w(erb haml slim)) 45 | dsl.watch_spec_files_for(rails.app_files) 46 | dsl.watch_spec_files_for(rails.views) 47 | 48 | watch(rails.controllers) do |m| 49 | [ 50 | rspec.spec.call("routing/#{m[1]}_routing"), 51 | rspec.spec.call("controllers/#{m[1]}_controller"), 52 | rspec.spec.call("acceptance/#{m[1]}") 53 | ] 54 | end 55 | 56 | # Rails config changes 57 | watch(rails.spec_helper) { rspec.spec_dir } 58 | watch(rails.routes) { "#{rspec.spec_dir}/routing" } 59 | watch(rails.app_controller) { "#{rspec.spec_dir}/controllers" } 60 | 61 | # Capybara features specs 62 | watch(rails.view_dirs) { |m| rspec.spec.call("features/#{m[1]}") } 63 | watch(rails.layouts) { |m| rspec.spec.call("features/#{m[1]}") } 64 | 65 | # Turnip features and steps 66 | watch(%r{^spec/acceptance/(.+)\.feature$}) 67 | watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) do |m| 68 | Dir[File.join("**/#{m[1]}.feature")][0] || "spec/acceptance" 69 | end 70 | end 71 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Paweł Strzałkowski 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # DDD example in Ruby on Rails 2 | 3 | This is a PoC application for implementing elements of Domain-Driven Design inside of a plain Ruby on Rails application. 4 | 5 | THIS IS NOT PRODUCTION-LEVEL CODE. Its purpose is to serve as a validation of ideas and a discussion starting point. 6 | 7 | ## Identified Subdomains and implemented Bounded Contexts 8 | 9 | ### DragonHunt 10 | Our company organises raids on dragons. But we need to assemble the parties first 11 | 12 | ### CooperationNegotiation 13 | Before a party is assembled, its leader needs to negotiate a contract. The contract signature is the defining moment for the party to be assembled. 14 | 15 | ## Implemented scenario, joining two contexts 16 | 17 | It implements a simple scenario (using ubiquitous languages for each of the domains): 18 | - start negotiation by preparing a draft contract 19 | - modify text of the contract to satisfy the client and the company 20 | - the contract, in its final text form, needs to be signed by the client 21 | - the contract, in its final text form, needs to be signed by the company 22 | - when both sides sign the contract, it cannot be modified further 23 | - signed contracts can be listed, including the text of contract and the time it has been signed 24 | - when the contract is signed by both sides, a party is assembled in the DragonHunt context 25 | 26 | ## Used DDD features 27 | 28 | - contexts defined as modules inside of `app/modules/` folder 29 | - layers defined in each modules within `application|domain|infrastructure` folders 30 | - repositories put into `infrastructure` layer 31 | - persistance models put into `infrastructure` layer and translated into/out of domain models using repositories 32 | - application services for each possible action within `cooperation_negotiation` context 33 | - domain objects defined as POROs 34 | - domain events defined as POROs 35 | - domain events handled synchronously and used for cross-context communication 36 | - factory methods defined on domain objects 37 | - read models 38 | 39 | ## Installation 40 | 41 | ```sh 42 | rails db:create 43 | rails db:migrate 44 | 45 | rails db:seed 46 | ``` 47 | 48 | ## Reply all test scenarios with 49 | 50 | ``` 51 | rails db:seed:replant 52 | ``` 53 | 54 | ## Testing 55 | 56 | The project uses Rspec as its testing framework. Run 57 | ``` 58 | rspec 59 | ``` 60 | to run all tests. 61 | 62 | For continues testing during development you may use Guard with 63 | ``` 64 | guard 65 | ``` 66 | 67 | ## Future plans 68 | 69 | - I'm thinking about adding some controllers and frontend to show that it can operate as a normal application. 70 | 71 | ## Enjoy 72 | Please let me know if you see anything you like, don't like or think can be done better 73 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | # Add your own tasks in files placed in lib/tasks ending in .rake, 2 | # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. 3 | 4 | require_relative "config/application" 5 | 6 | Rails.application.load_tasks 7 | -------------------------------------------------------------------------------- /app/assets/config/manifest.js: -------------------------------------------------------------------------------- 1 | //= link_tree ../images 2 | //= link_directory ../stylesheets .css 3 | //= link_tree ../../javascript .js 4 | //= link_tree ../../../vendor/javascript .js 5 | -------------------------------------------------------------------------------- /app/assets/images/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pstrzalk/ddd-example-in-ruby-on-rails/46d1bbfc84aaf9c4d55cae814a33fb385eb6432f/app/assets/images/.keep -------------------------------------------------------------------------------- /app/assets/stylesheets/application.css: -------------------------------------------------------------------------------- 1 | /* 2 | * This is a manifest file that'll be compiled into application.css, which will include all the files 3 | * listed below. 4 | * 5 | * Any CSS (and SCSS, if configured) file within this directory, lib/assets/stylesheets, or any plugin's 6 | * vendor/assets/stylesheets directory can be referenced here using a relative path. 7 | * 8 | * You're free to add application-wide styles to this file and they'll appear at the bottom of the 9 | * compiled file so the styles you add here take precedence over styles defined in any other CSS 10 | * files in this directory. Styles in this file should be added after the last require_* statement. 11 | * It is generally better to create a new file per style scope. 12 | * 13 | *= require_tree . 14 | *= require_self 15 | */ 16 | -------------------------------------------------------------------------------- /app/channels/application_cable/channel.rb: -------------------------------------------------------------------------------- 1 | module ApplicationCable 2 | class Channel < ActionCable::Channel::Base 3 | end 4 | end 5 | -------------------------------------------------------------------------------- /app/channels/application_cable/connection.rb: -------------------------------------------------------------------------------- 1 | module ApplicationCable 2 | class Connection < ActionCable::Connection::Base 3 | end 4 | end 5 | -------------------------------------------------------------------------------- /app/controllers/application_controller.rb: -------------------------------------------------------------------------------- 1 | class ApplicationController < ActionController::Base 2 | private 3 | 4 | def current_identity 5 | cookies.permanent[:identity] 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /app/controllers/concerns/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pstrzalk/ddd-example-in-ruby-on-rails/46d1bbfc84aaf9c4d55cae814a33fb385eb6432f/app/controllers/concerns/.keep -------------------------------------------------------------------------------- /app/helpers/application_helper.rb: -------------------------------------------------------------------------------- 1 | module ApplicationHelper 2 | end 3 | -------------------------------------------------------------------------------- /app/javascript/application.js: -------------------------------------------------------------------------------- 1 | // Configure your import map in config/importmap.rb. Read more: https://github.com/rails/importmap-rails 2 | import "@hotwired/turbo-rails" 3 | import "controllers" 4 | -------------------------------------------------------------------------------- /app/javascript/controllers/application.js: -------------------------------------------------------------------------------- 1 | import { Application } from "@hotwired/stimulus" 2 | 3 | const application = Application.start() 4 | 5 | // Configure Stimulus development experience 6 | application.debug = false 7 | window.Stimulus = application 8 | 9 | export { application } 10 | -------------------------------------------------------------------------------- /app/javascript/controllers/hello_controller.js: -------------------------------------------------------------------------------- 1 | import { Controller } from "@hotwired/stimulus" 2 | 3 | export default class extends Controller { 4 | connect() { 5 | this.element.textContent = "Hello World!" 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /app/javascript/controllers/index.js: -------------------------------------------------------------------------------- 1 | // Import and register all your controllers from the importmap under controllers/* 2 | 3 | import { application } from "controllers/application" 4 | 5 | // Eager load all controllers defined in the import map under controllers/**/*_controller 6 | import { eagerLoadControllersFrom } from "@hotwired/stimulus-loading" 7 | eagerLoadControllersFrom("controllers", application) 8 | 9 | // Lazy load controllers as they appear in the DOM (remember not to preload controllers in import map!) 10 | // import { lazyLoadControllersFrom } from "@hotwired/stimulus-loading" 11 | // lazyLoadControllersFrom("controllers", application) 12 | -------------------------------------------------------------------------------- /app/jobs/application_job.rb: -------------------------------------------------------------------------------- 1 | class ApplicationJob < ActiveJob::Base 2 | # Automatically retry jobs that encountered a deadlock 3 | # retry_on ActiveRecord::Deadlocked 4 | 5 | # Most jobs are safe to ignore if the underlying records are no longer available 6 | # discard_on ActiveJob::DeserializationError 7 | end 8 | -------------------------------------------------------------------------------- /app/lib/autowired_repository.rb: -------------------------------------------------------------------------------- 1 | module AutowiredRepository 2 | # Solution inspired by Java's Hibernate annotiations, which allow using repositories as domain objects 3 | # The domain objects are automatically replaced with implementations on usage 4 | # Example may be found in https://github.com/VaughnVernon/IDDD_Samples - implementation of examples from the Red Book 5 | 6 | # Java Example description 7 | # Application layer uses repository as a domain object 8 | # https://github.com/VaughnVernon/IDDD_Samples/blob/master/iddd_identityaccess/src/main/java/com/saasovation/identityaccess/application/AccessApplicationService.java#L25 9 | # Even though this domain object is just an interface 10 | # https://github.com/VaughnVernon/IDDD_Samples/blob/master/iddd_identityaccess/src/main/java/com/saasovation/identityaccess/domain/model/identity/GroupRepository.java 11 | # The repository is automatically wired to inMemory implementation in test env 12 | # https://github.com/VaughnVernon/IDDD_Samples/blob/master/iddd_identityaccess/src/test/resources/applicationContext-identityaccess-test.xml#L35 13 | # The repository is automatically wired to Hibernate implementation in other envs 14 | # https://github.com/VaughnVernon/IDDD_Samples/blob/master/iddd_identityaccess/src/main/resources/applicationContext-identityaccess.xml#L33 15 | 16 | def get 17 | self.name.gsub('::Domain::', "::Infrastructure::#{wire_type}").constantize.new 18 | end 19 | 20 | # This way of defining repository implementations doesn't scale well for a bigger application 21 | # However, this is just an example - this may be done with JSONs, YMLs, meta programing or any other solution 22 | def wire_type 23 | return 'Db' unless Rails.env.test? 24 | 25 | if self.name == 'CooperationNegotiation::Domain::ContractRepository' 26 | 'InMemory' 27 | else 28 | 'Db' 29 | end 30 | end 31 | end 32 | -------------------------------------------------------------------------------- /app/lib/clock.rb: -------------------------------------------------------------------------------- 1 | class Clock < Time 2 | def self.utc 3 | @utc_time || Time.now.utc.to_s 4 | end 5 | 6 | def self.utc=(utc_time) 7 | @utc_time = utc_time 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /app/lib/event_store.rb: -------------------------------------------------------------------------------- 1 | module EventStore 2 | HANDLERS = { 3 | 'CooperationNegotiation::Domain::Events::ContractSigned' => [ 4 | 'DragonHunt::Application::Handlers::CooperationNegotiation::ContractSigned', 5 | 'ReadModelHandler' 6 | ] 7 | }.freeze 8 | 9 | class Write 10 | def call(event) 11 | handlers = HANDLERS[event.class.name] 12 | return unless handlers 13 | 14 | handlers.each do |handler_class_name| 15 | handler_class_name.constantize.call(event) 16 | end 17 | end 18 | end 19 | 20 | module Substitute 21 | class Write 22 | attr_reader :written 23 | 24 | def initialize 25 | @written = [] 26 | end 27 | 28 | def call(event) 29 | handlers = HANDLERS[event.class.name] 30 | return unless handlers 31 | 32 | @written ||= [] 33 | @written << event 34 | end 35 | end 36 | end 37 | end 38 | -------------------------------------------------------------------------------- /app/lib/read_model_handler.rb: -------------------------------------------------------------------------------- 1 | class ReadModelHandler 2 | DEFINITIONS = { 3 | 'CooperationNegotiation::Domain::Events::ContractSigned' => [ 4 | { 5 | model: ReadModels::SignedContract, 6 | identity_attribute: 'contract_id', 7 | event_read_model_attribute_map: { 8 | client_id: 'client_id', 9 | text: 'text', 10 | time: 'created_at' 11 | } 12 | } 13 | ] 14 | }.freeze 15 | 16 | def self.call(event) 17 | definitions = DEFINITIONS[event.class.name] 18 | return unless definitions 19 | 20 | definitions.each do |definition| 21 | read_model_attributes = definition[:event_read_model_attribute_map].to_h do |event_key, read_model_key| 22 | [read_model_key, event.public_send(event_key)] 23 | end 24 | 25 | definition[:model].save_record( 26 | event.public_send(definition[:identity_attribute]), 27 | read_model_attributes 28 | ) 29 | end 30 | end 31 | end 32 | -------------------------------------------------------------------------------- /app/mailers/application_mailer.rb: -------------------------------------------------------------------------------- 1 | class ApplicationMailer < ActionMailer::Base 2 | default from: "from@example.com" 3 | layout "mailer" 4 | end 5 | -------------------------------------------------------------------------------- /app/models/application_record.rb: -------------------------------------------------------------------------------- 1 | class ApplicationRecord < ActiveRecord::Base 2 | primary_abstract_class 3 | end 4 | -------------------------------------------------------------------------------- /app/models/concerns/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pstrzalk/ddd-example-in-ruby-on-rails/46d1bbfc84aaf9c4d55cae814a33fb385eb6432f/app/models/concerns/.keep -------------------------------------------------------------------------------- /app/models/read_models/signed_contract.rb: -------------------------------------------------------------------------------- 1 | module ReadModels 2 | class SignedContract < ApplicationRecord 3 | def self.table_name 4 | 'read_models_signed_contracts' 5 | end 6 | 7 | def self.save_record(contract_id, attributes = {}) 8 | attributes_with_unique_identity = attributes.merge(id: contract_id) 9 | 10 | upsert( 11 | attributes_with_unique_identity, 12 | unique_by: :id 13 | ) 14 | end 15 | end 16 | end 17 | -------------------------------------------------------------------------------- /app/modules/authorization/application/api.rb: -------------------------------------------------------------------------------- 1 | module Authorization 2 | module Application 3 | class Api 4 | def self.identity_in_role?(identity, role_name) 5 | return true if identity == '00000000-0000-0000-0000-000000000001' && role_name == 'admin' 6 | return true if identity.to_s.match(/\h{8}-(\h{4}-){3}\h{12}/) && role_name == 'client' 7 | 8 | false 9 | end 10 | end 11 | end 12 | end 13 | -------------------------------------------------------------------------------- /app/modules/commons/domain/with_events.rb: -------------------------------------------------------------------------------- 1 | module Commons 2 | module Domain 3 | module WithEvents 4 | def dispatch_event(event) 5 | self.uncommitted_events ||= [] 6 | 7 | uncommitted_events << event 8 | end 9 | 10 | def clear_uncommited_events 11 | self.uncommitted_events = [] 12 | end 13 | 14 | def uncommited_events 15 | uncommitted_events&.dup || [] 16 | end 17 | 18 | private 19 | 20 | attr_accessor :uncommitted_events 21 | end 22 | end 23 | end 24 | -------------------------------------------------------------------------------- /app/modules/cooperation_negotiation/application/controllers/contract_controller.rb: -------------------------------------------------------------------------------- 1 | module CooperationNegotiation 2 | module Application 3 | module Controllers 4 | class ContractController < ::ApplicationController 5 | def prepare_draft 6 | service = Services::PrepareDraftContract.new 7 | service.call(current_identity, params[:client_id]) 8 | 9 | render :ok 10 | end 11 | end 12 | end 13 | end 14 | end 15 | -------------------------------------------------------------------------------- /app/modules/cooperation_negotiation/application/services/modify_contract_text.rb: -------------------------------------------------------------------------------- 1 | module CooperationNegotiation 2 | module Application 3 | module Services 4 | class ModifyContractText 5 | def initialize 6 | self.repository = Domain::ContractRepository.get 7 | end 8 | 9 | def call(contract_id:, text:) 10 | contract = repository.of_id(contract_id) 11 | contract.modify_text(text) 12 | 13 | repository.save(contract) 14 | end 15 | 16 | private 17 | 18 | attr_accessor :repository 19 | end 20 | end 21 | end 22 | end 23 | -------------------------------------------------------------------------------- /app/modules/cooperation_negotiation/application/services/prepare_draft_contract.rb: -------------------------------------------------------------------------------- 1 | module CooperationNegotiation 2 | module Application 3 | module Services 4 | class PrepareDraftContract 5 | Unauthorized = Class.new(StandardError) 6 | 7 | def initialize 8 | self.repository = Domain::ContractRepository.get 9 | end 10 | 11 | def call(identity:, client_id:) 12 | # move this authorization API call into domain somehow. It should be domain's decission to allow only admins 13 | # example in IDDD - collaboratorService is 14 | # import com.saasovation.collaboration.domain.model.collaborator.CollaboratorService; 15 | raise Unauthorized unless Authorization::Application::Api.identity_in_role?(identity, 'admin') 16 | 17 | contract = Domain::Contract.prepare_draft(client_id:) 18 | 19 | repository.save(contract) 20 | end 21 | 22 | private 23 | 24 | attr_accessor :repository 25 | end 26 | end 27 | end 28 | end 29 | -------------------------------------------------------------------------------- /app/modules/cooperation_negotiation/application/services/sign_contract_by_client.rb: -------------------------------------------------------------------------------- 1 | module CooperationNegotiation 2 | module Application 3 | module Services 4 | class SignContractByClient 5 | def initialize 6 | self.repository = Domain::ContractRepository.get 7 | end 8 | 9 | def call(contract_id:) 10 | contract = repository.of_id(contract_id) 11 | contract.sign_by_client 12 | 13 | repository.save(contract) 14 | end 15 | 16 | private 17 | 18 | attr_accessor :repository 19 | end 20 | end 21 | end 22 | end 23 | -------------------------------------------------------------------------------- /app/modules/cooperation_negotiation/application/services/sign_contract_by_company.rb: -------------------------------------------------------------------------------- 1 | module CooperationNegotiation 2 | module Application 3 | module Services 4 | class SignContractByCompany 5 | def initialize 6 | self.repository = Domain::ContractRepository.get 7 | end 8 | 9 | def call(contract_id:) 10 | contract = repository.of_id(contract_id) 11 | contract.sign_by_company 12 | 13 | repository.save(contract) 14 | end 15 | 16 | private 17 | 18 | attr_accessor :repository 19 | end 20 | end 21 | end 22 | end 23 | -------------------------------------------------------------------------------- /app/modules/cooperation_negotiation/domain/contract.rb: -------------------------------------------------------------------------------- 1 | module CooperationNegotiation 2 | module Domain 3 | class Contract 4 | include Commons::Domain::WithEvents 5 | 6 | AlreadySignedError = Class.new(StandardError) 7 | AlreadySignedByClientError = Class.new(StandardError) 8 | AlreadySignedByCompanyError = Class.new(StandardError) 9 | 10 | attr_reader :id, :client_id, :text 11 | 12 | def self.prepare_draft(client_id:) 13 | contract = new(client_id: client_id) 14 | 15 | event = Events::ContractDraftPrepared.new 16 | event.client_id = client_id 17 | event.time = ::Clock.utc 18 | contract.send(:dispatch_event, event) 19 | 20 | contract 21 | end 22 | 23 | def initialize(client_id:, id: nil) 24 | self.id = id 25 | self.client_id = client_id 26 | self.text = '' 27 | self.client_signature = false 28 | self.company_signature = false 29 | end 30 | 31 | def sign_by_client 32 | raise AlreadySignedByClientError if client_signature 33 | 34 | self.client_signature = true 35 | 36 | dispatch_signature_event 37 | end 38 | 39 | def signed_by_client? 40 | self.client_signature 41 | end 42 | 43 | def sign_by_company 44 | raise AlreadySignedByCompanyError if company_signature 45 | 46 | self.company_signature = true 47 | 48 | dispatch_signature_event 49 | end 50 | 51 | def signed_by_company? 52 | self.company_signature 53 | end 54 | 55 | def modify_text(new_text) 56 | raise AlreadySignedError if signed? 57 | 58 | self.text = new_text 59 | self.client_signature = false 60 | self.company_signature = false 61 | 62 | event = Events::ContractTextModified.new 63 | event.text = new_text 64 | event.time = ::Clock.utc 65 | dispatch_event(event) 66 | end 67 | 68 | private 69 | 70 | def signed? 71 | signed_by_client? && signed_by_company? 72 | end 73 | 74 | def dispatch_signature_event 75 | return unless signed? 76 | 77 | event = Events::ContractSigned.new 78 | event.client_id = client_id 79 | event.text = text 80 | event.time = ::Clock.utc 81 | dispatch_event(event) 82 | end 83 | 84 | attr_writer :id, :client_id, :text 85 | attr_accessor :client_signature, :company_signature 86 | end 87 | end 88 | end 89 | -------------------------------------------------------------------------------- /app/modules/cooperation_negotiation/domain/contract_repository.rb: -------------------------------------------------------------------------------- 1 | module CooperationNegotiation 2 | module Domain 3 | class ContractRepository 4 | extend AutowiredRepository 5 | end 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /app/modules/cooperation_negotiation/domain/events/contract_draft_prepared.rb: -------------------------------------------------------------------------------- 1 | module CooperationNegotiation 2 | module Domain 3 | module Events 4 | class ContractDraftPrepared 5 | attr_accessor :client_id, :contract_id, :time 6 | end 7 | end 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /app/modules/cooperation_negotiation/domain/events/contract_signed.rb: -------------------------------------------------------------------------------- 1 | module CooperationNegotiation 2 | module Domain 3 | module Events 4 | class ContractSigned 5 | attr_accessor :contract_id, :client_id, :text, :time 6 | end 7 | end 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /app/modules/cooperation_negotiation/domain/events/contract_text_modified.rb: -------------------------------------------------------------------------------- 1 | module CooperationNegotiation 2 | module Domain 3 | module Events 4 | class ContractTextModified 5 | attr_accessor :text, :contract_id, :time 6 | end 7 | end 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /app/modules/cooperation_negotiation/infrastructure/db_contract.rb: -------------------------------------------------------------------------------- 1 | module CooperationNegotiation 2 | module Infrastructure 3 | class DbContract < ApplicationRecord 4 | def self.table_name 5 | 'cooperation_negotiation_contracts' 6 | end 7 | end 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /app/modules/cooperation_negotiation/infrastructure/db_contract_repository.rb: -------------------------------------------------------------------------------- 1 | module CooperationNegotiation 2 | module Infrastructure 3 | class DbContractRepository 4 | attr_reader :event_store_write 5 | 6 | def initialize(event_store_write: ::EventStore::Write.new) 7 | @event_store_write = event_store_write 8 | end 9 | 10 | def of_id(id) 11 | db_contract = DbContract.find_by(id: id) 12 | return unless db_contract 13 | 14 | build_from_db_contract(db_contract) 15 | end 16 | 17 | def of_client_id(client_id) 18 | db_contract = DbContract.find_by(client_id: client_id) 19 | return unless db_contract 20 | 21 | build_from_db_contract(db_contract) 22 | end 23 | 24 | def save(contract) 25 | db_contract = DbContract.find_by(id: contract.id) if contract.id 26 | db_contract ||= DbContract.new(id: contract.id) 27 | 28 | db_contract.assign_attributes( 29 | client_id: contract.send(:client_id), 30 | text: contract.send(:text), 31 | client_signature: contract.send(:client_signature), 32 | company_signature: contract.send(:company_signature) 33 | ) 34 | 35 | ActiveRecord::Base.transaction do 36 | db_contract.save! 37 | 38 | commit_events(contract) 39 | end 40 | 41 | contract.send('id=', db_contract.id) 42 | end 43 | 44 | private 45 | 46 | def build_from_db_contract(db_contract) 47 | contract = Domain::Contract.new(id: db_contract.id, client_id: db_contract.client_id) 48 | contract.send('text=', db_contract.text) 49 | contract.send('client_signature=', db_contract.client_signature) 50 | contract.send('company_signature=', db_contract.company_signature) 51 | 52 | contract 53 | end 54 | 55 | def commit_events(contract) 56 | return if contract.uncommited_events.blank? 57 | 58 | contract.uncommited_events.each do |event| 59 | event.contract_id = contract.id 60 | 61 | @event_store_write.call(event) 62 | end 63 | 64 | contract.clear_uncommited_events 65 | end 66 | end 67 | end 68 | end 69 | -------------------------------------------------------------------------------- /app/modules/cooperation_negotiation/infrastructure/in_memory_contract_repository.rb: -------------------------------------------------------------------------------- 1 | module CooperationNegotiation 2 | module Infrastructure 3 | class InMemoryContractRepository 4 | attr_reader :event_store_write, :memory 5 | 6 | def initialize(event_store_write: ::EventStore::Write.new) 7 | @event_store_write = event_store_write 8 | @@memory ||= {} 9 | end 10 | 11 | def of_id(id) 12 | @@memory[id] 13 | end 14 | 15 | def of_client_id(client_id) 16 | @@memory.each do |id, contract| 17 | return contract if contract.client_id == client_id 18 | end 19 | 20 | nil 21 | end 22 | 23 | def save(contract) 24 | id = next_identity 25 | 26 | contract.send('id=', id) 27 | 28 | @@memory[id] = contract 29 | commit_events(contract) 30 | end 31 | 32 | private 33 | 34 | def next_identity 35 | SecureRandom.uuid 36 | end 37 | 38 | def commit_events(contract) 39 | return if contract.uncommited_events.blank? 40 | 41 | contract.uncommited_events.each do |event| 42 | event.contract_id = contract.id 43 | 44 | @event_store_write.call(event) 45 | end 46 | 47 | contract.clear_uncommited_events 48 | end 49 | end 50 | end 51 | end 52 | -------------------------------------------------------------------------------- /app/modules/dragon_hunt/application/handlers/cooperation_negotiation/contract_signed.rb: -------------------------------------------------------------------------------- 1 | module DragonHunt 2 | module Application 3 | module Handlers 4 | module CooperationNegotiation 5 | class ContractSigned 6 | def self.call(event) 7 | repository = Domain::PartyRepository.get 8 | party = Domain::Party.assemble(client_id: event.client_id) 9 | 10 | repository.save(party) 11 | end 12 | end 13 | end 14 | end 15 | end 16 | end 17 | -------------------------------------------------------------------------------- /app/modules/dragon_hunt/domain/party.rb: -------------------------------------------------------------------------------- 1 | module DragonHunt 2 | module Domain 3 | class Party 4 | attr_reader :id, :client_id 5 | 6 | def self.assemble(client_id:) 7 | new(client_id: client_id) 8 | end 9 | 10 | def initialize(client_id:, id: nil) 11 | self.id = id 12 | self.client_id = client_id 13 | end 14 | 15 | def ==(other) 16 | id == other.id && client_id == other.client_id 17 | end 18 | 19 | private 20 | 21 | attr_writer :id, :client_id 22 | end 23 | end 24 | end 25 | -------------------------------------------------------------------------------- /app/modules/dragon_hunt/domain/party_repository.rb: -------------------------------------------------------------------------------- 1 | module DragonHunt 2 | module Domain 3 | class PartyRepository 4 | extend AutowiredRepository 5 | end 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /app/modules/dragon_hunt/infrastructure/db_party.rb: -------------------------------------------------------------------------------- 1 | module DragonHunt 2 | module Infrastructure 3 | class DbParty < ApplicationRecord 4 | def self.table_name 5 | 'dragon_hunt_parties' 6 | end 7 | end 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /app/modules/dragon_hunt/infrastructure/db_party_repository.rb: -------------------------------------------------------------------------------- 1 | module DragonHunt 2 | module Infrastructure 3 | class DbPartyRepository 4 | def of_id(id) 5 | db_party = DbParty.find_by(id:) 6 | return unless db_party 7 | 8 | Domain::Party.new(id: id, client_id: db_party.client_id) 9 | end 10 | 11 | def of_client_id(client_id) 12 | db_party = DbParty.find_by(client_id: client_id) 13 | return unless db_party 14 | 15 | Domain::Party.new(id: db_party.id, client_id: db_party.client_id) 16 | end 17 | 18 | def save(party) 19 | db_party = DbParty.find_by(id: party.id) if party.id 20 | db_party ||= DbParty.new(id: party.id) 21 | 22 | db_party.assign_attributes( 23 | client_id: party.send(:client_id), 24 | ) 25 | 26 | db_party.save! 27 | end 28 | end 29 | end 30 | end 31 | -------------------------------------------------------------------------------- /app/views/layouts/application.html.erb: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | DddExampleInRubyOnRails 5 | 6 | <%= csrf_meta_tags %> 7 | <%= csp_meta_tag %> 8 | 9 | <%= stylesheet_link_tag "application", "data-turbo-track": "reload" %> 10 | <%= javascript_importmap_tags %> 11 | 12 | 13 | 14 | <%= yield %> 15 | 16 | 17 | -------------------------------------------------------------------------------- /app/views/layouts/mailer.html.erb: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 8 | 9 | 10 | 11 | <%= yield %> 12 | 13 | 14 | -------------------------------------------------------------------------------- /app/views/layouts/mailer.text.erb: -------------------------------------------------------------------------------- 1 | <%= yield %> 2 | -------------------------------------------------------------------------------- /bin/bundle: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # frozen_string_literal: true 3 | 4 | # 5 | # This file was generated by Bundler. 6 | # 7 | # The application 'bundle' is installed as part of a gem, and 8 | # this file is here to facilitate running it. 9 | # 10 | 11 | require "rubygems" 12 | 13 | m = Module.new do 14 | module_function 15 | 16 | def invoked_as_script? 17 | File.expand_path($0) == File.expand_path(__FILE__) 18 | end 19 | 20 | def env_var_version 21 | ENV["BUNDLER_VERSION"] 22 | end 23 | 24 | def cli_arg_version 25 | return unless invoked_as_script? # don't want to hijack other binstubs 26 | return unless "update".start_with?(ARGV.first || " ") # must be running `bundle update` 27 | bundler_version = nil 28 | update_index = nil 29 | ARGV.each_with_index do |a, i| 30 | if update_index && update_index.succ == i && a =~ Gem::Version::ANCHORED_VERSION_PATTERN 31 | bundler_version = a 32 | end 33 | next unless a =~ /\A--bundler(?:[= ](#{Gem::Version::VERSION_PATTERN}))?\z/ 34 | bundler_version = $1 35 | update_index = i 36 | end 37 | bundler_version 38 | end 39 | 40 | def gemfile 41 | gemfile = ENV["BUNDLE_GEMFILE"] 42 | return gemfile if gemfile && !gemfile.empty? 43 | 44 | File.expand_path("../Gemfile", __dir__) 45 | end 46 | 47 | def lockfile 48 | lockfile = 49 | case File.basename(gemfile) 50 | when "gems.rb" then gemfile.sub(/\.rb$/, gemfile) 51 | else "#{gemfile}.lock" 52 | end 53 | File.expand_path(lockfile) 54 | end 55 | 56 | def lockfile_version 57 | return unless File.file?(lockfile) 58 | lockfile_contents = File.read(lockfile) 59 | return unless lockfile_contents =~ /\n\nBUNDLED WITH\n\s{2,}(#{Gem::Version::VERSION_PATTERN})\n/ 60 | Regexp.last_match(1) 61 | end 62 | 63 | def bundler_requirement 64 | @bundler_requirement ||= 65 | env_var_version || cli_arg_version || 66 | bundler_requirement_for(lockfile_version) 67 | end 68 | 69 | def bundler_requirement_for(version) 70 | return "#{Gem::Requirement.default}.a" unless version 71 | 72 | bundler_gem_version = Gem::Version.new(version) 73 | 74 | requirement = bundler_gem_version.approximate_recommendation 75 | 76 | return requirement unless Gem.rubygems_version < Gem::Version.new("2.7.0") 77 | 78 | requirement += ".a" if bundler_gem_version.prerelease? 79 | 80 | requirement 81 | end 82 | 83 | def load_bundler! 84 | ENV["BUNDLE_GEMFILE"] ||= gemfile 85 | 86 | activate_bundler 87 | end 88 | 89 | def activate_bundler 90 | gem_error = activation_error_handling do 91 | gem "bundler", bundler_requirement 92 | end 93 | return if gem_error.nil? 94 | require_error = activation_error_handling do 95 | require "bundler/version" 96 | end 97 | return if require_error.nil? && Gem::Requirement.new(bundler_requirement).satisfied_by?(Gem::Version.new(Bundler::VERSION)) 98 | warn "Activating bundler (#{bundler_requirement}) failed:\n#{gem_error.message}\n\nTo install the version of bundler this project requires, run `gem install bundler -v '#{bundler_requirement}'`" 99 | exit 42 100 | end 101 | 102 | def activation_error_handling 103 | yield 104 | nil 105 | rescue StandardError, LoadError => e 106 | e 107 | end 108 | end 109 | 110 | m.load_bundler! 111 | 112 | if m.invoked_as_script? 113 | load Gem.bin_path("bundler", "bundle") 114 | end 115 | -------------------------------------------------------------------------------- /bin/importmap: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | require_relative "../config/application" 4 | require "importmap/commands" 5 | -------------------------------------------------------------------------------- /bin/rails: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | APP_PATH = File.expand_path("../config/application", __dir__) 3 | require_relative "../config/boot" 4 | require "rails/commands" 5 | -------------------------------------------------------------------------------- /bin/rake: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | require_relative "../config/boot" 3 | require "rake" 4 | Rake.application.run 5 | -------------------------------------------------------------------------------- /bin/setup: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | require "fileutils" 3 | 4 | # path to your application root. 5 | APP_ROOT = File.expand_path("..", __dir__) 6 | 7 | def system!(*args) 8 | system(*args) || abort("\n== Command #{args} failed ==") 9 | end 10 | 11 | FileUtils.chdir APP_ROOT do 12 | # This script is a way to set up or update your development environment automatically. 13 | # This script is idempotent, so that you can run it at any time and get an expectable outcome. 14 | # Add necessary setup steps to this file. 15 | 16 | puts "== Installing dependencies ==" 17 | system! "gem install bundler --conservative" 18 | system("bundle check") || system!("bundle install") 19 | 20 | # puts "\n== Copying sample files ==" 21 | # unless File.exist?("config/database.yml") 22 | # FileUtils.cp "config/database.yml.sample", "config/database.yml" 23 | # end 24 | 25 | puts "\n== Preparing database ==" 26 | system! "bin/rails db:prepare" 27 | 28 | puts "\n== Removing old logs and tempfiles ==" 29 | system! "bin/rails log:clear tmp:clear" 30 | 31 | puts "\n== Restarting application server ==" 32 | system! "bin/rails restart" 33 | end 34 | -------------------------------------------------------------------------------- /config.ru: -------------------------------------------------------------------------------- 1 | # This file is used by Rack-based servers to start the application. 2 | 3 | require_relative "config/environment" 4 | 5 | run Rails.application 6 | Rails.application.load_server 7 | -------------------------------------------------------------------------------- /config/application.rb: -------------------------------------------------------------------------------- 1 | require_relative "boot" 2 | 3 | require "rails" 4 | # Pick the frameworks you want: 5 | require "active_model/railtie" 6 | require "active_job/railtie" 7 | require "active_record/railtie" 8 | require "active_storage/engine" 9 | require "action_controller/railtie" 10 | require "action_mailer/railtie" 11 | require "action_mailbox/engine" 12 | require "action_text/engine" 13 | require "action_view/railtie" 14 | require "action_cable/engine" 15 | # require "rails/test_unit/railtie" 16 | 17 | # Require the gems listed in Gemfile, including any gems 18 | # you've limited to :test, :development, or :production. 19 | Bundler.require(*Rails.groups) 20 | 21 | module DddExampleInRubyOnRails 22 | class Application < Rails::Application 23 | # Initialize configuration defaults for originally generated Rails version. 24 | config.load_defaults 7.0 25 | 26 | # Configuration for the application, engines, and railties goes here. 27 | # 28 | # These settings can be overridden in specific environments using the files 29 | # in config/environments, which are processed later. 30 | # 31 | # config.time_zone = "Central Time (US & Canada)" 32 | # config.eager_load_paths << Rails.root.join("extras") 33 | 34 | # Don't generate system test files. 35 | config.generators.system_tests = nil 36 | end 37 | end 38 | -------------------------------------------------------------------------------- /config/boot.rb: -------------------------------------------------------------------------------- 1 | ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__) 2 | 3 | require "bundler/setup" # Set up gems listed in the Gemfile. 4 | require "bootsnap/setup" # Speed up boot time by caching expensive operations. 5 | -------------------------------------------------------------------------------- /config/cable.yml: -------------------------------------------------------------------------------- 1 | development: 2 | adapter: redis 3 | url: redis://localhost:6379/1 4 | 5 | test: 6 | adapter: test 7 | 8 | production: 9 | adapter: redis 10 | url: <%= ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" } %> 11 | channel_prefix: ddd_example_in_ruby_on_rails_production 12 | -------------------------------------------------------------------------------- /config/credentials.yml.enc: -------------------------------------------------------------------------------- 1 | LcG7+J94IULXj7H4zV9B8J2k5pIdin65273KbhUgn2R7iGA/zEk+zChXMtf63huh5O+Sy7DezusVYW42nFUEDYdmXnDCe2FDOLgh5eYHd8jY2/UaBhA9qdGzORCo8farVKsC9EsnHWADTnQphq7H/+JeKWIvwEkLYkyrNTMBEAUB6IXhbUzwfGgP8BOybvH5k3xUrQyF8qm9V/SVcoT+VCDQelrl6QI0tE1ShE1BpUZwI48I4juZ4MeWPfcADgy6JA4kyu81QMKQi+wHUwJFjaaRkeuEEbYCdugXkT3NyIu7p09uZ4r5Lhe3wA6+PJS43NRdxrXrBM4j3f3PTWOfN2uDZJWfvE4FE1m2NZ4euAeBLSKmvj2ITsJumdMVRniZ8+s2Rb4G7A1ZMLUxbfxnnlvQJBbVmrc86ga5--aaay0ZxcEwSDyZv5--UPiTeSey+HXDMCeG87sI3A== -------------------------------------------------------------------------------- /config/database.yml: -------------------------------------------------------------------------------- 1 | # PostgreSQL. Versions 9.3 and up are supported. 2 | # 3 | # Install the pg driver: 4 | # gem install pg 5 | # On macOS with Homebrew: 6 | # gem install pg -- --with-pg-config=/usr/local/bin/pg_config 7 | # On macOS with MacPorts: 8 | # gem install pg -- --with-pg-config=/opt/local/lib/postgresql84/bin/pg_config 9 | # On Windows: 10 | # gem install pg 11 | # Choose the win32 build. 12 | # Install PostgreSQL and put its /bin directory on your path. 13 | # 14 | # Configure Using Gemfile 15 | # gem "pg" 16 | # 17 | default: &default 18 | adapter: postgresql 19 | encoding: unicode 20 | # For details on connection pooling, see Rails configuration guide 21 | # https://guides.rubyonrails.org/configuring.html#database-pooling 22 | pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> 23 | 24 | development: 25 | <<: *default 26 | database: ddd_example_in_ruby_on_rails_development 27 | 28 | # The specified database role being used to connect to postgres. 29 | # To create additional roles in postgres see `$ createuser --help`. 30 | # When left blank, postgres will use the default role. This is 31 | # the same name as the operating system user running Rails. 32 | #username: ddd_example_in_ruby_on_rails 33 | 34 | # The password associated with the postgres role (username). 35 | #password: 36 | 37 | # Connect on a TCP socket. Omitted by default since the client uses a 38 | # domain socket that doesn't need configuration. Windows does not have 39 | # domain sockets, so uncomment these lines. 40 | #host: localhost 41 | 42 | # The TCP port the server listens on. Defaults to 5432. 43 | # If your server runs on a different port number, change accordingly. 44 | #port: 5432 45 | 46 | # Schema search path. The server defaults to $user,public 47 | #schema_search_path: myapp,sharedapp,public 48 | 49 | # Minimum log levels, in increasing order: 50 | # debug5, debug4, debug3, debug2, debug1, 51 | # log, notice, warning, error, fatal, and panic 52 | # Defaults to warning. 53 | #min_messages: notice 54 | 55 | # Warning: The database defined as "test" will be erased and 56 | # re-generated from your development database when you run "rake". 57 | # Do not set this db to the same as development or production. 58 | test: 59 | <<: *default 60 | database: ddd_example_in_ruby_on_rails_test 61 | 62 | # As with config/credentials.yml, you never want to store sensitive information, 63 | # like your database password, in your source code. If your source code is 64 | # ever seen by anyone, they now have access to your database. 65 | # 66 | # Instead, provide the password or a full connection URL as an environment 67 | # variable when you boot the app. For example: 68 | # 69 | # DATABASE_URL="postgres://myuser:mypass@localhost/somedatabase" 70 | # 71 | # If the connection URL is provided in the special DATABASE_URL environment 72 | # variable, Rails will automatically merge its configuration values on top of 73 | # the values provided in this file. Alternatively, you can specify a connection 74 | # URL environment variable explicitly: 75 | # 76 | # production: 77 | # url: <%= ENV["MY_APP_DATABASE_URL"] %> 78 | # 79 | # Read https://guides.rubyonrails.org/configuring.html#configuring-a-database 80 | # for a full overview on how database connection configuration can be specified. 81 | # 82 | production: 83 | <<: *default 84 | database: ddd_example_in_ruby_on_rails_production 85 | username: ddd_example_in_ruby_on_rails 86 | password: <%= ENV["DDD_EXAMPLE_IN_RUBY_ON_RAILS_DATABASE_PASSWORD"] %> 87 | -------------------------------------------------------------------------------- /config/environment.rb: -------------------------------------------------------------------------------- 1 | # Load the Rails application. 2 | require_relative "application" 3 | 4 | # Initialize the Rails application. 5 | Rails.application.initialize! 6 | -------------------------------------------------------------------------------- /config/environments/development.rb: -------------------------------------------------------------------------------- 1 | require "active_support/core_ext/integer/time" 2 | 3 | Rails.application.configure do 4 | # Settings specified here will take precedence over those in config/application.rb. 5 | 6 | # In the development environment your application's code is reloaded any time 7 | # it changes. This slows down response time but is perfect for development 8 | # since you don't have to restart the web server when you make code changes. 9 | config.cache_classes = false 10 | 11 | # Do not eager load code on boot. 12 | config.eager_load = false 13 | 14 | # Show full error reports. 15 | config.consider_all_requests_local = true 16 | 17 | # Enable server timing 18 | config.server_timing = true 19 | 20 | # Enable/disable caching. By default caching is disabled. 21 | # Run rails dev:cache to toggle caching. 22 | if Rails.root.join("tmp/caching-dev.txt").exist? 23 | config.action_controller.perform_caching = true 24 | config.action_controller.enable_fragment_cache_logging = true 25 | 26 | config.cache_store = :memory_store 27 | config.public_file_server.headers = { 28 | "Cache-Control" => "public, max-age=#{2.days.to_i}" 29 | } 30 | else 31 | config.action_controller.perform_caching = false 32 | 33 | config.cache_store = :null_store 34 | end 35 | 36 | # Store uploaded files on the local file system (see config/storage.yml for options). 37 | config.active_storage.service = :local 38 | 39 | # Don't care if the mailer can't send. 40 | config.action_mailer.raise_delivery_errors = false 41 | 42 | config.action_mailer.perform_caching = false 43 | 44 | # Print deprecation notices to the Rails logger. 45 | config.active_support.deprecation = :log 46 | 47 | # Raise exceptions for disallowed deprecations. 48 | config.active_support.disallowed_deprecation = :raise 49 | 50 | # Tell Active Support which deprecation messages to disallow. 51 | config.active_support.disallowed_deprecation_warnings = [] 52 | 53 | # Raise an error on page load if there are pending migrations. 54 | config.active_record.migration_error = :page_load 55 | 56 | # Highlight code that triggered database queries in logs. 57 | config.active_record.verbose_query_logs = true 58 | 59 | # Suppress logger output for asset requests. 60 | config.assets.quiet = true 61 | 62 | # Raises error for missing translations. 63 | # config.i18n.raise_on_missing_translations = true 64 | 65 | # Annotate rendered view with file names. 66 | # config.action_view.annotate_rendered_view_with_filenames = true 67 | 68 | # Uncomment if you wish to allow Action Cable access from any origin. 69 | # config.action_cable.disable_request_forgery_protection = true 70 | end 71 | -------------------------------------------------------------------------------- /config/environments/production.rb: -------------------------------------------------------------------------------- 1 | require "active_support/core_ext/integer/time" 2 | 3 | Rails.application.configure do 4 | # Settings specified here will take precedence over those in config/application.rb. 5 | 6 | # Code is not reloaded between requests. 7 | config.cache_classes = true 8 | 9 | # Eager load code on boot. This eager loads most of Rails and 10 | # your application in memory, allowing both threaded web servers 11 | # and those relying on copy on write to perform better. 12 | # Rake tasks automatically ignore this option for performance. 13 | config.eager_load = true 14 | 15 | # Full error reports are disabled and caching is turned on. 16 | config.consider_all_requests_local = false 17 | config.action_controller.perform_caching = true 18 | 19 | # Ensures that a master key has been made available in either ENV["RAILS_MASTER_KEY"] 20 | # or in config/master.key. This key is used to decrypt credentials (and other encrypted files). 21 | # config.require_master_key = true 22 | 23 | # Disable serving static files from the `/public` folder by default since 24 | # Apache or NGINX already handles this. 25 | config.public_file_server.enabled = ENV["RAILS_SERVE_STATIC_FILES"].present? 26 | 27 | # Compress CSS using a preprocessor. 28 | # config.assets.css_compressor = :sass 29 | 30 | # Do not fallback to assets pipeline if a precompiled asset is missed. 31 | config.assets.compile = false 32 | 33 | # Enable serving of images, stylesheets, and JavaScripts from an asset server. 34 | # config.asset_host = "http://assets.example.com" 35 | 36 | # Specifies the header that your server uses for sending files. 37 | # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for Apache 38 | # config.action_dispatch.x_sendfile_header = "X-Accel-Redirect" # for NGINX 39 | 40 | # Store uploaded files on the local file system (see config/storage.yml for options). 41 | config.active_storage.service = :local 42 | 43 | # Mount Action Cable outside main process or domain. 44 | # config.action_cable.mount_path = nil 45 | # config.action_cable.url = "wss://example.com/cable" 46 | # config.action_cable.allowed_request_origins = [ "http://example.com", /http:\/\/example.*/ ] 47 | 48 | # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. 49 | # config.force_ssl = true 50 | 51 | # Include generic and useful information about system operation, but avoid logging too much 52 | # information to avoid inadvertent exposure of personally identifiable information (PII). 53 | config.log_level = :info 54 | 55 | # Prepend all log lines with the following tags. 56 | config.log_tags = [ :request_id ] 57 | 58 | # Use a different cache store in production. 59 | # config.cache_store = :mem_cache_store 60 | 61 | # Use a real queuing backend for Active Job (and separate queues per environment). 62 | # config.active_job.queue_adapter = :resque 63 | # config.active_job.queue_name_prefix = "ddd_example_in_ruby_on_rails_production" 64 | 65 | config.action_mailer.perform_caching = false 66 | 67 | # Ignore bad email addresses and do not raise email delivery errors. 68 | # Set this to true and configure the email server for immediate delivery to raise delivery errors. 69 | # config.action_mailer.raise_delivery_errors = false 70 | 71 | # Enable locale fallbacks for I18n (makes lookups for any locale fall back to 72 | # the I18n.default_locale when a translation cannot be found). 73 | config.i18n.fallbacks = true 74 | 75 | # Don't log any deprecations. 76 | config.active_support.report_deprecations = false 77 | 78 | # Use default logging formatter so that PID and timestamp are not suppressed. 79 | config.log_formatter = ::Logger::Formatter.new 80 | 81 | # Use a different logger for distributed setups. 82 | # require "syslog/logger" 83 | # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new "app-name") 84 | 85 | if ENV["RAILS_LOG_TO_STDOUT"].present? 86 | logger = ActiveSupport::Logger.new(STDOUT) 87 | logger.formatter = config.log_formatter 88 | config.logger = ActiveSupport::TaggedLogging.new(logger) 89 | end 90 | 91 | # Do not dump schema after migrations. 92 | config.active_record.dump_schema_after_migration = false 93 | end 94 | -------------------------------------------------------------------------------- /config/environments/test.rb: -------------------------------------------------------------------------------- 1 | require "active_support/core_ext/integer/time" 2 | 3 | # The test environment is used exclusively to run your application's 4 | # test suite. You never need to work with it otherwise. Remember that 5 | # your test database is "scratch space" for the test suite and is wiped 6 | # and recreated between test runs. Don't rely on the data there! 7 | 8 | Rails.application.configure do 9 | # Settings specified here will take precedence over those in config/application.rb. 10 | 11 | # Turn false under Spring and add config.action_view.cache_template_loading = true. 12 | config.cache_classes = true 13 | 14 | # Eager loading loads your whole application. When running a single test locally, 15 | # this probably isn't necessary. It's a good idea to do in a continuous integration 16 | # system, or in some way before deploying your code. 17 | config.eager_load = ENV["CI"].present? 18 | 19 | # Configure public file server for tests with Cache-Control for performance. 20 | config.public_file_server.enabled = true 21 | config.public_file_server.headers = { 22 | "Cache-Control" => "public, max-age=#{1.hour.to_i}" 23 | } 24 | 25 | # Show full error reports and disable caching. 26 | config.consider_all_requests_local = true 27 | config.action_controller.perform_caching = false 28 | config.cache_store = :null_store 29 | 30 | # Raise exceptions instead of rendering exception templates. 31 | config.action_dispatch.show_exceptions = false 32 | 33 | # Disable request forgery protection in test environment. 34 | config.action_controller.allow_forgery_protection = false 35 | 36 | # Store uploaded files on the local file system in a temporary directory. 37 | config.active_storage.service = :test 38 | 39 | config.action_mailer.perform_caching = false 40 | 41 | # Tell Action Mailer not to deliver emails to the real world. 42 | # The :test delivery method accumulates sent emails in the 43 | # ActionMailer::Base.deliveries array. 44 | config.action_mailer.delivery_method = :test 45 | 46 | # Print deprecation notices to the stderr. 47 | config.active_support.deprecation = :stderr 48 | 49 | # Raise exceptions for disallowed deprecations. 50 | config.active_support.disallowed_deprecation = :raise 51 | 52 | # Tell Active Support which deprecation messages to disallow. 53 | config.active_support.disallowed_deprecation_warnings = [] 54 | 55 | # Raises error for missing translations. 56 | # config.i18n.raise_on_missing_translations = true 57 | 58 | # Annotate rendered view with file names. 59 | # config.action_view.annotate_rendered_view_with_filenames = true 60 | end 61 | -------------------------------------------------------------------------------- /config/importmap.rb: -------------------------------------------------------------------------------- 1 | # Pin npm packages by running ./bin/importmap 2 | 3 | pin "application", preload: true 4 | pin "@hotwired/turbo-rails", to: "turbo.min.js", preload: true 5 | pin "@hotwired/stimulus", to: "stimulus.min.js", preload: true 6 | pin "@hotwired/stimulus-loading", to: "stimulus-loading.js", preload: true 7 | pin_all_from "app/javascript/controllers", under: "controllers" 8 | -------------------------------------------------------------------------------- /config/initializers/assets.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Version of your assets, change this if you want to expire all your assets. 4 | Rails.application.config.assets.version = "1.0" 5 | 6 | # Add additional assets to the asset load path. 7 | # Rails.application.config.assets.paths << Emoji.images_path 8 | 9 | # Precompile additional assets. 10 | # application.js, application.css, and all non-JS/CSS in the app/assets 11 | # folder are already added. 12 | # Rails.application.config.assets.precompile += %w( admin.js admin.css ) 13 | -------------------------------------------------------------------------------- /config/initializers/content_security_policy.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Define an application-wide content security policy. 4 | # See the Securing Rails Applications Guide for more information: 5 | # https://guides.rubyonrails.org/security.html#content-security-policy-header 6 | 7 | # Rails.application.configure do 8 | # config.content_security_policy do |policy| 9 | # policy.default_src :self, :https 10 | # policy.font_src :self, :https, :data 11 | # policy.img_src :self, :https, :data 12 | # policy.object_src :none 13 | # policy.script_src :self, :https 14 | # policy.style_src :self, :https 15 | # # Specify URI for violation reports 16 | # # policy.report_uri "/csp-violation-report-endpoint" 17 | # end 18 | # 19 | # # Generate session nonces for permitted importmap and inline scripts 20 | # config.content_security_policy_nonce_generator = ->(request) { request.session.id.to_s } 21 | # config.content_security_policy_nonce_directives = %w(script-src) 22 | # 23 | # # Report violations without enforcing the policy. 24 | # # config.content_security_policy_report_only = true 25 | # end 26 | -------------------------------------------------------------------------------- /config/initializers/filter_parameter_logging.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Configure parameters to be filtered from the log file. Use this to limit dissemination of 4 | # sensitive information. See the ActiveSupport::ParameterFilter documentation for supported 5 | # notations and behaviors. 6 | Rails.application.config.filter_parameters += [ 7 | :passw, :secret, :token, :_key, :crypt, :salt, :certificate, :otp, :ssn 8 | ] 9 | -------------------------------------------------------------------------------- /config/initializers/inflections.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Add new inflection rules using the following format. Inflections 4 | # are locale specific, and you may define rules for as many different 5 | # locales as you wish. All of these examples are active by default: 6 | # ActiveSupport::Inflector.inflections(:en) do |inflect| 7 | # inflect.plural /^(ox)$/i, "\\1en" 8 | # inflect.singular /^(ox)en/i, "\\1" 9 | # inflect.irregular "person", "people" 10 | # inflect.uncountable %w( fish sheep ) 11 | # end 12 | 13 | # These inflection rules are supported but not enabled by default: 14 | # ActiveSupport::Inflector.inflections(:en) do |inflect| 15 | # inflect.acronym "RESTful" 16 | # end 17 | -------------------------------------------------------------------------------- /config/initializers/permissions_policy.rb: -------------------------------------------------------------------------------- 1 | # Define an application-wide HTTP permissions policy. For further 2 | # information see https://developers.google.com/web/updates/2018/06/feature-policy 3 | # 4 | # Rails.application.config.permissions_policy do |f| 5 | # f.camera :none 6 | # f.gyroscope :none 7 | # f.microphone :none 8 | # f.usb :none 9 | # f.fullscreen :self 10 | # f.payment :self, "https://secure.example.com" 11 | # end 12 | -------------------------------------------------------------------------------- /config/locales/en.yml: -------------------------------------------------------------------------------- 1 | # Files in the config/locales directory are used for internationalization 2 | # and are automatically loaded by Rails. If you want to use locales other 3 | # than English, add the necessary files in this directory. 4 | # 5 | # To use the locales, use `I18n.t`: 6 | # 7 | # I18n.t "hello" 8 | # 9 | # In views, this is aliased to just `t`: 10 | # 11 | # <%= t("hello") %> 12 | # 13 | # To use a different locale, set it with `I18n.locale`: 14 | # 15 | # I18n.locale = :es 16 | # 17 | # This would use the information in config/locales/es.yml. 18 | # 19 | # The following keys must be escaped otherwise they will not be retrieved by 20 | # the default I18n backend: 21 | # 22 | # true, false, on, off, yes, no 23 | # 24 | # Instead, surround them with single quotes. 25 | # 26 | # en: 27 | # "true": "foo" 28 | # 29 | # To learn more, please read the Rails Internationalization guide 30 | # available at https://guides.rubyonrails.org/i18n.html. 31 | 32 | en: 33 | hello: "Hello world" 34 | -------------------------------------------------------------------------------- /config/puma.rb: -------------------------------------------------------------------------------- 1 | # Puma can serve each request in a thread from an internal thread pool. 2 | # The `threads` method setting takes two numbers: a minimum and maximum. 3 | # Any libraries that use thread pools should be configured to match 4 | # the maximum value specified for Puma. Default is set to 5 threads for minimum 5 | # and maximum; this matches the default thread size of Active Record. 6 | # 7 | max_threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 } 8 | min_threads_count = ENV.fetch("RAILS_MIN_THREADS") { max_threads_count } 9 | threads min_threads_count, max_threads_count 10 | 11 | # Specifies the `worker_timeout` threshold that Puma will use to wait before 12 | # terminating a worker in development environments. 13 | # 14 | worker_timeout 3600 if ENV.fetch("RAILS_ENV", "development") == "development" 15 | 16 | # Specifies the `port` that Puma will listen on to receive requests; default is 3000. 17 | # 18 | port ENV.fetch("PORT") { 3000 } 19 | 20 | # Specifies the `environment` that Puma will run in. 21 | # 22 | environment ENV.fetch("RAILS_ENV") { "development" } 23 | 24 | # Specifies the `pidfile` that Puma will use. 25 | pidfile ENV.fetch("PIDFILE") { "tmp/pids/server.pid" } 26 | 27 | # Specifies the number of `workers` to boot in clustered mode. 28 | # Workers are forked web server processes. If using threads and workers together 29 | # the concurrency of the application would be max `threads` * `workers`. 30 | # Workers do not work on JRuby or Windows (both of which do not support 31 | # processes). 32 | # 33 | # workers ENV.fetch("WEB_CONCURRENCY") { 2 } 34 | 35 | # Use the `preload_app!` method when specifying a `workers` number. 36 | # This directive tells Puma to first boot the application and load code 37 | # before forking the application. This takes advantage of Copy On Write 38 | # process behavior so workers use less memory. 39 | # 40 | # preload_app! 41 | 42 | # Allow puma to be restarted by `bin/rails restart` command. 43 | plugin :tmp_restart 44 | -------------------------------------------------------------------------------- /config/routes.rb: -------------------------------------------------------------------------------- 1 | Rails.application.routes.draw do 2 | # Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html 3 | 4 | # Defines the root path route ("/") 5 | # root "articles#index" 6 | end 7 | -------------------------------------------------------------------------------- /config/storage.yml: -------------------------------------------------------------------------------- 1 | test: 2 | service: Disk 3 | root: <%= Rails.root.join("tmp/storage") %> 4 | 5 | local: 6 | service: Disk 7 | root: <%= Rails.root.join("storage") %> 8 | 9 | # Use bin/rails credentials:edit to set the AWS secrets (as aws:access_key_id|secret_access_key) 10 | # amazon: 11 | # service: S3 12 | # access_key_id: <%= Rails.application.credentials.dig(:aws, :access_key_id) %> 13 | # secret_access_key: <%= Rails.application.credentials.dig(:aws, :secret_access_key) %> 14 | # region: us-east-1 15 | # bucket: your_own_bucket-<%= Rails.env %> 16 | 17 | # Remember not to checkin your GCS keyfile to a repository 18 | # google: 19 | # service: GCS 20 | # project: your_project 21 | # credentials: <%= Rails.root.join("path/to/gcs.keyfile") %> 22 | # bucket: your_own_bucket-<%= Rails.env %> 23 | 24 | # Use bin/rails credentials:edit to set the Azure Storage secret (as azure_storage:storage_access_key) 25 | # microsoft: 26 | # service: AzureStorage 27 | # storage_account_name: your_account_name 28 | # storage_access_key: <%= Rails.application.credentials.dig(:azure_storage, :storage_access_key) %> 29 | # container: your_container_name-<%= Rails.env %> 30 | 31 | # mirror: 32 | # service: Mirror 33 | # primary: local 34 | # mirrors: [ amazon, google, microsoft ] 35 | -------------------------------------------------------------------------------- /db/migrate/20221123212261_enable_pgcypto.rb: -------------------------------------------------------------------------------- 1 | class EnablePgcypto < ActiveRecord::Migration[7.0] 2 | def change 3 | enable_extension "pgcrypto" 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /db/migrate/20221123212610_create_cooperation_negotiation_contracts.rb: -------------------------------------------------------------------------------- 1 | class CreateCooperationNegotiationContracts < ActiveRecord::Migration[7.0] 2 | def change 3 | create_table :cooperation_negotiation_contracts, id: :uuid do |t| 4 | t.uuid :client_id, index: { unique: true } 5 | t.boolean :client_signature, default: false 6 | t.boolean :company_signature, default: false 7 | 8 | t.text :text, default: '' 9 | 10 | t.timestamps 11 | end 12 | end 13 | end 14 | -------------------------------------------------------------------------------- /db/migrate/20221123212818_create_dragon_hunt_parties.rb: -------------------------------------------------------------------------------- 1 | class CreateDragonHuntParties < ActiveRecord::Migration[7.0] 2 | def change 3 | create_table :dragon_hunt_parties, id: :uuid do |t| 4 | t.uuid :client_id, index: { unique: true } 5 | 6 | t.timestamps 7 | end 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /db/migrate/20221124233218_create_read_models_signed_contracts.rb: -------------------------------------------------------------------------------- 1 | class CreateReadModelsSignedContracts < ActiveRecord::Migration[7.0] 2 | def change 3 | create_table :read_models_signed_contracts, id: :uuid do |t| 4 | t.uuid :client_id 5 | t.text :text 6 | 7 | t.timestamps 8 | end 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /db/schema.rb: -------------------------------------------------------------------------------- 1 | # This file is auto-generated from the current state of the database. Instead 2 | # of editing this file, please use the migrations feature of Active Record to 3 | # incrementally modify your database, and then regenerate this schema definition. 4 | # 5 | # This file is the source Rails uses to define your schema when running `bin/rails 6 | # db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to 7 | # be faster and is potentially less error prone than running all of your 8 | # migrations from scratch. Old migrations may fail to apply correctly if those 9 | # migrations use external dependencies or application code. 10 | # 11 | # It's strongly recommended that you check this file into your version control system. 12 | 13 | ActiveRecord::Schema[7.0].define(version: 2022_11_24_233218) do 14 | # These are extensions that must be enabled in order to support this database 15 | enable_extension "pgcrypto" 16 | enable_extension "plpgsql" 17 | 18 | create_table "cooperation_negotiation_contracts", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| 19 | t.uuid "client_id" 20 | t.boolean "client_signature", default: false 21 | t.boolean "company_signature", default: false 22 | t.text "text", default: "" 23 | t.datetime "created_at", null: false 24 | t.datetime "updated_at", null: false 25 | t.index ["client_id"], name: "index_cooperation_negotiation_contracts_on_client_id", unique: true 26 | end 27 | 28 | create_table "dragon_hunt_parties", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| 29 | t.uuid "client_id" 30 | t.datetime "created_at", null: false 31 | t.datetime "updated_at", null: false 32 | t.index ["client_id"], name: "index_dragon_hunt_parties_on_client_id", unique: true 33 | end 34 | 35 | create_table "read_models_signed_contracts", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| 36 | t.uuid "client_id" 37 | t.text "text" 38 | t.datetime "created_at", null: false 39 | t.datetime "updated_at", null: false 40 | end 41 | 42 | end 43 | -------------------------------------------------------------------------------- /db/seeds.rb: -------------------------------------------------------------------------------- 1 | def print_header(label) 2 | puts "\n========================\n== #{label}" 3 | end 4 | 5 | contract_repository = CooperationNegotiation::Domain::ContractRepository.get 6 | 7 | admin_identity = '00000000-0000-0000-0000-000000000001' 8 | 9 | client_id = '00000000-0000-0000-0000-000000000007' 10 | CooperationNegotiation::Application::Services::PrepareDraftContract.new.call(identity: admin_identity, client_id: client_id) 11 | contract = contract_repository.of_client_id(client_id) 12 | CooperationNegotiation::Application::Services::ModifyContractText.new.call(contract_id: contract.id, text: 'foo foo') 13 | 14 | client_id = '00000000-0000-0000-0000-000000000008' 15 | CooperationNegotiation::Application::Services::PrepareDraftContract.new.call(identity: admin_identity, client_id: client_id) 16 | contract = contract_repository.of_client_id(client_id) 17 | CooperationNegotiation::Application::Services::SignContractByClient.new.call(contract_id: contract.id) 18 | 19 | client_id = '00000000-0000-0000-0000-000000000009' 20 | CooperationNegotiation::Application::Services::PrepareDraftContract.new.call(identity: admin_identity, client_id: client_id) 21 | contract = contract_repository.of_client_id(client_id) 22 | CooperationNegotiation::Application::Services::ModifyContractText.new.call(contract_id: contract.id, text: 'The correct one') 23 | CooperationNegotiation::Application::Services::SignContractByClient.new.call(contract_id: contract.id) 24 | CooperationNegotiation::Application::Services::SignContractByCompany.new.call(contract_id: contract.id) 25 | 26 | print_header 'Contracts' 27 | pp CooperationNegotiation::Infrastructure::DbContract.all 28 | 29 | print_header 'Parties' 30 | pp DragonHunt::Infrastructure::DbParty.all 31 | 32 | print_header 'ReadModels::SignedContracts' 33 | pp ReadModels::SignedContract.all 34 | -------------------------------------------------------------------------------- /lib/assets/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pstrzalk/ddd-example-in-ruby-on-rails/46d1bbfc84aaf9c4d55cae814a33fb385eb6432f/lib/assets/.keep -------------------------------------------------------------------------------- /lib/tasks/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pstrzalk/ddd-example-in-ruby-on-rails/46d1bbfc84aaf9c4d55cae814a33fb385eb6432f/lib/tasks/.keep -------------------------------------------------------------------------------- /log/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pstrzalk/ddd-example-in-ruby-on-rails/46d1bbfc84aaf9c4d55cae814a33fb385eb6432f/log/.keep -------------------------------------------------------------------------------- /public/404.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | The page you were looking for doesn't exist (404) 5 | 6 | 55 | 56 | 57 | 58 | 59 |
60 |
61 |

The page you were looking for doesn't exist.

62 |

You may have mistyped the address or the page may have moved.

63 |
64 |

If you are the application owner check the logs for more information.

65 |
66 | 67 | 68 | -------------------------------------------------------------------------------- /public/422.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | The change you wanted was rejected (422) 5 | 6 | 55 | 56 | 57 | 58 | 59 |
60 |
61 |

The change you wanted was rejected.

62 |

Maybe you tried to change something you didn't have access to.

63 |
64 |

If you are the application owner check the logs for more information.

65 |
66 | 67 | 68 | -------------------------------------------------------------------------------- /public/500.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | We're sorry, but something went wrong (500) 5 | 6 | 55 | 56 | 57 | 58 | 59 |
60 |
61 |

We're sorry, but something went wrong.

62 |
63 |

If you are the application owner check the logs for more information.

64 |
65 | 66 | 67 | -------------------------------------------------------------------------------- /public/apple-touch-icon-precomposed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pstrzalk/ddd-example-in-ruby-on-rails/46d1bbfc84aaf9c4d55cae814a33fb385eb6432f/public/apple-touch-icon-precomposed.png -------------------------------------------------------------------------------- /public/apple-touch-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pstrzalk/ddd-example-in-ruby-on-rails/46d1bbfc84aaf9c4d55cae814a33fb385eb6432f/public/apple-touch-icon.png -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pstrzalk/ddd-example-in-ruby-on-rails/46d1bbfc84aaf9c4d55cae814a33fb385eb6432f/public/favicon.ico -------------------------------------------------------------------------------- /public/robots.txt: -------------------------------------------------------------------------------- 1 | # See https://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file 2 | -------------------------------------------------------------------------------- /spec/modules/authorization/application/api_spec.rb: -------------------------------------------------------------------------------- 1 | require_relative "../../../rails_helper" 2 | 3 | module Authorization 4 | module Application 5 | describe Api do 6 | describe '.identity_in_role?' do 7 | context 'when checking an admin identity' do 8 | let(:identity) { '00000000-0000-0000-0000-000000000001' } 9 | 10 | it { expect(described_class.identity_in_role?(identity, 'admin')).to be true } 11 | it { expect(described_class.identity_in_role?(identity, 'client')).to be true } 12 | it { expect(described_class.identity_in_role?(identity, 'foo')).to be false } 13 | end 14 | 15 | context 'when checking a client identity' do 16 | let(:identity) { '00000000-0000-0000-0000-000000000005' } 17 | 18 | it { expect(described_class.identity_in_role?(identity, 'client')).to be true } 19 | it { expect(described_class.identity_in_role?(identity, 'admin')).to be false } 20 | it { expect(described_class.identity_in_role?(identity, 'foo')).to be false } 21 | end 22 | 23 | context 'when checking a non-uuid identity' do 24 | let(:identity) { 'foo' } 25 | 26 | it { expect(described_class.identity_in_role?(identity, 'client')).to be false } 27 | it { expect(described_class.identity_in_role?(identity, 'admin')).to be false } 28 | it { expect(described_class.identity_in_role?(identity, 'bar')).to be false } 29 | end 30 | end 31 | end 32 | end 33 | end 34 | -------------------------------------------------------------------------------- /spec/modules/cooperation_negotiation/application/services/modify_contract_text_spec.rb: -------------------------------------------------------------------------------- 1 | require_relative "../../../../rails_helper" 2 | 3 | module CooperationNegotiation 4 | module Application 5 | module Services 6 | describe ModifyContractText do 7 | let(:client_id) { '00000000-0000-0000-0000-000000000001' } 8 | let(:repository) { Domain::ContractRepository.get } 9 | 10 | describe '.call' do 11 | it 'prepares a draft contract' do 12 | contract = Domain::Contract.prepare_draft(client_id:) 13 | repository.save(contract) 14 | 15 | contract_id = contract.id 16 | 17 | service = described_class.new 18 | service.call(contract_id:, text: 'Modified content') 19 | 20 | contract = repository.of_id(contract_id) 21 | 22 | expect(contract.text).to eq 'Modified content' 23 | end 24 | end 25 | end 26 | end 27 | end 28 | end 29 | -------------------------------------------------------------------------------- /spec/modules/cooperation_negotiation/application/services/prepare_draft_contract_spec.rb: -------------------------------------------------------------------------------- 1 | require_relative "../../../../rails_helper" 2 | 3 | module CooperationNegotiation 4 | module Application 5 | module Services 6 | describe PrepareDraftContract do 7 | let(:identity) { '00000000-0000-0000-0000-000000000000' } 8 | let(:client_id) { '00000000-1234-1234-1234-000000000000' } 9 | let(:repository) { Domain::ContractRepository.get } 10 | 11 | describe '.call' do 12 | it 'prepares a draft contract' do 13 | allow(Authorization::Application::Api) 14 | .to receive(:identity_in_role?).with(identity, 'admin').and_return(true) 15 | 16 | service = described_class.new 17 | service.call(identity:, client_id:) 18 | 19 | expect(repository.of_client_id(client_id)).to be_present 20 | end 21 | 22 | it 'raises unauthorized' do 23 | allow(Authorization::Application::Api) 24 | .to receive(:identity_in_role?).with(identity, 'admin').and_return(false) 25 | 26 | service = described_class.new 27 | 28 | expect { service.call(identity:, client_id:) }.to raise_error(PrepareDraftContract::Unauthorized) 29 | end 30 | end 31 | end 32 | end 33 | end 34 | end 35 | -------------------------------------------------------------------------------- /spec/modules/cooperation_negotiation/application/services/sign_contract_by_client_spec.rb: -------------------------------------------------------------------------------- 1 | require_relative "../../../../rails_helper" 2 | 3 | module CooperationNegotiation 4 | module Application 5 | module Services 6 | describe SignContractByClient do 7 | let(:client_id) { '00000000-0000-0000-0000-000000000001' } 8 | let(:repository) { Domain::ContractRepository.get } 9 | 10 | describe '.call' do 11 | it 'adds client signature' do 12 | contract = Domain::Contract.prepare_draft(client_id:) 13 | repository.save(contract) 14 | 15 | contract_id = contract.id 16 | 17 | service = described_class.new 18 | service.call(contract_id:) 19 | 20 | contract = repository.of_id(contract_id) 21 | expect(contract).to be_signed_by_client 22 | end 23 | end 24 | end 25 | end 26 | end 27 | end 28 | -------------------------------------------------------------------------------- /spec/modules/cooperation_negotiation/application/services/sign_contract_by_company_spec.rb: -------------------------------------------------------------------------------- 1 | require_relative "../../../../rails_helper" 2 | 3 | module CooperationNegotiation 4 | module Application 5 | module Services 6 | describe SignContractByCompany do 7 | let(:client_id) { '00000000-0000-0000-0000-000000000001' } 8 | let(:repository) { Domain::ContractRepository.get } 9 | 10 | describe '.call' do 11 | it 'adds company signature' do 12 | contract = Domain::Contract.prepare_draft(client_id:) 13 | repository.save(contract) 14 | 15 | contract_id = contract.id 16 | 17 | service = described_class.new 18 | service.call(contract_id:) 19 | 20 | contract = repository.of_id(contract_id) 21 | expect(contract).to be_signed_by_company 22 | end 23 | end 24 | end 25 | end 26 | end 27 | end 28 | -------------------------------------------------------------------------------- /spec/modules/cooperation_negotiation/domain/contract_spec.rb: -------------------------------------------------------------------------------- 1 | require_relative "../../../rails_helper" 2 | 3 | module CooperationNegotiation 4 | module Domain 5 | describe Contract do 6 | let(:id) { SecureRandom.uuid } 7 | let(:client_id) { SecureRandom.uuid } 8 | 9 | describe '.prepare_draft' do 10 | it 'initializes a contract with an event' do 11 | time = '2023-01-01 23:18:44 UTC' 12 | ::Clock.utc = time 13 | 14 | contract = described_class.prepare_draft(client_id:) 15 | 16 | expect(contract).to be_a(Contract) 17 | expect(contract.client_id).to eq client_id 18 | 19 | events = contract.uncommited_events 20 | expect(events.size).to eq 1 21 | event = events.first 22 | expect(event).to be_a(Events::ContractDraftPrepared) 23 | expect(event).to have_attributes(client_id:, time:) 24 | end 25 | end 26 | 27 | describe '.initialize' do 28 | it 'initializes a new contract' do 29 | contract = described_class.new(client_id:) 30 | 31 | expect(contract).to have_attributes(id: nil, client_id:) 32 | expect(contract.send(:text)).to eq '' 33 | expect(contract.send(:client_signature)).to be false 34 | expect(contract.send(:company_signature)).to be false 35 | end 36 | end 37 | 38 | describe '.sign_by_client' do 39 | it 'marks as signed by client' do 40 | contract = described_class.new(client_id:) 41 | 42 | contract.sign_by_client 43 | 44 | expect(contract).to be_signed_by_client 45 | expect(contract.uncommited_events).to be_empty 46 | end 47 | 48 | context 'already signed by client' do 49 | it 'raises error' do 50 | contract = described_class.new(client_id:) 51 | contract.sign_by_client 52 | 53 | expect { contract.sign_by_client }.to raise_error(Contract::AlreadySignedByClientError) 54 | end 55 | end 56 | 57 | context 'signed by company before' do 58 | it 'dispaches an event' do 59 | time = '2023-01-01 23:18:44 UTC' 60 | ::Clock.utc = time 61 | 62 | contract = described_class.new(client_id:) 63 | contract.send('text=', 'bar') 64 | contract.sign_by_company 65 | contract.sign_by_client 66 | 67 | expect(contract).to be_signed_by_client 68 | 69 | events = contract.uncommited_events 70 | expect(events.size).to eq 1 71 | event = events.first 72 | expect(event).to be_a(Events::ContractSigned) 73 | expect(event).to have_attributes(time:, client_id:, text: 'bar') 74 | end 75 | end 76 | end 77 | 78 | describe 'signed_by_client?' do 79 | it 'is true' do 80 | contract = described_class.new(client_id:) 81 | contract.sign_by_client 82 | expect(contract).to be_signed_by_client 83 | end 84 | 85 | it 'is false' do 86 | contract = described_class.new(client_id:) 87 | expect(contract).not_to be_signed_by_client 88 | end 89 | end 90 | 91 | describe '.sign_by_company' do 92 | it 'marks as signed by company' do 93 | contract = described_class.new(client_id:) 94 | contract.sign_by_company 95 | 96 | expect(contract).to be_signed_by_company 97 | expect(contract.uncommited_events).to be_empty 98 | end 99 | 100 | context 'already signed by company' do 101 | it 'raises error' do 102 | contract = described_class.new(client_id:) 103 | contract.sign_by_company 104 | 105 | expect { contract.sign_by_company }.to raise_error(Contract::AlreadySignedByCompanyError) 106 | end 107 | end 108 | 109 | context 'signed by client before' do 110 | it 'dispaches an event' do 111 | time = '2023-01-01 23:18:44 UTC' 112 | ::Clock.utc = time 113 | 114 | contract = described_class.new(client_id:) 115 | contract.send('text=', 'bar') 116 | contract.sign_by_client 117 | contract.sign_by_company 118 | 119 | expect(contract).to be_signed_by_company 120 | 121 | events = contract.uncommited_events 122 | expect(events.size).to eq 1 123 | event = events.first 124 | expect(event).to be_a(Events::ContractSigned) 125 | expect(event).to have_attributes(time:, client_id:, text: 'bar') 126 | end 127 | end 128 | end 129 | 130 | describe 'signed_by_company?' do 131 | it 'is true' do 132 | contract = described_class.new(client_id:) 133 | contract.sign_by_company 134 | expect(contract).to be_signed_by_company 135 | end 136 | 137 | it 'is false' do 138 | contract = described_class.new(client_id:) 139 | expect(contract).not_to be_signed_by_company 140 | end 141 | end 142 | 143 | describe '.modify_text' do 144 | it 'changes the text' do 145 | time = '2023-01-01 23:18:44 UTC' 146 | ::Clock.utc = time 147 | 148 | contract = described_class.new(client_id:) 149 | contract.modify_text('foo') 150 | 151 | expect(contract.send(:text)).to eq 'foo' 152 | 153 | events = contract.uncommited_events 154 | expect(events.size).to eq 1 155 | event = events.first 156 | expect(event).to be_a(Events::ContractTextModified) 157 | expect(event).to have_attributes(time:, text: 'foo') 158 | end 159 | 160 | it 'clears client signature' do 161 | contract = described_class.new(client_id:) 162 | contract.sign_by_client 163 | contract.modify_text('foo') 164 | 165 | expect(contract).not_to be_signed_by_client 166 | end 167 | 168 | it 'clears company signature' do 169 | contract = described_class.new(client_id:) 170 | contract.sign_by_company 171 | contract.modify_text('foo') 172 | 173 | expect(contract).not_to be_signed_by_company 174 | end 175 | 176 | it 'raises error' do 177 | contract = described_class.new(client_id:) 178 | contract.sign_by_client 179 | contract.sign_by_company 180 | 181 | expect { contract.modify_text('foo') }.to raise_error(Contract::AlreadySignedError) 182 | end 183 | end 184 | end 185 | end 186 | end 187 | -------------------------------------------------------------------------------- /spec/modules/cooperation_negotiation/domain/events/contract_draft_prepared_spec.rb: -------------------------------------------------------------------------------- 1 | require_relative "../../../../rails_helper" 2 | 3 | module CooperationNegotiation 4 | module Domain 5 | module Events 6 | describe ContractDraftPrepared do 7 | it 'has attributes' do 8 | event = described_class.new 9 | event.contract_id = :boo 10 | event.client_id = :moo 11 | event.time = :zoo 12 | 13 | expect(event).to have_attributes( 14 | contract_id: :boo, 15 | client_id: :moo, 16 | time: :zoo 17 | ) 18 | end 19 | end 20 | end 21 | end 22 | end 23 | -------------------------------------------------------------------------------- /spec/modules/cooperation_negotiation/domain/events/contract_signed_spec.rb: -------------------------------------------------------------------------------- 1 | require_relative "../../../../rails_helper" 2 | 3 | module CooperationNegotiation 4 | module Domain 5 | module Events 6 | describe ContractSigned do 7 | it 'has attributes' do 8 | event = described_class.new 9 | event.text = :foo 10 | event.contract_id = :boo 11 | event.client_id = :moo 12 | event.time = :zoo 13 | 14 | expect(event).to have_attributes( 15 | text: :foo, 16 | contract_id: :boo, 17 | client_id: :moo, 18 | time: :zoo 19 | ) 20 | end 21 | end 22 | end 23 | end 24 | end 25 | -------------------------------------------------------------------------------- /spec/modules/cooperation_negotiation/domain/events/contract_text_modified_spec.rb: -------------------------------------------------------------------------------- 1 | require_relative "../../../../rails_helper" 2 | 3 | module CooperationNegotiation 4 | module Domain 5 | module Events 6 | describe ContractTextModified do 7 | it 'has attributes' do 8 | event = described_class.new 9 | event.text = :foo 10 | event.contract_id = :boo 11 | event.time = :zoo 12 | 13 | expect(event).to have_attributes( 14 | text: :foo, 15 | contract_id: :boo, 16 | time: :zoo 17 | ) 18 | end 19 | end 20 | end 21 | end 22 | end 23 | -------------------------------------------------------------------------------- /spec/modules/cooperation_negotiation/infrastructure/db_contract_repository_spec.rb: -------------------------------------------------------------------------------- 1 | require_relative "../../../rails_helper" 2 | 3 | module CooperationNegotiation 4 | module Infrastructure 5 | describe DbContractRepository do 6 | subject(:repository) { described_class.new(event_store_write: ::EventStore::Substitute::Write.new) } 7 | 8 | let(:id) { "00000000-0000-0000-0000-000000000001" } 9 | let(:client_id) { "00000000-0000-0000-0000-000000000002" } 10 | 11 | describe '#of_id' do 12 | it 'finds a persisted entry' do 13 | DbContract.create( 14 | id:, 15 | client_id:, 16 | text: 'foo', 17 | client_signature: true, 18 | company_signature: true 19 | ) 20 | 21 | contract = repository.of_id(id) 22 | 23 | expect(contract).to be_a(Domain::Contract) 24 | expect(contract).to have_attributes(id:, client_id:) 25 | expect(contract.send(:client_signature)).to be true 26 | expect(contract.send(:company_signature)).to be true 27 | end 28 | 29 | it 'does not find a persisted entry' do 30 | expect(repository.of_id(id)).to be_nil 31 | end 32 | end 33 | 34 | describe '#of_client_id' do 35 | it 'finds a persisted entry' do 36 | DbContract.create( 37 | id:, 38 | client_id:, 39 | text: 'foo', 40 | client_signature: true, 41 | company_signature: true 42 | ) 43 | 44 | contract = repository.of_client_id(client_id) 45 | 46 | expect(contract).to be_a(Domain::Contract) 47 | expect(contract).to have_attributes(id:, client_id:) 48 | expect(contract.send(:client_signature)).to be true 49 | expect(contract.send(:company_signature)).to be true 50 | end 51 | 52 | it 'does not find a persisted entry' do 53 | expect(repository.of_id(client_id)).to be_nil 54 | end 55 | end 56 | 57 | describe '#save' do 58 | it 'creates a new db_contract record with given id' do 59 | contract = Domain::Contract.new(id:, client_id:) 60 | contract.modify_text('bar') 61 | contract.sign_by_client 62 | contract.sign_by_company 63 | 64 | expect { repository.save(contract) }.to change(DbContract, :count).by(1) 65 | 66 | db_contract = DbContract.find(id) 67 | expect(db_contract).to have_attributes( 68 | id:, 69 | client_id:, 70 | text: 'bar', 71 | client_signature: true, 72 | company_signature: true 73 | ) 74 | end 75 | 76 | it 'commits ContractSigned event' do 77 | time = '2023-01-01 23:18:44 UTC' 78 | ::Clock.utc = time 79 | 80 | contract = Domain::Contract.prepare_draft(client_id:) 81 | contract.modify_text('foo') 82 | contract.sign_by_client 83 | contract.sign_by_company 84 | 85 | contract_signed = contract.uncommited_events.find { |event| event.is_a?(Domain::Events::ContractSigned) } 86 | repository.save(contract) 87 | expect(contract.uncommited_events.size).to eq 0 88 | 89 | written_events = repository.event_store_write.written 90 | expect(written_events.size).to eq 1 91 | expect(written_events.first).to be_a(Domain::Events::ContractSigned) 92 | expect(written_events.first).to have_attributes(client_id:, time:, text: 'foo') 93 | end 94 | 95 | it 'creates a new db_contract record with generated id' do 96 | contract = Domain::Contract.new(client_id:) 97 | 98 | expect { repository.save(contract) }.to change(DbContract, :count).by(1) 99 | 100 | db_contract = DbContract.last 101 | expect(db_contract.client_id).to eq client_id 102 | expect(db_contract.id).not_to be_nil 103 | 104 | expect(contract.id).to eq db_contract.id 105 | end 106 | 107 | it 'updates an existing db_contract record' do 108 | db_contract = DbContract.create(id:, client_id:) 109 | 110 | other_client_id = "00000000-0000-0000-0000-000000000003" 111 | contract = Domain::Contract.new(id:, client_id: other_client_id) 112 | 113 | expect { repository.save(contract) }.not_to change(DbContract, :count) 114 | 115 | db_contract.reload 116 | expect(db_contract.client_id).to eq other_client_id 117 | end 118 | end 119 | end 120 | end 121 | end 122 | -------------------------------------------------------------------------------- /spec/modules/cooperation_negotiation/infrastructure/db_contract_spec.rb: -------------------------------------------------------------------------------- 1 | require_relative "../../../rails_helper" 2 | 3 | module CooperationNegotiation 4 | module Infrastructure 5 | describe DbContract do 6 | it "can be persisted" do 7 | expect { described_class.create }.to change(described_class, :count).by(1) 8 | end 9 | end 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /spec/modules/dragon_hunt/application/handlers/cooperation_negotiation/contract_signed_spec.rb: -------------------------------------------------------------------------------- 1 | require_relative "../../../../../rails_helper" 2 | 3 | module DragonHunt 4 | module Application 5 | module Handlers 6 | module CooperationNegotiation 7 | describe ContractSigned do 8 | describe '.call' do 9 | let(:id) { '00000000-0000-0000-0000-000000000001' } 10 | let(:client_id) { '00000000-0000-0000-0000-000000000002' } 11 | 12 | it 'saves the party' do 13 | event = ::CooperationNegotiation::Domain::Events::ContractSigned.new 14 | event.client_id = client_id 15 | described_class.call(event) 16 | 17 | repository = Domain::PartyRepository.get 18 | expect(repository.of_client_id(client_id)).to be_present 19 | end 20 | end 21 | end 22 | end 23 | end 24 | end 25 | end 26 | -------------------------------------------------------------------------------- /spec/modules/dragon_hunt/domain/party_spec.rb: -------------------------------------------------------------------------------- 1 | require_relative "../../../rails_helper" 2 | 3 | module DragonHunt 4 | module Domain 5 | describe Party do 6 | let(:id) { SecureRandom.uuid } 7 | let(:client_id) { SecureRandom.uuid } 8 | 9 | describe '.assemble' do 10 | let(:assembled_party) { described_class.assemble(client_id: client_id) } 11 | 12 | it { expect(assembled_party).to be_a(Party) } 13 | it { expect(assembled_party.client_id).to eq client_id } 14 | end 15 | 16 | describe '.initialize' do 17 | it 'initializes' do 18 | party = described_class.new(client_id: , id:) 19 | 20 | expect(party.client_id).to eq client_id 21 | expect(party.id).to eq id 22 | end 23 | 24 | context 'when id is not provided' do 25 | it 'initializes' do 26 | party = described_class.new(client_id:) 27 | 28 | expect(party.client_id).to eq client_id 29 | expect(party.id).to eq nil 30 | end 31 | end 32 | end 33 | end 34 | end 35 | end 36 | -------------------------------------------------------------------------------- /spec/modules/dragon_hunt/infrastructure/db_party_repository_spec.rb: -------------------------------------------------------------------------------- 1 | require_relative "../../../rails_helper" 2 | 3 | module DragonHunt 4 | module Infrastructure 5 | describe DbPartyRepository do 6 | subject(:repository) { described_class.new } 7 | 8 | let(:id) { "00000000-0000-0000-0000-000000000001" } 9 | let(:client_id) { "00000000-0000-0000-0000-000000000002" } 10 | 11 | describe '#of_id' do 12 | it 'finds a persisted entry' do 13 | DbParty.create(id:, client_id:) 14 | 15 | party = repository.of_id(id) 16 | 17 | expect(party).to be_a(Domain::Party) 18 | expect(party).to have_attributes(id:, client_id:) 19 | end 20 | 21 | it 'does not find a persisted entry' do 22 | expect(repository.of_id(id)).to be_nil 23 | end 24 | end 25 | 26 | describe '#save' do 27 | it 'creates a new db_party record with given id' do 28 | party = Domain::Party.new(id:, client_id:) 29 | 30 | expect { repository.save(party) }.to change(DbParty, :count).by(1) 31 | 32 | db_party = DbParty.find(id) 33 | expect(db_party).to have_attributes(id:, client_id:) 34 | end 35 | 36 | it 'creates a new db_party record with generated id' do 37 | party = Domain::Party.new(client_id:) 38 | 39 | expect { repository.save(party) }.to change(DbParty, :count).by(1) 40 | 41 | db_party = DbParty.last 42 | expect(db_party.client_id).to eq client_id 43 | expect(db_party.id).not_to be_nil 44 | end 45 | 46 | it 'updates an existing db_party record' do 47 | db_party = DbParty.create(id:, client_id:) 48 | 49 | other_client_id = "00000000-0000-0000-0000-000000000003" 50 | party = Domain::Party.new(id:, client_id: other_client_id) 51 | 52 | expect { repository.save(party) }.not_to change(DbParty, :count) 53 | 54 | db_party.reload 55 | expect(db_party.client_id).to eq other_client_id 56 | end 57 | end 58 | end 59 | end 60 | end 61 | -------------------------------------------------------------------------------- /spec/modules/dragon_hunt/infrastructure/db_party_spec.rb: -------------------------------------------------------------------------------- 1 | require_relative "../../../rails_helper" 2 | 3 | module DragonHunt 4 | module Infrastructure 5 | describe DbParty do 6 | it "can be persisted" do 7 | expect { described_class.create }.to change(described_class, :count).by(1) 8 | end 9 | end 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /spec/rails_helper.rb: -------------------------------------------------------------------------------- 1 | # This file is copied to spec/ when you run 'rails generate rspec:install' 2 | require 'spec_helper' 3 | ENV['RAILS_ENV'] ||= 'test' 4 | require_relative '../config/environment' 5 | # Prevent database truncation if the environment is production 6 | abort("The Rails environment is running in production mode!") if Rails.env.production? 7 | require 'rspec/rails' 8 | # Add additional requires below this line. Rails is not loaded until this point! 9 | 10 | # Requires supporting ruby files with custom matchers and macros, etc, in 11 | # spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are 12 | # run as spec files by default. This means that files in spec/support that end 13 | # in _spec.rb will both be required and run as specs, causing the specs to be 14 | # run twice. It is recommended that you do not name files matching this glob to 15 | # end with _spec.rb. You can configure this pattern with the --pattern 16 | # option on the command line or in ~/.rspec, .rspec or `.rspec-local`. 17 | # 18 | # The following line is provided for convenience purposes. It has the downside 19 | # of increasing the boot-up time by auto-requiring all files in the support 20 | # directory. Alternatively, in the individual `*_spec.rb` files, manually 21 | # require only the support files necessary. 22 | # 23 | # Dir[Rails.root.join('spec', 'support', '**', '*.rb')].sort.each { |f| require f } 24 | 25 | # Checks for pending migrations and applies them before tests are run. 26 | # If you are not using ActiveRecord, you can remove these lines. 27 | begin 28 | ActiveRecord::Migration.maintain_test_schema! 29 | rescue ActiveRecord::PendingMigrationError => e 30 | abort e.to_s.strip 31 | end 32 | RSpec.configure do |config| 33 | # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures 34 | config.fixture_path = "#{::Rails.root}/spec/fixtures" 35 | 36 | # If you're not using ActiveRecord, or you'd prefer not to run each of your 37 | # examples within a transaction, remove the following line or assign false 38 | # instead of true. 39 | config.use_transactional_fixtures = true 40 | 41 | # You can uncomment this line to turn off ActiveRecord support entirely. 42 | # config.use_active_record = false 43 | 44 | # RSpec Rails can automatically mix in different behaviours to your tests 45 | # based on their file location, for example enabling you to call `get` and 46 | # `post` in specs under `spec/controllers`. 47 | # 48 | # You can disable this behaviour by removing the line below, and instead 49 | # explicitly tag your specs with their type, e.g.: 50 | # 51 | # RSpec.describe UsersController, type: :controller do 52 | # # ... 53 | # end 54 | # 55 | # The different available types are documented in the features, such as in 56 | # https://relishapp.com/rspec/rspec-rails/docs 57 | config.infer_spec_type_from_file_location! 58 | 59 | # Filter lines from Rails gems in backtraces. 60 | config.filter_rails_from_backtrace! 61 | # arbitrary gems may also be filtered via: 62 | # config.filter_gems_from_backtrace("gem name") 63 | end 64 | -------------------------------------------------------------------------------- /spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | require "simplecov" 2 | SimpleCov.start "rails" do 3 | add_filter "app/channels/application_cable/channel.rb" 4 | add_filter "app/channels/application_cable/connection.rb" 5 | add_filter "app/jobs/application_job.rb" 6 | add_filter "app/mailers/application_mailer.rb" 7 | end 8 | 9 | # This file was generated by the `rails generate rspec:install` command. Conventionally, all 10 | # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`. 11 | # The generated `.rspec` file contains `--require spec_helper` which will cause 12 | # this file to always be loaded, without a need to explicitly require it in any 13 | # files. 14 | # 15 | # Given that it is always loaded, you are encouraged to keep this file as 16 | # light-weight as possible. Requiring heavyweight dependencies from this file 17 | # will add to the boot time of your test suite on EVERY test run, even for an 18 | # individual file that may not need all of that loaded. Instead, consider making 19 | # a separate helper file that requires the additional dependencies and performs 20 | # the additional setup, and require it from the spec files that actually need 21 | # it. 22 | # 23 | # See https://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration 24 | RSpec.configure do |config| 25 | # rspec-expectations config goes here. You can use an alternate 26 | # assertion/expectation library such as wrong or the stdlib/minitest 27 | # assertions if you prefer. 28 | config.expect_with :rspec do |expectations| 29 | # This option will default to `true` in RSpec 4. It makes the `description` 30 | # and `failure_message` of custom matchers include text for helper methods 31 | # defined using `chain`, e.g.: 32 | # be_bigger_than(2).and_smaller_than(4).description 33 | # # => "be bigger than 2 and smaller than 4" 34 | # ...rather than: 35 | # # => "be bigger than 2" 36 | expectations.include_chain_clauses_in_custom_matcher_descriptions = true 37 | end 38 | 39 | # rspec-mocks config goes here. You can use an alternate test double 40 | # library (such as bogus or mocha) by changing the `mock_with` option here. 41 | config.mock_with :rspec do |mocks| 42 | # Prevents you from mocking or stubbing a method that does not exist on 43 | # a real object. This is generally recommended, and will default to 44 | # `true` in RSpec 4. 45 | mocks.verify_partial_doubles = true 46 | end 47 | 48 | # This option will default to `:apply_to_host_groups` in RSpec 4 (and will 49 | # have no way to turn it off -- the option exists only for backwards 50 | # compatibility in RSpec 3). It causes shared context metadata to be 51 | # inherited by the metadata hash of host groups and examples, rather than 52 | # triggering implicit auto-inclusion in groups with matching metadata. 53 | config.shared_context_metadata_behavior = :apply_to_host_groups 54 | 55 | # The settings below are suggested to provide a good initial experience 56 | # with RSpec, but feel free to customize to your heart's content. 57 | =begin 58 | # This allows you to limit a spec run to individual examples or groups 59 | # you care about by tagging them with `:focus` metadata. When nothing 60 | # is tagged with `:focus`, all examples get run. RSpec also provides 61 | # aliases for `it`, `describe`, and `context` that include `:focus` 62 | # metadata: `fit`, `fdescribe` and `fcontext`, respectively. 63 | config.filter_run_when_matching :focus 64 | 65 | # Allows RSpec to persist some state between runs in order to support 66 | # the `--only-failures` and `--next-failure` CLI options. We recommend 67 | # you configure your source control system to ignore this file. 68 | config.example_status_persistence_file_path = "spec/examples.txt" 69 | 70 | # Limits the available syntax to the non-monkey patched syntax that is 71 | # recommended. For more details, see: 72 | # https://relishapp.com/rspec/rspec-core/docs/configuration/zero-monkey-patching-mode 73 | config.disable_monkey_patching! 74 | 75 | # Many RSpec users commonly either run the entire suite or an individual 76 | # file, and it's useful to allow more verbose output when running an 77 | # individual spec file. 78 | if config.files_to_run.one? 79 | # Use the documentation formatter for detailed output, 80 | # unless a formatter has already been configured 81 | # (e.g. via a command-line flag). 82 | config.default_formatter = "doc" 83 | end 84 | 85 | # Print the 10 slowest examples and example groups at the 86 | # end of the spec run, to help surface which specs are running 87 | # particularly slow. 88 | config.profile_examples = 10 89 | 90 | # Run specs in random order to surface order dependencies. If you find an 91 | # order dependency and want to debug it, you can fix the order by providing 92 | # the seed, which is printed after each run. 93 | # --seed 1234 94 | config.order = :random 95 | 96 | # Seed global randomization in this process using the `--seed` CLI option. 97 | # Setting this allows you to use `--seed` to deterministically reproduce 98 | # test failures related to randomization by passing the same `--seed` value 99 | # as the one that triggered the failure. 100 | Kernel.srand config.seed 101 | =end 102 | end 103 | -------------------------------------------------------------------------------- /storage/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pstrzalk/ddd-example-in-ruby-on-rails/46d1bbfc84aaf9c4d55cae814a33fb385eb6432f/storage/.keep -------------------------------------------------------------------------------- /tmp/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pstrzalk/ddd-example-in-ruby-on-rails/46d1bbfc84aaf9c4d55cae814a33fb385eb6432f/tmp/.keep -------------------------------------------------------------------------------- /tmp/pids/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pstrzalk/ddd-example-in-ruby-on-rails/46d1bbfc84aaf9c4d55cae814a33fb385eb6432f/tmp/pids/.keep -------------------------------------------------------------------------------- /tmp/storage/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pstrzalk/ddd-example-in-ruby-on-rails/46d1bbfc84aaf9c4d55cae814a33fb385eb6432f/tmp/storage/.keep -------------------------------------------------------------------------------- /vendor/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pstrzalk/ddd-example-in-ruby-on-rails/46d1bbfc84aaf9c4d55cae814a33fb385eb6432f/vendor/.keep -------------------------------------------------------------------------------- /vendor/javascript/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pstrzalk/ddd-example-in-ruby-on-rails/46d1bbfc84aaf9c4d55cae814a33fb385eb6432f/vendor/javascript/.keep --------------------------------------------------------------------------------