Sha256: ca47cafd360fd312698be35c12a9eee25191ee36a90dcd4199e71b59dc70331e

Contents?: true

Size: 1.89 KB

Versions: 1

Compression:

Stored size: 1.89 KB

Contents

# encoding: utf-8
# frozen_string_literal: true
require 'spec_helper'

RSpec.describe 'readonly option' do

  include FormtasticSpecHelper

  before do
    @output_buffer = ActionView::OutputBuffer.new ''
    mock_everything
  end

  describe "placeholder text" do
    [:email, :number, :password, :phone, :search, :string, :url, :text, :date_picker, :time_picker, :datetime_picker].each do |type|

      describe "for #{type} inputs" do

        describe "when readonly is found in input_html" do
          it "sets readonly attribute" do
            concat(semantic_form_for(@new_post) do |builder|
              concat(builder.input(:title, :as => type, input_html: {readonly: true}))
            end)
              expect(output_buffer.to_str).to have_tag((type == :text ? 'textarea' : 'input') + '[@readonly]')
          end
        end

        describe "when readonly not found in input_html" do
          describe "when column is not readonly attribute" do
            it "doesn't set readonly attribute" do
              concat(semantic_form_for(@new_post) do |builder|
                concat(builder.input(:title, :as => type))
              end)
                expect(output_buffer.to_str).not_to have_tag((type == :text ? 'textarea' : 'input') + '[@readonly]')
            end
          end
          describe "when column is readonly attribute" do
            it "sets readonly attribute" do
              input_class = "Formtastic::Inputs::#{type.to_s.camelize}Input".constantize
              expect_any_instance_of(input_class).to receive(:readonly_attribute?).at_least(1).and_return(true)
              concat(semantic_form_for(@new_post) do |builder|
                concat(builder.input(:title, :as => type))
              end)
                expect(output_buffer.to_str).to have_tag((type == :text ? 'textarea' : 'input') + '[@readonly]')
            end
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
formtastic-5.0.0 spec/inputs/readonly_spec.rb