Skip to content

Commit

Permalink
Merge from 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
cinconnu committed Oct 11, 2012
2 parents 1307798 + 76b53ef commit 6be0aab
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 0 deletions.
18 changes: 18 additions & 0 deletions README.rdoc
Expand Up @@ -152,16 +152,34 @@ on Spaceship:
Spaceship#warpdrive?
Spaceship#warpdrive=
Spaceship#warpdrive_changed?
Spaceship#all_warpdrives
Spaceship#selected_warpdrives
Spaceship#select_all_warpdrives
Spaceship#unselect_all_warpdrives
Spaceship#selected_warpdrives=
Spaceship#has_warpdrive?

Spaceship#shields
Spaceship#shields?
Spaceship#shields=
Spaceship#shields_changed?
Spaceship#all_shields
Spaceship#selected_shields
Spaceship#select_all_shields
Spaceship#unselect_all_shields
Spaceship#selected_shields=
Spaceship#has_shield?

Spaceship#electrolytes
Spaceship#electrolytes?
Spaceship#electrolytes=
Spaceship#electrolytes_changed?
Spaceship#all_electrolytes
Spaceship#selected_electrolytes
Spaceship#select_all_electrolytes
Spaceship#unselect_all_electrolytes
Spaceship#selected_electrolytes=
Spaceship#has_electrolyte?

Opionally, you can set the <tt>:bang_methods</tt> option to true to enable the bang methods:

Expand Down
8 changes: 8 additions & 0 deletions lib/flag_shih_tzu.rb
Expand Up @@ -104,6 +104,10 @@ def selected_#{colmn}=(selected_flags)
end
end
def has_#{colmn.singularize}?
not selected_#{colmn}.empty?
end
EVAL
end

Expand Down Expand Up @@ -270,6 +274,10 @@ def unselect_all_flags(column)
end
end

def has_flag?(column = DEFAULT_COLUMN_NAME)
not selected_flags(column).empty?
end

private

def get_bit_for(flag, colmn)
Expand Down
47 changes: 47 additions & 0 deletions test/flag_shih_tzu_test.rb
Expand Up @@ -423,6 +423,22 @@ def test_should_define_an_unselect_all_flags_method
assert !@spaceship.electrolytes
end

def test_should_define_an_has_flag_method
assert !@spaceship.has_flag?('flags')

@spaceship.warpdrive = true
assert @spaceship.has_flag?('flags')

@spaceship.shields = true
assert @spaceship.has_flag?('flags')

@spaceship.electrolytes = true
assert @spaceship.has_flag?('flags')

@spaceship.unselect_all_flags('flags')
assert !@spaceship.has_flag?('flags')
end

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

def test_should_define_a_customized_all_flags_reader_method
Expand Down Expand Up @@ -477,6 +493,19 @@ def test_should_define_a_customized_selected_flags_writer_method
assert !@small_spaceship.hyperspace
end

def test_should_define_a_customized_has_flag_method
assert !@small_spaceship.has_bit?

@small_spaceship.warpdrive = true
assert @small_spaceship.has_bit?

@small_spaceship.hyperspace = true
assert @small_spaceship.has_bit?

@small_spaceship.unselect_all_bits
assert !@small_spaceship.has_bit?
end

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

def test_should_define_a_customized_all_flags_reader_method_with_2_columns
Expand Down Expand Up @@ -562,6 +591,24 @@ def test_should_define_a_customized_selected_flags_writer_method_with_2_columns
assert !@big_spaceship.dajanatroj
end

def test_should_define_a_customized_has_flag_method_with_2_columns
assert !@big_spaceship.has_bit?
assert !@big_spaceship.has_commander?

@big_spaceship.warpdrive = true
@big_spaceship.jeanlucpicard = true
assert @big_spaceship.has_bit?
assert @big_spaceship.has_commander?

@big_spaceship.hyperspace = true
@big_spaceship.dajanatroj = true
assert @big_spaceship.has_bit?

@big_spaceship.unselect_all_bits
@big_spaceship.unselect_all_commanders
assert !@big_spaceship.has_bit?
end

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

def test_should_define_an_attribute_reader_predicate_method
Expand Down

0 comments on commit 6be0aab

Please sign in to comment.