Merge pull request #511 from clearsightstudio/bugfix/indexable_nil_section_title

Fixes runtime crash when using the indexable table module and a section title is nil
This commit is contained in:
Jamon Holmgren
2014-07-28 21:18:49 -07:00
3 changed files with 22 additions and 1 deletions

View File

@@ -12,6 +12,14 @@ class TableScreenIndexable < PM::TableScreen
end
class TableScreenIndexableNil < TableScreenIndexable
indexable
def table_data
super.push({title: nil, cells: [{ title: "Single cell for group nil" }]})
end
end
class TableScreenIndexableSearchable < TableScreenIndexable
indexable
searchable

View File

@@ -4,7 +4,7 @@ module ProMotion
def table_data_index
return nil if self.promotion_table_data.filtered || !self.class.get_indexable
index = self.promotion_table_data.sections.collect{ |section| section[:title][0] }
index = self.promotion_table_data.sections.collect{ |section| (section[:title] || " ")[0] } || []
index.unshift("{search}") if self.class.get_searchable
index
end

View File

@@ -11,6 +11,19 @@ describe "PM::Table module indexable" do
end
describe "PM::Table module indexable with nil section title" do
before do
@screen = TableScreenIndexableNil.new
end
it "should not crash when a section title is nil" do
result = %w{ A G M O S U }
@screen.sectionIndexTitlesForTableView(@screen.table_view).should == result.push(" ")
end
end
describe "PM::Table module indexable/searchable" do
before do