Skip to content

Commit

Permalink
Merge bcea701 into 0623a85
Browse files Browse the repository at this point in the history
  • Loading branch information
xpol committed Sep 17, 2018
2 parents 0623a85 + bcea701 commit b54f8b7
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/flag_shih_tzu.rb
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ def unselect_all_#{colmn}
# useful for a form builder
def selected_#{colmn}=(chosen_flags)
unselect_all_flags("#{colmn}")
return if chosen_flags.nil?
chosen_flags.each do |selected_flag|
enable_flag(selected_flag.to_sym, "#{colmn}") if selected_flag.present?
end
Expand Down Expand Up @@ -514,6 +515,7 @@ def selected_flags(colmn = DEFAULT_COLUMN_NAME)
# use selected_#{column}= for custom column names.
def selected_flags=(chosen_flags)
unselect_all_flags
return if chosen_flags.nil?
chosen_flags.each do |selected_flag|
if selected_flag.present?
enable_flag(selected_flag.to_sym, DEFAULT_COLUMN_NAME)
Expand Down
35 changes: 35 additions & 0 deletions test/flag_shih_tzu_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -846,6 +846,30 @@ def test_should_define_an_has_flag_method_with_arity_0
assert !@spaceship.has_flag?
end


def test_should_define_a_selected_flags_writer_method
@spaceship.selected_flags = [:warpdrive]
assert @spaceship.warpdrive
assert !@spaceship.shields
assert !@spaceship.electrolytes

@spaceship.selected_flags = [:warpdrive, :shields, :electrolytes]
assert @spaceship.warpdrive
assert @spaceship.shields
assert @spaceship.electrolytes

@spaceship.selected_flags = []
assert !@spaceship.warpdrive
assert !@spaceship.shields
assert !@spaceship.electrolytes

@spaceship.selected_flags = [:warpdrive, :shields, :electrolytes]
@spaceship.selected_flags = nil
assert !@spaceship.warpdrive
assert !@spaceship.shields
assert !@spaceship.electrolytes
end

# --------------------------------------------------

def test_should_define_a_customized_all_flags_reader_method
Expand Down Expand Up @@ -901,6 +925,10 @@ def test_should_define_a_customized_selected_flags_writer_method
@small_spaceship.selected_bits = []
assert !@small_spaceship.warpdrive
assert !@small_spaceship.hyperspace

@small_spaceship.selected_bits = nil
assert !@small_spaceship.warpdrive
assert !@small_spaceship.hyperspace
end

def test_should_define_a_customized_has_flag_method
Expand Down Expand Up @@ -1007,6 +1035,13 @@ def test_should_define_a_customized_selected_flags_writer_method_with_2_columns
assert !@big_spaceship.hyperspace
assert !@big_spaceship.jeanlucpicard
assert !@big_spaceship.dajanatroj

@big_spaceship.selected_bits = nil
@big_spaceship.selected_commanders = nil
assert !@big_spaceship.warpdrive
assert !@big_spaceship.hyperspace
assert !@big_spaceship.jeanlucpicard
assert !@big_spaceship.dajanatroj
end

def test_should_define_a_customized_has_flag_method_with_2_columns
Expand Down

0 comments on commit b54f8b7

Please sign in to comment.