From 9ac144ec3f5f1627ece78db9ebb548965a8b908d Mon Sep 17 00:00:00 2001 From: Austin Seraphin Date: Mon, 27 Apr 2015 14:43:28 -0400 Subject: [PATCH 1/3] Wrote the spec to test if the TableScreen has tableView:commitEditingStyle:forRowAtIndexPath --- spec/unit/tables/table_screen_spec.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/spec/unit/tables/table_screen_spec.rb b/spec/unit/tables/table_screen_spec.rb index 33d83aa6..16053f45 100644 --- a/spec/unit/tables/table_screen_spec.rb +++ b/spec/unit/tables/table_screen_spec.rb @@ -63,6 +63,22 @@ screen.view.estimatedRowHeight.should == 77 end + it "sets up proper accessibility methods" do +class NoneditableTableScreen < PM::TableScreen + def on_load + end + def table_data + [{title: test, + cells: [{title: "Non-editable test"}]}] + end +end +noneditable=NoneditableTableScreen.new +noneditable.on_load +index_path=NSIndexPath.indexPathForRow(0, inSection: 0) +lambda {noneditable.tableView(noneditable, commitEditingStyle: UITableViewCellEditingStyleDelete, forRowAtIndexPath: index_path)}.should.raise NoMethodError +@screen.should.respond_to(:"tableView:commitEditingStyle:forRowAtIndexPath") + end + end describe "search functionality" do From 1c39217afb77c67cb8c32956a82f7f6b6600b583 Mon Sep 17 00:00:00 2001 From: Austin Seraphin Date: Mon, 27 Apr 2015 14:57:19 -0400 Subject: [PATCH 2/3] Added a spec for editable? --- spec/unit/tables/table_screen_spec.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spec/unit/tables/table_screen_spec.rb b/spec/unit/tables/table_screen_spec.rb index 16053f45..272a426b 100644 --- a/spec/unit/tables/table_screen_spec.rb +++ b/spec/unit/tables/table_screen_spec.rb @@ -74,8 +74,10 @@ def table_data end noneditable=NoneditableTableScreen.new noneditable.on_load +noneditable.editable?.should==false index_path=NSIndexPath.indexPathForRow(0, inSection: 0) lambda {noneditable.tableView(noneditable, commitEditingStyle: UITableViewCellEditingStyleDelete, forRowAtIndexPath: index_path)}.should.raise NoMethodError +@screen.editable?.must==true @screen.should.respond_to(:"tableView:commitEditingStyle:forRowAtIndexPath") end From f88864fe2089f6e600aa730536cfeddf4980897c Mon Sep 17 00:00:00 2001 From: Austin Seraphin Date: Mon, 27 Apr 2015 15:24:06 -0400 Subject: [PATCH 3/3] Created PM::TableScreen#set_up_accessibility, #editable? and moved tableView:commitEditingStyle:forRowAtIndexPath to a new PM::TableScreen::Editable module --- lib/ProMotion/table/table.rb | 16 ++++++++++++++++ spec/unit/tables/table_screen_spec.rb | 4 ++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/ProMotion/table/table.rb b/lib/ProMotion/table/table.rb index 5cbdbc16..a65c5ddb 100644 --- a/lib/ProMotion/table/table.rb +++ b/lib/ProMotion/table/table.rb @@ -20,6 +20,7 @@ def screen_setup set_up_refreshable set_up_longpressable set_up_row_height + set_up_accessibility end def check_table_data @@ -89,6 +90,19 @@ def set_up_row_height end end + def editable? + self.promotion_table_data.sections.each do |section| + section[:cells].each do |cell| + return true if [:insert,:delete].include?(cell[:editing_style]) + end + end + false + end + + def set_up_accessibility + self.extend(Editable) if editable? +end + def searching? self.promotion_table_data.filtered end @@ -235,11 +249,13 @@ def tableView(_, editingStyleForRowAtIndexPath: index_path) map_cell_editing_style(data_cell[:editing_style]) end + module Editable def tableView(_, commitEditingStyle: editing_style, forRowAtIndexPath: index_path) if editing_style == UITableViewCellEditingStyleDelete delete_row(index_path) end end + end def tableView(_, canMoveRowAtIndexPath:index_path) data_cell = self.promotion_table_data.cell(index_path: index_path, unfiltered: true) diff --git a/spec/unit/tables/table_screen_spec.rb b/spec/unit/tables/table_screen_spec.rb index 272a426b..4113070d 100644 --- a/spec/unit/tables/table_screen_spec.rb +++ b/spec/unit/tables/table_screen_spec.rb @@ -68,7 +68,7 @@ class NoneditableTableScreen < PM::TableScreen def on_load end def table_data - [{title: test, + [{title: "test", cells: [{title: "Non-editable test"}]}] end end @@ -77,7 +77,7 @@ def table_data noneditable.editable?.should==false index_path=NSIndexPath.indexPathForRow(0, inSection: 0) lambda {noneditable.tableView(noneditable, commitEditingStyle: UITableViewCellEditingStyleDelete, forRowAtIndexPath: index_path)}.should.raise NoMethodError -@screen.editable?.must==true +@screen.editable?.should==true @screen.should.respond_to(:"tableView:commitEditingStyle:forRowAtIndexPath") end