Sha256: dfdac8fffff609f924b26373440f4b7bf60fb7e48edb15e23fafcd34adae7740

Contents?: true

Size: 1.74 KB

Versions: 34

Compression:

Stored size: 1.74 KB

Contents

# encoding: utf-8

require 'spec_helper'

describe RailsAdminSettings::Setting do
  it { is_expected.to have_fields(:enabled, :key, :kind, :raw) }

  it "correctly return content when enabled" do
    setting = FactoryGirl.create(:setting)
    expect(setting.to_s).to eq "Контент 1"
  end

  it "return empty string when disabled" do
    setting = FactoryGirl.create(:setting, enabled: false)
    expect(setting.to_s).to eq ""
  end

  it "correctly process {{year}}" do
    setting = FactoryGirl.create(:setting, raw: '© {{year}} company')
    expect(setting.val).to eq "© #{Time.now.strftime('%Y')} company"
  end

  it "correctly process {{year|2010}}" do
    setting = FactoryGirl.create(:setting, raw: '© {{year|2010}} company')
    expect(setting.val).to eq "© 2010-#{Time.now.strftime('%Y')} company"
  end

  it "correctly process {{year|current_year}}" do
    setting = FactoryGirl.create(:setting, raw: '© {{year|' + Time.now.strftime('%Y') + '}} company')
    expect(setting.val).to eq "© #{Time.now.strftime('%Y')} company"
    expect(setting.val.class.name).not_to eq "ActiveSupport::SafeBuffer"
  end

  it 'return html_safe string when in html mode' do
    setting = FactoryGirl.create(:setting, raw: '© {{year}} company', kind: 'html')
    expect(setting.val).to eq "© #{Time.now.strftime('%Y')} company"
    expect(setting.val.class.name).to eq "ActiveSupport::SafeBuffer"
  end

  it 'sanitize html when in sanitized mode' do
    setting = FactoryGirl.create(:setting, raw: '&copy; {{year}} company <a href="javascript:alert()">test</a>', kind: 'sanitized')
    expect(setting.val).to eq "© #{Time.now.strftime('%Y')} company <a>test</a>"
    expect(setting.val.class.name).to eq "ActiveSupport::SafeBuffer"
  end
end

Version data entries

34 entries across 34 versions & 2 rubygems

Version Path
ack_rails_admin_settings-1.2.3.3 spec/model_spec.rb
ack_rails_admin_settings-1.2.3.2 spec/model_spec.rb
ack_rails_admin_settings-1.2.3.1 spec/model_spec.rb
ack_rails_admin_settings-1.2.3 spec/model_spec.rb
rails_admin_settings-1.3.2 spec/model_spec.rb
rails_admin_settings-1.3.1 spec/model_spec.rb
rails_admin_settings-1.3.0 spec/model_spec.rb
rails_admin_settings-1.2.1 spec/model_spec.rb
rails_admin_settings-1.2.0 spec/model_spec.rb
ack_rails_admin_settings-1.2.2.1 spec/model_spec.rb
ack_rails_admin_settings-1.2.2 spec/model_spec.rb
ack_rails_admin_settings-1.2.1.3 spec/model_spec.rb
ack_rails_admin_settings-1.2.1.2 spec/model_spec.rb
ack_rails_admin_settings-1.2.1.1 spec/model_spec.rb
ack_rails_admin_settings-1.2.1 spec/model_spec.rb
ack_rails_admin_settings-1.2.0.2 spec/model_spec.rb
rails_admin_settings-1.1.4 spec/model_spec.rb
ack_rails_admin_settings-1.2.0.1 spec/model_spec.rb
ack_rails_admin_settings-1.1.5 spec/model_spec.rb
ack_rails_admin_settings-1.1.4 spec/model_spec.rb