Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Support/wasp sw #34

Merged
merged 74 commits into from
Mar 9, 2019
Merged

Support/wasp sw #34

merged 74 commits into from
Mar 9, 2019

Conversation

joe4dev
Copy link
Contributor

@joe4dev joe4dev commented Mar 9, 2019

  • Add benchmark execution filtering
  • Add test cases
  • Refactor codebase
  • Fix linter warnings

Commit message conventions inspired by: "How to Write a Git Commit Message"
Source: https://chris.beams.io/posts/git-commit/
Motivation:
1) The project is dominated by Rails and the Rails docs favor single quote style
2) The majority of existing code follows this style (381 offenses vs 1439)

* Rubocop's styleguide: https://github.com/rubocop-hq/ruby-style-guide#strings
* Github's styleguide: https://github.com/github/rubocop-github/blob/master/STYLEGUIDE.md#strings

* Docs: https://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Style/StringLiterals
* Reddit discussion: https://www.reddit.com/r/rails/comments/7g7vto/single_or_double_quotes/
Motivation:

1. Prepare project for Ruby 3+
2. Improve performance (minor)

Potential Side Effects:

* Usage of dynamic/inline string modification
* Searched for `<<` appearances:
  * One critical appearance: app/models/shell_runner.rb:13
    => Apply `.dup` fix because `"".frozen? #=> true` but `"".dup.frozen? #=> false`
* No regression discovered with test suite.

Background:

* Good explanation in this blogpost series: https://freelancing-gods.com/2017/07/27/an-introduction-to-frozen-string-literals.html
* Rubocopy Docs: https://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Style/FrozenStringLiteralComment
* StackOverflow: https://stackoverflow.com/questions/37799296/what-does-the-comment-frozen-string-literal-true-do
Motivation: git best practice
Rubocop rule: Layout/SpaceAroundOperators
Rubocop rule: Layout/SpaceInsideHashLiteralBraces
Rubocop rules: Layout/SpaceAroundEqualsInParameterDefault
Rubocop rule: Layout/CaseIndentation
Rubocop rule: Layout/IndentationWidth: Use 2 (not 4) spaces for indentation.
Use `key: :value` instead of `:key => :value`

Rubocop rule: Style/HashSyntax: Use the new Ruby 1.9 hash syntax.
Rubocop rule: Layout/SpaceBeforeBlockBraces: Space missing to the left of {.
Rubocop rule: Layout/IndentationConsistency: Inconsistent indentation detected
Rubocop rule: Style/RedundantReturn: Redundant return detected.
Rubocop rule: Style/Semicolon: Do not use semicolons to terminate expressions.
Rubocop rule: Layout/SpaceInsideParens: Space inside parentheses detected.
Rubocop rule: Layout/SpaceBeforeFirstArg: Put one space between the method name and the first argument.
Rubocop rule: Layout/ElseAlignment: Align else with when.
Rubocop rule: Style/MethodDefParentheses: Use def with parentheses when there are parameters.
Rubocop rule: Style/ParenthesesAroundCondition: Don't use parentheses around the condition of an elsif.
Rubocop rule: Layout/CommentIndentation: Incorrect indentation detected
Rubocop rule: Layout/SpaceInsideBlockBraces: Space missing inside }
Rubocop rule: Layout/EmptyLinesAroundBlockBody: Extra empty line detected at block body end
Rubocop rule: Layout/LeadingCommentSpace: Missing space after #
Rubocop rule: Style/BracesAroundHashParameters: Redundant curly braces around a hash parameter
Rubocop rule: Layout/SpaceInsideParens: Space inside parentheses detected
Clarify the side effect by adding the `exec` (execution) part to the method name.
Fix unclear similarity with `ssh_shell_cmd`
* More flexible and powerful
* Handle params interpretation at controller-level instead of passing them (i.e., params[:active]) into models

Source: https://www.justinweiss.com/articles/search-and-filter-rails-models-without-bloating-your-controller/
Unable to implement (with reasonable effort).

First attempt:

```ruby
 # frozen_string_literal: true

require 'rails_helper'

describe BenchmarkDefinitionsController do
  let(:benchmark_definition) { attributes_for(:benchmark_definition) }

  # StackOverflow: https://stackoverflow.com/questions/28947241/how-to-post-with-missing-authenticity-token-in-rspec-rails-request-test
  context 'invalid authenticity token' do
    before do
      ActionController::Base.allow_forgery_protection = true
    end
    it 'should throw an InvalidAuthenticityToken exception' do
      # Handle unverified request is triggered first!
      expect { post benchmark_definitions_path, params: benchmark_definition }.to raise_error(ActionController::InvalidAuthenticityToken)
    end
    after do
      ActionController::Base.allow_forgery_protection = false
    end
  end
end
```
This is somewhat related to [Move Statements to Callers](https://refactoring.com/catalog/moveStatementsToCallers.html)
combined together with introducing a callback instead of manually calling a method to initialize variables.
Notice that this is a special case of a constructor because the actual Ruby-alike constructor (i.e., initialize)
is not applicable here due to Rails context.

Rails callbacks: https://guides.rubyonrails.org/active_record_callbacks.html
This is somewhat related to [Move Statements to Callers](https://refactoring.com/catalog/moveStatementsToCallers.html)
combined together with introducing a callback instead of manually calling a method to initialize variables.
Notice that this is a special case of a constructor because the actual Ruby-alike constructor (i.e., initialize)
is not applicable here due to Rails context.

Rails callbacks: https://guides.rubyonrails.org/active_record_callbacks.html
This is somewhat related to [Move Statements to Callers](https://refactoring.com/catalog/moveStatementsToCallers.html)
combined together with introducing a callback instead of manually calling a method to initialize variables.
Notice that this is a special case of a constructor because the actual Ruby-alike constructor (i.e., initialize)
is not applicable here due to Rails context.

Rails callbacks: https://guides.rubyonrails.org/active_record_callbacks.html
@coveralls
Copy link

Pull Request Test Coverage Report for Build 89

  • 51 of 69 (73.91%) changed or added relevant lines in 23 files are covered.
  • 2 unchanged lines in 2 files lost coverage.
  • Overall coverage increased (+10.0%) to 78.172%

Changes Missing Coverage Covered Lines Changed/Added Lines %
app/controllers/application_controller.rb 1 2 50.0%
app/controllers/metric_definitions_controller.rb 1 2 50.0%
app/helpers/virtual_machine_instances_helper.rb 0 1 0.0%
app/controllers/errors_controller.rb 0 3 0.0%
app/models/benchmark_execution.rb 5 8 62.5%
app/models/vagrant_runner.rb 3 7 42.86%
app/controllers/benchmark_executions_controller.rb 3 8 37.5%
Files with Coverage Reduction New Missed Lines %
app/controllers/errors_controller.rb 1 0.0%
app/models/benchmark_execution.rb 1 58.88%
Totals Coverage Status
Change from base Build 85: 10.0%
Covered Lines: 838
Relevant Lines: 1072

💛 - Coveralls

@joe4dev joe4dev merged commit 23ff761 into master Mar 9, 2019
@joe4dev joe4dev deleted the support/wasp-sw branch March 9, 2019 17:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants