Skip to content

Commit

Permalink
Updated rubocop to 0.58.2 (#1132)
Browse files Browse the repository at this point in the history
  • Loading branch information
justin808 authored Aug 19, 2018
1 parent 0dbfb69 commit 00b30ac
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 38 deletions.
2 changes: 2 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ AllCops:
Include:
- '**/Rakefile'
- '**/config.ru'
- 'Gemfile'
- '**/*.rb'

Exclude:
- 'vendor/**/*'
Expand Down
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,17 @@ See [Upgrading React on Rails](./docs/basics/upgrading-react-on-rails.md) for mo
Changes since last non-beta release.

*Please add entries here for your pull requests that are not yet released.*

### [11.1.2] - 2018-08-18

#### Fixed
- Tests now properly exist if the config.build_test_command fails
- Source path for project using Webpacker would default to "app/javascript" even if when the node_modules
directory was set to "client". Fix now makes the configuration of this crystal clear.
- renamed method RenderOptions.has_random_dom_id? to RenderOptions.random_dom_id? for rubocop rule.



### [11.1.1] - 2018-08-09
#### Fixed
- `TRUE` was deprecated in ruby 2.4, using `true` instead. [PR 1128](https://github.com/shakacode/react_on_rails/pull/1128) by [Aguardientico](https://github.com/Aguardientico).
Expand Down
2 changes: 1 addition & 1 deletion lib/generators/react_on_rails/dev_tests_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def add_yarn_relative_install_script_in_package_json
replacement_value = <<-STRING
"scripts": {
"postinstall": "yarn link react-on-rails",
STRING
STRING
new_client_package_json_contents = contents.gsub(/ {2}"scripts": {/,
replacement_value)
File.open(package_json, "w+") { |f| f.puts new_client_package_json_contents }
Expand Down
4 changes: 2 additions & 2 deletions lib/react_on_rails/react_component/render_options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def dom_id
end
end

def has_random_dom_id?
def random_dom_id?
return false if options[:id]

return false unless random_dom_id
Expand Down Expand Up @@ -77,7 +77,7 @@ def to_s
attr_reader :options

def base_dom_id
"#{react_component_name}-react-component"
"#{react_component_name}-react-component"
end

def generate_unique_dom_id
Expand Down
10 changes: 5 additions & 5 deletions lib/react_on_rails/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

module ReactOnRails
module Utils
TRUNCATION_FILLER = "\n... TRUNCATED ...\n"
TRUNCATION_FILLER = "\n... TRUNCATED ...\n".freeze

# https://forum.shakacode.com/t/yak-of-the-week-ruby-2-4-pathname-empty-changed-to-look-at-file-size/901
# return object if truthy, else return nil
Expand Down Expand Up @@ -163,10 +163,10 @@ def self.smart_trim(str, max_length = 1000)

return str[0, 1] + TRUNCATION_FILLER if max_length == 1

midpoint = (str.length / 2.0).ceil;
to_remove = str.length - max_length;
lstrip = (to_remove / 2.0).ceil;
rstrip = to_remove - lstrip;
midpoint = (str.length / 2.0).ceil
to_remove = str.length - max_length
lstrip = (to_remove / 2.0).ceil
rstrip = to_remove - lstrip
str[0..(midpoint - lstrip - 1)] + TRUNCATION_FILLER + str[(midpoint + rstrip)..-1]
end
end
Expand Down
6 changes: 3 additions & 3 deletions spec/dummy/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ GIT
PATH
remote: ../..
specs:
react_on_rails (11.1.0.beta.1)
react_on_rails (11.1.1)
addressable
connection_pool
execjs (~> 2.5)
Expand Down Expand Up @@ -235,7 +235,7 @@ GEM
rspec-retry (0.6.1)
rspec-core (> 3.3)
rspec-support (3.7.1)
rubocop (0.58.1)
rubocop (0.58.2)
jaro_winkler (~> 1.5.1)
parallel (~> 1.10)
parser (>= 2.5, != 2.5.1.1)
Expand All @@ -246,7 +246,7 @@ GEM
ruby-lint (2.3.1)
parser (~> 2.2)
slop (~> 3.4, >= 3.4.7)
ruby-progressbar (1.9.0)
ruby-progressbar (1.10.0)
ruby_dep (1.5.0)
rubyzip (1.2.1)
sass (3.5.6)
Expand Down
2 changes: 2 additions & 0 deletions spec/dummy/spec/helpers/react_on_rails_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require "rails_helper"
require "support/script_tag_utils"

# rubocop:disable Metrics/BlockLength
describe ReactOnRailsHelper, type: :helper do
before do
allow(self).to receive(:request) {
Expand Down Expand Up @@ -298,3 +299,4 @@ class PlainClass
end
end
end
# rubocop:enable Metrics/BlockLength
8 changes: 4 additions & 4 deletions spec/react_on_rails/react_component/render_options_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def the_attrs(react_component_name: "App", options: {})

expect(SecureRandom).to receive(:uuid).and_return("123456789")
expect(opts.dom_id).to eq "SomeApp-react-component-123456789"
expect(opts.has_random_dom_id?).to eq(true)
expect(opts.random_dom_id?).to eq(true)
end

it "is memoized" do
Expand All @@ -81,10 +81,10 @@ def the_attrs(react_component_name: "App", options: {})

context "with random_dom_id set to false" do
it "returns a default identifier" do
attrs = the_attrs(react_component_name: "SomeApp", options: { random_dom_id: false})
attrs = the_attrs(react_component_name: "SomeApp", options: { random_dom_id: false })
opts = described_class.new(attrs)
expect(opts.dom_id).to eq "SomeApp-react-component"
expect(opts.has_random_dom_id?).to eq(false)
expect(opts.random_dom_id?).to eq(false)
end
end
end
Expand All @@ -97,7 +97,7 @@ def the_attrs(react_component_name: "App", options: {})
opts = described_class.new(attrs)

expect(opts.dom_id).to eq "im-an-id"
expect(opts.has_random_dom_id?).to eq(false)
expect(opts.random_dom_id?).to eq(false)
end
end
end
Expand Down
47 changes: 24 additions & 23 deletions spec/react_on_rails/utils_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ module ReactOnRails
end
before do
allow(ReactOnRails).to receive_message_chain(:configuration, :generated_assets_dir)
.and_return("")
.and_return("")
allow(Webpacker).to receive_message_chain("dev_server.running?")
.and_return(false)
.and_return(false)
allow(Webpacker).to receive_message_chain("config.public_output_path")
.and_return(webpacker_public_output_path)
.and_return(webpacker_public_output_path)
allow(ReactOnRails::WebpackerUtils).to receive(:using_webpacker?).and_return(true)
end

Expand All @@ -39,8 +39,8 @@ module ReactOnRails
# [2] (pry) ReactOnRails::WebpackerUtils: 0> Webpacker.manifest.lookup("app-bundle.js")
# "/webpack/development/app-bundle-c1d2b6ab73dffa7d9c0e.js"
allow(Webpacker).to receive_message_chain("manifest.lookup!")
.with("webpack-bundle.js")
.and_return("/webpack/dev/webpack-bundle-0123456789abcdef.js")
.with("webpack-bundle.js")
.and_return("/webpack/dev/webpack-bundle-0123456789abcdef.js")
end

it { expect(subject).to eq("#{webpacker_public_output_path}/webpack-bundle-0123456789abcdef.js") }
Expand All @@ -58,15 +58,15 @@ module ReactOnRails
context "Without Webpacker enabled" do
before do
allow(ReactOnRails).to receive_message_chain(:configuration, :generated_assets_dir)
.and_return("public/webpack/dev")
.and_return("public/webpack/dev")
allow(ReactOnRails::WebpackerUtils).to receive(:using_webpacker?).and_return(false)
end

it {
expect(subject).to eq(File.expand_path(
File.join(Rails.root,
"public/webpack/dev/webpack-bundle.js")
))
File.join(Rails.root,
"public/webpack/dev/webpack-bundle.js")
))
}
end
end
Expand All @@ -76,17 +76,17 @@ module ReactOnRails
allow(Rails).to receive(:root).and_return(Pathname.new("."))
allow(ReactOnRails::WebpackerUtils).to receive(:using_webpacker?).and_return(true)
allow(Webpacker).to receive_message_chain("config.public_output_path")
.and_return(Pathname.new("public/webpack/development"))
.and_return(Pathname.new("public/webpack/development"))
end

context "With Webpacker enabled and server file not in manifest", :webpacker do
it "returns the unhashed server path" do
server_bundle_name = "server-bundle.js"
allow(ReactOnRails).to receive_message_chain("configuration.server_bundle_js_file")
.and_return(server_bundle_name)
.and_return(server_bundle_name)
allow(Webpacker).to receive_message_chain("manifest.lookup!")
.with(server_bundle_name)
.and_raise(Webpacker::Manifest::MissingEntryError)
.with(server_bundle_name)
.and_raise(Webpacker::Manifest::MissingEntryError)

path = Utils.server_bundle_js_file_path

Expand All @@ -97,10 +97,10 @@ module ReactOnRails
context "With Webpacker enabled and server file in the manifest", :webpacker do
it "returns the correct path hashed server path" do
allow(ReactOnRails).to receive_message_chain("configuration.server_bundle_js_file")
.and_return("webpack-bundle.js")
.and_return("webpack-bundle.js")
allow(Webpacker).to receive_message_chain("manifest.lookup!")
.with("webpack-bundle.js")
.and_return("webpack/development/webpack-bundle-123456.js")
.with("webpack-bundle.js")
.and_return("webpack/development/webpack-bundle-123456.js")

path = Utils.server_bundle_js_file_path

Expand Down Expand Up @@ -250,10 +250,10 @@ module ReactOnRails

describe ".smart_trim" do
it "trims smartly" do
s = '1234567890'
s = "1234567890"

expect(Utils.smart_trim(s, -1)).to eq('1234567890')
expect(Utils.smart_trim(s, 0)).to eq('1234567890')
expect(Utils.smart_trim(s, -1)).to eq("1234567890")
expect(Utils.smart_trim(s, 0)).to eq("1234567890")
expect(Utils.smart_trim(s, 1)).to eq("1#{Utils::TRUNCATION_FILLER}")
expect(Utils.smart_trim(s, 2)).to eq("1#{Utils::TRUNCATION_FILLER}0")
expect(Utils.smart_trim(s, 3)).to eq("1#{Utils::TRUNCATION_FILLER}90")
Expand All @@ -263,15 +263,16 @@ module ReactOnRails
expect(Utils.smart_trim(s, 7)).to eq("123#{Utils::TRUNCATION_FILLER}7890")
expect(Utils.smart_trim(s, 8)).to eq("1234#{Utils::TRUNCATION_FILLER}7890")
expect(Utils.smart_trim(s, 9)).to eq("1234#{Utils::TRUNCATION_FILLER}67890")
expect(Utils.smart_trim(s, 10)).to eq('1234567890')
expect(Utils.smart_trim(s, 11)).to eq('1234567890')
expect(Utils.smart_trim(s, 10)).to eq("1234567890")
expect(Utils.smart_trim(s, 11)).to eq("1234567890")
end

it "trims handles a hash" do
s = { a: '1234567890' }
s = { a: "1234567890" }

expect(Utils.smart_trim(s, 9)).to eq(
"{:a=#{Utils::TRUNCATION_FILLER}890\"}")
"{:a=#{Utils::TRUNCATION_FILLER}890\"}"
)
end
end
end
Expand Down

0 comments on commit 00b30ac

Please sign in to comment.