Commit 2baf97af04942b366203ae72e7ec2f456f66618b
1 parent
7c877fc3
Exists in
master
and in
29 other branches
ActionItem612: enhancing group joining moderation
* added new wording * enhanced formatting * fixed a bug in acts_as_having_settings that was making boolean settings with false as default not return false! git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@2444 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
4 changed files
with
56 additions
and
8 deletions
Show diff stats
app/views/profile_editor/_organization.rhtml
... | ... | @@ -13,7 +13,18 @@ |
13 | 13 | <%= f.text_area(:management_information, :rows => 5) %> |
14 | 14 | <%= f.text_area(:description, :rows => 5) if @profile.kind_of?(Community) %> |
15 | 15 | <h1><%= _('Moderation options') %></h1> |
16 | - <p> | |
17 | - <%= check_box 'profile_data', 'closed' %> | |
18 | - <%= _("New members must be approved by an administrator before joining this group?") %> | |
19 | - </p> | |
16 | + <div style='margin-bottom: 1em'> | |
17 | + <%= _('New members must be approved:')%> | |
18 | + </div> | |
19 | + <div style='margin-bottom: 0.5em'> | |
20 | + <%= radio_button 'profile_data', 'closed', 'true', :style => 'float: left' %> | |
21 | + <div style='margin-left: 30px'> | |
22 | + <%= _('<strong>Before</strong> joining this group (a moderator has to accept the member in pending request before member can access the intranet and/or the website).') %> | |
23 | + </div> | |
24 | + </div> | |
25 | + <div> | |
26 | + <%= radio_button 'profile_data', 'closed', 'false', :style => 'float: left' %> | |
27 | + <div style='margin-left: 30px'> | |
28 | + <%= _('<strong>After</strong> joining this group (a moderator can always desactivate access for users later).') %> | |
29 | + </div> | |
30 | + </div> | ... | ... |
lib/acts_as_having_settings.rb
... | ... | @@ -21,7 +21,7 @@ module ActsAsHavingSettings |
21 | 21 | def settings_items(*names) |
22 | 22 | |
23 | 23 | options = names.last.is_a?(Hash) ? names.pop : {} |
24 | - default = options[:default] ? options[:default].inspect : "val" | |
24 | + default = (!options[:default].nil?) ? options[:default].inspect : "val" | |
25 | 25 | data_type = options[:type] || :string |
26 | 26 | |
27 | 27 | names.each do |setting| | ... | ... |
test/functional/profile_editor_controller_test.rb
... | ... | @@ -271,10 +271,42 @@ class ProfileEditorControllerTest < Test::Unit::TestCase |
271 | 271 | assert_not_nil assigns(:profile).image |
272 | 272 | end |
273 | 273 | |
274 | - should 'show field to set closed organization' do | |
275 | - org = Organization.create!(:name => 'test org', :identifier => 'testorg', :contact_person => 'my contact') | |
274 | + should 'display closed attribute for organizations when it is set' do | |
275 | + org = Organization.create!(:name => 'test org', :identifier => 'testorg', :contact_person => 'my contact', :closed => true) | |
276 | + get :edit, :profile => 'testorg' | |
277 | + | |
278 | + assert_tag :tag => 'input', :attributes => { :type => 'radio', :name => 'profile_data[closed]', :value => 'true', :checked => 'checked' } | |
279 | + assert_no_tag :tag => 'input', :attributes => { :type => 'radio', :name => 'profile_data[closed]', :value => 'false', :checked => 'checked' } | |
280 | + end | |
281 | + | |
282 | + should 'display closed attribute for organizations when it is set to false' do | |
283 | + org = Organization.create!(:name => 'test org', :identifier => 'testorg', :contact_person => 'my contact', :closed => false) | |
284 | + get :edit, :profile => 'testorg' | |
285 | + assert_no_tag :tag => 'input', :attributes => { :type => 'radio', :name => 'profile_data[closed]', :value => 'true', :checked => 'checked' } | |
286 | + assert_tag :tag => 'input', :attributes => { :type => 'radio', :name => 'profile_data[closed]', :value => 'false', :checked => 'checked' } | |
287 | + end | |
288 | + | |
289 | + should 'display closed attribute for organizations when it is set to nothing at all' do | |
290 | + org = Organization.create!(:name => 'test org', :identifier => 'testorg', :contact_person => 'my contact', :closed => nil) | |
276 | 291 | get :edit, :profile => 'testorg' |
277 | - assert_tag :tag => 'input', :attributes => { :type => 'checkbox', :name => 'profile_data[closed]' } | |
292 | + assert_no_tag :tag => 'input', :attributes => { :type => 'radio', :name => 'profile_data[closed]', :value => 'true', :checked => 'checked' } | |
293 | + assert_tag :tag => 'input', :attributes => { :type => 'radio', :name => 'profile_data[closed]', :value => 'false', :checked => 'checked' } | |
294 | + end | |
295 | + | |
296 | + should 'set closed attribute correctly' do | |
297 | + org = Organization.create!(:name => 'test org', :identifier => 'testorg', :contact_person => 'my contact', :closed => false) | |
298 | + | |
299 | + post :edit, :profile => 'testorg', :profile_data => { :closed => 'true' } | |
300 | + org.reload | |
301 | + assert org.closed | |
302 | + end | |
303 | + | |
304 | + should 'unset closed attribute correctly' do | |
305 | + org = Organization.create!(:name => 'test org', :identifier => 'testorg', :contact_person => 'my contact', :closed => true) | |
306 | + | |
307 | + post :edit, :profile => 'testorg', :profile_data => { :closed => 'false' } | |
308 | + org.reload | |
309 | + assert !org.closed | |
278 | 310 | end |
279 | 311 | |
280 | 312 | should 'display manage members options if has permission' do | ... | ... |
test/unit/acts_as_having_settings_test.rb
... | ... | @@ -5,6 +5,7 @@ class ActsAsHavingSettingsTest < Test::Unit::TestCase |
5 | 5 | # using Block class as a sample user of the module |
6 | 6 | class TestClass < Block |
7 | 7 | settings_items :flag, :type => :boolean |
8 | + settings_items :flag_disabled_by_default, :type => :boolean, :default => false | |
8 | 9 | end |
9 | 10 | |
10 | 11 | should 'store settings in a hash' do |
... | ... | @@ -57,6 +58,10 @@ class ActsAsHavingSettingsTest < Test::Unit::TestCase |
57 | 58 | assert_equal false, obj.flag |
58 | 59 | end |
59 | 60 | |
61 | + should 'return false by default when the default is false' do | |
62 | + assert_equal false, TestClass.new.flag_disabled_by_default | |
63 | + end | |
64 | + | |
60 | 65 | should 'be able to specify type of atrributes (boolean)' do |
61 | 66 | obj = TestClass.new |
62 | 67 | obj.flag = 'true' | ... | ... |