require "spec_helper"

describe "Contact creation", auth: :user do
  include Admin::ContactSteps

  let!(:contact_group)       { create(:contact_group, :with_organisation, title: "new contact type") }
  let(:contact)              { build :contact }
  let!(:contact_organisation) { create :organisation }

  before {
    verify !contact_exists(contact)
  }

  specify "it can be created" do
    expect {
      create_contact(
        title: contact.title,
        description: contact.description,
        contact_information: contact.contact_information
      ) do
        select contact_organisation, from: "contact_organisation_id"
        select contact_group, from: "contact_contact_group_ids"
      end
    }.to change { Contact.count }.by(1)
  end
end

require "spec_helper"

describe "Contact creation", auth: :user do
  include Admin::ContactSteps

  let!(:contact_group)       { create(:contact_group, :with_organisation, title: "new contact type") }
  let(:contact)              { attributes_for :contact }
  let!(:contact_organisation) { create :organisation }

  before {
    verify !contact_exists(contact)
  }

  specify "it can be created" do
    expect {
      create_contact(
        title: contact[:title],
        description: contact[:description],
        contact_information: contact[:contact_information]
      ) do
        select contact_organisation, from: "contact_organisation_id"
        select contact_group, from: "contact_contact_group_ids"
      end
    }.to change { Contact.count }.by(1)
  end
end

Use `attributes_for` to generate test data
Use `attributes_for` to generate test data

The `contact` model here isn't used as an object, it's just created to
have test values. `attributes_for` can be used to get a hash with the
same information. This makes it clear we won't be using the `Contact`
object.
