Sha256: f4431dea3cf0dff2fccd1231be56568f56c1a6dd541389f7cb2d240033b62745

Contents?: true

Size: 1.81 KB

Versions: 4

Compression:

Stored size: 1.81 KB

Contents

# encoding: utf-8
require 'spec_helper'

RSpec.describe 'readonly option' do

  include FormtasticSpecHelper

  before do
    @output_buffer = ''
    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 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).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 have_tag((type == :text ? 'textarea' : 'input') + '[@readonly]')
            end
          end
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
date_n_time_picker_activeadmin-0.1.2 vendor/bundle/ruby/2.6.0/gems/formtastic-4.0.0/spec/inputs/readonly_spec.rb
date_n_time_picker_activeadmin-0.1.1 vendor/bundle/ruby/2.6.0/gems/formtastic-4.0.0/spec/inputs/readonly_spec.rb
formtastic-4.0.0 spec/inputs/readonly_spec.rb
formtastic-4.0.0.rc1 spec/inputs/readonly_spec.rb