docbrown/spec/services/profile_fields/import_from_csv_spec.rb
Michael Kohl c2d23cfc4d
[deploy] Seed profile fields (#9605)
* Fix schema.rb

* Add service objects for base and link fields

* Add link fields to seeds

* Make placeholder a keyword argument

* Add work fields

* Add explanation column to profile fields

* Add coding fields

* Switch from inheritance to mixin

* Add email checkbox to base fields

* Add branding fields

* Add spec for ProfileFields::FieldDefinition

* Move migration back into correct location

* Rename column from explanation to description

* Rename attribute in mixin

* chore: rename from explanation to description

* Add ProfileFields::ImportFromCsv

* Simplify ProfileFields::ImportFromCsv

* Add comment about disabled cop to spec

* Add TODO comment to Rake task

* Document mixin

* Add groups to profile fields

Co-authored-by: Ridhwana <ridhwana.khan16@gmail.com>
2020-08-05 10:11:30 -04:00

38 lines
1.4 KiB
Ruby

require "rails_helper"
RSpec.describe ProfileFields::ImportFromCsv do
# Importing is slow, so we only do it once and then clean up after outselves.
# rubocop:disable RSpec/BeforeAfterAll
before(:all) { described_class.call(file_fixture("profile_fields.csv")) }
after(:all) { ProfileField.destroy_all }
# rubocop:enable RSpec/BeforeAfterAll
it "ignores empty lines" do
expect(ProfileField.count).to eq 3
end
it "handles missing descriptions", :aggregate_failures do
field = ProfileField.find_by!(label: "Name")
expect(field.input_type).to eq "text_field"
expect(field.placeholder_text).to eq "John Doe"
expect(field.description).to be_nil
expect(field.group).to eq "Basic"
end
it "handles missing placeholder_texts", :aggregate_failures do
field = ProfileField.find_by!(label: "Skills/Languages")
expect(field.input_type).to eq "text_area"
expect(field.placeholder_text).to be_nil
expect(field.description).to eq "Programming languages"
expect(field.group).to eq "Coding"
end
it "handles commas in correctly quoted fields", :aggregate_failures do
field = ProfileField.find_by!(label: "Color")
expect(field.input_type).to eq "color_field"
expect(field.placeholder_text).to eq "#000000"
expect(field.description).to eq "Used for backgrounds, borders etc."
expect(field.group).to eq "Branding"
end
end