Skip to content

Commit

Permalink
Appease rubocop
Browse files Browse the repository at this point in the history
  • Loading branch information
tvdeyen committed Jul 14, 2021
1 parent 0018a10 commit 73eebb7
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 78 deletions.
2 changes: 1 addition & 1 deletion lib/alchemy/forms/builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def input(attribute_name, options = {}, &block)

# Renders a simple_form input that displays a datepicker
#
def datepicker(attribute_name, options = {}, &block)
def datepicker(attribute_name, options = {})
options[:wrapper] = :alchemy

type = options[:as] || :date
Expand Down
80 changes: 50 additions & 30 deletions spec/libraries/forms/builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,16 @@
let(:form_object) { double("FormObject", foo: "2021-07-14") }

it "returns input field with date value set" do
expect(template).to receive(:text_field).with("Ding", :foo, hash_including(
type: :text,
data: { datepicker_type: :date },
value: "2021-07-14T00:00:00Z",
class: [:string, :required, :date],
))
expect(template).to receive(:text_field).with(
"Ding",
:foo,
hash_including(
type: :text,
data: { datepicker_type: :date },
value: "2021-07-14T00:00:00Z",
class: [:string, :required, :date],
)
)
subject
end
end
Expand All @@ -43,12 +47,16 @@
let(:options) { { as: :date, input_html: { value: "2021-08-01" } } }

it "returns input field with parsed date value set" do
expect(template).to receive(:text_field).with("Ding", :foo, hash_including(
type: :text,
data: { datepicker_type: :date },
value: "2021-08-01T00:00:00Z",
class: [:string, :required, :date],
))
expect(template).to receive(:text_field).with(
"Ding",
:foo,
hash_including(
type: :text,
data: { datepicker_type: :date },
value: "2021-08-01T00:00:00Z",
class: [:string, :required, :date],
)
)
subject
end
end
Expand All @@ -58,12 +66,16 @@
let(:options) { { as: :date } }

it "returns input field with datepicker attributes" do
expect(template).to receive(:text_field).with("Ding", :foo, hash_including(
type: :text,
data: { datepicker_type: :date },
value: nil,
class: [:string, :required, :date],
))
expect(template).to receive(:text_field).with(
"Ding",
:foo,
hash_including(
type: :text,
data: { datepicker_type: :date },
value: nil,
class: [:string, :required, :date],
)
)
subject
end
end
Expand All @@ -72,12 +84,16 @@
let(:options) { { as: :time } }

it "returns input field with datepicker attributes" do
expect(template).to receive(:text_field).with("Ding", :foo, hash_including(
type: :text,
data: { datepicker_type: :time },
value: nil,
class: [:string, :required, :time],
))
expect(template).to receive(:text_field).with(
"Ding",
:foo,
hash_including(
type: :text,
data: { datepicker_type: :time },
value: nil,
class: [:string, :required, :time],
)
)
subject
end
end
Expand All @@ -86,12 +102,16 @@
let(:options) { { as: :datetime } }

it "returns input field with datepicker attributes" do
expect(template).to receive(:text_field).with("Ding", :foo, hash_including(
type: :text,
data: { datepicker_type: :datetime },
value: nil,
class: [:string, :required, :datetime],
))
expect(template).to receive(:text_field).with(
"Ding",
:foo,
hash_including(
type: :text,
data: { datepicker_type: :datetime },
value: nil,
class: [:string, :required, :datetime],
)
)
subject
end
end
Expand Down
106 changes: 59 additions & 47 deletions spec/libraries/resources_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class ResourcesControllerForEngine
include Alchemy::ResourcesHelper

def resource_handler
@resource_handler ||= Alchemy::Resource.new("admin/engine_resources", {"engine_name" => "my_engine"})
@resource_handler ||= Alchemy::Resource.new("admin/engine_resources", { "engine_name" => "my_engine" })
end
end

Expand Down Expand Up @@ -119,7 +119,7 @@ def resource_handler
subject { controller.render_attribute(resource_item, attributes, options) }

let(:options) { {} }
let(:attributes) { {name: "name"} }
let(:attributes) { { name: "name" } }

it "should return the value from resource attribute" do
allow(resource_item).to receive(:name).and_return("my-name")
Expand Down Expand Up @@ -167,15 +167,15 @@ def resource_handler
end

context "but with options[:truncate] set to 10" do
let(:options) { {truncate: 10} }
let(:options) { { truncate: 10 } }

it "does not truncate the values" do
expect(subject.length).to eq(10)
end
end

context "but with options[:truncate] set to false" do
let(:options) { {truncate: false} }
let(:options) { { truncate: false } }

it "does not truncate the values" do
expect(subject.length).to eq(51)
Expand Down Expand Up @@ -203,7 +203,7 @@ def resource_handler
end

context "with options[:datetime_format] set to other format" do
let(:options) { {datetime_format: "OTHR"} }
let(:options) { { datetime_format: "OTHR" } }

it "uses this format" do
expect(controller).to receive(:l).with(now, format: "OTHR")
Expand Down Expand Up @@ -232,7 +232,7 @@ def resource_handler
end

context "with options[:time_format] set to other format" do
let(:options) { {time_format: "OTHR"} }
let(:options) { { time_format: "OTHR" } }

it "uses this format" do
expect(controller).to receive(:l).with(now, format: "OTHR")
Expand All @@ -248,101 +248,113 @@ def resource_handler
context "a boolean" do
let(:attribute) do
{
type: :boolean
type: :boolean,
}
end

it "just returns hint options" do
is_expected.to match(hash_including(
hint: nil
))
is_expected.to match(
hash_including(
hint: nil,
)
)
end
end

context "a date" do
let(:attribute) do
{
type: :date
type: :date,
}
end

it "returns options for date picker" do
is_expected.to match(hash_including(
hint: nil,
as: "string",
input_html: {
data: { datepicker_type: "date" }
}
))
is_expected.to match(
hash_including(
hint: nil,
as: "string",
input_html: {
data: { datepicker_type: "date" },
},
)
)
end
end

context "a datetime" do
let(:attribute) do
{
type: :datetime
type: :datetime,
}
end

it "returns options for datetime picker" do
is_expected.to match(hash_including(
hint: nil,
as: "string",
input_html: {
data: { datepicker_type: "datetime" }
}
))
is_expected.to match(
hash_including(
hint: nil,
as: "string",
input_html: {
data: { datepicker_type: "datetime" },
},
)
)
end
end

context "a time" do
let(:attribute) do
{
type: :time
type: :time,
}
end

it "returns options for time picker" do
is_expected.to match(hash_including(
hint: nil,
as: "string",
input_html: {
data: { datepicker_type: "time" }
}
))
is_expected.to match(
hash_including(
hint: nil,
as: "string",
input_html: {
data: { datepicker_type: "time" },
},
)
)
end
end

context "a text" do
let(:attribute) do
{
type: :text
type: :text,
}
end

it "returns options for textarea" do
is_expected.to match(hash_including(
hint: nil,
as: "text",
input_html: {
rows: 4
}
))
is_expected.to match(
hash_including(
hint: nil,
as: "text",
input_html: {
rows: 4,
},
)
)
end
end

context "everything else" do
let(:attribute) do
{
type: :foo
type: :foo,
}
end

it "returns options for text input field" do
is_expected.to match(hash_including(
hint: nil,
as: "string"
))
is_expected.to match(
hash_including(
hint: nil,
as: "string",
)
)
end
end
end
Expand Down

0 comments on commit 73eebb7

Please sign in to comment.