forked from ontoportal/goo
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31 from ontoportal-lirmm/feature/add-models-on-up…
…date-callbacks Feature: Add models on update callbacks
- Loading branch information
1 parent
6dda059
commit ef5c258
Showing
5 changed files
with
104 additions
and
13 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
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,53 @@ | ||
require_relative 'test_case' | ||
|
||
|
||
require_relative 'models' | ||
|
||
class TestUpdateCallBack < Goo::Base::Resource | ||
model :update_callback_model, name_with: :code | ||
attribute :code, enforce: [:string, :existence] | ||
attribute :name, enforce: [:string, :existence] | ||
attribute :first_name, onUpdate: :update_name | ||
attribute :last_name, onUpdate: :update_name | ||
|
||
|
||
def update_name(inst, attr) | ||
self.name = self.first_name + self.last_name | ||
end | ||
end | ||
|
||
class TestUpdateCallBacks < MiniTest::Unit::TestCase | ||
|
||
def self.before_suite | ||
GooTestData.delete_all [TestUpdateCallBack] | ||
end | ||
|
||
def self.after_suite | ||
GooTestData.delete_all [TestUpdateCallBack] | ||
end | ||
|
||
|
||
def test_update_callback | ||
p = TestUpdateCallBack.new | ||
p.code = "1" | ||
p.name = "name" | ||
p.first_name = "first_name" | ||
p.last_name = "last_name" | ||
|
||
assert p.valid? | ||
p.save | ||
|
||
p.bring_remaining | ||
|
||
assert_equal p.first_name + p.last_name, p.name | ||
|
||
p.last_name = "last_name2" | ||
p.save | ||
|
||
p.bring_remaining | ||
assert_equal "last_name2", p.last_name | ||
assert_equal p.first_name + p.last_name, p.name | ||
end | ||
|
||
end | ||
|