Skip to content

Commit

Permalink
Fix RuboCop offenses
Browse files Browse the repository at this point in the history
And enable `context_dependent` of Style/BracesAroundHashParameters cop.
  • Loading branch information
koic committed Aug 16, 2017
1 parent 11fd246 commit 7c260ae
Show file tree
Hide file tree
Showing 31 changed files with 141 additions and 139 deletions.
1 change: 1 addition & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Style/AndOr:
# method call.
Style/BracesAroundHashParameters:
Enabled: true
EnforcedStyle: context_dependent

# Align `when` with `case`.
Layout/CaseIndentation:
Expand Down
2 changes: 1 addition & 1 deletion actioncable/test/channel/stream_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ class StreamFromTest < ActionCable::TestCase
subscribe_to connection, identifiers: { id: 1 }

connection.websocket.expects(:transmit)
@server.broadcast "test_room_1", { foo: "bar" }, coder: DummyEncoder
@server.broadcast "test_room_1", { foo: "bar" }, { coder: DummyEncoder }
wait_for_async
wait_for_executor connection.server.worker_pool.executor
end
Expand Down
4 changes: 2 additions & 2 deletions actionpack/test/controller/live_stream_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ def sse_with_event
def sse_with_retry
sse = SSE.new(response.stream, retry: 1000)
sse.write("{\"name\":\"John\"}")
sse.write({ name: "Ryan" }, retry: 1500)
sse.write({ name: "Ryan" }, { retry: 1500 })
ensure
sse.close
end

def sse_with_id
sse = SSE.new(response.stream)
sse.write("{\"name\":\"John\"}", id: 1)
sse.write({ name: "Ryan" }, id: 2)
sse.write({ name: "Ryan" }, { id: 2 })
ensure
sse.close
end
Expand Down
2 changes: 1 addition & 1 deletion actionpack/test/controller/redirect_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def redirect_with_status
end

def redirect_with_status_hash
redirect_to({ action: "hello_world" }, status: 301)
redirect_to({ action: "hello_world" }, { status: 301 })
end

def redirect_with_protocol
Expand Down
20 changes: 10 additions & 10 deletions actionpack/test/controller/resources_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -943,8 +943,8 @@ def test_resource_has_only_collection_action
assert_resource_allowed_routes("products", {}, { id: "1" }, [], [:index, :new, :create, :show, :edit, :update, :destroy])
assert_resource_allowed_routes("products", { format: "xml" }, { id: "1" }, [], [:index, :new, :create, :show, :edit, :update, :destroy])

assert_recognizes({ controller: "products", action: "sale" }, path: "products/sale", method: :get)
assert_recognizes({ controller: "products", action: "sale", format: "xml" }, path: "products/sale.xml", method: :get)
assert_recognizes({ controller: "products", action: "sale" }, { path: "products/sale", method: :get })
assert_recognizes({ controller: "products", action: "sale", format: "xml" }, { path: "products/sale.xml", method: :get })
end
end

Expand All @@ -959,8 +959,8 @@ def test_resource_has_only_member_action
assert_resource_allowed_routes("products", {}, { id: "1" }, [], [:index, :new, :create, :show, :edit, :update, :destroy])
assert_resource_allowed_routes("products", { format: "xml" }, { id: "1" }, [], [:index, :new, :create, :show, :edit, :update, :destroy])

assert_recognizes({ controller: "products", action: "preview", id: "1" }, path: "products/1/preview", method: :get)
assert_recognizes({ controller: "products", action: "preview", id: "1", format: "xml" }, path: "products/1/preview.xml", method: :get)
assert_recognizes({ controller: "products", action: "preview", id: "1" }, { path: "products/1/preview", method: :get })
assert_recognizes({ controller: "products", action: "preview", id: "1", format: "xml" }, { path: "products/1/preview.xml", method: :get })
end
end

Expand All @@ -977,8 +977,8 @@ def test_singleton_resource_has_only_member_action
assert_singleton_resource_allowed_routes("accounts", {}, [], [:new, :create, :show, :edit, :update, :destroy])
assert_singleton_resource_allowed_routes("accounts", { format: "xml" }, [], [:new, :create, :show, :edit, :update, :destroy])

assert_recognizes({ controller: "accounts", action: "signup" }, path: "account/signup", method: :get)
assert_recognizes({ controller: "accounts", action: "signup", format: "xml" }, path: "account/signup.xml", method: :get)
assert_recognizes({ controller: "accounts", action: "signup" }, { path: "account/signup", method: :get })
assert_recognizes({ controller: "accounts", action: "signup", format: "xml" }, { path: "account/signup.xml", method: :get })
end
end

Expand All @@ -995,8 +995,8 @@ def test_nested_resource_has_only_show_and_member_action
assert_resource_allowed_routes("images", { product_id: "1" }, { id: "2" }, :show, [:index, :new, :create, :edit, :update, :destroy], "products/1/images")
assert_resource_allowed_routes("images", { product_id: "1", format: "xml" }, { id: "2" }, :show, [:index, :new, :create, :edit, :update, :destroy], "products/1/images")

assert_recognizes({ controller: "images", action: "thumbnail", product_id: "1", id: "2" }, path: "products/1/images/2/thumbnail", method: :get)
assert_recognizes({ controller: "images", action: "thumbnail", product_id: "1", id: "2", format: "jpg" }, path: "products/1/images/2/thumbnail.jpg", method: :get)
assert_recognizes({ controller: "images", action: "thumbnail", product_id: "1", id: "2" }, { path: "products/1/images/2/thumbnail", method: :get })
assert_recognizes({ controller: "images", action: "thumbnail", product_id: "1", id: "2", format: "jpg" }, { path: "products/1/images/2/thumbnail.jpg", method: :get })
end
end

Expand Down Expand Up @@ -1069,7 +1069,7 @@ def test_assert_routing_accepts_all_as_a_valid_method
match "/products", to: "products#show", via: :all
end

assert_routing({ method: "all", path: "/products" }, controller: "products", action: "show")
assert_routing({ method: "all", path: "/products" }, { controller: "products", action: "show" })
end
end

Expand All @@ -1080,7 +1080,7 @@ def test_assert_routing_fails_when_not_all_http_methods_are_recognized
end

assert_raises(Minitest::Assertion) do
assert_routing({ method: "all", path: "/products" }, controller: "products", action: "show")
assert_routing({ method: "all", path: "/products" }, { controller: "products", action: "show" })
end
end
end
Expand Down
8 changes: 4 additions & 4 deletions actionpack/test/controller/test_case_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -392,9 +392,9 @@ def test_should_not_impose_childless_html_tags_in_xml

def test_assert_generates
assert_generates "controller/action/5", controller: "controller", action: "action", id: "5"
assert_generates "controller/action/7", { id: "7" }, controller: "controller", action: "action"
assert_generates "controller/action/5", { controller: "controller", action: "action", id: "5", name: "bob" }, {}, name: "bob"
assert_generates "controller/action/7", { id: "7", name: "bob" }, { controller: "controller", action: "action" }, name: "bob"
assert_generates "controller/action/7", { id: "7" }, { controller: "controller", action: "action" }
assert_generates "controller/action/5", { controller: "controller", action: "action", id: "5", name: "bob" }, {}, { name: "bob" }
assert_generates "controller/action/7", { id: "7", name: "bob" }, { controller: "controller", action: "action" }, { name: "bob" }
assert_generates "controller/action/7", { id: "7" }, { controller: "controller", action: "action", name: "bob" }, {}
end

Expand All @@ -405,7 +405,7 @@ def test_assert_routing
def test_assert_routing_with_method
with_routing do |set|
set.draw { resources(:content) }
assert_routing({ method: "post", path: "content" }, controller: "content", action: "create")
assert_routing({ method: "post", path: "content" }, { controller: "content", action: "create" })
end
end

Expand Down
12 changes: 6 additions & 6 deletions actionpack/test/dispatch/routing_assertions_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ def test_assert_generates
end

def test_assert_generates_with_defaults
assert_generates("/articles/1/edit", { controller: "articles", action: "edit" }, id: "1")
assert_generates("/articles/1/edit", { controller: "articles", action: "edit" }, { id: "1" })
end

def test_assert_generates_with_extras
assert_generates("/articles", { controller: "articles", action: "index", page: "1" }, {}, page: "1")
assert_generates("/articles", { controller: "articles", action: "index", page: "1" }, {}, { page: "1" })
end

def test_assert_recognizes
Expand All @@ -50,8 +50,8 @@ def test_assert_recognizes_with_extras
end

def test_assert_recognizes_with_method
assert_recognizes({ controller: "articles", action: "create" }, path: "/articles", method: :post)
assert_recognizes({ controller: "articles", action: "update", id: "1" }, path: "/articles/1", method: :put)
assert_recognizes({ controller: "articles", action: "create" }, { path: "/articles", method: :post })
assert_recognizes({ controller: "articles", action: "update", id: "1" }, { path: "/articles/1", method: :put })
end

def test_assert_recognizes_with_hash_constraint
Expand Down Expand Up @@ -96,11 +96,11 @@ def test_assert_routing_raises_message
end

def test_assert_routing_with_defaults
assert_routing("/articles/1/edit", { controller: "articles", action: "edit", id: "1" }, id: "1")
assert_routing("/articles/1/edit", { controller: "articles", action: "edit", id: "1" }, { id: "1" })
end

def test_assert_routing_with_extras
assert_routing("/articles", { controller: "articles", action: "index", page: "1" }, {}, page: "1")
assert_routing("/articles", { controller: "articles", action: "index", page: "1" }, {}, { page: "1" })
end

def test_assert_routing_with_hash_constraint
Expand Down
10 changes: 5 additions & 5 deletions actionpack/test/journey/router_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -186,22 +186,22 @@ def test_path_not_found
def test_required_part_in_recall
get "/messages/:a/:b", to: "foo#bar"

path, _ = @formatter.generate(nil, { controller: "foo", action: "bar", a: "a" }, b: "b")
path, _ = @formatter.generate(nil, { controller: "foo", action: "bar", a: "a" }, { b: "b" })
assert_equal "/messages/a/b", path
end

def test_splat_in_recall
get "/*path", to: "foo#bar"

path, _ = @formatter.generate(nil, { controller: "foo", action: "bar" }, path: "b")
path, _ = @formatter.generate(nil, { controller: "foo", action: "bar" }, { path: "b" })
assert_equal "/b", path
end

def test_recall_should_be_used_when_scoring
get "/messages/:action(/:id(.:format))", to: "foo#bar"
get "/messages/:id(.:format)", to: "bar#baz"

path, _ = @formatter.generate(nil, { controller: "foo", id: 10 }, action: "index")
path, _ = @formatter.generate(nil, { controller: "foo", id: 10 }, { action: "index" })
assert_equal "/messages/index/10", path
end

Expand Down Expand Up @@ -314,7 +314,7 @@ def test_generate_uses_recall_if_needed
path, params = @formatter.generate(
nil,
{ controller: "tasks", id: 10 },
action: "index")
{ action: "index" })
assert_equal "/tasks/index/10", path
assert_equal({}, params)
end
Expand All @@ -325,7 +325,7 @@ def test_generate_with_name
path, params = @formatter.generate(
"tasks",
{ controller: "tasks" },
controller: "tasks", action: "index")
{ controller: "tasks", action: "index" })
assert_equal "/tasks", path
assert_equal({}, params)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,10 @@ class WithLayouts < PrefixedViews

private
def self.layout(formats)
find_template(name.underscore, { formats: formats }, _prefixes: ["layouts"])
find_template(name.underscore, { formats: formats }, { _prefixes: ["layouts"] })
rescue ActionView::MissingTemplate
begin
find_template("application", { formats: formats }, _prefixes: ["layouts"])
find_template("application", { formats: formats }, { _prefixes: ["layouts"] })
rescue ActionView::MissingTemplate
end
end
Expand Down
Loading

0 comments on commit 7c260ae

Please sign in to comment.