Sha256: f5f3c650df8fea8c29f2d07ef40f3ccb7201af535cc28b1842a432c947ca4c5b

Contents?: true

Size: 1.69 KB

Versions: 9

Compression:

Stored size: 1.69 KB

Contents

# frozen_string_literal: true

require 'rails_helper'
require 'formify/spec_helpers'

describe Forms::<%= class_name %>, type: :form do
  include Formify::SpecHelpers

<% if all_attributes.any? %>
<% all_attributes.each do |attr| -%>
<% if factory_bot? && factory?(attr) -%>
  let(:<%= attr %>) { FactoryBot.create(:<%= attr %>) }
<% else -%>
  let(:<%= attr %>) { <%= attr.upcase %>_VALUE }
<% end -%>
<% end -%>

<% end -%>
<% if spec_comments? -%>
  # :attributes is used to initialize the form.
  # These values should result in a valid form.
  # You can override these in blocks or use let(:attributes_override) { { foo: bar } }
<% end -%>
<% if all_attributes.any? %>
  let(:attributes) do
    {
<% all_attributes.each_with_index do |attr, i| -%>
      <%= attr %>: <%= attr %><%= ',' unless all_attributes.count == (i + 1)%>
<% end -%>
    }
  end

<% end -%>
  it { expect_valid }<% if spec_comments? -%> # Expect the form to be valid<% end %>
  it { expect(result).to be_success }
  it { expect(value).to be_a(<%= inferred_model_name %>) }<% if spec_comments? -%> # Model name inferred<% end %>
<% all_attributes.each do |attr| -%>

  describe '#<%= attr %>' do
    it { expect_error_with_missing_attribute(:<%= attr %>) }
    xit { expect_error_with_attribute_value(:<%= attr %>, <%= attr.upcase %>_BAD_VALUE, message: nil) } # :message is optional
    xit { expect_valid_with_attribute_value(:<%= attr %>, <%= attr.upcase %>_GOOD_VALUE) }
  end

<% end -%>
<% if spec_comments? -%>

  # Other Expectation Helpers
  # xit { expect_error_message(message) }
  # xit { expect_error_with_attribute(attribute) }
  # xit { expect_not_valid(attribute: nil, message: nil) } # :attribute and :message are optional
<% end -%>
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
formify-0.23.3 lib/generators/form/templates/form_spec.rb.tt
formify-0.23.2 lib/generators/form/templates/form_spec.rb.tt
formify-0.23.1 lib/generators/form/templates/form_spec.rb.tt
formify-0.23.0 lib/generators/form/templates/form_spec.rb.tt
formify-0.22.6 lib/generators/form/templates/form_spec.rb.tt
formify-0.22.5 lib/generators/form/templates/form_spec.rb.tt
formify-0.22.4 lib/generators/form/templates/form_spec.rb.tt
formify-0.22.3 lib/generators/form/templates/form_spec.rb.tt
formify-0.22.2 lib/generators/form/templates/form_spec.rb.tt