Sha256: 15809bc5ca3e125002775312602fd5dc18fe55a58ed4321047e929df0c9aab39

Contents?: true

Size: 1.38 KB

Versions: 8

Compression:

Stored size: 1.38 KB

Contents

# encoding: utf-8

require 'spec_helper'

# this tests check how well thecore_settings handles settings disappearing from DB during execution
# real usage: app specs with database_cleaner enabled
describe 'Database trickery' do

  it "should handle settings disappearing from DB" do
    email = "my@mail.ru"
    email2 = "my2@mail.ru"
    Settings.email = email
    expect(Settings.email).to eq(email)
    ThecoreSettings::Setting.destroy_all
    # settings are still cached
    expect(Settings.email).to eq(email)

    Settings.email = email2
    expect(Settings.email).to eq(email2)
  end

  it "should handle settings appearing in DB when settings are loaded" do
    expect(Settings.tst2).to eq('')
    ThecoreSettings::Setting.create!(key: 'tst', raw: 'tst')
    # settings are still cached, but when we try to create a setting it sees updated value in DB
    expect(Settings.tst).to eq('tst')
  end

  it "should handle settings appearing in DB when settings are not loaded" do
    ThecoreSettings::Setting.create(key: 'tst', raw: 'tst')
    Settings.tst = 'str'
    expect(Settings.tst).to eq('str')
  end

  it "#destroy_all!" do
    Settings.tst = 'str'
    Settings.destroy_all!
    expect(Settings.tst).to eq('')
  end

  it "#destroy!" do
    Settings.tst = 'str'
    Settings.tst2 = 'str2'
    Settings.destroy!(:tst)
    expect(Settings.tst).to eq('')
    expect(Settings.tst2).to eq('str2')
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
thecore_settings-2.0.9 spec/database_trickery_spec.rb
thecore_settings-2.0.8 spec/database_trickery_spec.rb
thecore_settings-2.0.7 spec/database_trickery_spec.rb
thecore_settings-2.0.6 spec/database_trickery_spec.rb
thecore_settings-2.0.5 spec/database_trickery_spec.rb
thecore_settings-2.0.4 spec/database_trickery_spec.rb
thecore_settings-2.0.3 spec/database_trickery_spec.rb
thecore_settings-2.0.2 spec/database_trickery_spec.rb