docbrown/spec/models/profile_spec.rb
rhymes 10efa25c0a
Add missing presence validators to models (#10495)
* Add missing presence validator for Tag

* Add missing presence validators to Follow

* Add missing presence validators to ProfileField

* Add missing presence validators to Comment

* Add missing presence validators to Profile

* Add missing presence validators to Organization

* Add missing presence validators to Badge

* Add missing presence validators to Webhook::Endpoint

* Add missing presence validators to NotificationSubscription

* Add missing presence validators to PodcastEpisode

* Add missing presence validators to Sponsorship

* Add missing presence validators to PollOption

* Add missing presence validators to Poll

* Add missing presence validators to Article

* Add missing presence validators to EmailAuthorization

* Add missing presence validators to AuditLog

* Add missing presence validators to DataUpdateScript

* Add missing presence validators to User

* Add missing presence validators to SiteConfig

* Fix specs
2020-10-01 16:15:32 +02:00

35 lines
988 B
Ruby

require "rails_helper"
RSpec.describe Profile, type: :model do
describe "validations" do
subject { create(:profile) }
it { is_expected.to validate_uniqueness_of(:user_id) }
it { is_expected.to validate_presence_of(:data) }
end
context "when accessing profile fields" do
before do
create(:profile_field, label: "Test 1")
create(:profile_field, label: "Test 2", input_type: :check_box)
described_class.refresh_attributes!
end
let(:profile) { described_class.new }
it "defines accessors for active profile fields", :aggregate_failures do
expect(profile).to respond_to(:test1)
expect(profile).to respond_to(:test2)
end
it "performs ActiveRecord typecasting for profile fields", :aggregate_failures do
expect do
profile.test2 = "true"
end.to change(profile, :test2).from(nil).to(true)
expect do
profile.test2 = "f"
end.to change(profile, :test2).to(false)
end
end
end