Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge from 'development'

  • Loading branch information...
commit 6be0aab6fbfd9b55c997ab606b2e4a24a843ffa0 2 parents 1307798 + 76b53ef
@cinconnu cinconnu authored
Showing with 73 additions and 0 deletions.
  1. +18 −0 README.rdoc
  2. +8 −0 lib/flag_shih_tzu.rb
  3. +47 −0 test/flag_shih_tzu_test.rb
View
18 README.rdoc
@@ -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:
View
8 lib/flag_shih_tzu.rb
@@ -104,6 +104,10 @@ def selected_#{colmn}=(selected_flags)
end
end
+ def has_#{colmn.singularize}?
+ not selected_#{colmn}.empty?
+ end
+
EVAL
end
@@ -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)
View
47 test/flag_shih_tzu_test.rb
@@ -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
@@ -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
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.