<commit_before>require 'rails_helper'

RSpec.describe 'date_time', type: :view do
  class DateTimeModel
    extend ActiveModel::Naming
    include ActiveModel::Conversion

    def initialize(column_sql_type)
      @column_sql_type = column_sql_type
    end

    def persisted?
      true
    end

    def column_for_attribute(*)
      Struct.new(:sql_type).new(@column_sql_type)
    end

    def has_attribute?(*)
      true
    end

    def test
      @test ||= DateTime.now
    end
  end

  let(:object) { DateTimeModel.new('datetime') }
  subject! do
    simple_form_for object, url: 'test' do |f|
      f.input :test
    end
    render text: output_buffer
  end

  context 'when the database column is a datetime' do
    it 'displays the text field' do
      expect(rendered).to have_tag('div.form-group.bootstrap_date_time') do
        with_tag('input.bootstrap_date_time', with: { value: object.test })
      end
    end

    it 'has a hidden datepicker control' do
      selector = 'div.form-group.bootstrap_date_time div.input-group'
      required_style = { style: 'display: none' }

      expect(rendered).to have_tag(selector, with: required_style) do
        with_tag('input.bootstrap_date_time', with: { type: 'hidden' })
      end
    end
  end
end<commit_msg>Add specs for the column inference for date columns, and non-date/non-datetime columns.<commit_after>require 'rails_helper'

RSpec.describe 'date_time', type: :view do
  class DateTimeModel
    extend ActiveModel::Naming
    include ActiveModel::Conversion

    def initialize(column_sql_type)
      @column_sql_type = column_sql_type
    end

    def persisted?
      true
    end

    def column_for_attribute(*)
      Struct.new(:sql_type).new(@column_sql_type)
    end

    def has_attribute?(*)
      true
    end

    def test
      @test ||= DateTime.now
    end
  end

  subject! do
    simple_form_for object, url: 'test' do |f|
      f.input :test
    end
    render text: output_buffer
  end

  context 'when the database column is a datetime' do
    let(:object) { DateTimeModel.new('datetime') }
    it 'displays the text field' do
      expect(rendered).to have_tag('div.form-group.bootstrap_date_time') do
        with_tag('input.bootstrap_date_time', with: { value: object.test })
      end
    end

    it 'has a hidden datepicker control' do
      selector = 'div.form-group.bootstrap_date_time div.input-group'
      required_style = { style: 'display: none' }

      expect(rendered).to have_tag(selector, with: required_style) do
        with_tag('input.bootstrap_date_time', with: { type: 'hidden' })
      end
    end
  end

  context 'when the database column is a date' do
    let(:object) { DateTimeModel.new('date') }
    it 'displays the text field' do
      expect(rendered).to have_tag('div.form-group.bootstrap_date') do
        with_tag('input.bootstrap_date', with: { value: object.test })
      end
    end
  end

  context 'when the database column is not a datetime' do
    let(:object) { DateTimeModel.new('string') }
    it 'does not have a  datepicker control' do
      expect(rendered).not_to have_tag('div.form-group.bootstrap_date_time')
    end
  end
end
{'fraction_non_alphanumeric': 0.09649952696310313, 'fraction_numerical': 0.0, 'mean_word_length': 3.005050505050505, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6611911', 'n_tokens_mistral': 1007, 'n_tokens_neox': 970, 'n_words': 269}