Skip to content

Instantly share code, notes, and snippets.

@kryzhovnik
Created December 8, 2022 20:21
Show Gist options
  • Save kryzhovnik/82d6321bfd171bb39d008b5cd9da3bb2 to your computer and use it in GitHub Desktop.
Save kryzhovnik/82d6321bfd171bb39d008b5cd9da3bb2 to your computer and use it in GitHub Desktop.
# frozen_string_literal: true
require "bundler/inline"
gemfile(true) do
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
gem "rails", github: "rails/rails", branch: "main"
gem 'rails-dom-testing'
end
require "active_support"
require "active_support/core_ext/object/blank"
require "minitest/autorun"
require "active_model"
require "action_view"
Post = Struct.new(:title, :author_name, :body, :secret, :persisted, :written_on, :cost) do
extend ActiveModel::Naming
include ActiveModel::Conversion
extend ActiveModel::Translation
alias_method :secret?, :secret
alias_method :persisted?, :persisted
def initialize(*args)
super
@persisted = false
end
end
class BugTest < Minitest::Test
include ActionView::Helpers::FormHelper
include Rails::Dom::Testing::Assertions
def test_date_field_with_datetime_value_attr
expected = %{<input id="post_written_on" name="post[written_on]" type="date" value="2013-06-29" />}
value = DateTime.new(2013, 6, 29)
assert_dom_equal(expected, date_field("post", "written_on", value: value))
end
def test_time_field_with_value_attr
expected = %{<input id="post_written_on" name="post[written_on]" type="time" value="01:02:03.000" />}
value = DateTime.new(2004, 6, 15, 1, 2, 3)
assert_dom_equal(expected, time_field("post", "written_on", value: value))
end
def test_datetime_field_with_value_attr
expected = %{<input id="post_written_on" name="post[written_on]" type="datetime-local" value="2013-06-29T13:37:00" />}
value = DateTime.new(2013, 6, 29, 13, 37)
assert_dom_equal(expected, datetime_field("post", "written_on", value: value))
end
def test_month_field_with_datetime_value_attr
expected = %{<input id="post_written_on" name="post[written_on]" type="month" value="2004-06" />}
value = DateTime.new(2004, 6, 15, 1, 2, 3)
assert_dom_equal(expected, month_field("post", "written_on", value: value))
end
def test_week_field_with_datetime_value_attr
expected = %{<input id="post_written_on" name="post[written_on]" type="week" value="2004-W25" />}
value = DateTime.new(2004, 6, 15, 1, 2, 3)
assert_dom_equal(expected, week_field("post", "written_on", value: value))
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment