docbrown/spec/models/profile_spec.rb
Michael Kohl d284e597cd
[deploy] Add Profiles::Update service object (#9912)
* Add Profiles::Update service object

* Refactor

* Rename Profile.fields to Profile.attributes

* Keep sync from user -> profile

* And and update comments

* Rename Profile.refresh_store_accessors!

* Make forwarding getters in user dynamic

* Add more explanation

* Fix typo

* Update service object

* Fix return value

* Fix specs

* Travis, let's be friends again?

* Remove Travis change

* Add require_dependency in Profile

* Refactor

* More refactoring

* Avoid double sync

* Fix specs

* Fix mapped attributes sync
2020-09-03 09:19:25 -04:00

34 lines
934 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) }
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