diff --git a/app/views/profile_editor/_organization.rhtml b/app/views/profile_editor/_organization.rhtml
index 57fa906..ff3d38e 100644
--- a/app/views/profile_editor/_organization.rhtml
+++ b/app/views/profile_editor/_organization.rhtml
@@ -13,7 +13,18 @@
<%= f.text_area(:management_information, :rows => 5) %>
<%= f.text_area(:description, :rows => 5) if @profile.kind_of?(Community) %>
<%= _('Moderation options') %>
-
- <%= check_box 'profile_data', 'closed' %>
- <%= _("New members must be approved by an administrator before joining this group?") %>
-
+
+ <%= _('New members must be approved:')%>
+
+
+ <%= radio_button 'profile_data', 'closed', 'true', :style => 'float: left' %>
+
+ <%= _('Before joining this group (a moderator has to accept the member in pending request before member can access the intranet and/or the website).') %>
+
+
+
+ <%= radio_button 'profile_data', 'closed', 'false', :style => 'float: left' %>
+
+ <%= _('After joining this group (a moderator can always desactivate access for users later).') %>
+
+
diff --git a/lib/acts_as_having_settings.rb b/lib/acts_as_having_settings.rb
index 181001b..de8af62 100644
--- a/lib/acts_as_having_settings.rb
+++ b/lib/acts_as_having_settings.rb
@@ -21,7 +21,7 @@ module ActsAsHavingSettings
def settings_items(*names)
options = names.last.is_a?(Hash) ? names.pop : {}
- default = options[:default] ? options[:default].inspect : "val"
+ default = (!options[:default].nil?) ? options[:default].inspect : "val"
data_type = options[:type] || :string
names.each do |setting|
diff --git a/test/functional/profile_editor_controller_test.rb b/test/functional/profile_editor_controller_test.rb
index f57b38c..b77a8ed 100644
--- a/test/functional/profile_editor_controller_test.rb
+++ b/test/functional/profile_editor_controller_test.rb
@@ -271,10 +271,42 @@ class ProfileEditorControllerTest < Test::Unit::TestCase
assert_not_nil assigns(:profile).image
end
- should 'show field to set closed organization' do
- org = Organization.create!(:name => 'test org', :identifier => 'testorg', :contact_person => 'my contact')
+ should 'display closed attribute for organizations when it is set' do
+ org = Organization.create!(:name => 'test org', :identifier => 'testorg', :contact_person => 'my contact', :closed => true)
+ get :edit, :profile => 'testorg'
+
+ assert_tag :tag => 'input', :attributes => { :type => 'radio', :name => 'profile_data[closed]', :value => 'true', :checked => 'checked' }
+ assert_no_tag :tag => 'input', :attributes => { :type => 'radio', :name => 'profile_data[closed]', :value => 'false', :checked => 'checked' }
+ end
+
+ should 'display closed attribute for organizations when it is set to false' do
+ org = Organization.create!(:name => 'test org', :identifier => 'testorg', :contact_person => 'my contact', :closed => false)
+ get :edit, :profile => 'testorg'
+ assert_no_tag :tag => 'input', :attributes => { :type => 'radio', :name => 'profile_data[closed]', :value => 'true', :checked => 'checked' }
+ assert_tag :tag => 'input', :attributes => { :type => 'radio', :name => 'profile_data[closed]', :value => 'false', :checked => 'checked' }
+ end
+
+ should 'display closed attribute for organizations when it is set to nothing at all' do
+ org = Organization.create!(:name => 'test org', :identifier => 'testorg', :contact_person => 'my contact', :closed => nil)
get :edit, :profile => 'testorg'
- assert_tag :tag => 'input', :attributes => { :type => 'checkbox', :name => 'profile_data[closed]' }
+ assert_no_tag :tag => 'input', :attributes => { :type => 'radio', :name => 'profile_data[closed]', :value => 'true', :checked => 'checked' }
+ assert_tag :tag => 'input', :attributes => { :type => 'radio', :name => 'profile_data[closed]', :value => 'false', :checked => 'checked' }
+ end
+
+ should 'set closed attribute correctly' do
+ org = Organization.create!(:name => 'test org', :identifier => 'testorg', :contact_person => 'my contact', :closed => false)
+
+ post :edit, :profile => 'testorg', :profile_data => { :closed => 'true' }
+ org.reload
+ assert org.closed
+ end
+
+ should 'unset closed attribute correctly' do
+ org = Organization.create!(:name => 'test org', :identifier => 'testorg', :contact_person => 'my contact', :closed => true)
+
+ post :edit, :profile => 'testorg', :profile_data => { :closed => 'false' }
+ org.reload
+ assert !org.closed
end
should 'display manage members options if has permission' do
diff --git a/test/unit/acts_as_having_settings_test.rb b/test/unit/acts_as_having_settings_test.rb
index 8572ec2..39c2413 100644
--- a/test/unit/acts_as_having_settings_test.rb
+++ b/test/unit/acts_as_having_settings_test.rb
@@ -5,6 +5,7 @@ class ActsAsHavingSettingsTest < Test::Unit::TestCase
# using Block class as a sample user of the module
class TestClass < Block
settings_items :flag, :type => :boolean
+ settings_items :flag_disabled_by_default, :type => :boolean, :default => false
end
should 'store settings in a hash' do
@@ -57,6 +58,10 @@ class ActsAsHavingSettingsTest < Test::Unit::TestCase
assert_equal false, obj.flag
end
+ should 'return false by default when the default is false' do
+ assert_equal false, TestClass.new.flag_disabled_by_default
+ end
+
should 'be able to specify type of atrributes (boolean)' do
obj = TestClass.new
obj.flag = 'true'
--
libgit2 0.21.2