diff --git a/lib/alchemy/forms/builder.rb b/lib/alchemy/forms/builder.rb index e8267ecb52..212a639d48 100644 --- a/lib/alchemy/forms/builder.rb +++ b/lib/alchemy/forms/builder.rb @@ -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 diff --git a/spec/libraries/forms/builder_spec.rb b/spec/libraries/forms/builder_spec.rb index 73547572e9..7448ae23a2 100644 --- a/spec/libraries/forms/builder_spec.rb +++ b/spec/libraries/forms/builder_spec.rb @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/spec/libraries/resources_helper_spec.rb b/spec/libraries/resources_helper_spec.rb index c87f17bd36..43d9a71d8e 100644 --- a/spec/libraries/resources_helper_spec.rb +++ b/spec/libraries/resources_helper_spec.rb @@ -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 @@ -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") @@ -167,7 +167,7 @@ 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) @@ -175,7 +175,7 @@ def resource_handler 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) @@ -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") @@ -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") @@ -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