Slide 1

Slide 1 text

Lessons learned from a huge Rails app Nahuel Garbezza @ngarbezza

Slide 2

Slide 2 text

Olá! Hi! Hola!

Slide 3

Slide 3 text

Who I am!

Slide 4

Slide 4 text

How big is an application? How can we measure it?

Slide 5

Slide 5 text

Ways to measure an application size > ActiveRecord::Base.descendants.size => 557 $ git shortlog -s | wc -l 302

Slide 6

Slide 6 text

Ways to measure an application size > Rails::Engine.subclasses.sum { |e| e.routes.routes.size } => 1554 Bundle complete! 234 Gemfile dependencies, 459 gems now installed.

Slide 7

Slide 7 text

the context

Slide 8

Slide 8 text

Context I worked with

Slide 9

Slide 9 text

“big” means “out of control”

Slide 10

Slide 10 text

but “out of control” is not bad if you trust your team

Slide 11

Slide 11 text

Working together as a group! Building trust in your engineering team

Slide 12

Slide 12 text

what to do with non-Rails code? business logic

Slide 13

Slide 13 text

/lib $ tree lib/ lib/ ├── additional_params.rb ├── address_validator.rb ├── aol_integration.rb ├── api_throttled_client.rb ├── bad_login_detector.rb ├── cache_keys_invalidator.rb ├── command_interpreter.rb ├── customer_survey.rb ├── default_operation.rb ├── html_errors_formatter.rb ├── json_to_xml_to_json.rb ├── log_middleware.rb ├── measure_converter.rb ├── money_helper.rb ├── one_time_activation.rb ├── product_selector.rb ├── profit_calculator.rb ├── registration_step.rb ├── sharing_policy.rb ├── stuff.rb ├── unknown_identity.rb ├── url_generator.rb ├── user_search_result.rb ├── world_changer.rb ├── xml_utilities.rb └── ...

Slide 14

Slide 14 text

modularization

Slide 15

Slide 15 text

what to do with non-Rails code? interfaces entry points Modularization

Slide 16

Slide 16 text

modularization (level 1) namespaces

Slide 17

Slide 17 text

what to do with non-Rails code? api/integrations/facebook Api::Integrations::Facebook Modularization using Namespaces

Slide 18

Slide 18 text

modularization (level 2) Rails engines

Slide 19

Slide 19 text

what to do with non-Rails code? Modularization using Rails engines

Slide 20

Slide 20 text

build a test suite you can trust

Slide 21

Slide 21 text

build a test suite you can trust https://medium.com/@kentbeck_7670/test-desiderata-94150638a4b3

Slide 22

Slide 22 text

“self-growing” tests

Slide 23

Slide 23 text

build a test suite you can trust class Conference < ApplicationRecord has_many :attendants end class Attendant < ApplicationRecord belongs_to :conference end “Self-growing” test: check for factories validity FactoryBot.define do factory :conference do title { 'RubyConfBR 2019' } description { 'foo' } end factory :attendant do name { ‘Nahuel’ } conference end end

Slide 24

Slide 24 text

build a test suite you can trust class FactoriesValidityTest < ActiveSupport::TestCase all_factory_names = FactoryBot.factories.map(&:name) all_factory_names.each do |factory_name| test "factory #{factory_name} creates a valid object" do instance = FactoryBot.build(factory_name) assert_equal true, instance.valid? end end end “Self-growing” test: check for factories validity 1 test running N different instances

Slide 25

Slide 25 text

build a test suite you can trust class Conference < ApplicationRecord has_many :attendants validates :description, length: { minimum: 20 } end class Attendant < ApplicationRecord belongs_to :conference end “Self-growing” test: check for factories validity FactoryBot.define do factory :conference do title { 'RubyConfBR 2019' } description { 'foo' } end factory :attendant do name { ‘Nahuel’ } conference end end Oops

Slide 26

Slide 26 text

build a test suite you can trust class FactoriesValidityTest < ActiveSupport::TestCase all_factory_names = FactoryBot.factories.map(&:name) all_factory_names.each do |factory_name| test "factory #{factory_name} creates a valid object" do instance = FactoryBot.build(factory_name) assert_equal true, instance.valid? end end end “Self-growing” test: check for factories validity Feedback about problems in one of our factories

Slide 27

Slide 27 text

fight against flaky tests ツ

Slide 28

Slide 28 text

build a test suite you can trust Most common flaky tests causes

Slide 29

Slide 29 text

test your tests

Slide 30

Slide 30 text

build a test suite you can trust Mutation Testing expecting the tests to fail https://github.com/mbj/mutant Testing our tests with Mutation Testing

Slide 31

Slide 31 text

taking care of your production errors

Slide 32

Slide 32 text

track notified alerts protocol fix and improve Taking care of production errors

Slide 33

Slide 33 text

Errors give you great feedback Taking care of production errors

Slide 34

Slide 34 text

bonus

Slide 35

Slide 35 text

No content

Slide 36

Slide 36 text

Muito obrigado! Thank you so much! Muchas gracias!

Slide 37

Slide 37 text

Creative Software Development