Added on_submit method and test.

This commit is contained in:
Jamon Holmgren
2013-08-22 09:36:50 -07:00
parent 36b8ff860d
commit 6b0b9f2d35
3 changed files with 16 additions and 3 deletions

View File

@@ -2,7 +2,7 @@ module ProMotion
if defined?(Formotion) && defined?(Formotion::FormController)
class FormotionScreen < Formotion::FormController
include ProMotion::ScreenModule
def self.new(args = {})
s = self.alloc.initWithStyle(UITableViewStyleGrouped)
s.on_create(args) if s.respond_to?(:on_create)
@@ -19,6 +19,8 @@ module ProMotion
s.tableView.allowsSelectionDuringEditing = true
s.title = t
s.form.on_submit { |form| s.on_submit(form) if s.respond_to?(:on_submit) }
s
end
@@ -28,11 +30,11 @@ module ProMotion
self.form.controller = self
self.tableView.reloadData
end
def screen_setup
self.title = self.class.send(:get_title)
end
def loadView
super
self.send(:on_load) if self.respond_to?(:on_load)

View File

@@ -1,4 +1,5 @@
class TestFormotionScreen < PM::FormotionScreen
attr_accessor :submitted_form
title "Formotion Test"
@@ -22,4 +23,8 @@ class TestFormotionScreen < PM::FormotionScreen
}
end
def on_submit(form)
self.submitted_form = form
end
end

View File

@@ -13,4 +13,10 @@ describe "PM::FormotionScreen" do
@screen.title.should == "Formotion Test"
end
it "should fire the on_submit method when form is submitted" do
@screen.form.submit
@screen.submitted_form.should.not.be.nil
@screen.submitted_form.render.should.be.kind_of(Hash)
end
end