Skip to content

Commit

Permalink
Merge 35dba51 into f80974e
Browse files Browse the repository at this point in the history
  • Loading branch information
timoschilling committed Nov 2, 2014
2 parents f80974e + 35dba51 commit 9a2a6a8
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 3 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ group :test do
gem 'rails-i18n' # Provides default i18n for many languages
gem 'rspec'
gem 'rspec-rails'
gem 'i18n-spec'
gem 'shoulda-matchers'
gem 'sqlite3'
end
9 changes: 9 additions & 0 deletions lib/active_admin/helpers/settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ def setting(name, default)
read_default_setting name.to_sym
end
end

define_method "#{name}?" do
value = public_send(name)
if value.is_a? Array
value.any?
else
value.present?
end
end
end

def deprecated_setting(name, default, message = nil)
Expand Down
12 changes: 12 additions & 0 deletions spec/unit/i18n_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
require 'rails_helper'

Dir.glob('config/locales/*.yml') do |locale_file|
describe locale_file do
it { is_expected.to be_parseable }
it { is_expected.to have_one_top_level_namespace }
it { is_expected.to be_named_like_top_level_namespace }
it { is_expected.to_not have_legacy_interpolations }
it { is_expected.to have_a_valid_locale }
it { is_expected.to be_a_subset_of 'config/locales/en.yml' }
end
end
36 changes: 33 additions & 3 deletions spec/unit/settings_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,39 @@
end

describe "instance API" do
before{ subject.inheritable_setting :left, :right }
it "should work" do
expect(heir.new.left).to eq :right
describe "the setter `config.left =`" do
before{ subject.inheritable_setting :left, :right }
it "should work" do
config = heir.new
config.left = :none
expect(config.left).to eq :none
end
end

describe "the getter `config.left`" do
before{ subject.inheritable_setting :left, :right }
it "should work" do
expect(heir.new.left).to eq :right
end
end

describe "the getter with question-mark `config.left?`" do
{
"nil" => [nil, false],
"false" => [false, false],
"true" => [true, true],
"string" => ["string", true],
"empty string" => ["", false],
"array" => [[1, 2], true],
"empty array" => [[], false]
}.each do |context, (value, result)|
context "with a #{context} value" do
before{ subject.inheritable_setting :left, value }
it "should be #{result}" do
expect(heir.new.left?).to eq result
end
end
end
end
end

Expand Down

0 comments on commit 9a2a6a8

Please sign in to comment.