Refactor user preferences, add defaults from file
* Turn prefs into a flat hash structure, since nesting is not worth the trouble * Add a custom serializer class for prefs * Add a config file for defaults and merge set prefs with unset ones * Use booleans for "true" and "false", and integers where appropriate
This commit is contained in:
@@ -140,7 +140,7 @@ RSpec.describe User, type: :model do
|
||||
|
||||
before do
|
||||
# TODO remove when defaults are implemented
|
||||
user.update! preferences: {"xmpp" => { "exchange_contacts_with_invitees" => true }}
|
||||
user.update! preferences: { xmpp_exchange_contacts_with_invitees: true }
|
||||
Invitation.create! user: user, invited_user_id: guest.id, used_at: DateTime.now
|
||||
allow_any_instance_of(User).to receive(:enable_service).and_return(true)
|
||||
end
|
||||
@@ -152,7 +152,7 @@ RSpec.describe User, type: :model do
|
||||
|
||||
context "automatic contact exchange disabled" do
|
||||
before do
|
||||
user.update! preferences: {"xmpp" => { "exchange_contacts_with_invitees" => false }}
|
||||
user.update! preferences: { xmpp_exchange_contacts_with_invitees: false }
|
||||
end
|
||||
|
||||
it "does not exchange XMPP contacts with the inviter" do
|
||||
@@ -162,50 +162,4 @@ RSpec.describe User, type: :model do
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "#pref_enabled?" do
|
||||
describe "preference not set" do
|
||||
# TODO return default value
|
||||
it "returns false" do
|
||||
expect(user.pref_enabled?("lightning:notify_sats_received")).to be(false)
|
||||
end
|
||||
end
|
||||
|
||||
describe "preference is set" do
|
||||
it "returns true for boolean true" do
|
||||
user.preferences.merge!({"lightning" => {"notify_sats_received" => true}})
|
||||
expect(user.pref_enabled?("lightning:notify_sats_received")).to be(true)
|
||||
end
|
||||
|
||||
it "returns true for string 'true'" do
|
||||
user.preferences.merge!({"lightning" => {"notify_sats_received" => "true"}})
|
||||
expect(user.pref_enabled?("lightning:notify_sats_received")).to be(true)
|
||||
end
|
||||
|
||||
it "returns true for string 'enabled'" do
|
||||
user.preferences.merge!({"lightning" => {"notify_sats_received" => "enabled"}})
|
||||
expect(user.pref_enabled?("lightning:notify_sats_received")).to be(true)
|
||||
end
|
||||
|
||||
it "returns true for integer 1" do
|
||||
user.preferences.merge!({"lightning" => {"notify_sats_received" => 1}})
|
||||
expect(user.pref_enabled?("lightning:notify_sats_received")).to be(true)
|
||||
end
|
||||
|
||||
it "returns false for boolean false" do
|
||||
user.preferences.merge!({"lightning" => {"notify_sats_received" => false}})
|
||||
expect(user.pref_enabled?("lightning:notify_sats_received")).to be(false)
|
||||
end
|
||||
|
||||
it "returns false for string 'false'" do
|
||||
user.preferences.merge!({"lightning" => {"notify_sats_received" => "false"}})
|
||||
expect(user.pref_enabled?("lightning:notify_sats_received")).to be(false)
|
||||
end
|
||||
|
||||
it "returns false for integer 0" do
|
||||
user.preferences.merge!({"lightning" => {"notify_sats_received" => 0}})
|
||||
expect(user.pref_enabled?("lightning:notify_sats_received")).to be(false)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user