提交 7c260ae2 编写于 作者: K Koichi ITO

Fix RuboCop offenses

And enable `context_dependent` of Style/BracesAroundHashParameters cop.
上级 11fd246d
......@@ -16,6 +16,7 @@ Style/AndOr:
# method call.
Style/BracesAroundHashParameters:
Enabled: true
EnforcedStyle: context_dependent
# Align `when` with `case`.
Layout/CaseIndentation:
......
......@@ -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
......
......@@ -30,7 +30,7 @@ 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
......@@ -38,7 +38,7 @@ def sse_with_retry
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
......
......@@ -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
......
......@@ -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
......@@ -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
......@@ -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
......@@ -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
......@@ -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
......@@ -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
......
......@@ -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
......@@ -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
......
......@@ -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
......@@ -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
......@@ -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
......
......@@ -186,14 +186,14 @@ 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
......@@ -201,7 +201,7 @@ 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
......@@ -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
......@@ -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
......
......@@ -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
......
......@@ -95,7 +95,7 @@ def with_collection_check_boxes(*args, &block)
test "collection radio accepts html options as input" do
collection = [[1, true], [0, false]]
with_collection_radio_buttons :user, :active, collection, :last, :first, {}, class: "special-radio"
with_collection_radio_buttons :user, :active, collection, :last, :first, {}, { class: "special-radio" }
assert_select "input[type=radio][value=true].special-radio#user_active_true"
assert_select "input[type=radio][value=false].special-radio#user_active_false"
......@@ -215,7 +215,7 @@ def with_collection_check_boxes(*args, &block)
test "collection radio buttons generates a hidden field using the given :name in :html_options" do
collection = [Category.new(1, "Category 1"), Category.new(2, "Category 2")]
with_collection_radio_buttons :user, :category_ids, collection, :id, :name, {}, name: "user[other_category_ids]"
with_collection_radio_buttons :user, :category_ids, collection, :id, :name, {}, { name: "user[other_category_ids]" }
assert_select "input[type=hidden][name='user[other_category_ids]'][value='']", count: 1
end
......@@ -259,7 +259,7 @@ def with_collection_check_boxes(*args, &block)
test "collection check boxes generates a hidden field using the given :name in :html_options" do
collection = [Category.new(1, "Category 1"), Category.new(2, "Category 2")]
with_collection_check_boxes :user, :category_ids, collection, :id, :name, {}, name: "user[other_category_ids][]"
with_collection_check_boxes :user, :category_ids, collection, :id, :name, {}, { name: "user[other_category_ids][]" }
assert_select "input[type=hidden][name='user[other_category_ids][]'][value='']", count: 1
end
......@@ -446,7 +446,7 @@ def with_collection_check_boxes(*args, &block)
test "collection check boxes accepts html options" do
collection = [[1, "Category 1"], [2, "Category 2"]]
with_collection_check_boxes :user, :category_ids, collection, :first, :last, {}, class: "check"
with_collection_check_boxes :user, :category_ids, collection, :first, :last, {}, { class: "check" }
assert_select 'input.check[type=checkbox][value="1"]'
assert_select 'input.check[type=checkbox][value="2"]'
......
......@@ -1386,7 +1386,7 @@ def test_nil_id
)
assert_dom_equal(
'<select name="post[secret]"></select>',
select("post", "secret", [], {}, "id" => nil)
select("post", "secret", [], {}, { "id" => nil })
)
assert_dom_equal(
text_field("post", "title", "id" => nil),
......
......@@ -491,7 +491,7 @@ def test_select
def test_select_without_multiple
assert_dom_equal(
"<select id=\"post_category\" name=\"post[category]\"></select>",
select(:post, :category, "", {}, multiple: false)
select(:post, :category, "", {}, { multiple: false })
)
end
......@@ -639,7 +639,7 @@ def test_select_under_fields_for_with_block_without_options
end
def test_select_with_multiple_to_add_hidden_input
output_buffer = select(:post, :category, "", {}, multiple: true)
output_buffer = select(:post, :category, "", {}, { multiple: true })
assert_dom_equal(
"<input type=\"hidden\" name=\"post[category][]\" value=\"\"/><select multiple=\"multiple\" id=\"post_category\" name=\"post[category][]\"></select>",
output_buffer
......@@ -647,7 +647,7 @@ def test_select_with_multiple_to_add_hidden_input
end
def test_select_with_multiple_and_without_hidden_input
output_buffer = select(:post, :category, "", { include_hidden: false }, multiple: true)
output_buffer = select(:post, :category, "", { include_hidden: false }, { multiple: true })
assert_dom_equal(
"<select multiple=\"multiple\" id=\"post_category\" name=\"post[category][]\"></select>",
output_buffer
......@@ -655,7 +655,7 @@ def test_select_with_multiple_and_without_hidden_input
end
def test_select_with_multiple_and_with_explicit_name_ending_with_brackets
output_buffer = select(:post, :category, [], { include_hidden: false }, multiple: true, name: "post[category][]")
output_buffer = select(:post, :category, [], { include_hidden: false }, { multiple: true, name: "post[category][]" })
assert_dom_equal(
"<select multiple=\"multiple\" id=\"post_category\" name=\"post[category][]\"></select>",
output_buffer
......@@ -663,7 +663,7 @@ def test_select_with_multiple_and_with_explicit_name_ending_with_brackets
end
def test_select_with_multiple_and_disabled_to_add_disabled_hidden_input
output_buffer = select(:post, :category, "", {}, multiple: true, disabled: true)
output_buffer = select(:post, :category, "", {}, { multiple: true, disabled: true })
assert_dom_equal(
"<input disabled=\"disabled\"type=\"hidden\" name=\"post[category][]\" value=\"\"/><select multiple=\"multiple\" disabled=\"disabled\" id=\"post_category\" name=\"post[category][]\"></select>",
output_buffer
......@@ -682,7 +682,7 @@ def test_select_with_blank
def test_select_with_include_blank_false_and_required
@post = Post.new
@post.category = "<mus>"
e = assert_raises(ArgumentError) { select("post", "category", %w( abe <mus> hest), { include_blank: false }, required: "required") }
e = assert_raises(ArgumentError) { select("post", "category", %w( abe <mus> hest), { include_blank: false }, { required: "required" }) }
assert_match(/include_blank cannot be false for a required field./, e.message)
end
......@@ -762,7 +762,7 @@ def test_select_with_html_options
@post.category = ""
assert_dom_equal(
"<select class=\"disabled\" disabled=\"disabled\" name=\"post[category]\" id=\"post_category\"><option value=\"\">Please select</option>\n<option value=\"\"></option>\n</select>",
select("post", "category", [], { prompt: true, include_blank: true }, class: "disabled", disabled: true)
select("post", "category", [], { prompt: true, include_blank: true }, { class: "disabled", disabled: true })
)
end
......@@ -778,42 +778,42 @@ def test_select_with_nil
def test_required_select
assert_dom_equal(
%(<select id="post_category" name="post[category]" required="required"><option value=""></option>\n<option value="abe">abe</option>\n<option value="mus">mus</option>\n<option value="hest">hest</option></select>),
select("post", "category", %w(abe mus hest), {}, required: true)
select("post", "category", %w(abe mus hest), {}, { required: true })
)
end
def test_required_select_with_include_blank_prompt
assert_dom_equal(
%(<select id="post_category" name="post[category]" required="required"><option value="">Select one</option>\n<option value="abe">abe</option>\n<option value="mus">mus</option>\n<option value="hest">hest</option></select>),
select("post", "category", %w(abe mus hest), { include_blank: "Select one" }, required: true)
select("post", "category", %w(abe mus hest), { include_blank: "Select one" }, { required: true })
)
end
def test_required_select_with_prompt
assert_dom_equal(
%(<select id="post_category" name="post[category]" required="required"><option value="">Select one</option>\n<option value="abe">abe</option>\n<option value="mus">mus</option>\n<option value="hest">hest</option></select>),
select("post", "category", %w(abe mus hest), { prompt: "Select one" }, required: true)
select("post", "category", %w(abe mus hest), { prompt: "Select one" }, { required: true })
)
end
def test_required_select_display_size_equals_to_one
assert_dom_equal(
%(<select id="post_category" name="post[category]" required="required" size="1"><option value=""></option>\n<option value="abe">abe</option>\n<option value="mus">mus</option>\n<option value="hest">hest</option></select>),
select("post", "category", %w(abe mus hest), {}, required: true, size: 1)
select("post", "category", %w(abe mus hest), {}, { required: true, size: 1 })
)
end
def test_required_select_with_display_size_bigger_than_one
assert_dom_equal(
%(<select id="post_category" name="post[category]" required="required" size="2"><option value="abe">abe</option>\n<option value="mus">mus</option>\n<option value="hest">hest</option></select>),
select("post", "category", %w(abe mus hest), {}, required: true, size: 2)
select("post", "category", %w(abe mus hest), {}, { required: true, size: 2 })
)
end
def test_required_select_with_multiple_option
assert_dom_equal(
%(<input name="post[category][]" type="hidden" value=""/><select id="post_category" multiple="multiple" name="post[category][]" required="required"><option value="abe">abe</option>\n<option value="mus">mus</option>\n<option value="hest">hest</option></select>),
select("post", "category", %w(abe mus hest), {}, required: true, multiple: true)
select("post", "category", %w(abe mus hest), {}, { required: true, multiple: true })
)
end
......@@ -852,7 +852,7 @@ def test_select_with_index_option
assert_dom_equal(
expected,
select("album[]", "genre", %w[rap rock country], {}, index: nil)
select("album[]", "genre", %w[rap rock country], {}, { index: nil })
)
end
......@@ -982,7 +982,7 @@ def test_collection_select_with_blank_and_style
assert_dom_equal(
"<select id=\"post_author_name\" name=\"post[author_name]\" style=\"width: 200px\"><option value=\"\"></option>\n<option value=\"&lt;Abe&gt;\">&lt;Abe&gt;</option>\n<option value=\"Babe\" selected=\"selected\">Babe</option>\n<option value=\"Cabe\">Cabe</option></select>",
collection_select("post", "author_name", dummy_posts, "author_name", "author_name", { include_blank: true }, "style" => "width: 200px")
collection_select("post", "author_name", dummy_posts, "author_name", "author_name", { include_blank: true }, { "style" => "width: 200px" })
)
end
......@@ -992,7 +992,7 @@ def test_collection_select_with_blank_as_string_and_style
assert_dom_equal(
"<select id=\"post_author_name\" name=\"post[author_name]\" style=\"width: 200px\"><option value=\"\">No Selection</option>\n<option value=\"&lt;Abe&gt;\">&lt;Abe&gt;</option>\n<option value=\"Babe\" selected=\"selected\">Babe</option>\n<option value=\"Cabe\">Cabe</option></select>",
collection_select("post", "author_name", dummy_posts, "author_name", "author_name", { include_blank: "No Selection" }, "style" => "width: 200px")
collection_select("post", "author_name", dummy_posts, "author_name", "author_name", { include_blank: "No Selection" }, { "style" => "width: 200px" })
)
end
......@@ -1003,10 +1003,10 @@ def test_collection_select_with_multiple_option_appends_array_brackets_and_hidde
expected = "<input type=\"hidden\" name=\"post[author_name][]\" value=\"\"/><select id=\"post_author_name\" name=\"post[author_name][]\" multiple=\"multiple\"><option value=\"\"></option>\n<option value=\"&lt;Abe&gt;\">&lt;Abe&gt;</option>\n<option value=\"Babe\" selected=\"selected\">Babe</option>\n<option value=\"Cabe\">Cabe</option></select>"
# Should suffix default name with [].
assert_dom_equal expected, collection_select("post", "author_name", dummy_posts, "author_name", "author_name", { include_blank: true }, multiple: true)
assert_dom_equal expected, collection_select("post", "author_name", dummy_posts, "author_name", "author_name", { include_blank: true }, { multiple: true })
# Shouldn't suffix custom name with [].
assert_dom_equal expected, collection_select("post", "author_name", dummy_posts, "author_name", "author_name", { include_blank: true, name: "post[author_name][]" }, multiple: true)
assert_dom_equal expected, collection_select("post", "author_name", dummy_posts, "author_name", "author_name", { include_blank: true, name: "post[author_name][]" }, { multiple: true })
end
def test_collection_select_with_blank_and_selected
......@@ -1149,7 +1149,7 @@ def test_time_zone_select_with_blank_as_string
def test_time_zone_select_with_style
@firm = Firm.new("D")
html = time_zone_select("firm", "time_zone", nil, {},
"style" => "color: red")
{ "style" => "color: red" })
assert_dom_equal "<select id=\"firm_time_zone\" name=\"firm[time_zone]\" style=\"color: red\">" \
"<option value=\"A\">A</option>\n" \
"<option value=\"B\">B</option>\n" \
......@@ -1159,13 +1159,13 @@ def test_time_zone_select_with_style
"</select>",
html
assert_dom_equal html, time_zone_select("firm", "time_zone", nil, {},
style: "color: red")
{ style: "color: red" })
end
def test_time_zone_select_with_blank_and_style
@firm = Firm.new("D")
html = time_zone_select("firm", "time_zone", nil,
{ include_blank: true }, "style" => "color: red")
{ include_blank: true }, { "style" => "color: red" })
assert_dom_equal "<select id=\"firm_time_zone\" name=\"firm[time_zone]\" style=\"color: red\">" \
"<option value=\"\"></option>\n" \
"<option value=\"A\">A</option>\n" \
......@@ -1176,13 +1176,13 @@ def test_time_zone_select_with_blank_and_style
"</select>",
html
assert_dom_equal html, time_zone_select("firm", "time_zone", nil,
{ include_blank: true }, style: "color: red")
{ include_blank: true }, { style: "color: red" })
end
def test_time_zone_select_with_blank_as_string_and_style
@firm = Firm.new("D")
html = time_zone_select("firm", "time_zone", nil,
{ include_blank: "No Zone" }, "style" => "color: red")
{ include_blank: "No Zone" }, { "style" => "color: red" })
assert_dom_equal "<select id=\"firm_time_zone\" name=\"firm[time_zone]\" style=\"color: red\">" \
"<option value=\"\">No Zone</option>\n" \
"<option value=\"A\">A</option>\n" \
......@@ -1193,7 +1193,7 @@ def test_time_zone_select_with_blank_as_string_and_style
"</select>",
html
assert_dom_equal html, time_zone_select("firm", "time_zone", nil,
{ include_blank: "No Zone" }, style: "color: red")
{ include_blank: "No Zone" }, { style: "color: red" })
end
def test_time_zone_select_with_priority_zones
......
......@@ -100,53 +100,53 @@ def test_form_tag
end
def test_form_tag_multipart
actual = form_tag({}, "multipart" => true)
actual = form_tag({}, { "multipart" => true })
expected = whole_form("http://www.example.com", enctype: true)
assert_dom_equal expected, actual
end
def test_form_tag_with_method_patch
actual = form_tag({}, method: :patch)
actual = form_tag({}, { method: :patch })
expected = whole_form("http://www.example.com", method: :patch)
assert_dom_equal expected, actual
end
def test_form_tag_with_method_put
actual = form_tag({}, method: :put)
actual = form_tag({}, { method: :put })
expected = whole_form("http://www.example.com", method: :put)
assert_dom_equal expected, actual
end
def test_form_tag_with_method_delete
actual = form_tag({}, method: :delete)
actual = form_tag({}, { method: :delete })
expected = whole_form("http://www.example.com", method: :delete)
assert_dom_equal expected, actual
end
def test_form_tag_with_remote
actual = form_tag({}, remote: true)
actual = form_tag({}, { remote: true })
expected = whole_form("http://www.example.com", remote: true)
assert_dom_equal expected, actual
end
def test_form_tag_with_remote_false
actual = form_tag({}, remote: false)
actual = form_tag({}, { remote: false })
expected = whole_form
assert_dom_equal expected, actual
end
def test_form_tag_enforce_utf8_true
actual = form_tag({}, enforce_utf8: true)
actual = form_tag({}, { enforce_utf8: true })
expected = whole_form("http://www.example.com", enforce_utf8: true)
assert_dom_equal expected, actual
assert actual.html_safe?
end
def test_form_tag_enforce_utf8_false
actual = form_tag({}, enforce_utf8: false)
actual = form_tag({}, { enforce_utf8: false })
expected = whole_form("http://www.example.com", enforce_utf8: false)
assert_dom_equal expected, actual
assert actual.html_safe?
......
......@@ -50,19 +50,19 @@ def test_simple_format_should_sanitize_input_when_sanitize_option_is_not_false
def test_simple_format_should_sanitize_input_when_sanitize_option_is_true
assert_equal "<p><b> test with unsafe string </b>code!</p>",
simple_format("<b> test with unsafe string </b><script>code!</script>", {}, sanitize: true)
simple_format("<b> test with unsafe string </b><script>code!</script>", {}, { sanitize: true })
end
def test_simple_format_should_not_sanitize_input_when_sanitize_option_is_false
assert_equal "<p><b> test with unsafe string </b><script>code!</script></p>", simple_format("<b> test with unsafe string </b><script>code!</script>", {}, sanitize: false)
assert_equal "<p><b> test with unsafe string </b><script>code!</script></p>", simple_format("<b> test with unsafe string </b><script>code!</script>", {}, { sanitize: false })
end
def test_simple_format_with_custom_wrapper
assert_equal "<div></div>", simple_format(nil, {}, wrapper_tag: "div")
assert_equal "<div></div>", simple_format(nil, {}, { wrapper_tag: "div" })
end
def test_simple_format_with_custom_wrapper_and_multi_line_breaks
assert_equal "<div>We want to put a wrapper...</div>\n\n<div>...right there.</div>", simple_format("We want to put a wrapper...\n\n...right there.", {}, wrapper_tag: "div")
assert_equal "<div>We want to put a wrapper...</div>\n\n<div>...right there.</div>", simple_format("We want to put a wrapper...\n\n...right there.", {}, { wrapper_tag: "div" })
end
def test_simple_format_should_not_change_the_text_passed
......
......@@ -15,11 +15,12 @@ def create_application_record
private
def application_record_file_name
@application_record_file_name ||= if namespaced?
"app/models/#{namespaced_path}/application_record.rb"
else
"app/models/application_record.rb"
end
@application_record_file_name ||=
if namespaced?
"app/models/#{namespaced_path}/application_record.rb"
else
"app/models/application_record.rb"
end
end
end
end
......
......@@ -16,7 +16,7 @@ class AttributeSetTest < ActiveRecord::TestCase
test "building with custom types" do
builder = AttributeSet::Builder.new(foo: Type::Float.new)
attributes = builder.build_from_database({ foo: "3.3", bar: "4.4" }, bar: Type::Integer.new)
attributes = builder.build_from_database({ foo: "3.3", bar: "4.4" }, { bar: Type::Integer.new })
assert_equal 3.3, attributes[:foo].value
assert_equal 4, attributes[:bar].value
......
......@@ -84,8 +84,8 @@ def url_for_direct_upload(key, expires_in:, content_type:, content_length:, chec
content_length: content_length,
checksum: checksum
},
expires_in: expires_in,
purpose: :blob_token
{ expires_in: expires_in,
purpose: :blob_token }
)
generated_url =
......
......@@ -100,11 +100,11 @@ def test_hash_key_identifiers_are_always_quoted
end
def test_hash_should_allow_key_filtering_with_only
assert_equal %({"a":1}), ActiveSupport::JSON.encode({ "a" => 1, :b => 2, :c => 3 }, only: "a")
assert_equal %({"a":1}), ActiveSupport::JSON.encode({ "a" => 1, :b => 2, :c => 3 }, { only: "a" })
end
def test_hash_should_allow_key_filtering_with_except
assert_equal %({"b":2}), ActiveSupport::JSON.encode({ "foo" => "bar", :b => 2, :c => 3 }, except: ["foo", :c])
assert_equal %({"b":2}), ActiveSupport::JSON.encode({ "foo" => "bar", :b => 2, :c => 3 }, { except: ["foo", :c] })
end
def test_time_to_json_includes_local_offset
......
......@@ -9,7 +9,7 @@ class Updater
class << self
def generator
@generator ||= Rails::Generators::PluginGenerator.new ["plugin"],
{ engine: true }, destination_root: ENGINE_ROOT
{ engine: true }, { destination_root: ENGINE_ROOT }
end
def run(action)
......
......@@ -11,7 +11,7 @@ namespace :app do
template = File.expand_path(template) if template !~ %r{\A[A-Za-z][A-Za-z0-9+\-\.]*://}
require_relative "../generators"
require_relative "../generators/rails/app/app_generator"
generator = Rails::Generators::AppGenerator.new [Rails.root], {}, destination_root: Rails.root
generator = Rails::Generators::AppGenerator.new [Rails.root], {}, { destination_root: Rails.root }
generator.apply template, verbose: false
end
......
......@@ -477,9 +477,9 @@ class ::PostsController < ActionController::Base ; end
class ::PostsController < ActionController::Base; end
get "/posts", {}, "HTTPS" => "off"
get "/posts", {}, { "HTTPS" => "off" }
assert_match('src="http://example.com/assets/application.self.js', last_response.body)
get "/posts", {}, "HTTPS" => "on"
get "/posts", {}, { "HTTPS" => "on" }
assert_match('src="https://example.com/assets/application.self.js', last_response.body)
end
......
......@@ -1333,10 +1333,10 @@ def index
end
end
get "/", {}, "HTTP_ACCEPT" => "application/xml"
get "/", {}, { "HTTP_ACCEPT" => "application/xml" }
assert_equal "HTML", last_response.body
get "/", { format: :xml }, "HTTP_ACCEPT" => "application/xml"
get "/", { format: :xml }, { "HTTP_ACCEPT" => "application/xml" }
assert_equal "XML", last_response.body
end
......
......@@ -32,7 +32,7 @@ def teardown
test "/rails/mailers is accessible with correct configuration" do
add_to_config "config.action_mailer.show_previews = true"
app("production")
get "/rails/mailers", {}, "REMOTE_ADDR" => "4.2.42.42"
get "/rails/mailers", {}, { "REMOTE_ADDR" => "4.2.42.42" }
assert_equal 200, last_response.status
end
......@@ -482,7 +482,7 @@ def foo
app("development")
get "/rails/mailers", {}, "SCRIPT_NAME" => "/my_app"
get "/rails/mailers", {}, { "SCRIPT_NAME" => "/my_app" }
assert_match '<h3><a href="/my_app/rails/mailers/notifier">Notifier</a></h3>', last_response.body
assert_match '<li><a href="/my_app/rails/mailers/notifier/foo">foo</a></li>', last_response.body
end
......
......@@ -56,7 +56,7 @@ def test_cache_keeps_if_modified_since
simple_controller
expected = "Wed, 30 May 1984 19:43:31 GMT"
get "/expires/keeps_if_modified_since", {}, "HTTP_IF_MODIFIED_SINCE" => expected
get "/expires/keeps_if_modified_since", {}, { "HTTP_IF_MODIFIED_SINCE" => expected }
assert_equal 200, last_response.status
assert_equal expected, last_response.body, "cache should have kept If-Modified-Since"
......@@ -121,7 +121,7 @@ def test_cache_works_with_etags
etag = last_response.headers["ETag"]
get "/expires/expires_etag", {}, "HTTP_IF_NONE_MATCH" => etag
get "/expires/expires_etag", {}, { "HTTP_IF_NONE_MATCH" => etag }
assert_equal "stale, valid, store", last_response.headers["X-Rack-Cache"]
assert_equal 304, last_response.status
assert_equal "", last_response.body
......@@ -139,7 +139,7 @@ def test_cache_works_with_etags_private
body = last_response.body
etag = last_response.headers["ETag"]
get "/expires/expires_etag", { private: true }, "HTTP_IF_NONE_MATCH" => etag
get "/expires/expires_etag", { private: true }, { "HTTP_IF_NONE_MATCH" => etag }
assert_equal "miss", last_response.headers["X-Rack-Cache"]
assert_not_equal body, last_response.body
end
......@@ -155,7 +155,7 @@ def test_cache_works_with_last_modified
last = last_response.headers["Last-Modified"]
get "/expires/expires_last_modified", {}, "HTTP_IF_MODIFIED_SINCE" => last
get "/expires/expires_last_modified", {}, { "HTTP_IF_MODIFIED_SINCE" => last }
assert_equal "stale, valid, store", last_response.headers["X-Rack-Cache"]
assert_equal 304, last_response.status
assert_equal "", last_response.body
......@@ -173,7 +173,7 @@ def test_cache_works_with_last_modified_private
body = last_response.body
last = last_response.headers["Last-Modified"]
get "/expires/expires_last_modified", { private: true }, "HTTP_IF_MODIFIED_SINCE" => last
get "/expires/expires_last_modified", { private: true }, { "HTTP_IF_MODIFIED_SINCE" => last }
assert_equal "miss", last_response.headers["X-Rack-Cache"]
assert_not_equal body, last_response.body
end
......
......@@ -276,7 +276,7 @@ def index
assert_equal "max-age=0, private, must-revalidate", last_response.headers["Cache-Control"]
assert_equal etag, last_response.headers["Etag"]
get "/", {}, "HTTP_IF_NONE_MATCH" => etag
get "/", {}, { "HTTP_IF_NONE_MATCH" => etag }
assert_equal 304, last_response.status
assert_equal "", last_response.body
assert_nil last_response.headers["Content-Type"]
......
......@@ -67,7 +67,7 @@ def test_app_update_does_not_generate_unnecessary_config_files
run_generator
generator = Rails::Generators::AppGenerator.new ["rails"],
{ api: true, update: true }, destination_root: destination_root, shell: @shell
{ api: true, update: true }, { destination_root: destination_root, shell: @shell }
quietly { generator.send(:update_config_files) }
assert_no_file "config/initializers/cookies_serializer.rb"
......@@ -78,7 +78,7 @@ def test_app_update_does_not_generate_unnecessary_bin_files
run_generator
generator = Rails::Generators::AppGenerator.new ["rails"],
{ api: true, update: true }, destination_root: destination_root, shell: @shell
{ api: true, update: true }, { destination_root: destination_root, shell: @shell }
quietly { generator.send(:update_bin_files) }
assert_no_file "bin/yarn"
......
......@@ -248,7 +248,7 @@ def test_app_update_create_new_framework_defaults
assert_no_file "#{app_root}/config/initializers/new_framework_defaults_5_2.rb"
stub_rails_application(app_root) do
generator = Rails::Generators::AppGenerator.new ["rails"], { update: true }, destination_root: app_root, shell: @shell
generator = Rails::Generators::AppGenerator.new ["rails"], { update: true }, { destination_root: app_root, shell: @shell }
generator.send(:app_const)
quietly { generator.send(:update_config_files) }
......
......@@ -53,7 +53,7 @@ def test_invoke
end
def test_invoke_pretended
create_migration(default_destination_path, {}, pretend: true)
create_migration(default_destination_path, {}, { pretend: true })
assert_no_file @migration.destination
end
......@@ -94,7 +94,7 @@ def test_invoke_forced_when_exists_not_identical
def test_invoke_forced_pretended_when_exists_not_identical
migration_exists!
create_migration(default_destination_path, { force: true }, pretend: true) do
create_migration(default_destination_path, { force: true }, { pretend: true }) do
"different content"
end
......@@ -106,7 +106,7 @@ def test_invoke_forced_pretended_when_exists_not_identical
def test_invoke_skipped_when_exists_not_identical
migration_exists!
create_migration(default_destination_path, {}, skip: true) { "different content" }
create_migration(default_destination_path, {}, { skip: true }) { "different content" }
assert_match(/skip db\/migrate\/2_create_articles\.rb\n/, invoke!)
assert_no_file @migration.destination
......@@ -122,7 +122,7 @@ def test_revoke
def test_revoke_pretended
migration_exists!
create_migration(default_destination_path, {}, pretend: true)
create_migration(default_destination_path, {}, { pretend: true })
assert_match(/remove db\/migrate\/1_create_articles\.rb\n/, revoke!)
assert_file @existing_migration.destination
......
......@@ -1297,10 +1297,10 @@ def index
boot_rails
get("/bukkits/bukkit", {}, "SCRIPT_NAME" => "/foo")
get("/bukkits/bukkit", {}, { "SCRIPT_NAME" => "/foo" })
assert_equal "/foo/bar", last_response.body
get("/bar", {}, "SCRIPT_NAME" => "/foo")
get("/bar", {}, { "SCRIPT_NAME" => "/foo" })
assert_equal "/foo/bukkits/bukkit", last_response.body
end
......@@ -1346,10 +1346,10 @@ def index
boot_rails
get("/bukkits/bukkit", {}, "SCRIPT_NAME" => "/foo")
get("/bukkits/bukkit", {}, { "SCRIPT_NAME" => "/foo" })
assert_equal "/foo/bar", last_response.body
get("/bar", {}, "SCRIPT_NAME" => "/foo")
get("/bar", {}, { "SCRIPT_NAME" => "/foo" })
assert_equal "/foo/bukkits/bukkit", last_response.body
end
......
......@@ -208,7 +208,7 @@ def app
assert_equal "/ada/blog/posts/1", last_response.body
# test generating engine's route from engine with default_url_options
get "/john/blog/posts", {}, "SCRIPT_NAME" => "/foo"
get "/john/blog/posts", {}, { "SCRIPT_NAME" => "/foo" }
assert_equal "/foo/john/blog/posts/1", last_response.body
# test generating engine's route from application
......@@ -222,10 +222,10 @@ def app
assert_equal "/john/blog/posts", last_response.body
# test generating engine's route from application with default_url_options
get "/engine_route", {}, "SCRIPT_NAME" => "/foo"
get "/engine_route", {}, { "SCRIPT_NAME" => "/foo" }
assert_equal "/foo/anonymous/blog/posts", last_response.body
get "/url_for_engine_route", {}, "SCRIPT_NAME" => "/foo"
get "/url_for_engine_route", {}, { "SCRIPT_NAME" => "/foo" }
assert_equal "/foo/john/blog/posts", last_response.body
# test generating application's route from engine
......@@ -243,14 +243,14 @@ def app
assert_equal "/anonymous/blog/posts/1", last_response.body
# test generating engine's route from other engine with default_url_options
get "/metrics/generate_blog_route", {}, "SCRIPT_NAME" => "/foo"
get "/metrics/generate_blog_route", {}, { "SCRIPT_NAME" => "/foo" }
assert_equal "/foo/anonymous/blog/posts/1", last_response.body
get "/metrics/generate_blog_route_in_view", {}, "SCRIPT_NAME" => "/foo"
get "/metrics/generate_blog_route_in_view", {}, { "SCRIPT_NAME" => "/foo" }
assert_equal "/foo/anonymous/blog/posts/1", last_response.body
# test generating application's route from engine with default_url_options
get "/someone/blog/generate_application_route", {}, "SCRIPT_NAME" => "/foo"
get "/someone/blog/generate_application_route", {}, { "SCRIPT_NAME" => "/foo" }
assert_equal "/foo/", last_response.body
# test polymorphic routes
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册