Sha256: faa9b2a1b59540be62cdf37b6d998480805d348e206a243b8e9f9f1b39c3f882

Contents?: true

Size: 1.29 KB

Versions: 25

Compression:

Stored size: 1.29 KB

Contents

module EasySettings
  RSpec.describe ParamsWrapper, clear_cache: true do

    let(:project) { FactoryBot.create(:project) }

    describe 'saving values' do
      it 'create easy_setting' do
        presenter = EasySettings::ParamsWrapper.from_params({'key' => 'value', 'key2' => 'value2'})
        expect{ presenter.save }.to change(EasySetting, :count).by(2)
        expect( EasySetting.find_by(name: 'key').value ).to eq('value')
        expect( EasySetting.value('key') ).to eq('value')
      end

      it 'create project setting' do
        EasySetting.where(name: ['key', 'key2']).destroy_all

        presenter = EasySettings::ParamsWrapper.from_params({'key' => 'value', 'key2' => 'value2'}, project: project)
        expect{ presenter.save }.to change(EasySetting, :count).by(2)
        expect( EasySetting.where(project_id: project.id).count ).to eq(2)
        expect( EasySetting.value('key') ).to eq(nil)
        expect( EasySetting.value('key', project) ).to eq('value')
      end

      it 'format value' do
        EasySetting.map.boolean_keys(:key, :key2)
        presenter = EasySettings::ParamsWrapper.from_params({'key' => '1', 'key2' => '0'})
        presenter.save
        expect(EasySetting.value('key')).to be true
        expect(EasySetting.value('key2')).to be false
      end
    end

  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
redmine_extensions-0.3.7 spec/presenters/easy_settings/params_wrapper_spec.rb
redmine_extensions-0.3.6 spec/presenters/easy_settings/params_wrapper_spec.rb
redmine_extensions-0.3.4 spec/presenters/easy_settings/params_wrapper_spec.rb
redmine_extensions-0.3.3 spec/presenters/easy_settings/params_wrapper_spec.rb
redmine_extensions-0.3.2 spec/presenters/easy_settings/params_wrapper_spec.rb