forked from clayallsopp/formotion
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed KVO-related problems. And added proper tests for it.
- Loading branch information
1 parent
93e1519
commit 64e7fd5
Showing
4 changed files
with
88 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
class User | ||
include Formotion::Formable | ||
|
||
attr_accessor :name, :score, :team | ||
|
||
form_property :name, :string | ||
form_property :score, :number, transform: lambda { |value| value.to_i } | ||
|
||
form_property :team, :picker, items: ["Red", "Blue", "Green"] | ||
|
||
form_title "Edit User" | ||
|
||
def initialize(name, score, team) | ||
self.name = name | ||
self.score = score | ||
self.team = team | ||
end | ||
end | ||
|
||
class ObserverTest | ||
include BubbleWrap::KVO | ||
|
||
def users | ||
@users ||= [User.new("Harry", 100, "Green"), | ||
User.new("Ron", 80, "Blue"), | ||
User.new("Hermione", 120, "Red")] | ||
end | ||
|
||
def start_observing | ||
observe(self.users.first, "team") do |old_value, new_value| | ||
end | ||
end | ||
end | ||
|
||
describe "Formotion::Formable w/ KVO" do | ||
it "should work" do | ||
test = ObserverTest.new | ||
test.start_observing | ||
|
||
test.users[0].to_form.title.should == test.users[1].to_form.title | ||
test.users[0].class.form_properties.should == test.users[1].class.form_properties | ||
|
||
test.unobserve_all | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
class User | ||
include Formotion::Formable | ||
|
||
attr_accessor :name, :score, :team | ||
|
||
form_property :name, :string | ||
form_property :score, :number, transform: lambda { |value| value.to_i } | ||
|
||
form_property :team, :picker, items: ["Red", "Blue", "Green"] | ||
|
||
form_title "Edit User" | ||
|
||
def initialize(name, score, team) | ||
self.name = name | ||
self.score = score | ||
self.team = team | ||
end | ||
end | ||
|
||
class AwesomeUser < User | ||
end | ||
|
||
describe "Formotion::Formable w/ Subclasses" do | ||
it "should work" do | ||
user = User.new("Harry", 100, "Green") | ||
awesome = AwesomeUser.new("Clay", 200, "Red") | ||
|
||
user.to_form.title.should == awesome.to_form.title | ||
user.class.form_properties.should == awesome.class.form_properties | ||
end | ||
end |