Skip to content

Commit 3f37306

Browse files
committed
chore: Address Rubocop offenses
1 parent d4aa90c commit 3f37306

10 files changed

Lines changed: 49 additions & 47 deletions

File tree

lib/tiny_admin/actions/index.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def evaluate_options(options)
5252
def prepare_filters(fields)
5353
filters = (options[:filters] || []).map { _1.is_a?(Hash) ? _1 : { field: _1 } }
5454
filters = filters.each_with_object({}) { |filter, result| result[filter[:field]] = filter }
55-
values = (params['q'] || {})
55+
values = params['q'] || {}
5656
fields.each_with_object({}) do |(name, field), result|
5757
result[field] = { value: values[name], filter: filters[name] } if filters.key?(name)
5858
end

lib/tiny_admin/plugins/base_repository.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
module TinyAdmin
44
module Plugins
55
class BaseRepository
6-
RecordNotFound = Class.new(StandardError)
6+
class RecordNotFound < StandardError
7+
end
78

89
attr_reader :model
910

spec/lib/tiny_admin/actions/basic_action_spec.rb

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,35 +11,36 @@
1111
it "handles simple string field names" do
1212
result = action.attribute_options(["id", "name"])
1313
expect(result).to eq(
14-
"id" => {field: "id"},
15-
"name" => {field: "name"}
14+
"id" => { field: "id" },
15+
"name" => { field: "name" }
1616
)
1717
end
1818

1919
it "handles single-entry hash with method shorthand" do
20-
result = action.attribute_options([{title: "downcase, capitalize"}])
20+
result = action.attribute_options([{ title: "downcase, capitalize" }])
2121
expect(result).to eq(
22-
"title" => {field: "title", method: "downcase, capitalize"}
22+
"title" => { field: "title", method: "downcase, capitalize" }
2323
)
2424
end
2525

2626
it "handles multi-entry hash with explicit field key" do
27-
result = action.attribute_options([{field: "author_id", link_to: "authors"}])
27+
result = action.attribute_options([{ field: "author_id", link_to: "authors" }])
2828
expect(result).to eq(
29-
"author_id" => {field: "author_id", link_to: "authors"}
29+
"author_id" => { field: "author_id", link_to: "authors" }
3030
)
3131
end
3232

3333
it "handles mixed input types" do
34-
result = action.attribute_options([
34+
opts = [
3535
"id",
36-
{title: "upcase"},
37-
{field: "created_at", method: "strftime, %Y-%m-%d"}
38-
])
36+
{ title: "upcase" },
37+
{ field: "created_at", method: "strftime, %Y-%m-%d" }
38+
]
39+
result = action.attribute_options(opts)
3940
expect(result).to eq(
40-
"id" => {field: "id"},
41-
"title" => {field: "title", method: "upcase"},
42-
"created_at" => {field: "created_at", method: "strftime, %Y-%m-%d"}
41+
"id" => { field: "id" },
42+
"title" => { field: "title", method: "upcase" },
43+
"created_at" => { field: "created_at", method: "strftime, %Y-%m-%d" }
4344
)
4445
end
4546
end

spec/lib/tiny_admin/field_spec.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
end
2222

2323
it "uses the provided options when given" do
24-
options = {method: "downcase"}
24+
options = { method: "downcase" }
2525
field = described_class.create_field(name: "name", options: options)
2626
expect(field.options).to eq(options)
2727
end
@@ -39,7 +39,7 @@
3939

4040
describe "#apply_call_option" do
4141
it "chains method calls on the target" do
42-
field = described_class.new(name: "title", title: "Title", type: :string, options: {call: "to_s, downcase"})
42+
field = described_class.new(name: "title", title: "Title", type: :string, options: { call: "to_s, downcase" })
4343
expect(field.apply_call_option(42)).to eq("42")
4444
end
4545

@@ -49,7 +49,7 @@
4949
end
5050

5151
it "handles nil target safely via safe navigation" do
52-
field = described_class.new(name: "title", title: "Title", type: :string, options: {call: "nonexistent"})
52+
field = described_class.new(name: "title", title: "Title", type: :string, options: { call: "nonexistent" })
5353
expect(field.apply_call_option(nil)).to be_nil
5454
end
5555
end
@@ -66,7 +66,7 @@
6666
end
6767

6868
it "applies the helper method from options" do
69-
field = described_class.new(name: "name", title: "Name", type: :string, options: {method: "downcase"})
69+
field = described_class.new(name: "name", title: "Name", type: :string, options: { method: "downcase" })
7070
allow(TinyAdmin.settings).to receive(:helper_class).and_return(TinyAdmin::Support)
7171
expect(field.translate_value("HELLO")).to eq("hello")
7272
end
@@ -81,15 +81,15 @@ def self.upcase(value, options: [])
8181

8282
field = described_class.new(
8383
name: "name", title: "Name", type: :string,
84-
options: {method: "upcase", converter: "TestConverter"}
84+
options: { method: "upcase", converter: "TestConverter" }
8585
)
8686
expect(field.translate_value("hello")).to eq("HELLO")
8787
end
8888

8989
it "passes additional args to the method" do
9090
field = described_class.new(
9191
name: "value", title: "Value", type: :float,
92-
options: {method: "round, 1"}
92+
options: { method: "round, 1" }
9393
)
9494
allow(TinyAdmin.settings).to receive(:helper_class).and_return(TinyAdmin::Support)
9595
expect(field.translate_value(3.456)).to eq(3.5)

spec/lib/tiny_admin/plugins/active_record_repository_spec.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
end
3232

3333
it "returns only specified fields when options given" do
34-
options = {"name" => {}, "email" => {}}
34+
options = { "name" => {}, "email" => {} }
3535
fields = repository.fields(options: options)
3636
expect(fields.keys).to eq(["name", "email"])
3737
end
@@ -72,7 +72,7 @@
7272
end
7373

7474
it "returns only specified fields when fields given", :aggregate_failures do
75-
attrs = repository.index_record_attrs(author, fields: {"name" => nil, "email" => nil})
75+
attrs = repository.index_record_attrs(author, fields: { "name" => nil, "email" => nil })
7676
expect(attrs.keys).to eq(["name", "email"])
7777
expect(attrs["name"]).to eq(author.name)
7878
end
@@ -93,7 +93,7 @@
9393
end
9494

9595
it "sorts when sort option given" do
96-
records, = repository.list(page: 1, limit: 10, sort: {name: :desc})
96+
records, = repository.list(page: 1, limit: 10, sort: { name: :desc })
9797
names = records.map(&:name)
9898
expect(names).to eq(names.sort.reverse)
9999
end
@@ -104,7 +104,7 @@
104104

105105
it "filters string fields with LIKE" do
106106
title_field = TinyAdmin::Field.new(name: "title", title: "Title", type: :string)
107-
filters = {title_field => {value: "post 1"}}
107+
filters = { title_field => { value: "post 1" } }
108108
results = post_repository.apply_filters(Post.all, filters)
109109
results.each do |post|
110110
expect(post.title.downcase).to include("post 1")
@@ -114,7 +114,7 @@
114114
it "filters non-string fields with equality" do
115115
author = Author.first
116116
author_field = TinyAdmin::Field.new(name: "author_id", title: "Author", type: :integer)
117-
filters = {author_field => {value: author.id}}
117+
filters = { author_field => { value: author.id } }
118118
results = post_repository.apply_filters(Post.all, filters)
119119
results.each do |post|
120120
expect(post.author_id).to eq(author.id)
@@ -123,14 +123,14 @@
123123

124124
it "skips filters with nil or empty values" do
125125
title_field = TinyAdmin::Field.new(name: "title", title: "Title", type: :string)
126-
filters = {title_field => {value: nil}}
126+
filters = { title_field => { value: nil } }
127127
results = post_repository.apply_filters(Post.all, filters)
128128
expect(results.count).to eq(Post.count)
129129
end
130130

131131
it "sanitizes SQL LIKE input" do
132132
title_field = TinyAdmin::Field.new(name: "title", title: "Title", type: :string)
133-
filters = {title_field => {value: "100%"}}
133+
filters = { title_field => { value: "100%" } }
134134
# Should not raise or cause SQL injection
135135
expect { post_repository.apply_filters(Post.all, filters).to_a }.not_to raise_error
136136
end

spec/lib/tiny_admin/section_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
end
2121

2222
it "stores provided options" do
23-
section = described_class.new(name: "Link", slug: "link", options: {target: "_blank"})
24-
expect(section.options).to eq({target: "_blank"})
23+
section = described_class.new(name: "Link", slug: "link", options: { target: "_blank" })
24+
expect(section.options).to eq({ target: "_blank" })
2525
end
2626
end
2727
end

spec/lib/tiny_admin/settings_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
end
5050

5151
it "converts nested string class names to constants" do
52-
settings[:authentication] = {plugin: "TinyAdmin::Plugins::NoAuth"}
52+
settings[:authentication] = { plugin: "TinyAdmin::Plugins::NoAuth" }
5353
expect(settings[:authentication, :plugin]).to eq(TinyAdmin::Plugins::NoAuth)
5454
end
5555

spec/lib/tiny_admin/store_spec.rb

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
describe "#prepare_sections" do
2424
context "with a content section" do
2525
let(:sections) do
26-
[{slug: "about", name: "About", type: :content, content: "<h1>About</h1>"}]
26+
[{ slug: "about", name: "About", type: :content, content: "<h1>About</h1>" }]
2727
end
2828

2929
it "adds to pages and navbar", :aggregate_failures do
@@ -42,7 +42,7 @@
4242
end
4343

4444
let(:sections) do
45-
[{slug: "dashboard", name: "Dashboard", type: :page, page: page_class}]
45+
[{ slug: "dashboard", name: "Dashboard", type: :page, page: page_class }]
4646
end
4747

4848
it "adds to pages and navbar", :aggregate_failures do
@@ -56,7 +56,7 @@
5656

5757
context "with a resource section" do
5858
let(:sections) do
59-
[{slug: "authors", name: "Authors", type: :resource, model: Author}]
59+
[{ slug: "authors", name: "Authors", type: :resource, model: Author }]
6060
end
6161

6262
it "adds to resources and navbar", :aggregate_failures do
@@ -71,7 +71,7 @@
7171

7272
context "with a hidden resource section" do
7373
let(:sections) do
74-
[{slug: "secret", name: "Secret", type: :resource, model: Author, options: [:hidden]}]
74+
[{ slug: "secret", name: "Secret", type: :resource, model: Author, options: [:hidden] }]
7575
end
7676

7777
it "adds to resources but not to visible navbar items", :aggregate_failures do
@@ -84,14 +84,14 @@
8484

8585
context "with a url section" do
8686
let(:sections) do
87-
[{slug: "google", name: "Google", type: :url, url: "https://google.com", options: {target: "_blank"}}]
87+
[{ slug: "google", name: "Google", type: :url, url: "https://google.com", options: { target: "_blank" } }]
8888
end
8989

9090
it "adds to navbar with the url as path", :aggregate_failures do
9191
store.prepare_sections(sections, logout: nil)
9292
expect(store.navbar.size).to eq(1)
9393
expect(store.navbar.first.path).to eq("https://google.com")
94-
expect(store.navbar.first.options).to eq({target: "_blank"})
94+
expect(store.navbar.first.options).to eq({ target: "_blank" })
9595
end
9696

9797
it "does not add to pages or resources", :aggregate_failures do
@@ -105,7 +105,7 @@
105105
let(:section_module) do
106106
mod = Class.new do
107107
def self.to_h
108-
{slug: "dynamic", name: "Dynamic", type: :content, content: "<p>Hi</p>"}
108+
{ slug: "dynamic", name: "Dynamic", type: :content, content: "<p>Hi</p>" }
109109
end
110110
end
111111
mod
@@ -143,9 +143,9 @@ def self.to_h
143143
context "with multiple section types" do
144144
let(:sections) do
145145
[
146-
{slug: "about", name: "About", type: :content, content: "<p>Test</p>"},
147-
{slug: "users", name: "Users", type: :resource, model: Author},
148-
{slug: "ext", name: "External", type: :url, url: "https://example.com"}
146+
{ slug: "about", name: "About", type: :content, content: "<p>Test</p>" },
147+
{ slug: "users", name: "Users", type: :resource, model: Author },
148+
{ slug: "ext", name: "External", type: :url, url: "https://example.com" }
149149
]
150150
end
151151

spec/lib/tiny_admin/utils_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
end
1010

1111
it "converts nested hash params to bracket notation", :aggregate_failures do
12-
result = utils_instance.params_to_s("q" => {"title" => "test", "author" => "john"})
12+
result = utils_instance.params_to_s("q" => { "title" => "test", "author" => "john" })
1313
expect(result).to include("q[title]=test")
1414
expect(result).to include("q[author]=john")
1515
end
@@ -19,7 +19,7 @@
1919
end
2020

2121
it "handles mixed flat and nested params", :aggregate_failures do
22-
result = utils_instance.params_to_s("p" => "1", "q" => {"name" => "test"})
22+
result = utils_instance.params_to_s("p" => "1", "q" => { "name" => "test" })
2323
expect(result).to include("p=1")
2424
expect(result).to include("q[name]=test")
2525
end

tiny_admin.gemspec

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ Gem::Specification.new do |spec|
2828
spec.files = Dir['{app,db,lib}/**/*', 'LICENSE.txt', 'README.md']
2929
spec.require_paths = ['lib']
3030

31-
spec.add_runtime_dependency 'phlex', '~> 1', '>= 1.10.0'
32-
spec.add_runtime_dependency 'roda', '~> 3'
33-
spec.add_runtime_dependency 'tilt', '~> 2'
34-
spec.add_runtime_dependency 'zeitwerk', '~> 2'
31+
spec.add_dependency 'phlex', '~> 1', '>= 1.10.0'
32+
spec.add_dependency 'roda', '~> 3'
33+
spec.add_dependency 'tilt', '~> 2'
34+
spec.add_dependency 'zeitwerk', '~> 2'
3535
end

0 commit comments

Comments
 (0)